Skip to content

Commit 1c2b812

Browse files
[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
1 parent 2dc0fa0 commit 1c2b812

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=x86-64 < %s 2>&1 | FileCheck %s
2+
3+
# This test checks that https://github.com/llvm/llvm-project/issues/62528 is resolved.
4+
foo:
5+
pushq %rbp
6+
7+
# CHECK-NOT: <stdin>:4:1: error: symbol 'foo' is already defined
8+

llvm/tools/llvm-mca/llvm-mca.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,6 @@ int main(int argc, char **argv) {
401401
// Tell SrcMgr about this buffer, which is what the parser will pick up.
402402
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
403403

404-
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
405-
std::unique_ptr<MCObjectFileInfo> MOFI(
406-
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
407-
Ctx.setObjectFileInfo(MOFI.get());
408-
409404
std::unique_ptr<buffer_ostream> BOS;
410405

411406
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
@@ -433,7 +428,11 @@ int main(int argc, char **argv) {
433428
}
434429

435430
// Parse the input and create CodeRegions that llvm-mca can analyze.
436-
mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI,
431+
MCContext ACtx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
432+
std::unique_ptr<MCObjectFileInfo> AMOFI(
433+
TheTarget->createMCObjectFileInfo(ACtx, /*PIC=*/false));
434+
ACtx.setObjectFileInfo(AMOFI.get());
435+
mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, ACtx, *MAI, *STI,
437436
*MCII);
438437
Expected<const mca::AnalysisRegions &> RegionsOrErr =
439438
CRG.parseAnalysisRegions(std::move(IPtemp));
@@ -471,7 +470,11 @@ int main(int argc, char **argv) {
471470

472471
// Parse the input and create InstrumentRegion that llvm-mca
473472
// can use to improve analysis.
474-
mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI,
473+
MCContext ICtx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
474+
std::unique_ptr<MCObjectFileInfo> IMOFI(
475+
TheTarget->createMCObjectFileInfo(ICtx, /*PIC=*/false));
476+
ICtx.setObjectFileInfo(IMOFI.get());
477+
mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, ICtx, *MAI, *STI,
475478
*MCII, *IM);
476479
Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
477480
IRG.parseInstrumentRegions(std::move(IPtemp));
@@ -547,7 +550,7 @@ int main(int argc, char **argv) {
547550
unsigned RegionIdx = 0;
548551

549552
std::unique_ptr<MCCodeEmitter> MCE(
550-
TheTarget->createMCCodeEmitter(*MCII, Ctx));
553+
TheTarget->createMCCodeEmitter(*MCII, ACtx));
551554
assert(MCE && "Unable to create code emitter!");
552555

553556
std::unique_ptr<MCAsmBackend> MAB(TheTarget->createMCAsmBackend(

0 commit comments

Comments
 (0)