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" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 23 | #include <map> |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 25 | #include "CGBuilder.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 26 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 27 | namespace llvm { |
| 28 | class MDNode; |
| 29 | } |
| 30 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 31 | namespace clang { |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 32 | class VarDecl; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 33 | class ObjCInterfaceDecl; |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 34 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 35 | namespace CodeGen { |
| 36 | class CodeGenModule; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 37 | class CodeGenFunction; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 38 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | /// CGDebugInfo - This class gathers all debug information during compilation |
| 40 | /// and is responsible for emitting to llvm globals or pass directly to |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 41 | /// the backend. |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 42 | class CGDebugInfo { |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 43 | CodeGenModule *M; |
Devang Patel | 87de649 | 2009-04-23 18:09:16 +0000 | [diff] [blame] | 44 | bool isMainCompileUnitCreated; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 45 | llvm::DIFactory DebugFactory; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 47 | SourceLocation CurLoc, PrevLoc; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 48 | |
| 49 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 50 | llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 51 | |
| 52 | /// TypeCache - Cache of previously constructed Types. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 53 | // FIXME: Eliminate this map. Be careful of iterator invalidation. |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 54 | std::map<void *, llvm::WeakVH> TypeCache; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 56 | bool BlockLiteralGenericSet; |
| 57 | llvm::DIType BlockLiteralGeneric; |
| 58 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 59 | std::vector<llvm::DIDescriptor> RegionStack; |
Eli Friedman | 3f2af10 | 2008-05-22 01:40:10 +0000 | [diff] [blame] | 60 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 61 | /// Helper functions for getOrCreateType. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 62 | llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 63 | llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 64 | llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 65 | llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 66 | llvm::DIType CreateType(const ObjCObjectPointerType *Ty, |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 67 | llvm::DICompileUnit Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 68 | llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 69 | llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 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); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 73 | llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 74 | llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); |
| 75 | llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 76 | |
| 77 | public: |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 78 | CGDebugInfo(CodeGenModule *m); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 79 | ~CGDebugInfo(); |
| 80 | |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 81 | /// setLocation - Update the current source location. If \arg loc is |
| 82 | /// invalid it is ignored. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 83 | void setLocation(SourceLocation Loc); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 84 | |
| 85 | /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of |
| 86 | /// source line. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 87 | void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 88 | |
| 89 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
Daniel Dunbar | 2284ac9 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 90 | /// start of a new function. |
Mike Stump | 91cc815 | 2009-10-23 01:52:13 +0000 | [diff] [blame^] | 91 | void EmitFunctionStart(const char *Name, QualType FnType, |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 92 | llvm::Function *Fn, CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 94 | /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | /// of a new block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 96 | void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
| 98 | /// 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] | 99 | /// block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 100 | void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 101 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 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); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 106 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 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); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 119 | /// EmitGlobalVariable - Emit information about a global variable. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 120 | void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 121 | |
| 122 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
| 123 | void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Chris Lattner | 86cd8af | 2008-11-03 09:11:11 +0000 | [diff] [blame] | 125 | private: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 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); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 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); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 134 | /// getContext - Get context info for the decl. |
| 135 | llvm::DIDescriptor getContext(const VarDecl *Decl,llvm::DIDescriptor &CU); |
| 136 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 137 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 138 | /// new one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 139 | llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 140 | |
| 141 | /// getOrCreateType - Get the type from the cache or create a new type if |
| 142 | /// necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 143 | llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 144 | |
| 145 | /// CreateTypeNode - Create type metadata for a source language type. |
| 146 | llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 147 | }; |
| 148 | } // namespace CodeGen |
| 149 | } // namespace clang |
| 150 | |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 151 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 152 | #endif |