1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[MC] Untangle MCContext and MCObjectFileInfo

This untangles the MCContext and the MCObjectFileInfo. There is a circular
dependency between MCContext and MCObjectFileInfo. Currently this dependency
also exists during construction: You can't contruct a MOFI without a MCContext
without constructing the MCContext with a dummy version of that MOFI first.
This removes this dependency during construction. In a perfect world,
MCObjectFileInfo wouldn't depend on MCContext at all, but only be stored in the
MCContext, like other MC information. This is future work.

This also shifts/adds more information to the MCContext making it more
available to the different targets. Namely:

- TargetTriple
- ObjectFileType
- SubtargetInfo

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D101462
This commit is contained in:
Philipp Krones 2021-05-05 10:03:02 -07:00 committed by Fangrui Song
parent 7dee8977b2
commit 0d572a30c9
43 changed files with 242 additions and 203 deletions

View File

@ -74,8 +74,14 @@ namespace llvm {
using DiagHandlerTy = using DiagHandlerTy =
std::function<void(const SMDiagnostic &, bool, const SourceMgr &, std::function<void(const SMDiagnostic &, bool, const SourceMgr &,
std::vector<const MDNode *> &)>; std::vector<const MDNode *> &)>;
enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF };
private: private:
Environment Env;
/// The triple for this object.
Triple TT;
/// The SourceMgr for this object, if any. /// The SourceMgr for this object, if any.
const SourceMgr *SrcMgr; const SourceMgr *SrcMgr;
@ -94,6 +100,9 @@ namespace llvm {
/// The MCObjectFileInfo for this target. /// The MCObjectFileInfo for this target.
const MCObjectFileInfo *MOFI; const MCObjectFileInfo *MOFI;
/// The MCSubtargetInfo for this target.
const MCSubtargetInfo *MSTI;
std::unique_ptr<CodeViewContext> CVContext; std::unique_ptr<CodeViewContext> CVContext;
/// Allocator object used for creating machine code objects. /// Allocator object used for creating machine code objects.
@ -383,8 +392,9 @@ namespace llvm {
DenseSet<StringRef> ELFSeenGenericMergeableSections; DenseSet<StringRef> ELFSeenGenericMergeableSections;
public: public:
explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, explicit MCContext(const Triple &TheTriple, const MCAsmInfo *MAI,
const MCObjectFileInfo *MOFI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI,
const MCSubtargetInfo *MSTI,
const SourceMgr *Mgr = nullptr, const SourceMgr *Mgr = nullptr,
MCTargetOptions const *TargetOpts = nullptr, MCTargetOptions const *TargetOpts = nullptr,
bool DoAutoReset = true); bool DoAutoReset = true);
@ -392,6 +402,9 @@ namespace llvm {
MCContext &operator=(const MCContext &) = delete; MCContext &operator=(const MCContext &) = delete;
~MCContext(); ~MCContext();
Environment getObjectFileType() const { return Env; }
const Triple &getTargetTriple() const { return TT; }
const SourceMgr *getSourceManager() const { return SrcMgr; } const SourceMgr *getSourceManager() const { return SrcMgr; }
void initInlineSourceManager(); void initInlineSourceManager();
@ -409,6 +422,8 @@ namespace llvm {
const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; } const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
const MCSubtargetInfo *getSubtargetInfo() const { return MSTI; }
CodeViewContext &getCVContext(); CodeViewContext &getCVContext();
void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; } void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }

View File

@ -227,7 +227,7 @@ protected:
MCSection *TOCBaseSection = nullptr; MCSection *TOCBaseSection = nullptr;
public: public:
void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx, void initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
bool LargeCodeModel = false); bool LargeCodeModel = false);
MCContext &getContext() const { return *Ctx; } MCContext &getContext() const { return *Ctx; }
@ -416,16 +416,11 @@ public:
MCSection *getEHFrameSection() const { return EHFrameSection; } MCSection *getEHFrameSection() const { return EHFrameSection; }
enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF };
Environment getObjectFileType() const { return Env; }
bool isPositionIndependent() const { return PositionIndependent; } bool isPositionIndependent() const { return PositionIndependent; }
private: private:
Environment Env;
bool PositionIndependent = false; bool PositionIndependent = false;
MCContext *Ctx = nullptr; MCContext *Ctx = nullptr;
Triple TT;
VersionTuple SDKVersion; VersionTuple SDKVersion;
void initMachOMCObjectFileInfo(const Triple &T); void initMachOMCObjectFileInfo(const Triple &T);
@ -436,8 +431,6 @@ private:
MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const; MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
public: public:
const Triple &getTargetTriple() const { return TT; }
void setSDKVersion(const VersionTuple &TheSDKVersion) { void setSDKVersion(const VersionTuple &TheSDKVersion) {
SDKVersion = TheSDKVersion; SDKVersion = TheSDKVersion;
} }

View File

@ -217,8 +217,9 @@ void MachineModuleInfo::finalize() {
MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI) MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
: TM(std::move(MMI.TM)), : TM(std::move(MMI.TM)),
Context(MMI.TM.getMCAsmInfo(), MMI.TM.getMCRegisterInfo(), Context(MMI.TM.getTargetTriple(), MMI.TM.getMCAsmInfo(),
MMI.TM.getObjFileLowering(), nullptr, nullptr, false), MMI.TM.getMCRegisterInfo(), MMI.TM.getObjFileLowering(),
MMI.TM.getMCSubtargetInfo(), nullptr, nullptr, false),
MachineFunctions(std::move(MMI.MachineFunctions)) { MachineFunctions(std::move(MMI.MachineFunctions)) {
ObjFileMMI = MMI.ObjFileMMI; ObjFileMMI = MMI.ObjFileMMI;
CurCallSite = MMI.CurCallSite; CurCallSite = MMI.CurCallSite;
@ -232,15 +233,17 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
} }
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM) MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
: TM(*TM), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
TM->getObjFileLowering(), nullptr, nullptr, false) { TM->getMCRegisterInfo(), TM->getObjFileLowering(),
TM->getMCSubtargetInfo(), nullptr, nullptr, false) {
initialize(); initialize();
} }
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM, MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM,
MCContext *ExtContext) MCContext *ExtContext)
: TM(*TM), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
TM->getObjFileLowering(), nullptr, nullptr, false), TM->getMCRegisterInfo(), TM->getObjFileLowering(),
TM->getMCSubtargetInfo(), nullptr, nullptr, false),
ExternalContext(ExtContext) { ExternalContext(ExtContext) {
initialize(); initialize();
} }

