Allow a target to create a null streamer.

Targets can assume that a target streamer is present, so they have to be able
to construct a null streamer in order to set the target streamer in it to.

Fixes a crash when using the null streamer with arm.

llvm-svn: 211358
This commit is contained in:
Rafael Espindola 2014-06-20 13:11:28 +00:00
parent 36a6193bf4
commit 1fc003e6c5
7 changed files with 62 additions and 73 deletions

View File

@ -51,6 +51,7 @@ namespace llvm {
class raw_ostream;
class formatted_raw_ostream;
MCStreamer *createNullStreamer(MCContext &Ctx);
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
@ -139,6 +140,7 @@ namespace llvm {
MCCodeEmitter *CE,
MCAsmBackend *TAB,
bool ShowInst);
typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);
typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
MCContext &Ctx);
typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
@ -225,6 +227,10 @@ namespace llvm {
/// AsmStreamer, if registered (default = llvm::createAsmStreamer).
AsmStreamerCtorTy AsmStreamerCtorFn;
/// Construction function for this target's NullStreamer, if registered
/// (default = llvm::createNullStreamer).
NullStreamerCtorTy NullStreamerCtorFn;
/// MCRelocationInfoCtorFn - Construction function for this target's
/// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
@ -235,8 +241,8 @@ namespace llvm {
public:
Target()
: AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
MCSymbolizerCtorFn(nullptr) {}
: AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr),
MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
/// @name Target Information
/// @{
@ -447,6 +453,12 @@ namespace llvm {
InstPrint, CE, TAB, ShowInst);
}
MCStreamer *createNullStreamer(MCContext &Ctx) const {
if (NullStreamerCtorFn)
return NullStreamerCtorFn(Ctx);
return llvm::createNullStreamer(Ctx);
}
/// createMCRelocationInfo - Create a target specific MCRelocationInfo.
///
/// \param TT The target triple.
@ -780,6 +792,10 @@ namespace llvm {
T.AsmStreamerCtorFn = Fn;
}
static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
T.NullStreamerCtorFn = Fn;
}
/// RegisterMCRelocationInfo - Register an MCRelocationInfo
/// implementation for the given target.
///

View File

@ -209,7 +209,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
case CGFT_Null:
// The Null output is intended for use for performance analysis and testing,
// not real users.
AsmStreamer.reset(createNullStreamer(*Context));
AsmStreamer.reset(getTarget().createNullStreamer(*Context));
break;
}

View File

@ -1332,6 +1332,12 @@ MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
return S;
}
MCStreamer *createARMNullStreamer(MCContext &Ctx) {
MCStreamer *S = llvm::createNullStreamer(Ctx);
new ARMTargetStreamer(*S);
return S;
}
MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
raw_ostream &OS, MCCodeEmitter *Emitter,
bool RelaxAll, bool NoExecStack,

View File

@ -427,6 +427,12 @@ extern "C" void LLVMInitializeARMTargetMC() {
TargetRegistry::RegisterAsmStreamer(TheThumbLETarget, createMCAsmStreamer);
TargetRegistry::RegisterAsmStreamer(TheThumbBETarget, createMCAsmStreamer);
// Register the null streamer.
TargetRegistry::RegisterNullStreamer(TheARMLETarget, createARMNullStreamer);
TargetRegistry::RegisterNullStreamer(TheARMBETarget, createARMNullStreamer);
TargetRegistry::RegisterNullStreamer(TheThumbLETarget, createARMNullStreamer);
TargetRegistry::RegisterNullStreamer(TheThumbBETarget, createARMNullStreamer);
// Register the MCInstPrinter.
TargetRegistry::RegisterMCInstPrinter(TheARMLETarget, createARMMCInstPrinter);
TargetRegistry::RegisterMCInstPrinter(TheARMBETarget, createARMMCInstPrinter);

View File

@ -51,6 +51,8 @@ MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
MCAsmBackend *TAB, bool ShowInst);
MCStreamer *createARMNullStreamer(MCContext &Ctx);
MCCodeEmitter *createARMLEMCCodeEmitter(const MCInstrInfo &MCII,
const MCRegisterInfo &MRI,
const MCSubtargetInfo &STI,

View File

@ -40,78 +40,34 @@ void ARMTargetStreamer::finish() { ConstantPools->emitAll(Streamer); }
// The remaining callbacks should be handled separately by each
// streamer.
void ARMTargetStreamer::emitFnStart() {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitFnEnd() {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitCantUnwind() {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitPersonality(const MCSymbol *Personality) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitPersonalityIndex(unsigned Index) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitHandlerData() {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitFnStart() {}
void ARMTargetStreamer::emitFnEnd() {}
void ARMTargetStreamer::emitCantUnwind() {}
void ARMTargetStreamer::emitPersonality(const MCSymbol *Personality) {}
void ARMTargetStreamer::emitPersonalityIndex(unsigned Index) {}
void ARMTargetStreamer::emitHandlerData() {}
void ARMTargetStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
int64_t Offset) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitPad(int64_t Offset) {
llvm_unreachable("unimplemented");
}
void
ARMTargetStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitUnwindRaw(
int64_t StackOffset, const SmallVectorImpl<uint8_t> &Opcodes) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::switchVendor(StringRef Vendor) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
llvm_unreachable("unimplemented");
int64_t Offset) {}
void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {}
void ARMTargetStreamer::emitPad(int64_t Offset) {}
void ARMTargetStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) {}
void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset,
const SmallVectorImpl<uint8_t> &Opcodes) {
}
void ARMTargetStreamer::switchVendor(StringRef Vendor) {}
void ARMTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {}
void ARMTargetStreamer::emitTextAttribute(unsigned Attribute,
StringRef String) {
llvm_unreachable("unimplemented");
}
StringRef String) {}
void ARMTargetStreamer::emitIntTextAttribute(unsigned Attribute,
unsigned IntValue,
StringRef StringValue) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitArch(unsigned Arch) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitObjectArch(unsigned Arch) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitFPU(unsigned FPU) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::finishAttributeSection() {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitInst(uint32_t Inst, char Suffix) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::AnnotateTLSDescriptorSequence(
const MCSymbolRefExpr *SRE) {
llvm_unreachable("unimplemented");
}
unsigned IntValue,
StringRef StringValue) {}
void ARMTargetStreamer::emitArch(unsigned Arch) {}
void ARMTargetStreamer::emitObjectArch(unsigned Arch) {}
void ARMTargetStreamer::emitFPU(unsigned FPU) {}
void ARMTargetStreamer::finishAttributeSection() {}
void ARMTargetStreamer::emitInst(uint32_t Inst, char Suffix) {}
void
ARMTargetStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) {}
void ARMTargetStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
llvm_unreachable("unimplemented");
}
void ARMTargetStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {}

View File

@ -6,6 +6,9 @@
; Also test that the null streamer doesn't crash with debug info.
; RUN: %llc_dwarf -O0 -filetype=null < %s
; Test the null streamer with a terget streamer too.
; RUN: llc -O0 -filetype=null -mtriple=arm-linux < %s
; generated from the following source compiled to bitcode with clang -g -O1
; static int i;
; int main() {