MLIR  19.0.0git
Namespaces | Macros | Functions
BuiltinAttributes.cpp File Reference
#include "mlir/IR/BuiltinAttributes.h"
#include "AttributeDetail.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/BuiltinDialect.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/DialectResourceBlobManager.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/Types.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include <optional>
#include "mlir/IR/BuiltinAttributes.cpp.inc"

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 
 mlir::detail
 Detect if any of the given parameter types has a sub-element handler.
 

Macros

#define DEBUG_TYPE   "builtinattributes"
 
#define GET_ATTRDEF_CLASSES
 Tablegen Attribute Definitions. More...
 
#define GET_ATTRDEF_LIST
 

Functions

template<bool inPlace>
static bool dictionaryAttrSort (ArrayRef< NamedAttribute > value, SmallVectorImpl< NamedAttribute > &storage)
 Helper function that does either an in place sort or sorts from source array into destination. More...
 
static std::optional< NamedAttributefindDuplicateElement (ArrayRef< NamedAttribute > value)
 Returns an entry with a duplicate name from the given sorted array of named attributes. More...
 
static size_t getDenseElementStorageWidth (size_t origWidth)
 Get the bitwidth of a dense element type within the buffer. More...
 
static size_t getDenseElementStorageWidth (Type elementType)
 
static void setBit (char *rawData, size_t bitPos, bool value)
 Set a bit to a specific value. More...
 
static bool getBit (const char *rawData, size_t bitPos)
 Return the value of the specified bit. More...
 
static void copyAPIntToArrayForBEmachine (APInt value, size_t numBytes, char *result)
 Copy actual numBytes data from value (APInt) to char array(result) for BE format. More...
 
static void copyArrayToAPIntForBEmachine (const char *inArray, size_t numBytes, APInt &result)
 Copy numBytes data from inArray(char array) to result(APINT) for BE format. More...
 
static void writeBits (char *rawData, size_t bitPos, APInt value)
 Writes value to the bit position bitPos in array rawData. More...
 
static APInt readBits (const char *rawData, size_t bitPos, size_t bitWidth)
 Reads the next bitWidth bits from the bit position bitPos in array rawData. More...
 
template<typename Values >
static bool hasSameElementsOrSplat (ShapedType type, const Values &values)
 Returns true if 'values' corresponds to a splat, i.e. More...
 
static bool isValidIntOrFloat (Type type, int64_t dataEltSize, bool isInt, bool isSigned)
 Check the information for a C++ data type, check if this type is valid for the current attribute. More...
 
static bool isComplexOfIntType (Type type)
 Return if the given complex type has an integer element type. More...
 
template<typename APRangeT >
static void writeAPIntsToBuffer (size_t storageWidth, std::vector< char > &data, APRangeT &&values)
 Utility method to write a range of APInt values to a buffer. More...
 
template<typename Fn , typename Attr >
static ShapedType mappingHelper (Fn mapping, Attr &attr, ShapedType inType, Type newElementType, llvm::SmallVectorImpl< char > &data)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "builtinattributes"

Definition at line 27 of file BuiltinAttributes.cpp.

◆ GET_ATTRDEF_CLASSES

#define GET_ATTRDEF_CLASSES

Tablegen Attribute Definitions.

Definition at line 36 of file BuiltinAttributes.cpp.

◆ GET_ATTRDEF_LIST

#define GET_ATTRDEF_LIST

Function Documentation

◆ copyAPIntToArrayForBEmachine()

static void copyAPIntToArrayForBEmachine ( APInt  value,
size_t  numBytes,
char *  result 
)
static

Copy actual numBytes data from value (APInt) to char array(result) for BE format.

Definition at line 471 of file BuiltinAttributes.cpp.

Referenced by writeBits().

◆ copyArrayToAPIntForBEmachine()

static void copyArrayToAPIntForBEmachine ( const char *  inArray,
size_t  numBytes,
APInt &  result 
)
static

Copy numBytes data from inArray(char array) to result(APINT) for BE format.

Definition at line 500 of file BuiltinAttributes.cpp.

Referenced by readBits().

◆ dictionaryAttrSort()

template<bool inPlace>
static bool dictionaryAttrSort ( ArrayRef< NamedAttribute value,
SmallVectorImpl< NamedAttribute > &  storage 
)
static

Helper function that does either an in place sort or sorts from source array into destination.

If inPlace then storage is both the source and the destination, else value is the source and storage destination. Returns whether source was sorted.

Definition at line 60 of file BuiltinAttributes.cpp.

◆ findDuplicateElement()

static std::optional<NamedAttribute> findDuplicateElement ( ArrayRef< NamedAttribute value)
static

Returns an entry with a duplicate name from the given sorted array of named attributes.

Returns std::nullopt if all elements have unique names.

Definition at line 102 of file BuiltinAttributes.cpp.

◆ getBit()

static bool getBit ( const char *  rawData,
size_t  bitPos 
)
static

Return the value of the specified bit.

Definition at line 465 of file BuiltinAttributes.cpp.

Referenced by mlir::DenseElementsAttr::BoolElementIterator::operator*(), and readBits().

◆ getDenseElementStorageWidth() [1/2]

static size_t getDenseElementStorageWidth ( size_t  origWidth)
static

Get the bitwidth of a dense element type within the buffer.

DenseElementsAttr requires bitwidths greater than 1 to be aligned by 8.

Definition at line 449 of file BuiltinAttributes.cpp.

Referenced by mlir::DenseElementsAttr::get(), getDenseElementStorageWidth(), mlir::DenseElementsAttr::isValidRawBuffer(), mappingHelper(), mlir::DenseElementsAttr::IntElementIterator::operator*(), and mlir::DenseElementsAttr::ComplexIntElementIterator::operator*().

◆ getDenseElementStorageWidth() [2/2]

static size_t getDenseElementStorageWidth ( Type  elementType)
static

◆ hasSameElementsOrSplat()

template<typename Values >
static bool hasSameElementsOrSplat ( ShapedType  type,
const Values &  values 
)
static

Returns true if 'values' corresponds to a splat, i.e.

one element, or has the same element count as 'type'.

Definition at line 588 of file BuiltinAttributes.cpp.

Referenced by mlir::DenseElementsAttr::get().

◆ isComplexOfIntType()

static bool isComplexOfIntType ( Type  type)
static

Return if the given complex type has an integer element type.

Definition at line 1179 of file BuiltinAttributes.cpp.

References mlir::DenseElementsAttr::getElementType().

Referenced by mlir::DenseElementsAttr::tryGetComplexIntValues().

◆ isValidIntOrFloat()

static bool isValidIntOrFloat ( Type  type,
int64_t  dataEltSize,
bool  isInt,
bool  isSigned 
)
static

Check the information for a C++ data type, check if this type is valid for the current attribute.

This method is used to verify specific type invariants that the templatized 'getValues' method cannot.

Definition at line 1101 of file BuiltinAttributes.cpp.

References mlir::detail::getDenseElementBitWidth(), and mlir::Type::isIndex().

Referenced by mlir::DenseElementsAttr::isValidComplex(), and mlir::DenseElementsAttr::isValidIntOrFloat().

◆ mappingHelper()

template<typename Fn , typename Attr >
static ShapedType mappingHelper ( Fn  mapping,
Attr &  attr,
ShapedType  inType,
Type  newElementType,
llvm::SmallVectorImpl< char > &  data 
)
static

◆ readBits()

static APInt readBits ( const char *  rawData,
size_t  bitPos,
size_t  bitWidth 
)
static

Reads the next bitWidth bits from the bit position bitPos in array rawData.

Definition at line 560 of file BuiltinAttributes.cpp.

References copyArrayToAPIntForBEmachine(), mlir::detail::divideCeil(), and getBit().

Referenced by mlir::DenseElementsAttr::IntElementIterator::operator*(), and mlir::DenseElementsAttr::ComplexIntElementIterator::operator*().

◆ setBit()

static void setBit ( char *  rawData,
size_t  bitPos,
bool  value 
)
static

Set a bit to a specific value.

Definition at line 457 of file BuiltinAttributes.cpp.

Referenced by mlir::DenseElementsAttr::get(), and writeBits().

◆ writeAPIntsToBuffer()

template<typename APRangeT >
static void writeAPIntsToBuffer ( size_t  storageWidth,
std::vector< char > &  data,
APRangeT &&  values 
)
static

Utility method to write a range of APInt values to a buffer.

Definition at line 1301 of file BuiltinAttributes.cpp.

References mlir::detail::divideCeil(), and writeBits().

◆ writeBits()

static void writeBits ( char *  rawData,
size_t  bitPos,
APInt  value 
)
static

Writes value to the bit position bitPos in array rawData.

Definition at line 534 of file BuiltinAttributes.cpp.

References copyAPIntToArrayForBEmachine(), mlir::detail::divideCeil(), and setBit().

Referenced by mlir::DenseElementsAttr::get(), mappingHelper(), and writeAPIntsToBuffer().