CIRCT 24.0.0git
Loading...
Searching...
No Matches
HWAttributes.cpp File Reference
#include "circt/Dialect/HW/HWAttributes.h"
#include "circt/Dialect/HW/HWDialect.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/HW/HWTypes.h"
#include "circt/Support/LLVM.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "circt/Dialect/HW/HWAttributes.cpp.inc"
Include dependency graph for HWAttributes.cpp:

Go to the source code of this file.

Macros

#define GET_ATTRDEF_CLASSES
#define GET_ATTRDEF_LIST

Functions

static Attribute parseParamExprWithOpcode (StringRef opcodeStr, DialectAsmParser &p, Type type)
 Internal method used for .mlir file parsing when parsing the "#hw.param.expr.mul" form of the attribute.
static std::string canonicalizeFilename (const Twine &directory, const Twine &filename)
static void printSymbolName (AsmPrinter &p, StringAttr sym)
static TypedAttr foldBinaryOp (ArrayRef< TypedAttr > operands, llvm::function_ref< APInt(const APInt &, const APInt &)> calculate)
 Given a binary function, if the two operands are known constant integers, use the specified fold function to compute the result.
static TypedAttr foldUnaryOp (ArrayRef< TypedAttr > operands, llvm::function_ref< APInt(const APInt &)> calculate)
 Given a unary function, if the operand is a known constant integer, use the specified fold function to compute the result.
static ParamExprAttr dyn_castPE (PEO opcode, Attribute value)
 If the specified attribute is a ParamExprAttr with the specified opcode, return it.
static bool paramExprOperandSortPredicate (Attribute lhs, Attribute rhs)
 This implements a < comparison for two operands to an associative operation imposing an ordering upon them.
static TypedAttr simplifyAssocOp (PEO opcode, SmallVector< TypedAttr, 4 > &operands, llvm::function_ref< APInt(const APInt &, const APInt &)> calculateFn, llvm::function_ref< bool(const APInt &)> identityConstantFn, llvm::function_ref< bool(const APInt &)> destructiveConstantFn={})
 Given a fully associative variadic integer operation, constant fold any constant operands and move them to the right.
static std::pair< TypedAttr, TypedAttr > decomposeAddend (TypedAttr operand)
 Analyze an operand to an add.
