aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen/DebugLoc.h
blob: b6097afe306dbbdd664a91237645c31733324247 (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
//===---- 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 {

  /// DebugLocTuple - Debug location tuple of filename id, line and column.
  ///
  struct DebugLocTuple {
    unsigned Src, Line, Col;

    DebugLocTuple(unsigned s, unsigned l, unsigned c)
      : Src(s), Line(l), Col(c) {};
  };

  /// 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) {}

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

    bool isInvalid() { return Idx == ~0U; }
    bool isUnknown() { return Idx == 0; }
  };

  struct DebugLocTupleDenseMapInfo {
    static inline DebugLocTuple getEmptyKey() {
      return DebugLocTuple(~0U, ~0U, ~0U);
    }
    static inline DebugLocTuple getTombstoneKey() {
      return DebugLocTuple(~1U, ~1U, ~1U);
    }
    static unsigned getHashValue(const DebugLocTuple &Val) {
      return DenseMapInfo<unsigned>::getHashValue(Val.Src) ^
             DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
             DenseMapInfo<unsigned>::getHashValue(Val.Col);
    }
    static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
      return LHS.Src  == RHS.Src &&
             LHS.Line == RHS.Line &&
             LHS.Col  == RHS.Col;
    }

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

  typedef DenseMap<DebugLocTuple, unsigned, DebugLocTupleDenseMapInfo>
    DebugIdMapType;
    
  /// DebugLocTracker - This class tracks debug location information.
  ///
  struct DebugLocTracker {
    // NumDebugLocations - Size of the DebugLocations vector.
    unsigned NumDebugLocations;

    // DebugLocations - A vector of unique DebugLocTuple's.
    //
    std::vector<DebugLocTuple> DebugLocations;

    // DebugIdsMap - This maps DebugLocTuple's to indices into
    // DebugLocations vector.
    DebugIdMapType DebugIdMap;

    DebugLocTracker() : NumDebugLocations(0) {}

    ~DebugLocTracker() {
      DebugLocations.clear();
      DebugIdMap.clear();
    }
  };
  
} // end namespace llvm

#endif /* LLVM_CODEGEN_DEBUGLOC_H */