LLVM API Documentation

DebugLoc.h
Go to the documentation of this file.
00001 //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a number of light weight data structures used
00011 // to describe and track debug location information.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_IR_DEBUGLOC_H
00016 #define LLVM_IR_DEBUGLOC_H
00017 
00018 #include "llvm/Support/DataTypes.h"
00019 
00020 namespace llvm {
00021   template <typename T> struct DenseMapInfo;
00022   class MDNode;
00023   class LLVMContext;
00024 
00025   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
00026   /// and MachineInstr to compactly encode file/line/scope information for an
00027   /// operation.
00028   class DebugLoc {
00029     friend struct DenseMapInfo<DebugLoc>;
00030 
00031     /// getEmptyKey() - A private constructor that returns an unknown that is
00032     /// not equal to the tombstone key or DebugLoc().
00033     static DebugLoc getEmptyKey() {
00034       DebugLoc DL;
00035       DL.LineCol = 1;
00036       return DL;
00037     }
00038 
00039     /// getTombstoneKey() - A private constructor that returns an unknown that
00040     /// is not equal to the empty key or DebugLoc().
00041     static DebugLoc getTombstoneKey() {
00042       DebugLoc DL;
00043       DL.LineCol = 2;
00044       return DL;
00045     }
00046 
00047     /// LineCol - This 32-bit value encodes the line and column number for the
00048     /// location, encoded as 24-bits for line and 8 bits for col.  A value of 0
00049     /// for either means unknown.
00050     uint32_t LineCol;
00051 
00052     /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
00053     /// decoded by LLVMContext.  0 is unknown.
00054     int ScopeIdx;
00055   public:
00056     DebugLoc() : LineCol(0), ScopeIdx(0) {}  // Defaults to unknown.
00057 
00058     /// get - Get a new DebugLoc that corresponds to the specified line/col
00059     /// scope/inline location.
00060     static DebugLoc get(unsigned Line, unsigned Col,
00061                         MDNode *Scope, MDNode *InlinedAt = nullptr);
00062 
00063     /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
00064     static DebugLoc getFromDILocation(MDNode *N);
00065 
00066     /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
00067     static DebugLoc getFromDILexicalBlock(MDNode *N);
00068 
00069     /// isUnknown - Return true if this is an unknown location.
00070     bool isUnknown() const { return ScopeIdx == 0; }
00071 
00072     unsigned getLine() const {
00073       return (LineCol << 8) >> 8;  // Mask out column.
00074     }
00075 
00076     unsigned getCol() const {
00077       return LineCol >> 24;
00078     }
00079 
00080     /// getScope - This returns the scope pointer for this DebugLoc, or null if
00081     /// invalid.
00082     MDNode *getScope(const LLVMContext &Ctx) const;
00083 
00084     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
00085     /// null if invalid or not present.
00086     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
00087 
00088     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
00089     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
00090                               const LLVMContext &Ctx) const;
00091 
00092     /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
00093     MDNode *getScopeNode(const LLVMContext &Ctx) const;
00094 
00095     // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
00096     // number info for the function.
00097     DebugLoc getFnDebugLoc(const LLVMContext &Ctx);
00098 
00099     /// getAsMDNode - This method converts the compressed DebugLoc node into a
00100     /// DILocation compatible MDNode.
00101     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
00102 
00103     bool operator==(const DebugLoc &DL) const {
00104       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
00105     }
00106     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
00107 
00108     void dump(const LLVMContext &Ctx) const;
00109   };
00110 
00111   template <>
00112   struct DenseMapInfo<DebugLoc> {
00113     static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); }
00114     static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); }
00115     static unsigned getHashValue(const DebugLoc &Key);
00116     static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; }
00117   };
00118 } // end namespace llvm
00119 
00120 #endif /* LLVM_SUPPORT_DEBUGLOC_H */