diff options
author | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
---|---|---|
committer | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
commit | 954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a (patch) | |
tree | 23479cbe88acf8d056fb2e8d5c44a9978290c5fb /clang/test/CodeGen | |
parent | 192dd7df2f3104274db57e3b853390faa7e1aa25 (diff) | |
download | bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.tar.gz bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.zip |
clang support gnu asm goto.
Syntax:
asm [volatile] goto ( AssemblerTemplate
:
: InputOperands
: Clobbers
: GotoLabels)
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1
to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3
asm.fallthrough:
Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".
Diagnostic
1> duplicate asm operand name are used in output, input and label.
2> goto out of scope.
llvm-svn: 362045
Diffstat (limited to 'clang/test/CodeGen')
-rw-r--r-- | clang/test/CodeGen/asm-goto.c | 18 | ||||
-rw-r--r-- | clang/test/CodeGen/asm.c | 12 | ||||
-rw-r--r-- | clang/test/CodeGen/inline-asm-mixed-style.c | 10 |
3 files changed, 35 insertions, 5 deletions
diff --git a/clang/test/CodeGen/asm-goto.c b/clang/test/CodeGen/asm-goto.c new file mode 100644 index 00000000000..2c4a1a0c4df --- /dev/null +++ b/clang/test/CodeGen/asm-goto.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -O0 -emit-llvm %s -o - | FileCheck %s + +int foo(int cond) +{ + // CHECK: callbr void asm sideeffect + // CHECK: to label %asm.fallthrough [label %label_true, label %loop], !srcloc !2 + // CHECK: asm.fallthrough: + asm volatile goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop); + asm volatile goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop); + // CHECK: callbr void asm sideeffect + // CHECK: to label %asm.fallthrough1 [label %label_true, label %loop], !srcloc !3 + // CHECK: asm.fallthrough1: + return 0; +loop: + return 0; +label_true: + return 1; +} diff --git a/clang/test/CodeGen/asm.c b/clang/test/CodeGen/asm.c index 038d346e999..7de79639bfd 100644 --- a/clang/test/CodeGen/asm.c +++ b/clang/test/CodeGen/asm.c @@ -262,3 +262,15 @@ void t31(int len) { // CHECK: @t31 // CHECK: call void asm sideeffect "", "=*%rm,=*rm,0,1,~{dirflag},~{fpsr},~{flags}" } + +// CHECK: @t32 +int t32(int cond) +{ + asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop); + // CHECK: callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@t32, %label_true), i8* blockaddress(@t32, %loop)) #1 + return 0; +loop: + return 0; +label_true: + return 1; +} diff --git a/clang/test/CodeGen/inline-asm-mixed-style.c b/clang/test/CodeGen/inline-asm-mixed-style.c index 6b830d9fa7a..a9e111cd5dd 100644 --- a/clang/test/CodeGen/inline-asm-mixed-style.c +++ b/clang/test/CodeGen/inline-asm-mixed-style.c @@ -1,4 +1,3 @@ -// RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -fsyntax-only -verify %s -DCHECK_ASM_GOTO // RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -O0 -emit-llvm -S %s -o - | FileCheck %s // REQUIRES: x86-registered-target @@ -20,10 +19,11 @@ void f() { // CHECK: movl %ebx, %eax // CHECK: movl %ecx, %edx -#ifdef CHECK_ASM_GOTO - __asm volatile goto ("movl %ecx, %edx"); // expected-error {{'asm goto' constructs are not supported yet}} + __asm volatile goto ("movl %ecx, %edx"); + // CHECK: movl %ecx, %edx __asm mov eax, ebx - __asm goto ("movl %ecx, %edx"); // expected-error {{'asm goto' constructs are not supported yet}} -#endif + __asm goto ("movl %ecx, %edx"); + // CHECK: movl %ebx, %eax + // CHECK: movl %ecx, %edx } |