MLIR 22.0.0git
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/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/Endian.h"
#include <optional>
#include "mlir/IR/BuiltinAttributes.cpp.inc"

Go to the source code of this file.

Namespaces

namespace  mlir
 Include the generated interface declarations.
namespace  mlir::detail
 AttrTypeReplacer.

Macros

#define DEBUG_TYPE   "builtinattributes"
#define GET_ATTRDEF_CLASSES
 Tablegen Attribute Definitions.
#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.
static std::optional< NamedAttributefindDuplicateElement (ArrayRef< NamedAttribute > value)
 Returns an entry with a duplicate name from the given sorted array of named attributes.
static size_t getDenseElementStorageWidth (size_t origWidth)
 Get the bitwidth of a dense element type within the buffer.
static size_t getDenseElementStorageWidth (Type elementType)
static void setBit (char *rawData, size_t bitPos, bool value)
 Set a bit to a specific value.
static bool getBit (const char *rawData, size_t bitPos)
 Return the value of the specified bit.
static void copyAPIntToArrayForBEmachine (APInt value, size_t numBytes, char *result)
 Copy actual numBytes data from value (APInt) to char array(result) for BE format.
static void copyArrayToAPIntForBEmachine (const char *inArray, size_t numBytes, APInt &result)
 Copy numBytes data from inArray(char array) to result(APINT) for BE format.
static void writeBits (char *rawData, size_t bitPos, APInt value)
 Writes value to the bit position bitPos in array rawData.
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.
template<typename Values>
static bool hasSameNumElementsOrSplat (ShapedType type, const Values &values)
 Returns true if 'values' corresponds to a splat, i.e.
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.
static bool isComplexOfIntType (Type type)
 Return if the given complex type has an integer element type.
template<typename APRangeT>
static void writeAPIntsToBuffer (size_t storageWidth, SmallVectorImpl< char > &data, APRangeT &&values)
 Utility method to write a range of APInt values to a buffer.
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 26 of file BuiltinAttributes.cpp.

◆ GET_ATTRDEF_CLASSES

#define GET_ATTRDEF_CLASSES

Tablegen Attribute Definitions.

Definition at line 35 of file BuiltinAttributes.cpp.

◆ GET_ATTRDEF_LIST

#define GET_ATTRDEF_LIST

Function Documentation

◆ copyAPIntToArrayForBEmachine()

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 483 of file BuiltinAttributes.cpp.

References result.

Referenced by writeBits().

◆ copyArrayToAPIntForBEmachine()

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 512 of file BuiltinAttributes.cpp.

References result.

Referenced by readBits().

◆ dictionaryAttrSort()

template<bool inPlace>
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 59 of file BuiltinAttributes.cpp.

◆ findDuplicateElement()

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 101 of file BuiltinAttributes.cpp.

◆ getBit()

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

Return the value of the specified bit.

Definition at line 477 of file BuiltinAttributes.cpp.

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

◆ getDenseElementStorageWidth() [1/2]

◆ getDenseElementStorageWidth() [2/2]

size_t getDenseElementStorageWidth ( Type elementType)
static

◆ hasSameNumElementsOrSplat()

template<typename Values>
bool hasSameNumElementsOrSplat ( 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 600 of file BuiltinAttributes.cpp.

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

◆ isComplexOfIntType()

bool isComplexOfIntType ( Type type)
static

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

Definition at line 1189 of file BuiltinAttributes.cpp.

References getElementType().

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

◆ isValidIntOrFloat()

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 1117 of file BuiltinAttributes.cpp.

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

◆ mappingHelper()

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

◆ readBits()

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 572 of file BuiltinAttributes.cpp.

References copyArrayToAPIntForBEmachine(), getBit(), and result.

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

◆ setBit()

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

Set a bit to a specific value.

Definition at line 469 of file BuiltinAttributes.cpp.

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

◆ writeAPIntsToBuffer()

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

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

Definition at line 1311 of file BuiltinAttributes.cpp.

References writeBits().

◆ writeBits()

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

Writes value to the bit position bitPos in array rawData.

Definition at line 546 of file BuiltinAttributes.cpp.

References copyAPIntToArrayForBEmachine(), and setBit().

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