Add the simple PPC integer constraints
authorChris Lattner <sabre@nondot.org>
Tue, 7 Feb 2006 00:47:13 +0000 (00:47 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 7 Feb 2006 00:47:13 +0000 (00:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26027 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/PowerPC/PPCISelLowering.h

index ec35f37e96e4620cdeb3c1d7bb2e5603bf63c71d..76bcf1e5c36871dca291102a40814bce1f8cb907 100644 (file)
@@ -1035,3 +1035,44 @@ getRegForInlineAsmConstraint(const std::string &Constraint) const {
   // Handle explicit register names.
   return TargetLowering::getRegForInlineAsmConstraint(Constraint);
 }
+
+// isOperandValidForConstraint
+bool PPCTargetLowering::
+isOperandValidForConstraint(SDOperand Op, char Letter) {
+  switch (Letter) {
+  default: break;
+  case 'I':
+  case 'J':
+  case 'K':
+  case 'L':
+  case 'M':
+  case 'N':
+  case 'O':
+  case 'P': {
+    if (!isa<ConstantSDNode>(Op)) return false;  // Must be an immediate.
+    unsigned Value = cast<ConstantSDNode>(Op)->getValue();
+    switch (Letter) {
+    default: assert(0 && "Unknown constraint letter!");
+    case 'I':  // "I" is a signed 16-bit constant.
+      return (short)Value == (int)Value;
+    case 'J':  // "J" is a constant with only the high-order 16 bits nonzero.
+    case 'L':  // "L" is a signed 16-bit constant shifted left 16 bits.
+      return (short)Value == 0;
+    case 'K':  // "K" is a constant with only the low-order 16 bits nonzero.
+      return (Value >> 16) == 0;
+    case 'M':  // "M" is a constant that is greater than 31.
+      return Value > 31;
+    case 'N':  // "N" is a positive constant that is an exact power of two.
+      return (int)Value > 0 && isPowerOf2_32(Value);
+    case 'O':  // "O" is the constant zero. 
+      return Value == 0;
+    case 'P':  // "P" is a constant whose negation is a signed 16-bit constant.
+      return (short)-Value == (int)-Value;
+    }
+    break;
+  }
+  }
+  
+  // Handle standard constraint letters.
+  return TargetLowering::isOperandValidForConstraint(Op, Letter);
+}
index 30db16c8f9a2e75c03e585dd4340be74c6489a41..bcf4c6ffe4883706c5a9952de81be4fcb0808a76 100644 (file)
@@ -99,7 +99,7 @@ namespace llvm {
     
     std::vector<unsigned> 
       getRegForInlineAsmConstraint(const std::string &Constraint) const;
-
+    bool isOperandValidForConstraint(SDOperand Op, char ConstraintLetter);
   };
 }