brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · d695195 Raw
48 lines · cpp
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-exception6//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 15using namespace mlir;16 17namespace {18/// This is a test pass that tests Blocks's isInLoop method by checking if each19/// block in a function is in a loop and outputing if it is20struct IsInLoopPass21    : public PassWrapper<IsInLoopPass, OperationPass<func::FuncOp>> {22  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(IsInLoopPass)23 24  StringRef getArgument() const final { return "test-block-is-in-loop"; }25  StringRef getDescription() const final {26    return "Test mlir::blockIsInLoop()";27  }28 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      else36        llvm::outs() << "not in a loop\n";37      block->print(llvm::outs());38      llvm::outs() << "\n";39    });40  }41};42 43} // namespace44 45namespace mlir {46void registerLoopLikeInterfaceTestPasses() { PassRegistration<IsInLoopPass>(); }47} // namespace mlir48