View File

@ -1645,7 +1645,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
// Append "$symbol" to the section name *before* IR-level mangling is // Append "$symbol" to the section name *before* IR-level mangling is
// applied when targetting mingw. This is what GCC does, and the ld.bfd // applied when targetting mingw. This is what GCC does, and the ld.bfd
// COFF linker will not properly handle comdats otherwise. // COFF linker will not properly handle comdats otherwise.
if (getTargetTriple().isWindowsGNUEnvironment()) if (getContext().getTargetTriple().isWindowsGNUEnvironment())
raw_svector_ostream(Name) << '$' << ComdatGV->getName(); raw_svector_ostream(Name) << '$' << ComdatGV->getName();
return getContext().getCOFFSection(Name, Characteristics, Kind, return getContext().getCOFFSection(Name, Characteristics, Kind,
@ -1762,7 +1762,8 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
std::string Flags; std::string Flags;
for (const GlobalValue &GV : M.global_values()) { for (const GlobalValue &GV : M.global_values()) {
raw_string_ostream OS(Flags); raw_string_ostream OS(Flags);
emitLinkerFlagsForGlobalCOFF(OS, &GV, getTargetTriple(), getMangler()); emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
getMangler());
OS.flush(); OS.flush();
if (!Flags.empty()) { if (!Flags.empty()) {
Streamer.SwitchSection(getDrectveSection()); Streamer.SwitchSection(getDrectveSection());
@ -1786,7 +1787,8 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
continue; continue;
raw_string_ostream OS(Flags); raw_string_ostream OS(Flags);
emitLinkerFlagsForUsedCOFF(OS, GV, getTargetTriple(), getMangler()); emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
getMangler());
OS.flush(); OS.flush();
if (!Flags.empty()) { if (!Flags.empty()) {
@ -1865,16 +1867,16 @@ static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection( MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
unsigned Priority, const MCSymbol *KeySym) const { unsigned Priority, const MCSymbol *KeySym) const {
return getCOFFStaticStructorSection(getContext(), getTargetTriple(), true, return getCOFFStaticStructorSection(
Priority, KeySym, getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
cast<MCSectionCOFF>(StaticCtorSection)); cast<MCSectionCOFF>(StaticCtorSection));
} }
MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection( MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
unsigned Priority, const MCSymbol *KeySym) const { unsigned Priority, const MCSymbol *KeySym) const {
return getCOFFStaticStructorSection(getContext(), getTargetTriple(), false, return getCOFFStaticStructorSection(
Priority, KeySym, getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
cast<MCSectionCOFF>(StaticDtorSection)); cast<MCSectionCOFF>(StaticDtorSection));
} }
const MCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference( const MCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference(

View File

@ -50,14 +50,15 @@ bool DwarfStreamer::init(Triple TheTriple) {
if (!MAI) if (!MAI)
return error("no asm info for target " + TripleName, Context), false; 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, "", "")); MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
if (!MSTI) if (!MSTI)
return error("no subtarget info for target " + TripleName, Context), false; 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); MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions);
if (!MAB) if (!MAB)
return error("no asm backend for target " + TripleName, Context), false; return error("no asm backend for target " + TripleName, Context), false;
@ -212,7 +213,7 @@ void DwarfStreamer::emitPaperTrailWarningsDie(DIE &Die) {
Asm.emitInt32(11 + Die.getSize() - 4); Asm.emitInt32(11 + Die.getSize() - 4);
Asm.emitInt16(2); Asm.emitInt16(2);
Asm.emitInt32(0); Asm.emitInt32(0);
Asm.emitInt8(MOFI->getTargetTriple().isArch64Bit() ? 8 : 4); Asm.emitInt8(MC->getTargetTriple().isArch64Bit() ? 8 : 4);
DebugInfoSectionSize += 11; DebugInfoSectionSize += 11;
emitDIE(Die); emitDIE(Die);
} }

View File

@ -484,9 +484,8 @@ void MCAsmStreamer::changeSection(MCSection *Section,
if (MCTargetStreamer *TS = getTargetStreamer()) { if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS); TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
} else { } else {
Section->PrintSwitchToSection( Section->PrintSwitchToSection(*MAI, getContext().getTargetTriple(), OS,
*MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS, Subsection);
Subsection);
} }
} }

View File

