1 //===- TestBlockInLoop.cpp - Pass to test mlir::blockIsInLoop -------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "mlir/Dialect/Func/IR/FuncOps.h" 10 #include "mlir/IR/BuiltinOps.h" 11 #include "mlir/Interfaces/LoopLikeInterface.h" 12 #include "mlir/Pass/Pass.h" 13 #include "llvm/Support/raw_ostream.h" 14 15 using namespace mlir; 16 17 namespace { 18 /// This is a test pass that tests Blocks's isInLoop method by checking if each 19 /// block in a function is in a loop and outputing if it is 20 struct IsInLoopPass 21 : public PassWrapper<IsInLoopPass, OperationPass<func::FuncOp>> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID__anonae2c3e990111::IsInLoopPass22 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(IsInLoopPass) 23 24 StringRef getArgument() const final { return "test-block-is-in-loop"; } getDescription__anonae2c3e990111::IsInLoopPass25 StringRef getDescription() const final { 26 return "Test mlir::blockIsInLoop()"; 27 } 28 runOnOperation__anonae2c3e990111::IsInLoopPass29 void runOnOperation() override { 30 mlir::func::FuncOp func = getOperation(); 31 func.walk([](mlir::Block *block) { 32 llvm::outs() << "Block is "; 33 if (LoopLikeOpInterface::blockIsInLoop(block)) 34 llvm::outs() << "in a loop\n"; 35 else 36 llvm::outs() << "not in a loop\n"; 37 block->print(llvm::outs()); 38 llvm::outs() << "\n"; 39 }); 40 } 41 }; 42 43 } // namespace 44 45 namespace mlir { registerLoopLikeInterfaceTestPasses()46void registerLoopLikeInterfaceTestPasses() { PassRegistration<IsInLoopPass>(); } 47 } // namespace mlir 48