CIRCT  19.0.0git
FunctionEliminationPass.cpp
Go to the documentation of this file.
1 //===- FunctionEliminationPass.cpp - Implement Function Elimination Pass --===//
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 //===----------------------------------------------------------------------===//
8 //
9 // Implement pass to check that all functions got inlined and delete them.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "PassDetails.h"
16 #include "mlir/Dialect/Func/IR/FuncOps.h"
17 #include "mlir/IR/Visitors.h"
18 
19 using namespace circt;
20 
21 namespace {
22 
23 struct FunctionEliminationPass
24  : public llhd::FunctionEliminationBase<FunctionEliminationPass> {
25  void runOnOperation() override;
26 };
27 
28 void FunctionEliminationPass::runOnOperation() {
29  ModuleOp module = getOperation();
30 
31  WalkResult result = module.walk([](mlir::func::CallOp op) -> WalkResult {
32  if (isa<llhd::ProcOp>(op->getParentOp()) ||
33  isa<llhd::EntityOp>(op->getParentOp())) {
34  return emitError(
35  op.getLoc(),
36  "Not all functions are inlined, there is at least "
37  "one function call left within a llhd.proc or llhd.entity.");
38  }
39  return WalkResult::advance();
40  });
41 
42  if (result.wasInterrupted()) {
43  signalPassFailure();
44  return;
45  }
46 
47  module.walk([](mlir::func::FuncOp op) { op.erase(); });
48 }
49 } // namespace
50 
51 std::unique_ptr<OperationPass<ModuleOp>>
53  return std::make_unique<FunctionEliminationPass>();
54 }
std::unique_ptr< OperationPass< ModuleOp > > createFunctionEliminationPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21