[llvm] r288092 - Recognize ${:uid} escapes in intel syntax inline asm
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 16:29:28 PST 2016
Author: rnk
Date: Mon Nov 28 18:29:27 2016
New Revision: 288092
URL: http://llvm.org/viewvc/llvm-project?rev=288092&view=rev
Log:
Recognize ${:uid} escapes in intel syntax inline asm
It looks like this logic was duplicated long ago and the GCC side of
things has grown additional functionality. We need ${:uid} at least to
generate unique MS inline asm labels (PR23715), so expose these.
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/trunk/test/CodeGen/X86/ms-inline-asm.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=288092&r1=288091&r2=288092&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Mon Nov 28 18:29:27 2016
@@ -193,6 +193,23 @@ static void EmitMSInlineAsmStr(const cha
}
if (Done) break;
+ // If we have ${:foo}, then this is not a real operand reference, it is a
+ // "magic" string reference, just like in .td files. Arrange to call
+ // PrintSpecial.
+ if (LastEmitted[0] == '{' && LastEmitted[1] == ':') {
+ LastEmitted += 2;
+ const char *StrStart = LastEmitted;
+ const char *StrEnd = strchr(StrStart, '}');
+ if (!StrEnd)
+ report_fatal_error("Unterminated ${:foo} operand in inline asm"
+ " string: '" + Twine(AsmStr) + "'");
+
+ std::string Val(StrStart, StrEnd);
+ AP->PrintSpecial(MI, OS, Val.c_str());
+ LastEmitted = StrEnd+1;
+ break;
+ }
+
const char *IDStart = LastEmitted;
const char *IDEnd = IDStart;
while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
Modified: llvm/trunk/test/CodeGen/X86/ms-inline-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/ms-inline-asm.ll?rev=288092&r1=288091&r2=288092&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/ms-inline-asm.ll (original)
+++ llvm/trunk/test/CodeGen/X86/ms-inline-asm.ll Mon Nov 28 18:29:27 2016
@@ -126,6 +126,37 @@ entry:
; CHECK: ret
}
+; Make sure ${:uid} works. Clang uses it for MS inline asm labels.
+;
+; C source:
+; int uid() {
+; int r;
+; __asm {
+; xor eax, eax
+; wloop:
+; inc eax
+; cmp eax, 42
+; jne wloop
+; mov r, eax
+; }
+; return r;
+; }
+define i32 @uid() {
+entry:
+ %r = alloca i32, align 4
+ %0 = bitcast i32* %r to i8*
+ call void asm sideeffect inteldialect "xor eax, eax\0A\09.L__MSASMLABEL_.${:uid}__wloop:\0A\09inc eax\0A\09cmp eax, $$42\0A\09jne .L__MSASMLABEL_.${:uid}__wloop\0A\09mov dword ptr $0, eax", "=*m,~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"(i32* nonnull %r)
+ %1 = load i32, i32* %r, align 4
+ ret i32 %1
+; CHECK-LABEL: uid:
+; CHECK: {{## InlineAsm Start|#APP}}
+; CHECK: .L__MSASMLABEL_.0__wloop:
+; CHECK: jne .L__MSASMLABEL_.0__wloop
+; CHECK: .att_syntax
+; CHECK: {{## InlineAsm End|#NO_APP}}
+; CHECK: ret
+}
+
declare hidden void @other_func()
define void @naked() #0 {
More information about the llvm-commits
mailing list