[llvm] r265699 - [RegisterBankInfo] Provide a default constructor for InstructionMapping

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 10:30:19 PDT 2016


Author: qcolombet
Date: Thu Apr  7 12:30:18 2016
New Revision: 265699

URL: http://llvm.org/viewvc/llvm-project?rev=265699&view=rev
Log:
[RegisterBankInfo] Provide a default constructor for InstructionMapping
helper class.

The default constructor creates invalid (isValid() == false) instances
and may be used to communicate that a mapping was not found.

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=265699&r1=265698&r2=265699&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Thu Apr  7 12:30:18 2016
@@ -96,11 +96,19 @@ public:
     /// The rationale is that it is more efficient for the optimizers
     /// to be able to assume that the mapping of the ith operand is
     /// at the index i.
+    ///
+    /// \pre ID != InvalidMappingID
     InstructionMapping(unsigned ID, unsigned Cost, unsigned NumOperands)
         : ID(ID), Cost(Cost), NumOperands(NumOperands) {
+      assert(getID() != InvalidMappingID &&
+             "Use the default constructor for invalid mapping");
       OperandsMapping.reset(new ValueMapping[getNumOperands()]);
     }
 
+    /// Default constructor.
+    /// Use this constructor to express that the mapping is invalid.
+    InstructionMapping() : ID(InvalidMappingID), Cost(0), NumOperands(0) {}
+
     /// Get the cost.
     unsigned getCost() const { return Cost; }
 
@@ -120,6 +128,10 @@ public:
       getOperandMapping(i) = ValMapping;
     }
 
+    /// Check whether this object is valid.
+    /// This is a lightweight check for obvious wrong instance.
+    bool isValid() const { return getID() != InvalidMappingID; }
+
     /// Verifiy that this mapping makes sense for \p MI.
     void verify(const MachineInstr &MI) const;
   };
@@ -224,6 +236,11 @@ public:
   /// Make sure not to use that identifier to avoid possible collision.
   static const unsigned DefaultMappingID;
 
+  /// Identifier used when the related instruction mapping instance
+  /// is generated by the default constructor.
+  /// Make sure not to use that identifier.
+  static const unsigned InvalidMappingID;
+
   /// Get the mapping of the different operands of \p MI
   /// on the register bank.
   /// This mapping should be the direct translation of \p MI.

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=265699&r1=265698&r2=265699&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Thu Apr  7 12:30:18 2016
@@ -31,6 +31,7 @@
 using namespace llvm;
 
 const unsigned RegisterBankInfo::DefaultMappingID = UINT_MAX;
+const unsigned RegisterBankInfo::InvalidMappingID = UINT_MAX - 1;
 
 /// Get the size in bits of the \p OpIdx-th operand of \p MI.
 ///




More information about the llvm-commits mailing list