1 //===---- llvm/Support/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_SUPPORT_DEBUGLOC_H
16 #define LLVM_SUPPORT_DEBUGLOC_H
19 template <typename T> struct DenseMapInfo;
23 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
24 /// and MachineInstr to compactly encode file/line/scope information for an
27 friend struct DenseMapInfo<DebugLoc>;
29 /// getEmptyKey() - A private constructor that returns an unknown that is
30 /// not equal to the tombstone key or DebugLoc().
31 static DebugLoc getEmptyKey() {
37 /// getTombstoneKey() - A private constructor that returns an unknown that
38 /// is not equal to the empty key or DebugLoc().
39 static DebugLoc getTombstoneKey() {
45 /// LineCol - This 32-bit value encodes the line and column number for the
46 /// location, encoded as 24-bits for line and 8 bits for col. A value of 0
47 /// for either means unknown.
50 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
51 /// decoded by LLVMContext. 0 is unknown.
54 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
56 /// get - Get a new DebugLoc that corresponds to the specified line/col
57 /// scope/inline location.
58 static DebugLoc get(unsigned Line, unsigned Col,
59 MDNode *Scope, MDNode *InlinedAt = 0);
61 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
62 static DebugLoc getFromDILocation(MDNode *N);
64 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
65 static DebugLoc getFromDILexicalBlock(MDNode *N);
67 /// isUnknown - Return true if this is an unknown location.
68 bool isUnknown() const { return ScopeIdx == 0; }
70 unsigned getLine() const {
71 return (LineCol << 8) >> 8; // Mask out column.
74 unsigned getCol() const {
78 /// getScope - This returns the scope pointer for this DebugLoc, or null if
80 MDNode *getScope(const LLVMContext &Ctx) const;
82 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
83 /// null if invalid or not present.
84 MDNode *getInlinedAt(const LLVMContext &Ctx) const;
86 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
87 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
88 const LLVMContext &Ctx) const;
91 /// getAsMDNode - This method converts the compressed DebugLoc node into a
92 /// DILocation compatible MDNode.
93 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
95 bool operator==(const DebugLoc &DL) const {
96 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
98 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
100 void dump(const LLVMContext &Ctx) const;
104 struct DenseMapInfo<DebugLoc> {
105 static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); }
106 static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); }
107 static unsigned getHashValue(const DebugLoc &Key);
108 static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; }
110 } // end namespace llvm
112 #endif /* LLVM_DEBUGLOC_H */