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
) {
24 a
->offset
= c
->bits
.i
;
31 alias(Ref p
, int sp
, Ref q
, int sq
, int *delta
, Fn
*fn
)
38 *delta
= ap
.offset
- aq
.offset
;
39 ovlap
= ap
.offset
< aq
.offset
+ sq
&& aq
.offset
< ap
.offset
+ sp
;
41 if (astack(ap
.type
) && astack(aq
.type
)) {
42 /* if both are offsets of the same
43 * stack slot, they alias iif they
45 if (ap
.base
== aq
.base
&& ovlap
)
50 if (ap
.type
== ASym
&& aq
.type
== ASym
) {
51 /* they conservatively alias if the
52 * symbols are different, or they
53 * alias for sure if they overlap */
54 if (!symeq(ap
.u
.sym
, aq
.u
.sym
))
61 if ((ap
.type
== ACon
&& aq
.type
== ACon
)
62 || (ap
.type
== aq
.type
&& ap
.base
== aq
.base
)) {
63 assert(ap
.type
== ACon
|| ap
.type
== AUnk
);
64 /* if they have the same base, we
65 * can rely on the offsets only */
71 /* if one of the two is unknown
72 * there may be aliasing unless
73 * the other is provably local */
74 if (ap
.type
== AUnk
&& aq
.type
!= ALoc
)
76 if (aq
.type
== AUnk
&& ap
.type
!= ALoc
)
83 escapes(Ref r
, Fn
*fn
)
89 a
= &fn
->tmp
[r
.val
].alias
;
90 return !astack(a
->type
) || a
->slot
->type
== AEsc
;
98 assert(rtype(r
) <= RType
);
99 if (rtype(r
) == RTmp
) {
100 a
= &fn
->tmp
[r
.val
].alias
;
102 a
->slot
->type
= AEsc
;
119 for (t
=0; t
<fn
->ntmp
; t
++)
120 fn
->tmp
[t
].alias
.type
= ABot
;
121 for (n
=0; n
<fn
->nblk
; ++n
) {
123 for (p
=b
->phi
; p
; p
=p
->link
) {
124 for (m
=0; m
<p
->narg
; m
++)
126 assert(rtype(p
->to
) == RTmp
);
127 a
= &fn
->tmp
[p
->to
.val
].alias
;
128 assert(a
->type
== ABot
);
134 for (i
=b
->ins
; i
<&b
->ins
[b
->nins
]; ++i
) {
136 if (!req(i
->to
, R
)) {
137 assert(rtype(i
->to
) == RTmp
);
138 a
= &fn
->tmp
[i
->to
.val
].alias
;
139 assert(a
->type
== ABot
);
140 if (Oalloc
<= i
->op
&& i
->op
<= Oalloc1
) {
144 if (rtype(i
->arg
[0]) == RCon
) {
145 c
= &fn
->con
[i
->arg
[0].val
];
147 if (c
->type
== CBits
)
148 if (0 <= x
&& x
<= NBit
)
158 if (i
->op
== Ocopy
) {
160 getalias(a
, i
->arg
[0], fn
);
163 getalias(&a0
, i
->arg
[0], fn
);
164 getalias(&a1
, i
->arg
[1], fn
);
165 if (a0
.type
== ACon
) {
167 a
->offset
+= a0
.offset
;
169 else if (a1
.type
== ACon
) {
171 a
->offset
+= a1
.offset
;
174 if (req(i
->to
, R
) || a
->type
== AUnk
) {
182 if (rtype(i
->arg
[1]) == RTmp
) {
183 a
= &fn
->tmp
[i
->arg
[1].val
].alias
;
185 assert(astack(a
->type
));
187 if (0 <= x
&& x
< NBit
) {
188 w
= BIT(storesz(i
)) - 1;
189 a
->slot
->u
.loc
.m
|= w
<< x
;
191 a
->slot
->u
.loc
.sz
= -1;