]> granicus.if.org Git - llvm/commitdiff
Merging r230147:
authorTom Stellard <thomas.stellard@amd.com>
Tue, 28 Apr 2015 19:12:20 +0000 (19:12 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 28 Apr 2015 19:12:20 +0000 (19:12 +0000)
------------------------------------------------------------------------
r230147 | Matthew.Arsenault | 2015-02-21 16:29:04 -0500 (Sat, 21 Feb 2015) | 2 lines

R600/SI: Don't crash when getting immediate operand size

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@236022 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/R600/SIInstrInfo.h

index b25e35e3add0573d0c641e403f1327e3ce0a71cd..129803072672cb83d2b13a207b33ab9c2c823f88 100644 (file)
@@ -247,7 +247,27 @@ public:
   /// the register class of its machine operand.
   /// to infer the correct register class base on the other operands.
   const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
-                                           unsigned OpNo) const;\
+                                           unsigned OpNo) const;
+
+  /// \brief Return the size in bytes of the operand OpNo on the given
+  // instruction opcode.
+  unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
+    const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
+
+    if (OpInfo.RegClass == -1) {
+      // If this is an immediate operand, this must be a 32-bit literal.
+      assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
+      return 4;
+    }
+
+    return RI.getRegClass(OpInfo.RegClass)->getSize();
+  }
+
+  /// \brief This form should usually be preferred since it handles operands
+  /// with unknown register classes.
+  unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
+    return getOpRegClass(MI, OpNo)->getSize();
+  }
 
   /// \returns true if it is legal for the operand at index \p OpNo
   /// to read a VGPR.