@@ -21,6 +21,42 @@ using namespace mlir::smt;
2121// BitVectorAttr
2222// ===----------------------------------------------------------------------===//
2323
24+ namespace mlir {
25+ namespace smt {
26+ namespace detail {
27+ struct BitVectorAttrStorage : public mlir ::AttributeStorage {
28+ using KeyTy = APInt;
29+ BitVectorAttrStorage (APInt value) : value(std::move(value)) {}
30+
31+ KeyTy getAsKey () const { return value; }
32+
33+ // NOTE: the implementation of this operator is the reason we need to define
34+ // the storage manually. The auto-generated version would just do the direct
35+ // equality check of the APInt, but that asserts the bitwidth of both to be
36+ // the same, leading to a crash. This implementation, therefore, checks for
37+ // matching bit-width beforehand.
38+ bool operator ==(const KeyTy &key) const {
39+ return (value.getBitWidth () == key.getBitWidth () && value == key);
40+ }
41+
42+ static llvm::hash_code hashKey (const KeyTy &key) {
43+ return llvm::hash_value (key);
44+ }
45+
46+ static BitVectorAttrStorage *
47+ construct (mlir::AttributeStorageAllocator &allocator, KeyTy &&key) {
48+ return new (allocator.allocate <BitVectorAttrStorage>())
49+ BitVectorAttrStorage (std::move (key));
50+ }
51+
52+ APInt value;
53+ };
54+ } // namespace detail
55+ } // namespace smt
56+ } // namespace mlir
57+
58+ APInt BitVectorAttr::getValue () const { return getImpl ()->value ; }
59+
2460LogicalResult BitVectorAttr::verify (
2561 function_ref<InFlightDiagnostic()> emitError,
2662 APInt value) { // NOLINT(performance-unnecessary-value-param)
0 commit comments