1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

[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:
Quentin Colombet 2016-09-28 22:20:24 +00:00
parent 5d501f4c5e
commit 7c54f93b53
2 changed files with 25 additions and 10 deletions

View File

@ -143,10 +143,23 @@ public:
/// Number of partial mapping to break down this value.
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.
const PartialMapping *begin() const { return BreakDown; }
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
/// \p MeaningFulBitWidth.
/// \note This method does not check anything when assertions are disabled.

View File

@ -355,21 +355,23 @@ RegisterBankInfo::getValueMapping(unsigned StartIdx, unsigned Length,
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 &
RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
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;
hash_code Hash = hashValueMapping(BreakDown, NumBreakDowns);
const auto &It = MapOfValueMappings.find(Hash);
if (It != MapOfValueMappings.end())
return *It->second;