llvm.org GIT mirror llvm / 93f085c
Merging r368477: ------------------------------------------------------------------------ r368477 | void | 2019-08-09 22:16:31 +0200 (Fri, 09 Aug 2019) | 22 lines [MC] Don't recreate a label if it's already used Summary: This patch keeps track of MCSymbols created for blocks that were referenced in inline asm. It prevents creating a new symbol which doesn't refer to the block. Inline asm may have a reference to a label. The asm parser however doesn't recognize it as a label and tries to create a new symbol. The result being that instead of the original symbol (e.g. ".Ltmp0") the parser replaces it in the inline asm with the new one (e.g. ".Ltmp00") without updating it in the symbol table. So the machine basic block retains the "old" symbol (".Ltmp0"), but the inline asm uses the new one (".Ltmp00"). Reviewers: nickdesaulniers, craig.topper Subscribers: nathanchance, javed.absar, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65304 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_90@368676 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 2 months ago
7 changed file(s) with 124 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
111111 /// number of section symbols with the same name).
112112 StringMap UsedNames;
113113
114 /// Keeps track of labels that are used in inline assembly.
115 SymbolTable InlineAsmUsedLabelNames;
116
114117 /// The next ID to dole out to an unnamed assembler temporary symbol with
115118 /// a given prefix.
116119 StringMap NextID;
375378 /// still want any modifications to the table itself to use the MCContext
376379 /// APIs.
377380 const SymbolTable &getSymbols() const { return Symbols; }
381
382 /// isInlineAsmLabel - Return true if the name is a label referenced in
383 /// inline assembly.
384 MCSymbol *getInlineAsmLabel(StringRef Name) const {
385 return InlineAsmUsedLabelNames.lookup(Name);
386 }
387
388 /// registerInlineAsmLabel - Records that the name is a label referenced in
389 /// inline assembly.
390 void registerInlineAsmLabel(MCSymbol *Sym);
378391
379392 /// @}
380393
431431 const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
432432 MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
433433 Sym->print(OS, AP->MAI);
434 MMI->getContext().registerInlineAsmLabel(Sym);
434435 } else if (MI->getOperand(OpNo).isMBB()) {
435436 const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
436437 Sym->print(OS, AP->MAI);
6060 bool DoAutoReset)
6161 : SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
6262 Symbols(Allocator), UsedNames(Allocator),
63 InlineAsmUsedLabelNames(Allocator),
6364 CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
6465 AutoReset(DoAutoReset) {
6566 SecureLogFile = AsSecureLogFileName;
8990 XCOFFAllocator.DestroyAll();
9091
9192 MCSubtargetAllocator.DestroyAll();
93 InlineAsmUsedLabelNames.clear();
9294 UsedNames.clear();
9395 Symbols.clear();
9496 Allocator.Reset();
269271 uint64_t Val) {
270272 auto Symbol = getOrCreateSymbol(Sym);
271273 Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
274 }
275
276 void MCContext::registerInlineAsmLabel(MCSymbol *Sym) {
277 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
272278 }
273279
274280 //===----------------------------------------------------------------------===//
11411141 }
11421142 }
11431143
1144 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
1144 MCSymbol *Sym = getContext().getInlineAsmLabel(SymbolName);
1145 if (!Sym)
1146 Sym = getContext().getOrCreateSymbol(SymbolName);
11451147
11461148 // If this is an absolute variable reference, substitute it now to preserve
11471149 // semantics in the face of reassignment.
0 ; RUN: llc < %s -mtriple=aarch64-linux-gnu | FileCheck %s
1
2 @X = common local_unnamed_addr global i32 0, align 4
3
4 define i32 @test1() {
5 ; CHECK-LABEL: test1:
6 ; CHECK: .word b
7 ; CHECK-NEXT: .word .Ltmp0
8 ; CHECK-LABEL: .Ltmp0:
9 ; CHECK-LABEL: .LBB0_1: // %l_yes
10 ; CHECK-LABEL: .LBB0_2: // %cleanup
11 entry:
12 callbr void asm sideeffect "1:\0A\09.word b, ${0:l}\0A\09", "X"(i8* blockaddress(@test1, %l_yes))
13 to label %cleanup [label %l_yes]
14
15 l_yes:
16 br label %cleanup
17
18 cleanup:
19 %retval.0 = phi i32 [ 1, %l_yes ], [ 0, %entry ]
20 ret i32 %retval.0
21 }
22
23 define void @test2() {
24 ; CHECK-LABEL: test2:
25 entry:
26 %0 = load i32, i32* @X, align 4
27 %and = and i32 %0, 1
28 %tobool = icmp eq i32 %and, 0
29 br i1 %tobool, label %if.end10, label %if.then
30
31 if.then:
32 ; CHECK: .word b
33 ; CHECK-NEXT: .word .Ltmp2
34 ; CHECK-LABEL: .Ltmp2:
35 ; CHECK-NEXT: .LBB1_3: // %if.end6
36 callbr void asm sideeffect "1:\0A\09.word b, ${0:l}\0A\09", "X"(i8* blockaddress(@test2, %if.end6))
37 to label %if.then4 [label %if.end6]
38
39 if.then4:
40 %call5 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
41 br label %if.end6
42
43 if.end6:
44 %.pre = load i32, i32* @X, align 4
45 %.pre13 = and i32 %.pre, 1
46 %phitmp = icmp eq i32 %.pre13, 0
47 br i1 %phitmp, label %if.end10, label %if.then9
48
49 if.then9:
50 ; CHECK-LABEL: .Ltmp4:
51 ; CHECK-NEXT: .LBB1_5: // %l_yes
52 callbr void asm sideeffect "", "X"(i8* blockaddress(@test2, %l_yes))
53 to label %if.end10 [label %l_yes]
54
55 if.end10:
56 br label %l_yes
57
58 l_yes:
59 ret void
60 }
61
62 declare i32 @g(...)
0 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
1
2 define i32 @test1(i32 %x) {
3 ; CHECK-LABEL: test1:
4 ; CHECK: .quad .Ltmp0
5 ; CHECK-NEXT: .quad .Ltmp1
6 ; CHECK-LABEL: .Ltmp1:
7 ; CHECK-LABEL: .LBB0_1: # %bar
8 ; CHECK-NEXT: callq foo
9 ; CHECK-LABEL: .Ltmp0:
10 ; CHECK-NEXT: # %bb.2: # %baz
11 entry:
12 callbr void asm sideeffect ".quad ${0:l}\0A\09.quad ${1:l}", "i,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %baz), i8* blockaddress(@test1, %bar))
13 to label %asm.fallthrough [label %bar]
14
15 asm.fallthrough:
16 br label %bar
17
18 bar:
19 %call = tail call i32 @foo(i32 %x)
20 br label %baz
21
22 baz:
23 %call1 = tail call i32 @mux(i32 %call)
24 ret i32 %call1
25 }
26
27 declare i32 @foo(i32)
28
29 declare i32 @mux(i32)
1111 ; CHECK-NEXT: addl $4, %eax
1212 ; CHECK-NEXT: #APP
1313 ; CHECK-NEXT: xorl %eax, %eax
14 ; CHECK-NEXT: jmp .Ltmp00
14 ; CHECK-NEXT: jmp .Ltmp0
1515 ; CHECK-NEXT: #NO_APP
1616 ; CHECK-NEXT: .LBB0_1: # %normal
1717 ; CHECK-NEXT: xorl %eax, %eax
8686 ; CHECK-NEXT: # Parent Loop BB2_3 Depth=3
8787 ; CHECK-NEXT: # => This Inner Loop Header: Depth=4
8888 ; CHECK-NEXT: #APP
89 ; CHECK-NEXT: jmp .Ltmp10
90 ; CHECK-NEXT: jmp .Ltmp20
91 ; CHECK-NEXT: jmp .Ltmp30
89 ; CHECK-NEXT: jmp .Ltmp1
90 ; CHECK-NEXT: jmp .Ltmp2
91 ; CHECK-NEXT: jmp .Ltmp3
9292 ; CHECK-NEXT: #NO_APP
9393 ; CHECK-NEXT: .LBB2_5: # %normal0
9494 ; CHECK-NEXT: # in Loop: Header=BB2_4 Depth=4
9595 ; CHECK-NEXT: #APP
96 ; CHECK-NEXT: jmp .Ltmp10
97 ; CHECK-NEXT: jmp .Ltmp20
98 ; CHECK-NEXT: jmp .Ltmp30
99 ; CHECK-NEXT: jmp .Ltmp40
96 ; CHECK-NEXT: jmp .Ltmp1
97 ; CHECK-NEXT: jmp .Ltmp2
98 ; CHECK-NEXT: jmp .Ltmp3
99 ; CHECK-NEXT: jmp .Ltmp4
100100 ; CHECK-NEXT: #NO_APP
101101 ; CHECK-NEXT: .LBB2_6: # %normal1
102102 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax