CIRCT
20.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.
Namespaces | |
circt | |
The InstanceGraph op interface, see InstanceGraphInterface.td for more details. | |
circt::firrtl | |
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 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. More... | |
static bool | isUInt1 (Type type) |
Return true if this value is 1 bit UInt. More... | |
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. More... | |
static void | replaceOpAndCopyName (PatternRewriter &rewriter, Operation *op, Value newValue) |
A wrapper of PatternRewriter::replaceOp to propagate "name" attribute. More... | |
template<typename OpTy , typename... Args> | |
static OpTy | replaceOpWithNewOpAndCopyName (PatternRewriter &rewriter, Operation *op, Args &&...args) |
A wrapper of PatternRewriter::replaceOpWithNewOp to propagate "name" attribute. More... | |
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. More... | |
static std::optional< APSInt > | getConstant (Attribute operand) |
Determine the value of a constant operand for the sake of constant folding. More... | |
static bool | isConstantZero (Attribute operand) |
Determine whether a constant operand is a zero value for the sake of constant folding. More... | |
static bool | isConstantOne (Attribute operand) |
Determine whether a constant operand is a one value for the sake of constant folding. More... | |
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. More... | |
static LogicalResult | canonicalizePrimOp (Operation *op, PatternRewriter &rewriter, const function_ref< OpFoldResult(ArrayRef< Attribute >)> &canonicalize) |
Applies the canonicalization function canonicalize to the given operation. More... | |
static APInt | getMaxUnsignedValue (unsigned bitWidth) |
Get the largest unsigned value of a given bit width. More... | |
static APInt | getMinSignedValue (unsigned bitWidth) |
Get the smallest signed value of a given bit width. More... | |
static APInt | getMaxSignedValue (unsigned bitWidth) |
Get the largest signed value of a given bit width. More... | |
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. More... | |
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. More... | |
static void | replaceOpWithRegion (PatternRewriter &rewriter, Operation *op, Region ®ion) |
Replaces the given op with the contents of the given single-block region. More... | |
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 198 of file FIRRTLFolds.cpp.
|
static |
Definition at line 3176 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 281 of file FIRRTLFolds.cpp.
References assert(), AssertLikeOp::canonicalize(), replaceOpAndCopyName(), and width.
|
static |
Definition at line 3287 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2270 of file FIRRTLFolds.cpp.
References dropWrite(), isDefinedByOneConstantOp(), and seq::reg().
|
static |
Definition at line 1753 of file FIRRTLFolds.cpp.
References circt::firrtl::getSingleConnectUserOf(), circt::firrtl::hasDontTouch(), circt::firrtl::hasDroppableName(), and replaceOpAndCopyName().
|
static |
Definition at line 2153 of file FIRRTLFolds.cpp.
References circt::calyx::direction::get().
|
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 210 of file FIRRTLFolds.cpp.
References assert(), Compare, DivideOrShift, getExtendedConstant(), circt::firrtl::getIntAttr(), and Normal.
|
static |
Definition at line 1972 of file FIRRTLFolds.cpp.
References circt::firrtl::detail::replaceWithNewForceability().
|
static |
Definition at line 32 of file FIRRTLFolds.cpp.
References Python.support::connect().
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 3316 of file FIRRTLFolds.cpp.
References circt::isConstantZero().
|
static |
Definition at line 3152 of file FIRRTLFolds.cpp.
Referenced by canonicalizeImmediateVerifOp().
|
static |
Definition at line 2353 of file FIRRTLFolds.cpp.
References assert(), Python.support::connect(), circt::calyx::direction::get(), and seq::reg().
|
static |
Definition at line 3069 of file FIRRTLFolds.cpp.
References circt::firrtl::getSingleConnectUserOf(), and seq::reg().
|
static |
Definition at line 1282 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 170 of file FIRRTLFolds.cpp.
Referenced by 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 1835 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 149 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 351 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 339 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 345 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2290 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 71 of file FIRRTLFolds.cpp.
|
static |
Determine whether a constant operand is a one value for the sake of constant folding.
Definition at line 190 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 182 of file FIRRTLFolds.cpp.
References getConstant().
|
static |
Definition at line 3310 of file FIRRTLFolds.cpp.
|
static |
Definition at line 2261 of file FIRRTLFolds.cpp.
Referenced by canonicalizeRegResetWithOneReset().
|
static |
Definition at line 2309 of file FIRRTLFolds.cpp.
References getPortFieldValue().
|
static |
Definition at line 2320 of file FIRRTLFolds.cpp.
References assert(), and circt::firrtl::data.
|
static |
Definition at line 3366 of file FIRRTLFolds.cpp.
References circt::firrtl::FIRRTLTypeSwitch< T, ResultT >::Case().
|
static |
Return true if this value is 1 bit UInt.
Definition at line 82 of file FIRRTLFolds.cpp.
|
static |
Definition at line 48 of file FIRRTLFolds.cpp.
References assert().
|
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 111 of file FIRRTLFolds.cpp.
References updateName().
Referenced by canonicalizePrimOp(), and canonicalizeSingleSetConnect().
|
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 124 of file FIRRTLFolds.cpp.
References updateName().
|
static |
Replaces the given op with the contents of the given single-block region.
Definition at line 1893 of file FIRRTLFolds.cpp.
References assert().
|
static |
Definition at line 2337 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 1266 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 91 of file FIRRTLFolds.cpp.
References assert(), and circt::chooseName().
Referenced by replaceOpAndCopyName(), and replaceOpWithNewOpAndCopyName().