1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +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 =
std::function<void(const SMDiagnostic &, bool, const SourceMgr &,
std::vector<const MDNode *> &)>;
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 @@ namespace llvm {
/// The MCObjectFileInfo for this target.
const MCObjectFileInfo *MOFI;
/// The MCSubtargetInfo for this target.
const MCSubtargetInfo *MSTI;
std::unique_ptr<CodeViewContext> CVContext;
/// Allocator object used for creating machine code objects.
@ -383,8 +392,9 @@ namespace llvm {
DenseSet<StringRef> 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 @@ namespace llvm {
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 @@ namespace llvm {
const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
const MCSubtargetInfo *getSubtargetInfo() const { return MSTI; }
CodeViewContext &getCVContext();
void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }

View File

@ -227,7 +227,7 @@ protected:
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 @@ public:
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 @@ private:
MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
public:
const Triple &getTargetTriple() const { return TT; }
void setSDKVersion(const VersionTuple &TheSDKVersion) {
SDKVersion = TheSDKVersion;
}

View File

@ -217,8 +217,9 @@ void MachineModuleInfo::finalize() {
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(MachineModuleInfo &&MMI)
}
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();
}

View File

@ -1645,7 +1645,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
// 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 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
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 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
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 @@ static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
unsigned Priority, const MCSymbol *KeySym) const {
return getCOFFStaticStructorSection(getContext(), getTargetTriple(), true,
Priority, KeySym,
cast<MCSectionCOFF>(StaticCtorSection));
return getCOFFStaticStructorSection(
getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
cast<MCSectionCOFF>(StaticCtorSection));
}
MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
unsigned Priority, const MCSymbol *KeySym) const {
return getCOFFStaticStructorSection(getContext(), getTargetTriple(), false,
Priority, KeySym,
cast<MCSectionCOFF>(StaticDtorSection));
return getCOFFStaticStructorSection(
getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
cast<MCSectionCOFF>(StaticDtorSection));
}
const MCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference(

View File

@ -50,14 +50,15 @@ bool DwarfStreamer::init(Triple TheTriple) {
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 @@ void DwarfStreamer::emitPaperTrailWarningsDie(DIE &Die) {
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);
}

View File

@ -484,9 +484,8 @@ void MCAsmStreamer::changeSection(MCSection *Section,
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);
}
}

View File

@ -62,11 +62,13 @@ static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
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 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
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 *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
"MCSymbol classes must be trivially destructible");
static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
"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);

View File

@ -74,7 +74,8 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
return nullptr;
// 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)
return nullptr;

View File

@ -515,7 +515,7 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
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);

View File

