[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp DwarfWriter.cpp MachineDebugInfo.cpp

Jim Laskey jlaskey at apple.com
Wed Jan 4 14:28:39 PST 2006



Changes in directory llvm/lib/CodeGen:

AsmPrinter.cpp updated: 1.35 -> 1.36
DwarfWriter.cpp updated: 1.4 -> 1.5
MachineDebugInfo.cpp updated: 1.2 -> 1.3
---
Log message:

Applied some recommend changes from sabre.  The dominate one beginning "let the
pass manager do it's thing."  Fixes crash when compiling -g files and suppresses
dwarf statements if no debug info is present.


---
Diffs of the changes:  (+150 -89)

 AsmPrinter.cpp       |    1 
 DwarfWriter.cpp      |  132 +++++++++++++++++++++++++++++++++++++++++----------
 MachineDebugInfo.cpp |  106 ++++++++++++++++------------------------
 3 files changed, 150 insertions(+), 89 deletions(-)


Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.35 llvm/lib/CodeGen/AsmPrinter.cpp:1.36
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.35	Wed Jan  4 07:52:30 2006
+++ llvm/lib/CodeGen/AsmPrinter.cpp	Wed Jan  4 16:28:25 2006
@@ -16,7 +16,6 @@
 #include "llvm/Constants.h"
 #include "llvm/Module.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
-#include "llvm/CodeGen/MachineDebugInfo.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetMachine.h"


Index: llvm/lib/CodeGen/DwarfWriter.cpp
diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.4 llvm/lib/CodeGen/DwarfWriter.cpp:1.5
--- llvm/lib/CodeGen/DwarfWriter.cpp:1.4	Wed Jan  4 08:30:12 2006
+++ llvm/lib/CodeGen/DwarfWriter.cpp	Wed Jan  4 16:28:25 2006
@@ -11,32 +11,35 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/CodeGen/DwarfWriter.h"
 
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/CodeGen/DwarfWriter.h"
+#include "llvm/CodeGen/MachineDebugInfo.h"
 #include "llvm/Support/CommandLine.h"
 
+#include <iostream>
 
-namespace llvm {
+using namespace llvm;
 
 static cl::opt<bool>
 DwarfVerbose("dwarf-verbose", cl::Hidden,
                                 cl::desc("Add comments to dwarf directives."));
 
 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
-/// unsigned leb128 value.
+/// unsigned leb128 value.  Comment is added to the end of the directive if
+/// DwarfVerbose is true (should not contain any newlines.)
 ///
-void DwarfWriter::EmitULEB128Bytes(unsigned Value, std::string Comment) {
+void DwarfWriter::EmitULEB128Bytes(unsigned Value, const char *Comment) const {
   if (hasLEB128) {
     O << "\t.uleb128\t"
       << Value;
   } else {
-    O << Asm->getData8bitsDirective();
+    O << Asm->Data8bitsDirective;
     EmitULEB128(Value);
   }
   if (DwarfVerbose) {
     O << "\t"
-      << Asm->getCommentString()
+      << Asm->CommentString
       << " "
       << Comment
       << " "
@@ -46,19 +49,20 @@
 }
 
 /// EmitSLEB128Bytes - Emit an assembler byte data directive to compose a
-/// signed leb128 value.
+/// signed leb128 value.  Comment is added to the end of the directive if
+/// DwarfVerbose is true (should not contain any newlines.)
 ///
-void DwarfWriter::EmitSLEB128Bytes(int Value, std::string Comment) {
+void DwarfWriter::EmitSLEB128Bytes(int Value, const char *Comment) const {
   if (hasLEB128) {
     O << "\t.sleb128\t"
       << Value;
   } else {
-    O << Asm->getData8bitsDirective();
+    O << Asm->Data8bitsDirective;
     EmitSLEB128(Value);
   }
   if (DwarfVerbose) {
     O << "\t"
-      << Asm->getCommentString()
+      << Asm->CommentString
       << " "
       << Comment
       << " "
@@ -67,13 +71,75 @@
   O << "\n";
 }
 
-/// BeginModule - Emit all dwarf sections that should come prior to the content.
+/// EmitHex - Emit a hexidecimal string to the output stream.
 ///
-void DwarfWriter::BeginModule() {
-  if (!DebugInfo.hasInfo()) return;
-  EmitComment("Dwarf Begin Module");
+void DwarfWriter::EmitHex(unsigned Value) const {
+  O << "0x"
+    << std::hex
+    << Value
+    << std::dec;
+}
+
+/// EmitComment - Emit a simple string comment.
+///
+void DwarfWriter::EmitComment(const char *Comment) const {
+  O << "\t"
+    << Asm->CommentString
+    << " "
+    << Comment
+    << "\n";
+}
+
+/// EmitULEB128 - Emit a series of hexidecimal values (separated by commas)
+/// representing an unsigned leb128 value.
+///
+void DwarfWriter::EmitULEB128(unsigned Value) const {
+  do {
+    unsigned Byte = Value & 0x7f;
+    Value >>= 7;
+    if (Value) Byte |= 0x80;
+    EmitHex(Byte);
+    if (Value) O << ", ";
+  } while (Value);
+}
+
+/// EmitSLEB128 - Emit a series of hexidecimal values (separated by commas)
+/// representing a signed leb128 value.
+///
+void DwarfWriter::EmitSLEB128(int Value) const {
+  int Sign = Value >> (8 * sizeof(Value) - 1);
+  bool IsMore;
   
-  // define base addresses for dwarf sections
+  do {
+    unsigned Byte = Value & 0x7f;
+    Value >>= 7;
+    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
+    if (IsMore) Byte |= 0x80;
+    EmitHex(Byte);
+    if (IsMore) O << ", ";
+  } while (IsMore);
+}
+
+/// EmitLabelName - Emit label name for internal use by dwarf.
+///
+void DwarfWriter::EmitLabelName(const char *Tag, int Num) const {
+  O << Asm->PrivateGlobalPrefix
+    << "debug_"
+    << Tag
+    << Num;
+}
+
+/// EmitLabel - Emit location label for internal use by dwarf.
+///
+void DwarfWriter::EmitLabel(const char *Tag, int Num) const {
+  EmitLabelName(Tag, Num);
+  O << ":\n";
+}
+
+/// EmitInitial -Emit initial dwarf declarations.
+///
+void DwarfWriter::EmitInitial() const {
+  // Dwarf section's base addresses.
   Asm->SwitchSection(DwarfAbbrevSection, 0);
   EmitLabel("abbrev", 0);
   Asm->SwitchSection(DwarfInfoSection, 0);
@@ -82,33 +148,51 @@
   EmitLabel("line", 0);
 }
 
+/// ShouldEmitDwarf - Determine if dwarf declarations should be made.
+///
+bool DwarfWriter::ShouldEmitDwarf() {
+  // Check if debug info is present.
+  if (!DebugInfo || !DebugInfo->hasInfo()) return false;
+  
+  // Make sure initial declarations are made.
+  if (!didInitial) {
+    EmitInitial();
+    didInitial = true;
+  }
+  
+  // Okay to emit.
+  return true;
+}
+
+/// BeginModule - Emit all dwarf sections that should come prior to the content.
+///
+void DwarfWriter::BeginModule() {
+  if (!ShouldEmitDwarf()) return;
+  EmitComment("Dwarf Begin Module");
+}
+
 /// EndModule - Emit all dwarf sections that should come after the content.
 ///
 void DwarfWriter::EndModule() {
-  if (!DebugInfo.hasInfo()) return;
+  if (!ShouldEmitDwarf()) return;
   EmitComment("Dwarf End Module");
   // Print out dwarf file info
-  std::vector<std::string> Sources = DebugInfo.getSourceFiles();
+  std::vector<std::string> Sources = DebugInfo->getSourceFiles();
   for (unsigned i = 0, N = Sources.size(); i < N; i++) {
     O << "\t; .file\t" << (i + 1) << "," << "\"" << Sources[i]  << "\"" << "\n";
   }
 }
 
-
 /// BeginFunction - Emit pre-function debug information.
 ///
 void DwarfWriter::BeginFunction() {
-  if (!DebugInfo.hasInfo()) return;
+  if (!ShouldEmitDwarf()) return;
   EmitComment("Dwarf Begin Function");
 }
 
 /// EndFunction - Emit post-function debug information.
 ///
 void DwarfWriter::EndFunction() {
-  if (!DebugInfo.hasInfo()) return;
+  if (!ShouldEmitDwarf()) return;
   EmitComment("Dwarf End Function");
 }
-
-
-} // End llvm namespace
-


Index: llvm/lib/CodeGen/MachineDebugInfo.cpp
diff -u llvm/lib/CodeGen/MachineDebugInfo.cpp:1.2 llvm/lib/CodeGen/MachineDebugInfo.cpp:1.3
--- llvm/lib/CodeGen/MachineDebugInfo.cpp:1.2	Wed Jan  4 09:04:11 2006
+++ llvm/lib/CodeGen/MachineDebugInfo.cpp	Wed Jan  4 16:28:25 2006
@@ -18,74 +18,52 @@
 
 // Handle the Pass registration stuff necessary to use TargetData's.
 namespace {
-  RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information",
-                                  PassInfo::Analysis | PassInfo::Optimization);
+  RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
 }
-
-namespace llvm {
-  
-  /// DebugInfo - Keep track of debug information for the function.
-  ///
-  // FIXME - making it global until we can find a proper place to hang it from.
-  MachineDebugInfo *DebugInfo;
-
-  // FIXME - temporary hack until we can find a place to hand debug info from.
-  ModulePass *createDebugInfoPass() {
-    if (!DebugInfo) DebugInfo = new MachineDebugInfo();
-    return (ModulePass *)DebugInfo;
-  }
   
-  /// getDebugInfo - Returns the DebugInfo.
-  MachineDebugInfo &getMachineDebugInfo() {
-    assert(DebugInfo && "DebugInfo pass not created");
-    return *DebugInfo;
-  }
-
-  /// doInitialization - Initialize the debug state for a new module.
-  ///
-  bool MachineDebugInfo::doInitialization() {
-    return true;
-  }
+/// doInitialization - Initialize the debug state for a new module.
+///
+bool MachineDebugInfo::doInitialization() {
+  return false;
+}
 
-  /// doFinalization - Tear down the debug state after completion of a module.
-  ///
-  bool MachineDebugInfo::doFinalization() {
-    
-    return true;
-  }
+/// doFinalization - Tear down the debug state after completion of a module.
+///
+bool MachineDebugInfo::doFinalization() {
+  return false;
+}
 
-  /// RecordSource - Register a source file with debug info.  Returns an id.
-  ///
-  unsigned MachineDebugInfo::RecordSource(std::string fname,
-                                          std::string dirname) {
-    // Compose a key
-    std::string path = dirname + "/" + fname;
-    // Check if the source file is already recorded
-    StrIntMapIter SMI = SourceMap.find(path);
-    // If already there return existing id
-    if (SMI != SourceMap.end()) return SMI->second;
-    // Bump up the count
-    ++SourceCount;
-    // Record the count
-    SourceMap[path] = SourceCount;
-    // Return id
-    return SourceCount;
-  }
+/// getUniqueSourceID - Register a source file with debug info.  Returns an id.
+///
+unsigned MachineDebugInfo::getUniqueSourceID(const std::string &fname,
+                                             const std::string &dirname) {
+  // Compose a key
+  const std::string path = dirname + "/" + fname;
+  // Check if the source file is already recorded
+  std::map<std::string, unsigned>::iterator
+      SMI = SourceMap.lower_bound(path);
+  // If already there return existing id
+  if (SMI != SourceMap.end() && SMI->first == path) return SMI->second;
+  // Bump up the count
+  ++SourceCount;
+  // Record the count
+  SourceMap.insert(SMI, std::make_pair(path, SourceCount));
+  // Return id
+  return SourceCount;
+}
 
-  /// getSourceFiles - Return a vector of files.  Vector index + 1 equals id.
-  ///
-  std::vector<std::string> MachineDebugInfo::getSourceFiles() {
-    std::vector<std::string> Sources(SourceCount);
-    
-    for (StrIntMapIter SMI = SourceMap.begin(), E = SourceMap.end(); SMI != E;
-                       SMI++) {
-      unsigned Index = SMI->second - 1;
-      std::string Path = SMI->first;
-      Sources[Index] = Path;
-    }
-    return Sources;
+/// getSourceFiles - Return a vector of files.  Vector index + 1 equals id.
+///
+std::vector<std::string> MachineDebugInfo::getSourceFiles() const {
+  std::vector<std::string> Sources(SourceCount);
+  
+  for (std::map<std::string, unsigned>::const_iterator SMI = SourceMap.begin(),
+                                                       E = SourceMap.end();
+                                                       SMI != E; SMI++) {
+    unsigned Index = SMI->second - 1;
+    const std::string &Path = SMI->first;
+    Sources[Index] = Path;
   }
-
-
-};
+  return Sources;
+}
 






More information about the llvm-commits mailing list