CIRCT  19.0.0git
HandshakePasses.h
Go to the documentation of this file.
1 //===- HandshakePasses.h - Handshake pass entry points ----------*- 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 header file defines prototypes that expose pass constructors.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_HANDSHAKE_HANDSHAKEPASSES_H
14 #define CIRCT_DIALECT_HANDSHAKE_HANDSHAKEPASSES_H
15 
16 #include "circt/Support/LLVM.h"
17 #include <map>
18 #include <memory>
19 #include <optional>
20 #include <set>
21 
22 #include "mlir/Dialect/Func/IR/FuncOps.h"
23 #include "mlir/Dialect/MemRef/IR/MemRef.h"
24 #include "mlir/Dialect/SCF/IR/SCF.h"
25 
26 namespace circt {
27 namespace handshake {
28 class FuncOp;
29 
30 std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
32 std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
34 std::unique_ptr<mlir::Pass> createHandshakeMaterializeForksSinksPass();
35 std::unique_ptr<mlir::Pass> createHandshakeDematerializeForksSinksPass();
36 std::unique_ptr<mlir::Pass> createHandshakeRemoveBuffersPass();
37 std::unique_ptr<mlir::Pass> createHandshakeAddIDsPass();
38 std::unique_ptr<mlir::Pass>
39 createHandshakeLowerExtmemToHWPass(std::optional<bool> createESIWrapper = {});
40 std::unique_ptr<mlir::Pass> createHandshakeLegalizeMemrefsPass();
41 std::unique_ptr<mlir::OperationPass<handshake::FuncOp>>
42 createHandshakeInsertBuffersPass(const std::string &strategy = "all",
43  unsigned bufferSize = 2);
44 std::unique_ptr<mlir::Pass> createHandshakeLockFunctionsPass();
45 
46 /// Iterates over the handshake::FuncOp's in the program to build an instance
47 /// graph. In doing so, we detect whether there are any cycles in this graph, as
48 /// well as infer a top function for the design by performing a topological sort
49 /// of the instance graph. The result of this sort is placed in sortedFuncs.
50 using InstanceGraph = std::map<std::string, std::set<std::string>>;
51 LogicalResult resolveInstanceGraph(ModuleOp moduleOp,
52  InstanceGraph &instanceGraph,
53  std::string &topLevel,
54  SmallVectorImpl<std::string> &sortedFuncs);
55 
56 // Checks all block arguments and values within op to ensure that all
57 // values have exactly one use.
58 LogicalResult verifyAllValuesHasOneUse(handshake::FuncOp op);
59 
60 // Adds sink operations to any unused value in r.
61 LogicalResult addSinkOps(Region &r, OpBuilder &rewriter);
62 
63 // Adds fork operations to any value with multiple uses in r.
64 LogicalResult addForkOps(Region &r, OpBuilder &rewriter);
65 void insertFork(Value result, bool isLazy, OpBuilder &rewriter);
66 
67 // Adds a locking mechanism around the region.
68 LogicalResult lockRegion(Region &r, OpBuilder &rewriter);
69 
70 // Applies the spcified buffering strategy on the region r.
71 LogicalResult bufferRegion(Region &r, OpBuilder &rewriter, StringRef strategy,
72  unsigned bufferSize);
73 
74 /// Generate the code for registering passes.
75 #define GEN_PASS_REGISTRATION
76 #include "circt/Dialect/Handshake/HandshakePasses.h.inc"
77 
78 } // namespace handshake
79 } // namespace circt
80 
81 #endif // CIRCT_DIALECT_HANDSHAKE_HANDSHAKEPASSES_H
std::unique_ptr< mlir::OperationPass< handshake::FuncOp > > createHandshakeInsertBuffersPass(const std::string &strategy="all", unsigned bufferSize=2)
Definition: Buffers.cpp:215
std::unique_ptr< mlir::Pass > createHandshakeMaterializeForksSinksPass()
std::unique_ptr< mlir::OperationPass< mlir::ModuleOp > > createHandshakeOpCountPass()
Definition: Analysis.cpp:614
std::map< std::string, std::set< std::string > > InstanceGraph
Iterates over the handshake::FuncOp's in the program to build an instance graph.
LogicalResult resolveInstanceGraph(ModuleOp moduleOp, InstanceGraph &instanceGraph, std::string &topLevel, SmallVectorImpl< std::string > &sortedFuncs)
Iterates over the handshake::FuncOp's in the program to build an instance graph.
Definition: PassHelpers.cpp:38
std::unique_ptr< mlir::OperationPass< mlir::ModuleOp > > createHandshakeDotPrintPass()
Definition: Analysis.cpp:609
LogicalResult addForkOps(Region &r, OpBuilder &rewriter)
LogicalResult verifyAllValuesHasOneUse(handshake::FuncOp op)
std::unique_ptr< mlir::Pass > createHandshakeLowerExtmemToHWPass(std::optional< bool > createESIWrapper={})
std::unique_ptr< mlir::Pass > createHandshakeDematerializeForksSinksPass()
void insertFork(Value result, bool isLazy, OpBuilder &rewriter)
std::unique_ptr< mlir::Pass > createHandshakeLegalizeMemrefsPass()
std::unique_ptr< mlir::Pass > createHandshakeRemoveBuffersPass()
Definition: Buffers.cpp:210
std::unique_ptr< mlir::Pass > createHandshakeLockFunctionsPass()
std::unique_ptr< mlir::Pass > createHandshakeAddIDsPass()
Definition: Analysis.cpp:618
LogicalResult bufferRegion(Region &r, OpBuilder &rewriter, StringRef strategy, unsigned bufferSize)
Definition: Buffers.cpp:171
LogicalResult lockRegion(Region &r, OpBuilder &rewriter)
LogicalResult addSinkOps(Region &r, OpBuilder &rewriter)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21