Sanjiv Gupta | 40e56a1 | 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 | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 17 | #include "clang/AST/Type.h" |
Sanjiv Gupta | 40e56a1 | 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 | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 32 | class TypeDesc; |
| 33 | class SubprogramDesc; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | namespace clang { |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 37 | class FunctionDecl; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 38 | namespace CodeGen { |
| 39 | class CodeGenModule; |
| 40 | |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +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 |
| 43 | /// the backend. |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 44 | class CGDebugInfo { |
| 45 | private: |
| 46 | CodeGenModule *M; |
| 47 | llvm::DISerializer *SR; |
| 48 | SourceLocation CurLoc; |
| 49 | SourceLocation PrevLoc; |
| 50 | |
| 51 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
| 52 | std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache; |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 53 | |
| 54 | /// TypeCache - Cache of previously constructed Types. |
| 55 | std::map<void *, llvm::TypeDesc *> TypeCache; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 56 | |
| 57 | llvm::Function *StopPointFn; |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 58 | llvm::Function *FuncStartFn; |
| 59 | llvm::Function *DeclareFn; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 60 | llvm::Function *RegionStartFn; |
| 61 | llvm::Function *RegionEndFn; |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 62 | llvm::AnchorDesc *CompileUnitAnchor; |
| 63 | llvm::AnchorDesc *SubprogramAnchor; |
| 64 | std::vector<llvm::DebugInfoDesc *> RegionStack; |
| 65 | llvm::SubprogramDesc *Subprogram; |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame] | 66 | |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 67 | /// Helper functions for getOrCreateType. |
| 68 | llvm::TypeDesc *getOrCreateCVRType(QualType type, |
| 69 | llvm::CompileUnitDesc *unit); |
| 70 | llvm::TypeDesc *getOrCreateBuiltinType(QualType type, |
| 71 | llvm::CompileUnitDesc *unit); |
| 72 | llvm::TypeDesc *getOrCreateTypedefType(QualType type, |
| 73 | llvm::CompileUnitDesc *unit); |
| 74 | llvm::TypeDesc *getOrCreatePointerType(QualType type, |
| 75 | llvm::CompileUnitDesc *unit); |
| 76 | llvm::TypeDesc *getOrCreateFunctionType(QualType type, |
| 77 | llvm::CompileUnitDesc *unit); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 78 | |
| 79 | public: |
| 80 | CGDebugInfo(CodeGenModule *m); |
| 81 | ~CGDebugInfo(); |
| 82 | |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 83 | void setLocation(SourceLocation loc) { CurLoc = loc; } |
Sanjiv Gupta | 40e56a1 | 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. |
| 87 | void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 88 | |
| 89 | /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate |
| 90 | /// start of a new function |
| 91 | void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn, |
| 92 | llvm::IRBuilder &Builder); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 93 | |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 94 | /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 95 | /// of a new block. |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 96 | void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 97 | |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 98 | /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 99 | /// block. |
Sanjiv Gupta | 93eb825 | 2008-05-25 05:15:42 +0000 | [diff] [blame^] | 100 | void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder); |
| 101 | |
| 102 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 103 | /// new one if necessary. |
| 104 | llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc); |
| 105 | |
| 106 | /// getOrCreateType - Get the type from the cache or create a new type if |
| 107 | /// necessary. |
| 108 | llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit); |
| 109 | |
| 110 | /// getCastValueFor - Return a llvm representation for a given debug |
| 111 | /// information descriptor cast to an empty struct pointer. |
| 112 | llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD); |
| 113 | |
| 114 | /// getValueFor - Return a llvm representation for a given debug information |
| 115 | /// descriptor. |
| 116 | llvm::Value *getValueFor(llvm::DebugInfoDesc *DD); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 117 | }; |
| 118 | } // namespace CodeGen |
| 119 | } // namespace clang |
| 120 | |
| 121 | #endif |