Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1 | //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -----------------------===// |
| 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" |
| 19 | #include <map> |
| 20 | #include <vector> |
| 21 | |
| 22 | |
| 23 | namespace llvm { |
| 24 | class Function; |
| 25 | class IRBuilder; |
| 26 | class DISerializer; |
| 27 | class CompileUnitDesc; |
| 28 | class BasicBlock; |
| 29 | class AnchorDesc; |
| 30 | class DebugInfoDesc; |
| 31 | class Value; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 32 | class TypeDesc; |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 33 | class VariableDesc; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 34 | class SubprogramDesc; |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 35 | class GlobalVariable; |
| 36 | class GlobalVariableDesc; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 37 | class EnumeratorDesc; |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 38 | class SubrangeDesc; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | namespace clang { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 42 | class FunctionDecl; |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 43 | class VarDecl; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 44 | namespace CodeGen { |
| 45 | class CodeGenModule; |
| 46 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 47 | /// CGDebugInfo - This class gathers all debug information during compilation |
| 48 | /// and is responsible for emitting to llvm globals or pass directly to |
| 49 | /// the backend. |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 50 | class CGDebugInfo { |
| 51 | private: |
| 52 | CodeGenModule *M; |
| 53 | llvm::DISerializer *SR; |
| 54 | SourceLocation CurLoc; |
| 55 | SourceLocation PrevLoc; |
| 56 | |
| 57 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
| 58 | std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 59 | |
| 60 | /// TypeCache - Cache of previously constructed Types. |
| 61 | std::map<void *, llvm::TypeDesc *> TypeCache; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 62 | |
| 63 | llvm::Function *StopPointFn; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 64 | llvm::Function *FuncStartFn; |
| 65 | llvm::Function *DeclareFn; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 66 | llvm::Function *RegionStartFn; |
| 67 | llvm::Function *RegionEndFn; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 68 | llvm::AnchorDesc *CompileUnitAnchor; |
| 69 | llvm::AnchorDesc *SubprogramAnchor; |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 70 | llvm::AnchorDesc *GlobalVariableAnchor; |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 71 | std::vector<llvm::DebugInfoDesc *> RegionStack; |
| 72 | std::vector<llvm::VariableDesc *> VariableDescList; |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 73 | std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 74 | std::vector<llvm::EnumeratorDesc *> EnumDescList; |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 75 | std::vector<llvm::SubrangeDesc *> SubrangeDescList; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 76 | llvm::SubprogramDesc *Subprogram; |
Eli Friedman | 3f2af10 | 2008-05-22 01:40:10 +0000 | [diff] [blame] | 77 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 78 | /// Helper functions for getOrCreateType. |
| 79 | llvm::TypeDesc *getOrCreateCVRType(QualType type, |
| 80 | llvm::CompileUnitDesc *unit); |
| 81 | llvm::TypeDesc *getOrCreateBuiltinType(QualType type, |
| 82 | llvm::CompileUnitDesc *unit); |
| 83 | llvm::TypeDesc *getOrCreateTypedefType(QualType type, |
| 84 | llvm::CompileUnitDesc *unit); |
| 85 | llvm::TypeDesc *getOrCreatePointerType(QualType type, |
| 86 | llvm::CompileUnitDesc *unit); |
| 87 | llvm::TypeDesc *getOrCreateFunctionType(QualType type, |
| 88 | llvm::CompileUnitDesc *unit); |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 89 | llvm::TypeDesc *getOrCreateRecordType(QualType type, |
| 90 | llvm::CompileUnitDesc *unit); |
| 91 | llvm::TypeDesc *getOrCreateEnumType(QualType type, |
| 92 | llvm::CompileUnitDesc *unit); |
| 93 | llvm::TypeDesc *getOrCreateTaggedType(QualType type, |
| 94 | llvm::CompileUnitDesc *unit); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 95 | llvm::TypeDesc *getOrCreateArrayType(QualType type, |
| 96 | llvm::CompileUnitDesc *unit); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 97 | |
| 98 | public: |
| 99 | CGDebugInfo(CodeGenModule *m); |
| 100 | ~CGDebugInfo(); |
| 101 | |
Eli Friedman | 32ea35f | 2008-05-29 11:08:17 +0000 | [diff] [blame] | 102 | void setLocation(SourceLocation loc); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 103 | |
| 104 | /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of |
| 105 | /// source line. |
| 106 | void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 107 | |
| 108 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
| 109 | /// start of a new function |
| 110 | void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn, |
| 111 | llvm::IRBuilder &Builder); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 112 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 113 | /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 114 | /// of a new block. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 115 | void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 116 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 117 | /// 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] | 118 | /// block. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 119 | void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 120 | |
| 121 | /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. |
| 122 | void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, |
| 123 | llvm::IRBuilder &Builder); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 124 | |
| 125 | /// EmitGlobalVariable - Emit information about a global variable. |
| 126 | void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 127 | |
| 128 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 129 | /// new one if necessary. |
| 130 | llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc); |
| 131 | |
| 132 | /// getOrCreateType - Get the type from the cache or create a new type if |
| 133 | /// necessary. |
| 134 | llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit); |
| 135 | |
| 136 | /// getCastValueFor - Return a llvm representation for a given debug |
| 137 | /// information descriptor cast to an empty struct pointer. |
| 138 | llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD); |
| 139 | |
| 140 | /// getValueFor - Return a llvm representation for a given debug information |
| 141 | /// descriptor. |
| 142 | llvm::Value *getValueFor(llvm::DebugInfoDesc *DD); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 143 | }; |
| 144 | } // namespace CodeGen |
| 145 | } // namespace clang |
| 146 | |
| 147 | #endif |