Functions are always callable operations and thus every operation implementing the `FunctionOpInterface` also implements the `CallableOpInterface`. The only exception was the FuncOp in the toy example. To make implementation of the `FunctionOpInterface` easier, this commit lets `FunctionOpInterface` inherit from `CallableOpInterface` and merges some of their methods. More precisely, the `CallableOpInterface` has methods to get the argument and result attributes and a method to get the result types of the callable region. These methods are always implemented the same way as their analogues in `FunctionOpInterface` and thus this commit moves all the argument and result attribute handling methods to the callable interface as well as the methods to get the argument and result types. The `FuntionOpInterface` then does not have to declare them as well, but just inherits them from the `CallableOpInterface`. Adding the inheritance relation also required to move the `FunctionOpInterface` from the IR directory to the Interfaces directory since IR should not depend on Interfaces. Reviewed By: jpienaar, springerm Differential Revision: https://reviews.llvm.org/D157988
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
//===- TestCFGLoopInfo.cpp - Test CFG loop info analysis ------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements logic for testing the CFGLoopInfo analysis.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Analysis/CFGLoopInfo.h"
|
|
#include "mlir/Interfaces/FunctionInterfaces.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace {
|
|
/// A testing pass that applies the CFGLoopInfo analysis on a region and prints
|
|
/// the information it collected to llvm::errs().
|
|
struct TestCFGLoopInfo
|
|
: public PassWrapper<TestCFGLoopInfo, InterfacePass<FunctionOpInterface>> {
|
|
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCFGLoopInfo)
|
|
|
|
StringRef getArgument() const final { return "test-cfg-loop-info"; }
|
|
StringRef getDescription() const final {
|
|
return "Test the loop info analysis.";
|
|
}
|
|
|
|
void runOnOperation() override;
|
|
};
|
|
} // namespace
|
|
|
|
void TestCFGLoopInfo::runOnOperation() {
|
|
auto func = getOperation();
|
|
DominanceInfo &domInfo = getAnalysis<DominanceInfo>();
|
|
Region ®ion = func.getFunctionBody();
|
|
|
|
// Prints the label of the test.
|
|
llvm::errs() << "Testing : " << func.getNameAttr() << "\n";
|
|
if (region.empty()) {
|
|
llvm::errs() << "empty region\n";
|
|
return;
|
|
}
|
|
|
|
// Print all the block identifiers first such that the tests can match them.
|
|
llvm::errs() << "Blocks : ";
|
|
region.front().printAsOperand(llvm::errs());
|
|
for (auto &block : region.getBlocks()) {
|
|
llvm::errs() << ", ";
|
|
block.printAsOperand(llvm::errs());
|
|
}
|
|
llvm::errs() << "\n";
|
|
|
|
if (region.getBlocks().size() == 1) {
|
|
llvm::errs() << "no loops\n";
|
|
return;
|
|
}
|
|
|
|
llvm::DominatorTreeBase<mlir::Block, false> &domTree =
|
|
domInfo.getDomTree(®ion);
|
|
mlir::CFGLoopInfo loopInfo(domTree);
|
|
|
|
if (loopInfo.getTopLevelLoops().empty())
|
|
llvm::errs() << "no loops\n";
|
|
else
|
|
loopInfo.print(llvm::errs());
|
|
}
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
void registerTestCFGLoopInfoPass() { PassRegistration<TestCFGLoopInfo>(); }
|
|
} // namespace test
|
|
} // namespace mlir
|