From f646668799bd77ceebf73cd2f357d779f7abacf4 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 8 Jan 2009 23:40:34 +0000 Subject: [PATCH] Convert DwarfWriter into a pass. Now Users request DwarfWriter through getAnalysisUsage() instead of creating an instance of DwarfWriter object directly. llvm-svn: 61955 --- llvm/include/llvm/CodeGen/DwarfWriter.h | 15 ++++---- llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 25 ++++++------ .../Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 21 +++++----- .../CellSPU/AsmPrinter/SPUAsmPrinter.cpp | 16 ++++---- .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 38 +++++++++---------- .../X86/AsmPrinter/X86ATTAsmPrinter.cpp | 20 +++++----- .../Target/X86/AsmPrinter/X86ATTAsmPrinter.h | 6 +-- llvm/lib/Target/XCore/XCoreAsmPrinter.cpp | 18 +++++---- 8 files changed, 83 insertions(+), 76 deletions(-) diff --git a/llvm/include/llvm/CodeGen/DwarfWriter.h b/llvm/include/llvm/CodeGen/DwarfWriter.h index 8614eecfb05b..7ed5e612caea 100644 --- a/llvm/include/llvm/CodeGen/DwarfWriter.h +++ b/llvm/include/llvm/CodeGen/DwarfWriter.h @@ -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. /// diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 16d1531a47f8..6293590fd676 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -43,6 +43,10 @@ using namespace llvm; using namespace llvm::dwarf; +static RegisterPass +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. diff --git a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 97b4a1ba7ca2..27d28a65fbfd 100644 --- a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -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(); } - 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(); + AU.addRequired(); } }; } // 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(); assert(MMI); - DW.SetModuleInfo(MMI); + DW = getAnalysisToUpdate(); + 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); diff --git a/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index 98aa084d5045..31daab18d920 100644 --- a/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/llvm/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -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(); + AU.addRequired(); 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(); + assert(DW && "Dwarf Writer is not available"); MMI = getAnalysisToUpdate(); - 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); } diff --git a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 8b37167f4ad3..20589935fb62 100644 --- a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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(); + AU.addRequired(); 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(); + AU.addRequired(); 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(); assert(MMI); - DW.SetModuleInfo(MMI); + DW = getAnalysisToUpdate(); + 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(); assert(MMI); - DW.SetModuleInfo(MMI); + DW = getAnalysisToUpdate(); + 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 diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 76b1ddc2457a..e8a77a8d0348 100644 --- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -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(); - DW.SetModuleInfo(MMI); + DW = getAnalysisToUpdate(); + 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(); + 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(); + DW->EndModule(); } else if (Subtarget->isTargetELF()) { // Emit final debug information. - DW.EndModule(); + DwarfWriter *DW = getAnalysisToUpdate(); + DW->EndModule(); } return AsmPrinter::doFinalization(M); diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h index 40a5b4fb1d7e..3732ce86a864 100644 --- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h +++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h @@ -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(); } @@ -51,6 +50,7 @@ struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { Subtarget->isTargetCygMing()) { AU.addRequired(); } + AU.addRequired(); AsmPrinter::getAnalysisUsage(AU); } diff --git a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp index edd70468b416..0786f6186c49 100644 --- a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -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(); + AU.addRequired(); } }; } // 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()); + DW = getAnalysisToUpdate(); + assert(DW && "Dwarf Writer is not available"); + DW->BeginModule(&M, getAnalysisToUpdate(), + 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); }