Refine DebugLoc per review comments.
authorEvan Cheng <evan.cheng@apple.com>
Tue, 27 Jan 2009 21:15:07 +0000 (21:15 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 27 Jan 2009 21:15:07 +0000 (21:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63132 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/DebugLoc.h
include/llvm/CodeGen/MachineFunction.h
lib/CodeGen/MachineFunction.cpp

index baf6583a8ba7ba813fa4d136307e75d8a6cd13a9..89c51c443b05f2b696b12c1d6bd7bdb0d209ef39 100644 (file)
@@ -33,16 +33,21 @@ namespace llvm {
     unsigned Idx;
 
   public:
-    DebugLoc() : Idx(~0U) {}
+    DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
 
-    static DebugLoc getNoDebugLoc()   { DebugLoc L; L.Idx = 0;   return L; }
+    static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = 0;   return L; }
     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
 
-    bool isInvalid() { return Idx == ~0U; }
-    bool isUnknown() { return Idx == 0; }
+    // isInvalid - Return true if the DebugLoc is invalid.
+    bool isInvalid() const { return Idx == ~0U; }
+
+    // isUnknown - Return true if there is no debug info for the SDNode /
+    // MachineInstr.
+    bool isUnknown() const { return Idx == 0; }
   };
 
-  struct DebugLocTupleDenseMapInfo {
+  // Partially specialize DenseMapInfo for DebugLocTyple.
+  template<>  struct DenseMapInfo<DebugLocTuple> {
     static inline DebugLocTuple getEmptyKey() {
       return DebugLocTuple(~0U, ~0U, ~0U);
     }
@@ -63,9 +68,6 @@ namespace llvm {
     static bool isPod() { return true; }
   };
 
-  typedef DenseMap<DebugLocTuple, unsigned, DebugLocTupleDenseMapInfo>
-    DebugIdMapType;
-    
   /// DebugLocTracker - This class tracks debug location information.
   ///
   struct DebugLocTracker {
@@ -75,7 +77,7 @@ namespace llvm {
 
     // DebugIdsMap - This maps DebugLocTuple's to indices into
     // DebugLocations vector.
-    DebugIdMapType DebugIdMap;
+    DenseMap<DebugLocTuple, unsigned> DebugIdMap;
 
     DebugLocTracker() {}
 
index 4fa70fca6facec22a4da7a1acdacb01370f33d9b..0d5a71d142d7aafd3f7e400962b6a8bde2360871 100644 (file)
@@ -311,10 +311,10 @@ public:
   // Debug location.
   //
 
-  /// lookUpDebugLocId - Look up the DebugLocTuple index with the given
-  /// source file, line, and column. It may add a new filename and / or
-  /// a new DebugLocTuple.
-  unsigned lookUpDebugLocId(unsigned Src, unsigned Line, unsigned Col);
+  /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
+  /// source file, line, and column. If none currently exists, create add a new
+  /// new DebugLocTuple and insert it into the DebugIdMap.
+  unsigned getOrCreateDebugLocID(unsigned Src, unsigned Line, unsigned Col);
 };
 
 //===--------------------------------------------------------------------===//
index abd84ecbd5c353fc13f8e6c920025897b096bb31..b303b1b58c92b989bb0bd3b34bb1249e4dfa8380 100644 (file)
@@ -378,13 +378,14 @@ MachineFunction& MachineFunction::get(const Function *F)
   return *mc;
 }
 
-/// lookUpDebugLocId - Look up the DebugLocTuple index with the given
-/// source file, line, and column. It may add a new filename and / or
-/// a new DebugLocTuple.
-unsigned MachineFunction::lookUpDebugLocId(unsigned Src, unsigned Line,
-                                           unsigned Col) {
+/// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
+/// source file, line, and column. If none currently exists, create add a new
+/// new DebugLocTuple and insert it into the DebugIdMap.
+unsigned MachineFunction::getOrCreateDebugLocID(unsigned Src, unsigned Line,
+                                                unsigned Col) {
   struct DebugLocTuple Tuple(Src, Line, Col);
-  DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple);
+  DenseMap<DebugLocTuple, unsigned>::iterator II
+    = DebugLocInfo.DebugIdMap.find(Tuple);
   if (II != DebugLocInfo.DebugIdMap.end())
     return II->second;
   // Add a new tuple.