4 getalias(Alias
*a
, Ref r
, Fn
*fn
)
12 *a
= fn
->tmp
[r
.val
].alias
;
14 a
->type
= a
->slot
->type
;
15 assert(a
->type
!= ABot
);
19 if (c
->type
== CAddr
) {
25 a
->offset
= c
->bits
.i
;
32 alias(Ref p
, int sp
, Ref q
, int sq
, int *delta
, Fn
*fn
)
39 *delta
= ap
.offset
- aq
.offset
;
40 ovlap
= ap
.offset
< aq
.offset
+ sq
&& aq
.offset
< ap
.offset
+ sp
;
42 if (astack(ap
.type
) && astack(aq
.type
)) {
43 /* if both are offsets of the same
44 * stack slot, they alias iif they
46 if (req(ap
.base
, aq
.base
) && ovlap
)
51 if (ap
.type
== ASym
&& aq
.type
== ASym
) {
52 /* they conservatively alias if the
53 * symbols are different, or they
54 * alias for sure if they overlap */
55 if (ap
.label
!= aq
.label
)
62 if ((ap
.type
== ACon
&& aq
.type
== ACon
)
63 || (ap
.type
== aq
.type
&& req(ap
.base
, aq
.base
))) {
64 assert(ap
.type
== ACon
|| ap
.type
== AUnk
);
65 /* if they have the same base, we
66 * can rely on the offsets only */
72 /* if one of the two is unknown
73 * there may be aliasing unless
74 * the other is provably local */
75 if (ap
.type
== AUnk
&& aq
.type
!= ALoc
)
77 if (aq
.type
== AUnk
&& ap
.type
!= ALoc
)
84 escapes(Ref r
, Fn
*fn
)
90 a
= &fn
->tmp
[r
.val
].alias
;
91 return !astack(a
->type
) || a
->slot
->type
== AEsc
;
99 assert(rtype(r
) <= RType
);
100 if (rtype(r
) == RTmp
) {
101 a
= &fn
->tmp
[r
.val
].alias
;
103 a
->slot
->type
= AEsc
;
116 for (n
=0; n
<fn
->nblk
; ++n
) {
118 for (p
=b
->phi
; p
; p
=p
->link
) {
119 for (m
=0; m
<p
->narg
; m
++)
121 assert(rtype(p
->to
) == RTmp
);
122 a
= &fn
->tmp
[p
->to
.val
].alias
;
123 assert(a
->type
== ABot
);
129 for (i
=b
->ins
; i
<&b
->ins
[b
->nins
]; ++i
) {
131 if (!req(i
->to
, R
)) {
132 assert(rtype(i
->to
) == RTmp
);
133 a
= &fn
->tmp
[i
->to
.val
].alias
;
134 assert(a
->type
== ABot
);
135 if (Oalloc
<= i
->op
&& i
->op
<= Oalloc1
) {
145 if (i
->op
== Ocopy
) {
147 getalias(a
, i
->arg
[0], fn
);
150 getalias(&a0
, i
->arg
[0], fn
);
151 getalias(&a1
, i
->arg
[1], fn
);
152 if (a0
.type
== ACon
) {
154 a
->offset
+= a0
.offset
;
156 else if (a1
.type
== ACon
) {
158 a
->offset
+= a1
.offset
;
161 if (req(i
->to
, R
) || a
->type
== AUnk
) {