[llvm] r265556 - [RegisterBankInfo] Implement the verify method for the ValueMapping helper class.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 09:40:23 PDT 2016


Author: qcolombet
Date: Wed Apr  6 11:40:23 2016
New Revision: 265556

URL: http://llvm.org/viewvc/llvm-project?rev=265556&view=rev
Log:
[RegisterBankInfo] Implement the verify method for the ValueMapping helper class.
The method checks that the value is fully defined accross the different partial
mappings and that the partial mappings are compatible between each other.

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=265556&r1=265555&r2=265556&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Apr  6 11:40:23 2016
@@ -64,8 +64,8 @@ public:
   struct ValueMapping {
     /// How the value is broken down between the different register banks.
     SmallVector<PartialMapping, 2> BreakDown;
-    /// Verify that this mapping makes sense.
-    void verify() const;
+    /// Verify that this mapping makes sense for a value of \p ExpectedBitWidth.
+    void verify(unsigned ExpectedBitWidth) const;
   };
 
   /// Helper class that represents how the value of an instruction may be

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=265556&r1=265555&r2=265556&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Apr  6 11:40:23 2016
@@ -210,10 +210,22 @@ void RegisterBankInfo::PartialMapping::p
     OS << "nullptr";
 }
 
-void RegisterBankInfo::ValueMapping::verify() const {
-  // Check that all the partial mapping have the same bitwidth.
-  // Check that the union of the partial mappings covers the whole value.
-  // Check that each register bank is big enough to hold the partial value.
+void RegisterBankInfo::ValueMapping::verify(unsigned ExpectedBitWidth) const {
+  assert(!BreakDown.empty() && "Value mapped nowhere?!");
+  unsigned ValueBitWidth = BreakDown.back().Mask.getBitWidth();
+  assert(ValueBitWidth == ExpectedBitWidth && "BitWidth does not match");
+  APInt ValueMask(ValueBitWidth, 0);
+  for (const RegisterBankInfo::PartialMapping &PartMap : BreakDown) {
+    // Check that all the partial mapping have the same bitwidth.
+    assert(PartMap.Mask.getBitWidth() == ValueBitWidth &&
+           "Value does not have the same size accross the partial mappings");
+    // Check that the union of the partial mappings covers the whole value.
+    ValueMask |= PartMap.Mask;
+    // Check that each register bank is big enough to hold the partial value:
+    // this check is done by PartialMapping::verify
+    PartMap.verify();
+  }
+  assert(ValueMask.isAllOnesValue() && "Value is not fully mapped");
 }
 
 void RegisterBankInfo::InstructionMapping::verify(




More information about the llvm-commits mailing list