Skip to content

Commit b9599af

Browse files
authored
Merge pull request swiftlang#27062 from nate-chandler/instruction-worklist-style-followon
2 parents 568f615 + 20ee77f commit b9599af

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

include/swift/SIL/SILInstructionWorklist.h

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class SILInstructionWorklistBase {
4545
protected:
4646
SILInstructionWorklistBase(const char *loggingName)
4747
: loggingName(loggingName){};
48+
// Invokes the provided function with the debug stream and the previously
49+
// specified logging name.
50+
//
51+
// Note: Because it contains LLVM_DEBUG, the definition is in the .cpp file.
52+
// Consequently, we are relying on LTO to ensure that the calls are
53+
// inlined and removed in non-assert builds.
4854
void withDebugStream(
4955
std::function<void(llvm::raw_ostream &stream, const char *loggingName)>
5056
perform);
@@ -150,27 +156,7 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
150156
std::string instructionDescription
151157
#endif
152158
) {
153-
if (result != instruction) {
154-
assert(&*std::prev(instruction->getIterator()) == result &&
155-
"Expected new instruction inserted before existing instruction!");
156-
157-
withDebugStream([&](llvm::raw_ostream &stream, StringRef loggingName) {
158-
stream << loggingName << ": Old = " << *instruction << '\n'
159-
<< " "
160-
<< " New = " << *result << '\n';
161-
});
162-
163-
// Everything uses the new instruction now.
164-
replaceInstUsesPairwiseWith(instruction, result);
165-
166-
// Push the new instruction and any users onto the worklist.
167-
add(result);
168-
addUsersOfAllResultsToWorklist(result);
169-
170-
eraseInstFromFunction(*instruction);
171-
172-
return true;
173-
} else {
159+
if (result == instruction) {
174160
withDebugStream([&](llvm::raw_ostream &stream, StringRef loggingName) {
175161
stream << loggingName << ": Mod = " << instructionDescription << '\n'
176162
<< " "
@@ -187,6 +173,26 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
187173
}
188174
return false;
189175
}
176+
177+
assert(&*std::prev(instruction->getIterator()) == result &&
178+
"Expected new instruction inserted before existing instruction!");
179+
180+
withDebugStream([&](llvm::raw_ostream &stream, StringRef loggingName) {
181+
stream << loggingName << ": Old = " << *instruction << '\n'
182+
<< " "
183+
<< " New = " << *result << '\n';
184+
});
185+
186+
// Everything uses the new instruction now.
187+
replaceInstUsesPairwiseWith(instruction, result);
188+
189+
// Push the new instruction and any users onto the worklist.
190+
add(result);
191+
addUsersOfAllResultsToWorklist(result);
192+
193+
eraseInstFromFunction(*instruction);
194+
195+
return true;
190196
}
191197

192198
// Insert the instruction newInstruction before instruction old in old's

0 commit comments

Comments
 (0)