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