Remove isPod() from DenseMapInfo, splitting it out to its own
[oota-llvm.git] / include / llvm / Support / DebugLoc.h
1 //===---- llvm/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
11 // to describe and track debug location information.
12 // 
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_DEBUGLOC_H
16 #define LLVM_DEBUGLOC_H
17
18 #include "llvm/ADT/DenseMap.h"
19 #include <vector>
20
21 namespace llvm {
22   class MDNode;
23
24   /// DebugLocTuple - Debug location tuple of filename id, line and column.
25   ///
26   struct DebugLocTuple {
27     MDNode *Scope;
28     MDNode *InlinedAtLoc;
29     unsigned Line, Col;
30
31     DebugLocTuple()
32       : Scope(0), InlinedAtLoc(0), Line(~0U), Col(~0U) {}
33
34     DebugLocTuple(MDNode *n, MDNode *i, unsigned l, unsigned c)
35       : Scope(n), InlinedAtLoc(i), Line(l), Col(c) {}
36
37     bool operator==(const DebugLocTuple &DLT) const {
38       return Scope == DLT.Scope &&
39         InlinedAtLoc == DLT.InlinedAtLoc &&
40         Line == DLT.Line && Col == DLT.Col;
41     }
42     bool operator!=(const DebugLocTuple &DLT) const {
43       return !(*this == DLT);
44     }
45   };
46
47   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
48   /// to index into a vector of unique debug location tuples.
49   class DebugLoc {
50     unsigned Idx;
51
52   public:
53     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
54
55     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
56     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
57
58     unsigned getIndex() const { return Idx; }
59
60     /// isUnknown - Return true if there is no debug info for the SDNode /
61     /// MachineInstr.
62     bool isUnknown() const { return Idx == ~0U; }
63
64     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
65     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
66   };
67
68   // Specialize DenseMapInfo for DebugLocTuple.
69   template<> struct DenseMapInfo<DebugLocTuple> {
70     static inline DebugLocTuple getEmptyKey() {
71       return DebugLocTuple(0, 0, ~0U, ~0U);
72     }
73     static inline DebugLocTuple getTombstoneKey() {
74       return DebugLocTuple((MDNode*)~1U, (MDNode*)~1U, ~1U, ~1U);
75     }
76     static unsigned getHashValue(const DebugLocTuple &Val) {
77       return DenseMapInfo<MDNode*>::getHashValue(Val.Scope) ^
78              DenseMapInfo<MDNode*>::getHashValue(Val.InlinedAtLoc) ^
79              DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
80              DenseMapInfo<unsigned>::getHashValue(Val.Col);
81     }
82     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
83       return LHS.Scope        == RHS.Scope &&
84              LHS.InlinedAtLoc == RHS.InlinedAtLoc &&
85              LHS.Line         == RHS.Line &&
86              LHS.Col          == RHS.Col;
87     }
88   };
89   template <> struct isPodLike<DebugLocTuple> {static const bool value = true;};
90
91
92   /// DebugLocTracker - This class tracks debug location information.
93   ///
94   struct DebugLocTracker {
95     /// DebugLocations - A vector of unique DebugLocTuple's.
96     ///
97     std::vector<DebugLocTuple> DebugLocations;
98
99     /// DebugIdMap - This maps DebugLocTuple's to indices into the
100     /// DebugLocations vector.
101     DenseMap<DebugLocTuple, unsigned> DebugIdMap;
102
103     DebugLocTracker() {}
104   };
105   
106 } // end namespace llvm
107
108 #endif /* LLVM_DEBUGLOC_H */