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