diff --git a/mlir/include/mlir/IR/StmtVisitor.h b/mlir/include/mlir/IR/StmtVisitor.h index c3a7b68b077a..73f17e35e1c1 100644 --- a/mlir/include/mlir/IR/StmtVisitor.h +++ b/mlir/include/mlir/IR/StmtVisitor.h @@ -179,7 +179,7 @@ public: } // Function to walk a statement in post order DFS. - void walkPostOrder(Statement *s) { + RetTy walkPostOrder(Statement *s) { static_assert(std::is_base_of::value, "Must pass the derived type to this template!"); diff --git a/mlir/lib/Transforms/LoopUnroll.cpp b/mlir/lib/Transforms/LoopUnroll.cpp index c631bda88602..489a98f8468b 100644 --- a/mlir/lib/Transforms/LoopUnroll.cpp +++ b/mlir/lib/Transforms/LoopUnroll.cpp @@ -52,9 +52,10 @@ void LoopUnroll::runOnMLFunction(MLFunction *f) { // This method specialized to encode custom return logic. typedef llvm::iplist StmtListType; - bool walk(StmtListType::iterator Start, StmtListType::iterator End) { + bool walkPostOrder(StmtListType::iterator Start, + StmtListType::iterator End) { while (Start != End) - if (walk(&(*Start++))) + if (walkPostOrder(&(*Start++))) return true; return false; } @@ -62,31 +63,31 @@ void LoopUnroll::runOnMLFunction(MLFunction *f) { // FIXME: can't use base class method for this because that in turn would // need to use the derived class method above. CRTP doesn't allow it, and // the compiler error resulting from it is also very misleading! - void walkMLFunction(MLFunction *f) { walk(f->begin(), f->end()); } + void walkPostOrder(MLFunction *f) { walkPostOrder(f->begin(), f->end()); } - bool walkForStmt(ForStmt *forStmt) { - bool hasInnerLoops = walk(forStmt->begin(), forStmt->end()); + bool walkForStmtPostOrder(ForStmt *forStmt) { + bool hasInnerLoops = walkPostOrder(forStmt->begin(), forStmt->end()); if (!hasInnerLoops) loops.push_back(forStmt); return true; } - bool walkIfStmt(IfStmt *ifStmt) { - if (walk(ifStmt->getThenClause()->begin(), - ifStmt->getThenClause()->end()) || - walk(ifStmt->getElseClause()->begin(), - ifStmt->getElseClause()->end())) + bool walkIfStmtPostOrder(IfStmt *ifStmt) { + if (walkPostOrder(ifStmt->getThenClause()->begin(), + ifStmt->getThenClause()->end()) || + walkPostOrder(ifStmt->getElseClause()->begin(), + ifStmt->getElseClause()->end())) return true; return false; } bool walkOpStmt(OperationStmt *opStmt) { return false; } - using StmtWalker::walk; + using StmtWalker::walkPostOrder; }; InnermostLoopGatherer ilg; - ilg.walkMLFunction(f); + ilg.walkPostOrder(f); auto &loops = ilg.loops; for (auto *forStmt : loops) runOnForStmt(forStmt);