@@ -188,7 +188,8 @@ class DCE : public SILFunctionTransform {
188
188
void computeMinPredecessorLevels (PostDomTreeNode *root);
189
189
void insertControllingInfo (SILBasicBlock *Block, unsigned Level);
190
190
191
- void markValueLive (SILNode *V);
191
+ void markValueLive (SILValue V);
192
+ void markInstructionLive (SILInstruction *Inst);
192
193
void markTerminatorArgsLive (SILBasicBlock *Pred, SILBasicBlock *Succ,
193
194
size_t ArgIndex);
194
195
void markControllingTerminatorsLive (SILBasicBlock *Block);
@@ -208,32 +209,30 @@ class DCE : public SILFunctionTransform {
208
209
209
210
// Keep track of the fact that V is live and add it to our worklist
210
211
// so that we can process the values it depends on.
211
- void DCE::markValueLive (SILNode *V) {
212
- V = V->getRepresentativeSILNodeInObject ();
213
- if (LiveValues.count (V) || isa<SILUndef>(V))
214
- return ;
215
-
216
- LLVM_DEBUG (llvm::dbgs () << " Marking as live:\n " );
217
- LLVM_DEBUG (V->dump ());
218
-
219
- LiveValues.insert (V);
212
+ void DCE::markValueLive (SILValue V) {
213
+ if (SILInstruction *inst = V->getDefiningInstruction ())
214
+ return markInstructionLive (inst);
220
215
221
- if (auto *Def = dyn_cast<SILInstruction>(V)) {
222
- markControllingTerminatorsLive (Def->getParent ());
223
- Worklist.push_back (Def);
216
+ if (!LiveValues.insert (V).second || isa<SILUndef>(V))
224
217
return ;
225
- }
226
-
227
- // TODO: MultiValueInstruction
228
218
229
- assert (isa<SILArgument>(V) &&
230
- " Only expected instructions and arguments!" );
219
+ LLVM_DEBUG (llvm::dbgs () << " Marking as live: " << *V);
231
220
232
221
auto *Arg = cast<SILArgument>(V);
233
222
markControllingTerminatorsLive (Arg->getParent ());
234
223
propagateLiveBlockArgument (Arg);
235
224
}
236
225
226
+ void DCE::markInstructionLive (SILInstruction *Inst) {
227
+ if (!LiveValues.insert (Inst).second )
228
+ return ;
229
+
230
+ LLVM_DEBUG (llvm::dbgs () << " Marking as live: " << *Inst);
231
+
232
+ markControllingTerminatorsLive (Inst->getParent ());
233
+ Worklist.push_back (Inst);
234
+ }
235
+
237
236
// / Gets the producing instruction of a cond_fail condition. Currently these
238
237
// / are overflow builtins but may be extended to other instructions in the
239
238
// / future.
@@ -263,7 +262,7 @@ void DCE::markLive(SILFunction &F) {
263
262
if (auto *Prod = getProducer (cast<CondFailInst>(&I))) {
264
263
addReverseDependency (Prod, &I);
265
264
} else {
266
- markValueLive (&I);
265
+ markInstructionLive (&I);
267
266
}
268
267
break ;
269
268
}
@@ -272,7 +271,7 @@ void DCE::markLive(SILFunction &F) {
272
271
if (!Op->getType ().isAddress ()) {
273
272
addReverseDependency (Op, &I);
274
273
} else {
275
- markValueLive (&I);
274
+ markInstructionLive (&I);
276
275
}
277
276
break ;
278
277
}
@@ -290,7 +289,7 @@ void DCE::markLive(SILFunction &F) {
290
289
}
291
290
default :
292
291
if (seemsUseful (&I))
293
- markValueLive (&I);
292
+ markInstructionLive (&I);
294
293
}
295
294
}
296
295
}
@@ -319,7 +318,7 @@ void DCE::markTerminatorArgsLive(SILBasicBlock *Pred,
319
318
320
319
// If the arguments are live, we need to keep the terminator that
321
320
// delivers those arguments.
322
- markValueLive (Term);
321
+ markInstructionLive (Term);
323
322
324
323
switch (Term->getTermKind ()) {
325
324
case TermKind::ReturnInst:
@@ -380,11 +379,11 @@ void DCE::propagateLiveBlockArgument(SILArgument *Arg) {
380
379
// is in reverse direction: Only if its definition (the Arg) is alive, also
381
380
// the debug_value instruction is alive.
382
381
for (Operand *DU : getDebugUses (Arg))
383
- markValueLive (DU->getUser ());
382
+ markInstructionLive (DU->getUser ());
384
383
385
384
// Mark all reverse dependencies on the Arg live
386
385
for (auto *depInst : ReverseDependencies.lookup (Arg)) {
387
- markValueLive (depInst);
386
+ markInstructionLive (depInst);
388
387
}
389
388
390
389
auto *Block = Arg->getParent ();
@@ -406,14 +405,14 @@ void DCE::propagateLiveness(SILInstruction *I) {
406
405
// debug_value instruction is alive.
407
406
for (auto result : I->getResults ())
408
407
for (Operand *DU : getDebugUses (result))
409
- markValueLive (DU->getUser ());
408
+ markInstructionLive (DU->getUser ());
410
409
411
410
// Handle all other reverse-dependency instructions, like cond_fail,
412
411
// fix_lifetime, destroy_value, etc. Only if the definition is alive, the
413
412
// user itself is alive.
414
413
for (auto res : I->getResults ()) {
415
414
for (auto *depInst : ReverseDependencies.lookup (res)) {
416
- markValueLive (depInst);
415
+ markInstructionLive (depInst);
417
416
}
418
417
}
419
418
return ;
@@ -802,7 +801,7 @@ void DCE::markControllingTerminatorsLive(SILBasicBlock *Block) {
802
801
collectControllingBlocks (Block, ControllingBlocks);
803
802
804
803
for (auto BB : ControllingBlocks)
805
- markValueLive (BB->getTerminator ());
804
+ markInstructionLive (BB->getTerminator ());
806
805
}
807
806
808
807
} // end anonymous namespace
0 commit comments