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