Skip to content

Commit 0097628

Browse files
committed
[SSADestroyHoisting] Used iterative dataflow.
Previously, SSADestroyHoisting used two pessimistic BackwardReachability dataflows. Here, it is made to use IterativeBackwardReachability including a call to the optionally-used method solvePessimistic to do a pessimistic dataflow (to find barrier access scopes) and an optimistic dataflow (to find all barriers).
1 parent 90fb61c commit 0097628

File tree

7 files changed

+3278
-214
lines changed

7 files changed

+3278
-214
lines changed

include/swift/SIL/CFG.h

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,64 @@ class SILCfgTraits : public CfgTraits<SILCfgTraitsBase, SILCfgTraits> {
217217
template <> struct CfgTraitsFor<swift::SILBasicBlock> {
218218
using CfgTraits = SILCfgTraits;
219219
};
220-
221220
#endif
222221

223222
} // end llvm namespace
224223

224+
#include "swift/SIL/BasicBlockDatastructures.h"
225+
226+
namespace swift {
227+
// interface Visitor {
228+
// bool isInRegion(SILBasicBlock *)
229+
// void visit(SILBasicBlock *)
230+
// }
231+
template <typename Visitor>
232+
void visitPostOrderBackwards(SILFunction *function, SILBasicBlock *root,
233+
Visitor visitor) {
234+
SmallVector<std::pair<SILBasicBlock *, SILBasicBlock::pred_iterator>, 32>
235+
stack;
236+
BasicBlockSet visited(function);
237+
stack.push_back({root, root->pred_begin()});
238+
while (!stack.empty()) {
239+
while (stack.back().second != stack.back().first->pred_end()) {
240+
auto predecessor = *stack.back().second;
241+
stack.back().second++;
242+
if (!visitor.isInRegion(predecessor))
243+
continue;
244+
if (visited.insert(predecessor))
245+
stack.push_back({predecessor, predecessor->pred_begin()});
246+
}
247+
visitor.visit(stack.back().first);
248+
stack.pop_back();
249+
}
250+
}
251+
252+
// interface Visitor {
253+
// bool isInRegion(SILBasicBlock *)
254+
// void visit(SILBasicBlock *)
255+
// }
256+
template <typename Visitor>
257+
void visitSortedTopologicallyBackwards(SILFunction *function,
258+
ArrayRef<SILBasicBlock *> roots,
259+
Visitor &visitor) {
260+
BasicBlockSet visited(function);
261+
for (auto *root : roots) {
262+
struct Inner {
263+
Visitor &outer;
264+
BasicBlockSet &visited;
265+
int offset = 0;
266+
Inner(Visitor &outer, BasicBlockSet &visited)
267+
: outer(outer), visited(visited) {}
268+
bool isInRegion(SILBasicBlock *block) {
269+
return !visited.contains(block) && outer.isInRegion(block);
270+
}
271+
void visit(SILBasicBlock *block) { outer.visit(block); }
272+
};
273+
Inner inner(visitor, visited);
274+
visitPostOrderBackwards(function, root, inner);
275+
}
276+
}
277+
} // namespace swift
278+
225279
#endif
226280

0 commit comments

Comments
 (0)