|
CIRCT 22.0.0git
|
#include "circt/Dialect/Comb/CombOps.h"#include "circt/Dialect/HW/HWAttributes.h"#include "circt/Dialect/HW/HWOps.h"#include "circt/Support/Naming.h"#include "mlir/IR/Diagnostics.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/PatternMatch.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/SmallBitVector.h"#include "llvm/ADT/TypeSwitch.h"#include "llvm/Support/KnownBits.h"
Go to the source code of this file.
Functions | |
| static bool | isOpTriviallyRecursive (Operation *op) |
| static Value | createGenericOp (Location loc, OperationName name, ArrayRef< Value > operands, OpBuilder &builder) |
| Create a new instance of a generic operation that only has value operands, and has a single result value whose type matches the first operand. | |
| static TypedAttr | getIntAttr (const APInt &value, MLIRContext *context) |
| static void | getConcatOperands (Value v, SmallVectorImpl< Value > &result) |
| Flatten concat and mux operands into a vector. | |
| static bool | hasSVAttributes (Operation *op) |
| template<typename SubType > | |
| static ComplementMatcher< SubType > | m_Complement (const SubType &subExpr) |
| static bool | shouldBeFlattened (Operation *op) |
| Return true if the op will be flattened afterwards. | |
| static bool | tryFlatteningOperands (Operation *op, PatternRewriter &rewriter) |
Flattens a single input in op if hasOneUse is true and it can be defined as an Op. | |
| static std::pair< size_t, size_t > | getLowestBitAndHighestBitRequired (Operation *op, bool narrowTrailingBits, size_t originalOpWidth) |
| template<class OpTy > | |
| static bool | narrowOperationWidth (OpTy op, bool narrowTrailingBits, PatternRewriter &rewriter) |
| static Attribute | constFoldBinaryOp (ArrayRef< Attribute > operands, hw::PEO paramOpcode) |
Performs constant folding calculate with element-wise behavior on the two attributes in operands and returns the result if possible. | |
| static LogicalResult | extractConcatToConcatExtract (ExtractOp op, ConcatOp innerCat, PatternRewriter &rewriter) |
| static bool | extractFromReplicate (ExtractOp op, ReplicateOp replicate, PatternRewriter &rewriter) |
| static Attribute | constFoldAssociativeOp (ArrayRef< Attribute > operands, hw::PEO paramOpcode) |
| static bool | canonicalizeLogicalCstWithConcat (Operation *logicalOp, size_t concatIdx, const APInt &cst, PatternRewriter &rewriter) |
| When we find a logical operation (and, or, xor) with a constant e.g. | |
| static bool | canCombineOppositeBinCmpIntoConstant (OperandRange operands) |
| template<typename Op > | |
| static Value | getCommonOperand (Op op) |
Returns a single common operand that all inputs of the operation op can be traced back to, or an empty Value if no such operand exists. | |
| template<typename Op > | |
| static bool | canonicalizeIdempotentInputs (Op op, PatternRewriter &rewriter) |
Canonicalize an idempotent operation op so that only one input of any kind occurs. | |
| static void | canonicalizeXorIcmpTrue (XorOp op, unsigned icmpOperand, PatternRewriter &rewriter) |
| template<class Op , bool isSigned> | |
| static OpFoldResult | foldDiv (Op op, ArrayRef< Attribute > constants) |
| template<class Op , bool isSigned> | |
| static OpFoldResult | foldMod (Op op, ArrayRef< Attribute > constants) |
| static bool | getMuxChainCondConstant (Value cond, Value indexValue, bool isInverted, std::function< void(hw::ConstantOp)> constantFn) |
Check to see if the condition to the specified mux is an equality comparison indexValue and one or more constants. | |
| static Value | extractOperandFromFullyAssociative (Operation *fullyAssoc, size_t operandNo, PatternRewriter &rewriter) |
| Given a fully associative variadic operation like (a+b+c+d), break the expression into two parts, one without the specified operand (e.g. | |
| static bool | foldCommonMuxValue (MuxOp op, bool isTrueOperand, PatternRewriter &rewriter) |
Fold things like mux(cond, x|y|z|a, a) -> (x|y|z)&replicate(cond)|a and mux(cond, a, x|y|z|a) ->(x|y|z)&replicate(~cond) | a` (when isTrueOperand is true. | |
| static bool | foldCommonMuxOperation (MuxOp mux, Operation *trueOp, Operation *falseOp, PatternRewriter &rewriter) |
| This function is invoke when we find a mux with true/false operations that have the same opcode. | |
| static bool | foldMuxOfUniformArrays (MuxOp op, PatternRewriter &rewriter) |
| static bool | assumeMuxCondInOperand (Value muxCond, Value muxValue, bool constCond, PatternRewriter &rewriter) |
| If the mux condition is an operand to the op defining its true or false value, replace the condition with 1 or 0. | |
| static bool | applyCmpPredicate (ICmpPredicate predicate, const APInt &lhs, const APInt &rhs) |
| static bool | applyCmpPredicateToEqualOperands (ICmpPredicate predicate) |
| template<typename Range > | |
| static size_t | computeCommonPrefixLength (const Range &a, const Range &b) |
| static size_t | getTotalWidth (ArrayRef< Value > operands) |
| static LogicalResult | matchAndRewriteCompareConcat (ICmpOp op, Operation *lhs, Operation *rhs, PatternRewriter &rewriter) |
| Reduce the strength icmp(concat(...), concat(...)) by doing a element-wise comparison on common prefix and suffixes. | |
| static void | combineEqualityICmpWithKnownBitsAndConstant (ICmpOp cmpOp, const KnownBits &bitAnalysis, const APInt &rhsCst, PatternRewriter &rewriter) |
| Given an equality comparison with a constant value and some operand that has known bits, simplify the comparison to check only the unknown bits of the input. | |
| static void | combineEqualityICmpWithXorOfConstant (ICmpOp cmpOp, XorOp xorOp, const APInt &rhs, PatternRewriter &rewriter) |
|
static |
Definition at line 2742 of file CombFolds.cpp.
|
static |
Definition at line 2779 of file CombFolds.cpp.
Referenced by matchAndRewriteCompareConcat().
|
static |
If the mux condition is an operand to the op defining its true or false value, replace the condition with 1 or 0.
Definition at line 2360 of file CombFolds.cpp.
References hw.ConstantOp::create().
|
static |
Definition at line 804 of file CombFolds.cpp.
|
static |
Canonicalize an idempotent operation op so that only one input of any kind occurs.
Example: and(x, y, x, z) -> and(x, y, z)
Definition at line 914 of file CombFolds.cpp.
|
static |
When we find a logical operation (and, or, xor) with a constant e.g.
X & 42, we want to push the constant into the computation of X if it leads to simplification.
This function handles the case where the logical operation has a concat operand. We check to see if we can simplify the concat, e.g. when it has constant operands.
This returns true when a simplification happens.
Definition at line 726 of file CombFolds.cpp.
References assert(), hw.ConstantOp::create(), createGenericOp(), and circt::replaceOpAndCopyNamehint().
|
static |
Definition at line 1287 of file CombFolds.cpp.
References circt::replaceOpAndCopyNamehint().
|
static |
Given an equality comparison with a constant value and some operand that has known bits, simplify the comparison to check only the unknown bits of the input.
One simple example of this is that concat(0, stuff) == 0 can be simplified to stuff == 0, or and(x, 3) == 0 can be simplified to extract x[1:0] == 0
Definition at line 2950 of file CombFolds.cpp.
References hw.ConstantOp::create().
|
static |
Definition at line 3034 of file CombFolds.cpp.
References hw.ConstantOp::create().
|
static |
Definition at line 2823 of file CombFolds.cpp.
Referenced by matchAndRewriteCompareConcat().
|
static |
Definition at line 691 of file CombFolds.cpp.
References assert().
|
static |
Performs constant folding calculate with element-wise behavior on the two attributes in operands and returns the result if possible.
Definition at line 311 of file CombFolds.cpp.
References assert().
|
static |
Create a new instance of a generic operation that only has value operands, and has a single result value whose type matches the first operand.
This should not be used to create instances of ops with attributes or with more complicated type signatures.
Definition at line 38 of file CombFolds.cpp.
Referenced by canonicalizeLogicalCstWithConcat(), extractOperandFromFullyAssociative(), and tryFlatteningOperands().
|
static |
Definition at line 475 of file CombFolds.cpp.
References assert(), comb.ExtractOp::create(), and circt::replaceOpAndCopyNamehint().
|
static |
Definition at line 556 of file CombFolds.cpp.
|
static |
Given a fully associative variadic operation like (a+b+c+d), break the expression into two parts, one without the specified operand (e.g.
tmp = a+b+d) and one that combines that into the full expression (e.g. tmp+c), and return the inner expression.
NOTE: This mutates the operation in place if it only has a single user, which assumes that user will be removed.
Definition at line 2104 of file CombFolds.cpp.
References assert(), createGenericOp(), and circt::replaceOpAndCopyNamehint().
Referenced by foldCommonMuxValue().
|
static |
This function is invoke when we find a mux with true/false operations that have the same opcode.
Check to see if we can strength reduce the mux by applying it to less data by applying this transformation: mux(cond, op(a, b), op(a, c)) -> op(a, mux(cond, b, c))
Definition at line 2246 of file CombFolds.cpp.
References getConcatOperands(), and circt::replaceOpAndCopyNamehint().
|
static |
Fold things like mux(cond, x|y|z|a, a) -> (x|y|z)&replicate(cond)|a and mux(cond, a, x|y|z|a) ->(x|y|z)&replicate(~cond) | a` (when isTrueOperand is true.
Return true on successful transformation, false if not.
These are various forms of "predicated ops" that can be handled with a replicate/and combination.
Definition at line 2145 of file CombFolds.cpp.
References assert(), circt::comb::createOrFoldNot(), and extractOperandFromFullyAssociative().
|
static |
Definition at line 1640 of file CombFolds.cpp.
References constFoldBinaryOp().
|
static |
Definition at line 1667 of file CombFolds.cpp.
References constFoldBinaryOp(), and getIntAttr().
|
static |
Definition at line 2341 of file CombFolds.cpp.
|
static |
Returns a single common operand that all inputs of the operation op can be traced back to, or an empty Value if no such operand exists.
For example for or(a[0], a[1], ..., a[n-1]) this function returns a (assuming the bit-width of a is n).
Definition at line 879 of file CombFolds.cpp.
|
static |
Flatten concat and mux operands into a vector.
Definition at line 52 of file CombFolds.cpp.
References concat(), and getConcatOperands().
Referenced by foldCommonMuxOperation(), getConcatOperands(), and matchAndRewriteCompareConcat().
|
static |
Definition at line 46 of file CombFolds.cpp.
|
static |
Definition at line 186 of file CombFolds.cpp.
References assert().
Referenced by narrowOperationWidth().
|
static |
Check to see if the condition to the specified mux is an equality comparison indexValue and one or more constants.
If so, put the constants in the constants vector and return true, otherwise return false.
This is part of foldMuxChain.
Definition at line 1936 of file CombFolds.cpp.
References getMuxChainCondConstant().
Referenced by getMuxChainCondConstant().
|
static |
Definition at line 2837 of file CombFolds.cpp.
References assert().
Referenced by matchAndRewriteCompareConcat().
|
static |
Definition at line 67 of file CombFolds.cpp.
Referenced by findNestedElseIf().
|
static |
Definition at line 27 of file CombFolds.cpp.
|
inlinestatic |
Definition at line 84 of file CombFolds.cpp.
|
static |
Reduce the strength icmp(concat(...), concat(...)) by doing a element-wise comparison on common prefix and suffixes.
Returns success() if a rewriting happens. This handles both concat and replicate.
Definition at line 2852 of file CombFolds.cpp.
References applyCmpPredicateToEqualOperands(), assert(), computeCommonPrefixLength(), getConcatOperands(), and getTotalWidth().
|
static |
Definition at line 217 of file CombFolds.cpp.
References hw.ConstantOp::create(), and getLowestBitAndHighestBitRequired().
|
static |
Return true if the op will be flattened afterwards.
Op will be flattend if it has a single user which has a same op type. User must be in same block.
Definition at line 90 of file CombFolds.cpp.
References assert().
Referenced by tryFlatteningOperands().
|
static |
Flattens a single input in op if hasOneUse is true and it can be defined as an Op.
Returns true if successful, and false otherwise.
Example: op(1, 2, op(3, 4), 5) -> op(1, 2, 3, 4, 5) // returns true
Definition at line 108 of file CombFolds.cpp.
References createGenericOp(), circt::replaceOpAndCopyNamehint(), and shouldBeFlattened().