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