Delete unnecessary elses.
[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     /// isInvalid - Return true if the DebugLoc is invalid.
44     bool isInvalid() const { return Idx == ~0U; }
45
46     /// isUnknown - Return true if there is no debug info for the SDNode /
47     /// MachineInstr.
48     bool isUnknown() const { return Idx == 0; }
49   };
50
51   // Partially specialize DenseMapInfo for DebugLocTyple.
52   template<>  struct DenseMapInfo<DebugLocTuple> {
53     static inline DebugLocTuple getEmptyKey() {
54       return DebugLocTuple(~0U, ~0U, ~0U);
55     }
56     static inline DebugLocTuple getTombstoneKey() {
57       return DebugLocTuple(~1U, ~1U, ~1U);
58     }
59     static unsigned getHashValue(const DebugLocTuple &Val) {
60       return DenseMapInfo<unsigned>::getHashValue(Val.Src) ^
61              DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
62              DenseMapInfo<unsigned>::getHashValue(Val.Col);
63     }
64     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
65       return LHS.Src  == RHS.Src &&
66              LHS.Line == RHS.Line &&
67              LHS.Col  == RHS.Col;
68     }
69
70     static bool isPod() { return true; }
71   };
72
73   /// DebugLocTracker - This class tracks debug location information.
74   ///
75   struct DebugLocTracker {
76     /// DebugLocations - A vector of unique DebugLocTuple's.
77     ///
78     std::vector<DebugLocTuple> DebugLocations;
79
80     /// DebugIdsMap - This maps DebugLocTuple's to indices into DebugLocations
81     /// vector.
82     DenseMap<DebugLocTuple, unsigned> DebugIdMap;
83
84     DebugLocTracker() {}
85
86     ~DebugLocTracker() {
87       DebugLocations.clear();
88       DebugIdMap.clear();
89     }
90   };
91   
92 } // end namespace llvm
93
94 #endif /* LLVM_CODEGEN_DEBUGLOC_H */