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

std::unique_ptrify the MCStreamer argument to createAsmPrinter

llvm-svn: 226414
This commit is contained in:
David Blaikie 2015-01-18 20:29:04 +00:00
parent e51db749de
commit 8839ae1559
19 changed files with 89 additions and 68 deletions

View File

@ -127,7 +127,7 @@ private:
DwarfDebug *DD; DwarfDebug *DD;
protected: protected:
explicit AsmPrinter(TargetMachine &TM, MCStreamer &Streamer); explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
public: public:
virtual ~AsmPrinter(); virtual ~AsmPrinter();

View File

@ -23,6 +23,7 @@
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/Support/CodeGen.h" #include "llvm/Support/CodeGen.h"
#include <cassert> #include <cassert>
#include <memory>
#include <string> #include <string>
namespace llvm { namespace llvm {
@ -99,8 +100,11 @@ namespace llvm {
Reloc::Model RM, Reloc::Model RM,
CodeModel::Model CM, CodeModel::Model CM,
CodeGenOpt::Level OL); CodeGenOpt::Level OL);
typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM, // If it weren't for layering issues (this header is in llvm/Support, but
MCStreamer &Streamer); // depends on MC?) this should take the Streamer by value rather than rvalue
// reference.
typedef AsmPrinter *(*AsmPrinterCtorTy)(
TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
const MCRegisterInfo &MRI, const MCRegisterInfo &MRI,
StringRef TT, StringRef TT,
@ -376,10 +380,11 @@ namespace llvm {
/// createAsmPrinter - Create a target specific assembly printer pass. This /// createAsmPrinter - Create a target specific assembly printer pass. This
/// takes ownership of the MCStreamer object. /// takes ownership of the MCStreamer object.
AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{ AsmPrinter *createAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer) const {
if (!AsmPrinterCtorFn) if (!AsmPrinterCtorFn)
return nullptr; return nullptr;
return AsmPrinterCtorFn(TM, Streamer); return AsmPrinterCtorFn(TM, std::move(Streamer));
} }
MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI, MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
@ -1121,8 +1126,9 @@ namespace llvm {
} }
private: private:
static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) { static AsmPrinter *Allocator(TargetMachine &TM,
return new AsmPrinterImpl(TM, Streamer); std::unique_ptr<MCStreamer> &&Streamer) {
return new AsmPrinterImpl(TM, std::move(Streamer));
} }
}; };

View File

@ -98,15 +98,15 @@ static unsigned getGVAlignmentLog2(const GlobalValue *GV, const DataLayout &TD,
return NumBits; return NumBits;
} }
AsmPrinter::AsmPrinter(TargetMachine &tm, MCStreamer &Streamer) AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
: MachineFunctionPass(ID), TM(tm), MAI(tm.getMCAsmInfo()), : MachineFunctionPass(ID), TM(tm), MAI(tm.getMCAsmInfo()),
MII(tm.getSubtargetImpl()->getInstrInfo()), MII(tm.getSubtargetImpl()->getInstrInfo()),
OutContext(Streamer.getContext()), OutStreamer(Streamer), LastMI(nullptr), OutContext(Streamer->getContext()), OutStreamer(*Streamer.release()),
LastFn(0), Counter(~0U), SetCounter(0) { LastMI(nullptr), LastFn(0), Counter(~0U), SetCounter(0) {
DD = nullptr; MMI = nullptr; LI = nullptr; MF = nullptr; DD = nullptr; MMI = nullptr; LI = nullptr; MF = nullptr;
CurrentFnSym = CurrentFnSymForSize = nullptr; CurrentFnSym = CurrentFnSymForSize = nullptr;
GCMetadataPrinters = nullptr; GCMetadataPrinters = nullptr;
VerboseAsm = Streamer.isVerboseAsm(); VerboseAsm = OutStreamer.isVerboseAsm();
} }
AsmPrinter::~AsmPrinter() { AsmPrinter::~AsmPrinter() {

View File

@ -221,13 +221,11 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
} }
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful. // Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *AsmStreamer); FunctionPass *Printer =
getTarget().createAsmPrinter(*this, std::move(AsmStreamer));
if (!Printer) if (!Printer)
return true; return true;
// If successful, createAsmPrinter took ownership of AsmStreamer.
AsmStreamer.release();
PM.add(Printer); PM.add(Printer);
return false; return false;
@ -261,20 +259,16 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
if (!MCE || !MAB) if (!MCE || !MAB)
return true; return true;
std::unique_ptr<MCStreamer> AsmStreamer; std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
AsmStreamer.reset(getTarget() getTargetTriple(), *Ctx, *MAB, Out, MCE, STI,
.createMCObjectStreamer(getTargetTriple(), *Ctx, *MAB, Options.MCOptions.MCRelaxAll));
Out, MCE, STI,
Options.MCOptions.MCRelaxAll));
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful. // Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *AsmStreamer); FunctionPass *Printer =
getTarget().createAsmPrinter(*this, std::move(AsmStreamer));
if (!Printer) if (!Printer)
return true; return true;
// If successful, createAsmPrinter took ownership of AsmStreamer.
AsmStreamer.release();
PM.add(Printer); PM.add(Printer);
return false; // success! return false; // success!

