#include "mlir/Analysis/CFGLoopInfo.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
namespace {
struct TestCFGLoopInfo
: public PassWrapper<TestCFGLoopInfo, InterfacePass<FunctionOpInterface>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCFGLoopInfo)
StringRef getArgument() const final { return "test-cfg-loop-info"; }
StringRef getDescription() const final {
return "Test the loop info analysis.";
}
void runOnOperation() override;
};
}
void TestCFGLoopInfo::runOnOperation() {
auto func = getOperation();
DominanceInfo &domInfo = getAnalysis<DominanceInfo>();
Region ®ion = func.getFunctionBody();
llvm::errs() << "Testing : " << func.getNameAttr() << "\n";
if (region.empty()) {
llvm::errs() << "empty region\n";
return;
}
llvm::errs() << "Blocks : ";
region.front().printAsOperand(llvm::errs());
for (auto &block : region.getBlocks()) {
llvm::errs() << ", ";
block.printAsOperand(llvm::errs());
}
llvm::errs() << "\n";
if (region.getBlocks().size() == 1) {
llvm::errs() << "no loops\n";
return;
}
llvm::DominatorTreeBase<mlir::Block, false> &domTree =
domInfo.getDomTree(®ion);
mlir::CFGLoopInfo loopInfo(domTree);
if (loopInfo.getTopLevelLoops().empty())
llvm::errs() << "no loops\n";
else
loopInfo.print(llvm::errs());
}
namespace mlir {
namespace test {
void registerTestCFGLoopInfoPass() { PassRegistration<TestCFGLoopInfo>(); }
}
}