@@ -168,14 +168,22 @@ class SsaLiveIntervalBuilder extends HBaseVisitor with CodegenPhase {
168
168
int instructionId = 0 ;
169
169
170
170
/// The liveIns of basic blocks.
171
- final Map <HBasicBlock , LiveEnvironment > liveInstructions;
171
+ final Map <HBasicBlock , LiveEnvironment > liveInstructions = {} ;
172
172
173
173
/// The live intervals of instructions.
174
- final Map <HInstruction , LiveInterval > liveIntervals;
174
+ final Map <HInstruction , LiveInterval > liveIntervals = {};
175
+
176
+ /// Controlling conditions for control-flow operators. Control-flow operators,
177
+ /// e.g. `c ? a : b` , have a condition input `c` from the HIf node
178
+ /// at the top of the control flow diamond as well as the HPhi inputs for `a`
179
+ /// and `b` at the bottom of the diamond.
180
+ final Map <HInstruction , HInstruction > _phiToCondition = {};
175
181
176
- SsaLiveIntervalBuilder (this .generateAtUseSite, this .controlFlowOperators)
177
- : liveInstructions = new Map <HBasicBlock , LiveEnvironment >(),
178
- liveIntervals = new Map <HInstruction , LiveInterval >();
182
+ SsaLiveIntervalBuilder (this .generateAtUseSite, this .controlFlowOperators) {
183
+ for (HIf ifNode in controlFlowOperators) {
184
+ _phiToCondition[ifNode.joinBlock.phis.first] = ifNode.condition;
185
+ }
186
+ }
179
187
180
188
@override
181
189
void visitGraph (HGraph graph) {
@@ -187,6 +195,12 @@ class SsaLiveIntervalBuilder extends HBaseVisitor with CodegenPhase {
187
195
188
196
void markInputsAsLiveInEnvironment (
189
197
HInstruction instruction, LiveEnvironment environment) {
198
+ if (instruction is HPhi ) {
199
+ HInstruction condition = _phiToCondition[instruction];
200
+ if (condition != null ) {
201
+ markAsLiveInEnvironment (condition, environment);
202
+ }
203
+ }
190
204
for (int i = 0 , len = instruction.inputs.length; i < len; i++ ) {
191
205
markAsLiveInEnvironment (instruction.inputs[i], environment);
192
206
}
@@ -257,21 +271,7 @@ class SsaLiveIntervalBuilder extends HBaseVisitor with CodegenPhase {
257
271
258
272
@override
259
273
void visitBasicBlock (HBasicBlock block) {
260
- LiveEnvironment environment =
261
- new LiveEnvironment (liveIntervals, instructionId);
262
-
263
- // If the control flow instruction in this block will actually be
264
- // inlined in the codegen in the join block, we need to make
265
- // whatever is used by that control flow instruction as live in
266
- // the join block.
267
- if (controlFlowOperators.contains (block.last)) {
268
- HIf ifInstruction = block.last;
269
- HBasicBlock joinBlock = ifInstruction.joinBlock;
270
- if (generateAtUseSite.contains (joinBlock.phis.first)) {
271
- markInputsAsLiveInEnvironment (
272
- ifInstruction, liveInstructions[joinBlock]);
273
- }
274
- }
274
+ LiveEnvironment environment = LiveEnvironment (liveIntervals, instructionId);
275
275
276
276
// Add to the environment the liveIn of its successor, as well as
277
277
// the inputs of the phis of the successor that flow from this block.
0 commit comments