<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 25, 2009, at 11:41 PM, Evan Cheng wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Author: evancheng<br>Date: Mon Jan 26 01:41:49 2009<br>New Revision: 63008<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=63008&view=rev">http://llvm.org/viewvc/llvm-project?rev=63008&view=rev</a><br>Log:<br>Add data structure to define and track debug location during codegen.<br><br>Added:<br>    llvm/trunk/include/llvm/CodeGen/DebugLoc.h<br>Modified:<br>    llvm/trunk/include/llvm/CodeGen/MachineFunction.h<br>    llvm/trunk/lib/CodeGen/MachineFunction.cpp<br><br>Added: llvm/trunk/include/llvm/CodeGen/DebugLoc.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DebugLoc.h?rev=63008&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DebugLoc.h?rev=63008&view=auto</a><br><br>==============================================================================<br>--- llvm/trunk/include/llvm/CodeGen/DebugLoc.h (added)<br>+++ llvm/trunk/include/llvm/CodeGen/DebugLoc.h Mon Jan 26 01:41:49 2009<br>@@ -0,0 +1,109 @@<br>+//===---- llvm/CodeGen/DebugLoc.h - Debug Location Information --*- C++ -*-===//<br>+//<br>+//                     The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+//<br>+// This file defines a number of light weight data structures used by the code<br>+// generator to describe and track debug location information.<br>+<br>+#ifndef LLVM_CODEGEN_DEBUGLOC_H<br>+#define LLVM_CODEGEN_DEBUGLOC_H<br>+<br>+#include "llvm/ADT/DenseMap.h"<br>+#include "llvm/ADT/StringMap.h"<br>+#include <vector><br>+<br>+namespace llvm {<br>+<br>+  /// DebugLocTuple - Debug location tuple of filename id, line and column.<br>+  ///<br>+  struct DebugLocTuple {<br>+    unsigned FileId, Line, Col;<br>+<br>+    DebugLocTuple(unsigned fi, unsigned l, unsigned c)<br>+      : FileId(fi), Line(l), Col(c) {};<br>+  };<br>+</div></blockquote><div><br></div>Why not use SourceLineInfo directly instead of introducing DebugLocTuple ? </div><div><br></div><div><div>//===----------------------------------------------------------------------===//                 </div><div>/// SourceLineInfo - This class is used to record source line correspondence.                    </div><div>///                                                                                              </div><div>class SourceLineInfo {</div><div>  unsigned Line;                        // Source line number.                                   </div><div>  unsigned Column;                      // Source column.                                        </div><div>  unsigned SourceID;                    // Source ID number.                                     </div><div>  unsigned LabelID;                     // Label in code ID number.                              </div><div>public</div><div>...</div><div><br></div><div>SourceLineInfo is managed using UniqueVector in DwarfWriter. Is there a known reason to use DenseMap ? I'm just curious<span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; white-space: pre; "><span class="Apple-style-span" style="font-family: Verdana; font-size: 11px; white-space: normal; ">. </span></span></div><div><br></div><div>-</div><div>Devan</div><div><br></div><blockquote type="cite"><div><br>+  /// DebugLoc - Debug location id. This is carried by SDNode and<br>+  /// MachineInstr to index into a vector of unique debug location tuples. <br>+  class DebugLoc {<br>+    unsigned Idx;<br>+<br>+  public:<br>+    DebugLoc() : Idx(~0U) {}<br>+<br>+    static DebugLoc getNoDebugLoc()   { DebugLoc L; L.Idx = 0;   return L; }<br>+    static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }<br>+<br>+    bool isInvalid() { return Idx == ~0U; }<br>+    bool isUnknown() { return Idx == 0; }<br>+  };<br>+<br>+  struct DebugLocTupleDenseMapInfo {<br>+    static inline DebugLocTuple getEmptyKey() {<br>+      return DebugLocTuple(~0U, ~0U, ~0U);<br>+    }<br>+    static inline DebugLocTuple getTombstoneKey() {<br>+      return DebugLocTuple(~1U, ~1U, ~1U);<br>+    }<br>+    static unsigned getHashValue(const DebugLocTuple &Val) {<br>+      return DenseMapInfo<unsigned>::getHashValue(Val.FileId) ^<br>+             DenseMapInfo<unsigned>::getHashValue(Val.Line) ^<br>+             DenseMapInfo<unsigned>::getHashValue(Val.Col);<br>+    }<br>+    static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {<br>+      return LHS.FileId == RHS.FileId &&<br>+             LHS.Line == RHS.Line &&<br>+             LHS.Col == RHS.Col;<br>+    }<br>+<br>+    static bool isPod() { return true; }<br>+  };<br>+<br>+  typedef DenseMap<DebugLocTuple, unsigned, DebugLocTupleDenseMapInfo><br>+    DebugIdMapType;<br>+    <br>+  /// DebugLocTracker - This class tracks debug location information.<br>+  ///<br>+  struct DebugLocTracker {<br>+    // NumFilenames - Size of the DebugFilenames vector.<br>+    //<br>+    unsigned NumFilenames;<br>+    <br>+    // DebugFilenames - A vector of unique file names.<br>+    //<br>+    std::vector<std::string> DebugFilenames;<br>+<br>+    // DebugFilenamesMap - File name to DebugFilenames index map.<br>+    //<br>+    StringMap<unsigned> DebugFilenamesMap;<br>+<br>+    // NumDebugLocations - Size of the DebugLocations vector.<br>+    unsigned NumDebugLocations;<br>+<br>+    // DebugLocations - A vector of unique DebugLocTuple's.<br>+    //<br>+    std::vector<DebugLocTuple> DebugLocations;<br>+<br>+    // DebugIdsMap - This maps DebugLocTuple's to indices into<br>+    // DebugLocations vector.<br>+    DebugIdMapType DebugIdMap;<br>+<br>+    DebugLocTracker() : NumFilenames(0), NumDebugLocations(0) {}<br>+<br>+    ~DebugLocTracker() {<br>+      NumFilenames = 0;<br>+      DebugFilenames.clear();<br>+      DebugFilenamesMap.clear();<br>+      DebugLocations.clear();<br>+      DebugIdMap.clear();<br>+    }<br>+  };<br>+  <br>+} // end namespace llvm<br>+<br>+#endif /* LLVM_CODEGEN_DEBUGLOC_H */<br><br>Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=63008&r1=63007&r2=63008&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=63008&r1=63007&r2=63008&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)<br>+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Mon Jan 26 01:41:49 2009<br>@@ -19,6 +19,7 @@<br> #define LLVM_CODEGEN_MACHINEFUNCTION_H<br><br> #include "llvm/ADT/ilist.h"<br>+#include "llvm/CodeGen/DebugLoc.h"<br> #include "llvm/CodeGen/MachineBasicBlock.h"<br> #include "llvm/Support/Annotation.h"<br> #include "llvm/Support/Allocator.h"<br>@@ -27,11 +28,11 @@<br> namespace llvm {<br><br> class Function;<br>-class TargetMachine;<br> class MachineRegisterInfo;<br> class MachineFrameInfo;<br> class MachineConstantPool;<br> class MachineJumpTableInfo;<br>+class TargetMachine;<br><br> template <><br> struct ilist_traits<MachineBasicBlock><br>@@ -94,6 +95,9 @@<br>   typedef ilist<MachineBasicBlock> BasicBlockListType;<br>   BasicBlockListType BasicBlocks;<br><br>+  // Tracks debug locations.<br>+  DebugLocTracker DebugLocInfo;<br>+<br> public:<br>   MachineFunction(const Function *Fn, const TargetMachine &TM);<br>   ~MachineFunction();<br>@@ -302,6 +306,15 @@<br>   /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.<br>   ///<br>   void DeleteMachineBasicBlock(MachineBasicBlock *MBB);<br>+<br>+  //===--------------------------------------------------------------------===//<br>+  // Debug location.<br>+  //<br>+<br>+  /// lookUpDebugLocId - Look up the DebugLocTuple index with the given<br>+  /// filename, line, and column. It may add a new filename and / or<br>+  /// a new DebugLocTuple.<br>+  unsigned lookUpDebugLocId(const char *Filename, unsigned Line, unsigned Col);<br> };<br><br> //===--------------------------------------------------------------------===//<br><br>Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=63008&r1=63007&r2=63008&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=63008&r1=63007&r2=63008&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Mon Jan 26 01:41:49 2009<br>@@ -378,6 +378,33 @@<br>   return *mc;<br> }<br><br>+/// lookUpDebugLocId - Look up the DebugLocTuple index with the given<br>+/// filename, line, and column. It may add a new filename and / or<br>+/// a new DebugLocTuple.<br>+unsigned MachineFunction::lookUpDebugLocId(const char *Filename, unsigned Line,<br>+                                           unsigned Col) {<br>+  unsigned FileId;<br>+  StringMap<unsigned>::iterator I =<br>+    DebugLocInfo.DebugFilenamesMap.find(Filename);<br>+  if (I != DebugLocInfo.DebugFilenamesMap.end())<br>+    FileId = I->second;<br>+  else {<br>+    // Add a new filename.<br>+    FileId = DebugLocInfo.NumFilenames++;<br>+    DebugLocInfo.DebugFilenames.push_back(Filename);<br>+    DebugLocInfo.DebugFilenamesMap[Filename] = FileId;<br>+  }<br>+<br>+  struct DebugLocTuple Tuple(FileId, Line, Col);<br>+  DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple);<br>+  if (II != DebugLocInfo.DebugIdMap.end())<br>+    return II->second;<br>+  // Add a new tuple.<br>+  DebugLocInfo.DebugLocations.push_back(Tuple);<br>+  DebugLocInfo.DebugIdMap[Tuple] = DebugLocInfo.NumDebugLocations;<br>+  return DebugLocInfo.NumDebugLocations++;<br>+}<br>+<br> //===----------------------------------------------------------------------===//<br> //  MachineFrameInfo implementation<br> //===----------------------------------------------------------------------===//<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></div></blockquote></div><br></body></html>