blob: 7e41143837c3e321bca759b4007e5145d017f0e8 [file] [log] [blame]
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +00001//===--- 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 Gupta1c6a38b2008-05-25 05:15:42 +000017#include "clang/AST/Type.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000018#include "clang/Basic/SourceLocation.h"
Daniel Dunbar58bf6102008-08-11 16:50:21 +000019#include "llvm/Support/IRBuilder.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000020#include <map>
21#include <vector>
22
23
24namespace llvm {
25 class Function;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000026 class DISerializer;
27 class CompileUnitDesc;
28 class BasicBlock;
29 class AnchorDesc;
30 class DebugInfoDesc;
31 class Value;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000032 class TypeDesc;
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000033 class VariableDesc;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000034 class SubprogramDesc;
Sanjiv Gupta686226b2008-06-05 08:59:10 +000035 class GlobalVariable;
36 class GlobalVariableDesc;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +000037 class EnumeratorDesc;
Sanjiv Gupta507de852008-06-09 10:47:41 +000038 class SubrangeDesc;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000039}
40
41namespace clang {
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000042 class FunctionDecl;
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000043 class VarDecl;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000044namespace CodeGen {
45 class CodeGenModule;
46
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000047/// 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 Guptae8b9f5b2008-05-08 08:54:20 +000050class CGDebugInfo {
51private:
52 CodeGenModule *M;
53 llvm::DISerializer *SR;
54 SourceLocation CurLoc;
55 SourceLocation PrevLoc;
56
Daniel Dunbar58bf6102008-08-11 16:50:21 +000057 typedef llvm::IRBuilder<> BuilderType;
58
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000059 /// CompileUnitCache - Cache of previously constructed CompileUnits.
60 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000061
62 /// TypeCache - Cache of previously constructed Types.
63 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000064
65 llvm::Function *StopPointFn;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000066 llvm::Function *FuncStartFn;
67 llvm::Function *DeclareFn;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000068 llvm::Function *RegionStartFn;
69 llvm::Function *RegionEndFn;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000070 llvm::AnchorDesc *CompileUnitAnchor;
71 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta686226b2008-06-05 08:59:10 +000072 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000073 std::vector<llvm::DebugInfoDesc *> RegionStack;
74 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta686226b2008-06-05 08:59:10 +000075 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +000076 std::vector<llvm::EnumeratorDesc *> EnumDescList;
Sanjiv Gupta507de852008-06-09 10:47:41 +000077 std::vector<llvm::SubrangeDesc *> SubrangeDescList;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000078 llvm::SubprogramDesc *Subprogram;
Eli Friedman3f2af102008-05-22 01:40:10 +000079
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000080 /// Helper functions for getOrCreateType.
81 llvm::TypeDesc *getOrCreateCVRType(QualType type,
82 llvm::CompileUnitDesc *unit);
83 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
84 llvm::CompileUnitDesc *unit);
85 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
86 llvm::CompileUnitDesc *unit);
87 llvm::TypeDesc *getOrCreatePointerType(QualType type,
88 llvm::CompileUnitDesc *unit);
89 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
90 llvm::CompileUnitDesc *unit);
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +000091 llvm::TypeDesc *getOrCreateRecordType(QualType type,
92 llvm::CompileUnitDesc *unit);
93 llvm::TypeDesc *getOrCreateEnumType(QualType type,
94 llvm::CompileUnitDesc *unit);
95 llvm::TypeDesc *getOrCreateTaggedType(QualType type,
96 llvm::CompileUnitDesc *unit);
Sanjiv Gupta507de852008-06-09 10:47:41 +000097 llvm::TypeDesc *getOrCreateArrayType(QualType type,
98 llvm::CompileUnitDesc *unit);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000099
100public:
101 CGDebugInfo(CodeGenModule *m);
102 ~CGDebugInfo();
103
Eli Friedman32ea35f2008-05-29 11:08:17 +0000104 void setLocation(SourceLocation loc);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000105
106 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
107 /// source line.
Daniel Dunbar58bf6102008-08-11 16:50:21 +0000108 void EmitStopPoint(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000109
110 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
111 /// start of a new function
112 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
Daniel Dunbar58bf6102008-08-11 16:50:21 +0000113 BuilderType &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000114
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000115 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000116 /// of a new block.
Daniel Dunbar58bf6102008-08-11 16:50:21 +0000117 void EmitRegionStart(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000118
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000119 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000120 /// block.
Daniel Dunbar58bf6102008-08-11 16:50:21 +0000121 void EmitRegionEnd(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000122
123 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
124 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
Daniel Dunbar58bf6102008-08-11 16:50:21 +0000125 BuilderType &Builder);
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000126
127 /// EmitGlobalVariable - Emit information about a global variable.
128 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000129
130 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
131 /// new one if necessary.
132 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
133
134 /// getOrCreateType - Get the type from the cache or create a new type if
135 /// necessary.
136 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
137
138 /// getCastValueFor - Return a llvm representation for a given debug
139 /// information descriptor cast to an empty struct pointer.
140 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
141
142 /// getValueFor - Return a llvm representation for a given debug information
143 /// descriptor.
144 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000145};
146} // namespace CodeGen
147} // namespace clang
148
149#endif