[llvm-branch-commits] [llvm-branch] r368676 - Merging r368477:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 13 05:07:33 PDT 2019


Author: hans
Date: Tue Aug 13 05:07:33 2019
New Revision: 368676

URL: http://llvm.org/viewvc/llvm-project?rev=368676&view=rev
Log:
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
------------------------------------------------------------------------

Added:
    llvm/branches/release_90/test/CodeGen/AArch64/callbr-asm-label.ll
      - copied unchanged from r368477, llvm/trunk/test/CodeGen/AArch64/callbr-asm-label.ll
    llvm/branches/release_90/test/CodeGen/X86/callbr-asm-label-addr.ll
      - copied unchanged from r368477, llvm/trunk/test/CodeGen/X86/callbr-asm-label-addr.ll
Modified:
    llvm/branches/release_90/   (props changed)
    llvm/branches/release_90/include/llvm/MC/MCContext.h
    llvm/branches/release_90/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
    llvm/branches/release_90/lib/MC/MCContext.cpp
    llvm/branches/release_90/lib/MC/MCParser/AsmParser.cpp
    llvm/branches/release_90/test/CodeGen/X86/callbr-asm.ll

Propchange: llvm/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 13 05:07:33 2019
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,366431,366481,366487,366527,366570,366660,366868,366925,367030,367062,367124,367215,367292,367304,367306,367314,367340-367341,367394,367396,367398,367403,367417,367662,367750,367753,367846-367847,367898,367941,368004,368230,368315,368324,368517-368519,368554,368572
+/llvm/trunk:155241,366431,366481,366487,366527,366570,366660,366868,366925,367030,367062,367124,367215,367292,367304,367306,367314,367340-367341,367394,367396,367398,367403,367417,367662,367750,367753,367846-367847,367898,367941,368004,368230,368315,368324,368477,368517-368519,368554,368572

