CIRCT  19.0.0git
LayerSink.cpp
Go to the documentation of this file.
1 //===- LayerSink.cpp - Sink ops into layer blocks -------------------------===//
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 file sinks operations into layer blocks.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "PassDetails.h"
14 
15 #include "circt/Support/Debug.h"
16 #include "mlir/IR/Dominance.h"
17 #include "mlir/Interfaces/ControlFlowInterfaces.h"
18 #include "mlir/Interfaces/SideEffectInterfaces.h"
19 #include "mlir/Transforms/ControlFlowSinkUtils.h"
20 
21 #define DEBUG_TYPE "firrtl-layer-sink"
22 
23 using namespace circt;
24 using namespace firrtl;
25 
26 namespace {
27 /// A control-flow sink pass.
28 struct LayerSink : public LayerSinkBase<LayerSink> {
29  void runOnOperation() override;
30 };
31 } // end anonymous namespace
32 
33 void LayerSink::runOnOperation() {
34  LLVM_DEBUG(debugPassHeader(this)
35  << "\n"
36  << "Module: '" << getOperation().getName() << "'\n";);
37  auto &domInfo = getAnalysis<mlir::DominanceInfo>();
38  getOperation()->walk([&](LayerBlockOp layerBlock) {
39  SmallVector<Region *> regionsToSink({&layerBlock.getRegion()});
40  numSunk = controlFlowSink(
41  regionsToSink, domInfo,
42  [](Operation *op, Region *) { return !hasDontTouch(op); },
43  [](Operation *op, Region *region) {
44  // Move the operation to the beginning of the region's entry block.
45  // This guarantees the preservation of SSA dominance of all of the
46  // operation's uses are in the region.
47  op->moveBefore(&region->front(), region->front().begin());
48  });
49  });
50 }
51 
52 std::unique_ptr<mlir::Pass> circt::firrtl::createLayerSinkPass() {
53  return std::make_unique<LayerSink>();
54 }
bool hasDontTouch(Value value)
Check whether a block argument ("port") or the operation defining a value has a DontTouch annotation,...
Definition: FIRRTLOps.cpp:287
std::unique_ptr< mlir::Pass > createLayerSinkPass()
Definition: LayerSink.cpp:52
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
llvm::raw_ostream & debugPassHeader(const mlir::Pass *pass, int width=80)
Write a boilerplate header for a pass to the debug stream.
Definition: Debug.cpp:31