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 {
32 : Scope(0), InlinedAtLoc(0), Line(~0U), Col(~0U) {}
34 DebugLocTuple(MDNode *n, MDNode *i, unsigned l, unsigned c)
35 : Scope(n), InlinedAtLoc(i), Line(l), Col(c) {}
37 bool operator==(const DebugLocTuple &DLT) const {
38 return Scope == DLT.Scope &&
39 InlinedAtLoc == DLT.InlinedAtLoc &&
40 Line == DLT.Line && Col == DLT.Col;
42 bool operator!=(const DebugLocTuple &DLT) const {
43 return !(*this == DLT);
47 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
48 /// to index into a vector of unique debug location tuples.
53 DebugLoc() : Idx(~0U) {} // Defaults to invalid.
55 static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; }
56 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
58 unsigned getIndex() const { return Idx; }
60 /// isUnknown - Return true if there is no debug info for the SDNode /
62 bool isUnknown() const { return Idx == ~0U; }
64 bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
65 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
68 // Specialize DenseMapInfo for DebugLocTuple.
69 template<> struct DenseMapInfo<DebugLocTuple> {
70 static inline DebugLocTuple getEmptyKey() {
71 return DebugLocTuple(0, 0, ~0U, ~0U);
73 static inline DebugLocTuple getTombstoneKey() {
74 return DebugLocTuple((MDNode*)~1U, (MDNode*)~1U, ~1U, ~1U);
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);
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 &&
89 static bool isPod() { return true; }
92 /// DebugLocTracker - This class tracks debug location information.
94 struct DebugLocTracker {
95 /// DebugLocations - A vector of unique DebugLocTuple's.
97 std::vector<DebugLocTuple> DebugLocations;
99 /// DebugIdMap - This maps DebugLocTuple's to indices into the
100 /// DebugLocations vector.
101 DenseMap<DebugLocTuple, unsigned> DebugIdMap;
106 } // end namespace llvm
108 #endif /* LLVM_DEBUGLOC_H */