Add all the plumbing needed for MC to expand cfi to the old tables in

the final assembly. It is the same technique used when targeting
assemblers that don't support .loc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130587 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2011-04-30 03:44:37 +00:00
parent a37bd1d02c
commit f1a5c7ec04
10 changed files with 69 additions and 9 deletions

View File

@ -510,6 +510,7 @@ namespace llvm {
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool isVerboseAsm,
bool useLoc, bool useLoc,
bool useCFI,
MCInstPrinter *InstPrint = 0, MCInstPrinter *InstPrint = 0,
MCCodeEmitter *CE = 0, MCCodeEmitter *CE = 0,
TargetAsmBackend *TAB = 0, TargetAsmBackend *TAB = 0,

View File

@ -108,6 +108,7 @@ protected: // Can only create subclasses.
unsigned MCNoExecStack : 1; unsigned MCNoExecStack : 1;
unsigned MCSaveTempLabels : 1; unsigned MCSaveTempLabels : 1;
unsigned MCUseLoc : 1; unsigned MCUseLoc : 1;
unsigned MCUseCFI : 1;
public: public:
virtual ~TargetMachine(); virtual ~TargetMachine();
@ -193,6 +194,12 @@ public:
/// setMCUseLoc - Set whether all we should use dwarf's .loc directive. /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
void setMCUseLoc(bool Value) { MCUseLoc = Value; } void setMCUseLoc(bool Value) { MCUseLoc = Value; }
/// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
bool hasMCUseCFI() const { return MCUseCFI; }
/// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
void setMCUseCFI(bool Value) { MCUseCFI = Value; }
/// getRelocationModel - Returns the code generation relocation model. The /// getRelocationModel - Returns the code generation relocation model. The
/// choices are static, PIC, and dynamic-no-pic, and target default. /// choices are static, PIC, and dynamic-no-pic, and target default.
static Reloc::Model getRelocationModel(); static Reloc::Model getRelocationModel();

View File

@ -43,7 +43,7 @@ namespace llvm {
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool isVerboseAsm,
bool useLoc, bool useLoc, bool useCFI,
MCInstPrinter *InstPrint, MCInstPrinter *InstPrint,
MCCodeEmitter *CE, MCCodeEmitter *CE,
TargetAsmBackend *TAB, TargetAsmBackend *TAB,
@ -96,6 +96,7 @@ namespace llvm {
formatted_raw_ostream &OS, formatted_raw_ostream &OS,
bool isVerboseAsm, bool isVerboseAsm,
bool useLoc, bool useLoc,
bool useCFI,
MCInstPrinter *InstPrint, MCInstPrinter *InstPrint,
MCCodeEmitter *CE, MCCodeEmitter *CE,
TargetAsmBackend *TAB, TargetAsmBackend *TAB,
@ -329,12 +330,13 @@ namespace llvm {
formatted_raw_ostream &OS, formatted_raw_ostream &OS,
bool isVerboseAsm, bool isVerboseAsm,
bool useLoc, bool useLoc,
bool useCFI,
MCInstPrinter *InstPrint, MCInstPrinter *InstPrint,
MCCodeEmitter *CE, MCCodeEmitter *CE,
TargetAsmBackend *TAB, TargetAsmBackend *TAB,
bool ShowInst) const { bool ShowInst) const {
// AsmStreamerCtorFn is default to llvm::createAsmStreamer // AsmStreamerCtorFn is default to llvm::createAsmStreamer
return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
InstPrint, CE, TAB, ShowInst); InstPrint, CE, TAB, ShowInst);
} }

View File

@ -149,6 +149,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
MCStreamer *S = getTarget().createAsmStreamer(*Context, Out, MCStreamer *S = getTarget().createAsmStreamer(*Context, Out,
getVerboseAsm(), getVerboseAsm(),
hasMCUseLoc(), hasMCUseLoc(),
hasMCUseCFI(),
InstPrinter, InstPrinter,
MCE, TAB, MCE, TAB,
ShowMCInst); ShowMCInst);

View File

