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 
15 #include "mlir/Pass/Pass.h"
16 
17 #include "circt/Support/Debug.h"
18 #include "mlir/IR/Dominance.h"
19 #include "mlir/Interfaces/ControlFlowInterfaces.h"
20 #include "mlir/Interfaces/SideEffectInterfaces.h"
21 #include "mlir/Transforms/ControlFlowSinkUtils.h"
22 
23 #define DEBUG_TYPE "firrtl-layer-sink"
24 
25 namespace circt {
26 namespace firrtl {
27 #define GEN_PASS_DEF_LAYERSINK
28 #include "circt/Dialect/FIRRTL/Passes.h.inc"
29 } // namespace firrtl
30 } // namespace circt
31 
32 using namespace circt;
33 using namespace firrtl;
34 
35 namespace {
36 /// A control-flow sink pass.
37 struct LayerSink : public circt::firrtl::impl::LayerSinkBase<LayerSink> {
38  void runOnOperation() override;
39 };
40 } // end anonymous namespace
41 
42 void LayerSink::runOnOperation() {
43  LLVM_DEBUG(debugPassHeader(this)
44  << "\n"
45  << "Module: '" << getOperation().getName() << "'\n";);
46  auto &domInfo = getAnalysis<mlir::DominanceInfo>();
47  getOperation()->walk([&](LayerBlockOp layerBlock) {
48  SmallVector<Region *> regionsToSink({&layerBlock.getRegion()});
49  numSunk = controlFlowSink(
50  regionsToSink, domInfo,
51  [](Operation *op, Region *) { return !hasDontTouch(op); },
52  [](Operation *op, Region *region) {
53  // Move the operation to the beginning of the region's entry block.
54  // This guarantees the preservation of SSA dominance of all of the
55  // operation's uses are in the region.
56  op->moveBefore(&region->front(), region->front().begin());
57  });
58  });
59 }
60 
61 std::unique_ptr<mlir::Pass> circt::firrtl::createLayerSinkPass() {
62  return std::make_unique<LayerSink>();
63 }
bool hasDontTouch(Value value)
Check whether a block argument ("port") or the operation defining a value has a DontTouch annotation,...
Definition: FIRRTLOps.cpp:314
std::unique_ptr< mlir::Pass > createLayerSinkPass()
Definition: LayerSink.cpp:61
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