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 bset(Ref r
, Blk
*b
, int *nlv
, Tmp
*tmp
)
29 if (!bshas(b
->in
, r
.val
)) {
30 nlv
[KBASE(tmp
[r
.val
].cls
)]++;
36 * requires rpo computation
43 int k
, t
, m
[2], n
, chg
, nlv
[2];
49 for (b
=f
->start
; b
; b
=b
->link
) {
50 bsinit(b
->in
, f
->ntmp
);
51 bsinit(b
->out
, f
->ntmp
);
52 bsinit(b
->gen
, f
->ntmp
);
56 for (n
=f
->nblk
-1; n
>=0; n
--) {
68 chg
|= !bsequal(b
->out
, u
);
70 memset(nlv
, 0, sizeof nlv
);
71 b
->out
->t
[0] |= T
.rglob
;
72 bscopy(b
->in
, b
->out
);
73 for (t
=0; bsiter(b
->in
, &t
); t
++)
74 nlv
[KBASE(f
->tmp
[t
].cls
)]++;
75 if (rtype(b
->jmp
.arg
) == RCall
) {
76 assert((int)bscount(b
->in
) == T
.nrglob
&&
79 b
->in
->t
[0] |= T
.retregs(b
->jmp
.arg
, nlv
);
81 bset(b
->jmp
.arg
, b
, nlv
, f
->tmp
);
84 for (i
=&b
->ins
[b
->nins
]; i
!=b
->ins
;) {
85 if ((--i
)->op
== Ocall
&& rtype(i
->arg
[1]) == RCall
) {
86 b
->in
->t
[0] &= ~T
.retregs(i
->arg
[1], m
);
89 /* caller-save registers are used
90 * by the callee, in that sense,
91 * right in the middle of the call,
93 nlv
[k
] += T
.nrsave
[k
];
94 if (nlv
[k
] > b
->nlive
[k
])
97 b
->in
->t
[0] |= T
.argregs(i
->arg
[1], m
);
99 nlv
[k
] -= T
.nrsave
[k
];
103 if (!req(i
->to
, R
)) {
104 assert(rtype(i
->to
) == RTmp
);
106 if (bshas(b
->in
, i
->to
.val
))
107 nlv
[KBASE(f
->tmp
[t
].cls
)]--;
112 switch (rtype(i
->arg
[k
])) {
114 ma
= &f
->mem
[i
->arg
[k
].val
];
115 bset(ma
->base
, b
, nlv
, f
->tmp
);
116 bset(ma
->index
, b
, nlv
, f
->tmp
);
119 bset(i
->arg
[k
], b
, nlv
, f
->tmp
);
123 if (nlv
[k
] > b
->nlive
[k
])
124 b
->nlive
[k
] = nlv
[k
];
133 fprintf(stderr
, "\n> Liveness analysis:\n");
134 for (b
=f
->start
; b
; b
=b
->link
) {
135 fprintf(stderr
, "\t%-10sin: ", b
->name
);
136 dumpts(b
->in
, f
->tmp
, stderr
);
137 fprintf(stderr
, "\t out: ");
138 dumpts(b
->out
, f
->tmp
, stderr
);
139 fprintf(stderr
, "\t gen: ");
140 dumpts(b
->gen
, f
->tmp
, stderr
);
141 fprintf(stderr
, "\t live: ");
142 fprintf(stderr
, "%d %d\n", b
->nlive
[0], b
->nlive
[1]);