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