@ -45,20 +45,20 @@ class MCAsmStreamer : public MCStreamer {
unsigned IsVerboseAsm : 1; unsigned IsVerboseAsm : 1;
unsigned ShowInst : 1; unsigned ShowInst : 1;
unsigned UseLoc : 1; unsigned UseLoc : 1;
unsigned UseCFI : 1;
bool needsSet(const MCExpr *Value); bool needsSet(const MCExpr *Value);
public: public:
MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os, MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
bool isVerboseAsm, bool isVerboseAsm, bool useLoc, bool useCFI,
bool useLoc,
MCInstPrinter *printer, MCCodeEmitter *emitter, MCInstPrinter *printer, MCCodeEmitter *emitter,
TargetAsmBackend *asmbackend, TargetAsmBackend *asmbackend,
bool showInst) bool showInst)
: MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend), InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm), CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
ShowInst(showInst), UseLoc(useLoc) { ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI) {
if (InstPrinter && IsVerboseAsm) if (InstPrinter && IsVerboseAsm)
InstPrinter->setCommentStream(CommentStream); InstPrinter->setCommentStream(CommentStream);
} }
@ -740,6 +740,9 @@ void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
void MCAsmStreamer::EmitCFIStartProc() { void MCAsmStreamer::EmitCFIStartProc() {
MCStreamer::EmitCFIStartProc(); MCStreamer::EmitCFIStartProc();
if (!UseCFI)
return;
OS << "\t.cfi_startproc"; OS << "\t.cfi_startproc";
EmitEOL(); EmitEOL();
} }
@ -747,6 +750,9 @@ void MCAsmStreamer::EmitCFIStartProc() {
void MCAsmStreamer::EmitCFIEndProc() { void MCAsmStreamer::EmitCFIEndProc() {
MCStreamer::EmitCFIEndProc(); MCStreamer::EmitCFIEndProc();
if (!UseCFI)
return;
OS << "\t.cfi_endproc"; OS << "\t.cfi_endproc";
EmitEOL(); EmitEOL();
} }
@ -754,6 +760,9 @@ void MCAsmStreamer::EmitCFIEndProc() {
void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
MCStreamer::EmitCFIDefCfa(Register, Offset); MCStreamer::EmitCFIDefCfa(Register, Offset);
if (!UseCFI)
return;
OS << ".cfi_def_cfa " << Register << ", " << Offset; OS << ".cfi_def_cfa " << Register << ", " << Offset;
EmitEOL(); EmitEOL();
} }
@ -761,6 +770,9 @@ void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) { void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
MCStreamer::EmitCFIDefCfaOffset(Offset); MCStreamer::EmitCFIDefCfaOffset(Offset);
if (!UseCFI)
return;
OS << "\t.cfi_def_cfa_offset " << Offset; OS << "\t.cfi_def_cfa_offset " << Offset;
EmitEOL(); EmitEOL();
} }
@ -768,6 +780,9 @@ void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) { void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
MCStreamer::EmitCFIDefCfaRegister(Register); MCStreamer::EmitCFIDefCfaRegister(Register);
if (!UseCFI)
return;
OS << "\t.cfi_def_cfa_register " << Register; OS << "\t.cfi_def_cfa_register " << Register;
EmitEOL(); EmitEOL();
} }
@ -775,6 +790,9 @@ void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
this->MCStreamer::EmitCFIOffset(Register, Offset); this->MCStreamer::EmitCFIOffset(Register, Offset);
if (!UseCFI)
return;
OS << "\t.cfi_offset " << Register << ", " << Offset; OS << "\t.cfi_offset " << Register << ", " << Offset;
EmitEOL(); EmitEOL();
} }
@ -783,6 +801,9 @@ void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
unsigned Encoding) { unsigned Encoding) {
MCStreamer::EmitCFIPersonality(Sym, Encoding); MCStreamer::EmitCFIPersonality(Sym, Encoding);
if (!UseCFI)
return;
OS << "\t.cfi_personality " << Encoding << ", " << *Sym; OS << "\t.cfi_personality " << Encoding << ", " << *Sym;
EmitEOL(); EmitEOL();
} }
@ -790,6 +811,9 @@ void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
MCStreamer::EmitCFILsda(Sym, Encoding); MCStreamer::EmitCFILsda(Sym, Encoding);
if (!UseCFI)
return;
OS << "\t.cfi_lsda " << Encoding << ", " << *Sym; OS << "\t.cfi_lsda " << Encoding << ", " << *Sym;
EmitEOL(); EmitEOL();
} }
@ -797,6 +821,9 @@ void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
void MCAsmStreamer::EmitCFIRememberState() { void MCAsmStreamer::EmitCFIRememberState() {
MCStreamer::EmitCFIRememberState(); MCStreamer::EmitCFIRememberState();
if (!UseCFI)
return;
OS << "\t.cfi_remember_state"; OS << "\t.cfi_remember_state";
EmitEOL(); EmitEOL();
} }
@ -804,6 +831,9 @@ void MCAsmStreamer::EmitCFIRememberState() {
void MCAsmStreamer::EmitCFIRestoreState() { void MCAsmStreamer::EmitCFIRestoreState() {
MCStreamer::EmitCFIRestoreState(); MCStreamer::EmitCFIRestoreState();
if (!UseCFI)
return;
OS << "\t.cfi_restore_state"; OS << "\t.cfi_restore_state";
EmitEOL(); EmitEOL();
} }
@ -811,6 +841,9 @@ void MCAsmStreamer::EmitCFIRestoreState() {
void MCAsmStreamer::EmitCFISameValue(int64_t Register) { void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
MCStreamer::EmitCFISameValue(Register); MCStreamer::EmitCFISameValue(Register);
if (!UseCFI)
return;
OS << "\t.cfi_same_value " << Register; OS << "\t.cfi_same_value " << Register;
EmitEOL(); EmitEOL();
} }
@ -818,6 +851,9 @@ void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
MCStreamer::EmitCFIRelOffset(Register, Offset); MCStreamer::EmitCFIRelOffset(Register, Offset);
if (!UseCFI)
return;
OS << "\t.cfi_rel_offset " << Register << ", " << Offset; OS << "\t.cfi_rel_offset " << Register << ", " << Offset;
EmitEOL(); EmitEOL();
} }
@ -825,6 +861,9 @@ void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
MCStreamer::EmitCFIAdjustCfaOffset(Adjustment); MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
if (!UseCFI)
return;
OS << "\t.cfi_adjust_cfa_offset " << Adjustment; OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
EmitEOL(); EmitEOL();
} }
@ -1008,8 +1047,9 @@ void MCAsmStreamer::Finish() {
MCStreamer *llvm::createAsmStreamer(MCContext &Context, MCStreamer *llvm::createAsmStreamer(MCContext &Context,
formatted_raw_ostream &OS, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useLoc, bool isVerboseAsm, bool useLoc,
bool useCFI,
MCInstPrinter *IP, MCCodeEmitter *CE, MCInstPrinter *IP, MCCodeEmitter *CE,
TargetAsmBackend *TAB, bool ShowInst) { TargetAsmBackend *TAB, bool ShowInst) {
return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, useCFI,
IP, CE, TAB, ShowInst); IP, CE, TAB, ShowInst);
} }

