Fix GCC build problem with 288f05f related to SmallVector. (#116958)
[llvm-project.git] / mlir / test / lib / IR / TestRegions.cpp
blobe850691631be2f97973460871ac9ad8a69396ac4
1 //===- TestRegions.cpp - Pass to test Region's methods --------------------===//
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 "TestDialect.h"
10 #include "mlir/Dialect/Func/IR/FuncOps.h"
11 #include "mlir/IR/BuiltinOps.h"
12 #include "mlir/Pass/Pass.h"
14 using namespace mlir;
16 namespace {
17 /// This is a test pass that tests Region's takeBody method by making the first
18 /// function take the body of the second.
19 struct TakeBodyPass
20 : public PassWrapper<TakeBodyPass, OperationPass<ModuleOp>> {
21 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TakeBodyPass)
23 StringRef getArgument() const final { return "test-take-body"; }
24 StringRef getDescription() const final { return "Test Region's takeBody"; }
26 void runOnOperation() override {
27 auto module = getOperation();
29 SmallVector<func::FuncOp> functions =
30 llvm::to_vector(module.getOps<func::FuncOp>());
31 if (functions.size() != 2) {
32 module.emitError("Expected only two functions in test");
33 signalPassFailure();
34 return;
37 functions[0].getBody().takeBody(functions[1].getBody());
41 } // namespace
43 namespace mlir {
44 void registerRegionTestPasses() { PassRegistration<TakeBodyPass>(); }
45 } // namespace mlir