LLVM API Documentation
00001 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- 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 bunch of datatypes that are useful for creating and 00011 // walking debug info in LLVM IR form. They essentially provide wrappers around 00012 // the information in the global variables that's needed when constructing the 00013 // DWARF information. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_ANALYSIS_DEBUGINFO_H 00018 #define LLVM_ANALYSIS_DEBUGINFO_H 00019 00020 #include "llvm/Target/TargetMachine.h" 00021 #include "llvm/ADT/StringMap.h" 00022 #include "llvm/ADT/DenseMap.h" 00023 #include "llvm/ADT/SmallVector.h" 00024 #include "llvm/ADT/SmallPtrSet.h" 00025 #include "llvm/Support/Dwarf.h" 00026 00027 namespace llvm { 00028 class BasicBlock; 00029 class Constant; 00030 class Function; 00031 class GlobalVariable; 00032 class Module; 00033 class Type; 00034 class Value; 00035 struct DbgStopPointInst; 00036 struct DbgDeclareInst; 00037 struct DbgFuncStartInst; 00038 struct DbgRegionStartInst; 00039 struct DbgRegionEndInst; 00040 class DebugLoc; 00041 struct DebugLocTracker; 00042 class Instruction; 00043 class LLVMContext; 00044 00045 class DIDescriptor { 00046 protected: 00047 GlobalVariable *DbgGV; 00048 00049 /// DIDescriptor constructor. If the specified GV is non-null, this checks 00050 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If 00051 /// not, the debug info is corrupt and we ignore it. 00052 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag); 00053 00054 const std::string &getStringField(unsigned Elt, std::string &Result) const; 00055 unsigned getUnsignedField(unsigned Elt) const { 00056 return (unsigned)getUInt64Field(Elt); 00057 } 00058 uint64_t getUInt64Field(unsigned Elt) const; 00059 DIDescriptor getDescriptorField(unsigned Elt) const; 00060 00061 template <typename DescTy> 00062 DescTy getFieldAs(unsigned Elt) const { 00063 return DescTy(getDescriptorField(Elt).getGV()); 00064 } 00065 00066 GlobalVariable *getGlobalVariableField(unsigned Elt) const; 00067 00068 public: 00069 explicit DIDescriptor() : DbgGV(0) {} 00070 explicit DIDescriptor(GlobalVariable *GV) : DbgGV(GV) {} 00071 00072 bool isNull() const { return DbgGV == 0; } 00073 00074 GlobalVariable *getGV() const { return DbgGV; } 00075 00076 unsigned getVersion() const { 00077 return getUnsignedField(0) & LLVMDebugVersionMask; 00078 } 00079 00080 unsigned getTag() const { 00081 return getUnsignedField(0) & ~LLVMDebugVersionMask; 00082 } 00083 00084 /// ValidDebugInfo - Return true if V represents valid debug info value. 00085 static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel); 00086 00087 /// dump - print descriptor. 00088 void dump() const; 00089 }; 00090 00091 /// DISubrange - This is used to represent ranges, for array bounds. 00092 class DISubrange : public DIDescriptor { 00093 public: 00094 explicit DISubrange(GlobalVariable *GV = 0) 00095 : DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {} 00096 00097 int64_t getLo() const { return (int64_t)getUInt64Field(1); } 00098 int64_t getHi() const { return (int64_t)getUInt64Field(2); } 00099 }; 00100 00101 /// DIArray - This descriptor holds an array of descriptors. 00102 class DIArray : public DIDescriptor { 00103 public: 00104 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {} 00105 00106 unsigned getNumElements() const; 00107 DIDescriptor getElement(unsigned Idx) const { 00108 return getDescriptorField(Idx); 00109 } 00110 }; 00111 00112 /// DICompileUnit - A wrapper for a compile unit. 00113 class DICompileUnit : public DIDescriptor { 00114 public: 00115 explicit DICompileUnit(GlobalVariable *GV = 0) 00116 : DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {} 00117 00118 unsigned getLanguage() const { return getUnsignedField(2); } 00119 const std::string &getFilename(std::string &F) const { 00120 return getStringField(3, F); 00121 } 00122 const std::string &getDirectory(std::string &F) const { 00123 return getStringField(4, F); 00124 } 00125 const std::string &getProducer(std::string &F) const { 00126 return getStringField(5, F); 00127 } 00128 00129 /// isMain - Each input file is encoded as a separate compile unit in LLVM 00130 /// debugging information output. However, many target specific tool chains 00131 /// prefer to encode only one compile unit in an object file. In this 00132 /// situation, the LLVM code generator will include debugging information 00133 /// entities in the compile unit that is marked as main compile unit. The 00134 /// code generator accepts maximum one main compile unit per module. If a 00135 /// module does not contain any main compile unit then the code generator 00136 /// will emit multiple compile units in the output object file. 00137 00138 bool isMain() const { return getUnsignedField(6); } 00139 bool isOptimized() const { return getUnsignedField(7); } 00140 const std::string &getFlags(std::string &F) const { 00141 return getStringField(8, F); 00142 } 00143 unsigned getRunTimeVersion() const { return getUnsignedField(9); } 00144 00145 /// Verify - Verify that a compile unit is well formed. 00146 bool Verify() const; 00147 00148 /// dump - print compile unit. 00149 void dump() const; 00150 }; 00151 00152 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). 00153 /// FIXME: it seems strange that this doesn't have either a reference to the 00154 /// type/precision or a file/line pair for location info. 00155 class DIEnumerator : public DIDescriptor { 00156 public: 00157 explicit DIEnumerator(GlobalVariable *GV = 0) 00158 : DIDescriptor(GV, dwarf::DW_TAG_enumerator) {} 00159 00160 const std::string &getName(std::string &F) const { 00161 return getStringField(1, F); 00162 } 00163 uint64_t getEnumValue() const { return getUInt64Field(2); } 00164 }; 00165 00166 /// DIType - This is a wrapper for a type. 00167 /// FIXME: Types should be factored much better so that CV qualifiers and 00168 /// others do not require a huge and empty descriptor full of zeros. 00169 class DIType : public DIDescriptor { 00170 public: 00171 enum { 00172 FlagPrivate = 1 << 0, 00173 FlagProtected = 1 << 1, 00174 FlagFwdDecl = 1 << 2 00175 }; 00176 00177 protected: 00178 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {} 00179 // This ctor is used when the Tag has already been validated by a derived 00180 // ctor. 00181 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {} 00182 00183 public: 00184 /// isDerivedType - Return true if the specified tag is legal for 00185 /// DIDerivedType. 00186 static bool isDerivedType(unsigned TAG); 00187 00188 /// isCompositeType - Return true if the specified tag is legal for 00189 /// DICompositeType. 00190 static bool isCompositeType(unsigned TAG); 00191 00192 /// isBasicType - Return true if the specified tag is legal for 00193 /// DIBasicType. 00194 static bool isBasicType(unsigned TAG) { 00195 return TAG == dwarf::DW_TAG_base_type; 00196 } 00197 00198 /// Verify - Verify that a type descriptor is well formed. 00199 bool Verify() const; 00200 public: 00201 explicit DIType(GlobalVariable *GV); 00202 explicit DIType() {} 00203 virtual ~DIType() {} 00204 00205 DIDescriptor getContext() const { return getDescriptorField(1); } 00206 const std::string &getName(std::string &F) const { 00207 return getStringField(2, F); 00208 } 00209 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } 00210 unsigned getLineNumber() const { return getUnsignedField(4); } 00211 uint64_t getSizeInBits() const { return getUInt64Field(5); } 00212 uint64_t getAlignInBits() const { return getUInt64Field(6); } 00213 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type 00214 // carry this is just plain insane. 00215 uint64_t getOffsetInBits() const { return getUInt64Field(7); } 00216 unsigned getFlags() const { return getUnsignedField(8); } 00217 bool isPrivate() const { return 00218 (getFlags() & FlagPrivate) != 0; 00219 } 00220 bool isProtected() const { 00221 return (getFlags() & FlagProtected) != 0; 00222 } 00223 bool isForwardDecl() const { 00224 return (getFlags() & FlagFwdDecl) != 0; 00225 } 00226 00227 /// dump - print type. 00228 void dump() const; 00229 }; 00230 00231 /// DIBasicType - A basic type, like 'int' or 'float'. 00232 class DIBasicType : public DIType { 00233 public: 00234 explicit DIBasicType(GlobalVariable *GV) 00235 : DIType(GV, dwarf::DW_TAG_base_type) {} 00236 00237 unsigned getEncoding() const { return getUnsignedField(9); } 00238 00239 /// dump - print basic type. 00240 void dump() const; 00241 }; 00242 00243 /// DIDerivedType - A simple derived type, like a const qualified type, 00244 /// a typedef, a pointer or reference, etc. 00245 class DIDerivedType : public DIType { 00246 protected: 00247 explicit DIDerivedType(GlobalVariable *GV, bool, bool) 00248 : DIType(GV, true, true) {} 00249 public: 00250 explicit DIDerivedType(GlobalVariable *GV) 00251 : DIType(GV, true, true) { 00252 if (GV && !isDerivedType(getTag())) 00253 DbgGV = 0; 00254 } 00255 00256 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } 00257 00258 /// getOriginalTypeSize - If this type is derived from a base type then 00259 /// return base type size. 00260 uint64_t getOriginalTypeSize() const; 00261 /// dump - print derived type. 00262 void dump() const; 00263 00264 /// replaceAllUsesWith - Replace all uses of debug info referenced by 00265 /// this descriptor. After this completes, the current debug info value 00266 /// is erased. 00267 void replaceAllUsesWith(DIDescriptor &D); 00268 }; 00269 00270 /// DICompositeType - This descriptor holds a type that can refer to multiple 00271 /// other types, like a function or struct. 00272 /// FIXME: Why is this a DIDerivedType?? 00273 class DICompositeType : public DIDerivedType { 00274 public: 00275 explicit DICompositeType(GlobalVariable *GV) 00276 : DIDerivedType(GV, true, true) { 00277 if (GV && !isCompositeType(getTag())) 00278 DbgGV = 0; 00279 } 00280 00281 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } 00282 unsigned getRunTimeLang() const { return getUnsignedField(11); } 00283 00284 /// Verify - Verify that a composite type descriptor is well formed. 00285 bool Verify() const; 00286 00287 /// dump - print composite type. 00288 void dump() const; 00289 }; 00290 00291 /// DIGlobal - This is a common class for global variables and subprograms. 00292 class DIGlobal : public DIDescriptor { 00293 protected: 00294 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag) 00295 : DIDescriptor(GV, RequiredTag) {} 00296 00297 /// isSubprogram - Return true if the specified tag is legal for 00298 /// DISubprogram. 00299 static bool isSubprogram(unsigned TAG) { 00300 return TAG == dwarf::DW_TAG_subprogram; 00301 } 00302 00303 /// isGlobalVariable - Return true if the specified tag is legal for 00304 /// DIGlobalVariable. 00305 static bool isGlobalVariable(unsigned TAG) { 00306 return TAG == dwarf::DW_TAG_variable; 00307 } 00308 00309 public: 00310 virtual ~DIGlobal() {} 00311 00312 DIDescriptor getContext() const { return getDescriptorField(2); } 00313 const std::string &getName(std::string &F) const { 00314 return getStringField(3, F); 00315 } 00316 const std::string &getDisplayName(std::string &F) const { 00317 return getStringField(4, F); 00318 } 00319 const std::string &getLinkageName(std::string &F) const { 00320 return getStringField(5, F); 00321 } 00322 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } 00323 unsigned getLineNumber() const { return getUnsignedField(7); } 00324 DIType getType() const { return getFieldAs<DIType>(8); } 00325 00326 /// isLocalToUnit - Return true if this subprogram is local to the current 00327 /// compile unit, like 'static' in C. 00328 unsigned isLocalToUnit() const { return getUnsignedField(9); } 00329 unsigned isDefinition() const { return getUnsignedField(10); } 00330 00331 /// dump - print global. 00332 void dump() const; 00333 }; 00334 00335 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). 00336 class DISubprogram : public DIGlobal { 00337 public: 00338 explicit DISubprogram(GlobalVariable *GV = 0) 00339 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {} 00340 00341 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } 00342 00343 /// getReturnTypeName - Subprogram return types are encoded either as 00344 /// DIType or as DICompositeType. 00345 const std::string &getReturnTypeName(std::string &F) const { 00346 DICompositeType DCT(getFieldAs<DICompositeType>(8)); 00347 if (!DCT.isNull()) { 00348 DIArray A = DCT.getTypeArray(); 00349 DIType T(A.getElement(0).getGV()); 00350 return T.getName(F); 00351 } 00352 DIType T(getFieldAs<DIType>(8)); 00353 return T.getName(F); 00354 } 00355 00356 /// Verify - Verify that a subprogram descriptor is well formed. 00357 bool Verify() const; 00358 00359 /// dump - print subprogram. 00360 void dump() const; 00361 00362 /// describes - Return true if this subprogram provides debugging 00363 /// information for the function F. 00364 bool describes(const Function *F); 00365 }; 00366 00367 /// DIGlobalVariable - This is a wrapper for a global variable. 00368 class DIGlobalVariable : public DIGlobal { 00369 public: 00370 explicit DIGlobalVariable(GlobalVariable *GV = 0) 00371 : DIGlobal(GV, dwarf::DW_TAG_variable) {} 00372 00373 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } 00374 00375 /// Verify - Verify that a global variable descriptor is well formed. 00376 bool Verify() const; 00377 00378 /// dump - print global variable. 00379 void dump() const; 00380 }; 00381 00382 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, 00383 /// global etc). 00384 class DIVariable : public DIDescriptor { 00385 public: 00386 explicit DIVariable(GlobalVariable *GV = 0) 00387 : DIDescriptor(GV) { 00388 if (GV && !isVariable(getTag())) 00389 DbgGV = 0; 00390 } 00391 00392 DIDescriptor getContext() const { return getDescriptorField(1); } 00393 const std::string &getName(std::string &F) const { 00394 return getStringField(2, F); 00395 } 00396 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } 00397 unsigned getLineNumber() const { return getUnsignedField(4); } 00398 DIType getType() const { return getFieldAs<DIType>(5); } 00399 00400 /// isVariable - Return true if the specified tag is legal for DIVariable. 00401 static bool isVariable(unsigned Tag); 00402 00403 /// Verify - Verify that a variable descriptor is well formed. 00404 bool Verify() const; 00405 00406 /// dump - print variable. 00407 void dump() const; 00408 }; 00409 00410 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc). 00411 class DIBlock : public DIDescriptor { 00412 public: 00413 explicit DIBlock(GlobalVariable *GV = 0) 00414 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {} 00415 00416 DIDescriptor getContext() const { return getDescriptorField(1); } 00417 }; 00418 00419 /// DIFactory - This object assists with the construction of the various 00420 /// descriptors. 00421 class DIFactory { 00422 Module &M; 00423 LLVMContext& VMContext; 00424 00425 // Cached values for uniquing and faster lookups. 00426 const Type *EmptyStructPtr; // "{}*". 00427 Function *StopPointFn; // llvm.dbg.stoppoint 00428 Function *FuncStartFn; // llvm.dbg.func.start 00429 Function *RegionStartFn; // llvm.dbg.region.start 00430 Function *RegionEndFn; // llvm.dbg.region.end 00431 Function *DeclareFn; // llvm.dbg.declare 00432 StringMap<Constant*> StringCache; 00433 DenseMap<Constant*, DIDescriptor> SimpleConstantCache; 00434 00435 DIFactory(const DIFactory &); // DO NOT IMPLEMENT 00436 void operator=(const DIFactory&); // DO NOT IMPLEMENT 00437 public: 00438 explicit DIFactory(Module &m); 00439 00440 /// GetOrCreateArray - Create an descriptor for an array of descriptors. 00441 /// This implicitly uniques the arrays created. 00442 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); 00443 00444 /// GetOrCreateSubrange - Create a descriptor for a value range. This 00445 /// implicitly uniques the values returned. 00446 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); 00447 00448 /// CreateCompileUnit - Create a new descriptor for the specified compile 00449 /// unit. 00450 DICompileUnit CreateCompileUnit(unsigned LangID, 00451 const std::string &Filename, 00452 const std::string &Directory, 00453 const std::string &Producer, 00454 bool isMain = false, 00455 bool isOptimized = false, 00456 const char *Flags = "", 00457 unsigned RunTimeVer = 0); 00458 00459 /// CreateEnumerator - Create a single enumerator value. 00460 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); 00461 00462 /// CreateBasicType - Create a basic type like int, float, etc. 00463 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name, 00464 DICompileUnit CompileUnit, unsigned LineNumber, 00465 uint64_t SizeInBits, uint64_t AlignInBits, 00466 uint64_t OffsetInBits, unsigned Flags, 00467 unsigned Encoding); 00468 00469 /// CreateDerivedType - Create a derived type like const qualified type, 00470 /// pointer, typedef, etc. 00471 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, 00472 const std::string &Name, 00473 DICompileUnit CompileUnit, 00474 unsigned LineNumber, 00475 uint64_t SizeInBits, uint64_t AlignInBits, 00476 uint64_t OffsetInBits, unsigned Flags, 00477 DIType DerivedFrom); 00478 00479 /// CreateCompositeType - Create a composite type like array, struct, etc. 00480 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, 00481 const std::string &Name, 00482 DICompileUnit CompileUnit, 00483 unsigned LineNumber, 00484 uint64_t SizeInBits, 00485 uint64_t AlignInBits, 00486 uint64_t OffsetInBits, unsigned Flags, 00487 DIType DerivedFrom, 00488 DIArray Elements, 00489 unsigned RunTimeLang = 0); 00490 00491 /// CreateSubprogram - Create a new descriptor for the specified subprogram. 00492 /// See comments in DISubprogram for descriptions of these fields. 00493 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name, 00494 const std::string &DisplayName, 00495 const std::string &LinkageName, 00496 DICompileUnit CompileUnit, unsigned LineNo, 00497 DIType Type, bool isLocalToUnit, 00498 bool isDefinition); 00499 00500 /// CreateGlobalVariable - Create a new descriptor for the specified global. 00501 DIGlobalVariable 00502 CreateGlobalVariable(DIDescriptor Context, const std::string &Name, 00503 const std::string &DisplayName, 00504 const std::string &LinkageName, 00505 DICompileUnit CompileUnit, 00506 unsigned LineNo, DIType Type, bool isLocalToUnit, 00507 bool isDefinition, llvm::GlobalVariable *GV); 00508 00509 /// CreateVariable - Create a new descriptor for the specified variable. 00510 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, 00511 const std::string &Name, 00512 DICompileUnit CompileUnit, unsigned LineNo, 00513 DIType Type); 00514 00515 /// CreateBlock - This creates a descriptor for a lexical block with the 00516 /// specified parent context. 00517 DIBlock CreateBlock(DIDescriptor Context); 00518 00519 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, 00520 /// inserting it at the end of the specified basic block. 00521 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo, 00522 BasicBlock *BB); 00523 00524 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to 00525 /// mark the start of the specified subprogram. 00526 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB); 00527 00528 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to 00529 /// mark the start of a region for the specified scoping descriptor. 00530 void InsertRegionStart(DIDescriptor D, BasicBlock *BB); 00531 00532 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to 00533 /// mark the end of a region for the specified scoping descriptor. 00534 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB); 00535 00536 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. 00537 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB); 00538 00539 private: 00540 Constant *GetTagConstant(unsigned TAG); 00541 Constant *GetStringConstant(const std::string &String); 00542 00543 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'. 00544 Constant *getCastToEmpty(DIDescriptor D); 00545 }; 00546 00547 /// Finds the stoppoint coressponding to this instruction, that is the 00548 /// stoppoint that dominates this instruction 00549 const DbgStopPointInst *findStopPoint(const Instruction *Inst); 00550 00551 /// Finds the stoppoint corresponding to first real (non-debug intrinsic) 00552 /// instruction in this Basic Block, and returns the stoppoint for it. 00553 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB); 00554 00555 /// Finds the dbg.declare intrinsic corresponding to this value if any. 00556 /// It looks through pointer casts too. 00557 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); 00558 00559 /// Find the debug info descriptor corresponding to this global variable. 00560 Value *findDbgGlobalDeclare(GlobalVariable *V); 00561 00562 bool getLocationInfo(const Value *V, std::string &DisplayName, 00563 std::string &Type, unsigned &LineNo, std::string &File, 00564 std::string &Dir); 00565 00566 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug 00567 /// info intrinsic. 00568 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI, 00569 CodeGenOpt::Level OptLev); 00570 00571 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug 00572 /// info intrinsic. 00573 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI, 00574 CodeGenOpt::Level OptLev); 00575 00576 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug 00577 /// info intrinsic. 00578 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI, 00579 CodeGenOpt::Level OptLev); 00580 00581 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug 00582 /// info intrinsic. 00583 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI, 00584 CodeGenOpt::Level OptLev); 00585 00586 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug 00587 /// info intrinsic. 00588 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI, 00589 CodeGenOpt::Level OptLev); 00590 00591 /// ExtractDebugLocation - Extract debug location information 00592 /// from llvm.dbg.stoppoint intrinsic. 00593 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI, 00594 DebugLocTracker &DebugLocInfo); 00595 00596 /// ExtractDebugLocation - Extract debug location information 00597 /// from llvm.dbg.func_start intrinsic. 00598 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI, 00599 DebugLocTracker &DebugLocInfo); 00600 00601 /// isInlinedFnStart - Return true if FSI is starting an inlined function. 00602 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn); 00603 00604 /// isInlinedFnEnd - Return true if REI is ending an inlined function. 00605 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn); 00606 00607 /// DebugInfoFinder - This object collects DebugInfo from a module. 00608 class DebugInfoFinder { 00609 00610 public: 00611 /// processModule - Process entire module and collect debug info 00612 /// anchors. 00613 void processModule(Module &M); 00614 00615 private: 00616 /// processType - Process DIType. 00617 void processType(DIType DT); 00618 00619 /// processSubprogram - Enumberate DISubprogram. 00620 void processSubprogram(DISubprogram SP); 00621 00622 /// processStopPoint - Process DbgStopPointInst. 00623 void processStopPoint(DbgStopPointInst *SPI); 00624 00625 /// processFuncStart - Process DbgFuncStartInst. 00626 void processFuncStart(DbgFuncStartInst *FSI); 00627 00628 /// processRegionStart - Process DbgRegionStart. 00629 void processRegionStart(DbgRegionStartInst *DRS); 00630 00631 /// processRegionEnd - Process DbgRegionEnd. 00632 void processRegionEnd(DbgRegionEndInst *DRE); 00633 00634 /// processDeclare - Process DbgDeclareInst. 00635 void processDeclare(DbgDeclareInst *DDI); 00636 00637 /// addCompileUnit - Add compile unit into CUs. 00638 bool addCompileUnit(DICompileUnit CU); 00639 00640 /// addGlobalVariable - Add global variable into GVs. 00641 bool addGlobalVariable(DIGlobalVariable DIG); 00642 00643 // addSubprogram - Add subprgoram into SPs. 00644 bool addSubprogram(DISubprogram SP); 00645 00646 /// addType - Add type into Tys. 00647 bool addType(DIType DT); 00648 00649 public: 00650 typedef SmallVector<GlobalVariable *, 8>::iterator iterator; 00651 iterator compile_unit_begin() { return CUs.begin(); } 00652 iterator compile_unit_end() { return CUs.end(); } 00653 iterator subprogram_begin() { return SPs.begin(); } 00654 iterator subprogram_end() { return SPs.end(); } 00655 iterator global_variable_begin() { return GVs.begin(); } 00656 iterator global_variable_end() { return GVs.end(); } 00657 iterator type_begin() { return TYs.begin(); } 00658 iterator type_end() { return TYs.end(); } 00659 00660 unsigned compile_unit_count() { return CUs.size(); } 00661 unsigned global_variable_count() { return GVs.size(); } 00662 unsigned subprogram_count() { return SPs.size(); } 00663 unsigned type_count() { return TYs.size(); } 00664 00665 private: 00666 SmallVector<GlobalVariable *, 8> CUs; // Compile Units 00667 SmallVector<GlobalVariable *, 8> SPs; // Subprograms 00668 SmallVector<GlobalVariable *, 8> GVs; // Global Variables 00669 SmallVector<GlobalVariable *, 8> TYs; // Types 00670 SmallPtrSet<GlobalVariable *, 64> NodesSeen; 00671 00672 }; 00673 } // end namespace llvm 00674 00675 #endif