From 02d330548d07cfbbb7cd496c94a514802527dfeb Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 11 Oct 2017 01:57:21 +0000 Subject: [PATCH] [MC] Have MCObjectStreamer take its MCAsmBackend argument via unique_ptr. MCObjectStreamer owns its MCAsmBackend -- this fixes the types to reflect that, and allows us to remove another instance of MCObjectStreamer's weird "holding ownership via someone else's reference" trick. llvm-svn: 315410 --- llvm/include/llvm/MC/MCELFStreamer.h | 8 +-- llvm/include/llvm/MC/MCObjectStreamer.h | 5 +- llvm/include/llvm/MC/MCWasmStreamer.h | 7 +-- llvm/include/llvm/MC/MCWinCOFFStreamer.h | 4 +- llvm/include/llvm/Support/TargetRegistry.h | 54 +++++++++---------- llvm/lib/CodeGen/LLVMTargetMachine.cpp | 7 ++- llvm/lib/MC/MCELFStreamer.cpp | 10 +++- llvm/lib/MC/MCMachOStreamer.cpp | 15 +++--- llvm/lib/MC/MCObjectStreamer.cpp | 10 ++-- llvm/lib/MC/MCWasmStreamer.cpp | 5 +- llvm/lib/MC/MCWinCOFFStreamer.cpp | 5 +- .../MCTargetDesc/AArch64ELFStreamer.cpp | 12 +++-- .../AArch64/MCTargetDesc/AArch64ELFStreamer.h | 3 +- .../MCTargetDesc/AArch64MCTargetDesc.cpp | 17 +++--- .../MCTargetDesc/AArch64WinCOFFStreamer.cpp | 18 +++---- .../MCTargetDesc/AArch64WinCOFFStreamer.h | 11 ++-- .../AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp | 16 +++--- .../AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h | 8 +-- .../MCTargetDesc/AMDGPUMCTargetDesc.cpp | 7 ++- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 26 ++++----- .../ARM/MCTargetDesc/ARMMCTargetDesc.cpp | 16 +++--- .../Target/ARM/MCTargetDesc/ARMMCTargetDesc.h | 3 +- .../ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp | 18 ++++--- .../BPF/MCTargetDesc/BPFMCTargetDesc.cpp | 10 ++-- .../MCTargetDesc/HexagonMCELFStreamer.cpp | 24 +++++++-- .../MCTargetDesc/HexagonMCELFStreamer.h | 17 +++--- .../MCTargetDesc/HexagonMCTargetDesc.cpp | 11 ++-- .../Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp | 5 +- .../Mips/MCTargetDesc/MipsELFStreamer.cpp | 14 ++++- .../Mips/MCTargetDesc/MipsELFStreamer.h | 12 ++--- .../lib/Target/Mips/MCTargetDesc/MipsMCNaCl.h | 3 +- .../Mips/MCTargetDesc/MipsMCTargetDesc.cpp | 8 +-- .../Mips/MCTargetDesc/MipsNaClELFStreamer.cpp | 11 ++-- .../Target/X86/MCTargetDesc/X86MCTargetDesc.h | 6 ++- .../X86/MCTargetDesc/X86WinCOFFStreamer.cpp | 12 +++-- llvm/tools/dsymutil/DwarfLinker.cpp | 4 +- llvm/tools/llvm-dwp/llvm-dwp.cpp | 5 +- llvm/tools/llvm-mc/llvm-mc.cpp | 4 +- .../DebugInfo/DWARF/DwarfGenerator.cpp | 4 +- 39 files changed, 251 insertions(+), 184 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 90434f34da5f..7c922ef29478 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -23,9 +23,8 @@ class MCInst; class MCELFStreamer : public MCObjectStreamer { public: - MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, TAB, OS, Emitter) {} + MCELFStreamer(MCContext &Context, std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter); ~MCELFStreamer() override = default; @@ -90,7 +89,8 @@ private: SmallVector BundleGroups; }; -MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createARMELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IsThumb); diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index f194f03eb7f9..89ab726a47ec 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -35,6 +35,7 @@ class raw_pwrite_stream; /// implementation. class MCObjectStreamer : public MCStreamer { std::unique_ptr ObjectWriter; + std::unique_ptr TAB; std::unique_ptr Assembler; MCSection::iterator CurInsertionPoint; bool EmitEHFrame; @@ -47,8 +48,8 @@ class MCObjectStreamer : public MCStreamer { MCSymbol *EmitCFILabel() override; protected: - MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter); + MCObjectStreamer(MCContext &Context, std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter); ~MCObjectStreamer() override; public: diff --git a/llvm/include/llvm/MC/MCWasmStreamer.h b/llvm/include/llvm/MC/MCWasmStreamer.h index bdd6f103cd44..2a373358d02d 100644 --- a/llvm/include/llvm/MC/MCWasmStreamer.h +++ b/llvm/include/llvm/MC/MCWasmStreamer.h @@ -26,9 +26,10 @@ class raw_ostream; class MCWasmStreamer : public MCObjectStreamer { public: - MCWasmStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, TAB, OS, Emitter), SeenIdent(false) {} + MCWasmStreamer(MCContext &Context, std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter) + : MCObjectStreamer(Context, std::move(TAB), OS, Emitter), + SeenIdent(false) {} ~MCWasmStreamer() override; diff --git a/llvm/include/llvm/MC/MCWinCOFFStreamer.h b/llvm/include/llvm/MC/MCWinCOFFStreamer.h index 3ab4d3450547..cf770a9a0b2c 100644 --- a/llvm/include/llvm/MC/MCWinCOFFStreamer.h +++ b/llvm/include/llvm/MC/MCWinCOFFStreamer.h @@ -27,8 +27,8 @@ class raw_pwrite_stream; class MCWinCOFFStreamer : public MCObjectStreamer { public: - MCWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, MCCodeEmitter &CE, - raw_pwrite_stream &OS); + MCWinCOFFStreamer(MCContext &Context, std::unique_ptr MAB, + MCCodeEmitter &CE, raw_pwrite_stream &OS); /// state management void reset() override { diff --git a/llvm/include/llvm/Support/TargetRegistry.h b/llvm/include/llvm/Support/TargetRegistry.h index 9106e0856b11..07b36be1325d 100644 --- a/llvm/include/llvm/Support/TargetRegistry.h +++ b/llvm/include/llvm/Support/TargetRegistry.h @@ -67,14 +67,17 @@ MCStreamer *createAsmStreamer(MCContext &Ctx, MCAsmBackend *TAB, bool ShowInst); /// Takes ownership of \p TAB and \p CE. -MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, +MCStreamer *createELFStreamer(MCContext &Ctx, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll); -MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, +MCStreamer *createMachOStreamer(MCContext &Ctx, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections = false); -MCStreamer *createWasmStreamer(MCContext &Ctx, MCAsmBackend &TAB, +MCStreamer *createWasmStreamer(MCContext &Ctx, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll); @@ -135,25 +138,21 @@ public: const MCRegisterInfo &MRI, MCContext &Ctx); using ELFStreamerCtorTy = MCStreamer *(*)(const Triple &T, MCContext &Ctx, - MCAsmBackend &TAB, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); - using MachOStreamerCtorTy = MCStreamer *(*)(MCContext &Ctx, MCAsmBackend &TAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, - bool RelaxAll, - bool DWARFMustBeAtTheEnd); - using COFFStreamerCtorTy = MCStreamer *(*)(MCContext &Ctx, MCAsmBackend &TAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, - bool RelaxAll, - bool IncrementalLinkerCompatible); - using WasmStreamerCtorTy = MCStreamer *(*)(const Triple &T, MCContext &Ctx, - MCAsmBackend &TAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, - bool RelaxAll); + using MachOStreamerCtorTy = + MCStreamer *(*)(MCContext &Ctx, std::unique_ptr &&TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, + bool RelaxAll, bool DWARFMustBeAtTheEnd); + using COFFStreamerCtorTy = + MCStreamer *(*)(MCContext &Ctx, std::unique_ptr &&TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, + bool RelaxAll, bool IncrementalLinkerCompatible); + using WasmStreamerCtorTy = MCStreamer + *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr &&TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); using NullTargetStreamerCtorTy = MCTargetStreamer *(*)(MCStreamer &S); using AsmTargetStreamerCtorTy = MCTargetStreamer *(*)( MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, @@ -435,7 +434,8 @@ public: /// \param Emitter The target independent assembler object.Takes ownership. /// \param RelaxAll Relax all fixups? MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx, - MCAsmBackend &TAB, raw_pwrite_stream &OS, + std::unique_ptr &&TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, const MCSubtargetInfo &STI, bool RelaxAll, bool IncrementalLinkerCompatible, @@ -446,28 +446,28 @@ public: llvm_unreachable("Unknown object format"); case Triple::COFF: assert(T.isOSWindows() && "only Windows COFF is supported"); - S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll, + S = COFFStreamerCtorFn(Ctx, std::move(TAB), OS, Emitter, RelaxAll, IncrementalLinkerCompatible); break; case Triple::MachO: if (MachOStreamerCtorFn) - S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll, + S = MachOStreamerCtorFn(Ctx, std::move(TAB), OS, Emitter, RelaxAll, DWARFMustBeAtTheEnd); else - S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll, + S = createMachOStreamer(Ctx, std::move(TAB), OS, Emitter, RelaxAll, DWARFMustBeAtTheEnd); break; case Triple::ELF: if (ELFStreamerCtorFn) - S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll); + S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), OS, Emitter, RelaxAll); else - S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll); + S = createELFStreamer(Ctx, std::move(TAB), OS, Emitter, RelaxAll); break; case Triple::Wasm: if (WasmStreamerCtorFn) - S = WasmStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll); + S = WasmStreamerCtorFn(T, Ctx, std::move(TAB), OS, Emitter, RelaxAll); else - S = createWasmStreamer(Ctx, TAB, OS, Emitter, RelaxAll); + S = createWasmStreamer(Ctx, std::move(TAB), OS, Emitter, RelaxAll); break; } if (ObjectTargetStreamerCtorFn) diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp index 753db8522636..00db011697f1 100644 --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstrInfo.h" @@ -163,7 +164,8 @@ bool LLVMTargetMachine::addAsmPrinter(PassManagerBase &PM, Triple T(getTargetTriple().str()); AsmStreamer.reset(getTarget().createMCObjectStreamer( - T, Context, *MAB, Out, MCE, STI, Options.MCOptions.MCRelaxAll, + T, Context, std::unique_ptr(MAB), Out, MCE, STI, + Options.MCOptions.MCRelaxAll, Options.MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ true)); break; @@ -238,7 +240,8 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, const Triple &T = getTargetTriple(); const MCSubtargetInfo &STI = *getMCSubtargetInfo(); std::unique_ptr AsmStreamer(getTarget().createMCObjectStreamer( - T, *Ctx, *MAB, Out, MCE, STI, Options.MCOptions.MCRelaxAll, + T, *Ctx, std::unique_ptr(MAB), Out, MCE, STI, + Options.MCOptions.MCRelaxAll, Options.MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ true)); diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 76976cab4660..4fdbcd7511c2 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -39,6 +39,11 @@ using namespace llvm; +MCELFStreamer::MCELFStreamer(MCContext &Context, + std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter) + : MCObjectStreamer(Context, std::move(TAB), OS, Emitter) {} + bool MCELFStreamer::isBundleLocked() const { return getCurrentSectionOnly()->isBundleLocked(); } @@ -639,10 +644,11 @@ void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, llvm_unreachable("ELF doesn't support this directive"); } -MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, +MCStreamer *llvm::createELFStreamer(MCContext &Context, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll) { - MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE); + MCELFStreamer *S = new MCELFStreamer(Context, std::move(MAB), OS, CE); if (RelaxAll) S->getAssembler().setRelaxAll(true); return S; diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 674c7b9bf619..293b87d41775 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -62,10 +62,12 @@ private: void EmitDataRegionEnd(); public: - MCMachOStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, bool DWARFMustBeAtTheEnd, bool label) - : MCObjectStreamer(Context, MAB, OS, Emitter), LabelSections(label), - DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd), CreatedADWARFSection(false) {} + MCMachOStreamer(MCContext &Context, std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, + bool DWARFMustBeAtTheEnd, bool label) + : MCObjectStreamer(Context, std::move(MAB), OS, Emitter), + LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd), + CreatedADWARFSection(false) {} /// state management void reset() override { @@ -483,11 +485,12 @@ void MCMachOStreamer::FinishImpl() { this->MCObjectStreamer::FinishImpl(); } -MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB, +MCStreamer *llvm::createMachOStreamer(MCContext &Context, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections) { - MCMachOStreamer *S = new MCMachOStreamer(Context, MAB, OS, CE, + MCMachOStreamer *S = new MCMachOStreamer(Context, std::move(MAB), OS, CE, DWARFMustBeAtTheEnd, LabelSections); const Triple &TT = Context.getObjectFileInfo()->getTargetTriple(); if (TT.isOSDarwin()) { diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 46d57265d85b..ba45d24fd080 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -25,16 +25,16 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, +MCObjectStreamer::MCObjectStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter_) - : MCStreamer(Context), ObjectWriter(TAB.createObjectWriter(OS)), - Assembler(llvm::make_unique(Context, TAB, *Emitter_, - *ObjectWriter)), + : MCStreamer(Context), ObjectWriter(TAB->createObjectWriter(OS)), + TAB(std::move(TAB)), Assembler(llvm::make_unique( + Context, *this->TAB, *Emitter_, *ObjectWriter)), EmitEHFrame(true), EmitDebugFrame(false) {} MCObjectStreamer::~MCObjectStreamer() { - delete &Assembler->getBackend(); delete &Assembler->getEmitter(); } diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp index be8a5c21610f..fdf1be67e4ec 100644 --- a/llvm/lib/MC/MCWasmStreamer.cpp +++ b/llvm/lib/MC/MCWasmStreamer.cpp @@ -200,10 +200,11 @@ void MCWasmStreamer::FinishImpl() { this->MCObjectStreamer::FinishImpl(); } -MCStreamer *llvm::createWasmStreamer(MCContext &Context, MCAsmBackend &MAB, +MCStreamer *llvm::createWasmStreamer(MCContext &Context, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll) { - MCWasmStreamer *S = new MCWasmStreamer(Context, MAB, OS, CE); + MCWasmStreamer *S = new MCWasmStreamer(Context, std::move(MAB), OS, CE); if (RelaxAll) S->getAssembler().setRelaxAll(true); return S; diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp index dddafb9691c7..c78a2e17c8d1 100644 --- a/llvm/lib/MC/MCWinCOFFStreamer.cpp +++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp @@ -41,9 +41,10 @@ using namespace llvm; #define DEBUG_TYPE "WinCOFFStreamer" -MCWinCOFFStreamer::MCWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, +MCWinCOFFStreamer::MCWinCOFFStreamer(MCContext &Context, + std::unique_ptr MAB, MCCodeEmitter &CE, raw_pwrite_stream &OS) - : MCObjectStreamer(Context, MAB, OS, &CE), CurSymbol(nullptr) {} + : MCObjectStreamer(Context, std::move(MAB), OS, &CE), CurSymbol(nullptr) {} void MCWinCOFFStreamer::EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index a0de3c39562b..380d5acafb41 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -86,10 +86,10 @@ class AArch64ELFStreamer : public MCELFStreamer { public: friend class AArch64TargetELFStreamer; - AArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB, + AArch64ELFStreamer(MCContext &Context, std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter) - : MCELFStreamer(Context, TAB, OS, Emitter), MappingSymbolCounter(0), - LastEMS(EMS_None) {} + : MCELFStreamer(Context, std::move(TAB), OS, Emitter), + MappingSymbolCounter(0), LastEMS(EMS_None) {} void ChangeSection(MCSection *Section, const MCExpr *Subsection) override { // We have to keep track of the mapping symbol state of any sections we @@ -198,10 +198,12 @@ MCTargetStreamer *createAArch64AsmTargetStreamer(MCStreamer &S, return new AArch64TargetAsmStreamer(S, OS); } -MCELFStreamer *createAArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createAArch64ELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - AArch64ELFStreamer *S = new AArch64ELFStreamer(Context, TAB, OS, Emitter); + AArch64ELFStreamer *S = + new AArch64ELFStreamer(Context, std::move(TAB), OS, Emitter); if (RelaxAll) S->getAssembler().setRelaxAll(true); return S; diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.h index ef48203c8bc0..5869764a90d1 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.h @@ -18,7 +18,8 @@ namespace llvm { -MCELFStreamer *createAArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createAArch64ELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp index 8618069fb0d1..b6c0c7f01f6b 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp @@ -100,26 +100,29 @@ static MCInstPrinter *createAArch64MCInstPrinter(const Triple &T, } static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx, - MCAsmBackend &TAB, raw_pwrite_stream &OS, + std::unique_ptr &&TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - return createAArch64ELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll); + return createAArch64ELFStreamer(Ctx, std::move(TAB), OS, Emitter, RelaxAll); } -static MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, +static MCStreamer *createMachOStreamer(MCContext &Ctx, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd) { - return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll, + return createMachOStreamer(Ctx, std::move(TAB), OS, Emitter, RelaxAll, DWARFMustBeAtTheEnd, /*LabelSections*/ true); } -static MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB, +static MCStreamer *createWinCOFFStreamer(MCContext &Ctx, + std::unique_ptr &&TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IncrementalLinkerCompatible) { - return createAArch64WinCOFFStreamer(Ctx, TAB, OS, Emitter, RelaxAll, - IncrementalLinkerCompatible); + return createAArch64WinCOFFStreamer(Ctx, std::move(TAB), OS, Emitter, + RelaxAll, IncrementalLinkerCompatible); } static MCInstrAnalysis *createAArch64InstrAnalysis(const MCInstrInfo *Info) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.cpp index 6c8da27e398f..f1ab9ffbe842 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.cpp @@ -17,19 +17,19 @@ class AArch64WinCOFFStreamer : public MCWinCOFFStreamer { public: friend class AArch64TargetWinCOFFStreamer; - AArch64WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, MCCodeEmitter &CE, - raw_pwrite_stream &OS) - : MCWinCOFFStreamer(C, AB, CE, OS) {} + AArch64WinCOFFStreamer(MCContext &C, std::unique_ptr AB, + MCCodeEmitter &CE, raw_pwrite_stream &OS) + : MCWinCOFFStreamer(C, std::move(AB), CE, OS) {} }; } // end anonymous namespace namespace llvm { -MCWinCOFFStreamer -*createAArch64WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, bool RelaxAll, - bool IncrementalLinkerCompatible) { - auto *S = new AArch64WinCOFFStreamer(Context, MAB, *Emitter, OS); +MCWinCOFFStreamer * +createAArch64WinCOFFStreamer(MCContext &Context, + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, + bool RelaxAll, bool IncrementalLinkerCompatible) { + auto *S = new AArch64WinCOFFStreamer(Context, std::move(MAB), *Emitter, OS); S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible); return S; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.h index 1b4fcd6804e2..0205a4178985 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFStreamer.h @@ -15,6 +15,7 @@ #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64WINCOFFSTREAMER_H #include "AArch64TargetStreamer.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCWinCOFFStreamer.h" namespace { @@ -33,11 +34,11 @@ public: namespace llvm { -MCWinCOFFStreamer -*createAArch64WinCOFFStreamer(MCContext &Context, MCAsmBackend &TAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, bool RelaxAll, - bool IncrementalLinkerCompatible); +MCWinCOFFStreamer * +createAArch64WinCOFFStreamer(MCContext &Context, + std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, + bool RelaxAll, bool IncrementalLinkerCompatible); } // end llvm namespace #endif diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp index bfdb7d7cff76..875cdffea560 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp @@ -10,13 +10,15 @@ #include "AMDGPUELFStreamer.h" #include "Utils/AMDGPUBaseInfo.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/MC/MCAsmBackend.h" using namespace llvm; AMDGPUELFStreamer::AMDGPUELFStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter) - : MCELFStreamer(Context, MAB, OS, Emitter) { + : MCELFStreamer(Context, std::move(MAB), OS, Emitter) { unsigned Arch = ELF::EF_AMDGPU_ARCH_NONE; switch (T.getArch()) { case Triple::r600: @@ -36,10 +38,8 @@ AMDGPUELFStreamer::AMDGPUELFStreamer(const Triple &T, MCContext &Context, MCA.setELFHeaderEFlags(EFlags); } -MCELFStreamer *llvm::createAMDGPUELFStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, - raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, - bool RelaxAll) { - return new AMDGPUELFStreamer(T, Context, MAB, OS, Emitter); +MCELFStreamer *llvm::createAMDGPUELFStreamer( + const Triple &T, MCContext &Context, std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { + return new AMDGPUELFStreamer(T, Context, std::move(MAB), OS, Emitter); } diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h index 386aa56c807c..2de1786d348f 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h @@ -25,12 +25,14 @@ class MCSubtargetInfo; class AMDGPUELFStreamer : public MCELFStreamer { public: - AMDGPUELFStreamer(const Triple &T, MCContext &Context, MCAsmBackend &MAB, - raw_pwrite_stream &OS, MCCodeEmitter *Emitter); + AMDGPUELFStreamer(const Triple &T, MCContext &Context, + std::unique_ptr MAB, raw_pwrite_stream &OS, + MCCodeEmitter *Emitter); }; MCELFStreamer *createAMDGPUELFStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); } // namespace llvm. diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp index 1682fc5e49bf..578a3c25646d 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp @@ -18,6 +18,7 @@ #include "AMDGPUTargetStreamer.h" #include "InstPrinter/AMDGPUInstPrinter.h" #include "SIDefines.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" @@ -78,9 +79,11 @@ static MCTargetStreamer * createAMDGPUObjectTargetStreamer( } static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - return createAMDGPUELFStreamer(T, Context, MAB, OS, Emitter, RelaxAll); + return createAMDGPUELFStreamer(T, Context, std::move(MAB), OS, Emitter, + RelaxAll); } extern "C" void LLVMInitializeAMDGPUTargetMC() { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index af11fa74bba8..872ec19c0f61 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -440,9 +440,9 @@ class ARMELFStreamer : public MCELFStreamer { public: friend class ARMTargetELFStreamer; - ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, bool IsThumb) - : MCELFStreamer(Context, TAB, OS, Emitter), IsThumb(IsThumb) { + ARMELFStreamer(MCContext &Context, std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool IsThumb) + : MCELFStreamer(Context, std::move(TAB), OS, Emitter), IsThumb(IsThumb) { EHReset(); } @@ -1485,19 +1485,21 @@ MCTargetStreamer *createARMObjectTargetStreamer(MCStreamer &S, return new ARMTargetStreamer(S); } -MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createARMELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IsThumb) { - ARMELFStreamer *S = new ARMELFStreamer(Context, TAB, OS, Emitter, IsThumb); - // FIXME: This should eventually end up somewhere else where more - // intelligent flag decisions can be made. For now we are just maintaining - // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default. - S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); + ARMELFStreamer *S = + new ARMELFStreamer(Context, std::move(TAB), OS, Emitter, IsThumb); + // FIXME: This should eventually end up somewhere else where more + // intelligent flag decisions can be made. For now we are just maintaining + // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default. + S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); - if (RelaxAll) - S->getAssembler().setRelaxAll(true); - return S; + if (RelaxAll) + S->getAssembler().setRelaxAll(true); + return S; } } // end namespace llvm diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp index 088f59cda766..279558883bc7 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp @@ -16,6 +16,7 @@ #include "ARMMCAsmInfo.h" #include "InstPrinter/ARMInstPrinter.h" #include "llvm/ADT/Triple.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCInstrAnalysis.h" #include "llvm/MC/MCInstrInfo.h" @@ -198,18 +199,21 @@ static MCAsmInfo *createARMMCAsmInfo(const MCRegisterInfo &MRI, } static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - return createARMELFStreamer(Ctx, MAB, OS, Emitter, false, - (T.getArch() == Triple::thumb || - T.getArch() == Triple::thumbeb)); + return createARMELFStreamer( + Ctx, std::move(MAB), OS, Emitter, false, + (T.getArch() == Triple::thumb || T.getArch() == Triple::thumbeb)); } -static MCStreamer *createARMMachOStreamer(MCContext &Ctx, MCAsmBackend &MAB, +static MCStreamer *createARMMachOStreamer(MCContext &Ctx, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd) { - return createMachOStreamer(Ctx, MAB, OS, Emitter, false, DWARFMustBeAtTheEnd); + return createMachOStreamer(Ctx, std::move(MAB), OS, Emitter, false, + DWARFMustBeAtTheEnd); } static MCInstPrinter *createARMMCInstPrinter(const Triple &T, diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h index a1b93e576642..cdbc45dce22c 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h @@ -93,7 +93,8 @@ MCAsmBackend *createThumbBEAsmBackend(const Target &T, // Construct a PE/COFF machine code streamer which will generate a PE/COFF // object file. -MCStreamer *createARMWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, +MCStreamer *createARMWinCOFFStreamer(MCContext &Context, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IncrementalLinkerCompatible); diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp index 83fa084e60c7..d4c95c08cdd9 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "ARMMCTargetDesc.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCWinCOFFStreamer.h" using namespace llvm; @@ -15,9 +16,9 @@ using namespace llvm; namespace { class ARMWinCOFFStreamer : public MCWinCOFFStreamer { public: - ARMWinCOFFStreamer(MCContext &C, MCAsmBackend &AB, MCCodeEmitter &CE, - raw_pwrite_stream &OS) - : MCWinCOFFStreamer(C, AB, CE, OS) {} + ARMWinCOFFStreamer(MCContext &C, std::unique_ptr AB, + MCCodeEmitter &CE, raw_pwrite_stream &OS) + : MCWinCOFFStreamer(C, std::move(AB), CE, OS) {} void EmitAssemblerFlag(MCAssemblerFlag Flag) override; void EmitThumbFunc(MCSymbol *Symbol) override; @@ -37,10 +38,13 @@ void ARMWinCOFFStreamer::EmitThumbFunc(MCSymbol *Symbol) { } } -MCStreamer *llvm::createARMWinCOFFStreamer( - MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, bool RelaxAll, bool IncrementalLinkerCompatible) { - auto *S = new ARMWinCOFFStreamer(Context, MAB, *Emitter, OS); +MCStreamer *llvm::createARMWinCOFFStreamer(MCContext &Context, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, + MCCodeEmitter *Emitter, + bool RelaxAll, + bool IncrementalLinkerCompatible) { + auto *S = new ARMWinCOFFStreamer(Context, std::move(MAB), *Emitter, OS); S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible); return S; } diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp index 797904e1c976..40459f57fee6 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp @@ -49,11 +49,11 @@ static MCSubtargetInfo *createBPFMCSubtargetInfo(const Triple &TT, return createBPFMCSubtargetInfoImpl(TT, CPU, FS); } -static MCStreamer *createBPFMCStreamer(const Triple &T, - MCContext &Ctx, MCAsmBackend &MAB, - raw_pwrite_stream &OS, MCCodeEmitter *Emitter, - bool RelaxAll) { - return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll); +static MCStreamer *createBPFMCStreamer(const Triple &T, MCContext &Ctx, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, + MCCodeEmitter *Emitter, bool RelaxAll) { + return createELFStreamer(Ctx, std::move(MAB), OS, Emitter, RelaxAll); } static MCInstPrinter *createBPFMCInstPrinter(const Triple &T, diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp index 47007e08a2ff..85b6296d8052 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp @@ -18,6 +18,7 @@ #include "MCTargetDesc/HexagonMCShuffler.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" @@ -43,6 +44,21 @@ static cl::opt GPSize cl::Prefix, cl::init(8)); +HexagonMCELFStreamer::HexagonMCELFStreamer(MCContext &Context, + std::unique_ptr TAB, + raw_pwrite_stream &OS, + MCCodeEmitter *Emitter) + : MCELFStreamer(Context, std::move(TAB), OS, Emitter), + MCII(createHexagonMCInstrInfo()) {} + +HexagonMCELFStreamer::HexagonMCELFStreamer(MCContext &Context, + std::unique_ptr TAB, + raw_pwrite_stream &OS, + MCCodeEmitter *Emitter, + MCAssembler *Assembler) + : MCELFStreamer(Context, std::move(TAB), OS, Emitter), + MCII(createHexagonMCInstrInfo()) {} + void HexagonMCELFStreamer::EmitInstruction(const MCInst &MCB, const MCSubtargetInfo &STI, bool) { assert(MCB.getOpcode() == Hexagon::BUNDLE); @@ -149,10 +165,10 @@ void HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, namespace llvm { - MCStreamer *createHexagonELFStreamer(Triple const &TT, MCContext &Context, - MCAsmBackend &MAB, - raw_pwrite_stream &OS, MCCodeEmitter *CE) { - return new HexagonMCELFStreamer(Context, MAB, OS, CE); +MCStreamer *createHexagonELFStreamer(Triple const &TT, MCContext &Context, + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *CE) { + return new HexagonMCELFStreamer(Context, std::move(MAB), OS, CE); } } // end namespace llvm diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.h b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.h index 024dff1a2f97..9c56dcff293f 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.h +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.h @@ -22,17 +22,12 @@ class HexagonMCELFStreamer : public MCELFStreamer { std::unique_ptr MCII; public: - HexagonMCELFStreamer(MCContext &Context, MCAsmBackend &TAB, - raw_pwrite_stream &OS, MCCodeEmitter *Emitter) - : MCELFStreamer(Context, TAB, OS, Emitter), - MCII(createHexagonMCInstrInfo()) {} + HexagonMCELFStreamer(MCContext &Context, std::unique_ptr TAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter); - HexagonMCELFStreamer(MCContext &Context, - MCAsmBackend &TAB, + HexagonMCELFStreamer(MCContext &Context, std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, - MCAssembler *Assembler) : - MCELFStreamer(Context, TAB, OS, Emitter), - MCII (createHexagonMCInstrInfo()) {} + MCAssembler *Assembler); void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool) override; @@ -45,8 +40,8 @@ public: }; MCStreamer *createHexagonELFStreamer(Triple const &TT, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, - MCCodeEmitter *CE); + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *CE); } // end namespace llvm diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index 1a361548f938..a695a3bdbc45 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -20,6 +20,7 @@ #include "MCTargetDesc/HexagonMCInstrInfo.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCELFStreamer.h" @@ -224,13 +225,11 @@ createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, return new HexagonTargetAsmStreamer(S, OS, IsVerboseAsm, *IP); } -static MCStreamer *createMCStreamer(Triple const &T, - MCContext &Context, - MCAsmBackend &MAB, +static MCStreamer *createMCStreamer(Triple const &T, MCContext &Context, + std::unique_ptr &&MAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter, - bool RelaxAll) { - return createHexagonELFStreamer(T, Context, MAB, OS, Emitter); + MCCodeEmitter *Emitter, bool RelaxAll) { + return createHexagonELFStreamer(T, Context, std::move(MAB), OS, Emitter); } static MCTargetStreamer * diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp index bcbde2b8b794..a491efc322c4 100644 --- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp +++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp @@ -60,12 +60,13 @@ createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { } static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { if (!T.isOSBinFormatELF()) llvm_unreachable("OS not supported"); - return createELFStreamer(Context, MAB, OS, Emitter, RelaxAll); + return createELFStreamer(Context, std::move(MAB), OS, Emitter, RelaxAll); } static MCInstPrinter *createLanaiMCInstPrinter(const Triple & /*T*/, diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp index f658aadff22f..2a8e801763cd 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp @@ -11,6 +11,7 @@ #include "MipsOptionRecord.h" #include "MipsTargetStreamer.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInst.h" @@ -19,6 +20,15 @@ using namespace llvm; +MipsELFStreamer::MipsELFStreamer(MCContext &Context, + std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter) + : MCELFStreamer(Context, std::move(MAB), OS, Emitter) { + RegInfoRecord = new MipsRegInfoRecord(this, Context); + MipsOptionRecords.push_back( + std::unique_ptr(RegInfoRecord)); +} + void MipsELFStreamer::EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool) { MCELFStreamer::EmitInstruction(Inst, STI); @@ -78,9 +88,9 @@ void MipsELFStreamer::EmitMipsOptionRecords() { } MCELFStreamer *llvm::createMipsELFStreamer(MCContext &Context, - MCAsmBackend &MAB, + std::unique_ptr MAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - return new MipsELFStreamer(Context, MAB, OS, Emitter); + return new MipsELFStreamer(Context, std::move(MAB), OS, Emitter); } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h index f5eda112817e..e087f12f181b 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h @@ -33,13 +33,8 @@ class MipsELFStreamer : public MCELFStreamer { SmallVector Labels; public: - MipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, - MCCodeEmitter *Emitter) - : MCELFStreamer(Context, MAB, OS, Emitter) { - RegInfoRecord = new MipsRegInfoRecord(this, Context); - MipsOptionRecords.push_back( - std::unique_ptr(RegInfoRecord)); - } + MipsELFStreamer(MCContext &Context, std::unique_ptr MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter); /// Overriding this function allows us to add arbitrary behaviour before the /// \p Inst is actually emitted. For example, we can inspect the operands and @@ -69,7 +64,8 @@ public: void createPendingLabelRelocs(); }; -MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, +MCELFStreamer *createMipsELFStreamer(MCContext &Context, + std::unique_ptr MAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); } // end namespace llvm diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCNaCl.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCNaCl.h index 687b800c2409..cbddef7dd5f3 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCNaCl.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCNaCl.h @@ -22,7 +22,8 @@ bool isBasePlusOffsetMemoryAccess(unsigned Opcode, unsigned *AddrIdx, bool baseRegNeedsLoadStoreMask(unsigned Reg); // This function creates an MCELFStreamer for Mips NaCl. -MCELFStreamer *createMipsNaClELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createMipsNaClELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll); } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp index e05cbc55ffee..30474e02a228 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp @@ -91,13 +91,15 @@ static MCInstPrinter *createMipsMCInstPrinter(const Triple &T, } static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context, - MCAsmBackend &MAB, raw_pwrite_stream &OS, + std::unique_ptr &&MAB, + raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { MCStreamer *S; if (!T.isOSNaCl()) - S = createMipsELFStreamer(Context, MAB, OS, Emitter, RelaxAll); + S = createMipsELFStreamer(Context, std::move(MAB), OS, Emitter, RelaxAll); else - S = createMipsNaClELFStreamer(Context, MAB, OS, Emitter, RelaxAll); + S = createMipsNaClELFStreamer(Context, std::move(MAB), OS, Emitter, + RelaxAll); return S; } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp index 9266f0e216d1..666876d5a32d 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp @@ -20,6 +20,7 @@ #include "Mips.h" #include "MipsELFStreamer.h" #include "MipsMCNaCl.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCInst.h" @@ -40,9 +41,9 @@ const unsigned LoadStoreStackMaskReg = Mips::T7; class MipsNaClELFStreamer : public MipsELFStreamer { public: - MipsNaClELFStreamer(MCContext &Context, MCAsmBackend &TAB, + MipsNaClELFStreamer(MCContext &Context, std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter) - : MipsELFStreamer(Context, TAB, OS, Emitter) {} + : MipsELFStreamer(Context, std::move(TAB), OS, Emitter) {} ~MipsNaClELFStreamer() override = default; @@ -255,11 +256,13 @@ bool baseRegNeedsLoadStoreMask(unsigned Reg) { return Reg != Mips::SP && Reg != Mips::T8; } -MCELFStreamer *createMipsNaClELFStreamer(MCContext &Context, MCAsmBackend &TAB, +MCELFStreamer *createMipsNaClELFStreamer(MCContext &Context, + std::unique_ptr TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll) { - MipsNaClELFStreamer *S = new MipsNaClELFStreamer(Context, TAB, OS, Emitter); + MipsNaClELFStreamer *S = + new MipsNaClELFStreamer(Context, std::move(TAB), OS, Emitter); if (RelaxAll) S->getAssembler().setRelaxAll(true); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h index 82e70119ca58..327852396e41 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h @@ -81,9 +81,11 @@ MCAsmBackend *createX86_64AsmBackend(const Target &T, const MCRegisterInfo &MRI, /// PE/COFF format object files. /// /// Takes ownership of \p AB and \p CE. -MCStreamer *createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, +MCStreamer *createX86WinCOFFStreamer(MCContext &C, + std::unique_ptr &&AB, raw_pwrite_stream &OS, MCCodeEmitter *CE, - bool RelaxAll, bool IncrementalLinkerCompatible); + bool RelaxAll, + bool IncrementalLinkerCompatible); /// Construct an X86 Mach-O object writer. std::unique_ptr createX86MachObjectWriter(raw_pwrite_stream &OS, diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp index cec0f9244c91..487823b258aa 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "X86MCTargetDesc.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCWin64EH.h" #include "llvm/MC/MCWinCOFFStreamer.h" @@ -17,9 +18,9 @@ namespace { class X86WinCOFFStreamer : public MCWinCOFFStreamer { Win64EH::UnwindEmitter EHStreamer; public: - X86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, MCCodeEmitter *CE, - raw_pwrite_stream &OS) - : MCWinCOFFStreamer(C, AB, *CE, OS) {} + X86WinCOFFStreamer(MCContext &C, std::unique_ptr AB, + MCCodeEmitter *CE, raw_pwrite_stream &OS) + : MCWinCOFFStreamer(C, std::move(AB), *CE, OS) {} void EmitWinEHHandlerData(SMLoc Loc) override; void EmitWindowsUnwindTables() override; @@ -48,11 +49,12 @@ void X86WinCOFFStreamer::FinishImpl() { } } -MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, +MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C, + std::unique_ptr &&AB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll, bool IncrementalLinkerCompatible) { - X86WinCOFFStreamer *S = new X86WinCOFFStreamer(C, AB, CE, OS); + X86WinCOFFStreamer *S = new X86WinCOFFStreamer(C, std::move(AB), CE, OS); S->getAssembler().setRelaxAll(RelaxAll); S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible); return S; diff --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp index be662f49e1a4..4b3a336de0e7 100644 --- a/llvm/tools/dsymutil/DwarfLinker.cpp +++ b/llvm/tools/dsymutil/DwarfLinker.cpp @@ -623,8 +623,8 @@ bool DwarfStreamer::init(Triple TheTriple, StringRef OutputFilename) { MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MS = TheTarget->createMCObjectStreamer( - TheTriple, *MC, *MAB, *OutFile, MCE, *MSTI, MCOptions.MCRelaxAll, - MCOptions.MCIncrementalLinkerCompatible, + TheTriple, *MC, std::unique_ptr(MAB), *OutFile, MCE, *MSTI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false); if (!MS) return error("no object streamer for target " + TripleName, Context); diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index aab3f88d257b..fd6559f281bb 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -20,6 +20,7 @@ #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstrInfo.h" @@ -706,8 +707,8 @@ int main(int argc, char **argv) { MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MS(TheTarget->createMCObjectStreamer( - TheTriple, MC, *MAB, OutFile, MCE, *MSTI, MCOptions.MCRelaxAll, - MCOptions.MCIncrementalLinkerCompatible, + TheTriple, MC, std::unique_ptr(MAB), OutFile, MCE, *MSTI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false)); if (!MS) return error("no object streamer for target " + TripleName, Context); diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index dcd74a6af8b4..01041b1f5b83 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -591,8 +591,8 @@ int main(int argc, char **argv) { MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU, MCOptions); Str.reset(TheTarget->createMCObjectStreamer( - TheTriple, Ctx, *MAB, *OS, CE, *STI, MCOptions.MCRelaxAll, - MCOptions.MCIncrementalLinkerCompatible, + TheTriple, Ctx, std::unique_ptr(MAB), *OS, CE, *STI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false)); if (NoExecStack) Str->InitSections(true); diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp index dba36e40d349..41a96ac845a7 100644 --- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -181,8 +181,8 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) { MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); MS = TheTarget->createMCObjectStreamer( - TheTriple, *MC, *MAB, *Stream, MCE, *MSTI, MCOptions.MCRelaxAll, - MCOptions.MCIncrementalLinkerCompatible, + TheTriple, *MC, std::unique_ptr(MAB), *Stream, MCE, *MSTI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false); if (!MS) return make_error("no object streamer for target " +