Fix GCC build problem with 288f05f related to SmallVector. (#116958)
[llvm-project.git] / mlir / test / lib / Interfaces / LoopLikeInterface / TestBlockInLoop.cpp
blobd695195064a6a60fe98d65e3207258ce6452e251
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 //===----------------------------------------------------------------------===//
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"
15 using namespace mlir;
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>> {
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";
35 else
36 llvm::outs() << "not in a loop\n";
37 block->print(llvm::outs());
38 llvm::outs() << "\n";
39 });
43 } // namespace
45 namespace mlir {
46 void registerLoopLikeInterfaceTestPasses() { PassRegistration<IsInLoopPass>(); }
47 } // namespace mlir