Index: include/llvm/MC/MCAsmInfo.h =================================================================== --- include/llvm/MC/MCAsmInfo.h +++ include/llvm/MC/MCAsmInfo.h @@ -29,6 +29,7 @@ class MCStreamer; class MCSubtargetInfo; class MCSymbol; +class Triple; namespace WinEH { @@ -647,6 +648,11 @@ bool canRelaxRelocations() const { return RelaxELFRelocations; } void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; } bool hasMipsExpressions() const { return HasMipsExpressions; } + + /// Adjusts 'PrivateGlobalPrefix' and 'PrivateLabelPrefix' based on Target + /// options and triple if necessary. + virtual void adjustPrefixes(const Triple &TT, const MCTargetOptions &Options, + StringRef CPU = "") {} }; } // end namespace llvm Index: lib/CodeGen/LLVMTargetMachine.cpp =================================================================== --- lib/CodeGen/LLVMTargetMachine.cpp +++ lib/CodeGen/LLVMTargetMachine.cpp @@ -70,6 +70,9 @@ if (Options.ExceptionModel != ExceptionHandling::None) TmpAsmInfo->setExceptionsType(Options.ExceptionModel); + TmpAsmInfo->adjustPrefixes(getTargetTriple(), Options.MCOptions, + getTargetCPU()); + AsmInfo.reset(TmpAsmInfo); } Index: lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h +++ lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h @@ -23,6 +23,8 @@ public: explicit MipsMCAsmInfo(const Triple &TheTriple); + void adjustPrefixes(const Triple &TT, const MCTargetOptions &Options, + StringRef CPU) override; }; } // namespace llvm Index: lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp +++ lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "MipsMCAsmInfo.h" +#include "MipsABIInfo.h" #include "llvm/ADT/Triple.h" using namespace llvm; @@ -23,10 +24,7 @@ if (TheTriple.isMIPS64() && TheTriple.getEnvironment() != Triple::GNUABIN32) CodePointerSize = CalleeSaveStackSlotSize = 8; - // FIXME: This condition isn't quite right but it's the best we can do until - // this object can identify the ABI. It will misbehave when using O32 - // on a mips64*-* triple. - if (TheTriple.isMIPS32()) { + if (TheTriple.isMIPS32() && TheTriple.getEnvironment() != Triple::GNUABIN32) { PrivateGlobalPrefix = "$"; PrivateLabelPrefix = "$"; } @@ -50,3 +48,15 @@ HasMipsExpressions = true; UseIntegratedAssembler = true; } + +void MipsMCAsmInfo::adjustPrefixes(const Triple &TT, + const MCTargetOptions &Options, + StringRef CPU) { + MipsABIInfo ABI = MipsABIInfo::computeTargetABI(TT, CPU, Options); + if (ABI.IsO32()) { + PrivateGlobalPrefix = "$"; + } else if (ABI.IsN32() || ABI.IsN64()) { + PrivateGlobalPrefix = ".L"; + } + PrivateLabelPrefix = PrivateGlobalPrefix; +} Index: test/CodeGen/Mips/compactbranches/no-beqzc-bnezc.ll =================================================================== --- test/CodeGen/Mips/compactbranches/no-beqzc-bnezc.ll +++ test/CodeGen/Mips/compactbranches/no-beqzc-bnezc.ll @@ -103,7 +103,7 @@ define i32 @f6(i32 %a) { ; CHECK-LABEL: f6: -; CHECK: beqzc ${{[0-9]+}}, $BB +; CHECK: beqzc ${{[0-9]+}}, {{((\$)|(\.L))}}BB %cmp = icmp eq i32 %a, 0 br i1 %cmp, label %if.then, label %if.end @@ -117,7 +117,7 @@ define i32 @f7(i32 %a) { ; CHECK-LABEL: f7: -; CHECK: bnezc ${{[0-9]+}}, $BB +; CHECK: bnezc ${{[0-9]+}}, {{((\$)|(\.L))}}BB %cmp = icmp eq i32 0, %a br i1 %cmp, label %if.then, label %if.end Index: test/MC/Mips/macro-li.d.s =================================================================== --- test/MC/Mips/macro-li.d.s +++ test/MC/Mips/macro-li.d.s @@ -18,7 +18,7 @@ li.d $4, 1.12345 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1072822694 # ALL: .4byte 3037400872 # ALL: .text @@ -58,7 +58,7 @@ li.d $4, 12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790602240 # ALL: .text @@ -90,7 +90,7 @@ li.d $4, 12345678910.0 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790602240 # ALL: .text @@ -122,7 +122,7 @@ li.d $4, 0.4 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1071225241 # ALL: .4byte 2576980378 # ALL: .text @@ -158,7 +158,7 @@ li.d $4, 12345678910.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790666967 # ALL: .text @@ -191,7 +191,7 @@ li.d $4, 12345678910123456789.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1139108501 # ALL: .4byte 836738583 # ALL: .text @@ -243,7 +243,7 @@ li.d $f4, 1.12345 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1072822694 # ALL: .4byte 3037400872 # ALL: .text @@ -286,7 +286,7 @@ li.d $f4, 12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790602240 # ALL: .text @@ -309,7 +309,7 @@ li.d $f4, 12345678910.0 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790602240 # ALL: .text @@ -332,7 +332,7 @@ li.d $f4, 0.4 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1071225241 # ALL: .4byte 2576980378 # ALL: .text @@ -375,7 +375,7 @@ li.d $f4, 2.515625 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1074012160 # ALL: .4byte 0 # ALL: .text @@ -398,7 +398,7 @@ li.d $f4, 12345678910.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1107754720 # ALL: .4byte 3790666967 # ALL: .text @@ -421,7 +421,7 @@ li.d $f4, 12345678910123456789.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1139108501 # ALL: .4byte 836738583 # ALL: .text Index: test/MC/Mips/macro-li.s.s =================================================================== --- test/MC/Mips/macro-li.s.s +++ test/MC/Mips/macro-li.s.s @@ -54,7 +54,7 @@ li.s $f4, 1.12345 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1066388790 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] @@ -84,7 +84,7 @@ li.s $f4, 12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1345844999 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] @@ -106,7 +106,7 @@ li.s $f4, 12345678910.0 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1345844999 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] @@ -129,7 +129,7 @@ li.s $f4, 0.4 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1053609165 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] @@ -155,7 +155,7 @@ li.s $f4, 12345678910.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1345844999 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] @@ -177,7 +177,7 @@ li.s $f4, 12345678910123456789.12345678910 # ALL: .section .rodata,"a",@progbits -# ALL: [[LABEL:\$tmp[0-9]+]]: +# ALL: [[LABEL:((\$)|(\.L))tmp[0-9]+]]: # ALL: .4byte 1596675242 # ALL: .text # O32-N32-PIC: lw $1, %got([[LABEL]])($gp) # encoding: [A,A,0x81,0x8f] Index: test/MC/Mips/private-prefix.s =================================================================== --- /dev/null +++ test/MC/Mips/private-prefix.s @@ -0,0 +1,22 @@ +# RUN: llvm-mc %s -triple=mips --target-abi=o32 | FileCheck %s --check-prefix=O32 +# RUN: llvm-mc %s -triple=mips --target-abi=n32 | FileCheck %s --check-prefix=N32 +# RUN: llvm-mc %s -triple=mips --target-abi=n64 | FileCheck %s --check-prefix=N64 +# RUN: llvm-mc %s -triple=mips64 --target-abi=o32 | FileCheck %s --check-prefix=O32 +# RUN: llvm-mc %s -triple=mips64 --target-abi=n32 | FileCheck %s --check-prefix=N32 +# RUN: llvm-mc %s -triple=mips64 --target-abi=n64 | FileCheck %s --check-prefix=N64 +# RUN: llvm-mc %s -triple=mips | FileCheck %s --check-prefix=O32 +# RUN: llvm-mc %s -triple=mips-gnu | FileCheck %s --check-prefix=O32 +# RUN: llvm-mc %s -triple=mips-gnuabin32 | FileCheck %s --check-prefix=N32 +# RUN: llvm-mc %s -triple=mips-gnuabi64 | FileCheck %s --check-prefix=O32 +# RUN: llvm-mc %s -triple=mips64 | FileCheck %s --check-prefix=N64 +# RUN: llvm-mc %s -triple=mips64-gnu | FileCheck %s --check-prefix=N64 +# RUN: llvm-mc %s -triple=mips64-gnuabin32 | FileCheck %s --check-prefix=N32 +# RUN: llvm-mc %s -triple=mips64-gnuabi64 | FileCheck %s --check-prefix=N64 + +# Checks if correct private global and label prefixes are used based on target +# options. + +# O32: $tmp0: +# N32: .Ltmp0: +# N64: .Ltmp0: +li.d $4, 1.12345 Index: tools/dsymutil/DwarfStreamer.cpp =================================================================== --- tools/dsymutil/DwarfStreamer.cpp +++ tools/dsymutil/DwarfStreamer.cpp @@ -61,9 +61,11 @@ if (!MRI) return error(Twine("no register info for target ") + TripleName, Context); + MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName)); if (!MAI) return error("no asm info for target " + TripleName, Context); + MAI->adjustPrefixes(TheTriple, MCOptions); MOFI.reset(new MCObjectFileInfo); MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get())); @@ -73,7 +75,6 @@ if (!MSTI) return error("no subtarget info for target " + TripleName, Context); - MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions); if (!MAB) return error("no asm backend for target " + TripleName, Context); Index: tools/llvm-dwp/llvm-dwp.cpp =================================================================== --- tools/llvm-dwp/llvm-dwp.cpp +++ tools/llvm-dwp/llvm-dwp.cpp @@ -676,6 +676,7 @@ if (!MRI) return error(Twine("no register info for target ") + TripleName, Context); + MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); if (!MAI) return error("no asm info for target " + TripleName, Context); @@ -694,6 +695,8 @@ if (!MAB) return error("no asm backend for target " + TripleName, Context); + MAI->adjustPrefixes(TheTriple, MCOptions); + std::unique_ptr MII(TheTarget->createMCInstrInfo()); if (!MII) return error("no instr info info for target " + TripleName, Context); @@ -716,7 +719,6 @@ OS = BOS.getPointer(); } - MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MS(TheTarget->createMCObjectStreamer( TheTriple, MC, std::unique_ptr(MAB), MAB->createObjectWriter(*OS), std::unique_ptr(MCE), *MSTI, Index: tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp =================================================================== --- tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp +++ tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp @@ -161,12 +161,13 @@ abort(); } + MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); if (!MAI) { errs() << "Unable to create target asm info!"; abort(); } - + MAI->adjustPrefixes(TheTriple, MCOptions, MCPU); MCObjectFileInfo MOFI; MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); @@ -193,8 +194,6 @@ std::unique_ptr CE = nullptr; std::unique_ptr MAB = nullptr; - MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); - std::string OutputString; raw_string_ostream Out(OutputString); auto FOut = std::make_unique(Out); Index: tools/llvm-mc/Disassembler.h =================================================================== --- tools/llvm-mc/Disassembler.h +++ tools/llvm-mc/Disassembler.h @@ -24,6 +24,7 @@ class SourceMgr; class MCSubtargetInfo; class MCStreamer; +class MCTargetOptions; class Disassembler { public: Index: tools/llvm-mc/llvm-mc.cpp =================================================================== --- tools/llvm-mc/llvm-mc.cpp +++ tools/llvm-mc/llvm-mc.cpp @@ -364,6 +364,7 @@ MAI->setCompressDebugSections(CompressDebugSections); } MAI->setPreserveAsmComments(PreserveComments); + MAI->adjustPrefixes(TheTriple, MCOptions, MCPU); // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. Index: tools/llvm-mca/llvm-mca.cpp =================================================================== --- tools/llvm-mca/llvm-mca.cpp +++ tools/llvm-mca/llvm-mca.cpp @@ -351,6 +351,9 @@ std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); assert(MAI && "Unable to create target asm info!"); + const MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); + MAI->adjustPrefixes(TheTriple, MCOptions, MCPU); + MCObjectFileInfo MOFI; SourceMgr SrcMgr; @@ -436,7 +439,7 @@ TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); std::unique_ptr MAB(TheTarget->createMCAsmBackend( - *STI, *MRI, InitMCTargetOptionsFromFlags())); + *STI, *MRI, MCOptions)); for (const std::unique_ptr &Region : Regions) { // Skip empty code regions. Index: unittests/DebugInfo/DWARF/DwarfGenerator.cpp =================================================================== --- unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -409,17 +409,18 @@ TripleName, inconvertibleErrorCode()); + MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName)); if (!MAI) return make_error("no asm info for target " + TripleName, inconvertibleErrorCode()); + MAI->adjustPrefixes(TheTriple, MCOptions); MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", "")); if (!MSTI) return make_error("no subtarget info for target " + TripleName, inconvertibleErrorCode()); - MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions); if (!MAB) return make_error("no asm backend for target " + TripleName, Index: unittests/ExecutionEngine/JITLink/JITLinkTestCommon.h =================================================================== --- unittests/ExecutionEngine/JITLink/JITLinkTestCommon.h +++ unittests/ExecutionEngine/JITLink/JITLinkTestCommon.h @@ -52,7 +52,7 @@ TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC, bool LargeCodeModel, MCTargetOptions Options, Error &Err); - Error initializeTripleSpecifics(Triple &TT); + Error initializeTripleSpecifics(Triple &TT, const MCTargetOptions &Options); void initializeTestSpecifics(StringRef AsmSource, const Triple &TT, bool PIC, bool LargeCodeModel); Index: unittests/ExecutionEngine/JITLink/JITLinkTestCommon.cpp =================================================================== --- unittests/ExecutionEngine/JITLink/JITLinkTestCommon.cpp +++ unittests/ExecutionEngine/JITLink/JITLinkTestCommon.cpp @@ -41,14 +41,15 @@ : ObjStream(ObjBuffer), Options(std::move(Options)) { ErrorAsOutParameter _(&Err); Triple TT(Triple::normalize(TripleStr)); - if (auto Err2 = initializeTripleSpecifics(TT)) { + if (auto Err2 = initializeTripleSpecifics(TT, Options)) { Err = std::move(Err2); return; } initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel); } -Error JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) { +Error JITLinkTestCommon::TestResources::initializeTripleSpecifics( + Triple &TT, const MCTargetOptions &Options) { std::string ErrorMsg; TheTarget = TargetRegistry::lookupTarget("", TT, ErrorMsg); @@ -62,6 +63,7 @@ MAI.reset(TheTarget->createMCAsmInfo(*MRI, TT.getTriple())); if (!MAI) report_fatal_error("Could not build MCAsmInfo for triple"); + MAI->adjustPrefixes(TT, Options); MCII.reset(TheTarget->createMCInstrInfo()); if (!MCII)