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
18 #include "llvm/Support/DataTypes.h"
\r
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 = 0);
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;
93 /// getAsMDNode - This method converts the compressed DebugLoc node into a
94 /// DILocation compatible MDNode.
95 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
97 bool operator==(const DebugLoc &DL) const {
98 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
100 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
102 void dump(const LLVMContext &Ctx) const;
106 struct DenseMapInfo<DebugLoc> {
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; }
112 } // end namespace llvm
114 #endif /* LLVM_SUPPORT_DEBUGLOC_H */