[llvm] r265555 - [RegisterBankInfo] Add a verify method for the PartialMapping helper class.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 09:33:27 PDT 2016
Author: qcolombet
Date: Wed Apr 6 11:33:26 2016
New Revision: 265555
URL: http://llvm.org/viewvc/llvm-project?rev=265555&view=rev
Log:
[RegisterBankInfo] Add a verify method for the PartialMapping helper class.
This verifies that the PartialMapping can be accomadated into the related
register bank.
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=265555&r1=265554&r2=265555&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Apr 6 11:33:26 2016
@@ -52,6 +52,11 @@ public:
/// Print this partial mapping on \p OS;
void print(raw_ostream &OS) const;
+
+ /// Check that the Mask is compatible with the RegBank.
+ /// Indeed, if the RegBank cannot accomadate the "active bits" of the mask,
+ /// there is no way this mapping is valid.
+ void verify() const;
};
/// Helper struct that represents how a value is mapped through
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=265555&r1=265554&r2=265555&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Apr 6 11:33:26 2016
@@ -181,6 +181,25 @@ void RegisterBankInfo::PartialMapping::d
dbgs() << '\n';
}
+void RegisterBankInfo::PartialMapping::verify() const {
+ assert(RegBank && "Register bank not set");
+ // Check what is the minimum width that will live into RegBank.
+ // RegBank will have to, at least, accomodate all the bits between the first
+ // and last bits active in Mask.
+ // If Mask is zero, then ActiveWidth is 0.
+ unsigned ActiveWidth = 0;
+ // Otherwise, remove the trailing and leading zeros from the bitwidth.
+ // 0..0 ActiveWidth 0..0.
+ if (Mask.getBoolValue())
+ ActiveWidth = Mask.getBitWidth() - Mask.countLeadingZeros() -
+ Mask.countTrailingZeros();
+ (void)ActiveWidth;
+ assert(ActiveWidth <= Mask.getBitWidth() &&
+ "Wrong computation of ActiveWidth, overflow?");
+ assert(RegBank->getSize() >= ActiveWidth &&
+ "Register bank too small for Mask");
+}
+
void RegisterBankInfo::PartialMapping::print(raw_ostream &OS) const {
SmallString<128> MaskStr;
Mask.toString(MaskStr, /*Radix*/ 2, /*Signed*/ 0, /*formatAsCLiteral*/ true);
More information about the llvm-commits
mailing list