Deleted Added
full compact
DebugLoc.h (276479) DebugLoc.h (280031)
1//===- 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_IR_DEBUGLOC_H
16#define LLVM_IR_DEBUGLOC_H
17
1//===- 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_IR_DEBUGLOC_H
16#define LLVM_IR_DEBUGLOC_H
17
18#include "llvm/IR/TrackingMDRef.h"
18#include "llvm/Support/DataTypes.h"
19
20namespace llvm {
19#include "llvm/Support/DataTypes.h"
20
21namespace llvm {
21 template <typename T> struct DenseMapInfo;
22 class MDNode;
22
23 class LLVMContext;
24 class raw_ostream;
23 class LLVMContext;
24 class raw_ostream;
25 class MDNode;
25
26 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
27 /// and MachineInstr to compactly encode file/line/scope information for an
28 /// operation.
29 class DebugLoc {
26
27 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
28 /// and MachineInstr to compactly encode file/line/scope information for an
29 /// operation.
30 class DebugLoc {
30 friend struct DenseMapInfo<DebugLoc>;
31 TrackingMDNodeRef Loc;
31
32
32 /// getEmptyKey() - A private constructor that returns an unknown that is
33 /// not equal to the tombstone key or DebugLoc().
34 static DebugLoc getEmptyKey() {
35 DebugLoc DL;
36 DL.LineCol = 1;
37 return DL;
33 public:
34 DebugLoc() {}
35 DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
36 DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
37 DebugLoc &operator=(DebugLoc &&X) {
38 Loc = std::move(X.Loc);
39 return *this;
38 }
40 }
39
40 /// getTombstoneKey() - A private constructor that returns an unknown that
41 /// is not equal to the empty key or DebugLoc().
42 static DebugLoc getTombstoneKey() {
43 DebugLoc DL;
44 DL.LineCol = 2;
45 return DL;
41 DebugLoc &operator=(const DebugLoc &X) {
42 Loc = X.Loc;
43 return *this;
46 }
47
44 }
45
48 /// LineCol - This 32-bit value encodes the line and column number for the
49 /// location, encoded as 24-bits for line and 8 bits for col. A value of 0
50 /// for either means unknown.
51 uint32_t LineCol;
46 /// \brief Check whether this has a trivial destructor.
47 bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
52
48
53 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
54 /// decoded by LLVMContext. 0 is unknown.
55 int ScopeIdx;
56 public:
57 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
58
59 /// get - Get a new DebugLoc that corresponds to the specified line/col
60 /// scope/inline location.
49 /// get - Get a new DebugLoc that corresponds to the specified line/col
50 /// scope/inline location.
61 static DebugLoc get(unsigned Line, unsigned Col,
62 MDNode *Scope, MDNode *InlinedAt = nullptr);
51 static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope,
52 MDNode *InlinedAt = nullptr);
63
64 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
65 static DebugLoc getFromDILocation(MDNode *N);
66
67 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
68 static DebugLoc getFromDILexicalBlock(MDNode *N);
69
70 /// isUnknown - Return true if this is an unknown location.
53
54 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
55 static DebugLoc getFromDILocation(MDNode *N);
56
57 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
58 static DebugLoc getFromDILexicalBlock(MDNode *N);
59
60 /// isUnknown - Return true if this is an unknown location.
71 bool isUnknown() const { return ScopeIdx == 0; }
61 bool isUnknown() const { return !Loc; }
72
62
73 unsigned getLine() const {
74 return (LineCol << 8) >> 8; // Mask out column.
75 }
63 unsigned getLine() const;
64 unsigned getCol() const;
76
65
77 unsigned getCol() const {
78 return LineCol >> 24;
79 }
80
81 /// getScope - This returns the scope pointer for this DebugLoc, or null if
82 /// invalid.
66 /// getScope - This returns the scope pointer for this DebugLoc, or null if
67 /// invalid.
83 MDNode *getScope(const LLVMContext &Ctx) const;
68 MDNode *getScope() const;
69 MDNode *getScope(const LLVMContext &) const { return getScope(); }
84
85 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
86 /// null if invalid or not present.
70
71 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
72 /// null if invalid or not present.
87 MDNode *getInlinedAt(const LLVMContext &Ctx) const;
73 MDNode *getInlinedAt() const;
74 MDNode *getInlinedAt(const LLVMContext &) const { return getInlinedAt(); }
88
89 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
75
76 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
77 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const;
90 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
78 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
91 const LLVMContext &Ctx) const;
79 const LLVMContext &) const {
80 return getScopeAndInlinedAt(Scope, IA);
81 }
92
93 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
82
83 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
94 MDNode *getScopeNode(const LLVMContext &Ctx) const;
84 MDNode *getScopeNode() const;
85 MDNode *getScopeNode(const LLVMContext &) const { return getScopeNode(); }
95
96 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
97 // number info for the function.
86
87 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
88 // number info for the function.
98 DebugLoc getFnDebugLoc(const LLVMContext &Ctx) const;
89 DebugLoc getFnDebugLoc() const;
90 DebugLoc getFnDebugLoc(const LLVMContext &) const {
91 return getFnDebugLoc();
92 }
99
100 /// getAsMDNode - This method converts the compressed DebugLoc node into a
101 /// DILocation compatible MDNode.
93
94 /// getAsMDNode - This method converts the compressed DebugLoc node into a
95 /// DILocation compatible MDNode.
102 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
96 MDNode *getAsMDNode() const;
97 MDNode *getAsMDNode(LLVMContext &) const { return getAsMDNode(); }
103
98
104 bool operator==(const DebugLoc &DL) const {
105 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
106 }
99 bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
107 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
108
100 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
101
109 void dump(const LLVMContext &Ctx) const;
102 void dump() const;
103 void dump(const LLVMContext &) const { dump(); }
110 /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
104 /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
111 void print(const LLVMContext &Ctx, raw_ostream &OS) const;
105 void print(raw_ostream &OS) const;
106 void print(const LLVMContext &, raw_ostream &OS) const { print(OS); }
112 };
113
107 };
108
114 template <>
115 struct DenseMapInfo<DebugLoc> {
116 static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); }
117 static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); }
118 static unsigned getHashValue(const DebugLoc &Key);
119 static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; }
120 };
121} // end namespace llvm
122
123#endif /* LLVM_SUPPORT_DEBUGLOC_H */
109} // end namespace llvm
110
111#endif /* LLVM_SUPPORT_DEBUGLOC_H */