tstellar / rpms / llvm

Forked from rpms/llvm 5 years ago
Clone
2653f00
From 8f5f7f9cb15387ddb010894c17e788b3116fe26d Mon Sep 17 00:00:00 2001
2653f00
From: Reid Kleckner <rnk@google.com>
2653f00
Date: Wed, 14 Feb 2018 00:33:00 +0000
2653f00
Subject: [PATCH 2/4] Merging r324645:
2653f00
 ------------------------------------------------------------------------
2653f00
 r324645 | dwmw2 | 2018-02-08 12:06:05 -0800 (Thu, 08 Feb 2018) | 5 lines
2653f00
2653f00
[X86] Support 'V' register operand modifier
2653f00
2653f00
This allows the register name to be printed without the leading '%'.
2653f00
This can be used for emitting calls to the retpoline thunks from inline
2653f00
asm.
2653f00
------------------------------------------------------------------------
2653f00
2653f00
2653f00
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@325089 91177308-0d34-0410-b5e6-96231b3b80d8
2653f00
---
2653f00
 lib/Target/X86/X86AsmPrinter.cpp          | 11 ++++++++++-
2653f00
 test/CodeGen/X86/inline-asm-modifier-V.ll | 14 ++++++++++++++
2653f00
 2 files changed, 24 insertions(+), 1 deletion(-)
2653f00
 create mode 100644 test/CodeGen/X86/inline-asm-modifier-V.ll
2653f00
2653f00
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
2653f00
index dc15aea..8c7ddd9 100644
2653f00
--- a/lib/Target/X86/X86AsmPrinter.cpp
2653f00
+++ b/lib/Target/X86/X86AsmPrinter.cpp
2653f00
@@ -344,6 +344,8 @@ static void printIntelMemReference(X86AsmPrinter &P, const MachineInstr *MI,
2653f00
 static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
2653f00
                               char Mode, raw_ostream &O) {
2653f00
   unsigned Reg = MO.getReg();
2653f00
+  bool EmitPercent = true;
2653f00
+
2653f00
   switch (Mode) {
2653f00
   default: return true;  // Unknown mode.
2653f00
   case 'b': // Print QImode register
2653f00
@@ -358,6 +360,9 @@ static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
2653f00
   case 'k': // Print SImode register
2653f00
     Reg = getX86SubSuperRegister(Reg, 32);
2653f00
     break;
2653f00
+  case 'V':
2653f00
+    EmitPercent = false;
2653f00
+    LLVM_FALLTHROUGH;
2653f00
   case 'q':
2653f00
     // Print 64-bit register names if 64-bit integer registers are available.
2653f00
     // Otherwise, print 32-bit register names.
2653f00
@@ -365,7 +370,10 @@ static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
2653f00
     break;
2653f00
   }
2653f00
 
2653f00
-  O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
2653f00
+  if (EmitPercent)
2653f00
+    O << '%';
2653f00
+
2653f00
+  O << X86ATTInstPrinter::getRegisterName(Reg);
2653f00
   return false;
2653f00
 }
2653f00
 
2653f00
@@ -438,6 +446,7 @@ bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
2653f00
     case 'w': // Print HImode register
2653f00
     case 'k': // Print SImode register
2653f00
     case 'q': // Print DImode register
2653f00
+    case 'V': // Print native register without '%'
2653f00
       if (MO.isReg())
2653f00
         return printAsmMRegister(*this, MO, ExtraCode[0], O);
2653f00
       printOperand(*this, MI, OpNo, O);
2653f00
diff --git a/test/CodeGen/X86/inline-asm-modifier-V.ll b/test/CodeGen/X86/inline-asm-modifier-V.ll
2653f00
new file mode 100644
2653f00
index 0000000..5a7f3fd
2653f00
--- /dev/null
2653f00
+++ b/test/CodeGen/X86/inline-asm-modifier-V.ll
2653f00
@@ -0,0 +1,14 @@
2653f00
+; RUN: llc < %s -mtriple=i686-- -no-integrated-as | FileCheck -check-prefix=X86 %s
2653f00
+; RUN: llc < %s -mtriple=x86_64-- -no-integrated-as | FileCheck -check-prefix=X64 %s
2653f00
+
2653f00
+; If the target does not have 64-bit integer registers, emit 32-bit register
2653f00
+; names.
2653f00
+
2653f00
+; X86: call __x86_indirect_thunk_e{{[abcd]}}x
2653f00
+; X64: call __x86_indirect_thunk_r
2653f00
+
2653f00
+define void @q_modifier(i32* %p) {
2653f00
+entry:
2653f00
+  tail call void asm sideeffect "call __x86_indirect_thunk_${0:V}", "r,~{dirflag},~{fpsr},~{flags}"(i32* %p)
2653f00
+  ret void
2653f00
+}
2653f00
-- 
2653f00
1.8.3.1
2653f00