diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -588,8 +588,9 @@ } llvm::SourceMgr TempSrcMgr; - llvm::MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &TempSrcMgr); - MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, Ctx); + llvm::MCContext Ctx(TheTriple, MAI.get(), MRI.get(), MOFI.get(), STI.get(), + &TempSrcMgr); + MOFI->initMCObjectFileInfo(Ctx, /*PIC=*/false); std::unique_ptr Buffer = llvm::MemoryBuffer::getMemBuffer(AsmString, ""); diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -387,7 +387,15 @@ // MCObjectFileInfo needs a MCContext reference in order to initialize itself. std::unique_ptr MOFI(new MCObjectFileInfo()); - MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr, &MCOptions); + // Build up the feature string from the target feature list. + std::string FS = llvm::join(Opts.Features, ","); + + std::unique_ptr STI( + TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); + assert(STI && "Unable to create subtarget info!"); + + MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), MOFI.get(), + STI.get(), &SrcMgr, &MCOptions); bool PIC = false; if (Opts.RelocationModel == "static") { @@ -400,7 +408,7 @@ PIC = false; } - MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx); + MOFI->initMCObjectFileInfo(Ctx, PIC); if (Opts.SaveTemporaryLabels) Ctx.setAllowTemporaryLabels(false); if (Opts.GenDwarfForAssembly) @@ -428,18 +436,11 @@ Ctx.setGenDwarfRootFile(Opts.InputFile, SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer()); - // Build up the feature string from the target feature list. - std::string FS = llvm::join(Opts.Features, ","); - std::unique_ptr Str; std::unique_ptr MCII(TheTarget->createMCInstrInfo()); assert(MCII && "Unable to create instruction info!"); - std::unique_ptr STI( - TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); - assert(STI && "Unable to create subtarget info!"); - raw_pwrite_stream *Out = FDOS.get(); std::unique_ptr BOS; @@ -493,8 +494,7 @@ // When -fembed-bitcode is passed to clang_as, a 1-byte marker // is emitted in __LLVM,__asm section if the object file is MachO format. - if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() == - MCObjectFileInfo::IsMachO) { + if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) { MCSection *AsmLabel = Ctx.getMachOSection( "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); Str.get()->SwitchSection(AsmLabel); diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp --- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -904,8 +904,9 @@ if (!asm_info_up) return Instance(); - std::unique_ptr context_up( - new llvm::MCContext(asm_info_up.get(), reg_info_up.get(), nullptr)); + std::unique_ptr context_up(new llvm::MCContext( + llvm::Triple(triple), asm_info_up.get(), reg_info_up.get(), + /*MOFI=*/nullptr, subtarget_info_up.get())); if (!context_up) return Instance(); diff --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp --- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp +++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp @@ -159,8 +159,9 @@ target->createMCSubtargetInfo(triple.getTriple(), cpu, features)); assert(m_asm_info.get() && m_subtype_info.get()); - m_context = std::make_unique(m_asm_info.get(), - m_reg_info.get(), nullptr); + m_context = std::make_unique( + triple, m_asm_info.get(), m_reg_info.get(), /*MOFI=*/nullptr, + m_subtype_info.get()); assert(m_context.get()); m_disasm.reset(target->createMCDisassembler(*m_subtype_info, *m_context)); diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp @@ -163,8 +163,9 @@ target->createMCSubtargetInfo(triple.getTriple(), cpu, features)); assert(m_asm_info.get() && m_subtype_info.get()); - m_context = std::make_unique(m_asm_info.get(), - m_reg_info.get(), nullptr); + m_context = std::make_unique( + triple, m_asm_info.get(), m_reg_info.get(), /*MOFI=*/nullptr, + m_subtype_info.get()); assert(m_context.get()); m_disasm.reset(target->createMCDisassembler(*m_subtype_info, *m_context)); diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -74,8 +74,14 @@ using DiagHandlerTy = std::function &)>; + enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF }; private: + Environment Env; + + /// The triple for this object. + Triple TT; + /// The SourceMgr for this object, if any. const SourceMgr *SrcMgr; @@ -94,6 +100,9 @@ /// The MCObjectFileInfo for this target. const MCObjectFileInfo *MOFI; + /// The MCSubtargetInfo for this target. + const MCSubtargetInfo *MSTI; + std::unique_ptr CVContext; /// Allocator object used for creating machine code objects. @@ -383,8 +392,9 @@ DenseSet ELFSeenGenericMergeableSections; public: - explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, - const MCObjectFileInfo *MOFI, + explicit MCContext(const Triple &TheTriple, const MCAsmInfo *MAI, + const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, + const MCSubtargetInfo *MSTI, const SourceMgr *Mgr = nullptr, MCTargetOptions const *TargetOpts = nullptr, bool DoAutoReset = true); @@ -392,6 +402,9 @@ MCContext &operator=(const MCContext &) = delete; ~MCContext(); + Environment getObjectFileType() const { return Env; } + + const Triple &getTargetTriple() const { return TT; } const SourceMgr *getSourceManager() const { return SrcMgr; } void initInlineSourceManager(); @@ -409,6 +422,8 @@ const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; } + const MCSubtargetInfo *getSubtargetInfo() const { return MSTI; } + CodeViewContext &getCVContext(); void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; } diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -227,7 +227,7 @@ MCSection *TOCBaseSection = nullptr; public: - void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx, + void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel = false); MCContext &getContext() const { return *Ctx; } @@ -416,16 +416,11 @@ MCSection *getEHFrameSection() const { return EHFrameSection; } - enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF }; - Environment getObjectFileType() const { return Env; } - bool isPositionIndependent() const { return PositionIndependent; } private: - Environment Env; bool PositionIndependent = false; MCContext *Ctx = nullptr; - Triple TT; VersionTuple SDKVersion; void initMachOMCObjectFileInfo(const Triple &T); @@ -436,8 +431,6 @@ MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const; public: - const Triple &getTargetTriple() const { return TT; } - void setSDKVersion(const VersionTuple &TheSDKVersion) { SDKVersion = TheSDKVersion; } diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -217,8 +217,9 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI) : TM(std::move(MMI.TM)), - Context(MMI.TM.getMCAsmInfo(), MMI.TM.getMCRegisterInfo(), - MMI.TM.getObjFileLowering(), nullptr, nullptr, false), + Context(MMI.TM.getTargetTriple(), MMI.TM.getMCAsmInfo(), + MMI.TM.getMCRegisterInfo(), MMI.TM.getObjFileLowering(), + MMI.TM.getMCSubtargetInfo(), nullptr, nullptr, false), MachineFunctions(std::move(MMI.MachineFunctions)) { ObjFileMMI = MMI.ObjFileMMI; CurCallSite = MMI.CurCallSite; @@ -232,15 +233,17 @@ } MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM) - : TM(*TM), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), - TM->getObjFileLowering(), nullptr, nullptr, false) { + : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), + TM->getMCRegisterInfo(), TM->getObjFileLowering(), + TM->getMCSubtargetInfo(), nullptr, nullptr, false) { initialize(); } MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM, MCContext *ExtContext) - : TM(*TM), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), - TM->getObjFileLowering(), nullptr, nullptr, false), + : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), + TM->getMCRegisterInfo(), TM->getObjFileLowering(), + TM->getMCSubtargetInfo(), nullptr, nullptr, false), ExternalContext(ExtContext) { initialize(); } diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1645,7 +1645,7 @@ // Append "$symbol" to the section name *before* IR-level mangling is // applied when targetting mingw. This is what GCC does, and the ld.bfd // COFF linker will not properly handle comdats otherwise. - if (getTargetTriple().isWindowsGNUEnvironment()) + if (getContext().getTargetTriple().isWindowsGNUEnvironment()) raw_svector_ostream(Name) << '$' << ComdatGV->getName(); return getContext().getCOFFSection(Name, Characteristics, Kind, @@ -1762,7 +1762,8 @@ std::string Flags; for (const GlobalValue &GV : M.global_values()) { raw_string_ostream OS(Flags); - emitLinkerFlagsForGlobalCOFF(OS, &GV, getTargetTriple(), getMangler()); + emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(), + getMangler()); OS.flush(); if (!Flags.empty()) { Streamer.SwitchSection(getDrectveSection()); @@ -1786,7 +1787,8 @@ continue; raw_string_ostream OS(Flags); - emitLinkerFlagsForUsedCOFF(OS, GV, getTargetTriple(), getMangler()); + emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(), + getMangler()); OS.flush(); if (!Flags.empty()) { @@ -1865,16 +1867,16 @@ MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection( unsigned Priority, const MCSymbol *KeySym) const { - return getCOFFStaticStructorSection(getContext(), getTargetTriple(), true, - Priority, KeySym, - cast(StaticCtorSection)); + return getCOFFStaticStructorSection( + getContext(), getContext().getTargetTriple(), true, Priority, KeySym, + cast(StaticCtorSection)); } MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection( unsigned Priority, const MCSymbol *KeySym) const { - return getCOFFStaticStructorSection(getContext(), getTargetTriple(), false, - Priority, KeySym, - cast(StaticDtorSection)); + return getCOFFStaticStructorSection( + getContext(), getContext().getTargetTriple(), false, Priority, KeySym, + cast(StaticDtorSection)); } const MCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference( diff --git a/llvm/lib/DWARFLinker/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/DWARFStreamer.cpp --- a/llvm/lib/DWARFLinker/DWARFStreamer.cpp +++ b/llvm/lib/DWARFLinker/DWARFStreamer.cpp @@ -50,14 +50,15 @@ if (!MAI) return error("no asm info for target " + TripleName, Context), false; - MOFI.reset(new MCObjectFileInfo); - MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get())); - MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC); - MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", "")); if (!MSTI) return error("no subtarget info for target " + TripleName, Context), false; + MOFI.reset(new MCObjectFileInfo); + MC.reset( + new MCContext(TheTriple, MAI.get(), MRI.get(), MOFI.get(), MSTI.get())); + MOFI->initMCObjectFileInfo(*MC, /*PIC=*/false); + MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions); if (!MAB) return error("no asm backend for target " + TripleName, Context), false; @@ -212,7 +213,7 @@ Asm.emitInt32(11 + Die.getSize() - 4); Asm.emitInt16(2); Asm.emitInt32(0); - Asm.emitInt8(MOFI->getTargetTriple().isArch64Bit() ? 8 : 4); + Asm.emitInt8(MC->getTargetTriple().isArch64Bit() ? 8 : 4); DebugInfoSectionSize += 11; emitDIE(Die); } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -484,9 +484,8 @@ if (MCTargetStreamer *TS = getTargetStreamer()) { TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS); } else { - Section->PrintSwitchToSection( - *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS, - Subsection); + Section->PrintSwitchToSection(*MAI, getContext().getTargetTriple(), OS, + Subsection); } } diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -62,11 +62,13 @@ SMD.print(nullptr, errs()); } -MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, - const MCObjectFileInfo *mofi, const SourceMgr *mgr, +MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, + const MCRegisterInfo *mri, const MCObjectFileInfo *mofi, + const MCSubtargetInfo *msti, const SourceMgr *mgr, MCTargetOptions const *TargetOpts, bool DoAutoReset) - : SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler), - MAI(mai), MRI(mri), MOFI(mofi), Symbols(Allocator), UsedNames(Allocator), + : TT(TheTriple), SrcMgr(mgr), InlineSrcMgr(nullptr), + DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MOFI(mofi), + MSTI(msti), Symbols(Allocator), UsedNames(Allocator), InlineAsmUsedLabelNames(Allocator), CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), AutoReset(DoAutoReset), TargetOptions(TargetOpts) { @@ -75,6 +77,34 @@ if (SrcMgr && SrcMgr->getNumBuffers()) MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID()) ->getBufferIdentifier()); + + switch (TheTriple.getObjectFormat()) { + case Triple::MachO: + Env = IsMachO; + break; + case Triple::COFF: + if (!TheTriple.isOSWindows()) + report_fatal_error( + "Cannot initialize MC for non-Windows COFF object files."); + + Env = IsCOFF; + break; + case Triple::ELF: + Env = IsELF; + break; + case Triple::Wasm: + Env = IsWasm; + break; + case Triple::XCOFF: + Env = IsXCOFF; + break; + case Triple::GOFF: + report_fatal_error("Cannot initialize MC for GOFF object file format"); + break; + case Triple::UnknownObjectFormat: + report_fatal_error("Cannot initialize MC for unknown object file format."); + break; + } } MCContext::~MCContext() { @@ -195,19 +225,18 @@ "MCSymbol classes must be trivially destructible"); static_assert(std::is_trivially_destructible(), "MCSymbol classes must be trivially destructible"); - if (MOFI) { - switch (MOFI->getObjectFileType()) { - case MCObjectFileInfo::IsCOFF: - return new (Name, *this) MCSymbolCOFF(Name, IsTemporary); - case MCObjectFileInfo::IsELF: - return new (Name, *this) MCSymbolELF(Name, IsTemporary); - case MCObjectFileInfo::IsMachO: - return new (Name, *this) MCSymbolMachO(Name, IsTemporary); - case MCObjectFileInfo::IsWasm: - return new (Name, *this) MCSymbolWasm(Name, IsTemporary); - case MCObjectFileInfo::IsXCOFF: - return createXCOFFSymbolImpl(Name, IsTemporary); - } + + switch (getObjectFileType()) { + case MCContext::IsCOFF: + return new (Name, *this) MCSymbolCOFF(Name, IsTemporary); + case MCContext::IsELF: + return new (Name, *this) MCSymbolELF(Name, IsTemporary); + case MCContext::IsMachO: + return new (Name, *this) MCSymbolMachO(Name, IsTemporary); + case MCContext::IsWasm: + return new (Name, *this) MCSymbolWasm(Name, IsTemporary); + case MCContext::IsXCOFF: + return createXCOFFSymbolImpl(Name, IsTemporary); } return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp --- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp +++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp @@ -74,7 +74,8 @@ return nullptr; // Set up the MCContext for creating symbols and MCExpr's. - std::unique_ptr Ctx(new MCContext(MAI.get(), MRI.get(), nullptr)); + std::unique_ptr Ctx(new MCContext(Triple(TT), MAI.get(), MRI.get(), + /*MOFI=*/nullptr, STI.get())); if (!Ctx) return nullptr; diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -515,7 +515,7 @@ MCMachOStreamer *S = new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE), DWARFMustBeAtTheEnd, LabelSections); - const Triple &Target = Context.getObjectFileInfo()->getTargetTriple(); + const Triple &Target = Context.getTargetTriple(); S->emitVersionForTarget(Target, Context.getObjectFileInfo()->getSDKVersion()); if (RelaxAll) S->getAssembler().setRelaxAll(true); diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -959,11 +959,10 @@ /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC); } -void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, - MCContext &ctx, +void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel) { PositionIndependent = PIC; - Ctx = &ctx; + Ctx = &MCCtx; // Common. CommDirectiveSupportsAlignment = true; @@ -982,45 +981,29 @@ DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. DwarfAccelTypesSection = nullptr; // Used only by selected targets. - TT = TheTriple; - - switch (TT.getObjectFormat()) { - case Triple::MachO: - Env = IsMachO; - initMachOMCObjectFileInfo(TT); + Triple TheTriple = Ctx->getTargetTriple(); + switch (Ctx->getObjectFileType()) { + case MCContext::IsMachO: + initMachOMCObjectFileInfo(TheTriple); break; - case Triple::COFF: - if (!TT.isOSWindows()) - report_fatal_error( - "Cannot initialize MC for non-Windows COFF object files."); - - Env = IsCOFF; - initCOFFMCObjectFileInfo(TT); + case MCContext::IsCOFF: + initCOFFMCObjectFileInfo(TheTriple); break; - case Triple::ELF: - Env = IsELF; - initELFMCObjectFileInfo(TT, LargeCodeModel); + case MCContext::IsELF: + initELFMCObjectFileInfo(TheTriple, LargeCodeModel); break; - case Triple::Wasm: - Env = IsWasm; - initWasmMCObjectFileInfo(TT); + case MCContext::IsWasm: + initWasmMCObjectFileInfo(TheTriple); break; - case Triple::GOFF: - report_fatal_error("Cannot initialize MC for GOFF object file format"); - break; - case Triple::XCOFF: - Env = IsXCOFF; - initXCOFFMCObjectFileInfo(TT); - break; - case Triple::UnknownObjectFormat: - report_fatal_error("Cannot initialize MC for unknown object file format."); + case MCContext::IsXCOFF: + initXCOFFMCObjectFileInfo(TheTriple); break; } } MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, uint64_t Hash) const { - switch (TT.getObjectFormat()) { + switch (Ctx->getTargetTriple().getObjectFormat()) { case Triple::ELF: return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, utostr(Hash), /*IsComdat=*/true); @@ -1041,7 +1024,7 @@ MCSection * MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { - if (Env != IsELF) + if (Ctx->getObjectFileType() != MCContext::IsELF) return StackSizesSection; const MCSectionELF &ElfSec = static_cast(TextSec); @@ -1059,7 +1042,7 @@ MCSection * MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { - if (Env != IsELF) + if (Ctx->getObjectFileType() != MCContext::IsELF) return nullptr; const MCSectionELF &ElfSec = static_cast(TextSec); @@ -1079,7 +1062,7 @@ MCSection * MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const { - if (Env == IsELF) { + if (Ctx->getObjectFileType() == MCContext::IsELF) { const auto *ElfSec = static_cast(TextSec); // Create a separate section for probes that comes with a comdat function. if (const MCSymbol *Group = ElfSec->getGroup()) { @@ -1095,7 +1078,7 @@ MCSection * MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { - if (Env == IsELF) { + if (Ctx->getObjectFileType() == MCContext::IsELF) { // Create a separate comdat group for each function's descriptor in order // for the linker to deduplicate. The duplication, must be from different // tranlation unit, can come from: @@ -1105,7 +1088,7 @@ // Use a concatenation of the section name and the function name as the // group name so that descriptor-only groups won't be folded with groups of // code. - if (TT.supportsCOMDAT() && !FuncName.empty()) { + if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { auto *S = static_cast(PseudoProbeDescSection); auto Flags = S->getFlags() | ELF::SHF_GROUP; return Ctx->getELFSection(S->getName(), S->getType(), Flags, diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -729,21 +729,21 @@ Out.setStartTokLocPtr(&StartTokLoc); // Initialize the platform / file format parser. - switch (Ctx.getObjectFileInfo()->getObjectFileType()) { - case MCObjectFileInfo::IsCOFF: + switch (Ctx.getObjectFileType()) { + case MCContext::IsCOFF: PlatformParser.reset(createCOFFAsmParser()); break; - case MCObjectFileInfo::IsMachO: + case MCContext::IsMachO: PlatformParser.reset(createDarwinAsmParser()); IsDarwin = true; break; - case MCObjectFileInfo::IsELF: + case MCContext::IsELF: PlatformParser.reset(createELFAsmParser()); break; - case MCObjectFileInfo::IsWasm: + case MCContext::IsWasm: PlatformParser.reset(createWasmAsmParser()); break; - case MCObjectFileInfo::IsXCOFF: + case MCContext::IsXCOFF: report_fatal_error( "Need to implement createXCOFFAsmParser for XCOFF format."); break; diff --git a/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/llvm/lib/MC/MCParser/COFFAsmParser.cpp --- a/llvm/lib/MC/MCParser/COFFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/COFFAsmParser.cpp @@ -403,7 +403,7 @@ SectionKind Kind = computeSectionKind(Flags); if (Kind.isText()) { - const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); + const Triple &T = getContext().getTargetTriple(); if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) Flags |= COFF::IMAGE_SCN_MEM_16BIT; } diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp --- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp @@ -695,7 +695,7 @@ return Error(Loc, toString(std::move(E))); // Issue a warning if the target is not powerpc and Section is a *coal* section. - Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple(); + Triple TT = getParser().getContext().getTargetTriple(); Triple::ArchType ArchTy = TT.getArch(); if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) { @@ -1091,7 +1091,7 @@ void DarwinAsmParser::checkVersion(StringRef Directive, StringRef Arg, SMLoc Loc, Triple::OSType ExpectedOS) { - const Triple &Target = getContext().getObjectFileInfo()->getTargetTriple(); + const Triple &Target = getContext().getTargetTriple(); if (Target.getOS() != ExpectedOS) Warning(Loc, Twine(Directive) + (Arg.empty() ? Twine() : Twine(' ') + Arg) + diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -1029,8 +1029,8 @@ EndStatementAtEOFStack.push_back(true); // Initialize the platform / file format parser. - switch (Ctx.getObjectFileInfo()->getObjectFileType()) { - case MCObjectFileInfo::IsCOFF: + switch (Ctx.getObjectFileType()) { + case MCContext::IsCOFF: PlatformParser.reset(createCOFFMasmParser()); break; default: diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -57,10 +57,9 @@ MCSection *Section, const MCExpr *Subsection, raw_ostream &OS) { - Section->PrintSwitchToSection( - *Streamer.getContext().getAsmInfo(), - Streamer.getContext().getObjectFileInfo()->getTargetTriple(), OS, - Subsection); + Section->PrintSwitchToSection(*Streamer.getContext().getAsmInfo(), + Streamer.getContext().getTargetTriple(), OS, + Subsection); } void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) { diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp --- a/llvm/lib/MC/MCWinCOFFStreamer.cpp +++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp @@ -181,8 +181,7 @@ void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { // SafeSEH is a feature specific to 32-bit x86. It does not exist (and is // unnecessary) on all platforms which use table-based exception dispatch. - if (getContext().getObjectFileInfo()->getTargetTriple().getArch() != - Triple::x86) + if (getContext().getTargetTriple().getArch() != Triple::x86) return; const MCSymbolCOFF *CSymbol = cast(Symbol); @@ -266,7 +265,7 @@ unsigned ByteAlignment) { auto *Symbol = cast(S); - const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); + const Triple &T = getContext().getTargetTriple(); if (T.isWindowsMSVCEnvironment()) { if (ByteAlignment > 32) report_fatal_error("alignment is limited to 32-bytes"); diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp --- a/llvm/lib/Object/ModuleSymbolTable.cpp +++ b/llvm/lib/Object/ModuleSymbolTable.cpp @@ -100,8 +100,8 @@ return; MCObjectFileInfo MOFI; - MCContext MCCtx(MAI.get(), MRI.get(), &MOFI); - MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, MCCtx); + MCContext MCCtx(TT, MAI.get(), MRI.get(), &MOFI, STI.get()); + MOFI.initMCObjectFileInfo(MCCtx, /*PIC=*/false); MOFI.setSDKVersion(M.getSDKVersion()); RecordStreamer Streamer(MCCtx, M); T->createNullTargetStreamer(Streamer); diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -5267,10 +5267,9 @@ /// ParseDirective parses the arm specific directives bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { - const MCObjectFileInfo::Environment Format = - getContext().getObjectFileInfo()->getObjectFileType(); - bool IsMachO = Format == MCObjectFileInfo::IsMachO; - bool IsCOFF = Format == MCObjectFileInfo::IsCOFF; + const MCContext::Environment Format = getContext().getObjectFileType(); + bool IsMachO = Format == MCContext::IsMachO; + bool IsCOFF = Format == MCContext::IsCOFF; auto IDVal = DirectiveID.getIdentifier().lower(); SMLoc Loc = DirectiveID.getLoc(); diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -32,7 +32,6 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstrDesc.h" #include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCAsmParserExtension.h" @@ -6331,10 +6330,10 @@ } enum { - COFF = (1 << MCObjectFileInfo::IsCOFF), - ELF = (1 << MCObjectFileInfo::IsELF), - MACHO = (1 << MCObjectFileInfo::IsMachO), - WASM = (1 << MCObjectFileInfo::IsWasm), + COFF = (1 << MCContext::IsCOFF), + ELF = (1 << MCContext::IsELF), + MACHO = (1 << MCContext::IsMachO), + WASM = (1 << MCContext::IsWasm), }; static const struct PrefixEntry { const char *Spelling; @@ -6357,20 +6356,20 @@ } uint8_t CurrentFormat; - switch (getContext().getObjectFileInfo()->getObjectFileType()) { - case MCObjectFileInfo::IsMachO: + switch (getContext().getObjectFileType()) { + case MCContext::IsMachO: CurrentFormat = MACHO; break; - case MCObjectFileInfo::IsELF: + case MCContext::IsELF: CurrentFormat = ELF; break; - case MCObjectFileInfo::IsCOFF: + case MCContext::IsCOFF: CurrentFormat = COFF; break; - case MCObjectFileInfo::IsWasm: + case MCContext::IsWasm: CurrentFormat = WASM; break; - case MCObjectFileInfo::IsXCOFF: + case MCContext::IsXCOFF: llvm_unreachable("unexpected object format"); break; } @@ -11002,10 +11001,9 @@ /// parseDirective parses the arm specific directives bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { - const MCObjectFileInfo::Environment Format = - getContext().getObjectFileInfo()->getObjectFileType(); - bool IsMachO = Format == MCObjectFileInfo::IsMachO; - bool IsCOFF = Format == MCObjectFileInfo::IsCOFF; + const MCContext::Environment Format = getContext().getObjectFileType(); + bool IsMachO = Format == MCContext::IsMachO; + bool IsCOFF = Format == MCContext::IsCOFF; std::string IDVal = DirectiveID.getIdentifier().lower(); if (IDVal == ".word") @@ -11143,8 +11141,8 @@ /// ::= .thumbfunc symbol_name bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { MCAsmParser &Parser = getParser(); - const auto Format = getContext().getObjectFileInfo()->getObjectFileType(); - bool IsMachO = Format == MCObjectFileInfo::IsMachO; + const auto Format = getContext().getObjectFileType(); + bool IsMachO = Format == MCContext::IsMachO; // Darwin asm has (optionally) function name after .thumb_func direction // ELF doesn't diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp @@ -94,7 +94,8 @@ outputDwarfFileDirectives(); OS << "\t.section"; Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(), - FI->getTargetTriple(), OS, SubSection); + getStreamer().getContext().getTargetTriple(), + OS, SubSection); // DWARF sections are enclosed into braces - emit the open one. OS << "\t{\n"; HasSections = true; diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -44,7 +44,7 @@ // `Initialize` can be called more than once. delete Mang; Mang = new Mangler(); - InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), ctx, + initMCObjectFileInfo(ctx, TM.isPositionIndependent(), TM.getCodeModel() == CodeModel::Large); // Reset various EH DWARF encodings. diff --git a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp --- a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp +++ b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp @@ -407,7 +407,8 @@ if (!MII) return make_error("Failed to initialise MII."); - Context.reset(new MCContext(AsmInfo.get(), RegisterInfo.get(), &MOFI)); + Context.reset(new MCContext(Triple(TripleName), AsmInfo.get(), + RegisterInfo.get(), &MOFI, SubtargetInfo.get())); Disassembler.reset( ObjectTarget->createMCDisassembler(*SubtargetInfo, *Context)); diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -875,15 +875,15 @@ if (!MAI) return error("no asm info for target " + TripleName, Context); - MCObjectFileInfo MOFI; - MCContext MC(MAI.get(), MRI.get(), &MOFI); - MOFI.InitMCObjectFileInfo(*ErrOrTriple, /*PIC*/ false, MC); - std::unique_ptr MSTI( TheTarget->createMCSubtargetInfo(TripleName, "", "")); if (!MSTI) return error("no subtarget info for target " + TripleName, Context); + MCObjectFileInfo MOFI; + MCContext MC(*ErrOrTriple, MAI.get(), MRI.get(), &MOFI, MSTI.get()); + MOFI.initMCObjectFileInfo(MC, /*PIC=*/false); + MCTargetOptions Options; auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options); if (!MAB) diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -176,8 +176,9 @@ Triple(FirstPoint.LLVMTriple), 0 /*default variant*/, *AsmInfo_, *InstrInfo_, *RegInfo_)); - Context_ = std::make_unique(AsmInfo_.get(), RegInfo_.get(), - &ObjectFileInfo_); + Context_ = std::make_unique( + Triple(FirstPoint.LLVMTriple), AsmInfo_.get(), RegInfo_.get(), + &ObjectFileInfo_, SubtargetInfo_.get()); Disasm_.reset(Target.createMCDisassembler(*SubtargetInfo_, *Context_)); assert(Disasm_ && "cannot create MCDisassembler. missing call to " "InitializeXXXTargetDisassembler ?"); diff --git a/llvm/tools/llvm-exegesis/lib/LlvmState.cpp b/llvm/tools/llvm-exegesis/lib/LlvmState.cpp --- a/llvm/tools/llvm-exegesis/lib/LlvmState.cpp +++ b/llvm/tools/llvm-exegesis/lib/LlvmState.cpp @@ -62,8 +62,10 @@ bool LLVMState::canAssemble(const MCInst &Inst) const { MCObjectFileInfo ObjectFileInfo; - MCContext Context(TheTargetMachine->getMCAsmInfo(), - TheTargetMachine->getMCRegisterInfo(), &ObjectFileInfo); + MCContext Context(TheTargetMachine->getTargetTriple(), + TheTargetMachine->getMCAsmInfo(), + TheTargetMachine->getMCRegisterInfo(), &ObjectFileInfo, + TheTargetMachine->getMCSubtargetInfo()); std::unique_ptr CodeEmitter( TheTargetMachine->getTarget().createMCCodeEmitter( *TheTargetMachine->getMCInstrInfo(), *TheTargetMachine->getMCRegisterInfo(), diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -132,10 +132,11 @@ MCObjectFileInfo ObjectFileInfo; const TargetMachine &TM = State.getTargetMachine(); - MCContext Context(TM.getMCAsmInfo(), TM.getMCRegisterInfo(), &ObjectFileInfo); + MCContext Context(TM.getTargetTriple(), TM.getMCAsmInfo(), + TM.getMCRegisterInfo(), &ObjectFileInfo, + TM.getMCSubtargetInfo()); Context.initInlineSourceManager(); - ObjectFileInfo.InitMCObjectFileInfo(TM.getTargetTriple(), /*PIC*/ false, - Context); + ObjectFileInfo.initMCObjectFileInfo(Context, /*PIC=*/false); BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result); std::string Error; diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -1256,7 +1256,8 @@ TripleName, inconvertibleErrorCode())); - MCContext Ctx(MAI.get(), MRI.get(), nullptr); + MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get()); std::unique_ptr Disassembler( TheTarget->createMCDisassembler(*STI, Ctx)); diff --git a/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp b/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp --- a/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp +++ b/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp @@ -170,12 +170,13 @@ abort(); } + std::unique_ptr STI( + TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); MCObjectFileInfo MOFI; - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); - + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); static const bool UsePIC = false; - MOFI.InitMCObjectFileInfo(TheTriple, UsePIC, Ctx); + MOFI.initMCObjectFileInfo(Ctx, UsePIC); const unsigned OutputAsmVariant = 0; std::unique_ptr MCII(TheTarget->createMCInstrInfo()); @@ -191,8 +192,6 @@ } const char *ProgName = "llvm-mc-fuzzer"; - std::unique_ptr STI( - TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); std::unique_ptr CE = nullptr; std::unique_ptr MAB = nullptr; diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -379,11 +379,25 @@ } MAI->setPreserveAsmComments(PreserveComments); + // Package up features to be passed to target/subtarget + std::string FeaturesStr; + if (MAttrs.size()) { + SubtargetFeatures Features; + for (unsigned i = 0; i != MAttrs.size(); ++i) + Features.AddFeature(MAttrs[i]); + FeaturesStr = Features.getString(); + } + + std::unique_ptr STI( + TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); + assert(STI && "Unable to create subtarget info!"); + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. MCObjectFileInfo MOFI; - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions); - MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr, + &MCOptions); + MOFI.initMCObjectFileInfo(Ctx, PIC, LargeCodeModel); if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); @@ -443,15 +457,6 @@ if (GenDwarfForAssembly) Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer()); - // Package up features to be passed to target/subtarget - std::string FeaturesStr; - if (MAttrs.size()) { - SubtargetFeatures Features; - for (unsigned i = 0; i != MAttrs.size(); ++i) - Features.AddFeature(MAttrs[i]); - FeaturesStr = Features.getString(); - } - sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) ? sys::fs::OF_TextWithCRLF : sys::fs::OF_None; @@ -477,10 +482,6 @@ std::unique_ptr MCII(TheTarget->createMCInstrInfo()); assert(MCII && "Unable to create instruction info!"); - std::unique_ptr STI( - TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); - assert(STI && "Unable to create subtarget info!"); - MCInstPrinter *IP = nullptr; if (FileType == OFT_AssemblyFile) { IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant, diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -377,9 +377,9 @@ // Tell SrcMgr about this buffer, which is what the parser will pick up. SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); - MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx); + MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); std::unique_ptr BOS; diff --git a/llvm/tools/llvm-ml/Disassembler.cpp b/llvm/tools/llvm-ml/Disassembler.cpp --- a/llvm/tools/llvm-ml/Disassembler.cpp +++ b/llvm/tools/llvm-ml/Disassembler.cpp @@ -123,31 +123,32 @@ return false; } -int Disassembler::disassemble(const Target &T, const std::string &Triple, +int Disassembler::disassemble(const Target &T, const std::string &TripleName, MCSubtargetInfo &STI, MCStreamer &Streamer, MemoryBuffer &Buffer, SourceMgr &SM, raw_ostream &Out) { - std::unique_ptr MRI(T.createMCRegInfo(Triple)); + std::unique_ptr MRI(T.createMCRegInfo(TripleName)); if (!MRI) { - errs() << "error: no register info for target " << Triple << "\n"; + errs() << "error: no register info for target " << TripleName << "\n"; return -1; } MCTargetOptions MCOptions; std::unique_ptr MAI( - T.createMCAsmInfo(*MRI, Triple, MCOptions)); + T.createMCAsmInfo(*MRI, TripleName, MCOptions)); if (!MAI) { - errs() << "error: no assembly info for target " << Triple << "\n"; + errs() << "error: no assembly info for target " << TripleName << "\n"; return -1; } // Set up the MCContext for creating symbols and MCExpr's. - MCContext Ctx(MAI.get(), MRI.get(), nullptr); + MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr, + &STI); std::unique_ptr DisAsm( T.createMCDisassembler(STI, Ctx)); if (!DisAsm) { - errs() << "error: no disassembler for target " << Triple << "\n"; + errs() << "error: no disassembler for target " << TripleName << "\n"; return -1; } diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -275,11 +275,15 @@ MAI->setPreserveAsmComments(InputArgs.hasArg(OPT_preserve_comments)); + std::unique_ptr STI(TheTarget->createMCSubtargetInfo( + TripleName, /*CPU=*/"", /*Features=*/"")); + assert(STI && "Unable to create subtarget info!"); + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. MCObjectFileInfo MOFI; - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); - MOFI.InitMCObjectFileInfo(TheTriple, /*PIC=*/false, Ctx, + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); + MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false, /*LargeCodeModel=*/true); if (InputArgs.hasArg(OPT_save_temp_labels)) @@ -312,10 +316,6 @@ std::unique_ptr MCII(TheTarget->createMCInstrInfo()); assert(MCII && "Unable to create instruction info!"); - std::unique_ptr STI(TheTarget->createMCSubtargetInfo( - TripleName, /*CPU=*/"", /*Features=*/"")); - assert(STI && "Unable to create subtarget info!"); - MCInstPrinter *IP = nullptr; if (FileType == "s") { const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm); diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7228,7 +7228,8 @@ std::unique_ptr STI( TheTarget->createMCSubtargetInfo(TripleName, MachOMCPU, FeaturesStr)); CHECK_TARGET_INFO_CREATION(STI); - MCContext Ctx(AsmInfo.get(), MRI.get(), nullptr); + MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get()); std::unique_ptr DisAsm( TheTarget->createMCDisassembler(*STI, Ctx)); CHECK_TARGET_INFO_CREATION(DisAsm); @@ -7278,7 +7279,9 @@ ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MachOMCPU, FeaturesStr)); CHECK_THUMB_TARGET_INFO_CREATION(ThumbSTI); - ThumbCtx.reset(new MCContext(ThumbAsmInfo.get(), ThumbMRI.get(), nullptr)); + ThumbCtx.reset(new MCContext(Triple(ThumbTripleName), ThumbAsmInfo.get(), + ThumbMRI.get(), /*MOFI=*/nullptr, + ThumbSTI.get())); ThumbDisAsm.reset(ThumbTarget->createMCDisassembler(*ThumbSTI, *ThumbCtx)); CHECK_THUMB_TARGET_INFO_CREATION(ThumbDisAsm); MCContext *PtrThumbCtx = ThumbCtx.get(); diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1577,9 +1577,9 @@ reportError(Obj->getFileName(), "no instruction info for target " + TripleName); MCObjectFileInfo MOFI; - MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI); + MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get()); // FIXME: for now initialize MCObjectFileInfo with default values - MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx); + MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); std::unique_ptr DisAsm( TheTarget->createMCDisassembler(*STI, Ctx)); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -333,8 +333,8 @@ exitWithError("no instruction info for target " + TripleName, FileName); MCObjectFileInfo MOFI; - MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI); - MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx); + MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get()); + MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); DisAsm.reset(TheTarget->createMCDisassembler(*STI, Ctx)); if (!DisAsm) exitWithError("no disassembler for target " + TripleName, FileName); diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -757,7 +757,8 @@ if (!MAI) ErrorAndExit("Unable to create target asm info!"); - MCContext Ctx(MAI.get(), MRI.get(), nullptr); + MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get()); std::unique_ptr Disassembler( TheTarget->createMCDisassembler(*STI, Ctx)); diff --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp --- a/llvm/tools/sancov/sancov.cpp +++ b/llvm/tools/sancov/sancov.cpp @@ -727,7 +727,7 @@ failIfEmpty(AsmInfo, "no asm info for target " + TripleName); std::unique_ptr MOFI(new MCObjectFileInfo); - MCContext Ctx(AsmInfo.get(), MRI.get(), MOFI.get()); + MCContext Ctx(TheTriple, AsmInfo.get(), MRI.get(), MOFI.get(), STI.get()); std::unique_ptr DisAsm( TheTarget->createMCDisassembler(*STI, Ctx)); failIfEmpty(DisAsm, "no disassembler info for target " + TripleName); diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -6,8 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/ADT/Triple.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineModuleInfo.h" @@ -33,8 +34,10 @@ #include "MFCommon.inc" std::unique_ptr createMCContext(MCAsmInfo *AsmInfo) { - return std::make_unique( - AsmInfo, nullptr, nullptr, nullptr, nullptr, false); + Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"", + /*EnvironmentStr=*/"elf"); + return std::make_unique(TheTriple, AsmInfo, nullptr, nullptr, + nullptr, nullptr, nullptr, false); } // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly diff --git a/llvm/unittests/CodeGen/MachineOperandTest.cpp b/llvm/unittests/CodeGen/MachineOperandTest.cpp --- a/llvm/unittests/CodeGen/MachineOperandTest.cpp +++ b/llvm/unittests/CodeGen/MachineOperandTest.cpp @@ -318,7 +318,8 @@ TEST(MachineOperandTest, PrintMCSymbol) { MCAsmInfo MAI; - MCContext Ctx(&MAI, /*MRI=*/nullptr, /*MOFI=*/nullptr); + Triple T = Triple("unknown-unknown-unknown"); + MCContext Ctx(T, &MAI, /*MRI=*/nullptr, /*MOFI=*/nullptr, /*MSTI=*/nullptr); MCSymbol *Sym = Ctx.getOrCreateSymbol("foo"); // Create a MachineOperand with a metadata and print it. diff --git a/llvm/unittests/CodeGen/TestAsmPrinter.cpp b/llvm/unittests/CodeGen/TestAsmPrinter.cpp --- a/llvm/unittests/CodeGen/TestAsmPrinter.cpp +++ b/llvm/unittests/CodeGen/TestAsmPrinter.cpp @@ -55,8 +55,9 @@ return make_error("no target machine for target " + TripleName, inconvertibleErrorCode()); - MC.reset(new MCContext(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), - TM->getObjFileLowering())); + Triple TheTriple(TripleName); + MC.reset(new MCContext(TheTriple, TM->getMCAsmInfo(), TM->getMCRegisterInfo(), + TM->getObjFileLowering(), TM->getMCSubtargetInfo())); TM->getObjFileLowering()->Initialize(*MC, *TM); MS = new StrictMock(MC.get()); diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp --- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -465,7 +465,7 @@ inconvertibleErrorCode()); TLOF = TM->getObjFileLowering(); - MC.reset(new MCContext(MAI.get(), MRI.get(), TLOF)); + MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), TLOF, MSTI.get())); TLOF->Initialize(*MC, *TM); MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC); diff --git a/llvm/unittests/MC/DwarfLineTables.cpp b/llvm/unittests/MC/DwarfLineTables.cpp --- a/llvm/unittests/MC/DwarfLineTables.cpp +++ b/llvm/unittests/MC/DwarfLineTables.cpp @@ -21,7 +21,7 @@ namespace { struct Context { - const char *Triple = "x86_64-pc-linux"; + const char *TripleName = "x86_64-pc-linux"; std::unique_ptr MRI; std::unique_ptr MAI; std::unique_ptr Ctx; @@ -33,14 +33,15 @@ // If we didn't build x86, do not run the test. std::string Error; - const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error); + const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); if (!TheTarget) return; - MRI.reset(TheTarget->createMCRegInfo(Triple)); + MRI.reset(TheTarget->createMCRegInfo(TripleName)); MCTargetOptions MCOptions; - MAI.reset(TheTarget->createMCAsmInfo(*MRI, Triple, MCOptions)); - Ctx = std::make_unique(MAI.get(), MRI.get(), nullptr); + MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); + Ctx = std::make_unique(Triple(TripleName), MAI.get(), MRI.get(), + /*MOFI=*/nullptr, /*MSTI=*/nullptr); } operator bool() { return Ctx.get(); } diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp --- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp +++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp @@ -112,9 +112,9 @@ SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); EXPECT_EQ(Buffer, nullptr); - Ctx.reset( - new MCContext(MUPMAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions)); - MOFI.InitMCObjectFileInfo(Triple, false, *Ctx, false); + Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), &MOFI, STI.get(), + &SrcMgr, &MCOptions)); + MOFI.initMCObjectFileInfo(*Ctx, /*PIC=*/false, /*LargeCodeModel=*/false); Str.reset(TheTarget->createNullStreamer(*Ctx)); diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -169,8 +169,8 @@ mai->setRelaxELFRelocations(true); llvm::MCObjectFileInfo mofi; - llvm::MCContext ctx(mai.get(), mri.get(), &mofi, &srcMgr, &mcOptions); - mofi.InitMCObjectFileInfo(triple, false, ctx, false); + llvm::MCContext ctx(triple, mai.get(), mri.get(), &mofi, &srcMgr, &mcOptions); + mofi.initMCObjectFileInfo(ctx, /*PIC=*/false, /*LargeCodeModel=*/false); SmallString<128> cwd; if (!llvm::sys::fs::current_path(cwd))