[llvm] r282642 - [RegisterBankInfo] Rework the APIs of ValueMapping.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 15:20:24 PDT 2016
Author: qcolombet
Date: Wed Sep 28 17:20:24 2016
New Revision: 282642
URL: http://llvm.org/viewvc/llvm-project?rev=282642&view=rev
Log:
[RegisterBankInfo] Rework the APIs of ValueMapping.
This is a preparatory commit for more TableGen-like structure.
NFC
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h?rev=282642&r1=282641&r2=282642&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Sep 28 17:20:24 2016
@@ -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.
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=282642&r1=282641&r2=282642&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Sep 28 17:20:24 2016
@@ -355,21 +355,23 @@ RegisterBankInfo::getValueMapping(unsign
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;
More information about the llvm-commits
mailing list