Convert DwarfWriter into a pass.
authorDevang Patel <dpatel@apple.com>
Thu, 8 Jan 2009 23:40:34 +0000 (23:40 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 8 Jan 2009 23:40:34 +0000 (23:40 +0000)
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

include/llvm/CodeGen/DwarfWriter.h
lib/CodeGen/AsmPrinter/DwarfWriter.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
lib/Target/XCore/XCoreAsmPrinter.cpp

index 8614eecfb05b6c6f1f9c34878d0fce8956c8773e..7ed5e612caea42eef60f1dc00deee7000eee7040 100644 (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.
   ///
index 16d1531a47f89d3d573f92872e566415d0f9f940..6293590fd67690c1e258c5920b05152374098355 100644 (file)
 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.
index 97b4a1ba7ca2947a188d17b4a4cb895efe73713f..27d28a65fbfd14ff0a8e9e0d66af13806c79f005 100644 (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);
index 98aa084d5045014611f196268da63e1f3eddcaa0..31daab18d920a27ef05a1e6e3507d9f67e15a389 100644 (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);
 }
index 8b37167f4ad3874a1adac59b7f6f274d939375b9..20589935fb62351c55eb0fd77296cd90837da9d0 100644 (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
index 76b1ddc2457a3042c500e2117d15050488781458..e8a77a8d034864e7b0b965972bc10606992a436a 100644 (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);
index 40a5b4fb1d7ec0e23e6e27340e669747b92eedc2..3732ce86a864f7703a5a44c5d3564f06f45af3bc 100644 (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);
   }
 
index edd70468b4167a090d862593638327188ce9c5e9..0786f6186c49df1d42b99da29b5da6cedd5bb44c 100644 (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);
 }