Convert DwarfWriter into a pass.

Now Users request DwarfWriter through getAnalysisUsage() instead of creating an instance of DwarfWriter object directly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61955 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2009-01-08 23:40:34 +00:00
parent 5d5ee80ea8
commit eb3fc28914
8 changed files with 83 additions and 76 deletions

View File

@ -20,6 +20,8 @@
#ifndef LLVM_CODEGEN_DWARFWRITER_H
#define LLVM_CODEGEN_DWARFWRITER_H
#include "llvm/Pass.h"
namespace llvm {
class AsmPrinter;
@ -35,7 +37,7 @@ class raw_ostream;
// DwarfWriter - Emits Dwarf debug and exception handling directives.
//
class DwarfWriter {
class DwarfWriter : public ImmutablePass {
private:
/// DD - Provides the DwarfWriter debug implementation.
///
@ -46,20 +48,19 @@ private:
DwarfException *DE;
public:
DwarfWriter(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T);
static char ID; // Pass identification, replacement for typeid
DwarfWriter();
virtual ~DwarfWriter();
/// SetModuleInfo - Set machine module info when it's known that pass manager
/// has created it. Set by the target AsmPrinter.
void SetModuleInfo(MachineModuleInfo *MMI);
//===--------------------------------------------------------------------===//
// Main entry points.
//
/// BeginModule - Emit all Dwarf sections that should come prior to the
/// content.
void BeginModule(Module *M);
void BeginModule(Module *M, MachineModuleInfo *MMI, raw_ostream &OS,
AsmPrinter *A, const TargetAsmInfo *T);
/// EndModule - Emit all Dwarf sections that should come after the content.
///

View File

@ -43,6 +43,10 @@
using namespace llvm;
using namespace llvm::dwarf;
static RegisterPass<DwarfWriter>
X("dwarfwriter", "DWARF Information Writer");
char DwarfWriter::ID = 0;
namespace llvm {
//===----------------------------------------------------------------------===//
@ -4897,10 +4901,7 @@ void DIE::dump() {
/// DwarfWriter Implementation
///
DwarfWriter::DwarfWriter(raw_ostream &OS, AsmPrinter *A,
const TargetAsmInfo *T) {
DE = new DwarfException(OS, A, T);
DD = new DwarfDebug(OS, A, T);
DwarfWriter::DwarfWriter() : ImmutablePass(&ID), DD(NULL), DE(NULL) {
}
DwarfWriter::~DwarfWriter() {
@ -4908,18 +4909,18 @@ DwarfWriter::~DwarfWriter() {
delete DD;
}
/// SetModuleInfo - Set machine module info when it's known that pass manager
/// has created it. Set by the target AsmPrinter.
void DwarfWriter::SetModuleInfo(MachineModuleInfo *MMI) {
DD->SetModuleInfo(MMI);
DE->SetModuleInfo(MMI);
}
/// BeginModule - Emit all Dwarf sections that should come prior to the
/// content.
void DwarfWriter::BeginModule(Module *M) {
void DwarfWriter::BeginModule(Module *M,
MachineModuleInfo *MMI,
raw_ostream &OS, AsmPrinter *A,
const TargetAsmInfo *T) {
DE = new DwarfException(OS, A, T);
DD = new DwarfDebug(OS, A, T);
DE->BeginModule(M);
DD->BeginModule(M);
DD->SetModuleInfo(MMI);
DE->SetModuleInfo(MMI);
}
/// EndModule - Emit all Dwarf sections that should come after the content.

View File

@ -44,12 +44,12 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
namespace {
struct VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter {
ARMAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
: AsmPrinter(O, TM, T), DW(O, this, T), MMI(NULL), AFI(NULL), MCP(NULL),
: AsmPrinter(O, TM, T), DW(0), MMI(NULL), AFI(NULL), MCP(NULL),
InCPMode(false) {
Subtarget = &TM.getSubtarget<ARMSubtarget>();
}
DwarfWriter DW;
DwarfWriter *DW;
MachineModuleInfo *MMI;
/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
@ -172,6 +172,7 @@ namespace {
AsmPrinter::getAnalysisUsage(AU);
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
AU.addRequired<DwarfWriter>();
}
};
} // end of anonymous namespace
@ -231,7 +232,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
if (Subtarget->isTargetDarwin()) {
// If the function is empty, then we need to emit *something*. Otherwise,
@ -262,7 +263,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
// Emit post-function debug information.
DW.EndFunction(&MF);
DW->EndFunction(&MF);
O.flush();
@ -776,15 +777,15 @@ void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
}
bool ARMAsmPrinter::doInitialization(Module &M) {
// Emit initial debug information.
DW.BeginModule(&M);
bool Result = AsmPrinter::doInitialization(M);
// AsmPrinter::doInitialization should have done this analysis.
// Emit initial debug information.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
DW.SetModuleInfo(MMI);
DW = getAnalysisToUpdate<DwarfWriter>();
assert(DW && "Dwarf Writer is not available");
DW->BeginModule(&M, MMI, O, this, TAI);
// Darwin wants symbols to be quoted if they have complex names.
if (Subtarget->isTargetDarwin())
@ -1012,7 +1013,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
// Emit initial debug information.
DW.EndModule();
DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
@ -1022,7 +1023,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
O << "\t.subsections_via_symbols\n";
} else {
// Emit final debug information for ELF.
DW.EndModule();
DW->EndModule();
}
return AsmPrinter::doFinalization(M);

View File

@ -288,13 +288,13 @@ namespace {
/// LinuxAsmPrinter - SPU assembly printer, customized for Linux
struct VISIBILITY_HIDDEN LinuxAsmPrinter : public SPUAsmPrinter {
DwarfWriter DW;
DwarfWriter *DW;
MachineModuleInfo *MMI;
LinuxAsmPrinter(raw_ostream &O, SPUTargetMachine &TM,
const TargetAsmInfo *T) :
SPUAsmPrinter(O, TM, T),
DW(O, this, T),
DW(0),
MMI(0)
{ }
@ -310,6 +310,7 @@ namespace {
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
AU.addRequired<DwarfWriter>();
SPUAsmPrinter::getAnalysisUsage(AU);
}
@ -456,7 +457,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
@ -479,7 +480,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// Emit post-function debug information.
DW.EndFunction(&MF);
DW->EndFunction(&MF);
// We didn't modify anything.
return false;
@ -490,9 +491,10 @@ bool LinuxAsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
SwitchToTextSection("\t.text");
// Emit initial debug information.
DW.BeginModule(&M);
DW = getAnalysisToUpdate<DwarfWriter>();
assert(DW && "Dwarf Writer is not available");
MMI = getAnalysisToUpdate<MachineModuleInfo>();
DW.SetModuleInfo(MMI);
DW->BeginModule(&M, MMI, O, this, TAI);
return Result;
}
@ -602,7 +604,7 @@ bool LinuxAsmPrinter::doFinalization(Module &M) {
// TODO
// Emit initial debug information.
DW.EndModule();
DW->EndModule();
return AsmPrinter::doFinalization(M);
}

View File

@ -292,13 +292,12 @@ namespace {
/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
struct VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
DwarfWriter DW;
DwarfWriter *DW;
MachineModuleInfo *MMI;
PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
const TargetAsmInfo *T)
: PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
: PPCAsmPrinter(O, TM, T), DW(0), MMI(0) {
}
virtual const char *getPassName() const {
@ -312,6 +311,7 @@ namespace {
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
@ -322,12 +322,12 @@ namespace {
/// OS X
struct VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
DwarfWriter DW;
DwarfWriter *DW;
MachineModuleInfo *MMI;
raw_ostream &OS;
PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
const TargetAsmInfo *T)
: PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
: PPCAsmPrinter(O, TM, T), DW(0), MMI(0), OS(O) {
}
virtual const char *getPassName() const {
@ -341,6 +341,7 @@ namespace {
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
@ -602,7 +603,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
@ -627,7 +628,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
SwitchToSection(TAI->SectionForGlobal(F));
// Emit post-function debug information.
DW.EndFunction(&MF);
DW->EndFunction(&MF);
O.flush();
@ -639,12 +640,11 @@ bool PPCLinuxAsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
// Emit initial debug information.
DW.BeginModule(&M);
// AsmPrinter::doInitialization should have done this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
DW.SetModuleInfo(MMI);
DW = getAnalysisToUpdate<DwarfWriter>();
assert(DW && "DwarfWriter is not available");
DW->BeginModule(&M, MMI, O, this, TAI);
// GNU as handles section names wrapped in quotes
Mang->setUseQuotes(true);
@ -753,7 +753,7 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
// TODO
// Emit initial debug information.
DW.EndModule();
DW->EndModule();
return AsmPrinter::doFinalization(M);
}
@ -792,7 +792,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
// If the function is empty, then we need to emit *something*. Otherwise, the
// function's label might be associated with something that it wasn't meant to
@ -821,7 +821,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// Emit post-function debug information.
DW.EndFunction(&MF);
DW->EndFunction(&MF);
// We didn't modify anything.
return false;
@ -854,13 +854,13 @@ bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
// Emit initial debug information.
DW.BeginModule(&M);
// We need this for Personality functions.
// AsmPrinter::doInitialization should have done this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
DW.SetModuleInfo(MMI);
DW = getAnalysisToUpdate<DwarfWriter>();
assert(DW && "DwarfWriter is not available");
DW->BeginModule(&M, MMI, O, this, TAI);
// Darwin wants symbols to be quoted if they have complex names.
Mang->setUseQuotes(true);
@ -1122,7 +1122,7 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
// Emit initial debug information.
DW.EndModule();
DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious

View File

@ -227,7 +227,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Emit pre-function debug and/or EH information.
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
// Print out code for the function.
bool hasAnyRealCode = false;
@ -260,7 +260,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Emit post-function debug information.
if (TAI->doesSupportDebugInformation())
DW.EndFunction(&MF);
DW->EndFunction(&MF);
// Print out jump tables referenced by the function.
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
@ -726,10 +726,6 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
/// doInitialization
bool X86ATTAsmPrinter::doInitialization(Module &M) {
if (TAI->doesSupportDebugInformation()) {
// Emit initial debug information.
DW.BeginModule(&M);
}
bool Result = AsmPrinter::doInitialization(M);
@ -738,7 +734,8 @@ bool X86ATTAsmPrinter::doInitialization(Module &M) {
// the MachineModuleInfo address on to DwarfWriter.
// AsmPrinter::doInitialization did this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
DW.SetModuleInfo(MMI);
DW = getAnalysisToUpdate<DwarfWriter>();
DW->BeginModule(&M, MMI, O, this, TAI);
}
// Darwin wants symbols to be quoted if they have complex names.
@ -973,7 +970,8 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
}
// Emit final debug information.
DW.EndModule();
DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
@ -992,10 +990,12 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
}
// Emit final debug information.
DW.EndModule();
DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
DW->EndModule();
} else if (Subtarget->isTargetELF()) {
// Emit final debug information.
DW.EndModule();
DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
DW->EndModule();
}
return AsmPrinter::doFinalization(M);

View File

@ -29,14 +29,13 @@ namespace llvm {
struct MachineJumpTableInfo;
struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
DwarfWriter DW;
DwarfWriter *DW;
MachineModuleInfo *MMI;
const X86Subtarget *Subtarget;
X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
const TargetAsmInfo *T)
: AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
: AsmPrinter(O, TM, T), DW(0), MMI(0) {
Subtarget = &TM.getSubtarget<X86Subtarget>();
}
@ -51,6 +50,7 @@ struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
Subtarget->isTargetCygMing()) {
AU.addRequired<MachineModuleInfo>();
}
AU.addRequired<DwarfWriter>();
AsmPrinter::getAnalysisUsage(AU);
}

View File

@ -56,10 +56,10 @@ namespace {
struct VISIBILITY_HIDDEN XCoreAsmPrinter : public AsmPrinter {
XCoreAsmPrinter(raw_ostream &O, XCoreTargetMachine &TM,
const TargetAsmInfo *T)
: AsmPrinter(O, TM, T), DW(O, this, T),
: AsmPrinter(O, TM, T), DW(0),
Subtarget(*TM.getSubtargetImpl()) { }
DwarfWriter DW;
DwarfWriter *DW;
const XCoreSubtarget &Subtarget;
virtual const char *getPassName() const {
@ -91,6 +91,7 @@ namespace {
AsmPrinter::getAnalysisUsage(AU);
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
AU.addRequired<DwarfWriter>();
}
};
} // end of anonymous namespace
@ -305,7 +306,7 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF)
emitFunctionStart(MF);
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
@ -332,7 +333,7 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF)
emitFunctionEnd(MF);
// Emit post-function debug information.
DW.EndFunction(&MF);
DW->EndFunction(&MF);
// We didn't modify anything.
return false;
@ -438,9 +439,10 @@ bool XCoreAsmPrinter::doInitialization(Module &M) {
}
// Emit initial debug information.
DW.BeginModule(&M);
DW.SetModuleInfo(getAnalysisToUpdate<MachineModuleInfo>());
DW = getAnalysisToUpdate<DwarfWriter>();
assert(DW && "Dwarf Writer is not available");
DW->BeginModule(&M, getAnalysisToUpdate<MachineModuleInfo>(),
O, this, TAI);
return Result;
}
@ -453,7 +455,7 @@ bool XCoreAsmPrinter::doFinalization(Module &M) {
}
// Emit final debug information.
DW.EndModule();
DW->EndModule();
return AsmPrinter::doFinalization(M);
}