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

[MC] Refactor MCObjectFileInfo initialization and allow targets to create MCObjectFileInfo

This makes it possible for targets to define their own MCObjectFileInfo.
This MCObjectFileInfo is then used to determine things like section alignment.

This is a follow up to D101462 and prepares for the RISCV backend defining the
text section alignment depending on the enabled extensions.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D101921
This commit is contained in:
Philipp Krones 2021-05-23 14:15:23 -07:00 committed by Fangrui Song
parent 130d03950d
commit df7a8b162e
31 changed files with 149 additions and 80 deletions

View File

@ -393,8 +393,7 @@ namespace llvm {
public:
explicit MCContext(const Triple &TheTriple, const MCAsmInfo *MAI,
const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI,
const MCSubtargetInfo *MSTI,
const MCRegisterInfo *MRI, const MCSubtargetInfo *MSTI,
const SourceMgr *Mgr = nullptr,
MCTargetOptions const *TargetOpts = nullptr,
bool DoAutoReset = true);
@ -416,6 +415,8 @@ namespace llvm {
this->DiagHandler = DiagHandler;
}
void setObjectFileInfo(const MCObjectFileInfo *Mofi) { MOFI = Mofi; }
const MCAsmInfo *getAsmInfo() const { return MAI; }
const MCRegisterInfo *getRegisterInfo() const { return MRI; }

View File

@ -23,6 +23,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
@ -130,6 +131,9 @@ public:
using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
const Triple &TT,
const MCTargetOptions &Options);
using MCObjectFileInfoCtorFnTy = MCObjectFileInfo *(*)(MCContext &Ctx,
bool PIC,
bool LargeCodeModel);
using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
@ -227,6 +231,9 @@ private:
/// registered.
MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
/// Constructor function for this target's MCObjectFileInfo, if registered.
MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
/// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
/// if registered.
MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
@ -350,6 +357,19 @@ public:
return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
}
/// Create a MCObjectFileInfo implementation for the specified target
/// triple.
///
MCObjectFileInfo *createMCObjectFileInfo(MCContext &Ctx, bool PIC,
bool LargeCodeModel = false) const {
if (!MCObjectFileInfoCtorFn) {
MCObjectFileInfo *MOFI = new MCObjectFileInfo();
MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
return MOFI;
}
return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
}
/// createMCInstrInfo - Create a MCInstrInfo implementation.
///
MCInstrInfo *createMCInstrInfo() const {
@ -724,6 +744,19 @@ struct TargetRegistry {
T.MCAsmInfoCtorFn = Fn;
}
/// Register a MCObjectFileInfo implementation for the given target.
///
/// Clients are responsible for ensuring that registration doesn't occur
/// while another thread is attempting to access the registry. Typically
/// this is done by initializing all targets at program startup.
///
/// @param T - The target being registered.
/// @param Fn - A function to construct a MCObjectFileInfo for the target.
static void RegisterMCObjectFileInfo(Target &T,
Target::MCObjectFileInfoCtorFnTy Fn) {
T.MCObjectFileInfoCtorFn = Fn;
}
/// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
/// given target.
///
@ -991,6 +1024,39 @@ struct RegisterMCAsmInfoFn {
}
};
/// Helper template for registering a target object file info implementation.
/// This invokes the static "Create" method on the class to actually do the
/// construction. Usage:
///
/// extern "C" void LLVMInitializeFooTarget() {
/// extern Target TheFooTarget;
/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
/// }
template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
RegisterMCObjectFileInfo(Target &T) {
TargetRegistry::RegisterMCObjectFileInfo(T, &Allocator);
}
private:
static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
bool LargeCodeModel = false) {
return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
}
};
/// Helper template for registering a target object file info implementation.
/// This invokes the specified function to do the construction. Usage:
///
/// extern "C" void LLVMInitializeFooTarget() {
/// extern Target TheFooTarget;
/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
/// }
struct RegisterMCObjectFileInfoFn {
RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn) {
TargetRegistry::RegisterMCObjectFileInfo(T, Fn);
}
};
/// RegisterMCInstrInfo - Helper template for registering a target instruction
/// info implementation. This invokes the static "Create" method on the class
/// to actually do the construction. Usage:

View File

