Actually source file has already been uniquified into an id during isel. Eliminate...
[oota-llvm.git] / include / llvm / CodeGen / DebugLoc.h
1 //===---- llvm/CodeGen/DebugLoc.h - Debug Location Information --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a number of light weight data structures used by the code
11 // generator to describe and track debug location information.
12
13 #ifndef LLVM_CODEGEN_DEBUGLOC_H
14 #define LLVM_CODEGEN_DEBUGLOC_H
15
16 #include "llvm/ADT/DenseMap.h"
17 #include <vector>
18
19 namespace llvm {
20
21   /// DebugLocTuple - Debug location tuple of filename id, line and column.
22   ///
23   struct DebugLocTuple {
24     unsigned Src, Line, Col;
25
26     DebugLocTuple(unsigned s, unsigned l, unsigned c)
27       : Src(s), Line(l), Col(c) {};
28   };
29
30   /// DebugLoc - Debug location id. This is carried by SDNode and
31   /// MachineInstr to index into a vector of unique debug location tuples. 
32   class DebugLoc {
33     unsigned Idx;
34
35   public:
36     DebugLoc() : Idx(~0U) {}
37
38     static DebugLoc getNoDebugLoc()   { DebugLoc L; L.Idx = 0;   return L; }
39     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
40
41     bool isInvalid() { return Idx == ~0U; }
42     bool isUnknown() { return Idx == 0; }
43   };
44
45   struct DebugLocTupleDenseMapInfo {
46     static inline DebugLocTuple getEmptyKey() {
47       return DebugLocTuple(~0U, ~0U, ~0U);
48     }
49     static inline DebugLocTuple getTombstoneKey() {
50       return DebugLocTuple(~1U, ~1U, ~1U);
51     }
52     static unsigned getHashValue(const DebugLocTuple &Val) {
53       return DenseMapInfo<unsigned>::getHashValue(Val.Src) ^
54              DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
55              DenseMapInfo<unsigned>::getHashValue(Val.Col);
56     }
57     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
58       return LHS.Src  == RHS.Src &&
59              LHS.Line == RHS.Line &&
60              LHS.Col  == RHS.Col;
61     }
62
63     static bool isPod() { return true; }
64   };
65
66   typedef DenseMap<DebugLocTuple, unsigned, DebugLocTupleDenseMapInfo>
67     DebugIdMapType;
68     
69   /// DebugLocTracker - This class tracks debug location information.
70   ///
71   struct DebugLocTracker {
72     // NumDebugLocations - Size of the DebugLocations vector.
73     unsigned NumDebugLocations;
74
75     // DebugLocations - A vector of unique DebugLocTuple's.
76     //
77     std::vector<DebugLocTuple> DebugLocations;
78
79     // DebugIdsMap - This maps DebugLocTuple's to indices into
80     // DebugLocations vector.
81     DebugIdMapType DebugIdMap;
82
83     DebugLocTracker() : NumDebugLocations(0) {}
84
85     ~DebugLocTracker() {
86       DebugLocations.clear();
87       DebugIdMap.clear();
88     }
89   };
90   
91 } // end namespace llvm
92
93 #endif /* LLVM_CODEGEN_DEBUGLOC_H */