LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DebugLoc.h
Go to the documentation of this file.
1 //===---- llvm/Support/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
11 // to describe and track debug location information.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_DEBUGLOC_H
16 #define LLVM_SUPPORT_DEBUGLOC_H
17 
18 #include "llvm/Support/DataTypes.h"
19 
20 namespace llvm {
21  template <typename T> struct DenseMapInfo;
22  class MDNode;
23  class LLVMContext;
24 
25  /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
26  /// and MachineInstr to compactly encode file/line/scope information for an
27  /// operation.
28  class DebugLoc {
29  friend struct DenseMapInfo<DebugLoc>;
30 
31  /// getEmptyKey() - A private constructor that returns an unknown that is
32  /// not equal to the tombstone key or DebugLoc().
33  static DebugLoc getEmptyKey() {
34  DebugLoc DL;
35  DL.LineCol = 1;
36  return DL;
37  }
38 
39  /// getTombstoneKey() - A private constructor that returns an unknown that
40  /// is not equal to the empty key or DebugLoc().
41  static DebugLoc getTombstoneKey() {
42  DebugLoc DL;
43  DL.LineCol = 2;
44  return DL;
45  }
46 
47  /// LineCol - This 32-bit value encodes the line and column number for the
48  /// location, encoded as 24-bits for line and 8 bits for col. A value of 0
49  /// for either means unknown.
50  uint32_t LineCol;
51 
52  /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
53  /// decoded by LLVMContext. 0 is unknown.
54  int ScopeIdx;
55  public:
56  DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
57 
58  /// get - Get a new DebugLoc that corresponds to the specified line/col
59  /// scope/inline location.
60  static DebugLoc get(unsigned Line, unsigned Col,
61  MDNode *Scope, MDNode *InlinedAt = 0);
62 
63  /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
65 
66  /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
68 
69  /// isUnknown - Return true if this is an unknown location.
70  bool isUnknown() const { return ScopeIdx == 0; }
71 
72  unsigned getLine() const {
73  return (LineCol << 8) >> 8; // Mask out column.
74  }
75 
76  unsigned getCol() const {
77  return LineCol >> 24;
78  }
79 
80  /// getScope - This returns the scope pointer for this DebugLoc, or null if
81  /// invalid.
82  MDNode *getScope(const LLVMContext &Ctx) const;
83 
84  /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
85  /// null if invalid or not present.
86  MDNode *getInlinedAt(const LLVMContext &Ctx) const;
87 
88  /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
89  void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
90  const LLVMContext &Ctx) const;
91 
92 
93  /// getAsMDNode - This method converts the compressed DebugLoc node into a
94  /// DILocation compatible MDNode.
95  MDNode *getAsMDNode(const LLVMContext &Ctx) const;
96 
97  bool operator==(const DebugLoc &DL) const {
98  return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
99  }
100  bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
101 
102  void dump(const LLVMContext &Ctx) const;
103  };
104 
105  template <>
107  static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); }
108  static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); }
109  static unsigned getHashValue(const DebugLoc &Key);
110  static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; }
111  };
112 } // end namespace llvm
113 
114 #endif /* LLVM_SUPPORT_DEBUGLOC_H */
bool operator==(const DebugLoc &DL) const
Definition: DebugLoc.h:97
static bool isEqual(DebugLoc LHS, DebugLoc RHS)
Definition: DebugLoc.h:110
MDNode * getAsMDNode(const LLVMContext &Ctx) const
Definition: DebugLoc.cpp:100
void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA, const LLVMContext &Ctx) const
getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
Definition: DebugLoc.cpp:49
MDNode - a tuple of other values.
Definition: Metadata.h:69
static DebugLoc getEmptyKey()
Definition: DebugLoc.h:107
bool isUnknown() const
isUnknown - Return true if this is an unknown location.
Definition: DebugLoc.h:70
unsigned getLine() const
Definition: DebugLoc.h:72
unsigned getCol() const
Definition: DebugLoc.h:76
static DebugLoc getFromDILexicalBlock(MDNode *N)
getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
Definition: DebugLoc.cpp:126
void dump(const LLVMContext &Ctx) const
Definition: DebugLoc.cpp:133
MDNode * getInlinedAt(const LLVMContext &Ctx) const
Definition: DebugLoc.cpp:37
MDNode * getScope(const LLVMContext &Ctx) const
Definition: DebugLoc.cpp:20
bool operator!=(const DebugLoc &DL) const
Definition: DebugLoc.h:100
#define N
static DebugLoc getFromDILocation(MDNode *N)
getFromDILocation - Translate the DILocation quad into a DebugLoc.
Definition: DebugLoc.cpp:117
static DebugLoc getTombstoneKey()
Definition: DebugLoc.h:108