@@ -127,20 +127,18 @@ class MandatoryCombiner final
127
127
// ===----------------------------------------------------------------------===//
128
128
129
129
void MandatoryCombiner::addReachableCodeToWorklist (SILFunction &function) {
130
- SmallBlotSetVector<SILBasicBlock *, 32 > blockWorklist;
131
- SmallBlotSetVector<SILBasicBlock *, 32 > blocksVisited;
132
- SmallVector<SILInstruction *, 128 > instructions;
130
+ SmallVector<SILBasicBlock *, 32 > blockWorklist;
131
+ SmallPtrSet<SILBasicBlock *, 32 > blockAlreadyAddedToWorklist;
132
+ SmallVector<SILInstruction *, 128 > initialInstructionWorklist;
133
+
134
+ {
135
+ auto *firstBlock = &*function.begin ();
136
+ blockWorklist.push_back (firstBlock);
137
+ blockAlreadyAddedToWorklist.insert (firstBlock);
138
+ }
133
139
134
- blockWorklist.insert (&*function.begin ());
135
140
while (!blockWorklist.empty ()) {
136
- auto *block = blockWorklist.pop_back_val ().getValueOr (nullptr );
137
- if (block == nullptr ) {
138
- continue ;
139
- }
140
-
141
- if (!blocksVisited.insert (block).second ) {
142
- continue ;
143
- }
141
+ auto *block = blockWorklist.pop_back_val ();
144
142
145
143
for (auto iterator = block->begin (), end = block->end (); iterator != end;) {
146
144
auto *instruction = &*iterator;
@@ -150,14 +148,17 @@ void MandatoryCombiner::addReachableCodeToWorklist(SILFunction &function) {
150
148
continue ;
151
149
}
152
150
153
- instructions .push_back (instruction);
151
+ initialInstructionWorklist .push_back (instruction);
154
152
}
155
153
156
- for_each (block->getSuccessorBlocks (),
157
- [&](SILBasicBlock *block) { blockWorklist.insert (block); });
154
+ llvm::copy_if (block->getSuccessorBlocks (),
155
+ std::back_inserter (blockWorklist),
156
+ [&](SILBasicBlock *block) -> bool {
157
+ return blockAlreadyAddedToWorklist.insert (block).second ;
158
+ });
158
159
}
159
160
160
- worklist.addInitialGroup (instructions );
161
+ worklist.addInitialGroup (initialInstructionWorklist );
161
162
}
162
163
163
164
bool MandatoryCombiner::doOneIteration (SILFunction &function,
@@ -282,6 +283,12 @@ class MandatoryCombine final : public SILFunctionTransform {
282
283
void run () override {
283
284
auto *function = getFunction ();
284
285
286
+ // If this function is an external declaration, bail. We only want to visit
287
+ // functions with bodies.
288
+ if (function->isExternalDeclaration ()) {
289
+ return ;
290
+ }
291
+
285
292
MandatoryCombiner combiner (createdInstructions);
286
293
bool madeChange = combiner.runOnFunction (*function);
287
294
0 commit comments