4 getalias(Alias
*a
, Ref r
, Fn
*fn
)
12 *a
= fn
->tmp
[r
.val
].alias
;
13 a
->type
= a
->slot
->type
;
14 assert(a
->type
!= ABot
);
18 if (c
->type
== CAddr
) {
20 strcpy(a
->label
, c
->label
);
23 a
->offset
= c
->bits
.i
;
30 alias(Ref p
, int sp
, Ref q
, int sq
, int *delta
, Fn
*fn
)
37 *delta
= ap
.offset
- aq
.offset
;
38 ovlap
= ap
.offset
< aq
.offset
+ sq
&& aq
.offset
< ap
.offset
+ sp
;
40 if (ap
.type
& aq
.type
& 1) {
41 /* if both are offsets of the same
42 * stack slot, they alias iif they
44 if (req(ap
.base
, aq
.base
) && ovlap
)
49 if (ap
.type
== ASym
&& aq
.type
== ASym
) {
50 /* they conservatively alias if the
51 * symbols are different, or they
52 * alias for sure if they overlap */
53 if (strcmp(ap
.label
, aq
.label
) != 0)
60 if ((ap
.type
== ACon
&& aq
.type
== ACon
)
61 || (ap
.type
== aq
.type
&& req(ap
.base
, aq
.base
))) {
62 assert(ap
.type
== ACon
|| ap
.type
== AUnk
);
63 /* if they have the same base, we
64 * can rely on the offsets only */
70 /* if one of the two is unknown
71 * there may be aliasing unless
72 * the other is provably local */
73 if (ap
.type
== AUnk
&& aq
.type
!= ALoc
)
75 if (aq
.type
== AUnk
&& ap
.type
!= ALoc
)
82 escapes(Ref r
, Fn
*fn
)
88 a
= &fn
->tmp
[r
.val
].alias
;
89 return !(a
->type
& 1) || a
->slot
->type
== AEsc
;
97 assert(rtype(r
) <= RType
);
98 if (rtype(r
) == RTmp
) {
99 a
= &fn
->tmp
[r
.val
].alias
;
100 if (a
->slot
->type
== ALoc
)
101 a
->slot
->type
= AEsc
;
114 for (n
=0; n
<fn
->nblk
; ++n
) {
116 for (p
=b
->phi
; p
; p
=p
->link
) {
117 assert(rtype(p
->to
) == RTmp
);
118 a
= &fn
->tmp
[p
->to
.val
].alias
;
119 assert(a
->type
== ABot
);
125 for (i
=b
->ins
; i
<&b
->ins
[b
->nins
]; ++i
) {
127 if (!req(i
->to
, R
)) {
128 assert(rtype(i
->to
) == RTmp
);
129 a
= &fn
->tmp
[i
->to
.val
].alias
;
130 assert(a
->type
== ABot
);
131 if (Oalloc
<= i
->op
&& i
->op
<= Oalloc1
)
139 if (i
->op
== Ocopy
) {
141 getalias(a
, i
->arg
[0], fn
);
144 getalias(&a0
, i
->arg
[0], fn
);
145 getalias(&a1
, i
->arg
[1], fn
);
146 if (a0
.type
== ACon
) {
148 a
->offset
+= a0
.offset
;
150 else if (a1
.type
== ACon
) {
152 a
->offset
+= a1
.offset
;
155 if (req(i
->to
, R
) || a
->type
== AUnk
) {