@ -62,11 +62,13 @@ static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
SMD.print(nullptr, errs()); SMD.print(nullptr, errs());
} }
MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
const MCObjectFileInfo *mofi, const SourceMgr *mgr, const MCRegisterInfo *mri, const MCObjectFileInfo *mofi,
const MCSubtargetInfo *msti, const SourceMgr *mgr,
MCTargetOptions const *TargetOpts, bool DoAutoReset) MCTargetOptions const *TargetOpts, bool DoAutoReset)
: SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler), : TT(TheTriple), SrcMgr(mgr), InlineSrcMgr(nullptr),
MAI(mai), MRI(mri), MOFI(mofi), Symbols(Allocator), UsedNames(Allocator), DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MOFI(mofi),
MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
InlineAsmUsedLabelNames(Allocator), InlineAsmUsedLabelNames(Allocator),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
AutoReset(DoAutoReset), TargetOptions(TargetOpts) { AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
@ -75,6 +77,34 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
if (SrcMgr && SrcMgr->getNumBuffers()) if (SrcMgr && SrcMgr->getNumBuffers())
MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID()) MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())
->getBufferIdentifier()); ->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() { MCContext::~MCContext() {
@ -195,19 +225,18 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
"MCSymbol classes must be trivially destructible"); "MCSymbol classes must be trivially destructible");
static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(), static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
"MCSymbol classes must be trivially destructible"); "MCSymbol classes must be trivially destructible");
if (MOFI) {
switch (MOFI->getObjectFileType()) { switch (getObjectFileType()) {
case MCObjectFileInfo::IsCOFF: case MCContext::IsCOFF:
return new (Name, *this) MCSymbolCOFF(Name, IsTemporary); return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
case MCObjectFileInfo::IsELF: case MCContext::IsELF:
return new (Name, *this) MCSymbolELF(Name, IsTemporary); return new (Name, *this) MCSymbolELF(Name, IsTemporary);
case MCObjectFileInfo::IsMachO: case MCContext::IsMachO:
return new (Name, *this) MCSymbolMachO(Name, IsTemporary); return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
case MCObjectFileInfo::IsWasm: case MCContext::IsWasm:
return new (Name, *this) MCSymbolWasm(Name, IsTemporary); return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
case MCObjectFileInfo::IsXCOFF: case MCContext::IsXCOFF:
return createXCOFFSymbolImpl(Name, IsTemporary); return createXCOFFSymbolImpl(Name, IsTemporary);
}
} }
return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
IsTemporary); IsTemporary);

View File

@ -74,7 +74,8 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
return nullptr; return nullptr;
// Set up the MCContext for creating symbols and MCExpr's. // Set up the MCContext for creating symbols and MCExpr's.
std::unique_ptr<MCContext> Ctx(new MCContext(MAI.get(), MRI.get(), nullptr)); std::unique_ptr<MCContext> Ctx(new MCContext(Triple(TT), MAI.get(), MRI.get(),
/*MOFI=*/nullptr, STI.get()));
if (!Ctx) if (!Ctx)
return nullptr; return nullptr;

View File

@ -515,7 +515,7 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
MCMachOStreamer *S = MCMachOStreamer *S =
new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE), new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
DWARFMustBeAtTheEnd, LabelSections); DWARFMustBeAtTheEnd, LabelSections);
const Triple &Target = Context.getObjectFileInfo()->getTargetTriple(); const Triple &Target = Context.getTargetTriple();
S->emitVersionForTarget(Target, Context.getObjectFileInfo()->getSDKVersion()); S->emitVersionForTarget(Target, Context.getObjectFileInfo()->getSDKVersion());
if (RelaxAll) if (RelaxAll)
S->getAssembler().setRelaxAll(true); S->getAssembler().setRelaxAll(true);

View File

