All,
Following up on my previous post about MS-style inline assembly [1], the
attached patches add support for a new inline assembly dialect function
attribute. This new attribute is intended to be used by the backend to
determine how the inline asm string should be parsed/printed. The llvm patch
adds the attdialect and inteldialect attributes and also adds a test case to
ensure the IR is correctly parsed, but there is no functional change at this
time. The clang patch adds the attdialect attribute to GNU-style inline
assembly statements with a test case. There was some discussion of adding an
asmdialect attribute that accepted an optional argument (e.g., asmdialect
"intel", asmdialect "att"), but this looks to add a great deal of complexity to
the attribute handling with minimal benefit.
Chad
[1] http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-August/052356.html)
Index: test/CodeGen/asm.c
===================================================================
--- test/CodeGen/asm.c (revision 161369)
+++ test/CodeGen/asm.c (working copy)
@@ -220,3 +220,11 @@
void t26 (__m256i *p) {
__asm__ volatile("vmovaps %0, %%ymm0" :: "m" (*(__m256i*)p) : "ymm0");
}
+
+// Check to make sure AT&T syntax attribute is emitted.
+void t27(void) {
+ asm volatile("nop");
+// CHECK: @t27
+// CHECK: call void asm sideeffect "nop"
+// CHECK: nounwind attdialect
+}
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp (revision 161369)
+++ lib/CodeGen/CGStmt.cpp (working copy)
@@ -1633,6 +1633,7 @@
S.isVolatile() || S.getNumOutputs() == 0);
llvm::CallInst *Result = Builder.CreateCall(IA, Args);
Result->addAttribute(~0, llvm::Attribute::NoUnwind);
+ Result->addAttribute(~0, llvm::Attribute::ATTDialect);
// Slap the source location of the inline asm into a !srcloc metadata on the
// call.
Index: test/CodeGen/X86/inline-asm.ll
===================================================================
--- test/CodeGen/X86/inline-asm.ll (revision 161369)
+++ test/CodeGen/X86/inline-asm.ll (working copy)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=x86
+; RUN: llc < %s -march=x86 | FileCheck %s
define i32 @test1() nounwind {
; Dest is AX, dest type = i32.
@@ -52,3 +52,14 @@
%0 = call { i32, i32, i32, i32, i32 } asm sideeffect "",
"=&r,=&r,=&r,=&r,=&q,r,~{ecx},~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %h)
nounwind
ret void
}
+
+; Check to make sure we can parse the attdialect attribute.
+define void @t8() nounwind {
+entry:
+ call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
attdialect
+ ret void
+; CHECK: _t8
+; CHECK: ## InlineAsm Start
+; CHECK-NEXT: nop
+; CHECK-NEXT: ## InlineAsm End
+}
Index: include/llvm/Attributes.h
===================================================================
--- include/llvm/Attributes.h (revision 161369)
+++ include/llvm/Attributes.h (working copy)
@@ -134,6 +134,8 @@
/// often, so lazy binding isn't
/// worthwhile.
DECLARE_LLVM_ATTRIBUTE(AddressSafety,1ULL<<32) ///< Address safety checking is
on.
+DECLARE_LLVM_ATTRIBUTE(ATTDialect,1ULL<<33) ///< AT&T inline asm syntax.
+DECLARE_LLVM_ATTRIBUTE(IntelDialect,1ULL<<34) ///< Intel inline asm syntax.
#undef DECLARE_LLVM_ATTRIBUTE
@@ -159,7 +161,8 @@
ReadOnly_i | NoInline_i | AlwaysInline_i | OptimizeForSize_i |
StackProtect_i | StackProtectReq_i | NoRedZone_i | NoImplicitFloat_i |
Naked_i | InlineHint_i | StackAlignment_i |
- UWTable_i | NonLazyBind_i | ReturnsTwice_i | AddressSafety_i};
+ UWTable_i | NonLazyBind_i | ReturnsTwice_i | AddressSafety_i |
+ ATTDialect_i | IntelDialect_i};
/// @brief Parameter attributes that do not apply to vararg call arguments.
const AttrConst VarArgsIncompatible = {StructRet_i};
Index: utils/llvm.grm
===================================================================
--- utils/llvm.grm (revision 161369)
+++ utils/llvm.grm (working copy)
@@ -175,6 +175,8 @@
| returns_twice
| nonlazybind
| address_safety
+ | attdialect
+ | inteldialect
;
OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
Index: lib/VMCore/Attributes.cpp
===================================================================
--- lib/VMCore/Attributes.cpp (revision 161369)
+++ lib/VMCore/Attributes.cpp (working copy)
@@ -88,6 +88,11 @@
Result += utostr(Attribute::getAlignmentFromAttrs(Attrs));
Result += " ";
}
+ if (Attrs & Attribute::ATTDialect)
+ Result += "attdialect ";
+ if (Attrs & Attribute::IntelDialect)
+ Result += "inteldialect ";
+
// Trim the trailing space.
assert(!Result.empty() && "Unknown attribute!");
Result.erase(Result.end()-1);
Index: lib/AsmParser/LLParser.cpp
===================================================================
--- lib/AsmParser/LLParser.cpp (revision 161369)
+++ lib/AsmParser/LLParser.cpp (working copy)
@@ -962,6 +962,8 @@
case lltok::kw_naked: Attrs |= Attribute::Naked; break;
case lltok::kw_nonlazybind: Attrs |= Attribute::NonLazyBind; break;
case lltok::kw_address_safety: Attrs |= Attribute::AddressSafety; break;
+ case lltok::kw_attdialect: Attrs |= Attribute::ATTDialect; break;
+ case lltok::kw_inteldialect: Attrs |= Attribute::IntelDialect; break;
case lltok::kw_alignstack: {
unsigned Alignment;
Index: lib/AsmParser/LLLexer.cpp
===================================================================
--- lib/AsmParser/LLLexer.cpp (revision 161369)
+++ lib/AsmParser/LLLexer.cpp (working copy)
@@ -553,6 +553,8 @@
KEYWORD(naked);
KEYWORD(nonlazybind);
KEYWORD(address_safety);
+ KEYWORD(attdialect);
+ KEYWORD(inteldialect);
KEYWORD(type);
KEYWORD(opaque);
Index: lib/AsmParser/LLToken.h
===================================================================
--- lib/AsmParser/LLToken.h (revision 161369)
+++ lib/AsmParser/LLToken.h (working copy)
@@ -105,6 +105,8 @@
kw_naked,
kw_nonlazybind,
kw_address_safety,
+ kw_attdialect,
+ kw_inteldialect,
kw_type,
kw_opaque,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits