CGDebugInfo.h revision 8fae060d6ef78d4cdd19ebff7dea9c3a566f8b23
1//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This is the source level debug info generator for llvm translation. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef CLANG_CODEGEN_CGDEBUGINFO_H 15#define CLANG_CODEGEN_CGDEBUGINFO_H 16 17#include "clang/AST/Type.h" 18#include "clang/AST/Expr.h" 19#include "clang/Basic/SourceLocation.h" 20#include "llvm/ADT/DenseMap.h" 21#include "llvm/Analysis/DebugInfo.h" 22#include "llvm/Support/ValueHandle.h" 23#include <map> 24 25#include "CGBuilder.h" 26 27namespace llvm { 28 class MDNode; 29} 30 31namespace clang { 32 class VarDecl; 33 class ObjCInterfaceDecl; 34 35namespace CodeGen { 36 class CodeGenModule; 37 class CodeGenFunction; 38 39/// CGDebugInfo - This class gathers all debug information during compilation 40/// and is responsible for emitting to llvm globals or pass directly to 41/// the backend. 42class CGDebugInfo { 43 CodeGenModule *M; 44 bool isMainCompileUnitCreated; 45 llvm::DIFactory DebugFactory; 46 47 SourceLocation CurLoc, PrevLoc; 48 49 /// CompileUnitCache - Cache of previously constructed CompileUnits. 50 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; 51 52 /// TypeCache - Cache of previously constructed Types. 53 // FIXME: Eliminate this map. Be careful of iterator invalidation. 54 std::map<void *, llvm::WeakVH> TypeCache; 55 56 bool BlockLiteralGenericSet; 57 llvm::DIType BlockLiteralGeneric; 58 59 std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack; 60 61 /// Helper functions for getOrCreateType. 62 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); 63 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); 64 llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U); 65 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); 66 llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 67 llvm::DICompileUnit Unit); 68 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); 69 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); 70 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); 71 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); 72 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); 73 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); 74 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); 75 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); 76 llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U); 77 78 llvm::DIType CreatePointerLikeType(unsigned Tag, 79 const Type *Ty, QualType PointeeTy, 80 llvm::DICompileUnit U); 81public: 82 CGDebugInfo(CodeGenModule *m); 83 ~CGDebugInfo(); 84 85 /// setLocation - Update the current source location. If \arg loc is 86 /// invalid it is ignored. 87 void setLocation(SourceLocation Loc); 88 89 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 90 /// source line. 91 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 92 93 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 94 /// start of a new function. 95 void EmitFunctionStart(const char *Name, QualType FnType, 96 llvm::Function *Fn, CGBuilderTy &Builder); 97 98 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 99 /// of a new block. 100 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 101 102 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 103 /// block. 104 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 105 106 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 107 /// variable declaration. 108 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 109 CGBuilderTy &Builder); 110 111 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 112 /// imported variable declaration in a block. 113 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, 114 llvm::Value *AI, 115 CGBuilderTy &Builder, 116 CodeGenFunction *CGF); 117 118 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 119 /// variable declaration. 120 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 121 CGBuilderTy &Builder); 122 123 /// EmitGlobalVariable - Emit information about a global variable. 124 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 125 126 /// EmitGlobalVariable - Emit information about an objective-c interface. 127 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 128 129private: 130 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 131 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 132 CGBuilderTy &Builder); 133 134 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 135 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, 136 CGBuilderTy &Builder, CodeGenFunction *CGF); 137 138 /// getContext - Get context info for the decl. 139 llvm::DIDescriptor getContext(const VarDecl *Decl,llvm::DIDescriptor &CU); 140 141 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a 142 /// new one if necessary. 143 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); 144 145 /// getOrCreateType - Get the type from the cache or create a new type if 146 /// necessary. 147 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); 148 149 /// CreateTypeNode - Create type metadata for a source language type. 150 llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); 151}; 152} // namespace CodeGen 153} // namespace clang 154 155 156#endif 157