Skip to content

Commit

Permalink
There is only one Asm streamer, there is no need for targets to regis…
Browse files Browse the repository at this point in the history
…ter it.

Instead, have the targets register a TargetStreamer to be use with the
asm streamer (if any).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232423 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Mar 16, 2015
1 parent 4fefd5c commit 9130d11
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 128 deletions.
73 changes: 32 additions & 41 deletions include/llvm/Support/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ namespace llvm {
const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB,
raw_ostream &OS, MCCodeEmitter *Emitter, const MCSubtargetInfo &STI,
bool RelaxAll);
typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
formatted_raw_ostream &OS,
bool isVerboseAsm,
bool useDwarfDirectory,
MCInstPrinter *InstPrint,
MCCodeEmitter *CE,
MCAsmBackend *TAB,
bool ShowInst);
typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
bool IsVerboseAsm);
typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
MCContext &Ctx);
typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
Expand Down Expand Up @@ -219,14 +214,14 @@ namespace llvm {
/// MCObjectStreamer, if registered.
MCObjectStreamerCtorTy MCObjectStreamerCtorFn;

/// AsmStreamerCtorFn - Construction function for this target's
/// AsmStreamer, if registered (default = llvm::createAsmStreamer).
AsmStreamerCtorTy AsmStreamerCtorFn;

/// Construction function for this target's null TargetStreamer, if
/// registered (default = nullptr).
NullTargetStreamerCtorTy NullTargetStreamerCtorFn;

/// Construction function for this target's asm TargetStreamer, if
/// registered (default = nullptr).
AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;

/// MCRelocationInfoCtorFn - Construction function for this target's
/// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
Expand All @@ -237,8 +232,8 @@ namespace llvm {

public:
Target()
: AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
MCSymbolizerCtorFn(nullptr) {}
: NullTargetStreamerCtorFn(nullptr), AsmTargetStreamerCtorFn(nullptr),
MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}

/// @name Target Information
/// @{
Expand Down Expand Up @@ -430,20 +425,24 @@ namespace llvm {
RelaxAll);
}

/// createAsmStreamer - Create a target specific MCStreamer.
MCStreamer *createAsmStreamer(MCContext &Ctx,
formatted_raw_ostream &OS,
bool isVerboseAsm,
bool useDwarfDirectory,
MCInstPrinter *InstPrint,
MCCodeEmitter *CE,
MCAsmBackend *TAB,
bool ShowInst) const {
if (AsmStreamerCtorFn)
return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
InstPrint, CE, TAB, ShowInst);
return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
InstPrint, CE, TAB, ShowInst);
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool IsVerboseAsm, bool UseDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) const {
MCStreamer *S =
llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
InstPrint, CE, TAB, ShowInst);
createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
return S;
}

MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool IsVerboseAsm) const {
if (AsmTargetStreamerCtorFn)
return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
return nullptr;
}

MCStreamer *createNullStreamer(MCContext &Ctx) const {
Expand Down Expand Up @@ -771,24 +770,16 @@ namespace llvm {
T.MCObjectStreamerCtorFn = Fn;
}

/// RegisterAsmStreamer - Register an assembly MCStreamer 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 an MCStreamer for the target.
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
T.AsmStreamerCtorFn = Fn;
}

static void
RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
T.NullTargetStreamerCtorFn = Fn;
}

static void RegisterAsmTargetStreamer(Target &T,
Target::AsmTargetStreamerCtorTy Fn) {
T.AsmTargetStreamerCtorFn = Fn;
}

/// RegisterMCRelocationInfo - Register an MCRelocationInfo
/// implementation for the given target.
///
Expand Down
14 changes: 5 additions & 9 deletions lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,11 @@ void AArch64TargetELFStreamer::emitInst(uint32_t Inst) {
}