@ -959,11 +959,10 @@ void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
/* 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 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
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::getDwarfComdatSection(const char *Name,
MCSection *
MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
if (Env != IsELF)
if (Ctx->getObjectFileType() != MCContext::IsELF)
return StackSizesSection;
const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
@ -1059,7 +1042,7 @@ MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
MCSection *
MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
if (Env != IsELF)
if (Ctx->getObjectFileType() != MCContext::IsELF)
return nullptr;
const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
@ -1079,7 +1062,7 @@ MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
MCSection *
MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const {
if (Env == IsELF) {
if (Ctx->getObjectFileType() == MCContext::IsELF) {
const auto *ElfSec = static_cast<const MCSectionELF *>(TextSec);
// Create a separate section for probes that comes with a comdat function.
if (const MCSymbol *Group = ElfSec->getGroup()) {
@ -1095,7 +1078,7 @@ MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const {
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 @@ MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
// 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<MCSectionELF *>(PseudoProbeDescSection);
auto Flags = S->getFlags() | ELF::SHF_GROUP;
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);
// 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;

View File

@ -403,7 +403,7 @@ bool COFFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
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;
}

View File

@ -695,7 +695,7 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
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 @@ bool DarwinAsmParser::parseSDKVersion(VersionTuple &SDKVersion) {
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) +

View File

@ -1029,8 +1029,8 @@ MasmParser::MasmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
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:

View File

@ -57,10 +57,9 @@ void MCTargetStreamer::changeSection(const MCSection *CurSection,
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) {

View File

@ -181,8 +181,7 @@ void MCWinCOFFStreamer::EndCOFFSymbolDef() {
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<MCSymbolCOFF>(Symbol);
@ -266,7 +265,7 @@ void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
auto *Symbol = cast<MCSymbolCOFF>(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");

View File

@ -100,8 +100,8 @@ initializeRecordStreamer(const Module &M,
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);

View File

@ -5267,10 +5267,9 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
/// 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();

View File

@ -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 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
}
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 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
}
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 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
/// 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 @@ void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
/// ::= .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

View File

@ -94,7 +94,8 @@ void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
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;

View File

@ -44,7 +44,7 @@ void TargetLoweringObjectFile::Initialize(MCContext &ctx,
// `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.

View File

@ -407,7 +407,8 @@ Error FileAnalysis::initialiseDisassemblyMembers() {
if (!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(
ObjectTarget->createMCDisassembler(*SubtargetInfo, *Context));

View File

@ -875,15 +875,15 @@ int main(int argc, char **argv) {
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<MCSubtargetInfo> 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)

View File

@ -176,8 +176,9 @@ Analysis::Analysis(const Target &Target, std::unique_ptr<MCInstrInfo> InstrInfo,
Triple(FirstPoint.LLVMTriple), 0 /*default variant*/, *AsmInfo_,
*InstrInfo_, *RegInfo_));
Context_ = std::make_unique<MCContext>(AsmInfo_.get(), RegInfo_.get(),
&ObjectFileInfo_);
Context_ = std::make_unique<MCContext>(
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 ?");

View File

@ -62,8 +62,10 @@ std::unique_ptr<LLVMTargetMachine> LLVMState::createTargetMachine() const {
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<const MCCodeEmitter> CodeEmitter(
TheTargetMachine->getTarget().createMCCodeEmitter(
*TheTargetMachine->getMCInstrInfo(), *TheTargetMachine->getMCRegisterInfo(),

View File

@ -132,10 +132,11 @@ Expected<std::vector<BenchmarkCode>> readSnippets(const LLVMState &State,
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;

View File

@ -1256,7 +1256,8 @@ static Error runChecks(Session &S) {
TripleName,
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(
TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -170,12 +170,13 @@ int AssembleOneInput(const uint8_t *Data, size_t Size) {
abort();
}
std::unique_ptr<MCSubtargetInfo> 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<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
@ -191,8 +192,6 @@ int AssembleOneInput(const uint8_t *Data, size_t Size) {
}
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<MCAsmBackend> MAB = nullptr;

View File

@ -379,11 +379,25 @@ int main(int argc, char **argv) {
}
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
// 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 @@ int main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
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;
if (FileType == OFT_AssemblyFile) {
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.
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;

View File

@ -123,31 +123,32 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray, StringRef &Str,
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<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple));
std::unique_ptr<const MCRegisterInfo> 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<const MCAsmInfo> 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<const MCDisassembler> 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;
}

View File

@ -275,11 +275,15 @@ int main(int Argc, char **Argv) {
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
// 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 @@ int main(int Argc, char **Argv) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
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;
if (FileType == "s") {
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(
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<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
CHECK_TARGET_INFO_CREATION(DisAsm);
@ -7278,7 +7279,9 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
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();

View File

@ -1577,9 +1577,9 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
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<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -333,8 +333,8 @@ void ProfiledBinary::setUpDisassembler(const ELFObjectFileBase *Obj) {
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);

View File

@ -757,7 +757,8 @@ static int linkAndVerify() {
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<MCDisassembler> Disassembler(
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);
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(
TheTarget->createMCDisassembler(*STI, Ctx));
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/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 @@ namespace {
#include "MFCommon.inc"
std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) {
return std::make_unique<MCContext>(
AsmInfo, nullptr, nullptr, nullptr, nullptr, false);
Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"",
/*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

View File

@ -318,7 +318,8 @@ TEST(MachineOperandTest, PrintMetadata) {
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.

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,
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<MockMCStreamer>(MC.get());

View File

@ -465,7 +465,7 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
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);

View File

@ -21,7 +21,7 @@ using namespace llvm;
namespace {
struct Context {
const char *Triple = "x86_64-pc-linux";
const char *TripleName = "x86_64-pc-linux";
std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MCAsmInfo> MAI;
std::unique_ptr<MCContext> Ctx;
@ -33,14 +33,15 @@ struct Context {
// 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<MCContext>(MAI.get(), MRI.get(), nullptr);
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(), MRI.get(),
/*MOFI=*/nullptr, /*MSTI=*/nullptr);
}
operator bool() { return Ctx.get(); }

View File

@ -112,9 +112,9 @@ protected:
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));