More complete solution to deleting blocks and debug info.
authorJim Laskey <jlaskey@mac.com>
Mon, 23 Oct 2006 14:56:37 +0000 (14:56 +0000)
committerJim Laskey <jlaskey@mac.com>
Mon, 23 Oct 2006 14:56:37 +0000 (14:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31129 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineDebugInfo.h
lib/CodeGen/BranchFolding.cpp
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/MachineDebugInfo.cpp

index c1134d06afb23f13bbbbf44cc11a32a115fda590..940adb7899691426259933fe3972bf4bee333196 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
 #define LLVM_CODEGEN_MACHINEDEBUGINFO_H
 
+#include <set>
+
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/UniqueVector.h"
@@ -979,6 +981,10 @@ private:
   //
   DebugScope *RootScope;
   
+  // DeletedLabelIDs - List of label IDs that have been removed from the
+  // module.
+  std::set<unsigned> DeletedLabelIDs;
+  
   // FrameMoves - List of moves done by a function's prolog.  Used to construct
   // frame maps by debug consumers.
   std::vector<MachineMove *> FrameMoves;
@@ -1029,11 +1035,14 @@ public:
   /// provide correspondence to the source line list.
   unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
   
-  /// RemoveLabelInfo - Remove the specified label # from MachineDebugInfo, for
-  /// example because the code was deleted.
-  void RemoveLabelInfo(unsigned LabelUID);
-  
+  /// InvalidateLabel - Inhibit use of the specified label # from
+  /// MachineDebugInfo, for example because the code was deleted.
+  void InvalidateLabel(unsigned LabelID);
   
+  /// isLabelValid - Check to make sure the label is still valid before
+  /// attempting to use.
+  bool isLabelValid(unsigned LabelID);
+
   /// RecordSource - Register a source file with debug info. Returns an source
   /// ID.
   unsigned RecordSource(const std::string &Directory,
index 0752e3c9f73e1ba5b3832f1eac499045730893bb..4643c7414ff4965c61b46ef32d14125862791c3e 100644 (file)
@@ -75,7 +75,7 @@ void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
          I != E; ++I) {
       if ((unsigned)I->getOpcode() == DWARF_LABELOpc) {
         // The label ID # is always operand #0, an immediate.
-        MDI->RemoveLabelInfo(I->getOperand(0).getImm());
+        MDI->InvalidateLabel(I->getOperand(0).getImm());
       }
     }
   }
index dc59b8106826443e373a6905861a0f6239d4e294..c600edbdf831b943e58d59d86850768a262370e6 100644 (file)
@@ -1755,17 +1755,24 @@ void DwarfWriter::ConstructScope(DebugScope *ParentScope,
     // FIXME - Ignore inlined functions for the time being.
     if (!Scope->getParent()) continue;
     
+    unsigned StartID = Scope->getStartLabelID();
+    unsigned EndID = Scope->getEndLabelID();
+    
+    // Throw out scope if block is discarded.
+    if (StartID && !DebugInfo->isLabelValid(StartID)) continue;
+    if (EndID && !DebugInfo->isLabelValid(EndID)) continue;
+    
     DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
     
     // Add the scope bounds.
-    if (unsigned StartID = Scope->getStartLabelID()) {
+    if (StartID) {
       ScopeDie->AddLabel(DW_AT_low_pc, DW_FORM_addr,
                          DWLabel("loc", StartID));
     } else {
       ScopeDie->AddLabel(DW_AT_low_pc, DW_FORM_addr,
                          DWLabel("func_begin", SubprogramCount));
     }
-    if (unsigned EndID = Scope->getEndLabelID()) {
+    if (EndID) {
       ScopeDie->AddLabel(DW_AT_high_pc, DW_FORM_addr,
                          DWLabel("loc", EndID));
     } else {
@@ -1975,6 +1982,10 @@ void DwarfWriter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
   for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
     MachineMove *Move = Moves[i];
     unsigned LabelID = Move->getLabelID();
+    
+    // Throw out move if the label is invalid.
+    if (LabelID && !DebugInfo->isLabelValid(LabelID)) continue;
+    
     const MachineLocation &Dst = Move->getDestination();
     const MachineLocation &Src = Move->getSource();
     
@@ -2194,6 +2205,10 @@ void DwarfWriter::EmitDebugLines() const {
     // Construct rows of the address, source, line, column matrix.
     for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
       const SourceLineInfo &LineInfo = LineInfos[i];
+      unsigned LabelID = LineInfo.getLabelID();
+      
+      // Throw out line info if label is invalid.
+      if (!DebugInfo->isLabelValid(LabelID)) continue;
       
       if (DwarfVerbose) {
         unsigned SourceID = LineInfo.getSourceID();
@@ -2210,7 +2225,7 @@ void DwarfWriter::EmitDebugLines() const {
       EmitInt8(0); EOL("Extended Op");
       EmitInt8(4 + 1); EOL("Op size");
       EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
-      EmitReference("loc",  LineInfo.getLabelID()); EOL("Location label");
+      EmitReference("loc",  LabelID); EOL("Location label");
       
       // If change of source, then switch to the new source.
       if (Source != LineInfo.getSourceID()) {
index a1f4f1338b20bf188296335c3452580d5dd4d1b8..380b8a9656d3f3e4d6067c306a72d8d6817f0ddb 100644 (file)
@@ -1451,6 +1451,7 @@ MachineDebugInfo::MachineDebugInfo()
 , LabelID(0)
 , ScopeMap()
 , RootScope(NULL)
+, DeletedLabelIDs()
 , FrameMoves()
 {}
 MachineDebugInfo::~MachineDebugInfo() {
@@ -1543,20 +1544,18 @@ unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column,
   return ID;
 }
 
-static bool LabelUIDComparison(const SourceLineInfo &LI, unsigned UID) {
-  return LI.getLabelID() < UID;
+/// InvalidateLabel - Inhibit use of the specified label # from
+/// MachineDebugInfo, for example because the code was deleted.
+void MachineDebugInfo::InvalidateLabel(unsigned LabelID) {
+  DeletedLabelIDs.insert(LabelID);
 }
 
-/// RemoveLabelInfo - Remove the specified label # from MachineDebugInfo, for
-/// example because the code was deleted.
-void MachineDebugInfo::RemoveLabelInfo(unsigned LabelUID) {
-  std::vector<SourceLineInfo>::iterator I =
-    std::lower_bound(Lines.begin(), Lines.end(), LabelUID, LabelUIDComparison);
-  assert(I != Lines.end() && "Didn't find label UID in MachineDebugInfo!");
-  Lines.erase(I);
+/// isLabelValid - Check to make sure the label is still valid before
+/// attempting to use.
+bool MachineDebugInfo::isLabelValid(unsigned LabelID) {
+  return DeletedLabelIDs.find(LabelID) == DeletedLabelIDs.end();
 }
 
-
 /// RecordSource - Register a source file with debug info. Returns an source
 /// ID.
 unsigned MachineDebugInfo::RecordSource(const std::string &Directory,