View File

@ -51,8 +51,8 @@ class AArch64AsmPrinter : public AsmPrinter {
StackMaps SM; StackMaps SM;
public: public:
AArch64AsmPrinter(TargetMachine &TM, MCStreamer &Streamer) AArch64AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, Streamer), : AsmPrinter(TM, std::move(Streamer)),
Subtarget(&TM.getSubtarget<AArch64Subtarget>()), Subtarget(&TM.getSubtarget<AArch64Subtarget>()),
MCInstLowering(OutContext, *this), SM(*this), AArch64FI(nullptr), MCInstLowering(OutContext, *this), SM(*this), AArch64FI(nullptr),
LOHLabelCounter(0) {} LOHLabelCounter(0) {}

View File

@ -57,6 +57,13 @@ using namespace llvm;
#define DEBUG_TYPE "asm-printer" #define DEBUG_TYPE "asm-printer"
ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)), AFI(nullptr), MCP(nullptr),
InConstantPool(false) {
Subtarget = &TM.getSubtarget<ARMSubtarget>();
}
void ARMAsmPrinter::EmitFunctionBodyEnd() { void ARMAsmPrinter::EmitFunctionBodyEnd() {
// Make sure to terminate any constant pools that were at the end // Make sure to terminate any constant pools that were at the end
// of the function. // of the function.

View File

@ -52,11 +52,8 @@ class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads; SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads;
public: public:
explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit ARMAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer), AFI(nullptr), MCP(nullptr), std::unique_ptr<MCStreamer> Streamer);
InConstantPool(false) {
Subtarget = &TM.getSubtarget<ARMSubtarget>();
}
const char *getPassName() const override { const char *getPassName() const override {
return "ARM Assembly / Object Emitter"; return "ARM Assembly / Object Emitter";

View File

@ -61,6 +61,12 @@ static cl::opt<bool> AlignCalls(
"hexagon-align-calls", cl::Hidden, cl::init(true), "hexagon-align-calls", cl::Hidden, cl::init(true),
cl::desc("Insert falign after call instruction for Hexagon target")); cl::desc("Insert falign after call instruction for Hexagon target"));
HexagonAsmPrinter::HexagonAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)) {
Subtarget = &TM.getSubtarget<HexagonSubtarget>();
}
void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
raw_ostream &O) { raw_ostream &O) {
const MachineOperand &MO = MI->getOperand(OpNo); const MachineOperand &MO = MI->getOperand(OpNo);

View File

@ -25,10 +25,8 @@ namespace llvm {
const HexagonSubtarget *Subtarget; const HexagonSubtarget *Subtarget;
public: public:
explicit HexagonAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit HexagonAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer) { std::unique_ptr<MCStreamer> Streamer);
Subtarget = &TM.getSubtarget<HexagonSubtarget>();
}
const char *getPassName() const override { const char *getPassName() const override {
return "Hexagon Assembly Printer"; return "Hexagon Assembly Printer";

View File

@ -39,8 +39,8 @@ using namespace llvm;
namespace { namespace {
class MSP430AsmPrinter : public AsmPrinter { class MSP430AsmPrinter : public AsmPrinter {
public: public:
MSP430AsmPrinter(TargetMachine &TM, MCStreamer &Streamer) MSP430AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, Streamer) {} : AsmPrinter(TM, std::move(Streamer)) {}
const char *getPassName() const override { const char *getPassName() const override {
return "MSP430 Assembly Printer"; return "MSP430 Assembly Printer";

View File

@ -99,9 +99,11 @@ public:
// reside on the TargetMachine, but are on the subtarget currently // reside on the TargetMachine, but are on the subtarget currently
// and we need them for the beginning of file output before we've // and we need them for the beginning of file output before we've
// seen a single function. // seen a single function.
explicit MipsAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit MipsAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer), MCP(nullptr), InConstantPool(false), std::unique_ptr<MCStreamer> Streamer)
Subtarget(&TM.getSubtarget<MipsSubtarget>()), MCInstLowering(*this) {} : AsmPrinter(TM, std::move(Streamer)), MCP(nullptr),
InConstantPool(false), Subtarget(&TM.getSubtarget<MipsSubtarget>()),
MCInstLowering(*this) {}
const char *getPassName() const override { const char *getPassName() const override {
return "Mips Assembly Printer"; return "Mips Assembly Printer";

View File

@ -298,8 +298,8 @@ private:
bool EmitGeneric; bool EmitGeneric;
public: public:
NVPTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) NVPTXAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, Streamer), : AsmPrinter(TM, std::move(Streamer)),
nvptxSubtarget(TM.getSubtarget<NVPTXSubtarget>()) { nvptxSubtarget(TM.getSubtarget<NVPTXSubtarget>()) {
CurrentBankselLabelInBasicBlock = ""; CurrentBankselLabelInBasicBlock = "";
reader = nullptr; reader = nullptr;

View File

@ -72,9 +72,11 @@ namespace {
uint64_t TOCLabelID; uint64_t TOCLabelID;
StackMaps SM; StackMaps SM;
public: public:
explicit PPCAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit PPCAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer), std::unique_ptr<MCStreamer> Streamer)
Subtarget(TM.getSubtarget<PPCSubtarget>()), TOCLabelID(0), SM(*this) {} : AsmPrinter(TM, std::move(Streamer)),
Subtarget(TM.getSubtarget<PPCSubtarget>()), TOCLabelID(0), SM(*this) {
}
const char *getPassName() const override { const char *getPassName() const override {
return "PowerPC Assembly Printer"; return "PowerPC Assembly Printer";
@ -104,8 +106,9 @@ namespace {
/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
class PPCLinuxAsmPrinter : public PPCAsmPrinter { class PPCLinuxAsmPrinter : public PPCAsmPrinter {
public: public:
explicit PPCLinuxAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit PPCLinuxAsmPrinter(TargetMachine &TM,
: PPCAsmPrinter(TM, Streamer) {} std::unique_ptr<MCStreamer> Streamer)
: PPCAsmPrinter(TM, std::move(Streamer)) {}
const char *getPassName() const override { const char *getPassName() const override {
return "Linux PPC Assembly Printer"; return "Linux PPC Assembly Printer";
@ -124,8 +127,9 @@ namespace {
/// OS X /// OS X
class PPCDarwinAsmPrinter : public PPCAsmPrinter { class PPCDarwinAsmPrinter : public PPCAsmPrinter {
public: public:
explicit PPCDarwinAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit PPCDarwinAsmPrinter(TargetMachine &TM,
: PPCAsmPrinter(TM, Streamer) {} std::unique_ptr<MCStreamer> Streamer)
: PPCAsmPrinter(TM, std::move(Streamer)) {}
const char *getPassName() const override { const char *getPassName() const override {
return "Darwin PPC Assembly Printer"; return "Darwin PPC Assembly Printer";
@ -1471,13 +1475,14 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
/// for a MachineFunction to the given output stream, in a format that the /// for a MachineFunction to the given output stream, in a format that the
/// Darwin assembler can deal with. /// Darwin assembler can deal with.
/// ///
static AsmPrinter *createPPCAsmPrinterPass(TargetMachine &tm, static AsmPrinter *
MCStreamer &Streamer) { createPPCAsmPrinterPass(TargetMachine &tm,
std::unique_ptr<MCStreamer> &&Streamer) {
const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>(); const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
if (Subtarget->isDarwin()) if (Subtarget->isDarwin())
return new PPCDarwinAsmPrinter(tm, Streamer); return new PPCDarwinAsmPrinter(tm, std::move(Streamer));
return new PPCLinuxAsmPrinter(tm, Streamer); return new PPCLinuxAsmPrinter(tm, std::move(Streamer));
} }
// Force static initialization. // Force static initialization.

View File

@ -73,9 +73,10 @@ static uint32_t getFPMode(const MachineFunction &F) {
FP_DENORM_MODE_DP(FP64Denormals); FP_DENORM_MODE_DP(FP64Denormals);
} }
static AsmPrinter *createAMDGPUAsmPrinterPass(TargetMachine &tm, static AsmPrinter *
MCStreamer &Streamer) { createAMDGPUAsmPrinterPass(TargetMachine &tm,
return new AMDGPUAsmPrinter(tm, Streamer); std::unique_ptr<MCStreamer> &&Streamer) {
return new AMDGPUAsmPrinter(tm, std::move(Streamer));
} }
extern "C" void LLVMInitializeR600AsmPrinter() { extern "C" void LLVMInitializeR600AsmPrinter() {
@ -83,8 +84,9 @@ extern "C" void LLVMInitializeR600AsmPrinter() {
TargetRegistry::RegisterAsmPrinter(TheGCNTarget, createAMDGPUAsmPrinterPass); TargetRegistry::RegisterAsmPrinter(TheGCNTarget, createAMDGPUAsmPrinterPass);
} }
AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer) { std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)) {
DisasmEnabled = TM.getSubtarget<AMDGPUSubtarget>().dumpCode(); DisasmEnabled = TM.getSubtarget<AMDGPUSubtarget>().dumpCode();
} }

View File

@ -85,7 +85,8 @@ private:
const SIProgramInfo &KernelInfo) const; const SIProgramInfo &KernelInfo) const;
public: public:
explicit AMDGPUAsmPrinter(TargetMachine &TM, MCStreamer &Streamer); explicit AMDGPUAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer);
bool runOnMachineFunction(MachineFunction &MF) override; bool runOnMachineFunction(MachineFunction &MF) override;

View File

@ -43,8 +43,9 @@ namespace {
*OutStreamer.getTargetStreamer()); *OutStreamer.getTargetStreamer());
} }
public: public:
explicit SparcAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit SparcAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer) {} std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)) {}
const char *getPassName() const override { const char *getPassName() const override {
return "Sparc Assembly Printer"; return "Sparc Assembly Printer";

View File

@ -26,8 +26,8 @@ private:
const SystemZSubtarget *Subtarget; const SystemZSubtarget *Subtarget;
public: public:
SystemZAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, Streamer) { : AsmPrinter(TM, std::move(Streamer)) {
Subtarget = &TM.getSubtarget<SystemZSubtarget>(); Subtarget = &TM.getSubtarget<SystemZSubtarget>();
} }

View File

@ -85,8 +85,9 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
void LowerTlsAddr(X86MCInstLower &MCInstLowering, const MachineInstr &MI); void LowerTlsAddr(X86MCInstLower &MCInstLowering, const MachineInstr &MI);
public: public:
explicit X86AsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit X86AsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer), SM(*this), SMShadowTracker(TM) { std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)), SM(*this), SMShadowTracker(TM) {
Subtarget = &TM.getSubtarget<X86Subtarget>(); Subtarget = &TM.getSubtarget<X86Subtarget>();
} }

View File

@ -55,9 +55,10 @@ namespace {
XCoreTargetStreamer &getTargetStreamer(); XCoreTargetStreamer &getTargetStreamer();
public: public:
explicit XCoreAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) explicit XCoreAsmPrinter(TargetMachine &TM,
: AsmPrinter(TM, Streamer), Subtarget(TM.getSubtarget<XCoreSubtarget>()), std::unique_ptr<MCStreamer> Streamer)
MCInstLowering(*this) {} : AsmPrinter(TM, std::move(Streamer)),
Subtarget(TM.getSubtarget<XCoreSubtarget>()), MCInstLowering(*this) {}
const char *getPassName() const override { const char *getPassName() const override {
return "XCore Assembly Printer"; return "XCore Assembly Printer";