[llvm] r368478 - [CodeGen] Require a name for a block addr target

Bill Wendling via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 13:18:30 PDT 2019


Author: void
Date: Fri Aug  9 13:18:30 2019
New Revision: 368478

URL: http://llvm.org/viewvc/llvm-project?rev=368478&view=rev
Log:
[CodeGen] Require a name for a block addr target

Summary:
A block address may be used in inline assembly. In which case it
requires a name so that the asm parser has something to parse. Creating
a name for every block address is a large hammer, but is necessary
because at the point when a temp symbol is created we don't necessarily
know if it's used in inline asm. This ensures that it exists regardless.

Reviewers: nickdesaulniers, craig.topper

Subscribers: nathanchance, javed.absar, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65352

Added:
    llvm/trunk/test/CodeGen/AArch64/callbr-asm-obj-file.ll
    llvm/trunk/test/CodeGen/X86/callbr-asm-obj-file.ll
Modified:
    llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp

Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=368478&r1=368477&r2=368478&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Fri Aug  9 13:18:30 2019
@@ -121,7 +121,7 @@ ArrayRef<MCSymbol *> MMIAddrLabelMap::ge
   BBCallbacks.back().setMap(this);
   Entry.Index = BBCallbacks.size() - 1;
   Entry.Fn = BB->getParent();
-  Entry.Symbols.push_back(Context.createTempSymbol());
+  Entry.Symbols.push_back(Context.createTempSymbol(!BB->hasAddressTaken()));
   return Entry.Symbols;
 }
 

Added: llvm/trunk/test/CodeGen/AArch64/callbr-asm-obj-file.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/callbr-asm-obj-file.ll?rev=368478&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/callbr-asm-obj-file.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/callbr-asm-obj-file.ll Fri Aug  9 13:18:30 2019
@@ -0,0 +1,102 @@
+; RUN: llc < %s -mtriple=aarch64-unknown-linux-gnu -filetype=obj -o - \
+; RUN:  | llvm-objdump -triple aarch64-unknown-linux-gnu -d - \
+; RUN:  | FileCheck %s
+
+%struct.c = type { i1 (...)* }
+
+ at l = common hidden local_unnamed_addr global i32 0, align 4
+
+; CHECK-LABEL: 0000000000000000 test1:
+; CHECK-LABEL: 0000000000000018 $d.1:
+; CHECK-LABEL: 0000000000000020 $x.2:
+; CHECK-NEXT:    b #16 <$x.4+0x4>
+; CHECK-LABEL: 000000000000002c $x.4:
+; CHECK-NEXT:    b #4 <$x.4+0x4>
+; CHECK-NEXT:    mov w0, wzr
+; CHECK-NEXT:    ldr x30, [sp], #16
+; CHECK-NEXT:    ret
+define hidden i32 @test1() {
+  %1 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
+  %2 = icmp eq i32 %1, 0
+  br i1 %2, label %3, label %5
+
+3:                                                ; preds = %0
+  callbr void asm sideeffect "1: nop\0A\09.quad a\0A\09b ${1:l}\0A\09.quad ${0:c}", "i,X"(i32* null, i8* blockaddress(@test1, %7))
+          to label %4 [label %7]
+
+4:                                                ; preds = %3
+  br label %7
+
+5:                                                ; preds = %0
+  %6 = tail call i32 bitcast (i32 (...)* @i to i32 ()*)()
+  br label %7
+
+7:                                                ; preds = %3, %4, %5
+  %8 = phi i32 [ %6, %5 ], [ 0, %4 ], [ 0, %3 ]
+  ret i32 %8
+}
+
+declare dso_local i32 @g(...) local_unnamed_addr
+
+declare dso_local i32 @i(...) local_unnamed_addr
+
+; CHECK-LABEL: 000000000000003c test2:
+; CHECK:         bl #0 <test2+0x18>
+; CHECK-LABEL: 0000000000000064 $d.5:
+; CHECK-LABEL: 000000000000006c $x.6:
+; CHECK-NEXT:    b #-24 <test2+0x18>
+define hidden i32 @test2() local_unnamed_addr {
+  %1 = load i32, i32* @l, align 4
+  %2 = icmp eq i32 %1, 0
+  br i1 %2, label %10, label %3
+
+3:                                                ; preds = %0
+  %4 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
+  %5 = icmp eq i32 %4, 0
+  br i1 %5, label %6, label %7
+
+6:                                                ; preds = %3
+  callbr void asm sideeffect "1: nop\0A\09.quad b\0A\09b ${1:l}\0A\09.quad ${0:c}", "i,X"(i32* null, i8* blockaddress(@test2, %7))
+          to label %10 [label %9]
+
+7:                                                ; preds = %3
+  %8 = tail call i32 bitcast (i32 (...)* @i to i32 ()*)()
+  br label %10
+
+9:                                                ; preds = %6
+  br label %10
+
+10:                                               ; preds = %7, %0, %6, %9
+  ret i32 undef
+}
+
+; CHECK-LABEL: 0000000000000084 test3:
+; CHECK-LABEL: 00000000000000a8 $d.9:
+; CHECK-LABEL: 00000000000000b0 $x.10:
+; CHECK-NEXT:    b #20 <$x.12+0x8>
+; CHECK-LABEL: 00000000000000bc $x.12:
+; CHECK-NEXT:    b #4 <$x.12+0x4>
+; CHECK-NEXT:    mov w0, wzr
+; CHECK-NEXT:    ldr x30, [sp], #16
+; CHECK-NEXT:    ret
+define internal i1 @test3() {
+  %1 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
+  %2 = icmp eq i32 %1, 0
+  br i1 %2, label %3, label %5
+
+3:                                                ; preds = %0
+  callbr void asm sideeffect "1: nop\0A\09.quad c\0A\09b ${1:l}\0A\09.quad ${0:c}", "i,X"(i32* null, i8* blockaddress(@test3, %8))
+          to label %4 [label %8]
+
+4:                                                ; preds = %3
+  br label %8
+
+5:                                                ; preds = %0
+  %6 = tail call i32 bitcast (i32 (...)* @i to i32 ()*)()
+  %7 = icmp ne i32 %6, 0
+  br label %8
+
+8:                                                ; preds = %3, %4, %5
+  %9 = phi i1 [ %7, %5 ], [ false, %4 ], [ false, %3 ]
+  ret i1 %9
+}

Added: llvm/trunk/test/CodeGen/X86/callbr-asm-obj-file.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/callbr-asm-obj-file.ll?rev=368478&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/callbr-asm-obj-file.ll (added)
+++ llvm/trunk/test/CodeGen/X86/callbr-asm-obj-file.ll Fri Aug  9 13:18:30 2019
@@ -0,0 +1,19 @@
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -filetype=obj -o - \
+; RUN:  | llvm-objdump -triple x86_64-linux-gnu -d - \
+; RUN:  | FileCheck %s
+
+; CHECK: 0000000000000000 test1:
+; CHECK-NEXT:   0: 74 00 je 0 <test1+0x2>
+; CHECK-NEXT:   2: c3    retq
+
+define void @test1() {
+entry:
+  callbr void asm sideeffect "je ${0:l}", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %a.b.normal.jump))
+          to label %asm.fallthrough [label %a.b.normal.jump]
+
+asm.fallthrough:
+  ret void
+
+a.b.normal.jump:
+  ret void
+}




More information about the llvm-commits mailing list