@ -218,9 +218,10 @@ void MachineModuleInfo::finalize() {
MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
: TM(std::move(MMI.TM)),
Context(MMI.TM.getTargetTriple(), MMI.TM.getMCAsmInfo(),
MMI.TM.getMCRegisterInfo(), MMI.TM.getObjFileLowering(),
MMI.TM.getMCSubtargetInfo(), nullptr, nullptr, false),
MMI.TM.getMCRegisterInfo(), MMI.TM.getMCSubtargetInfo(), nullptr,
nullptr, false),
MachineFunctions(std::move(MMI.MachineFunctions)) {
Context.setObjectFileInfo(MMI.TM.getObjFileLowering());
ObjFileMMI = MMI.ObjFileMMI;
CurCallSite = MMI.CurCallSite;
UsesMSVCFloatingPoint = MMI.UsesMSVCFloatingPoint;
@ -234,17 +235,19 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
: TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
TM->getMCRegisterInfo(), TM->getObjFileLowering(),
TM->getMCSubtargetInfo(), nullptr, nullptr, false) {
TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),
nullptr, nullptr, false) {
Context.setObjectFileInfo(TM->getObjFileLowering());
initialize();
}
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM,
MCContext *ExtContext)
: TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
TM->getMCRegisterInfo(), TM->getObjFileLowering(),
TM->getMCSubtargetInfo(), nullptr, nullptr, false),
TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),
nullptr, nullptr, false),
ExternalContext(ExtContext) {
Context.setObjectFileInfo(TM->getObjFileLowering());
initialize();
}

View File

@ -54,10 +54,9 @@ bool DwarfStreamer::init(Triple TheTriple) {
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);
MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get()));
MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false));
MC->setObjectFileInfo(MOFI.get());
MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions);
if (!MAB)

View File

@ -63,12 +63,12 @@ static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
}
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)
const MCRegisterInfo *mri, const MCSubtargetInfo *msti,
const SourceMgr *mgr, MCTargetOptions const *TargetOpts,
bool DoAutoReset)
: TT(TheTriple), SrcMgr(mgr), InlineSrcMgr(nullptr),
DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MOFI(mofi),
MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MSTI(msti),
Symbols(Allocator), UsedNames(Allocator),
InlineAsmUsedLabelNames(Allocator),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
AutoReset(DoAutoReset), TargetOptions(TargetOpts) {

View File

@ -74,8 +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(Triple(TT), MAI.get(), MRI.get(),
/*MOFI=*/nullptr, STI.get()));
std::unique_ptr<MCContext> Ctx(
new MCContext(Triple(TT), MAI.get(), MRI.get(), STI.get()));
if (!Ctx)
return nullptr;

View File

@ -99,10 +99,11 @@ initializeRecordStreamer(const Module &M,
if (!MCII)
return;
MCObjectFileInfo MOFI;
MCContext MCCtx(TT, MAI.get(), MRI.get(), &MOFI, STI.get());
MOFI.initMCObjectFileInfo(MCCtx, /*PIC=*/false);
MOFI.setSDKVersion(M.getSDKVersion());
MCContext MCCtx(TT, MAI.get(), MRI.get(), STI.get());
std::unique_ptr<MCObjectFileInfo> MOFI(
T->createMCObjectFileInfo(MCCtx, /*PIC=*/false));
MOFI->setSDKVersion(M.getSDKVersion());
MCCtx.setObjectFileInfo(MOFI.get());
RecordStreamer Streamer(MCCtx, M);
T->createNullTargetStreamer(Streamer);

View File

@ -408,7 +408,7 @@ Error FileAnalysis::initialiseDisassemblyMembers() {
return make_error<UnsupportedDisassembly>("Failed to initialise MII.");
Context.reset(new MCContext(Triple(TripleName), AsmInfo.get(),
RegisterInfo.get(), &MOFI, SubtargetInfo.get()));
RegisterInfo.get(), SubtargetInfo.get()));
Disassembler.reset(
ObjectTarget->createMCDisassembler(*SubtargetInfo, *Context));

View File

@ -207,7 +207,6 @@ private:
std::unique_ptr<const MCAsmInfo> AsmInfo;
std::unique_ptr<MCSubtargetInfo> SubtargetInfo;
std::unique_ptr<const MCInstrInfo> MII;
MCObjectFileInfo MOFI;
std::unique_ptr<MCContext> Context;
std::unique_ptr<const MCDisassembler> Disassembler;
std::unique_ptr<const MCInstrAnalysis> MIA;

View File

@ -880,9 +880,10 @@ int main(int argc, char **argv) {
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);
MCContext MC(*ErrOrTriple, MAI.get(), MRI.get(), MSTI.get());
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(MC, /*PIC=*/false));
MC.setObjectFileInfo(MOFI.get());
MCTargetOptions Options;
auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options);

View File