namespace llvm {
MCStreamer *
createAArch64MCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {
MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new AArch64TargetAsmStreamer(*S, OS);
return S;
MCTargetStreamer *createAArch64AsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new AArch64TargetAsmStreamer(S, OS);
}

MCELFStreamer *createAArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB,
Expand Down
12 changes: 6 additions & 6 deletions lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ extern "C" void LLVMInitializeAArch64TargetMC() {
TargetRegistry::RegisterMCObjectStreamer(TheARM64Target, createMCStreamer);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(TheAArch64leTarget,
createAArch64MCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheAArch64beTarget,
createAArch64MCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheARM64Target,
createAArch64MCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheAArch64leTarget,
createAArch64AsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheAArch64beTarget,
createAArch64AsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheARM64Target,
createAArch64AsmTargetStreamer);

// Register the MCInstPrinter.
TargetRegistry::RegisterMCInstPrinter(TheAArch64leTarget,
Expand Down
10 changes: 5 additions & 5 deletions lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MCRegisterInfo;
class MCObjectWriter;
class MCStreamer;
class MCSubtargetInfo;
class MCTargetStreamer;
class StringRef;
class Target;
class raw_ostream;
Expand All @@ -52,11 +53,10 @@ MCObjectWriter *createAArch64ELFObjectWriter(raw_ostream &OS, uint8_t OSABI,
MCObjectWriter *createAArch64MachObjectWriter(raw_ostream &OS, uint32_t CPUType,
uint32_t CPUSubtype);

MCStreamer *
createAArch64MCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst);
MCTargetStreamer *createAArch64AsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm);
} // End llvm namespace

// Defines symbolic names for AArch64 registers. This defines a mapping from
Expand Down
13 changes: 5 additions & 8 deletions lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,14 +1362,11 @@ void ARMELFStreamer::emitUnwindRaw(int64_t Offset,

namespace llvm {

MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {
MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new ARMTargetAsmStreamer(*S, OS, *InstPrint, isVerboseAsm);
return S;
MCTargetStreamer *createARMTargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new ARMTargetAsmStreamer(S, OS, *InstPrint, isVerboseAsm);
}

MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S) {
Expand Down
12 changes: 8 additions & 4 deletions lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,14 @@ extern "C" void LLVMInitializeARMTargetMC() {
TargetRegistry::RegisterMCObjectStreamer(TheThumbBETarget, createMCStreamer);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(TheARMLETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheARMBETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheThumbLETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheThumbBETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheARMLETarget,
createARMTargetAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheARMBETarget,
createARMTargetAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheThumbLETarget,
createARMTargetAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheThumbBETarget,
createARMTargetAsmStreamer);

// Register the null TargetStreamer.
TargetRegistry::RegisterNullTargetStreamer(TheARMLETarget,
Expand Down
9 changes: 4 additions & 5 deletions lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ namespace ARM_MC {
StringRef FS);
}

MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst);

MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S);
MCTargetStreamer *createARMTargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm);

MCCodeEmitter *createARMLEMCCodeEmitter(const MCInstrInfo &MCII,
const MCRegisterInfo &MRI,
Expand Down
26 changes: 13 additions & 13 deletions lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,11 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
return S;
}

static MCStreamer *
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {
MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new MipsTargetAsmStreamer(*S, OS);
return S;
static MCTargetStreamer *createMipsAsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new MipsTargetAsmStreamer(S, OS);
}

static MCTargetStreamer *createMipsNullTargetStreamer(MCStreamer &S) {
Expand Down Expand Up @@ -183,10 +179,14 @@ extern "C" void LLVMInitializeMipsTargetMC() {
createMCStreamer);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(TheMipsTarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheMipselTarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheMips64Target, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheMips64elTarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheMipsTarget,
createMipsAsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheMipselTarget,
createMipsAsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheMips64Target,
createMipsAsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheMips64elTarget,
createMipsAsmTargetStreamer);

TargetRegistry::RegisterNullTargetStreamer(TheMipsTarget,
createMipsNullTargetStreamer);
Expand Down
24 changes: 11 additions & 13 deletions lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,11 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
return S;
}

static MCStreamer *
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {

MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new PPCTargetAsmStreamer(*S, OS);
return S;
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new PPCTargetAsmStreamer(S, OS);
}

static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
Expand Down Expand Up @@ -309,9 +304,12 @@ extern "C" void LLVMInitializePowerPCTargetMC() {
TargetRegistry::RegisterMCObjectStreamer(ThePPC64LETarget, createMCStreamer);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(ThePPC32Target, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(ThePPC64Target, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(ThePPC64LETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(ThePPC32Target,
createAsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(ThePPC64Target,
createAsmTargetStreamer);
TargetRegistry::RegisterAsmTargetStreamer(ThePPC64LETarget,
createAsmTargetStreamer);

// Register the MCInstPrinter.
TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
Expand Down
23 changes: 9 additions & 14 deletions lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,11 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
return S;
}

static MCStreamer *
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {

MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new SparcTargetAsmStreamer(*S, OS);
return S;
static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new SparcTargetAsmStreamer(S, OS);
}

static MCInstPrinter *createSparcMCInstPrinter(const Target &T,
Expand Down Expand Up @@ -197,10 +192,10 @@ extern "C" void LLVMInitializeSparcTargetMC() {
createMCStreamer);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(TheSparcTarget,
createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheSparcV9Target,
createMCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheSparcTarget,
createTargetAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheSparcV9Target,
createTargetAsmStreamer);

// Register the MCInstPrinter
TargetRegistry::RegisterMCInstPrinter(TheSparcTarget,
Expand Down
17 changes: 7 additions & 10 deletions lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,11 @@ void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
}
}

static MCStreamer *
createXCoreMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst) {
MCStreamer *S = llvm::createAsmStreamer(
Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
new XCoreTargetAsmStreamer(*S, OS);
return S;
static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new XCoreTargetAsmStreamer(S, OS);
}

// Force static initialization.
Expand All @@ -160,5 +156,6 @@ extern "C" void LLVMInitializeXCoreTargetMC() {
TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
createXCoreMCInstPrinter);

TargetRegistry::RegisterAsmStreamer(TheXCoreTarget, createXCoreMCAsmStreamer);
TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget,
createTargetAsmStreamer);
}

0 comments on commit 9130d11

Please sign in to comment.