View File

@ -531,7 +531,7 @@ void PTXMCAsmStreamer::Finish() {}
namespace llvm { namespace llvm {
MCStreamer *createPTXAsmStreamer(MCContext &Context, MCStreamer *createPTXAsmStreamer(MCContext &Context,
formatted_raw_ostream &OS, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useLoc, bool isVerboseAsm, bool useLoc, bool useCFI,
MCInstPrinter *IP, MCInstPrinter *IP,
MCCodeEmitter *CE, TargetAsmBackend *TAB, MCCodeEmitter *CE, TargetAsmBackend *TAB,
bool ShowInst) { bool ShowInst) {

View File

@ -23,6 +23,7 @@ using namespace llvm;
namespace llvm { namespace llvm {
MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useLoc, bool isVerboseAsm, bool useLoc,
bool useCFI,
MCInstPrinter *InstPrint, MCInstPrinter *InstPrint,
MCCodeEmitter *CE, MCCodeEmitter *CE,
TargetAsmBackend *TAB, TargetAsmBackend *TAB,

View File

@ -227,7 +227,8 @@ TargetMachine::TargetMachine(const Target &T)
MCRelaxAll(false), MCRelaxAll(false),
MCNoExecStack(false), MCNoExecStack(false),
MCSaveTempLabels(false), MCSaveTempLabels(false),
MCUseLoc(true) { MCUseLoc(true),
MCUseCFI(true) {
// Typically it will be subtargets that will adjust FloatABIType from Default // Typically it will be subtargets that will adjust FloatABIType from Default
// to Soft or Hard. // to Soft or Hard.
if (UseSoftFloat) if (UseSoftFloat)

View File

@ -99,6 +99,9 @@ cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden, cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden,
cl::desc("Do not use .loc entries")); cl::desc("Do not use .loc entries"));
cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden,
cl::desc("Do not use .cfi_* directives"));
static cl::opt<bool> static cl::opt<bool>
DisableRedZone("disable-red-zone", DisableRedZone("disable-red-zone",
cl::desc("Do not emit code that uses the red zone."), cl::desc("Do not emit code that uses the red zone."),
@ -279,6 +282,9 @@ int main(int argc, char **argv) {
if (DisableDotLoc) if (DisableDotLoc)
Target.setMCUseLoc(false); Target.setMCUseLoc(false);
if (DisableCFI)
Target.setMCUseCFI(false);
// Disable .loc support for older OS X versions. // Disable .loc support for older OS X versions.
if (TheTriple.isMacOSX() && if (TheTriple.isMacOSX() &&
TheTriple.isMacOSXVersionLT(10, 6)) TheTriple.isMacOSXVersionLT(10, 6))

View File

@ -356,7 +356,8 @@ static int AssembleInput(const char *ProgName) {
TAB = TheTarget->createAsmBackend(TripleName); TAB = TheTarget->createAsmBackend(TripleName);
} }
Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true, Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true,
/*useLoc*/ true, IP, CE, TAB, /*useLoc*/ true,
/*useCFI*/ true, IP, CE, TAB,
ShowInst)); ShowInst));
} else if (FileType == OFT_Null) { } else if (FileType == OFT_Null) {
Str.reset(createNullStreamer(Ctx)); Str.reset(createNullStreamer(Ctx));