@ -176,9 +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>(
Triple(FirstPoint.LLVMTriple), AsmInfo_.get(), RegInfo_.get(),
&ObjectFileInfo_, SubtargetInfo_.get());
Context_ =
std::make_unique<MCContext>(Triple(FirstPoint.LLVMTriple), AsmInfo_.get(),
RegInfo_.get(), SubtargetInfo_.get());
Disasm_.reset(Target.createMCDisassembler(*SubtargetInfo_, *Context_));
assert(Disasm_ && "cannot create MCDisassembler. missing call to "
"InitializeXXXTargetDisassembler ?");

View File

@ -112,7 +112,6 @@ private:
const char *Separator) const;
const InstructionBenchmarkClustering &Clustering_;
MCObjectFileInfo ObjectFileInfo_;
std::unique_ptr<MCContext> Context_;
std::unique_ptr<MCSubtargetInfo> SubtargetInfo_;
std::unique_ptr<MCInstrInfo> InstrInfo_;

View File

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

View File

@ -130,13 +130,13 @@ Expected<std::vector<BenchmarkCode>> readSnippets(const LLVMState &State,
BenchmarkCode Result;
MCObjectFileInfo ObjectFileInfo;
const TargetMachine &TM = State.getTargetMachine();
MCContext Context(TM.getTargetTriple(), TM.getMCAsmInfo(),
TM.getMCRegisterInfo(), &ObjectFileInfo,
TM.getMCSubtargetInfo());
TM.getMCRegisterInfo(), TM.getMCSubtargetInfo());
std::unique_ptr<MCObjectFileInfo> ObjectFileInfo(
TM.getTarget().createMCObjectFileInfo(Context, /*PIC=*/false));
Context.setObjectFileInfo(ObjectFileInfo.get());
Context.initInlineSourceManager();
ObjectFileInfo.initMCObjectFileInfo(Context, /*PIC=*/false);
BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result);
std::string Error;

View File

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

View File

@ -173,10 +173,10 @@ int AssembleOneInput(const uint8_t *Data, size_t Size) {
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
MCObjectFileInfo MOFI;
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr);
static const bool UsePIC = false;
MOFI.initMCObjectFileInfo(Ctx, UsePIC);
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
Ctx.setObjectFileInfo(MOFI.get());
const unsigned OutputAsmVariant = 0;
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());

View File

@ -394,10 +394,11 @@ int main(int argc, char **argv) {
// 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(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr,
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
&MCOptions);
MOFI.initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel));
Ctx.setObjectFileInfo(MOFI.get());
if (SaveTempLabels)
Ctx.setAllowTemporaryLabels(false);

View File

@ -371,15 +371,15 @@ int main(int argc, char **argv) {
TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
assert(MAI && "Unable to create target asm info!");
MCObjectFileInfo MOFI;
SourceMgr SrcMgr;
// Tell SrcMgr about this buffer, which is what the parser will pick up.
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr);
MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false);
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
Ctx.setObjectFileInfo(MOFI.get());
std::unique_ptr<buffer_ostream> BOS;

View File

@ -142,8 +142,7 @@ int Disassembler::disassemble(const Target &T, const std::string &TripleName,
}
// Set up the MCContext for creating symbols and MCExpr's.
MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr,
&STI);
MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), &STI);
std::unique_ptr<const MCDisassembler> DisAsm(
T.createMCDisassembler(STI, Ctx));

View File

@ -281,10 +281,10 @@ int main(int Argc, char **Argv) {
// 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(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr);
MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false,
/*LargeCodeModel=*/true);
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
std::unique_ptr<MCObjectFileInfo> MOFI(TheTarget->createMCObjectFileInfo(
Ctx, /*PIC=*/false, /*LargeCodeModel=*/true));
Ctx.setObjectFileInfo(MOFI.get());
if (InputArgs.hasArg(OPT_save_temp_labels))
Ctx.setAllowTemporaryLabels(false);

View File

@ -7228,8 +7228,7 @@ 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(Triple(TripleName), AsmInfo.get(), MRI.get(), /*MOFI=*/nullptr,
STI.get());
MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), STI.get());
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
CHECK_TARGET_INFO_CREATION(DisAsm);
@ -7280,8 +7279,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
FeaturesStr));
CHECK_THUMB_TARGET_INFO_CREATION(ThumbSTI);
ThumbCtx.reset(new MCContext(Triple(ThumbTripleName), ThumbAsmInfo.get(),
ThumbMRI.get(), /*MOFI=*/nullptr,
ThumbSTI.get()));
ThumbMRI.get(), ThumbSTI.get()));
ThumbDisAsm.reset(ThumbTarget->createMCDisassembler(*ThumbSTI, *ThumbCtx));
CHECK_THUMB_TARGET_INFO_CREATION(ThumbDisAsm);
MCContext *PtrThumbCtx = ThumbCtx.get();

