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