@@ -128,6 +128,30 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
128
128
}
129
129
}
130
130
131
+ // / All operands of \p instruction to the worklist when performing 2 stage
132
+ // / instruction deletion. Meant to be used right before deleting an
133
+ // / instruction in callbacks like InstModCallback::onNotifyWillBeDeleted().
134
+ void addOperandsToWorklist (SILInstruction &instruction) {
135
+ assert (!instruction.hasUsesOfAnyResult () &&
136
+ " Cannot erase instruction that is used!" );
137
+
138
+ // Make sure that we reprocess all operands now that we reduced their
139
+ // use counts.
140
+ if (instruction.getNumOperands () < 8 ) {
141
+ for (auto &operand : instruction.getAllOperands ()) {
142
+ if (auto *operandInstruction =
143
+ operand.get ()->getDefiningInstruction ()) {
144
+ withDebugStream ([&](llvm::raw_ostream &stream,
145
+ StringRef loggingName) {
146
+ stream << loggingName << " : add op " << *operandInstruction << ' \n '
147
+ << " from erased inst to worklist\n " ;
148
+ });
149
+ add (operandInstruction);
150
+ }
151
+ }
152
+ }
153
+ }
154
+
131
155
// / When an instruction has been simplified, add all of its users to the
132
156
// / worklist, since additional simplifications of its users may have been
133
157
// / exposed.
@@ -296,29 +320,15 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
296
320
}
297
321
298
322
void eraseSingleInstFromFunction (SILInstruction &instruction,
299
- bool addOperandsToWorklist ) {
323
+ bool shouldAddOperandsToWorklist ) {
300
324
withDebugStream ([&](llvm::raw_ostream &stream, StringRef loggingName) {
301
325
stream << loggingName << " : ERASE " << instruction << ' \n ' ;
302
326
});
303
327
304
- assert (!instruction.hasUsesOfAnyResult () &&
305
- " Cannot erase instruction that is used!" );
328
+ // If we are asked to add operands to the worklist, do so now.
329
+ if (shouldAddOperandsToWorklist)
330
+ addOperandsToWorklist (instruction);
306
331
307
- // Make sure that we reprocess all operands now that we reduced their
308
- // use counts.
309
- if (instruction.getNumOperands () < 8 && addOperandsToWorklist) {
310
- for (auto &operand : instruction.getAllOperands ()) {
311
- if (auto *operandInstruction =
312
- operand.get ()->getDefiningInstruction ()) {
313
- withDebugStream ([&](llvm::raw_ostream &stream,
314
- StringRef loggingName) {
315
- stream << loggingName << " : add op " << *operandInstruction << ' \n '
316
- << " from erased inst to worklist\n " ;
317
- });
318
- add (operandInstruction);
319
- }
320
- }
321
- }
322
332
erase (&instruction);
323
333
instruction.eraseFromParent ();
324
334
}
0 commit comments