[llvm] r265735 - [RegisterBankInfo] Introduce getRegBankFromConstraints as an helper

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 15:35:04 PDT 2016


Author: qcolombet
Date: Thu Apr  7 17:35:03 2016
New Revision: 265735

URL: http://llvm.org/viewvc/llvm-project?rev=265735&view=rev
Log:
[RegisterBankInfo] Introduce getRegBankFromConstraints as an helper
method.

NFC.

The refactoring intends to make the code more readable and expose
more features to potential derived classes.

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=265735&r1=265734&r2=265735&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Thu Apr  7 17:35:03 2016
@@ -27,6 +27,7 @@
 namespace llvm {
 class MachineInstr;
 class MachineRegisterInfo;
+class TargetInstrInfo;
 class TargetRegisterInfo;
 class raw_ostream;
 
@@ -225,6 +226,17 @@ protected:
   /// any generic opcode that has not been lowered by target specific code.
   InstructionMapping getInstrMappingImpl(const MachineInstr &MI) const;
 
+  /// Get the register bank for the \p OpIdx-th operand of \p MI form
+  /// the encoding constraints, if any.
+  ///
+  /// \return A register bank that covers the register class of the
+  /// related encoding constraints or nullptr if \p MI did not provide
+  /// enough information to deduce it.
+  const RegisterBank *
+  getRegBankFromConstraints(const MachineInstr &MI, unsigned OpIdx,
+                            const TargetInstrInfo &TII,
+                            const TargetRegisterInfo &TRI) const;
+
 public:
   virtual ~RegisterBankInfo() {}
 

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=265735&r1=265734&r2=265735&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Thu Apr  7 17:35:03 2016
@@ -195,6 +195,23 @@ RegisterBankInfo::getRegBank(unsigned Re
   return nullptr;
 }
 
+const RegisterBank *RegisterBankInfo::getRegBankFromConstraints(
+    const MachineInstr &MI, unsigned OpIdx, const TargetInstrInfo &TII,
+    const TargetRegisterInfo &TRI) const {
+  // The mapping of the registers may be available via the
+  // register class constraints.
+  const TargetRegisterClass *RC = MI.getRegClassConstraint(OpIdx, &TII, &TRI);
+
+  if (!RC)
+    return nullptr;
+
+  const RegisterBank &RegBank = getRegBankFromRegClass(*RC);
+  // Sanity check that the target properly implemented getRegBankFromRegClass.
+  assert(RegBank.covers(*RC) &&
+         "The mapping of the register bank does not make sense");
+  return &RegBank;
+}
+
 RegisterBankInfo::InstructionMapping
 RegisterBankInfo::getInstrMappingImpl(const MachineInstr &MI) const {
   RegisterBankInfo::InstructionMapping Mapping(DefaultMappingID, /*Cost*/ 1,
@@ -225,26 +242,23 @@ RegisterBankInfo::getInstrMappingImpl(co
       continue;
     const RegisterBank *CurRegBank = getRegBank(Reg, MRI, TRI);
     if (!CurRegBank) {
-      // The mapping of the registers may be available via the
-      // register class constraints.
-      const TargetRegisterClass *RC =
-          MI.getRegClassConstraint(OpIdx, &TII, &TRI);
+      // If this is a target specific instruction, we can deduce
+      // the register bank from the encoding constraints.
+      CurRegBank = getRegBankFromConstraints(MI, OpIdx, TII, TRI);
+      if (!CurRegBank) {
+        // All our attempts failed, give up.
+        CompleteMapping = false;
 
-      if (RC)
-        CurRegBank = &getRegBankFromRegClass(*RC);
-    }
-    if (!CurRegBank) {
-      CompleteMapping = false;
+        if (!isCopyLike)
+          // MI does not carry enough information to guess the mapping.
+          return InstructionMapping();
 
-      if (!isCopyLike)
-        // MI does not carry enough information to guess the mapping.
-        return InstructionMapping();
-
-      // For copies, we want to keep interating to find a register
-      // bank for the other operands if we did not find one yet.
-      if(RegBank)
-        break;
-      continue;
+        // For copies, we want to keep interating to find a register
+        // bank for the other operands if we did not find one yet.
+        if (RegBank)
+          break;
+        continue;
+      }
     }
     RegBank = CurRegBank;
     RegSize = getSizeInBits(Reg, MRI, TRI);




More information about the llvm-commits mailing list