1 //===---- llvm/DebugLoc.h - Debug Location Information ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a number of light weight data structures used
11 // to describe and track debug location information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_DEBUGLOC_H
16 #define LLVM_DEBUGLOC_H
18 #include "llvm/ADT/DenseMap.h"
24 /// DebugLocTuple - Debug location tuple of filename id, line and column.
26 struct DebugLocTuple {
27 GlobalVariable *CompileUnit;
31 : CompileUnit(0), Line(~0U), Col(~0U) {};
33 DebugLocTuple(GlobalVariable *v, unsigned l, unsigned c)
34 : CompileUnit(v), Line(l), Col(c) {};
36 bool operator==(const DebugLocTuple &DLT) const {
37 return CompileUnit == DLT.CompileUnit &&
38 Line == DLT.Line && Col == DLT.Col;
40 bool operator!=(const DebugLocTuple &DLT) const {
41 return !(*this == DLT);
45 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
46 /// to index into a vector of unique debug location tuples.
51 DebugLoc() : Idx(~0U) {} // Defaults to invalid.
53 static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; }
54 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
56 unsigned getIndex() const { return Idx; }
58 /// isUnknown - Return true if there is no debug info for the SDNode /
60 bool isUnknown() const { return Idx == ~0U; }
62 bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
63 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
66 // Partially specialize DenseMapInfo for DebugLocTyple.
67 template<> struct DenseMapInfo<DebugLocTuple> {
68 static inline DebugLocTuple getEmptyKey() {
69 return DebugLocTuple(0, ~0U, ~0U);
71 static inline DebugLocTuple getTombstoneKey() {
72 return DebugLocTuple((GlobalVariable*)~1U, ~1U, ~1U);
74 static unsigned getHashValue(const DebugLocTuple &Val) {
75 return DenseMapInfo<GlobalVariable*>::getHashValue(Val.CompileUnit) ^
76 DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
77 DenseMapInfo<unsigned>::getHashValue(Val.Col);
79 static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
80 return LHS.CompileUnit == RHS.CompileUnit &&
81 LHS.Line == RHS.Line &&
85 static bool isPod() { return true; }
88 /// DebugLocTracker - This class tracks debug location information.
90 struct DebugLocTracker {
91 /// DebugLocations - A vector of unique DebugLocTuple's.
93 std::vector<DebugLocTuple> DebugLocations;
95 /// DebugIdMap - This maps DebugLocTuple's to indices into the
96 /// DebugLocations vector.
97 DenseMap<DebugLocTuple, unsigned> DebugIdMap;
102 } // end namespace llvm
104 #endif /* LLVM_DEBUGLOC_H */