@ -959,11 +959,10 @@ void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
/* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC); /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC);
} }
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
MCContext &ctx,
bool LargeCodeModel) { bool LargeCodeModel) {
PositionIndependent = PIC; PositionIndependent = PIC;
Ctx = &ctx; Ctx = &MCCtx;
// Common. // Common.
CommDirectiveSupportsAlignment = true; CommDirectiveSupportsAlignment = true;
@ -982,45 +981,29 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
DwarfAccelTypesSection = nullptr; // Used only by selected targets. DwarfAccelTypesSection = nullptr; // Used only by selected targets.
TT = TheTriple; Triple TheTriple = Ctx->getTargetTriple();
switch (Ctx->getObjectFileType()) {
switch (TT.getObjectFormat()) { case MCContext::IsMachO:
case Triple::MachO: initMachOMCObjectFileInfo(TheTriple);
Env = IsMachO;
initMachOMCObjectFileInfo(TT);
break; break;
case Triple::COFF: case MCContext::IsCOFF:
if (!TT.isOSWindows()) initCOFFMCObjectFileInfo(TheTriple);
report_fatal_error(
"Cannot initialize MC for non-Windows COFF object files.");
Env = IsCOFF;
initCOFFMCObjectFileInfo(TT);
break; break;
case Triple::ELF: case MCContext::IsELF:
Env = IsELF; initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
initELFMCObjectFileInfo(TT, LargeCodeModel);
break; break;
case Triple::Wasm: case MCContext::IsWasm:
Env = IsWasm; initWasmMCObjectFileInfo(TheTriple);
initWasmMCObjectFileInfo(TT);
break; break;
case Triple::GOFF: case MCContext::IsXCOFF:
report_fatal_error("Cannot initialize MC for GOFF object file format"); initXCOFFMCObjectFileInfo(TheTriple);
break;
case Triple::XCOFF:
Env = IsXCOFF;
initXCOFFMCObjectFileInfo(TT);
break;
case Triple::UnknownObjectFormat:
report_fatal_error("Cannot initialize MC for unknown object file format.");
break; break;
} }
} }
MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
uint64_t Hash) const { uint64_t Hash) const {
switch (TT.getObjectFormat()) { switch (Ctx->getTargetTriple().getObjectFormat()) {
case Triple::ELF: case Triple::ELF:
return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
utostr(Hash), /*IsComdat=*/true); utostr(Hash), /*IsComdat=*/true);
@ -1041,7 +1024,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
MCSection * MCSection *
MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
if (Env != IsELF) if (Ctx->getObjectFileType() != MCContext::IsELF)
return StackSizesSection; return StackSizesSection;
const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
@ -1059,7 +1042,7 @@ MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
MCSection * MCSection *
MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
if (Env != IsELF) if (Ctx->getObjectFileType() != MCContext::IsELF)
return nullptr; return nullptr;
const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
@ -1079,7 +1062,7 @@ MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
MCSection * MCSection *
MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const { MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const {
if (Env == IsELF) { if (Ctx->getObjectFileType() == MCContext::IsELF) {
const auto *ElfSec = static_cast<const MCSectionELF *>(TextSec); const auto *ElfSec = static_cast<const MCSectionELF *>(TextSec);
// Create a separate section for probes that comes with a comdat function. // Create a separate section for probes that comes with a comdat function.
if (const MCSymbol *Group = ElfSec->getGroup()) { if (const MCSymbol *Group = ElfSec->getGroup()) {
@ -1095,7 +1078,7 @@ MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const {
MCSection * MCSection *
MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { 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 // Create a separate comdat group for each function's descriptor in order
// for the linker to deduplicate. The duplication, must be from different // for the linker to deduplicate. The duplication, must be from different
// tranlation unit, can come from: // tranlation unit, can come from:
@ -1105,7 +1088,7 @@ MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
// Use a concatenation of the section name and the function name as the // 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 // group name so that descriptor-only groups won't be folded with groups of
// code. // code.
if (TT.supportsCOMDAT() && !FuncName.empty()) { if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) {
auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
auto Flags = S->getFlags() | ELF::SHF_GROUP; auto Flags = S->getFlags() | ELF::SHF_GROUP;
return Ctx->getELFSection(S->getName(), S->getType(), Flags, return Ctx->getELFSection(S->getName(), S->getType(), Flags,

View File

@ -729,21 +729,21 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
Out.setStartTokLocPtr(&StartTokLoc); Out.setStartTokLocPtr(&StartTokLoc);
// Initialize the platform / file format parser. // Initialize the platform / file format parser.
switch (Ctx.getObjectFileInfo()->getObjectFileType()) { switch (Ctx.getObjectFileType()) {
case MCObjectFileInfo::IsCOFF: case MCContext::IsCOFF:
PlatformParser.reset(createCOFFAsmParser()); PlatformParser.reset(createCOFFAsmParser());
break; break;
case MCObjectFileInfo::IsMachO: case MCContext::IsMachO:
PlatformParser.reset(createDarwinAsmParser()); PlatformParser.reset(createDarwinAsmParser());
IsDarwin = true; IsDarwin = true;
break; break;
case MCObjectFileInfo::IsELF: case MCContext::IsELF:
PlatformParser.reset(createELFAsmParser()); PlatformParser.reset(createELFAsmParser());
break; break;
case MCObjectFileInfo::IsWasm: case MCContext::IsWasm:
PlatformParser.reset(createWasmAsmParser()); PlatformParser.reset(createWasmAsmParser());
break; break;
case MCObjectFileInfo::IsXCOFF: case MCContext::IsXCOFF:
report_fatal_error( report_fatal_error(
"Need to implement createXCOFFAsmParser for XCOFF format."); "Need to implement createXCOFFAsmParser for XCOFF format.");
break; break;

View File

@ -403,7 +403,7 @@ bool COFFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
SectionKind Kind = computeSectionKind(Flags); SectionKind Kind = computeSectionKind(Flags);
if (Kind.isText()) { if (Kind.isText()) {
const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); const Triple &T = getContext().getTargetTriple();
if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
Flags |= COFF::IMAGE_SCN_MEM_16BIT; Flags |= COFF::IMAGE_SCN_MEM_16BIT;
} }

View File

@ -695,7 +695,7 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
return Error(Loc, toString(std::move(E))); return Error(Loc, toString(std::move(E)));
// Issue a warning if the target is not powerpc and Section is a *coal* section. // 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(); Triple::ArchType ArchTy = TT.getArch();
if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) { if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
@ -1091,7 +1091,7 @@ bool DarwinAsmParser::parseSDKVersion(VersionTuple &SDKVersion) {
void DarwinAsmParser::checkVersion(StringRef Directive, StringRef Arg, void DarwinAsmParser::checkVersion(StringRef Directive, StringRef Arg,
SMLoc Loc, Triple::OSType ExpectedOS) { SMLoc Loc, Triple::OSType ExpectedOS) {
const Triple &Target = getContext().getObjectFileInfo()->getTargetTriple(); const Triple &Target = getContext().getTargetTriple();
if (Target.getOS() != ExpectedOS) if (Target.getOS() != ExpectedOS)
Warning(Loc, Twine(Directive) + Warning(Loc, Twine(Directive) +
(Arg.empty() ? Twine() : Twine(' ') + Arg) + (Arg.empty() ? Twine() : Twine(' ') + Arg) +

View File

@ -1029,8 +1029,8 @@ MasmParser::MasmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
EndStatementAtEOFStack.push_back(true); EndStatementAtEOFStack.push_back(true);
// Initialize the platform / file format parser. // Initialize the platform / file format parser.
switch (Ctx.getObjectFileInfo()->getObjectFileType()) { switch (Ctx.getObjectFileType()) {
case MCObjectFileInfo::IsCOFF: case MCContext::IsCOFF:
PlatformParser.reset(createCOFFMasmParser()); PlatformParser.reset(createCOFFMasmParser());
break; break;
default: default:

View File

@ -57,10 +57,9 @@ void MCTargetStreamer::changeSection(const MCSection *CurSection,
MCSection *Section, MCSection *Section,
const MCExpr *Subsection, const MCExpr *Subsection,
raw_ostream &OS) { raw_ostream &OS) {
Section->PrintSwitchToSection( Section->PrintSwitchToSection(*Streamer.getContext().getAsmInfo(),
*Streamer.getContext().getAsmInfo(), Streamer.getContext().getTargetTriple(), OS,
Streamer.getContext().getObjectFileInfo()->getTargetTriple(), OS, Subsection);
Subsection);
} }
void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) { void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) {

View File

@ -181,8 +181,7 @@ void MCWinCOFFStreamer::EndCOFFSymbolDef() {
void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
// SafeSEH is a feature specific to 32-bit x86. It does not exist (and is // 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. // unnecessary) on all platforms which use table-based exception dispatch.
if (getContext().getObjectFileInfo()->getTargetTriple().getArch() != if (getContext().getTargetTriple().getArch() != Triple::x86)
Triple::x86)
return; return;
const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol); const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
@ -266,7 +265,7 @@ void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) { unsigned ByteAlignment) {
auto *Symbol = cast<MCSymbolCOFF>(S); auto *Symbol = cast<MCSymbolCOFF>(S);
const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); const Triple &T = getContext().getTargetTriple();
if (T.isWindowsMSVCEnvironment()) { if (T.isWindowsMSVCEnvironment()) {
if (ByteAlignment > 32) if (ByteAlignment > 32)
report_fatal_error("alignment is limited to 32-bytes"); report_fatal_error("alignment is limited to 32-bytes");

View File

@ -100,8 +100,8 @@ initializeRecordStreamer(const Module &M,
return; return;
MCObjectFileInfo MOFI; MCObjectFileInfo MOFI;
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI); MCContext MCCtx(TT, MAI.get(), MRI.get(), &MOFI, STI.get());
MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, MCCtx); MOFI.initMCObjectFileInfo(MCCtx, /*PIC=*/false);
MOFI.setSDKVersion(M.getSDKVersion()); MOFI.setSDKVersion(M.getSDKVersion());
RecordStreamer Streamer(MCCtx, M); RecordStreamer Streamer(MCCtx, M);
T->createNullTargetStreamer(Streamer); T->createNullTargetStreamer(Streamer);

View File

@ -5267,10 +5267,9 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
/// ParseDirective parses the arm specific directives /// ParseDirective parses the arm specific directives
bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
const MCObjectFileInfo::Environment Format = const MCContext::Environment Format = getContext().getObjectFileType();
getContext().getObjectFileInfo()->getObjectFileType(); bool IsMachO = Format == MCContext::IsMachO;
bool IsMachO = Format == MCObjectFileInfo::IsMachO; bool IsCOFF = Format == MCContext::IsCOFF;
bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
auto IDVal = DirectiveID.getIdentifier().lower(); auto IDVal = DirectiveID.getIdentifier().lower();
SMLoc Loc = DirectiveID.getLoc(); SMLoc Loc = DirectiveID.getLoc();

View File

@ -32,7 +32,6 @@
#include "llvm/MC/MCInst.h" #include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrDesc.h" #include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCAsmParser.h"
#include "llvm/MC/MCParser/MCAsmParserExtension.h" #include "llvm/MC/MCParser/MCAsmParserExtension.h"
@ -6331,10 +6330,10 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
} }
enum { enum {
COFF = (1 << MCObjectFileInfo::IsCOFF), COFF = (1 << MCContext::IsCOFF),
ELF = (1 << MCObjectFileInfo::IsELF), ELF = (1 << MCContext::IsELF),
MACHO = (1 << MCObjectFileInfo::IsMachO), MACHO = (1 << MCContext::IsMachO),
WASM = (1 << MCObjectFileInfo::IsWasm), WASM = (1 << MCContext::IsWasm),
}; };
static const struct PrefixEntry { static const struct PrefixEntry {
const char *Spelling; const char *Spelling;
@ -6357,20 +6356,20 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
} }
uint8_t CurrentFormat; uint8_t CurrentFormat;
switch (getContext().getObjectFileInfo()->getObjectFileType()) { switch (getContext().getObjectFileType()) {
case MCObjectFileInfo::IsMachO: case MCContext::IsMachO:
CurrentFormat = MACHO; CurrentFormat = MACHO;
break; break;
case MCObjectFileInfo::IsELF: case MCContext::IsELF:
CurrentFormat = ELF; CurrentFormat = ELF;
break; break;
case MCObjectFileInfo::IsCOFF: case MCContext::IsCOFF:
CurrentFormat = COFF; CurrentFormat = COFF;
break; break;
case MCObjectFileInfo::IsWasm: case MCContext::IsWasm:
CurrentFormat = WASM; CurrentFormat = WASM;
break; break;
case MCObjectFileInfo::IsXCOFF: case MCContext::IsXCOFF:
llvm_unreachable("unexpected object format"); llvm_unreachable("unexpected object format");
break; break;
} }
@ -11002,10 +11001,9 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
/// parseDirective parses the arm specific directives /// parseDirective parses the arm specific directives
bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
const MCObjectFileInfo::Environment Format = const MCContext::Environment Format = getContext().getObjectFileType();
getContext().getObjectFileInfo()->getObjectFileType(); bool IsMachO = Format == MCContext::IsMachO;
bool IsMachO = Format == MCObjectFileInfo::IsMachO; bool IsCOFF = Format == MCContext::IsCOFF;
bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
std::string IDVal = DirectiveID.getIdentifier().lower(); std::string IDVal = DirectiveID.getIdentifier().lower();
if (IDVal == ".word") if (IDVal == ".word")
@ -11143,8 +11141,8 @@ void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
/// ::= .thumbfunc symbol_name /// ::= .thumbfunc symbol_name
bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
MCAsmParser &Parser = getParser(); MCAsmParser &Parser = getParser();
const auto Format = getContext().getObjectFileInfo()->getObjectFileType(); const auto Format = getContext().getObjectFileType();
bool IsMachO = Format == MCObjectFileInfo::IsMachO; bool IsMachO = Format == MCContext::IsMachO;
// Darwin asm has (optionally) function name after .thumb_func direction // Darwin asm has (optionally) function name after .thumb_func direction
// ELF doesn't // ELF doesn't

View File

@ -94,7 +94,8 @@ void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
outputDwarfFileDirectives(); outputDwarfFileDirectives();
OS << "\t.section"; OS << "\t.section";
Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(), Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
FI->getTargetTriple(), OS, SubSection); getStreamer().getContext().getTargetTriple(),
OS, SubSection);
// DWARF sections are enclosed into braces - emit the open one. // DWARF sections are enclosed into braces - emit the open one.
OS << "\t{\n"; OS << "\t{\n";
HasSections = true; HasSections = true;

View File

@ -44,7 +44,7 @@ void TargetLoweringObjectFile::Initialize(MCContext &ctx,
// `Initialize` can be called more than once. // `Initialize` can be called more than once.
delete Mang; delete Mang;
Mang = new Mangler(); Mang = new Mangler();
InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), ctx, initMCObjectFileInfo(ctx, TM.isPositionIndependent(),
TM.getCodeModel() == CodeModel::Large); TM.getCodeModel() == CodeModel::Large);
// Reset various EH DWARF encodings. // Reset various EH DWARF encodings.

View File

@ -407,7 +407,8 @@ Error FileAnalysis::initialiseDisassemblyMembers() {
if (!MII) if (!MII)
return make_error<UnsupportedDisassembly>("Failed to initialise MII."); return make_error<UnsupportedDisassembly>("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( Disassembler.reset(
ObjectTarget->createMCDisassembler(*SubtargetInfo, *Context)); ObjectTarget->createMCDisassembler(*SubtargetInfo, *Context));

View File

@ -875,15 +875,15 @@ int main(int argc, char **argv) {
if (!MAI) if (!MAI)
return error("no asm info for target " + TripleName, Context); 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<MCSubtargetInfo> MSTI( std::unique_ptr<MCSubtargetInfo> MSTI(
TheTarget->createMCSubtargetInfo(TripleName, "", "")); TheTarget->createMCSubtargetInfo(TripleName, "", ""));
if (!MSTI) if (!MSTI)
return error("no subtarget info for target " + TripleName, Context); 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; MCTargetOptions Options;
auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options); auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options);
if (!MAB) if (!MAB)

View File

@ -176,8 +176,9 @@ Analysis::Analysis(const Target &Target, std::unique_ptr<MCInstrInfo> InstrInfo,
Triple(FirstPoint.LLVMTriple), 0 /*default variant*/, *AsmInfo_, Triple(FirstPoint.LLVMTriple), 0 /*default variant*/, *AsmInfo_,
*InstrInfo_, *RegInfo_)); *InstrInfo_, *RegInfo_));
Context_ = std::make_unique<MCContext>(AsmInfo_.get(), RegInfo_.get(), Context_ = std::make_unique<MCContext>(
&ObjectFileInfo_); Triple(FirstPoint.LLVMTriple), AsmInfo_.get(), RegInfo_.get(),
&ObjectFileInfo_, SubtargetInfo_.get());
Disasm_.reset(Target.createMCDisassembler(*SubtargetInfo_, *Context_)); Disasm_.reset(Target.createMCDisassembler(*SubtargetInfo_, *Context_));
assert(Disasm_ && "cannot create MCDisassembler. missing call to " assert(Disasm_ && "cannot create MCDisassembler. missing call to "
"InitializeXXXTargetDisassembler ?"); "InitializeXXXTargetDisassembler ?");

View File

@ -62,8 +62,10 @@ std::unique_ptr<LLVMTargetMachine> LLVMState::createTargetMachine() const {
bool LLVMState::canAssemble(const MCInst &Inst) const { bool LLVMState::canAssemble(const MCInst &Inst) const {
MCObjectFileInfo ObjectFileInfo; MCObjectFileInfo ObjectFileInfo;
MCContext Context(TheTargetMachine->getMCAsmInfo(), MCContext Context(TheTargetMachine->getTargetTriple(),
TheTargetMachine->getMCRegisterInfo(), &ObjectFileInfo); TheTargetMachine->getMCAsmInfo(),
TheTargetMachine->getMCRegisterInfo(), &ObjectFileInfo,
TheTargetMachine->getMCSubtargetInfo());
std::unique_ptr<const MCCodeEmitter> CodeEmitter( std::unique_ptr<const MCCodeEmitter> CodeEmitter(
TheTargetMachine->getTarget().createMCCodeEmitter( TheTargetMachine->getTarget().createMCCodeEmitter(
*TheTargetMachine->getMCInstrInfo(), *TheTargetMachine->getMCRegisterInfo(), *TheTargetMachine->getMCInstrInfo(), *TheTargetMachine->getMCRegisterInfo(),

View File

@ -132,10 +132,11 @@ Expected<std::vector<BenchmarkCode>> readSnippets(const LLVMState &State,
MCObjectFileInfo ObjectFileInfo; MCObjectFileInfo ObjectFileInfo;
const TargetMachine &TM = State.getTargetMachine(); 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(); Context.initInlineSourceManager();
ObjectFileInfo.InitMCObjectFileInfo(TM.getTargetTriple(), /*PIC*/ false, ObjectFileInfo.initMCObjectFileInfo(Context, /*PIC=*/false);
Context);
BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result); BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result);
std::string Error; std::string Error;

View File

@ -1256,7 +1256,8 @@ static Error runChecks(Session &S) {
TripleName, TripleName,
inconvertibleErrorCode())); inconvertibleErrorCode()));
MCContext Ctx(MAI.get(), MRI.get(), nullptr); MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr,
STI.get());
std::unique_ptr<MCDisassembler> Disassembler( std::unique_ptr<MCDisassembler> Disassembler(
TheTarget->createMCDisassembler(*STI, Ctx)); TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -170,12 +170,13 @@ int AssembleOneInput(const uint8_t *Data, size_t Size) {
abort(); abort();
} }
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
MCObjectFileInfo MOFI; 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; static const bool UsePIC = false;
MOFI.InitMCObjectFileInfo(TheTriple, UsePIC, Ctx); MOFI.initMCObjectFileInfo(Ctx, UsePIC);
const unsigned OutputAsmVariant = 0; const unsigned OutputAsmVariant = 0;
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
@ -191,8 +192,6 @@ int AssembleOneInput(const uint8_t *Data, size_t Size) {
} }
const char *ProgName = "llvm-mc-fuzzer"; const char *ProgName = "llvm-mc-fuzzer";
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
std::unique_ptr<MCCodeEmitter> CE = nullptr; std::unique_ptr<MCCodeEmitter> CE = nullptr;
std::unique_ptr<MCAsmBackend> MAB = nullptr; std::unique_ptr<MCAsmBackend> MAB = nullptr;

View File

@ -379,11 +379,25 @@ int main(int argc, char **argv) {
} }
MAI->setPreserveAsmComments(PreserveComments); 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<MCSubtargetInfo> 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 // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
// MCObjectFileInfo needs a MCContext reference in order to initialize itself. // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
MCObjectFileInfo MOFI; MCObjectFileInfo MOFI;
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions); MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr,
MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel); &MCOptions);
MOFI.initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
if (SaveTempLabels) if (SaveTempLabels)
Ctx.setAllowTemporaryLabels(false); Ctx.setAllowTemporaryLabels(false);
@ -443,15 +457,6 @@ int main(int argc, char **argv) {
if (GenDwarfForAssembly) if (GenDwarfForAssembly)
Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer()); 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::OpenFlags Flags = (FileType == OFT_AssemblyFile)
? sys::fs::OF_TextWithCRLF ? sys::fs::OF_TextWithCRLF
: sys::fs::OF_None; : sys::fs::OF_None;
@ -477,10 +482,6 @@ int main(int argc, char **argv) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
assert(MCII && "Unable to create instruction info!"); assert(MCII && "Unable to create instruction info!");
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
assert(STI && "Unable to create subtarget info!");
MCInstPrinter *IP = nullptr; MCInstPrinter *IP = nullptr;
if (FileType == OFT_AssemblyFile) { if (FileType == OFT_AssemblyFile) {
IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant, IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,

View File

@ -377,9 +377,9 @@ int main(int argc, char **argv) {
// Tell SrcMgr about this buffer, which is what the parser will pick up. // Tell SrcMgr about this buffer, which is what the parser will pick up.
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); 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<buffer_ostream> BOS; std::unique_ptr<buffer_ostream> BOS;

View File

@ -123,31 +123,32 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray, StringRef &Str,
return false; 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, MCSubtargetInfo &STI, MCStreamer &Streamer,
MemoryBuffer &Buffer, SourceMgr &SM, MemoryBuffer &Buffer, SourceMgr &SM,
raw_ostream &Out) { raw_ostream &Out) {
std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple)); std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(TripleName));
if (!MRI) { if (!MRI) {
errs() << "error: no register info for target " << Triple << "\n"; errs() << "error: no register info for target " << TripleName << "\n";
return -1; return -1;
} }
MCTargetOptions MCOptions; MCTargetOptions MCOptions;
std::unique_ptr<const MCAsmInfo> MAI( std::unique_ptr<const MCAsmInfo> MAI(
T.createMCAsmInfo(*MRI, Triple, MCOptions)); T.createMCAsmInfo(*MRI, TripleName, MCOptions));
if (!MAI) { if (!MAI) {
errs() << "error: no assembly info for target " << Triple << "\n"; errs() << "error: no assembly info for target " << TripleName << "\n";
return -1; return -1;
} }
// Set up the MCContext for creating symbols and MCExpr's. // 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<const MCDisassembler> DisAsm( std::unique_ptr<const MCDisassembler> DisAsm(
T.createMCDisassembler(STI, Ctx)); T.createMCDisassembler(STI, Ctx));
if (!DisAsm) { if (!DisAsm) {
errs() << "error: no disassembler for target " << Triple << "\n"; errs() << "error: no disassembler for target " << TripleName << "\n";
return -1; return -1;
} }

View File

@ -275,11 +275,15 @@ int main(int Argc, char **Argv) {
MAI->setPreserveAsmComments(InputArgs.hasArg(OPT_preserve_comments)); MAI->setPreserveAsmComments(InputArgs.hasArg(OPT_preserve_comments));
std::unique_ptr<MCSubtargetInfo> 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 // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
// MCObjectFileInfo needs a MCContext reference in order to initialize itself. // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
MCObjectFileInfo MOFI; MCObjectFileInfo MOFI;
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,
/*LargeCodeModel=*/true); /*LargeCodeModel=*/true);
if (InputArgs.hasArg(OPT_save_temp_labels)) if (InputArgs.hasArg(OPT_save_temp_labels))
@ -312,10 +316,6 @@ int main(int Argc, char **Argv) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
assert(MCII && "Unable to create instruction info!"); assert(MCII && "Unable to create instruction info!");
std::unique_ptr<MCSubtargetInfo> STI(TheTarget->createMCSubtargetInfo(
TripleName, /*CPU=*/"", /*Features=*/""));
assert(STI && "Unable to create subtarget info!");
MCInstPrinter *IP = nullptr; MCInstPrinter *IP = nullptr;
if (FileType == "s") { if (FileType == "s") {
const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm); const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm);

View File

@ -7228,7 +7228,8 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
std::unique_ptr<const MCSubtargetInfo> STI( std::unique_ptr<const MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MachOMCPU, FeaturesStr)); TheTarget->createMCSubtargetInfo(TripleName, MachOMCPU, FeaturesStr));
CHECK_TARGET_INFO_CREATION(STI); 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<MCDisassembler> DisAsm( std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx)); TheTarget->createMCDisassembler(*STI, Ctx));
CHECK_TARGET_INFO_CREATION(DisAsm); CHECK_TARGET_INFO_CREATION(DisAsm);
@ -7278,7 +7279,9 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MachOMCPU, ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MachOMCPU,
FeaturesStr)); FeaturesStr));
CHECK_THUMB_TARGET_INFO_CREATION(ThumbSTI); 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)); ThumbDisAsm.reset(ThumbTarget->createMCDisassembler(*ThumbSTI, *ThumbCtx));
CHECK_THUMB_TARGET_INFO_CREATION(ThumbDisAsm); CHECK_THUMB_TARGET_INFO_CREATION(ThumbDisAsm);
MCContext *PtrThumbCtx = ThumbCtx.get(); MCContext *PtrThumbCtx = ThumbCtx.get();

