#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Pass/Pass.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
namespace {
struct IsInLoopPass
: public PassWrapper<IsInLoopPass, OperationPass<func::FuncOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(IsInLoopPass)
StringRef getArgument() const final { return "test-block-is-in-loop"; }
StringRef getDescription() const final {
return "Test mlir::blockIsInLoop()";
}
void runOnOperation() override {
mlir::func::FuncOp func = getOperation();
func.walk([](mlir::Block *block) {
llvm::outs() << "Block is ";
if (LoopLikeOpInterface::blockIsInLoop(block))
llvm::outs() << "in a loop\n";
else
llvm::outs() << "not in a loop\n";
block->print(llvm::outs());
llvm::outs() << "\n";
});
}
};
}
namespace mlir {
void registerLoopLikeInterfaceTestPasses() { PassRegistration<IsInLoopPass>(); }
}