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;
25 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
26 /// and MachineInstr to compactly encode file/line/scope information for an
29 friend struct DenseMapInfo<DebugLoc>;
31 /// getEmptyKey() - A private constructor that returns an unknown that is
32 /// not equal to the tombstone key or DebugLoc().
33 static DebugLoc getEmptyKey() {
39 /// getTombstoneKey() - A private constructor that returns an unknown that
40 /// is not equal to the empty key or DebugLoc().
41 static DebugLoc getTombstoneKey() {
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.
52 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
53 /// decoded by LLVMContext. 0 is unknown.
56 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
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 = nullptr);
63 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
64 static DebugLoc getFromDILocation(MDNode *N);
66 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
67 static DebugLoc getFromDILexicalBlock(MDNode *N);
69 /// isUnknown - Return true if this is an unknown location.
70 bool isUnknown() const { return ScopeIdx == 0; }
72 unsigned getLine() const {
73 return (LineCol << 8) >> 8; // Mask out column.
76 unsigned getCol() const {
80 /// getScope - This returns the scope pointer for this DebugLoc, or null if
82 MDNode *getScope(const LLVMContext &Ctx) const;
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;
88 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
89 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
90 const LLVMContext &Ctx) const;
92 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
93 MDNode *getScopeNode(const LLVMContext &Ctx) const;
95 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
96 // number info for the function.
97 DebugLoc getFnDebugLoc(const LLVMContext &Ctx);
99 /// getAsMDNode - This method converts the compressed DebugLoc node into a
100 /// DILocation compatible MDNode.
101 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
103 bool operator==(const DebugLoc &DL) const {
104 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
106 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
108 void dump(const LLVMContext &Ctx) const;
112 struct DenseMapInfo<DebugLoc> {
113 static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); }
114 static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); }
115 static unsigned getHashValue(const DebugLoc &Key);
116 static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; }
118 } // end namespace llvm
120 #endif /* LLVM_SUPPORT_DEBUGLOC_H */