CIRCT  19.0.0git
GICM.cpp
Go to the documentation of this file.
1 //===- GICM.cpp - Group-invariant code motion pass --------------*- C++ -*-===//
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 // This pass performs GICM (group-invariant code motion) of operations which are
10 // deemed to be invariant of the group in which they are placed.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "circt/Support/LLVM.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/OperationSupport.h"
19 #include "mlir/Transforms/DialectConversion.h"
20 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21 
22 namespace circt {
23 namespace calyx {
24 #define GEN_PASS_DEF_GROUPINVARIANTCODEMOTION
25 #include "circt/Dialect/Calyx/CalyxPasses.h.inc"
26 } // namespace calyx
27 } // namespace circt
28 
29 using namespace circt;
30 using namespace calyx;
31 using namespace mlir;
32 
33 namespace {
34 
35 struct GroupInvariantCodeMotionPass
36  : public circt::calyx::impl::GroupInvariantCodeMotionBase<
37  GroupInvariantCodeMotionPass> {
38  void runOnOperation() override {
39  auto wires = getOperation().getWiresOp();
40  for (auto groupOp : wires.getOps<GroupOp>()) {
41  for (auto &op : llvm::make_early_inc_range(groupOp.getOps())) {
42  if (isa<GroupDoneOp, AssignOp, GroupGoOp>(op))
43  continue;
44  op.moveBefore(wires.getBodyBlock(), wires.getBodyBlock()->begin());
45  }
46  }
47  }
48 };
49 
50 } // end anonymous namespace
51 
52 std::unique_ptr<mlir::Pass> circt::calyx::createGroupInvariantCodeMotionPass() {
53  return std::make_unique<GroupInvariantCodeMotionPass>();
54 }
std::unique_ptr< mlir::Pass > createGroupInvariantCodeMotionPass()
Definition: GICM.cpp:52
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21