View File

@ -1581,10 +1581,11 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (!MII)
reportError(Obj->getFileName(),
"no instruction info for target " + TripleName);
MCObjectFileInfo MOFI;
MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get());
MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), STI.get());
// FIXME: for now initialize MCObjectFileInfo with default values
MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false);
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
Ctx.setObjectFileInfo(MOFI.get());
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));

View File

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

View File

@ -757,8 +757,7 @@ static int linkAndVerify() {
if (!MAI)
ErrorAndExit("Unable to create target asm info!");
MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), /*MOFI=*/nullptr,
STI.get());
MCContext Ctx(Triple(TripleName), MAI.get(), MRI.get(), STI.get());
std::unique_ptr<MCDisassembler> Disassembler(
TheTarget->createMCDisassembler(*STI, Ctx));

View File

@ -726,8 +726,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
failIfEmpty(AsmInfo, "no asm info for target " + TripleName);
std::unique_ptr<const MCObjectFileInfo> MOFI(new MCObjectFileInfo);
MCContext Ctx(TheTriple, AsmInfo.get(), MRI.get(), MOFI.get(), STI.get());
MCContext Ctx(TheTriple, AsmInfo.get(), MRI.get(), STI.get());
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
failIfEmpty(DisAsm, "no disassembler info for target " + TripleName);

View File

@ -37,7 +37,7 @@ std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) {
Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"",
/*EnvironmentStr=*/"elf");
return std::make_unique<MCContext>(TheTriple, AsmInfo, nullptr, nullptr,
nullptr, nullptr, nullptr, false);
nullptr, nullptr, false);
}
// This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly

View File

@ -319,7 +319,7 @@ TEST(MachineOperandTest, PrintMetadata) {
TEST(MachineOperandTest, PrintMCSymbol) {
MCAsmInfo MAI;
Triple T = Triple("unknown-unknown-unknown");
MCContext Ctx(T, &MAI, /*MRI=*/nullptr, /*MOFI=*/nullptr, /*MSTI=*/nullptr);
MCContext Ctx(T, &MAI, /*MRI=*/nullptr, /*MSTI=*/nullptr);
MCSymbol *Sym = Ctx.getOrCreateSymbol("foo");
// Create a MachineOperand with a metadata and print it.

View File

@ -57,8 +57,9 @@ llvm::Error TestAsmPrinter::init(const Target *TheTarget, StringRef TripleName,
Triple TheTriple(TripleName);
MC.reset(new MCContext(TheTriple, TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
TM->getObjFileLowering(), TM->getMCSubtargetInfo()));
TM->getMCSubtargetInfo()));
TM->getObjFileLowering()->Initialize(*MC, *TM);
MC->setObjectFileInfo(TM->getObjFileLowering());
MS = new StrictMock<MockMCStreamer>(MC.get());

View File

@ -464,9 +464,10 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
return make_error<StringError>("no target machine for target " + TripleName,
inconvertibleErrorCode());
MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get()));
TLOF = TM->getObjFileLowering();
MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), TLOF, MSTI.get()));
TLOF->Initialize(*MC, *TM);
MC->setObjectFileInfo(TLOF);
MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC);
if (!MCE)

View File

@ -41,7 +41,7 @@ struct Context {
MCTargetOptions MCOptions;
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(), MRI.get(),
/*MOFI=*/nullptr, /*MSTI=*/nullptr);
/*MSTI=*/nullptr);
}
operator bool() { return Ctx.get(); }

View File

@ -62,6 +62,7 @@ protected:
std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MockedUpMCAsmInfo> MUPMAI;
std::unique_ptr<const MCInstrInfo> MII;
std::unique_ptr<MCObjectFileInfo> MOFI;
std::unique_ptr<MCStreamer> Str;
std::unique_ptr<MCAsmParser> Parser;
std::unique_ptr<MCContext> Ctx;
@ -74,7 +75,6 @@ protected:
const Target *TheTarget;
const MCTargetOptions MCOptions;
MCObjectFileInfo MOFI;
SystemZAsmLexerTest() {
// We will use the SystemZ triple, because of missing
@ -112,9 +112,11 @@ protected:
SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
EXPECT_EQ(Buffer, nullptr);
Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), &MOFI, STI.get(),
&SrcMgr, &MCOptions));
MOFI.initMCObjectFileInfo(*Ctx, /*PIC=*/false, /*LargeCodeModel=*/false);
Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), STI.get(), &SrcMgr,
&MCOptions));
MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false,
/*LargeCodeModel=*/false));
Ctx->setObjectFileInfo(MOFI.get());
Str.reset(TheTarget->createNullStreamer(*Ctx));