View File

@ -1577,9 +1577,9 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
reportError(Obj->getFileName(), reportError(Obj->getFileName(),
"no instruction info for target " + TripleName); "no instruction info for target " + TripleName);
MCObjectFileInfo MOFI; 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 // FIXME: for now initialize MCObjectFileInfo with default values
MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx); MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false);
std::unique_ptr<MCDisassembler> DisAsm( std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx)); TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -333,8 +333,8 @@ void ProfiledBinary::setUpDisassembler(const ELFObjectFileBase *Obj) {
exitWithError("no instruction info for target " + TripleName, FileName); exitWithError("no instruction info for target " + TripleName, FileName);
MCObjectFileInfo MOFI; MCObjectFileInfo MOFI;
MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI); MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get());
MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx); MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false);
DisAsm.reset(TheTarget->createMCDisassembler(*STI, Ctx)); DisAsm.reset(TheTarget->createMCDisassembler(*STI, Ctx));
if (!DisAsm) if (!DisAsm)
exitWithError("no disassembler for target " + TripleName, FileName); exitWithError("no disassembler for target " + TripleName, FileName);

View File

@ -757,7 +757,8 @@ static int linkAndVerify() {
if (!MAI) if (!MAI)
ErrorAndExit("Unable to create target asm info!"); 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<MCDisassembler> Disassembler( std::unique_ptr<MCDisassembler> Disassembler(
TheTarget->createMCDisassembler(*STI, Ctx)); TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -727,7 +727,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
failIfEmpty(AsmInfo, "no asm info for target " + TripleName); failIfEmpty(AsmInfo, "no asm info for target " + TripleName);
std::unique_ptr<const MCObjectFileInfo> MOFI(new MCObjectFileInfo); std::unique_ptr<const MCObjectFileInfo> 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<MCDisassembler> DisAsm( std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx)); TheTarget->createMCDisassembler(*STI, Ctx));
failIfEmpty(DisAsm, "no disassembler info for target " + TripleName); failIfEmpty(DisAsm, "no disassembler info for target " + TripleName);

