blob: 129ba9419c992efaf9271db2d2e3d8497752c1b7 [file] [log] [blame]
Sanjiv Gupta40e56a12008-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 Gupta93eb8252008-05-25 05:15:42 +000017#include "clang/AST/Type.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000018#include "clang/Basic/SourceLocation.h"
19#include <map>
20#include <vector>
21
22
23namespace 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 Gupta93eb8252008-05-25 05:15:42 +000032 class TypeDesc;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000033 class VariableDesc;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000034 class SubprogramDesc;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000035 class GlobalVariable;
36 class GlobalVariableDesc;
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000037 class EnumeratorDesc;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000038}
39
40namespace clang {
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000041 class FunctionDecl;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000042 class VarDecl;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000043namespace CodeGen {
44 class CodeGenModule;
45
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000046/// CGDebugInfo - This class gathers all debug information during compilation
47/// and is responsible for emitting to llvm globals or pass directly to
48/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000049class CGDebugInfo {
50private:
51 CodeGenModule *M;
52 llvm::DISerializer *SR;
53 SourceLocation CurLoc;
54 SourceLocation PrevLoc;
55
56 /// CompileUnitCache - Cache of previously constructed CompileUnits.
57 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000058
59 /// TypeCache - Cache of previously constructed Types.
60 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000061
62 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000063 llvm::Function *FuncStartFn;
64 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000065 llvm::Function *RegionStartFn;
66 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000067 llvm::AnchorDesc *CompileUnitAnchor;
68 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000069 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000070 std::vector<llvm::DebugInfoDesc *> RegionStack;
71 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000072 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000073 std::vector<llvm::EnumeratorDesc *> EnumDescList;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000074 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000075
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000076 /// Helper functions for getOrCreateType.
77 llvm::TypeDesc *getOrCreateCVRType(QualType type,
78 llvm::CompileUnitDesc *unit);
79 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
80 llvm::CompileUnitDesc *unit);
81 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
82 llvm::CompileUnitDesc *unit);
83 llvm::TypeDesc *getOrCreatePointerType(QualType type,
84 llvm::CompileUnitDesc *unit);
85 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
86 llvm::CompileUnitDesc *unit);
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000087 llvm::TypeDesc *getOrCreateRecordType(QualType type,
88 llvm::CompileUnitDesc *unit);
89 llvm::TypeDesc *getOrCreateEnumType(QualType type,
90 llvm::CompileUnitDesc *unit);
91 llvm::TypeDesc *getOrCreateTaggedType(QualType type,
92 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000093
94public:
95 CGDebugInfo(CodeGenModule *m);
96 ~CGDebugInfo();
97
Eli Friedman6a03c262008-05-29 11:08:17 +000098 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000099
100 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
101 /// source line.
102 void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000103
104 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
105 /// start of a new function
106 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
107 llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000108
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000109 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000110 /// of a new block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000111 void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000112
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000113 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000114 /// block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000115 void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +0000116
117 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
118 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
119 llvm::IRBuilder &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000120
121 /// EmitGlobalVariable - Emit information about a global variable.
122 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000123
124 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
125 /// new one if necessary.
126 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
127
128 /// getOrCreateType - Get the type from the cache or create a new type if
129 /// necessary.
130 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
131
132 /// getCastValueFor - Return a llvm representation for a given debug
133 /// information descriptor cast to an empty struct pointer.
134 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
135
136 /// getValueFor - Return a llvm representation for a given debug information
137 /// descriptor.
138 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000139};
140} // namespace CodeGen
141} // namespace clang
142
143#endif