When scheduling a block in parts, keep track of the overall
[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
23   /// DebugLocTuple - Debug location tuple of filename id, line and column.
24   ///
25   struct DebugLocTuple {
26     unsigned Src, Line, Col;
27
28     DebugLocTuple(unsigned s, unsigned l, unsigned c)
29       : Src(s), Line(l), Col(c) {};
30   };
31
32   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
33   /// to index into a vector of unique debug location tuples.
34   class DebugLoc {
35     unsigned Idx;
36
37   public:
38     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
39
40     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = 0;   return L; }
41     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
42
43     unsigned getIndex() const { return Idx; }
44
45     /// isInvalid - Return true if the DebugLoc is invalid.
46     bool isInvalid() const { return Idx == ~0U; }
47
48     /// isUnknown - Return true if there is no debug info for the SDNode /
49     /// MachineInstr.
50     bool isUnknown() const { return Idx == 0; }
51
52     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
53     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
54   };
55
56   // Partially specialize DenseMapInfo for DebugLocTyple.
57   template<>  struct DenseMapInfo<DebugLocTuple> {
58     static inline DebugLocTuple getEmptyKey() {
59       return DebugLocTuple(~0U, ~0U, ~0U);
60     }
61     static inline DebugLocTuple getTombstoneKey() {
62       return DebugLocTuple(~1U, ~1U, ~1U);
63     }
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);
68     }
69     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
70       return LHS.Src  == RHS.Src &&
71              LHS.Line == RHS.Line &&
72              LHS.Col  == RHS.Col;
73     }
74
75     static bool isPod() { return true; }
76   };
77
78   /// DebugLocTracker - This class tracks debug location information.
79   ///
80   struct DebugLocTracker {
81     /// DebugLocations - A vector of unique DebugLocTuple's.
82     ///
83     std::vector<DebugLocTuple> DebugLocations;
84
85     /// DebugIdMap - This maps DebugLocTuple's to indices into the
86     /// DebugLocations vector.
87     DenseMap<DebugLocTuple, unsigned> DebugIdMap;
88
89     DebugLocTracker() {}
90   };
91   
92 } // end namespace llvm
93
94 #endif /* LLVM_CODEGEN_DEBUGLOC_H */