Modified: llvm/branches/release_90/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/include/llvm/MC/MCContext.h?rev=368676&r1=368675&r2=368676&view=diff
==============================================================================
--- llvm/branches/release_90/include/llvm/MC/MCContext.h (original)
+++ llvm/branches/release_90/include/llvm/MC/MCContext.h Tue Aug 13 05:07:33 2019
@@ -112,6 +112,9 @@ namespace llvm {
     /// number of section symbols with the same name).
     StringMap<bool, BumpPtrAllocator &> UsedNames;
 
+    /// Keeps track of labels that are used in inline assembly.
+    SymbolTable InlineAsmUsedLabelNames;
+
     /// The next ID to dole out to an unnamed assembler temporary symbol with
     /// a given prefix.
     StringMap<unsigned> NextID;
@@ -377,6 +380,16 @@ namespace llvm {
     /// APIs.
     const SymbolTable &getSymbols() const { return Symbols; }
 
+    /// isInlineAsmLabel - Return true if the name is a label referenced in
+    /// inline assembly.
+    MCSymbol *getInlineAsmLabel(StringRef Name) const {
+      return InlineAsmUsedLabelNames.lookup(Name);
+    }
+
+    /// registerInlineAsmLabel - Records that the name is a label referenced in
+    /// inline assembly.
+    void registerInlineAsmLabel(MCSymbol *Sym);
+
     /// @}
 
     /// \name Section Management

Modified: llvm/branches/release_90/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=368676&r1=368675&r2=368676&view=diff
==============================================================================
--- llvm/branches/release_90/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/branches/release_90/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Tue Aug 13 05:07:33 2019
@@ -432,6 +432,7 @@ static void EmitGCCInlineAsmStr(const ch
               const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
               MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
               Sym->print(OS, AP->MAI);
+              MMI->getContext().registerInlineAsmLabel(Sym);
             } else if (MI->getOperand(OpNo).isMBB()) {
               const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
               Sym->print(OS, AP->MAI);

Modified: llvm/branches/release_90/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/lib/MC/MCContext.cpp?rev=368676&r1=368675&r2=368676&view=diff
==============================================================================
--- llvm/branches/release_90/lib/MC/MCContext.cpp (original)
+++ llvm/branches/release_90/lib/MC/MCContext.cpp Tue Aug 13 05:07:33 2019
@@ -61,6 +61,7 @@ MCContext::MCContext(const MCAsmInfo *ma
                      bool DoAutoReset)
     : SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
       Symbols(Allocator), UsedNames(Allocator),
+      InlineAsmUsedLabelNames(Allocator),
       CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
       AutoReset(DoAutoReset) {
   SecureLogFile = AsSecureLogFileName;
@@ -90,6 +91,7 @@ void MCContext::reset() {
   XCOFFAllocator.DestroyAll();
 
   MCSubtargetAllocator.DestroyAll();
+  InlineAsmUsedLabelNames.clear();
   UsedNames.clear();
   Symbols.clear();
   Allocator.Reset();
@@ -272,6 +274,10 @@ void MCContext::setSymbolValue(MCStreame
   Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
 }
 
+void MCContext::registerInlineAsmLabel(MCSymbol *Sym) {
+  InlineAsmUsedLabelNames[Sym->getName()] = Sym;
+}
+
 //===----------------------------------------------------------------------===//
 // Section Management
 //===----------------------------------------------------------------------===//

Modified: llvm/branches/release_90/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/lib/MC/MCParser/AsmParser.cpp?rev=368676&r1=368675&r2=368676&view=diff
==============================================================================
--- llvm/branches/release_90/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/branches/release_90/lib/MC/MCParser/AsmParser.cpp Tue Aug 13 05:07:33 2019
@@ -1142,7 +1142,9 @@ bool AsmParser::parsePrimaryExpr(const M
       }
     }
 
-    MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
+    MCSymbol *Sym = getContext().getInlineAsmLabel(SymbolName);
+    if (!Sym)
+      Sym = getContext().getOrCreateSymbol(SymbolName);
 
     // If this is an absolute variable reference, substitute it now to preserve
     // semantics in the face of reassignment.

Modified: llvm/branches/release_90/test/CodeGen/X86/callbr-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/test/CodeGen/X86/callbr-asm.ll?rev=368676&r1=368675&r2=368676&view=diff
==============================================================================
--- llvm/branches/release_90/test/CodeGen/X86/callbr-asm.ll (original)
+++ llvm/branches/release_90/test/CodeGen/X86/callbr-asm.ll Tue Aug 13 05:07:33 2019
@@ -12,7 +12,7 @@ define i32 @test1(i32 %a) {
 ; CHECK-NEXT:    addl $4, %eax
 ; CHECK-NEXT:    #APP
 ; CHECK-NEXT:    xorl %eax, %eax
-; CHECK-NEXT:    jmp .Ltmp00
+; CHECK-NEXT:    jmp .Ltmp0
 ; CHECK-NEXT:    #NO_APP
 ; CHECK-NEXT:  .LBB0_1: # %normal
 ; CHECK-NEXT:    xorl %eax, %eax
@@ -87,17 +87,17 @@ define dso_local i32 @test3(i32 %a) {
 ; CHECK-NEXT:    # Parent Loop BB2_3 Depth=3
 ; CHECK-NEXT:    # => This Inner Loop Header: Depth=4
 ; CHECK-NEXT:    #APP
-; CHECK-NEXT:    jmp .Ltmp10
-; CHECK-NEXT:    jmp .Ltmp20
-; CHECK-NEXT:    jmp .Ltmp30
+; CHECK-NEXT:    jmp .Ltmp1
+; CHECK-NEXT:    jmp .Ltmp2
+; CHECK-NEXT:    jmp .Ltmp3
 ; CHECK-NEXT:    #NO_APP
 ; CHECK-NEXT:  .LBB2_5: # %normal0
 ; CHECK-NEXT:    # in Loop: Header=BB2_4 Depth=4
 ; CHECK-NEXT:    #APP
-; CHECK-NEXT:    jmp .Ltmp10
-; CHECK-NEXT:    jmp .Ltmp20
-; CHECK-NEXT:    jmp .Ltmp30
-; CHECK-NEXT:    jmp .Ltmp40
+; CHECK-NEXT:    jmp .Ltmp1
+; CHECK-NEXT:    jmp .Ltmp2
+; CHECK-NEXT:    jmp .Ltmp3
+; CHECK-NEXT:    jmp .Ltmp4
 ; CHECK-NEXT:    #NO_APP
 ; CHECK-NEXT:  .LBB2_6: # %normal1
 ; CHECK-NEXT:    movl {{[0-9]+}}(%esp), %eax




More information about the llvm-branch-commits mailing list