[llvm] r265563 - [RegisterBankInfo] Implement the verify method of the InstructionMapping helper class.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 10:01:44 PDT 2016


Author: qcolombet
Date: Wed Apr  6 12:01:43 2016
New Revision: 265563

URL: http://llvm.org/viewvc/llvm-project?rev=265563&view=rev
Log:
[RegisterBankInfo] Implement the verify method of the InstructionMapping helper class.
This checks that all the register operands get a proper mapping.

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=265563&r1=265562&r2=265563&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Apr  6 12:01:43 2016
@@ -89,7 +89,7 @@ public:
 
   public:
     /// Constructor for the mapping of an instruction.
-    /// \p NumOperands should be equal to number of all the operands of
+    /// \p NumOperands must be equal to number of all the operands of
     /// the related instruction.
     /// The rationale is that it is more efficient for the optimizers
     /// to be able to assume that the mapping of the ith operand is

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=265563&r1=265562&r2=265563&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Apr  6 12:01:43 2016
@@ -14,6 +14,9 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -231,4 +234,26 @@ void RegisterBankInfo::ValueMapping::ver
 void RegisterBankInfo::InstructionMapping::verify(
     const MachineInstr &MI) const {
   // Check that all the register operands are properly mapped.
+  const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
+  // Check the constructor invariant.
+  assert(NumOperands == MI.getNumOperands() &&
+         "NumOperands must match, see constructor");
+  for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
+    const MachineOperand &MO = MI.getOperand(Idx);
+    const RegisterBankInfo::ValueMapping &MOMapping = getOperandMapping(Idx);
+    if (!MO.isReg()) {
+      assert(MOMapping.BreakDown.empty() &&
+             "We should not care about non-reg mapping");
+      continue;
+    }
+    unsigned Reg = MO.getReg();
+    // Register size in bits.
+    // This size must match what the mapping expect.
+    unsigned RegSize = MRI.getSize(Reg);
+    // If Reg is not a generic register, query the register class to
+    // get its size.
+    if (!RegSize)
+      RegSize = MRI.getRegClass(Reg)->getSize() * 8;
+    MOMapping.verify(RegSize);
+  }
 }




More information about the llvm-commits mailing list