Skip to content

Commit 83a8b2b

Browse files
committed
sigh
1 parent cfe0e80 commit 83a8b2b

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,11 +1093,9 @@ def LLVM_TBAATagArrayAttr
10931093
//===----------------------------------------------------------------------===//
10941094
// ConstantRangeAttr
10951095
//===----------------------------------------------------------------------===//
1096+
10961097
def LLVM_ConstantRangeAttr : LLVM_Attr<"ConstantRange", "constant_range"> {
1097-
let parameters = (ins
1098-
"::llvm::APInt":$lower,
1099-
"::llvm::APInt":$upper
1100-
);
1098+
let parameters = (ins "::llvm::APInt":$lower, "::llvm::APInt":$upper);
11011099
let summary = "A range of two integers, corresponding to LLVM's ConstantRange";
11021100
let description = [{
11031101
A pair of two integers, mapping to the ConstantRange structure in LLVM IR,
@@ -1122,6 +1120,7 @@ def LLVM_ConstantRangeAttr : LLVM_Attr<"ConstantRange", "constant_range"> {
11221120

11231121
let hasCustomAssemblyFormat = 1;
11241122
let genVerifyDecl = 1;
1123+
let genStorageClass = 0;
11251124
}
11261125

11271126

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,54 @@
2323
namespace mlir {
2424
namespace LLVM {
2525

26+
namespace detail {
27+
struct ConstantRangeAttrStorage : public AttributeStorage {
28+
ConstantRangeAttrStorage(llvm::APInt lower, llvm::APInt upper)
29+
: lower(lower), upper(upper) {}
30+
31+
/// The hash key for this storage is a pair of the integer and type params.
32+
using KeyTy = std::pair<llvm::APInt, llvm::APInt>;
33+
34+
/// Define the comparison function for the key type.
35+
bool operator==(const KeyTy &key) const {
36+
if (lower.getBitWidth() != key.first.getBitWidth() ||
37+
upper.getBitWidth() != key.second.getBitWidth()) {
38+
return false;
39+
}
40+
return lower == key.first && upper == key.second;
41+
}
42+
43+
/// Define a hash function for the key type.
44+
/// Note: This isn't necessary because std::pair, unsigned, and Type all have
45+
/// hash functions already available.
46+
static llvm::hash_code hashKey(const KeyTy &key) {
47+
return llvm::hash_combine(key.first, key.second);
48+
}
49+
50+
/// Define a construction function for the key type.
51+
/// Note: This isn't necessary because KeyTy can be directly constructed with
52+
/// the given parameters.
53+
static KeyTy getKey(llvm::APInt lower, llvm::APInt upper) {
54+
return KeyTy(lower, upper);
55+
}
56+
57+
/// Define a construction method for creating a new instance of this storage.
58+
static ConstantRangeAttrStorage *construct(mlir::StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
59+
return new (allocator.allocate<ConstantRangeAttrStorage>())
60+
ConstantRangeAttrStorage(key.first, key.second);
61+
}
62+
63+
/// Construct an instance of the key from this storage class.
64+
KeyTy getAsKey() const {
65+
return KeyTy(lower, upper);
66+
}
67+
68+
/// The parametric data held by the storage class.
69+
llvm::APInt lower;
70+
llvm::APInt upper;
71+
};
72+
}
73+
2674
/// This class represents the base attribute for all debug info attributes.
2775
class DINodeAttr : public Attribute {
2876
public:
@@ -96,6 +144,9 @@ using linkage::Linkage;
96144

97145
#include "mlir/Dialect/LLVMIR/LLVMAttrInterfaces.h.inc"
98146

147+
148+
149+
99150
#define GET_ATTRDEF_CLASSES
100151
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.h.inc"
101152

0 commit comments

Comments
 (0)