CIRCT  20.0.0git
Macros | Functions
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. More...
 
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. More...
 
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. More...
 
static ParamExprAttr dyn_castPE (PEO opcode, Attribute value)
 If the specified attribute is a ParamExprAttr with the specified opcode, return it. More...
 
static bool paramExprOperandSortPredicate (Attribute lhs, Attribute rhs)
 This implements a < comparison for two operands to an associative operation imposing an ordering upon them. More...
 
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. More...
 
static std::pair< TypedAttr, TypedAttr > decomposeAddend (TypedAttr operand)
 Analyze an operand to an add. More...
 
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()

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

Definition at line 72 of file HWAttributes.cpp.

References append().

◆ decomposeAddend()

static 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 610 of file HWAttributes.cpp.

References dyn_castPE(), and circt::calyx::direction::get().

Referenced by simplifyAdd().

◆ dyn_castPE()

static 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 473 of file HWAttributes.cpp.

Referenced by decomposeAddend(), and simplifyMul().

◆ evaluateParametricArrayType()

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

Definition at line 1017 of file HWAttributes.cpp.

◆ foldBinaryOp()

static 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 449 of file HWAttributes.cpp.

References assert(), and circt::calyx::direction::get().

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

◆ foldUnaryOp()

static 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 463 of file HWAttributes.cpp.

References assert(), and circt::calyx::direction::get().

Referenced by simplifyCLog2().

◆ getOneOfType()

static TypedAttr getOneOfType ( Type  type)
static

Definition at line 619 of file HWAttributes.cpp.

References circt::calyx::direction::get().

Referenced by simplifyAdd().

◆ isParamAttrWithParamRef()

static bool isParamAttrWithParamRef ( Attribute  expr)
static

Definition at line 1067 of file HWAttributes.cpp.

◆ paramExprOperandSortPredicate()

static 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 487 of file HWAttributes.cpp.

◆ parseParamExprWithOpcode()

static 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 918 of file HWAttributes.cpp.

◆ printSymbolName()

static void printSymbolName ( AsmPrinter &  p,
StringAttr  sym 
)
static

Definition at line 233 of file HWAttributes.cpp.

◆ replaceDeclRefInExpr()

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

Definition at line 947 of file HWAttributes.cpp.

◆ simplifyAdd()

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

◆ simplifyAnd()

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

Definition at line 702 of file HWAttributes.cpp.

References simplifyAssocOp().

◆ simplifyAssocOp()

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 = {} 
)
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 552 of file HWAttributes.cpp.

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

◆ simplifyCLog2()

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

Definition at line 801 of file HWAttributes.cpp.

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

◆ simplifyDivS()

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

Definition at line 771 of file HWAttributes.cpp.

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

◆ simplifyDivU()

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

Definition at line 761 of file HWAttributes.cpp.

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

◆ simplifyModS()

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

◆ simplifyModU()

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

◆ simplifyMul()

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

Definition at line 672 of file HWAttributes.cpp.

References dyn_castPE(), circt::calyx::direction::get(), and simplifyAssocOp().

◆ simplifyOr()

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

Definition at line 709 of file HWAttributes.cpp.

References simplifyAssocOp().

◆ simplifyShl()

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

◆ simplifyShrS()

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

Definition at line 751 of file HWAttributes.cpp.

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

◆ simplifyShrU()

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

Definition at line 741 of file HWAttributes.cpp.

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

◆ simplifyStrConcat()

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

Definition at line 809 of file HWAttributes.cpp.

References assert(), and circt::calyx::direction::get().

◆ simplifyXor()

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

Definition at line 716 of file HWAttributes.cpp.

References simplifyAssocOp().