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 | // |
| 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 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceLocation.h" |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
| 20 | #include "llvm/Analysis/DebugInfo.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 21 | #include <map> |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 23 | #include "CGBuilder.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 24 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 25 | namespace clang { |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 26 | class VarDecl; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 27 | class ObjCInterfaceDecl; |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 28 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 29 | namespace CodeGen { |
| 30 | class CodeGenModule; |
| 31 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 32 | /// CGDebugInfo - This class gathers all debug information during compilation |
| 33 | /// and is responsible for emitting to llvm globals or pass directly to |
| 34 | /// the backend. |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 35 | class CGDebugInfo { |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 36 | CodeGenModule *M; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 37 | llvm::DIFactory DebugFactory; |
| 38 | |
| 39 | SourceLocation CurLoc, PrevLoc; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 40 | |
| 41 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 42 | llvm::DenseMap<const FileEntry*, llvm::DICompileUnit> CompileUnitCache; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 43 | |
| 44 | /// TypeCache - Cache of previously constructed Types. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 45 | // FIXME: Eliminate this map. Be careful of iterator invalidation. |
| 46 | std::map<void *, llvm::DIType> TypeCache; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 48 | std::vector<llvm::DIDescriptor> RegionStack; |
Eli Friedman | 3f2af10 | 2008-05-22 01:40:10 +0000 | [diff] [blame] | 49 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 50 | /// Helper functions for getOrCreateType. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 51 | llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); |
| 52 | llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U); |
| 53 | llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); |
| 54 | llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); |
| 55 | llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); |
| 56 | llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); |
| 57 | llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 58 | llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 59 | llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); |
| 60 | llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 61 | |
| 62 | public: |
| 63 | CGDebugInfo(CodeGenModule *m); |
| 64 | ~CGDebugInfo(); |
| 65 | |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 66 | /// setLocation - Update the current source location. If \arg loc is |
| 67 | /// invalid it is ignored. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 68 | void setLocation(SourceLocation Loc); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 69 | |
| 70 | /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of |
| 71 | /// source line. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 72 | void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 73 | |
| 74 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
Daniel Dunbar | 2284ac9 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 75 | /// start of a new function. |
| 76 | void EmitFunctionStart(const char *Name, QualType ReturnType, |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 77 | llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 78 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 79 | /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 80 | /// of a new block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 81 | void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 82 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 83 | /// 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] | 84 | /// block. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 85 | void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 87 | /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic |
| 88 | /// variable declaration. |
| 89 | void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, |
| 90 | CGBuilderTy &Builder); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 92 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 93 | /// variable declaration. |
| 94 | void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, |
| 95 | CGBuilderTy &Builder); |
| 96 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 97 | /// EmitGlobalVariable - Emit information about a global variable. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 98 | void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 99 | |
| 100 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
| 101 | void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); |
| 102 | |
Chris Lattner | 86cd8af | 2008-11-03 09:11:11 +0000 | [diff] [blame] | 103 | private: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 104 | /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. |
| 105 | void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, |
| 106 | CGBuilderTy &Builder); |
| 107 | |
Chris Lattner | 86cd8af | 2008-11-03 09:11:11 +0000 | [diff] [blame] | 108 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 109 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 110 | /// new one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 111 | llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 112 | |
| 113 | /// getOrCreateType - Get the type from the cache or create a new type if |
| 114 | /// necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 115 | llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 116 | }; |
| 117 | } // namespace CodeGen |
| 118 | } // namespace clang |
| 119 | |
| 120 | #endif |