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 
14 #include "PassDetails.h"
17 #include "circt/Support/LLVM.h"
18 #include "mlir/IR/BuiltinTypes.h"
19 #include "mlir/IR/OperationSupport.h"
20 #include "mlir/Transforms/DialectConversion.h"
21 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22 
23 using namespace circt;
24 using namespace calyx;
25 using namespace mlir;
26 
27 namespace {
28 
29 struct GroupInvariantCodeMotionPass
30  : public GroupInvariantCodeMotionBase<GroupInvariantCodeMotionPass> {
31  void runOnOperation() override {
32  auto wires = getOperation().getWiresOp();
33  for (auto groupOp : wires.getOps<GroupOp>()) {
34  for (auto &op : llvm::make_early_inc_range(groupOp.getOps())) {
35  if (isa<GroupDoneOp, AssignOp, GroupGoOp>(op))
36  continue;
37  op.moveBefore(wires.getBodyBlock(), wires.getBodyBlock()->begin());
38  }
39  }
40  }
41 };
42 
43 } // end anonymous namespace
44 
45 std::unique_ptr<mlir::Pass> circt::calyx::createGroupInvariantCodeMotionPass() {
46  return std::make_unique<GroupInvariantCodeMotionPass>();
47 }
std::unique_ptr< mlir::Pass > createGroupInvariantCodeMotionPass()
Definition: GICM.cpp:45
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21