View File

@ -6,8 +6,9 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/ADT/Triple.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h"
@ -33,8 +34,10 @@ namespace {
#include "MFCommon.inc" #include "MFCommon.inc"
std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) { std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) {
return std::make_unique<MCContext>( Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"",
AsmInfo, nullptr, nullptr, nullptr, nullptr, false); /*EnvironmentStr=*/"elf");
return std::make_unique<MCContext>(TheTriple, AsmInfo, nullptr, nullptr,
nullptr, nullptr, nullptr, false);
} }
// This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly

View File

@ -318,7 +318,8 @@ TEST(MachineOperandTest, PrintMetadata) {
TEST(MachineOperandTest, PrintMCSymbol) { TEST(MachineOperandTest, PrintMCSymbol) {
MCAsmInfo MAI; 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"); MCSymbol *Sym = Ctx.getOrCreateSymbol("foo");
// Create a MachineOperand with a metadata and print it. // Create a MachineOperand with a metadata and print it.

View File

@ -55,8 +55,9 @@ llvm::Error TestAsmPrinter::init(const Target *TheTarget, StringRef TripleName,
return make_error<StringError>("no target machine for target " + TripleName, return make_error<StringError>("no target machine for target " + TripleName,
inconvertibleErrorCode()); inconvertibleErrorCode());
MC.reset(new MCContext(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), Triple TheTriple(TripleName);
TM->getObjFileLowering())); MC.reset(new MCContext(TheTriple, TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
TM->getObjFileLowering(), TM->getMCSubtargetInfo()));
TM->getObjFileLowering()->Initialize(*MC, *TM); TM->getObjFileLowering()->Initialize(*MC, *TM);
MS = new StrictMock<MockMCStreamer>(MC.get()); MS = new StrictMock<MockMCStreamer>(MC.get());

View File

@ -465,7 +465,7 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
inconvertibleErrorCode()); inconvertibleErrorCode());
TLOF = TM->getObjFileLowering(); 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); TLOF->Initialize(*MC, *TM);
MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC); MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC);

