1206083Srdivacky//===---- llvm/Support/DebugLoc.h - Debug Location Information --*- C++ -*-===// 2194612Sed// 3194612Sed// The LLVM Compiler Infrastructure 4194612Sed// 5194612Sed// This file is distributed under the University of Illinois Open Source 6194612Sed// License. See LICENSE.TXT for details. 7194612Sed// 8194612Sed//===----------------------------------------------------------------------===// 9194612Sed// 10194612Sed// This file defines a number of light weight data structures used 11194612Sed// to describe and track debug location information. 12249423Sdim// 13194612Sed//===----------------------------------------------------------------------===// 14194612Sed 15206124Srdivacky#ifndef LLVM_SUPPORT_DEBUGLOC_H 16206124Srdivacky#define LLVM_SUPPORT_DEBUGLOC_H 17194612Sed 18263508Sdim#include "llvm/Support/DataTypes.h" 19263508Sdim 20194612Sednamespace llvm { 21239462Sdim template <typename T> struct DenseMapInfo; 22198090Srdivacky class MDNode; 23206083Srdivacky class LLVMContext; 24249423Sdim 25206083Srdivacky /// DebugLoc - Debug location id. This is carried by Instruction, SDNode, 26206083Srdivacky /// and MachineInstr to compactly encode file/line/scope information for an 27206083Srdivacky /// operation. 28206124Srdivacky class DebugLoc { 29221345Sdim friend struct DenseMapInfo<DebugLoc>; 30221345Sdim 31221345Sdim /// getEmptyKey() - A private constructor that returns an unknown that is 32221345Sdim /// not equal to the tombstone key or DebugLoc(). 33221345Sdim static DebugLoc getEmptyKey() { 34221345Sdim DebugLoc DL; 35221345Sdim DL.LineCol = 1; 36221345Sdim return DL; 37221345Sdim } 38221345Sdim 39221345Sdim /// getTombstoneKey() - A private constructor that returns an unknown that 40221345Sdim /// is not equal to the empty key or DebugLoc(). 41221345Sdim static DebugLoc getTombstoneKey() { 42221345Sdim DebugLoc DL; 43221345Sdim DL.LineCol = 2; 44221345Sdim return DL; 45221345Sdim } 46221345Sdim 47206083Srdivacky /// LineCol - This 32-bit value encodes the line and column number for the 48206083Srdivacky /// location, encoded as 24-bits for line and 8 bits for col. A value of 0 49206083Srdivacky /// for either means unknown. 50263508Sdim uint32_t LineCol; 51249423Sdim 52206083Srdivacky /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information, 53206083Srdivacky /// decoded by LLVMContext. 0 is unknown. 54206083Srdivacky int ScopeIdx; 55206083Srdivacky public: 56206124Srdivacky DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown. 57249423Sdim 58206083Srdivacky /// get - Get a new DebugLoc that corresponds to the specified line/col 59206083Srdivacky /// scope/inline location. 60206124Srdivacky static DebugLoc get(unsigned Line, unsigned Col, 61206124Srdivacky MDNode *Scope, MDNode *InlinedAt = 0); 62249423Sdim 63206124Srdivacky /// getFromDILocation - Translate the DILocation quad into a DebugLoc. 64206124Srdivacky static DebugLoc getFromDILocation(MDNode *N); 65224145Sdim 66224145Sdim /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc. 67224145Sdim static DebugLoc getFromDILexicalBlock(MDNode *N); 68224145Sdim 69206083Srdivacky /// isUnknown - Return true if this is an unknown location. 70206083Srdivacky bool isUnknown() const { return ScopeIdx == 0; } 71249423Sdim 72206083Srdivacky unsigned getLine() const { 73206083Srdivacky return (LineCol << 8) >> 8; // Mask out column. 74206083Srdivacky } 75249423Sdim 76206083Srdivacky unsigned getCol() const { 77206083Srdivacky return LineCol >> 24; 78206083Srdivacky } 79249423Sdim 80206083Srdivacky /// getScope - This returns the scope pointer for this DebugLoc, or null if 81206083Srdivacky /// invalid. 82206083Srdivacky MDNode *getScope(const LLVMContext &Ctx) const; 83249423Sdim 84206083Srdivacky /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or 85206083Srdivacky /// null if invalid or not present. 86206083Srdivacky MDNode *getInlinedAt(const LLVMContext &Ctx) const; 87249423Sdim 88206083Srdivacky /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values. 89206083Srdivacky void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA, 90206083Srdivacky const LLVMContext &Ctx) const; 91249423Sdim 92249423Sdim 93206083Srdivacky /// getAsMDNode - This method converts the compressed DebugLoc node into a 94206083Srdivacky /// DILocation compatible MDNode. 95206083Srdivacky MDNode *getAsMDNode(const LLVMContext &Ctx) const; 96249423Sdim 97206124Srdivacky bool operator==(const DebugLoc &DL) const { 98206083Srdivacky return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx; 99206083Srdivacky } 100194612Sed bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } 101224145Sdim 102224145Sdim void dump(const LLVMContext &Ctx) const; 103194612Sed }; 104221345Sdim 105221345Sdim template <> 106221345Sdim struct DenseMapInfo<DebugLoc> { 107239462Sdim static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); } 108239462Sdim static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); } 109221345Sdim static unsigned getHashValue(const DebugLoc &Key); 110239462Sdim static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; } 111221345Sdim }; 112194612Sed} // end namespace llvm 113194612Sed 114249423Sdim#endif /* LLVM_SUPPORT_DEBUGLOC_H */ 115