forked from OSchip/llvm-project
[RegisterBankInfo] Rework the APIs of ValueMapping.
This is a preparatory commit for more TableGen-like structure. NFC llvm-svn: 282642
This commit is contained in:
parent
38175a2e75
commit
97d2d21d65
|
@ -143,10 +143,23 @@ public:
|
||||||
/// Number of partial mapping to break down this value.
|
/// Number of partial mapping to break down this value.
|
||||||
unsigned NumBreakDowns;
|
unsigned NumBreakDowns;
|
||||||
|
|
||||||
|
/// The default constructor creates an invalid (isValid() == false)
|
||||||
|
/// instance.
|
||||||
|
ValueMapping() : ValueMapping(nullptr, 0) {}
|
||||||
|
|
||||||
|
/// Initialize a ValueMapping with the given parameter.
|
||||||
|
/// \p BreakDown needs to have a life time at least as long
|
||||||
|
/// as this instance.
|
||||||
|
ValueMapping(const PartialMapping *BreakDown, unsigned NumBreakDowns)
|
||||||
|
: BreakDown(BreakDown), NumBreakDowns(NumBreakDowns) {}
|
||||||
|
|
||||||
/// Iterators through the PartialMappings.
|
/// Iterators through the PartialMappings.
|
||||||
const PartialMapping *begin() const { return BreakDown; }
|
const PartialMapping *begin() const { return BreakDown; }
|
||||||
const PartialMapping *end() const { return BreakDown + NumBreakDowns; }
|
const PartialMapping *end() const { return BreakDown + NumBreakDowns; }
|
||||||
|
|
||||||
|
/// Check if this ValueMapping is valid.
|
||||||
|
bool isValid() const { return BreakDown && NumBreakDowns; }
|
||||||
|
|
||||||
/// Verify that this mapping makes sense for a value of
|
/// Verify that this mapping makes sense for a value of
|
||||||
/// \p MeaningFulBitWidth.
|
/// \p MeaningFulBitWidth.
|
||||||
/// \note This method does not check anything when assertions are disabled.
|
/// \note This method does not check anything when assertions are disabled.
|
||||||
|
|
|
@ -355,21 +355,23 @@ RegisterBankInfo::getValueMapping(unsigned StartIdx, unsigned Length,
|
||||||
return getValueMapping(&getPartialMapping(StartIdx, Length, RegBank), 1);
|
return getValueMapping(&getPartialMapping(StartIdx, Length, RegBank), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static hash_code
|
||||||
|
hashValueMapping(const RegisterBankInfo::PartialMapping *BreakDown,
|
||||||
|
unsigned NumBreakDowns) {
|
||||||
|
if (LLVM_LIKELY(NumBreakDowns == 1))
|
||||||
|
return hash_value(*BreakDown);
|
||||||
|
SmallVector<size_t, 8> Hashes(NumBreakDowns);
|
||||||
|
for (unsigned Idx = 0; Idx != NumBreakDowns; ++Idx)
|
||||||
|
Hashes.push_back(hash_value(BreakDown[Idx]));
|
||||||
|
return hash_combine_range(Hashes.begin(), Hashes.end());
|
||||||
|
}
|
||||||
|
|
||||||
const RegisterBankInfo::ValueMapping &
|
const RegisterBankInfo::ValueMapping &
|
||||||
RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
|
RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
|
||||||
unsigned NumBreakDowns) const {
|
unsigned NumBreakDowns) const {
|
||||||
hash_code Hash;
|
|
||||||
if (LLVM_LIKELY(NumBreakDowns == 1))
|
|
||||||
Hash = hash_value(*BreakDown);
|
|
||||||
else {
|
|
||||||
SmallVector<size_t, 8> Hashes;
|
|
||||||
for (unsigned Idx = 0; Idx != NumBreakDowns; ++Idx)
|
|
||||||
Hashes.push_back(hash_value(BreakDown[Idx]));
|
|
||||||
Hash = hash_combine_range(Hashes.begin(), Hashes.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
++NumValueMappingsAccessed;
|
++NumValueMappingsAccessed;
|
||||||
|
|
||||||
|
hash_code Hash = hashValueMapping(BreakDown, NumBreakDowns);
|
||||||
const auto &It = MapOfValueMappings.find(Hash);
|
const auto &It = MapOfValueMappings.find(Hash);
|
||||||
if (It != MapOfValueMappings.end())
|
if (It != MapOfValueMappings.end())
|
||||||
return *It->second;
|
return *It->second;
|
||||||
|
|
Loading…
Reference in New Issue