Stmt visitors and walkers.
- Update InnermostLoopGatherer to use a post order traversal (linear
time/single traversal).
- Drop getNumNestedLoops().
- Update isInnermost() to use the StmtWalker.
When using return values in conjunction with walkers, the StmtWalker CRTP
pattern doesn't appear to be of any use. It just requires overriding nearly all
of the methods, which is what InnermostLoopGatherer currently does. Please see
FIXME/ENLIGHTENME comments. TODO: figure this out from this CL discussion.
Note
- Comments on visitor/walker base class are out of date; will update when this
CL is finalized.
PiperOrigin-RevId: 206340901
diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp
index e598f2a..60beeca 100644
--- a/lib/IR/Function.cpp
+++ b/lib/IR/Function.cpp
@@ -121,9 +121,9 @@
: Function(name, type, Kind::MLFunc), StmtBlock(StmtBlockKind::MLFunc) {}
MLFunction::~MLFunction() {
- struct DropReferencesPass : public StmtVisitor<DropReferencesPass> {
+ struct DropReferencesPass : public StmtWalker<DropReferencesPass> {
void visitOperationStmt(OperationStmt *stmt) { stmt->dropAllReferences(); }
};
DropReferencesPass pass;
- pass.visit(this);
+ pass.walk(const_cast<MLFunction *>(this));
}