LLVM API Documentation

DebugLoc.h

Go to the documentation of this file.
00001 //===---- llvm/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_DEBUGLOC_H
00016 #define LLVM_DEBUGLOC_H
00017 
00018 #include "llvm/ADT/DenseMap.h"
00019 #include <vector>
00020 
00021 namespace llvm {
00022   class GlobalVariable;
00023 
00024   /// DebugLocTuple - Debug location tuple of filename id, line and column.
00025   ///
00026   struct DebugLocTuple {
00027     GlobalVariable *CompileUnit;
00028     unsigned Line, Col;
00029 
00030     DebugLocTuple()
00031       : CompileUnit(0), Line(~0U), Col(~0U) {};
00032 
00033     DebugLocTuple(GlobalVariable *v, unsigned l, unsigned c)
00034       : CompileUnit(v), Line(l), Col(c) {};
00035 
00036     bool operator==(const DebugLocTuple &DLT) const {
00037       return CompileUnit == DLT.CompileUnit &&
00038              Line == DLT.Line && Col == DLT.Col;
00039     }
00040     bool operator!=(const DebugLocTuple &DLT) const {
00041       return !(*this == DLT);
00042     }
00043   };
00044 
00045   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
00046   /// to index into a vector of unique debug location tuples.
00047   class DebugLoc {
00048     unsigned Idx;
00049 
00050   public:
00051     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
00052 
00053     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
00054     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
00055 
00056     unsigned getIndex() const { return Idx; }
00057 
00058     /// isUnknown - Return true if there is no debug info for the SDNode /
00059     /// MachineInstr.
00060     bool isUnknown() const { return Idx == ~0U; }
00061 
00062     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
00063     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
00064   };
00065 
00066   // Partially specialize DenseMapInfo for DebugLocTyple.
00067   template<>  struct DenseMapInfo<DebugLocTuple> {
00068     static inline DebugLocTuple getEmptyKey() {
00069       return DebugLocTuple(0, ~0U, ~0U);
00070     }
00071     static inline DebugLocTuple getTombstoneKey() {
00072       return DebugLocTuple((GlobalVariable*)~1U, ~1U, ~1U);
00073     }
00074     static unsigned getHashValue(const DebugLocTuple &Val) {
00075       return DenseMapInfo<GlobalVariable*>::getHashValue(Val.CompileUnit) ^
00076              DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
00077              DenseMapInfo<unsigned>::getHashValue(Val.Col);
00078     }
00079     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
00080       return LHS.CompileUnit == RHS.CompileUnit &&
00081              LHS.Line        == RHS.Line &&
00082              LHS.Col         == RHS.Col;
00083     }
00084 
00085     static bool isPod() { return true; }
00086   };
00087 
00088   /// DebugLocTracker - This class tracks debug location information.
00089   ///
00090   struct DebugLocTracker {
00091     /// DebugLocations - A vector of unique DebugLocTuple's.
00092     ///
00093     std::vector<DebugLocTuple> DebugLocations;
00094 
00095     /// DebugIdMap - This maps DebugLocTuple's to indices into the
00096     /// DebugLocations vector.
00097     DenseMap<DebugLocTuple, unsigned> DebugIdMap;
00098 
00099     DebugLocTracker() {}
00100   };
00101   
00102 } // end namespace llvm
00103 
00104 #endif /* LLVM_DEBUGLOC_H */