Skip to content

Commit 717e1a1

Browse files
committed
Comment the eliminateDeadInstruction and related APIs.
When the underlying utility was changed for OSSA, it changed the semantics of the callback, which breaks the way I've always used a deletion callback to update iterators. /// \p callback is called on each deleted instruction before deleting any /// instructions. This way, the SIL is valid in the callback. However, the /// callback cannot be used to update instruction iterators since other /// instructions to be deleted remain in the instruction list.
1 parent db7ee5f commit 717e1a1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class InstructionDeleter {
8585

8686
/// If the instruction \p inst is dead, delete it immediately and record
8787
/// its operands so that they can be cleaned up later.
88+
///
89+
/// \p callback is called on each deleted instruction before deleting any
90+
/// instructions. This way, the SIL is valid in the callback. However, the
91+
/// callback cannot be used to update instruction iterators since other
92+
/// instructions to be deleted remain in the instruction list.
8893
void deleteIfDead(
8994
SILInstruction *inst,
9095
llvm::function_ref<void(SILInstruction *)> callback =
@@ -102,8 +107,10 @@ class InstructionDeleter {
102107
/// \pre the instruction to be deleted must not have any use other than
103108
/// incidental uses.
104109
///
105-
/// \param callback a callback called whenever an instruction
106-
/// is deleted.
110+
/// \p callback is called on each deleted instruction before deleting any
111+
/// instructions. This way, the SIL is valid in the callback. However, the
112+
/// callback cannot be used to update instruction iterators since other
113+
/// instructions to be deleted remain in the instruction list.
107114
void forceDeleteAndFixLifetimes(
108115
SILInstruction *inst,
109116
llvm::function_ref<void(SILInstruction *)> callback =
@@ -122,8 +129,10 @@ class InstructionDeleter {
122129
/// \pre the instruction to be deleted must not have any use other than
123130
/// incidental uses.
124131
///
125-
/// \param callback a callback called whenever an instruction
126-
/// is deleted.
132+
/// \p callback is called on each deleted instruction before deleting any
133+
/// instructions. This way, the SIL is valid in the callback. However, the
134+
/// callback cannot be used to update instruction iterators since other
135+
/// instructions to be deleted remain in the instruction list.
127136
void forceDelete(
128137
SILInstruction *inst,
129138
llvm::function_ref<void(SILInstruction *)> callback =
@@ -137,7 +146,10 @@ class InstructionDeleter {
137146
/// function body in an inconsistent state, it needs to be made consistent
138147
/// before this method is invoked.
139148
///
140-
/// \param callback a callback called whenever an instruction is deleted.
149+
/// \p callback is called on each deleted instruction before deleting any
150+
/// instructions. This way, the SIL is valid in the callback. However, the
151+
/// callback cannot be used to update instruction iterators since other
152+
/// instructions to be deleted remain in the instruction list.
141153
void
142154
cleanUpDeadInstructions(llvm::function_ref<void(SILInstruction *)> callback =
143155
[](SILInstruction *) {});
@@ -170,7 +182,10 @@ class InstructionDeleter {
170182
/// \pre the SIL function containing the instruction is assumed to be
171183
/// consistent, i.e., does not have under or over releases.
172184
///
173-
/// \param callback a callback called whenever an instruction is deleted.
185+
/// \p callback is called on each deleted instruction before deleting any
186+
/// instructions. This way, the SIL is valid in the callback. However, the
187+
/// callback cannot be used to update instruction iterators since other
188+
/// instructions to be deleted remain in the instruction list.
174189
void eliminateDeadInstruction(
175190
SILInstruction *inst, llvm::function_ref<void(SILInstruction *)> callback =
176191
[](SILInstruction *) {});

0 commit comments

Comments
 (0)