CIRCT 22.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/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 209 of file FIRRTLFolds.cpp.
|
static |
Definition at line 3514 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 292 of file FIRRTLFolds.cpp.
References assert(), and replaceOpAndCopyName().
|
static |
Definition at line 3628 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2584 of file FIRRTLFolds.cpp.
References dropWrite(), and isDefinedByOneConstantOp().
|
static |
Definition at line 2070 of file FIRRTLFolds.cpp.
References empty, circt::firrtl::getSingleConnectUserOf(), circt::firrtl::hasDontTouch(), circt::firrtl::hasDroppableName(), and replaceOpAndCopyName().
|
static |
Definition at line 2467 of file FIRRTLFolds.cpp.
|
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 221 of file FIRRTLFolds.cpp.
References assert(), Compare, DivideOrShift, getExtendedConstant(), circt::firrtl::getIntAttr(), and Normal.
|
static |
Definition at line 2287 of file FIRRTLFolds.cpp.
References circt::firrtl::detail::replaceWithNewForceability().
|
static |
Definition at line 32 of file FIRRTLFolds.cpp.
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 3657 of file FIRRTLFolds.cpp.
References circt::isConstantZero().
|
static |
Definition at line 3490 of file FIRRTLFolds.cpp.
Referenced by canonicalizeConcurrentVerifOp(), canonicalizeImmediateVerifOp(), and canonicalizeImmediateVerifOp().
|
static |
Definition at line 2671 of file FIRRTLFolds.cpp.
References assert().
|
static |
Definition at line 3407 of file FIRRTLFolds.cpp.
References circt::firrtl::getSingleConnectUserOf().
|
static |
Definition at line 1601 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 181 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 2151 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 160 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 362 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 350 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 356 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2608 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 82 of file FIRRTLFolds.cpp.
|
static |
Determine whether a constant operand is a one value for the sake of constant folding.
Definition at line 201 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 193 of file FIRRTLFolds.cpp.
References getConstant().
|
static |
Definition at line 3651 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2575 of file FIRRTLFolds.cpp.
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 47 of file FIRRTLFolds.cpp.
Referenced by moveNameHint(), and updateName().
|
static |
Definition at line 2627 of file FIRRTLFolds.cpp.
References getPortFieldValue().
|
static |
Definition at line 2638 of file FIRRTLFolds.cpp.
References assert(), and circt::firrtl::data.
|
static |
Definition at line 3707 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 93 of file FIRRTLFolds.cpp.
|
static |
Definition at line 59 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 122 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 135 of file FIRRTLFolds.cpp.
References updateName().
|
static |
Replaces the given op with the contents of the given single-block region.
Definition at line 2209 of file FIRRTLFolds.cpp.
References assert().
|
static |
Definition at line 2655 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 1585 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 102 of file FIRRTLFolds.cpp.
References assert(), circt::chooseName(), and isOkToPropagateName().
Referenced by replaceOpAndCopyName(), and replaceOpWithNewOpAndCopyName().