1 //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a number of light weight data structures used
11 // to describe and track debug location information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
18 #include "llvm/Support/DataTypes.h"
21 template <typename T> struct DenseMapInfo;
26 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
27 /// and MachineInstr to compactly encode file/line/scope information for an
30 friend struct DenseMapInfo<DebugLoc>;
32 /// getEmptyKey() - A private constructor that returns an unknown that is
33 /// not equal to the tombstone key or DebugLoc().
34 static DebugLoc getEmptyKey() {
40 /// getTombstoneKey() - A private constructor that returns an unknown that
41 /// is not equal to the empty key or DebugLoc().
42 static DebugLoc getTombstoneKey() {
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.
53 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
54 /// decoded by LLVMContext. 0 is unknown.
57 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
59 /// get - Get a new DebugLoc that corresponds to the specified line/col
60 /// scope/inline location.
61 static DebugLoc get(unsigned Line, unsigned Col,
62 MDNode *Scope, MDNode *InlinedAt = nullptr);
64 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
65 static DebugLoc getFromDILocation(MDNode *N);
67 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
68 static DebugLoc getFromDILexicalBlock(MDNode *N);
70 /// isUnknown - Return true if this is an unknown location.
71 bool isUnknown() const { return ScopeIdx == 0; }
73 unsigned getLine() const {
74 return (LineCol << 8) >> 8; // Mask out column.
77 unsigned getCol() const {
81 /// getScope - This returns the scope pointer for this DebugLoc, or null if
83 MDNode *getScope(const LLVMContext &Ctx) const;
85 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
86 /// null if invalid or not present.
87 MDNode *getInlinedAt(const LLVMContext &Ctx) const;
89 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
90 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
91 const LLVMContext &Ctx) const;
93 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
94 MDNode *getScopeNode(const LLVMContext &Ctx) const;
96 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
97 // number info for the function.
98 DebugLoc getFnDebugLoc(const LLVMContext &Ctx) const;
100 /// getAsMDNode - This method converts the compressed DebugLoc node into a
101 /// DILocation compatible MDNode.
102 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
104 bool operator==(const DebugLoc &DL) const {
105 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
107 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
109 void dump(const LLVMContext &Ctx) const;
110 /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
111 void print(const LLVMContext &Ctx, raw_ostream &OS) const;
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; }
121 } // end namespace llvm
123 #endif /* LLVM_SUPPORT_DEBUGLOC_H */