4 getalias(Alias
*a
, Ref r
, Fn
*fn
)
12 *a
= fn
->tmp
[r
.val
].alias
;
13 assert(a
->type
!= ABot
);
17 if (c
->type
== CAddr
) {
19 strcpy(a
->label
, c
->label
);
22 a
->offset
= c
->bits
.i
;
28 alias(Ref p
, int sp
, Ref q
, int sq
, int *delta
, Fn
*fn
)
35 *delta
= ap
.offset
- aq
.offset
;
36 ovlap
= ap
.offset
< aq
.offset
+ sq
&& aq
.offset
< ap
.offset
+ sp
;
38 if (ap
.type
& aq
.type
& 1) {
39 /* if both are offsets of the same
40 * stack slot, they alias iif they
42 if (req(ap
.base
, aq
.base
) && ovlap
)
47 if (ap
.type
== ASym
&& aq
.type
== ASym
) {
48 /* they conservatively alias if the
49 * symbols are different, or they
50 * alias for sure if they overlap */
51 if (strcmp(ap
.label
, aq
.label
) != 0)
58 if ((ap
.type
== ACon
&& aq
.type
== ACon
)
59 || (ap
.type
== aq
.type
&& req(ap
.base
, aq
.base
))) {
60 assert(ap
.type
== ACon
|| ap
.type
== AUnk
);
61 /* if they have the same base, we
62 * can rely on the offsets only */
68 /* if one of the two is unknown
69 * there may be aliasing unless
70 * the other is provably local */
71 if (ap
.type
== AUnk
&& aq
.type
!= ALoc
)
73 if (aq
.type
== AUnk
&& ap
.type
!= ALoc
)
80 escapes(Ref r
, Fn
*fn
)
84 return fn
->tmp
[r
.val
].alias
.type
!= ALoc
;
92 assert(rtype(r
) <= RType
);
93 if (rtype(r
) == RTmp
) {
94 a
= &fn
->tmp
[r
.val
].alias
;
95 assert(a
->type
!= ABot
);
110 for (n
=0; n
<fn
->nblk
; ++n
) {
112 for (p
=b
->phi
; p
; p
=p
->link
) {
113 assert(rtype(p
->to
) == RTmp
);
114 a
= &fn
->tmp
[p
->to
.val
].alias
;
115 assert(a
->type
== ABot
);
120 for (i
=b
->ins
; i
<&b
->ins
[b
->nins
]; ++i
) {
122 if (!req(i
->to
, R
)) {
123 assert(rtype(i
->to
) == RTmp
);
124 a
= &fn
->tmp
[i
->to
.val
].alias
;
125 assert(a
->type
== ABot
);
126 if (Oalloc
<= i
->op
&& i
->op
<= Oalloc1
)
133 if (i
->op
== Ocopy
) {
135 getalias(a
, i
->arg
[0], fn
);
138 getalias(&a0
, i
->arg
[0], fn
);
139 getalias(&a1
, i
->arg
[1], fn
);
140 if (a0
.type
== ACon
) {
142 a
->offset
+= a0
.offset
;
144 else if (a1
.type
== ACon
) {
146 a
->offset
+= a1
.offset
;
149 if (req(i
->to
, R
) || a
->type
== AUnk
) {