@@ -45,6 +45,12 @@ class SILInstructionWorklistBase {
45
45
protected:
46
46
SILInstructionWorklistBase (const char *loggingName)
47
47
: 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.
48
54
void withDebugStream (
49
55
std::function<void (llvm::raw_ostream &stream, const char *loggingName)>
50
56
perform);
@@ -150,27 +156,7 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
150
156
std::string instructionDescription
151
157
#endif
152
158
) {
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) {
174
160
withDebugStream ([&](llvm::raw_ostream &stream, StringRef loggingName) {
175
161
stream << loggingName << " : Mod = " << instructionDescription << ' \n '
176
162
<< " "
@@ -187,6 +173,26 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
187
173
}
188
174
return false ;
189
175
}
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 ;
190
196
}
191
197
192
198
// Insert the instruction newInstruction before instruction old in old's
0 commit comments