|
CIRCT 23.0.0git
|
#include "circt/Dialect/FIRRTL/FIRRTLAttributes.h"#include "circt/Dialect/FIRRTL/FIRRTLOps.h"#include "circt/Dialect/FIRRTL/FIRRTLTypes.h"#include "circt/Dialect/FIRRTL/FIRRTLUtils.h"#include "circt/Support/APInt.h"#include "circt/Support/LLVM.h"#include "circt/Support/Naming.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/PatternMatch.h"#include "llvm/ADT/APSInt.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/StringExtras.h"#include "llvm/ADT/TypeSwitch.h"#include "circt/Dialect/FIRRTL/FIRRTLCanonicalization.h.inc"
Go to the source code of this file.
Classes | |
| class | ReductionCat |
| class | OrRCat |
| class | AndRCat |
| class | XorRCat |
| struct | BitsOfCat |
Namespaces | |
| namespace | circt |
| The InstanceGraph op interface, see InstanceGraphInterface.td for more details. | |
| namespace | circt::firrtl |
| namespace | circt::firrtl::patterns |
Enumerations | |
| enum class | BinOpKind { Normal , Compare , DivideOrShift } |
| This is the policy for folding, which depends on the sort of operator we're processing. More... | |
Functions | |
| static Value | dropWrite (PatternRewriter &rewriter, OpResult old, Value passthrough) |
| static bool | isOkToPropagateName (Operation *op) |
| static Value | moveNameHint (OpResult old, Value passthrough) |
| static bool | hasKnownWidthIntTypes (Operation *op) |
| Return true if this operation's operands and results all have a known width. | |
| static bool | isUInt1 (Type type) |
| Return true if this value is 1 bit UInt. | |
| static void | updateName (PatternRewriter &rewriter, Operation *op, StringAttr name) |
| Set the name of an op based on the best of two names: The current name, and the name passed in. | |
| static void | replaceOpAndCopyName (PatternRewriter &rewriter, Operation *op, Value newValue) |
A wrapper of PatternRewriter::replaceOp to propagate "name" attribute. | |
| template<typename OpTy , typename... Args> | |
| static OpTy | replaceOpWithNewOpAndCopyName (PatternRewriter &rewriter, Operation *op, Args &&...args) |
A wrapper of PatternRewriter::replaceOpWithNewOp to propagate "name" attribute. | |
| static std::optional< APSInt > | getExtendedConstant (Value operand, Attribute constant, int32_t destWidth) |
| Implicitly replace the operand to a constant folding operation with a const 0 in case the operand is non-constant but has a bit width 0, or if the operand is an invalid value. | |
| static std::optional< APSInt > | getConstant (Attribute operand) |
| Determine the value of a constant operand for the sake of constant folding. | |
| static bool | isConstantZero (Attribute operand) |
| Determine whether a constant operand is a zero value for the sake of constant folding. | |
| static bool | isConstantOne (Attribute operand) |
| Determine whether a constant operand is a one value for the sake of constant folding. | |
| static Attribute | constFoldFIRRTLBinaryOp (Operation *op, ArrayRef< Attribute > operands, BinOpKind opKind, const function_ref< APInt(const APSInt &, const APSInt &)> &calculate) |
Applies the constant folding function calculate to the given operands. | |
| static LogicalResult | canonicalizePrimOp (Operation *op, PatternRewriter &rewriter, const function_ref< OpFoldResult(ArrayRef< Attribute >)> &canonicalize) |
Applies the canonicalization function canonicalize to the given operation. | |
| static APInt | getMaxUnsignedValue (unsigned bitWidth) |
| Get the largest unsigned value of a given bit width. | |
| static APInt | getMinSignedValue (unsigned bitWidth) |
| Get the smallest signed value of a given bit width. | |
| static APInt | getMaxSignedValue (unsigned bitWidth) |
| Get the largest signed value of a given bit width. | |
| static void | replaceWithBits (Operation *op, Value value, unsigned hiBit, unsigned loBit, PatternRewriter &rewriter) |
| Replace the specified operation with a 'bits' op from the specified hi/lo bits. | |
| template<typename OpTy > | |
| static OpFoldResult | foldMux (OpTy op, typename OpTy::FoldAdaptor adaptor) |
| static LogicalResult | canonicalizeSingleSetConnect (MatchingConnectOp op, PatternRewriter &rewriter) |
| static AttachOp | getDominatingAttachUser (Value value, AttachOp dominatedAttach) |
| If the specified value has an AttachOp user strictly dominating by "dominatingAttach" then return it. | |
| static void | replaceOpWithRegion (PatternRewriter &rewriter, Operation *op, Region ®ion) |
| Replaces the given op with the contents of the given single-block region. | |
| template<typename OpTy > | |
| static LogicalResult | demoteForceableIfUnused (OpTy op, PatternRewriter &rewriter) |
| static Attribute | collectFields (MLIRContext *context, ArrayRef< Attribute > operands) |
| static bool | isDefinedByOneConstantOp (Value v) |
| static LogicalResult | canonicalizeRegResetWithOneReset (RegResetOp reg, PatternRewriter &rewriter) |
| static Value | getPortFieldValue (Value port, StringRef name) |
| static bool | isPortDisabled (Value port) |
| static bool | isPortUnused (Value port, StringRef data) |
| static void | replacePortField (PatternRewriter &rewriter, Value port, StringRef name, Value value) |
| static void | erasePort (PatternRewriter &rewriter, Value port) |
| static LogicalResult | foldHiddenReset (RegOp reg, PatternRewriter &rewriter) |
| static LogicalResult | eraseIfZeroOrNotZero (Operation *op, Value predicate, Value enable, PatternRewriter &rewriter, bool eraseIfZero) |
| template<class Op , bool EraseIfZero = false> | |
| static LogicalResult | canonicalizeImmediateVerifOp (Op op, PatternRewriter &rewriter) |
| static LogicalResult | canonicalizeRefResolveOfForceable (RefResolveOp op, PatternRewriter &rewriter) |
| static bool | isConstantZero (Value operand) |
| template<typename Op > | |
| static LogicalResult | eraseIfPredFalse (Op op, PatternRewriter &rewriter) |
| static bool | isTypeEmpty (FIRRTLType type) |
|
strong |
This is the policy for folding, which depends on the sort of operator we're processing.
| Enumerator | |
|---|---|
| Normal | |
| Compare | |
| DivideOrShift | |
Definition at line 210 of file FIRRTLFolds.cpp.
|
static |
Definition at line 3641 of file FIRRTLFolds.cpp.
References eraseIfZeroOrNotZero().
|
static |
Applies the canonicalization function canonicalize to the given operation.
Determines which (if any) of the operation's operands are constants, and provides them as arguments to the callback function. Any invalidvalue in the input is mapped to a constant zero. The value returned from the callback is used as the replacement for op, and an additional pad operation is inserted if necessary. Does nothing if the result of op is of unknown width, in which case the necessity of a pad cannot be determined.
Definition at line 293 of file FIRRTLFolds.cpp.
References assert(), and replaceOpAndCopyName().
|
static |
Definition at line 3755 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2723 of file FIRRTLFolds.cpp.
References dropWrite(), and isDefinedByOneConstantOp().
|
static |
Definition at line 2215 of file FIRRTLFolds.cpp.
References empty, circt::firrtl::getSingleConnectUserOf(), circt::firrtl::hasDontTouch(), circt::firrtl::hasDroppableName(), and replaceOpAndCopyName().
|
static |
Definition at line 2608 of file FIRRTLFolds.cpp.
References context.
|
static |
Applies the constant folding function calculate to the given operands.
Sign or zero extends the operands appropriately to the bitwidth of the result type if useDstWidth is true, else to the larger of the two operand bit widths and depending on whether the operation is to be performed on signed or unsigned operands.
Definition at line 222 of file FIRRTLFolds.cpp.
References assert(), Compare, DivideOrShift, getExtendedConstant(), circt::firrtl::getIntAttr(), and Normal.
|
static |
Definition at line 2428 of file FIRRTLFolds.cpp.
References circt::firrtl::detail::replaceWithNewForceability().
|
static |
Definition at line 33 of file FIRRTLFolds.cpp.
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 3784 of file FIRRTLFolds.cpp.
References circt::isConstantZero().
|
static |
Definition at line 3617 of file FIRRTLFolds.cpp.
Referenced by canonicalizeConcurrentVerifOp(), canonicalizeImmediateVerifOp(), and canonicalizeImmediateVerifOp().
|
static |
Definition at line 2810 of file FIRRTLFolds.cpp.
References assert().
|
static |
Definition at line 3534 of file FIRRTLFolds.cpp.
References circt::firrtl::getSingleConnectUserOf().
|
static |
Definition at line 1750 of file FIRRTLFolds.cpp.
References getConstant(), and circt::firrtl::getIntAttr().
|
static |
Determine the value of a constant operand for the sake of constant folding.
Definition at line 182 of file FIRRTLFolds.cpp.
Referenced by emulateBinaryOpForUnknownBits(), foldMux(), isConstantOne(), isConstantZero(), circt::firrtl::InstanceInfo::LatticeValue::mergeIn(), and circt::firrtl::InstanceInfo::LatticeValue::operator!().
|
static |
If the specified value has an AttachOp user strictly dominating by "dominatingAttach" then return it.
Definition at line 2296 of file FIRRTLFolds.cpp.
|
static |
Implicitly replace the operand to a constant folding operation with a const 0 in case the operand is non-constant but has a bit width 0, or if the operand is an invalid value.
This makes constant folding significantly easier, as we can simply pass the operands to an operation through this function to appropriately replace any zero-width dynamic values or invalid values with a constant of value 0.
Definition at line 161 of file FIRRTLFolds.cpp.
References assert(), and circt::extOrTruncZeroWidth().
Referenced by constFoldFIRRTLBinaryOp().
|
static |
Get the largest signed value of a given bit width.
Returns a 1-bit zero value if bitWidth is 0.
Definition at line 363 of file FIRRTLFolds.cpp.
|
static |
Get the largest unsigned value of a given bit width.
Returns a 1-bit zero value if bitWidth is 0.
Definition at line 351 of file FIRRTLFolds.cpp.
|
static |
Get the smallest signed value of a given bit width.
Returns a 1-bit zero value if bitWidth is 0.
Definition at line 357 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2747 of file FIRRTLFolds.cpp.
References assert(), and circt::firrtl::getSingleConnectUserOf().
Referenced by isPortDisabled().
|
static |
Return true if this operation's operands and results all have a known width.
This only works for integer types.
Definition at line 83 of file FIRRTLFolds.cpp.
|
static |
Determine whether a constant operand is a one value for the sake of constant folding.
Definition at line 202 of file FIRRTLFolds.cpp.
References getConstant().
|
static |
Determine whether a constant operand is a zero value for the sake of constant folding.
This considers invalidvalue to be zero.
Definition at line 194 of file FIRRTLFolds.cpp.
References getConstant().
|
static |
Definition at line 3778 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2714 of file FIRRTLFolds.cpp.
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 48 of file FIRRTLFolds.cpp.
Referenced by moveNameHint(), and updateName().
|
static |
Definition at line 2766 of file FIRRTLFolds.cpp.
References getPortFieldValue().
|
static |
Definition at line 2777 of file FIRRTLFolds.cpp.
References assert(), and circt::firrtl::data.
|
static |
Definition at line 3834 of file FIRRTLFolds.cpp.
References circt::firrtl::FIRRTLTypeSwitch< T, ResultT >::Case(), and isTypeEmpty().
Referenced by isTypeEmpty().
|
static |
Return true if this value is 1 bit UInt.
Definition at line 94 of file FIRRTLFolds.cpp.
|
static |
Definition at line 60 of file FIRRTLFolds.cpp.
References assert(), and isOkToPropagateName().
|
static |
A wrapper of PatternRewriter::replaceOp to propagate "name" attribute.
If a replaced op has a "name" attribute, this function propagates the name to the new value.
Definition at line 123 of file FIRRTLFolds.cpp.
References updateName().
Referenced by canonicalizePrimOp(), canonicalizeSingleSetConnect(), and BitsOfCat::matchAndRewrite().
|
static |
A wrapper of PatternRewriter::replaceOpWithNewOp to propagate "name" attribute.
If a replaced op has a "name" attribute, this function propagates the name to the new value.
Definition at line 136 of file FIRRTLFolds.cpp.
References updateName().
|
static |
Replaces the given op with the contents of the given single-block region.
Definition at line 2354 of file FIRRTLFolds.cpp.
References assert().
|
static |
Definition at line 2794 of file FIRRTLFolds.cpp.
References assert().
|
static |
Replace the specified operation with a 'bits' op from the specified hi/lo bits.
Insert a cast to handle the case where the original operation returned a signed integer.
Definition at line 1734 of file FIRRTLFolds.cpp.
|
static |
Set the name of an op based on the best of two names: The current name, and the name passed in.
Definition at line 103 of file FIRRTLFolds.cpp.
References assert(), circt::chooseName(), and isOkToPropagateName().
Referenced by replaceOpAndCopyName(), and replaceOpWithNewOpAndCopyName().