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_DEBUGLOC_H
16 #define LLVM_DEBUGLOC_H
18 #include "llvm/ADT/DenseMap.h"
25 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
26 /// and MachineInstr to compactly encode file/line/scope information for an
29 /// LineCol - This 32-bit value encodes the line and column number for the
30 /// location, encoded as 24-bits for line and 8 bits for col. A value of 0
31 /// for either means unknown.
34 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
35 /// decoded by LLVMContext. 0 is unknown.
38 NewDebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown.
40 static NewDebugLoc get(unsigned Line, unsigned Col,
41 MDNode *Scope, MDNode *InlinedAt);
43 /// isUnknown - Return true if this is an unknown location.
44 bool isUnknown() const { return ScopeIdx == 0; }
46 unsigned getLine() const {
47 return (LineCol << 8) >> 8; // Mask out column.
50 unsigned getCol() const {
54 /// getScope - This returns the scope pointer for this DebugLoc, or null if
56 MDNode *getScope(const LLVMContext &Ctx) const;
58 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
59 /// null if invalid or not present.
60 MDNode *getInlinedAt(const LLVMContext &Ctx) const;
62 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
63 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
64 const LLVMContext &Ctx) const;
67 /// getAsMDNode - This method converts the compressed DebugLoc node into a
68 /// DILocation compatible MDNode.
69 MDNode *getAsMDNode(const LLVMContext &Ctx) const;
71 bool operator==(const NewDebugLoc &DL) const {
72 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
74 bool operator!=(const NewDebugLoc &DL) const { return !(*this == DL); }
79 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
80 /// to index into a vector of unique debug location tuples.
84 DebugLoc() : Idx(~0U) {} // Defaults to invalid.
86 static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; }
87 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
89 unsigned getIndex() const { return Idx; }
91 /// isUnknown - Return true if there is no debug info for the SDNode /
93 bool isUnknown() const { return Idx == ~0U; }
95 bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
96 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
99 /// DebugLocTracker - This class tracks debug location information.
101 struct DebugLocTracker {
102 /// DebugLocations - A vector of unique DebugLocTuple's.
104 std::vector<MDNode *> DebugLocations;
106 /// DebugIdMap - This maps DebugLocTuple's to indices into the
107 /// DebugLocations vector.
108 DenseMap<MDNode *, unsigned> DebugIdMap;
113 } // end namespace llvm
115 #endif /* LLVM_DEBUGLOC_H */