Add support for the 'X' inline asm operand modifier.
authorEric Christopher <echristo@apple.com>
Thu, 10 May 2012 21:48:22 +0000 (21:48 +0000)
committerEric Christopher <echristo@apple.com>
Thu, 10 May 2012 21:48:22 +0000 (21:48 +0000)
Patch by Jack Carter.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156577 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsAsmPrinter.cpp
test/CodeGen/Mips/inlineasm-operand-code.ll [new file with mode: 0644]

index 33337383a0b32b9b4aee454d68c97cded219f2a0..65dd6e95873d04a402f4fe1f0302c92f04b7ea50 100644 (file)
@@ -382,14 +382,26 @@ bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
 }
 
 // Print out an operand for an inline asm expression.
-bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
+bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
                                      unsigned AsmVariant,const char *ExtraCode,
                                      raw_ostream &O) {
   // Does this asm operand have a single letter operand modifier?
-  if (ExtraCode && ExtraCode[0])
-    return true; // Unknown modifier.
+  if (ExtraCode && ExtraCode[0]) {
+    if (ExtraCode[1] != 0) return true; // Unknown modifier.
+
+    const MachineOperand &MO = MI->getOperand(OpNum);
+    switch (ExtraCode[0]) {
+      default:
+        return true;  // Unknown modifier.
+      case 'X': // hex const int
+        if ((MO.getType()) != MachineOperand::MO_Immediate)
+          return true;
+        O << "0x" << StringRef(utohexstr(MO.getImm())).lower();
+        return false;
+    }
+  }
 
-  printOperand(MI, OpNo, O);
+  printOperand(MI, OpNum, O);
   return false;
 }
 
diff --git a/test/CodeGen/Mips/inlineasm-operand-code.ll b/test/CodeGen/Mips/inlineasm-operand-code.ll
new file mode 100644 (file)
index 0000000..4568a84
--- /dev/null
@@ -0,0 +1,15 @@
+; Positive test for inline register constraints
+;
+; RUN: llc -march=mipsel < %s  | FileCheck %s
+
+define i32 @main() nounwind {
+entry:
+
+; X with -3
+;CHECK:        #APP
+;CHECK:        addi ${{[0-9]+}},${{[0-9]+}},0xfffffffffffffffd
+;CHECK:        #NO_APP
+  tail call i32 asm sideeffect "addi $0,$1,${2:X}", "=r,r,I"(i32 7, i32 -3) nounwind
+
+  ret i32 0
+}