[llvm-branch-commits] [llvm] 07808f6 - [llvm-mca] Fix duplicate symbols error

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 30 15:35:24 PDT 2023


Author: Michael Maitland
Date: 2023-05-30T15:34:23-07:00
New Revision: 07808f6947a9c3010846249f7cdc7c026e2cb78b

URL: https://github.com/llvm/llvm-project/commit/07808f6947a9c3010846249f7cdc7c026e2cb78b
DIFF: https://github.com/llvm/llvm-project/commit/07808f6947a9c3010846249f7cdc7c026e2cb78b.diff

LOG: [llvm-mca] Fix duplicate symbols error

Parsing instruments and analysis regions causes us to see the same
labels two times since we parse the same file twice under the same
context.

This change creates a seperate context for instrument parsing
and another for analysis region parsing. I will post a follow up
commit once I get some free cycles to parse analysis regions and
instruments in one parsing pass under a single context.

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

(cherry picked from commit 1c2b8129e99478a9b0222fc0aaf44a4a47e7ecd6)

Added: 
    llvm/test/tools/llvm-mca/X86/Generic/no-duplicate-symbols.s

Modified: 
    llvm/tools/llvm-mca/llvm-mca.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-mca/X86/Generic/no-duplicate-symbols.s b/llvm/test/tools/llvm-mca/X86/Generic/no-duplicate-symbols.s
new file mode 100644
index 0000000000000..8b8144c08b857
--- /dev/null
+++ b/llvm/test/tools/llvm-mca/X86/Generic/no-duplicate-symbols.s
@@ -0,0 +1,8 @@
+# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=x86-64 < %s 2>&1 | FileCheck %s
+
+# This test checks that https://github.com/llvm/llvm-project/issues/62528 is resolved.
+foo:
+  pushq   %rbp
+
+# CHECK-NOT:      <stdin>:4:1: error: symbol 'foo' is already defined
+

diff  --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index 73c341891ab7b..33adf15fccaf2 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -401,11 +401,6 @@ int main(int argc, char **argv) {
   // Tell SrcMgr about this buffer, which is what the parser will pick up.
   SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
 
-  MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
-  std::unique_ptr<MCObjectFileInfo> MOFI(
-      TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
-  Ctx.setObjectFileInfo(MOFI.get());
-
   std::unique_ptr<buffer_ostream> BOS;
 
   std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
@@ -433,7 +428,11 @@ int main(int argc, char **argv) {
   }
 
   // Parse the input and create CodeRegions that llvm-mca can analyze.
-  mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI,
+  MCContext ACtx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
+  std::unique_ptr<MCObjectFileInfo> AMOFI(
+      TheTarget->createMCObjectFileInfo(ACtx, /*PIC=*/false));
+  ACtx.setObjectFileInfo(AMOFI.get());
+  mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, ACtx, *MAI, *STI,
                                       *MCII);
   Expected<const mca::AnalysisRegions &> RegionsOrErr =
       CRG.parseAnalysisRegions(std::move(IPtemp));
@@ -471,7 +470,11 @@ int main(int argc, char **argv) {
 
   // Parse the input and create InstrumentRegion that llvm-mca
   // can use to improve analysis.
-  mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI,
+  MCContext ICtx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
+  std::unique_ptr<MCObjectFileInfo> IMOFI(
+      TheTarget->createMCObjectFileInfo(ICtx, /*PIC=*/false));
+  ICtx.setObjectFileInfo(IMOFI.get());
+  mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, ICtx, *MAI, *STI,
                                         *MCII, *IM);
   Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
       IRG.parseInstrumentRegions(std::move(IPtemp));
@@ -547,7 +550,7 @@ int main(int argc, char **argv) {
   unsigned RegionIdx = 0;
 
   std::unique_ptr<MCCodeEmitter> MCE(
-      TheTarget->createMCCodeEmitter(*MCII, Ctx));
+      TheTarget->createMCCodeEmitter(*MCII, ACtx));
   assert(MCE && "Unable to create code emitter!");
 
   std::unique_ptr<MCAsmBackend> MAB(TheTarget->createMCAsmBackend(


        


More information about the llvm-branch-commits mailing list