CGDebugInfo.h revision 200583
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 &CGM; 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 llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U); 78 79 llvm::DIType CreatePointerLikeType(unsigned Tag, 80 const Type *Ty, QualType PointeeTy, 81 llvm::DICompileUnit U); 82public: 83 CGDebugInfo(CodeGenModule &CGM); 84 ~CGDebugInfo(); 85 86 /// setLocation - Update the current source location. If \arg loc is 87 /// invalid it is ignored. 88 void setLocation(SourceLocation Loc); 89 90 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 91 /// source line. 92 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 93 94 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 95 /// start of a new function. 96 void EmitFunctionStart(llvm::StringRef Name, QualType FnType, 97 llvm::Function *Fn, CGBuilderTy &Builder); 98 99 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 100 /// of a new block. 101 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 102 103 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 104 /// block. 105 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 106 107 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 108 /// variable declaration. 109 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 110 CGBuilderTy &Builder); 111 112 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 113 /// imported variable declaration in a block. 114 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, 115 llvm::Value *AI, 116 CGBuilderTy &Builder, 117 CodeGenFunction *CGF); 118 119 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 120 /// variable declaration. 121 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 122 CGBuilderTy &Builder); 123 124 /// EmitGlobalVariable - Emit information about a global variable. 125 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 126 127 /// EmitGlobalVariable - Emit information about an objective-c interface. 128 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 129 130private: 131 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 132 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 133 CGBuilderTy &Builder); 134 135 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 136 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, 137 CGBuilderTy &Builder, CodeGenFunction *CGF); 138 139 /// getContext - Get context info for the decl. 140 llvm::DIDescriptor getContext(const VarDecl *Decl,llvm::DIDescriptor &CU); 141 142 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a 143 /// new one if necessary. 144 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); 145 146 /// getOrCreateType - Get the type from the cache or create a new type if 147 /// necessary. 148 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); 149 150 /// CreateTypeNode - Create type metadata for a source language type. 151 llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); 152}; 153} // namespace CodeGen 154} // namespace clang 155 156 157#endif 158