static TypedAttr getOneOfType (Type type)
static TypedAttr simplifyAdd (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyMul (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyAnd (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyOr (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyXor (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyShl (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyShrU (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyShrS (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyDivU (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyDivS (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyModU (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyModS (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyCLog2 (SmallVector< TypedAttr, 4 > &operands)
static TypedAttr simplifyStrConcat (SmallVector< TypedAttr, 4 > &operands)
static FailureOr< Attribute > replaceDeclRefInExpr (Location loc, const std::map< std::string, Attribute > &parameters, Attribute paramAttr, bool emitErrors)
template<typename TArray>
FailureOr< Type > evaluateParametricArrayType (Location loc, ArrayAttr parameters, TArray arrayType, bool emitErrors)
static bool isParamAttrWithParamRef (Attribute expr)

Macro Definition Documentation

◆ GET_ATTRDEF_CLASSES

#define GET_ATTRDEF_CLASSES

Definition at line 34 of file HWAttributes.cpp.

◆ GET_ATTRDEF_LIST

#define GET_ATTRDEF_LIST

Function Documentation

◆ canonicalizeFilename()

std::string canonicalizeFilename ( const Twine & directory,
const Twine & filename )
static

Definition at line 72 of file HWAttributes.cpp.

◆ decomposeAddend()

std::pair< TypedAttr, TypedAttr > decomposeAddend ( TypedAttr operand)
static

Analyze an operand to an add.

If it is a multiplication by a constant (e.g. (a*b*42) then split it into the non-constant and the constant portions (e.g. a*b and 42). Otherwise return the operand as the first value and null as the second (standin for "multiplication by 1").

Definition at line 613 of file HWAttributes.cpp.

References dyn_castPE().

Referenced by simplifyAdd().

◆ dyn_castPE()

ParamExprAttr dyn_castPE ( PEO opcode,
Attribute value )
static

If the specified attribute is a ParamExprAttr with the specified opcode, return it.

Otherwise return null.

Definition at line 476 of file HWAttributes.cpp.

Referenced by decomposeAddend(), and simplifyMul().

◆ evaluateParametricArrayType()

template<typename TArray>
FailureOr< Type > evaluateParametricArrayType ( Location loc,
ArrayAttr parameters,
TArray arrayType,
bool emitErrors )

◆ foldBinaryOp()

TypedAttr foldBinaryOp ( ArrayRef< TypedAttr > operands,
llvm::function_ref< APInt(const APInt &, const APInt &)> calculate )
static

Given a binary function, if the two operands are known constant integers, use the specified fold function to compute the result.

Definition at line 452 of file HWAttributes.cpp.

References assert().

Referenced by simplifyDivS(), simplifyDivU(), simplifyModS(), simplifyModU(), simplifyShrS(), and simplifyShrU().

◆ foldUnaryOp()

TypedAttr foldUnaryOp ( ArrayRef< TypedAttr > operands,
llvm::function_ref< APInt(const APInt &)> calculate )
static

Given a unary function, if the operand is a known constant integer, use the specified fold function to compute the result.

Definition at line 466 of file HWAttributes.cpp.

References assert().

Referenced by simplifyCLog2().

◆ getOneOfType()

TypedAttr getOneOfType ( Type type)
static

Definition at line 622 of file HWAttributes.cpp.

Referenced by simplifyAdd().

◆ isParamAttrWithParamRef()

bool isParamAttrWithParamRef ( Attribute expr)
static

Definition at line 1070 of file HWAttributes.cpp.

References isParamAttrWithParamRef().

Referenced by isParamAttrWithParamRef(), and circt::hw::isParametricType().

◆ paramExprOperandSortPredicate()

bool paramExprOperandSortPredicate ( Attribute lhs,
Attribute rhs )
static

This implements a < comparison for two operands to an associative operation imposing an ordering upon them.

The ordering provided puts more complex things to the start of the list, from left to right: expressions :: verbatims :: decl.refs :: constant

Definition at line 490 of file HWAttributes.cpp.

References paramExprOperandSortPredicate().

Referenced by paramExprOperandSortPredicate().

◆ parseParamExprWithOpcode()

Attribute parseParamExprWithOpcode ( StringRef opcode,
DialectAsmParser & p,
Type type )
static

Internal method used for .mlir file parsing when parsing the "#hw.param.expr.mul" form of the attribute.

Definition at line 921 of file HWAttributes.cpp.

◆ printSymbolName()

void printSymbolName ( AsmPrinter & p,
StringAttr sym )
static

Definition at line 236 of file HWAttributes.cpp.

◆ replaceDeclRefInExpr()

FailureOr< Attribute > replaceDeclRefInExpr ( Location loc,
const std::map< std::string, Attribute > & parameters,
Attribute paramAttr,
bool emitErrors )
static

Definition at line 950 of file HWAttributes.cpp.

References failure(), and replaceDeclRefInExpr().

Referenced by replaceDeclRefInExpr().

◆ simplifyAdd()

TypedAttr simplifyAdd ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 626 of file HWAttributes.cpp.

References decomposeAddend(), getOneOfType(), and simplifyAssocOp().

◆ simplifyAnd()

TypedAttr simplifyAnd ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 705 of file HWAttributes.cpp.

References simplifyAssocOp().

◆ simplifyAssocOp()

TypedAttr simplifyAssocOp ( PEO opcode,
SmallVector< TypedAttr, 4 > & operands,
llvm::function_ref< APInt(const APInt &, const APInt &)> calculateFn,
llvm::function_ref< bool(const APInt &)> identityConstantFn,
llvm::function_ref< bool(const APInt &)> destructiveConstantFn = {} )
static

Given a fully associative variadic integer operation, constant fold any constant operands and move them to the right.

If the whole expression is constant, then return that, otherwise update the operands list.

Definition at line 555 of file HWAttributes.cpp.

Referenced by simplifyAdd(), simplifyAnd(), simplifyMul(), simplifyOr(), and simplifyXor().

◆ simplifyCLog2()

TypedAttr simplifyCLog2 ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 804 of file HWAttributes.cpp.

References assert(), foldUnaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyDivS()

TypedAttr simplifyDivS ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 774 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyDivU()

TypedAttr simplifyDivU ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 764 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyModS()

TypedAttr simplifyModS ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 794 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyModU()

TypedAttr simplifyModU ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 784 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyMul()

TypedAttr simplifyMul ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 675 of file HWAttributes.cpp.

References dyn_castPE(), and simplifyAssocOp().

◆ simplifyOr()

TypedAttr simplifyOr ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 712 of file HWAttributes.cpp.

References simplifyAssocOp().

◆ simplifyShl()

TypedAttr simplifyShl ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 725 of file HWAttributes.cpp.

References assert(), and circt::hw::isHWIntegerType().

◆ simplifyShrS()

TypedAttr simplifyShrS ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 754 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyShrU()

TypedAttr simplifyShrU ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 744 of file HWAttributes.cpp.

References assert(), foldBinaryOp(), and circt::hw::isHWIntegerType().

◆ simplifyStrConcat()

TypedAttr simplifyStrConcat ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 812 of file HWAttributes.cpp.

References assert().

◆ simplifyXor()

TypedAttr simplifyXor ( SmallVector< TypedAttr, 4 > & operands)
static

Definition at line 719 of file HWAttributes.cpp.

References simplifyAssocOp().