13 #ifndef ATTRIBUTEDETAIL_H_    14 #define ATTRIBUTEDETAIL_H_    23 #include "llvm/ADT/APFloat.h"    24 #include "llvm/ADT/PointerIntPair.h"    25 #include "llvm/Support/TrailingObjects.h"    70   using KeyTy = std::pair<MLIRContext *, bool>;
    93       private llvm::TrailingObjects<DictionaryAttributeStorage,
   107     auto size = DictionaryAttributeStorage::totalSizeToAlloc<NamedAttribute>(
   113     std::uninitialized_copy(key.begin(), key.end(),
   120     return {getTrailingObjects<NamedAttribute>(), numElements};
   124   friend class llvm::TrailingObjects<DictionaryAttributeStorage,
   128   size_t numTrailingObjects(OverloadToken<NamedAttribute>)
 const {
   131   DictionaryAttributeStorage(
unsigned numElements) : numElements(numElements) {}
   134   const unsigned numElements;
   140       public llvm::TrailingObjects<FloatAttributeStorage, uint64_t> {
   141   using KeyTy = std::pair<Type, APFloat>;
   149     return key.first == 
getType() && key.second.bitwiseIsEqual(getValue());
   160       return KeyTy(type, APFloat(value));
   166                 APFloat::rmNearestTiesToEven, &unused);
   167     return KeyTy(type, val);
   173     const auto &apint = key.second.bitcastToAPInt();
   179         FloatAttributeStorage::totalSizeToAlloc<uint64_t>(elements.size());
   182         key.second.getSemantics(), key.first, elements.size());
   183     std::uninitialized_copy(elements.begin(), elements.end(),
   184                             result->getTrailingObjects<uint64_t>());
   190     auto val = APInt(APFloat::getSizeInBits(semantics),
   191                      {getTrailingObjects<uint64_t>(), numObjects});
   192     return APFloat(semantics, val);
   202       public llvm::TrailingObjects<IntegerAttributeStorage, uint64_t> {
   203   using KeyTy = std::pair<Type, APInt>;
   223     std::tie(type, value) = key;
   227         IntegerAttributeStorage::totalSizeToAlloc<uint64_t>(elements.size());
   230     std::uninitialized_copy(elements.begin(), elements.end(),
   231                             result->getTrailingObjects<uint64_t>());
   238       return APInt(64, {getTrailingObjects<uint64_t>(), numObjects});
   239     return APInt(
getType().getIntOrFloatBitWidth(),
   240                  {getTrailingObjects<uint64_t>(), numObjects});
   270         attrData(attrData) {}
   273   using KeyTy = std::tuple<Identifier, StringRef, Type>;
   275     return key == 
KeyTy(dialectNamespace, attrData, 
getType());
   282                                allocator.
copyInto(std::get<1>(key)),
   295   using KeyTy = std::pair<StringRef, Type>;
   318       public llvm::TrailingObjects<SymbolRefAttributeStorage,
   320   using KeyTy = std::pair<StringRef, ArrayRef<FlatSymbolRefAttr>>;
   323       : value(value), numNestedRefs(numNestedRefs) {}
   333     auto size = SymbolRefAttributeStorage::totalSizeToAlloc<FlatSymbolRefAttr>(
   337         allocator.
copyInto(key.first), key.second.size());
   338     std::uninitialized_copy(key.second.begin(), key.second.end(),
   345     return {getTrailingObjects<FlatSymbolRefAttr>(), numNestedRefs};
   379           bool isSplat = 
false)
   380         : type(type), data(data), hashCode(hashCode), isSplat(isSplat) {}
   396                                 bool isSplat = 
false)
   412         return (key.
data.front() & 1) == data.front();
   416     return key.
data == data;
   426       return KeyTy(ty, data, 0);
   437     assert(numElements != 1 && 
"splat of 1 element should already be detected");
   441     if (elementWidth == 1)
   442       return getKeyForBoolData(ty, data, numElements);
   450     size_t storageSize = llvm::divideCeil(elementWidth, CHAR_BIT);
   451     assert(((data.size() / storageSize) == numElements) &&
   452            "data does not hold expected number of elements");
   455     auto firstElt = data.take_front(storageSize);
   460     for (
size_t i = storageSize, e = data.size(); i != e; i += storageSize)
   461       if (memcmp(data.data(), &data[i], storageSize))
   462         return KeyTy(ty, data, llvm::hash_combine(hashVal, data.drop_front(i)));
   465     return KeyTy(ty, firstElt, hashVal, 
true);
   470                                  size_t numElements) {
   472     bool splatValue = splatData.front() & 1;
   475     auto generateSplatKey = [=] {
   476       return KeyTy(ty, data.take_front(1),
   483     size_t numOddElements = numElements % CHAR_BIT;
   484     if (splatValue && numOddElements != 0) {
   486       char lastElt = splatData.back();
   487       if (lastElt != llvm::maskTrailingOnes<unsigned char>(numOddElements))
   491       if (splatData.size() == 1)
   492         return generateSplatKey();
   493       splatData = splatData.drop_back();
   497     char mask = splatValue ? ~0 : 0;
   498     return llvm::all_of(splatData, [mask](
char c) { 
return c == mask; })
   515       char *rawData = 
reinterpret_cast<char *
>(
   516           allocator.
allocate(data.size(), 
alignof(uint64_t)));
   517       std::memcpy(rawData, data.data(), data.size());
   536   using KeyTy = std::tuple<Type, Dialect *, StringRef>;
   543     return key == std::make_tuple(
getType(), dialect, bytes);
   546     return llvm::hash_combine(std::get<0>(key), std::get<1>(key),
   557                                        allocator.
copyInto(std::get<2>(key)));
   566   using KeyTy = std::tuple<Type, DenseIntElementsAttr, DenseElementsAttr>;
   574     return key == std::make_tuple(
getType(), indices, values);
   577     return llvm::hash_combine(std::get<0>(key), std::get<1>(key),
   595 #endif // ATTRIBUTEDETAIL_H_ Type getType() const
Get the type of this attribute. 
Definition: Attributes.cpp:31
Definition: InferTypeOpInterface.cpp:20
Dialect * dialect
Definition: AttributeDetail.h:560
static unsigned hashKey(const KeyTy &key)
Definition: AttributeDetail.h:214
bool operator==(const KeyTy &key) const
We only check equality for and hash with the boolean key parameter. 
Definition: AttributeDetail.h:76
size_t numObjects
Definition: AttributeDetail.h:196
static IntegerSetAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:257
bool isSplat
A boolean that indicates if this data is a splat or not. 
Definition: AttributeDetail.h:392
static unsigned hashKey(const KeyTy &key)
Definition: AttributeDetail.h:77
An attribute representing a floating point value. 
Definition: AttributeDetail.h:138
IntegerAttributeStorage(Type type, size_t numObjects)
Definition: AttributeDetail.h:205
Integer types can have arbitrary bitwidth up to a large fixed limit. 
Definition: StandardTypes.h:82
Definition: Attributes.h:139
SymbolRefAttributeStorage(StringRef value, size_t numNestedRefs)
Definition: AttributeDetail.h:322
Definition: Attributes.h:129
Definition: Attributes.h:491
mlir::edsc::intrinsics::OperationBuilder< CopyOp > copy
Definition: Intrinsics.h:21
SparseElementsAttributeStorage(Type type, DenseIntElementsAttr indices, DenseElementsAttr values)
Definition: AttributeDetail.h:568
OpaqueElementsAttributeStorage(Type type, Dialect *dialect, StringRef bytes)
Definition: AttributeDetail.h:538
bool operator==(const KeyTy &key) const
Definition: AttributeDetail.h:274
Definition: StorageUniquer.h:89
Definition: Identifier.h:26
FloatAttributeStorage(const llvm::fltSemantics &semantics, Type type, size_t numObjects)
Definition: AttributeDetail.h:143
Definition: StandardTypes.h:113
static StringAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:306
size_t numNestedRefs
Definition: AttributeDetail.h:349
AffineMap value
Definition: AttributeDetail.h:46
static ArrayAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:59
StringRef value
Definition: AttributeDetail.h:312
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:359
BoolAttributeStorage(Type type, bool value)
Definition: AttributeDetail.h:72
static unsigned hashKey(const KeyTy &key)
Definition: AttributeDetail.h:545
static BoolAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Definition: AttributeDetail.h:81
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:102
AffineMap KeyTy
Definition: AttributeDetail.h:31
Definition: StandardTypes.h:178
bool operator==(const KeyTy &key) const
Key equality and hash functions. 
Definition: AttributeDetail.h:542
An attribute representing an array of other attributes. 
Definition: AttributeDetail.h:50
std::pair< Identifier, Attribute > NamedAttribute
Definition: Attributes.h:264
std::tuple< Type, Dialect *, StringRef > KeyTy
Definition: AttributeDetail.h:536
const llvm::fltSemantics & getFloatSemantics()
Return the floating semantics of this float type. 
Definition: StandardTypes.cpp:86
bool isIndex()
Definition: StandardTypes.cpp:30
bool value
Definition: AttributeDetail.h:87
An attribute representing a reference to a sparse vector or tensor object. 
Definition: AttributeDetail.h:565
std::pair< StringRef, ArrayRef< FlatSymbolRefAttr > > KeyTy
Definition: AttributeDetail.h:320
static SparseElementsAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:583
static IntegerType get(unsigned width, MLIRContext *context)
Definition: MLIRContext.cpp:511
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:301
T * allocate()
Allocate an instance of the provided type. 
Definition: StorageUniquer.h:109
DenseElementsAttributeStorage(ShapedType ty, ArrayRef< char > data, bool isSplat=false)
Definition: AttributeDetail.h:395
DenseElementsAttr values
Definition: AttributeDetail.h:590
An attribute representing a integral value. 
Definition: AttributeDetail.h:200
IntegerSet value
Definition: AttributeDetail.h:262
An attribute representing a boolean value. 
Definition: AttributeDetail.h:69
static IntegerAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:220
AffineMapAttributeStorage(AffineMap value)
Definition: AttributeDetail.h:33
size_t numObjects
Definition: AttributeDetail.h:243
Definition: Attributes.h:660
StringRef value
Definition: AttributeDetail.h:348
std::pair< MLIRContext *, bool > KeyTy
Definition: AttributeDetail.h:70
std::tuple< Identifier, StringRef, Type > KeyTy
The hash key used for uniquing. 
Definition: AttributeDetail.h:273
bool isBF16()
Definition: StandardTypes.cpp:25
An attribute representing a reference to a dense vector or tensor object. 
Definition: AttributeDetail.h:376
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:37
StringAttributeStorage(StringRef value, Type type)
Definition: AttributeDetail.h:297
StringRef bytes
Definition: AttributeDetail.h:561
static KeyTy getKey(Type type, double value)
Construct a key with a type and double. 
Definition: AttributeDetail.h:156
static llvm::hash_code hashKey(const KeyTy &key)
Hash the key for the storage. 
Definition: AttributeDetail.h:504
TypeAttributeStorage(Type value)
Definition: AttributeDetail.h:356
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:326
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:253
Definition: AffineMap.h:37
APFloat getValue() const
Returns an APFloat representing the stored value. 
Definition: AttributeDetail.h:189
Type value
Definition: AttributeDetail.h:368
ArrayRef< NamedAttribute > getElements() const
Return the elements of this dictionary attribute. 
Definition: AttributeDetail.h:119
static FloatAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:171
bool operator==(const KeyTy &key) const
Key equality and hash functions. 
Definition: AttributeDetail.h:211
Opaque Attribute Storage and Uniquing. 
Definition: AttributeDetail.h:266
ArrayRef< char > data
The raw buffer for the data storage. 
Definition: AttributeDetail.h:386
Definition: AttributeDetail.h:247
static KeyTy getKeyForBoolData(ShapedType ty, ArrayRef< char > data, size_t numElements)
Construct a key with a set of boolean data. 
Definition: AttributeDetail.h:469
static OpaqueElementsAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:552
Definition: AttributeDetail.h:30
DenseIntElementsAttr indices
Definition: AttributeDetail.h:589
An attribute representing a symbol reference. 
Definition: AttributeDetail.h:316
static AffineMapAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:41
Type getElementType() const
Return the element type. 
Definition: StandardTypes.cpp:119
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable. 
Definition: AffineExpr.h:201
static unsigned hashKey(const KeyTy &key)
Definition: AttributeDetail.h:576
Definition: AttributeDetail.h:535
static DenseElementsAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:510
std::pair< StringRef, Type > KeyTy
Definition: AttributeDetail.h:295
Identifier dialectNamespace
Definition: AttributeDetail.h:287
std::tuple< Type, DenseIntElementsAttr, DenseElementsAttr > KeyTy
Definition: AttributeDetail.h:566
IntegerSetAttributeStorage(IntegerSet value)
Definition: AttributeDetail.h:250
bool operator==(const KeyTy &key) const
Key equality and hash functions. 
Definition: AttributeDetail.h:148
KeyTy(ShapedType type, ArrayRef< char > data, llvm::hash_code hashCode, bool isSplat=false)
Definition: AttributeDetail.h:378
static DictionaryAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:106
An attribute representing a string value. 
Definition: AttributeDetail.h:294
static OpaqueAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Definition: AttributeDetail.h:278
APInt getValue() const
Returns an APInt representing the stored value. 
Definition: AttributeDetail.h:236
static TypeAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key)
Construct a new storage instance. 
Definition: AttributeDetail.h:362
std::pair< Type, APFloat > KeyTy
Definition: AttributeDetail.h:141
ArrayRef< char > data
Definition: AttributeDetail.h:529
Definition: AttributeSupport.h:34
bool isSplat
Definition: AttributeDetail.h:530
const llvm::fltSemantics & semantics
Definition: AttributeDetail.h:195
ArrayRef< T > copyInto(ArrayRef< T > elements)
Definition: StorageUniquer.h:93
llvm::hash_code hashCode
The computed hash code for the storage data. 
Definition: AttributeDetail.h:389
StringRef attrData
Definition: AttributeDetail.h:290
bool isa() const
Definition: Types.h:254
An attribute representing a dictionary of sorted named attributes. 
Definition: AttributeDetail.h:91
Definition: AttributeDetail.h:377
Definition: StandardTypes.h:70
bool operator==(const KeyTy &key) const
Compare this storage instance with the provided key. 
Definition: AttributeDetail.h:400
int64_t getNumElements() const
If it has static shape, return the number of elements. Otherwise, abort. 
Definition: StandardTypes.cpp:127
bool operator==(const KeyTy &key) const
Key equality and hash functions. 
Definition: AttributeDetail.h:573
bool operator==(const KeyTy &key) const
Key equality function. 
Definition: AttributeDetail.h:56
unsigned getElementTypeBitWidth() const
Definition: StandardTypes.cpp:123
ArrayRef< FlatSymbolRefAttr > getNestedRefs() const
Returns the set of nested references. 
Definition: AttributeDetail.h:344
std::pair< Type, APInt > KeyTy
Definition: AttributeDetail.h:203
ArrayRef< Attribute > value
Definition: AttributeDetail.h:65
bool isF64()
Definition: StandardTypes.cpp:28
Definition: Attributes.h:135
static SymbolRefAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance. 
Definition: AttributeDetail.h:332
static unsigned hashKey(const KeyTy &key)
Definition: AttributeDetail.h:151
ArrayAttributeStorage(ArrayRef< Attribute > value)
Definition: AttributeDetail.h:53
ShapedType type
The type of the dense elements. 
Definition: AttributeDetail.h:383
Definition: Attributes.h:1012
U cast() const
Definition: Types.h:264
static KeyTy getKey(ShapedType ty, ArrayRef< char > data, bool isKnownSplat)
Definition: AttributeDetail.h:423
OpaqueAttributeStorage(Identifier dialectNamespace, StringRef attrData, Type type)
Definition: AttributeDetail.h:267
An attribute representing a reference to a type. 
Definition: AttributeDetail.h:353
Definition: IntegerSet.h:42