Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 1 | //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===// |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 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 | // |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10 | // This is the source level debug info generator for llvm translation. |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANG_CODEGEN_CGDEBUGINFO_H |
| 15 | #define CLANG_CODEGEN_CGDEBUGINFO_H |
| 16 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 19 | #include "clang/Basic/SourceLocation.h" |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/Analysis/DebugInfo.h" |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ValueHandle.h" |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Allocator.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 24 | #include <map> |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 25 | |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 26 | #include "CGBuilder.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 27 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 28 | namespace llvm { |
| 29 | class MDNode; |
| 30 | } |
| 31 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 32 | namespace clang { |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 33 | class VarDecl; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 34 | class ObjCInterfaceDecl; |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 35 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 36 | namespace CodeGen { |
| 37 | class CodeGenModule; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 38 | class CodeGenFunction; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 39 | class GlobalDecl; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 40 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | /// CGDebugInfo - This class gathers all debug information during compilation |
| 42 | /// and is responsible for emitting to llvm globals or pass directly to |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 43 | /// the backend. |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 44 | class CGDebugInfo { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 45 | CodeGenModule &CGM; |
Devang Patel | 87de649 | 2009-04-23 18:09:16 +0000 | [diff] [blame] | 46 | bool isMainCompileUnitCreated; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 47 | llvm::DIFactory DebugFactory; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 49 | SourceLocation CurLoc, PrevLoc; |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 50 | |
| 51 | llvm::DIType VTablePtrType; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 52 | |
| 53 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 54 | llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 55 | |
| 56 | /// TypeCache - Cache of previously constructed Types. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 57 | // FIXME: Eliminate this map. Be careful of iterator invalidation. |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 58 | std::map<void *, llvm::WeakVH> TypeCache; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 59 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 60 | bool BlockLiteralGenericSet; |
| 61 | llvm::DIType BlockLiteralGeneric; |
| 62 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 63 | std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack; |
Devang Patel | 3dd96a1 | 2010-01-29 18:11:03 +0000 | [diff] [blame] | 64 | llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap; |
Eli Friedman | 3f2af10 | 2008-05-22 01:40:10 +0000 | [diff] [blame] | 65 | |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 66 | /// DebugInfoNames - This is a storage for names that are |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 67 | /// constructed on demand. For example, C++ destructors, C++ operators etc.. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 68 | llvm::BumpPtrAllocator DebugInfoNames; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 69 | |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 70 | llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache; |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame^] | 71 | llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache; |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 72 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 73 | /// Helper functions for getOrCreateType. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 74 | llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 75 | llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 76 | llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 77 | llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 78 | llvm::DIType CreateType(const ObjCObjectPointerType *Ty, |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 79 | llvm::DICompileUnit Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 80 | llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 81 | llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 82 | llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); |
| 83 | llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); |
| 84 | llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 85 | llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 86 | llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); |
| 87 | llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 88 | llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 89 | llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 90 | llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, |
| 91 | llvm::DICompileUnit Unit); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 92 | llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame^] | 93 | llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, |
| 94 | llvm::DIDescriptor Unit); |
| 95 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 96 | llvm::DIType CreatePointerLikeType(unsigned Tag, |
| 97 | const Type *Ty, QualType PointeeTy, |
| 98 | llvm::DICompileUnit U); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 99 | |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 100 | llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 101 | llvm::DICompileUnit Unit, |
| 102 | llvm::DICompositeType &RecordTy); |
| 103 | |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 104 | void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, |
| 105 | llvm::DICompileUnit U, |
| 106 | llvm::SmallVectorImpl<llvm::DIDescriptor> &E, |
| 107 | llvm::DICompositeType &T); |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 108 | void CollectCXXBases(const CXXRecordDecl *Decl, |
| 109 | llvm::DICompileUnit Unit, |
| 110 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
| 111 | llvm::DICompositeType &RecordTy); |
| 112 | |
| 113 | |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 114 | void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U, |
| 115 | llvm::SmallVectorImpl<llvm::DIDescriptor> &E); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 116 | |
| 117 | void CollectVtableInfo(const CXXRecordDecl *Decl, |
| 118 | llvm::DICompileUnit Unit, |
| 119 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys); |
| 120 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 121 | public: |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 122 | CGDebugInfo(CodeGenModule &CGM); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 123 | ~CGDebugInfo(); |
| 124 | |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 125 | /// setLocation - Update the current source location. If \arg loc is |
| 126 | /// invalid it is ignored. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 127 | void setLocation(SourceLocation Loc); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 128 | |
| 129 | /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of |
| 130 | /// source line. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 131 | void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 132 | |
| 133 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
Daniel Dunbar | 2284ac9 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 134 | /// start of a new function. |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 135 | void EmitFunctionStart(GlobalDecl GD, QualType FnType, |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 136 | llvm::Function *Fn, CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 137 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 138 | /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | /// of a new block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 140 | void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
| 142 | /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 143 | /// block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 144 | void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 146 | /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic |
| 147 | /// variable declaration. |
| 148 | void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, |
| 149 | CGBuilderTy &Builder); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 150 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 151 | /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an |
| 152 | /// imported variable declaration in a block. |
| 153 | void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, |
| 154 | llvm::Value *AI, |
| 155 | CGBuilderTy &Builder, |
| 156 | CodeGenFunction *CGF); |
| 157 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 158 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 159 | /// variable declaration. |
| 160 | void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, |
| 161 | CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 163 | /// EmitGlobalVariable - Emit information about a global variable. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 164 | void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 165 | |
| 166 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
| 167 | void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 86cd8af | 2008-11-03 09:11:11 +0000 | [diff] [blame] | 169 | private: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 170 | /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. |
| 171 | void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, |
| 172 | CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 174 | /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. |
| 175 | void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, |
| 176 | CGBuilderTy &Builder, CodeGenFunction *CGF); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 178 | /// getContextDescriptor - Get context info for the decl. |
Devang Patel | 3dd96a1 | 2010-01-29 18:11:03 +0000 | [diff] [blame] | 179 | llvm::DIDescriptor getContextDescriptor(const Decl *Decl, |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 180 | llvm::DIDescriptor &CU); |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 181 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 182 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 183 | /// new one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 184 | llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 185 | |
| 186 | /// getOrCreateType - Get the type from the cache or create a new type if |
| 187 | /// necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 188 | llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 189 | |
| 190 | /// CreateTypeNode - Create type metadata for a source language type. |
| 191 | llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 192 | |
| 193 | /// getFunctionName - Get function name for the given FunctionDecl. If the |
| 194 | /// name is constructred on demand (e.g. C++ destructor) then the name |
| 195 | /// is stored on the side. |
| 196 | llvm::StringRef getFunctionName(const FunctionDecl *FD); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 197 | |
| 198 | /// getVtableName - Get vtable name for the given Class. |
| 199 | llvm::StringRef getVtableName(const CXXRecordDecl *Decl); |
| 200 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 201 | }; |
| 202 | } // namespace CodeGen |
| 203 | } // namespace clang |
| 204 | |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 205 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 206 | #endif |