1 //===- TestBlockInLoop.cpp - Pass to test mlir::blockIsInLoop -------------===//
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
7 //===----------------------------------------------------------------------===//
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"
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
21 : public PassWrapper
<IsInLoopPass
, OperationPass
<func::FuncOp
>> {
22 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(IsInLoopPass
)
24 StringRef
getArgument() const final
{ return "test-block-is-in-loop"; }
25 StringRef
getDescription() const final
{
26 return "Test mlir::blockIsInLoop()";
29 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";
36 llvm::outs() << "not in a loop\n";
37 block
->print(llvm::outs());
46 void registerLoopLikeInterfaceTestPasses() { PassRegistration
<IsInLoopPass
>(); }