Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/Dialect/Affine/IR/AffineOps.h"
18#include "mlir/IR/BuiltinOps.h"
19#include "mlir/Pass/Pass.h"
20#include <limits>
21
22namespace circt {
23
24//===----------------------------------------------------------------------===//
25// Passes
26//===----------------------------------------------------------------------===//
27
28#define GEN_PASS_DECL
29
31 // Specify the format for op count data emission
34 JSON
35};
36
37#include "circt/Transforms/Passes.h.inc"
38
39void populateArithToCombPatterns(mlir::RewritePatternSet &patterns,
40 TypeConverter &typeConverter);
41
42std::unique_ptr<mlir::Pass> createMapArithToCombPass();
43std::unique_ptr<mlir::Pass> createFlattenMemRefPass();
44std::unique_ptr<mlir::Pass> createFlattenMemRefCallsPass();
45std::unique_ptr<mlir::Pass> createStripDebugInfoWithPredPass(
46 const std::function<bool(mlir::Location)> &pred);
47std::unique_ptr<mlir::Pass> createMaximizeSSAPass();
48std::unique_ptr<mlir::Pass> createInsertMergeBlocksPass();
49std::unique_ptr<mlir::Pass> createPrintOpCountPass();
50std::unique_ptr<mlir::Pass>
51createMemoryBankingPass(ArrayRef<unsigned> bankingFactors = {},
52 ArrayRef<unsigned> bankingDimensions = {});
53std::unique_ptr<mlir::Pass> createIndexSwitchToIfPass();
54std::unique_ptr<mlir::Pass> createHierarchicalRunner(
55 const std::string &topName,
56 llvm::function_ref<void(mlir::OpPassManager &)> pipeline,
57 bool includeBoundInstances = false);
58
59//===----------------------------------------------------------------------===//
60// Utility functions.
61//===----------------------------------------------------------------------===//
62
63// Returns true if the provided memref is considered unidimensional (having a
64// shape of size 1).
65bool isUniDimensional(mlir::MemRefType memref);
66
67// Returns true if the region is into maximal SSA form i.e., if all the values
68// within the region are in maximal SSA form.
69bool isRegionSSAMaximized(Region &region);
70
71/// Strategy class to control the behavior of SSA maximization. The class
72/// exposes overridable filter functions to dynamically select which blocks,
73/// block arguments, operations, and operation results should be put into
74/// maximal SSA form. All filter functions should return true whenever the
75/// entity they operate on should be considered for SSA maximization. By
76/// default, all filter functions always return true.
78public:
79 /// Determines whether a block should have the values it defines (i.e., block
80 /// arguments and operation results within the block) SSA maximized.
81 virtual bool maximizeBlock(Block *block);
82 /// Determines whether a block argument should be SSA maximized.
83 virtual bool maximizeArgument(BlockArgument arg);
84 /// Determines whether an operation should have its results SSA maximized.
85 virtual bool maximizeOp(Operation *op);
86 /// Determines whether an operation's result should be SSA maximized.
87 virtual bool maximizeResult(OpResult res);
88
89 virtual ~SSAMaximizationStrategy() = default;
90};
91
92/// Converts a single value within a function into maximal SSA form. This
93/// removes any implicit dataflow of this specific value within the enclosing
94/// function. The function adds new block arguments wherever necessary to carry
95/// the value explicitly between blocks.
96/// Succeeds when it was possible to convert the value into maximal SSA form.
97LogicalResult maximizeSSA(Value value, PatternRewriter &rewriter);
98
99/// Considers all of an operation's results for SSA maximization, following a
100/// provided strategy. This removes any implicit dataflow of the selected
101/// operation's results within the enclosing function. The function adds new
102/// block arguments wherever necessary to carry the results explicitly between
103/// blocks. Succeeds when it was possible to convert the selected operation's
104/// results into maximal SSA form.
105LogicalResult maximizeSSA(Operation *op, SSAMaximizationStrategy &strategy,
106 PatternRewriter &rewriter);
107
108/// Considers all values defined by a block (i.e., block arguments and operation
109/// results within the block) for SSA maximization, following a provided
110/// strategy. This removes any implicit dataflow of the selected values within
111/// the enclosing function. The function adds new block arguments wherever
112/// necessary to carry the values explicitly between blocks. Succeeds when it
113/// was possible to convert the selected values defined by the block into
114/// maximal SSA form.
115LogicalResult maximizeSSA(Block *block, SSAMaximizationStrategy &strategy,
116 PatternRewriter &rewriter);
117
118/// Considers all blocks within a region for SSA maximization, following a
119/// provided strategy. This removes any implicit dataflow of the values defined
120/// by selected blocks within the region. The function adds new block arguments
121/// wherever necessary to carry the region's values explicitly between blocks.
122/// Succeeds when it was possible to convert all of the values defined by
123/// selected blocks into maximal SSA form.
124LogicalResult maximizeSSA(Region &region, SSAMaximizationStrategy &strategy,
125 PatternRewriter &rewriter);
126
127/// Manually run merge block insertion on a region.
128///
129/// This transformation does treat loops like a single block and thus does not
130/// affect them.
131LogicalResult insertMergeBlocks(mlir::Region &r,
132 mlir::ConversionPatternRewriter &rewriter);
133
134//===----------------------------------------------------------------------===//
135// Registration
136//===----------------------------------------------------------------------===//
137
138/// Generate the code for registering passes.
139#define GEN_PASS_REGISTRATION
140#include "circt/Transforms/Passes.h.inc"
141
142} // namespace circt
143
144#endif // CIRCT_TRANSFORMS_PASSES_H
Strategy strategy
Strategy class to control the behavior of SSA maximization.
Definition Passes.h:77
virtual bool maximizeResult(OpResult res)
Determines whether an operation's result should be SSA maximized.
virtual ~SSAMaximizationStrategy()=default
virtual bool maximizeArgument(BlockArgument arg)
Determines whether a block argument should be SSA maximized.
virtual bool maximizeBlock(Block *block)
Determines whether a block should have the values it defines (i.e., block arguments and operation res...
virtual bool maximizeOp(Operation *op)
Determines whether an operation should have its results SSA maximized.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::Pass > createMaximizeSSAPass()
std::unique_ptr< mlir::Pass > createPrintOpCountPass()
std::unique_ptr< mlir::Pass > createHierarchicalRunner(const std::string &topName, llvm::function_ref< void(mlir::OpPassManager &)> pipeline, bool includeBoundInstances=false)
std::unique_ptr< mlir::Pass > createInsertMergeBlocksPass()
std::unique_ptr< mlir::Pass > createIndexSwitchToIfPass()
std::unique_ptr< mlir::Pass > createMemoryBankingPass(ArrayRef< unsigned > bankingFactors={}, ArrayRef< unsigned > bankingDimensions={})
void populateArithToCombPatterns(mlir::RewritePatternSet &patterns, TypeConverter &typeConverter)
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.
std::unique_ptr< mlir::Pass > createFlattenMemRefPass()
OpCountEmissionFormat
Definition Passes.h:30
bool isUniDimensional(mlir::MemRefType memref)
bool isRegionSSAMaximized(Region &region)
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.