4 liveon(BSet
*v
, Blk
*b
, Blk
*s
)
10 for (p
=s
->phi
; p
; p
=p
->link
)
11 if (rtype(p
->to
) == RTmp
)
13 for (p
=s
->phi
; p
; p
=p
->link
)
14 for (a
=0; a
<p
->narg
; a
++)
16 if (rtype(p
->arg
[a
]) == RTmp
) {
17 bsset(v
, p
->arg
[a
].val
);
18 bsset(b
->gen
, p
->arg
[a
].val
);
23 phitmp(int t
, Tmp
*tmp
)
32 phifix(int t1
, int *phi
, Tmp
*tmp
)
36 /* detect temporaries arguments
37 * of the same phi node that
38 * interfere and separate them
55 bset(Ref r
, Blk
*b
, int *nlv
, int *phi
, Tmp
*tmp
)
61 phifix(r
.val
, phi
, tmp
);
62 if (!bshas(b
->in
, r
.val
)) {
63 nlv
[KBASE(tmp
[r
.val
].cls
)]++;
69 * requires rpo computation
76 int k
, t
, m
[2], n
, chg
, nlv
[2];
83 phi
= emalloc(f
->ntmp
* sizeof phi
[0]);
84 for (b
=f
->start
; b
; b
=b
->link
) {
85 bsinit(b
->in
, f
->ntmp
);
86 bsinit(b
->out
, f
->ntmp
);
87 bsinit(b
->gen
, f
->ntmp
);
91 for (n
=f
->nblk
-1; n
>=0; n
--) {
103 chg
|= !bsequal(b
->out
, u
);
105 memset(phi
, 0, f
->ntmp
* sizeof phi
[0]);
106 memset(nlv
, 0, sizeof nlv
);
107 b
->out
->t
[0] |= RGLOB
;
108 bscopy(b
->in
, b
->out
);
109 for (t
=0; bsiter(b
->in
, &t
); t
++) {
110 phifix(t
, phi
, f
->tmp
);
111 nlv
[KBASE(f
->tmp
[t
].cls
)]++;
113 if (rtype(b
->jmp
.arg
) == RCall
) {
114 assert(bscount(b
->in
) == NRGlob
&& nlv
[0] == NRGlob
&& nlv
[1] == 0);
115 b
->in
->t
[0] |= retregs(b
->jmp
.arg
, nlv
);
117 bset(b
->jmp
.arg
, b
, nlv
, phi
, f
->tmp
);
119 b
->nlive
[k
] = nlv
[k
];
120 for (i
=&b
->ins
[b
->nins
]; i
!=b
->ins
;) {
121 if ((--i
)->op
== Ocall
&& rtype(i
->arg
[1]) == RCall
) {
122 b
->in
->t
[0] &= ~retregs(i
->arg
[1], m
);
125 if (nlv
[0] + NISave
> b
->nlive
[0])
126 b
->nlive
[0] = nlv
[0] + NISave
;
127 if (nlv
[1] + NFSave
> b
->nlive
[1])
128 b
->nlive
[1] = nlv
[1] + NFSave
;
129 b
->in
->t
[0] |= argregs(i
->arg
[1], m
);
133 if (!req(i
->to
, R
)) {
134 assert(rtype(i
->to
) == RTmp
);
136 if (bshas(b
->in
, i
->to
.val
))
137 nlv
[KBASE(f
->tmp
[t
].cls
)]--;
140 phi
[phitmp(t
, f
->tmp
)] = 0;
143 switch (rtype(i
->arg
[k
])) {
145 ma
= &f
->mem
[i
->arg
[k
].val
];
146 bset(ma
->base
, b
, nlv
, phi
, f
->tmp
);
147 bset(ma
->index
, b
, nlv
, phi
, f
->tmp
);
150 bset(i
->arg
[k
], b
, nlv
, phi
, f
->tmp
);
154 if (nlv
[k
] > b
->nlive
[k
])
155 b
->nlive
[k
] = nlv
[k
];
165 fprintf(stderr
, "\n> Liveness analysis:\n");
166 for (b
=f
->start
; b
; b
=b
->link
) {
167 fprintf(stderr
, "\t%-10sin: ", b
->name
);
168 dumpts(b
->in
, f
->tmp
, stderr
);
169 fprintf(stderr
, "\t out: ");
170 dumpts(b
->out
, f
->tmp
, stderr
);
171 fprintf(stderr
, "\t gen: ");
172 dumpts(b
->gen
, f
->tmp
, stderr
);
173 fprintf(stderr
, "\t live: ");
174 fprintf(stderr
, "%d %d\n", b
->nlive
[0], b
->nlive
[1]);