View File

@ -21,7 +21,7 @@ using namespace llvm;
namespace { namespace {
struct Context { struct Context {
const char *Triple = "x86_64-pc-linux"; const char *TripleName = "x86_64-pc-linux";
std::unique_ptr<MCRegisterInfo> MRI; std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MCAsmInfo> MAI; std::unique_ptr<MCAsmInfo> MAI;
std::unique_ptr<MCContext> Ctx; std::unique_ptr<MCContext> Ctx;
@ -33,14 +33,15 @@ struct Context {
// If we didn't build x86, do not run the test. // If we didn't build x86, do not run the test.
std::string Error; std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error); const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
if (!TheTarget) if (!TheTarget)
return; return;
MRI.reset(TheTarget->createMCRegInfo(Triple)); MRI.reset(TheTarget->createMCRegInfo(TripleName));
MCTargetOptions MCOptions; MCTargetOptions MCOptions;
MAI.reset(TheTarget->createMCAsmInfo(*MRI, Triple, MCOptions)); MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
Ctx = std::make_unique<MCContext>(MAI.get(), MRI.get(), nullptr); Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(), MRI.get(),
/*MOFI=*/nullptr, /*MSTI=*/nullptr);
} }
operator bool() { return Ctx.get(); } operator bool() { return Ctx.get(); }

View File

@ -112,9 +112,9 @@ protected:
SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
EXPECT_EQ(Buffer, nullptr); EXPECT_EQ(Buffer, nullptr);
Ctx.reset( Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), &MOFI, STI.get(),
new MCContext(MUPMAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions)); &SrcMgr, &MCOptions));
MOFI.InitMCObjectFileInfo(Triple, false, *Ctx, false); MOFI.initMCObjectFileInfo(*Ctx, /*PIC=*/false, /*LargeCodeModel=*/false);
Str.reset(TheTarget->createNullStreamer(*Ctx)); Str.reset(TheTarget->createNullStreamer(*Ctx));