1 //===---- llvm/CodeGen/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 by the code
11 // generator to describe and track debug location information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_DEBUGLOC_H
16 #define LLVM_CODEGEN_DEBUGLOC_H
18 #include "llvm/ADT/DenseMap.h"
23 /// DebugLocTuple - Debug location tuple of filename id, line and column.
25 struct DebugLocTuple {
26 unsigned Src, Line, Col;
28 DebugLocTuple(unsigned s, unsigned l, unsigned c)
29 : Src(s), Line(l), Col(c) {};
32 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
33 /// to index into a vector of unique debug location tuples.
38 DebugLoc() : Idx(~0U) {} // Defaults to invalid.
40 static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = 0; return L; }
41 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
43 unsigned getIndex() const { return Idx; }
45 /// isInvalid - Return true if the DebugLoc is invalid.
46 bool isInvalid() const { return Idx == ~0U; }
48 /// isUnknown - Return true if there is no debug info for the SDNode /
50 bool isUnknown() const { return Idx == 0; }
52 bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
53 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
56 // Partially specialize DenseMapInfo for DebugLocTyple.
57 template<> struct DenseMapInfo<DebugLocTuple> {
58 static inline DebugLocTuple getEmptyKey() {
59 return DebugLocTuple(~0U, ~0U, ~0U);
61 static inline DebugLocTuple getTombstoneKey() {
62 return DebugLocTuple(~1U, ~1U, ~1U);
64 static unsigned getHashValue(const DebugLocTuple &Val) {
65 return DenseMapInfo<unsigned>::getHashValue(Val.Src) ^
66 DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
67 DenseMapInfo<unsigned>::getHashValue(Val.Col);
69 static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
70 return LHS.Src == RHS.Src &&
71 LHS.Line == RHS.Line &&
75 static bool isPod() { return true; }
78 /// DebugLocTracker - This class tracks debug location information.
80 struct DebugLocTracker {
81 /// DebugLocations - A vector of unique DebugLocTuple's.
83 std::vector<DebugLocTuple> DebugLocations;
85 /// DebugIdMap - This maps DebugLocTuple's to indices into the
86 /// DebugLocations vector.
87 DenseMap<DebugLocTuple, unsigned> DebugIdMap;
92 } // end namespace llvm
94 #endif /* LLVM_CODEGEN_DEBUGLOC_H */