aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen/DebugLoc.h
blob: 495baf44deef13d165e8fc27b9a11667065579fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//===---- llvm/CodeGen/DebugLoc.h - Debug Location Information --*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines a number of light weight data structures used by the code
// generator to describe and track debug location information.
// 
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_DEBUGLOC_H
#define LLVM_CODEGEN_DEBUGLOC_H

#include "llvm/ADT/DenseMap.h"
#include <vector>

namespace llvm {
  class GlobalVariable;
  class MachineFunction;

  /// DebugScope - Debug scope id. This is carried into DebugLocTuple to index
  /// into a vector of DebugScopeInfos. Provides the ability to associate a
  /// SDNode/MachineInstr with the debug scope that it belongs to.
  ///
  class DebugScope {
    unsigned Idx;

  public:
    DebugScope() : Idx(~0U) {}  // Defaults to null.

    static DebugScope getInvalid()   { DebugScope S; S.Idx = ~0U; return S; }
    static DebugScope get(unsigned idx) { DebugScope S; S.Idx = idx; return S; }

    unsigned getIndex() const { return Idx; }

    /// isInvalid - Return true if it doesn't refer to any scope.
    bool isInvalid() const { return Idx == ~0U; }

    bool operator==(const DebugScope &DS) const { return Idx == DS.Idx; }
    bool operator!=(const DebugScope &DS) const { return !(*this == DS); }
  };

  /// DebugScopeInfo - Contains info about the scope global variable and the
  /// parent debug scope. DebugScope is only a "cookie" that can point to a
  /// specific DebugScopeInfo.
  ///
  struct DebugScopeInfo {
    GlobalVariable *GV;
    DebugScope Parent;

    DebugScopeInfo(GlobalVariable *gv, DebugScope parent)
      : GV(gv), Parent(parent) {}
    DebugScopeInfo()
      : GV(0), Parent(DebugScope::getInvalid()) {}
  };

  /// DebugScopeTracker - Create and keep track of the debug scope while
  /// entering/exiting subprograms and blocks. Used by the instruction
  /// selectors.
  ///
  class DebugScopeTracker {
    DebugScope CurScope;

  public:
    /// getCurScope - The current debug scope that we "entered" through
    /// EnterDebugScope.
    DebugScope getCurScope() const { return CurScope; }

    /// EnterDebugScope - Start a new debug scope. ScopeGV can be a DISubprogram
    /// or a DIBlock.
    void EnterDebugScope(GlobalVariable *ScopeGV, MachineFunction &MF);

    /// ExitDebugScope - "Pop" a DISubprogram or a DIBlock.
    void ExitDebugScope(GlobalVariable *ScopeGV, MachineFunction &MF);
  };

  /// DebugLocTuple - Debug location tuple of a DICompileUnit global variable,
  /// debug scope, line and column.
  ///
  struct DebugLocTuple {
    GlobalVariable *CompileUnit;
    DebugScope Scope;
    unsigned Line, Col;

    DebugLocTuple(GlobalVariable *v, DebugScope s, unsigned l, unsigned c)
      : CompileUnit(v), Scope(s), Line(l), Col(c) {};

    bool operator==(const DebugLocTuple &DLT) const {
      return CompileUnit == DLT.CompileUnit && Scope == DLT.Scope &&
             Line == DLT.Line && Col == DLT.Col;
    }
    bool operator!=(const DebugLocTuple &DLT) const {
      return !(*this == DLT);
    }
  };

  /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
  /// to index into a vector of unique debug location tuples.
  class DebugLoc {
    unsigned Idx;

  public:
    DebugLoc() : Idx(~0U) {}  // Defaults to invalid.

    static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
    static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }

    unsigned getIndex() const { return Idx; }

    /// isUnknown - Return true if there is no debug info for the SDNode /
    /// MachineInstr.
    bool isUnknown() const { return Idx == ~0U; }

    bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
    bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
  };

  // Partially specialize DenseMapInfo for DebugLocTyple.
  template<>  struct DenseMapInfo<DebugLocTuple> {
    static inline DebugLocTuple getEmptyKey() {
      return DebugLocTuple(0, DebugScope::getInvalid(), ~0U, ~0U);
    }
    static inline DebugLocTuple getTombstoneKey() {
      return DebugLocTuple((GlobalVariable*)~1U,DebugScope::get(~1U), ~1U, ~1U);
    }
    static unsigned getHashValue(const DebugLocTuple &Val) {
      return DenseMapInfo<GlobalVariable*>::getHashValue(Val.CompileUnit) ^
             DenseMapInfo<unsigned>::getHashValue(Val.Scope.getIndex()) ^
             DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
             DenseMapInfo<unsigned>::getHashValue(Val.Col);
    }
    static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
      return LHS.CompileUnit == RHS.CompileUnit &&
             LHS.Scope       == RHS.Scope &&
             LHS.Line        == RHS.Line &&
             LHS.Col         == RHS.Col;
    }

    static bool isPod() { return true; }
  };

  /// DebugLocTracker - This class tracks debug location information.
  ///
  struct DebugLocTracker {
    /// DebugLocations - A vector of unique DebugLocTuple's.
    ///
    std::vector<DebugLocTuple> DebugLocations;

    /// DebugIdMap - This maps DebugLocTuple's to indices into the
    /// DebugLocations vector.
    DenseMap<DebugLocTuple, unsigned> DebugIdMap;

    DebugLocTracker() {}
  };
  
} // end namespace llvm

#endif /* LLVM_CODEGEN_DEBUGLOC_H */