Skip to content

Commit

Permalink
[FIRRTL] Add getAsKey to type storages, NFC (#5614)
Browse files Browse the repository at this point in the history
This PR adds `getAsKey` methods to type storages. Close #5568
  • Loading branch information
uenoku authored Jul 18, 2023
1 parent 0fcb904 commit 2068ad5
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/Dialect/FIRRTL/FIRRTLTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ struct circt::firrtl::detail::FIRRTLBaseTypeStorage : mlir::TypeStorage {

bool operator==(const KeyTy &key) const { return key == isConst; }

KeyTy getAsKey() const { return isConst; }

static FIRRTLBaseTypeStorage *construct(TypeStorageAllocator &allocator,
KeyTy key) {
return new (allocator.allocate<FIRRTLBaseTypeStorage>())
Expand Down Expand Up @@ -1265,9 +1267,9 @@ struct circt::firrtl::detail::WidthTypeStorage : detail::FIRRTLBaseTypeStorage {
: FIRRTLBaseTypeStorage(isConst), width(width) {}
using KeyTy = std::pair<int32_t, char>;

bool operator==(const KeyTy &key) const {
return key == std::pair{width, isConst};
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(width, isConst); }

static WidthTypeStorage *construct(TypeStorageAllocator &allocator,
const KeyTy &key) {
Expand Down Expand Up @@ -1370,9 +1372,9 @@ struct circt::firrtl::detail::BundleTypeStorage
maxFieldID = fieldID;
}

bool operator==(const KeyTy &key) const {
return key == KeyTy(elements, isConst);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(elements, isConst); }

static llvm::hash_code hashKey(const KeyTy &key) {
return llvm::hash_combine(
Expand Down Expand Up @@ -1631,16 +1633,16 @@ struct circt::firrtl::detail::OpenBundleTypeStorage : mlir::TypeStorage {
maxFieldID = fieldID;
}

bool operator==(const KeyTy &key) const {
return key == KeyTy(elements, isConst);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

static llvm::hash_code hashKey(const KeyTy &key) {
return llvm::hash_combine(
llvm::hash_combine_range(key.first.begin(), key.first.end()),
key.second);
}

KeyTy getAsKey() const { return KeyTy(elements, isConst); }

static OpenBundleTypeStorage *construct(TypeStorageAllocator &allocator,
KeyTy key) {
return new (allocator.allocate<OpenBundleTypeStorage>())
Expand Down Expand Up @@ -1843,9 +1845,9 @@ struct circt::firrtl::detail::FVectorTypeStorage
props.containsConst |= isConst;
}

bool operator==(const KeyTy &key) const {
return key == std::make_tuple(elementType, numElements, isConst);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(elementType, numElements, isConst); }

static FVectorTypeStorage *construct(TypeStorageAllocator &allocator,
KeyTy key) {
Expand Down Expand Up @@ -1990,9 +1992,9 @@ struct circt::firrtl::detail::OpenVectorTypeStorage : mlir::TypeStorage {
props.containsConst |= isConst;
}

bool operator==(const KeyTy &key) const {
return key == std::make_tuple(elementType, numElements, isConst);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(elementType, numElements, isConst); }

static OpenVectorTypeStorage *construct(TypeStorageAllocator &allocator,
KeyTy key) {
Expand Down Expand Up @@ -2140,9 +2142,9 @@ struct circt::firrtl::detail::FEnumTypeStorage : detail::FIRRTLBaseTypeStorage {
recProps = props;
}

bool operator==(const KeyTy &key) const {
return key == KeyTy(elements, isConst);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(elements, isConst); }

static llvm::hash_code hashKey(const KeyTy &key) {
return llvm::hash_combine(
Expand Down Expand Up @@ -2350,9 +2352,9 @@ struct circt::firrtl::detail::BaseTypeAliasStorage
: detail::FIRRTLBaseTypeStorage(innerType.isConst()), name(name),
innerType(innerType) {}

bool operator==(const KeyTy &key) const {
return key == KeyTy(name, innerType);
}
bool operator==(const KeyTy &key) const { return key == getAsKey(); }

KeyTy getAsKey() const { return KeyTy(name, innerType); }

static llvm::hash_code hashKey(const KeyTy &key) {
return llvm::hash_combine(key);
Expand Down

0 comments on commit 2068ad5

Please sign in to comment.