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;
30 DebugLocTuple(GlobalVariable *v, unsigned l, unsigned c)
31 : CompileUnit(v), Line(l), Col(c) {};
33 bool operator==(const DebugLocTuple &DLT) const {
34 return CompileUnit == DLT.CompileUnit &&
35 Line == DLT.Line && Col == DLT.Col;
37 bool operator!=(const DebugLocTuple &DLT) const {
38 return !(*this == DLT);
42 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
43 /// to index into a vector of unique debug location tuples.
48 DebugLoc() : Idx(~0U) {} // Defaults to invalid.
50 static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; }
51 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
53 unsigned getIndex() const { return Idx; }
55 /// isUnknown - Return true if there is no debug info for the SDNode /
57 bool isUnknown() const { return Idx == ~0U; }
59 bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
60 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
63 // Partially specialize DenseMapInfo for DebugLocTyple.
64 template<> struct DenseMapInfo<DebugLocTuple> {
65 static inline DebugLocTuple getEmptyKey() {
66 return DebugLocTuple(0, ~0U, ~0U);
68 static inline DebugLocTuple getTombstoneKey() {
69 return DebugLocTuple((GlobalVariable*)~1U, ~1U, ~1U);
71 static unsigned getHashValue(const DebugLocTuple &Val) {
72 return DenseMapInfo<GlobalVariable*>::getHashValue(Val.CompileUnit) ^
73 DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
74 DenseMapInfo<unsigned>::getHashValue(Val.Col);
76 static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
77 return LHS.CompileUnit == RHS.CompileUnit &&
78 LHS.Line == RHS.Line &&
82 static bool isPod() { return true; }
85 /// DebugLocTracker - This class tracks debug location information.
87 struct DebugLocTracker {
88 /// DebugLocations - A vector of unique DebugLocTuple's.
90 std::vector<DebugLocTuple> DebugLocations;
92 /// DebugIdMap - This maps DebugLocTuple's to indices into the
93 /// DebugLocations vector.
94 DenseMap<DebugLocTuple, unsigned> DebugIdMap;
99 } // end namespace llvm
101 #endif /* LLVM_DEBUGLOC_H */