CIRCT  20.0.0git
Passes.h
Go to the documentation of this file.
1 //===- Passes.h - Pass Entrypoints ------------------------------*- 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 for CIRCT transformation passes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_TRANSFORMS_PASSES_H
14 #define CIRCT_TRANSFORMS_PASSES_H
15 
17 #include "mlir/IR/BuiltinOps.h"
18 #include "mlir/Pass/Pass.h"
19 #include <limits>
20 
21 namespace circt {
22 
23 //===----------------------------------------------------------------------===//
24 // Passes
25 //===----------------------------------------------------------------------===//
26 
27 #define GEN_PASS_DECL
28 
30  // Specify the format for op count data emission
31  Readable,
33  JSON
34 };
35 
36 #include "circt/Transforms/Passes.h.inc"
37 
38 std::unique_ptr<mlir::Pass> createMapArithToCombPass();
39 std::unique_ptr<mlir::Pass> createFlattenMemRefPass();
40 std::unique_ptr<mlir::Pass> createFlattenMemRefCallsPass();
41 std::unique_ptr<mlir::Pass> createStripDebugInfoWithPredPass(
42  const std::function<bool(mlir::Location)> &pred);
43 std::unique_ptr<mlir::Pass> createMaximizeSSAPass();
44 std::unique_ptr<mlir::Pass> createInsertMergeBlocksPass();
45 std::unique_ptr<mlir::Pass> createPrintOpCountPass();
46 
47 //===----------------------------------------------------------------------===//
48 // Utility functions.
49 //===----------------------------------------------------------------------===//
50 
51 // Returns true if the provided memref is considered unidimensional (having a
52 // shape of size 1).
53 bool isUniDimensional(mlir::MemRefType memref);
54 
55 // Returns true if the region is into maximal SSA form i.e., if all the values
56 // within the region are in maximal SSA form.
57 bool isRegionSSAMaximized(Region &region);
58 
59 /// Strategy class to control the behavior of SSA maximization. The class
60 /// exposes overridable filter functions to dynamically select which blocks,
61 /// block arguments, operations, and operation results should be put into
62 /// maximal SSA form. All filter functions should return true whenever the
63 /// entity they operate on should be considered for SSA maximization. By
64 /// default, all filter functions always return true.
66 public:
67  /// Determines whether a block should have the values it defines (i.e., block
68  /// arguments and operation results within the block) SSA maximized.
69  virtual bool maximizeBlock(Block *block);
70  /// Determines whether a block argument should be SSA maximized.
71  virtual bool maximizeArgument(BlockArgument arg);
72  /// Determines whether an operation should have its results SSA maximized.
73  virtual bool maximizeOp(Operation *op);
74  /// Determines whether an operation's result should be SSA maximized.
75  virtual bool maximizeResult(OpResult res);
76 
77  virtual ~SSAMaximizationStrategy() = default;
78 };
79 
80 /// Converts a single value within a function into maximal SSA form. This
81 /// removes any implicit dataflow of this specific value within the enclosing
82 /// function. The function adds new block arguments wherever necessary to carry
83 /// the value explicitly between blocks.
84 /// Succeeds when it was possible to convert the value into maximal SSA form.
85 LogicalResult maximizeSSA(Value value, PatternRewriter &rewriter);
86 
87 /// Considers all of an operation's results for SSA maximization, following a
88 /// provided strategy. This removes any implicit dataflow of the selected
89 /// operation's results within the enclosing function. The function adds new
90 /// block arguments wherever necessary to carry the results explicitly between
91 /// blocks. Succeeds when it was possible to convert the selected operation's
92 /// results into maximal SSA form.
93 LogicalResult maximizeSSA(Operation *op, SSAMaximizationStrategy &strategy,
94  PatternRewriter &rewriter);
95 
96 /// Considers all values defined by a block (i.e., block arguments and operation
97 /// results within the block) for SSA maximization, following a provided
98 /// strategy. This removes any implicit dataflow of the selected values within
99 /// the enclosing function. The function adds new block arguments wherever
100 /// necessary to carry the values explicitly between blocks. Succeeds when it
101 /// was possible to convert the selected values defined by the block into
102 /// maximal SSA form.
103 LogicalResult maximizeSSA(Block *block, SSAMaximizationStrategy &strategy,
104  PatternRewriter &rewriter);
105 
106 /// Considers all blocks within a region for SSA maximization, following a
107 /// provided strategy. This removes any implicit dataflow of the values defined
108 /// by selected blocks within the region. The function adds new block arguments
109 /// wherever necessary to carry the region's values explicitly between blocks.
110 /// Succeeds when it was possible to convert all of the values defined by
111 /// selected blocks into maximal SSA form.
112 LogicalResult maximizeSSA(Region &region, SSAMaximizationStrategy &strategy,
113  PatternRewriter &rewriter);
114 
115 /// Manually run merge block insertion on a region.
116 ///
117 /// This transformation does treat loops like a single block and thus does not
118 /// affect them.
119 LogicalResult insertMergeBlocks(mlir::Region &r,
120  mlir::ConversionPatternRewriter &rewriter);
121 
122 //===----------------------------------------------------------------------===//
123 // Registration
124 //===----------------------------------------------------------------------===//
125 
126 /// Generate the code for registering passes.
127 #define GEN_PASS_REGISTRATION
128 #include "circt/Transforms/Passes.h.inc"
129 
130 } // namespace circt
131 
132 #endif // CIRCT_TRANSFORMS_PASSES_H
Strategy strategy
Strategy class to control the behavior of SSA maximization.
Definition: Passes.h:65
virtual bool maximizeResult(OpResult res)
Determines whether an operation's result should be SSA maximized.
Definition: MaximizeSSA.cpp:81
virtual ~SSAMaximizationStrategy()=default
virtual bool maximizeArgument(BlockArgument arg)
Determines whether a block argument should be SSA maximized.
Definition: MaximizeSSA.cpp:77
virtual bool maximizeBlock(Block *block)
Determines whether a block should have the values it defines (i.e., block arguments and operation res...
Definition: MaximizeSSA.cpp:74
virtual bool maximizeOp(Operation *op)
Determines whether an operation should have its results SSA maximized.
Definition: MaximizeSSA.cpp:80
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
std::unique_ptr< mlir::Pass > createMaximizeSSAPass()
std::unique_ptr< mlir::Pass > createPrintOpCountPass()
std::unique_ptr< mlir::Pass > createInsertMergeBlocksPass()
std::unique_ptr< mlir::Pass > createMapArithToCombPass()
mlir::LogicalResult insertMergeBlocks(mlir::Region &r, mlir::ConversionPatternRewriter &rewriter)
Insert additional blocks that serve as counterparts to the blocks that diverged the control flow.
LogicalResult maximizeSSA(Value value, PatternRewriter &rewriter)
Converts a single value within a function into maximal SSA form.
Definition: MaximizeSSA.cpp:85
std::unique_ptr< mlir::Pass > createFlattenMemRefPass()
OpCountEmissionFormat
Definition: Passes.h:29
bool isUniDimensional(mlir::MemRefType memref)
bool isRegionSSAMaximized(Region &region)
Definition: MaximizeSSA.cpp:61
std::unique_ptr< mlir::Pass > createFlattenMemRefCallsPass()
std::unique_ptr< mlir::Pass > createStripDebugInfoWithPredPass(const std::function< bool(mlir::Location)> &pred)
Creates a pass to strip debug information from a function.