blob: 35d167ce816342f797f40166ee1c11fbbb40d008 [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 Gupta40e56a12008-05-08 08:54:20 +000037}
38
39namespace clang {
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000040 class FunctionDecl;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000041 class VarDecl;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000042namespace CodeGen {
43 class CodeGenModule;
44
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000045/// CGDebugInfo - This class gathers all debug information during compilation
46/// and is responsible for emitting to llvm globals or pass directly to
47/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000048class CGDebugInfo {
49private:
50 CodeGenModule *M;
51 llvm::DISerializer *SR;
52 SourceLocation CurLoc;
53 SourceLocation PrevLoc;
54
55 /// CompileUnitCache - Cache of previously constructed CompileUnits.
56 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000057
58 /// TypeCache - Cache of previously constructed Types.
59 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000060
61 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000062 llvm::Function *FuncStartFn;
63 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000064 llvm::Function *RegionStartFn;
65 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000066 llvm::AnchorDesc *CompileUnitAnchor;
67 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000068 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000069 std::vector<llvm::DebugInfoDesc *> RegionStack;
70 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000071 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000072 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000073
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000074 /// Helper functions for getOrCreateType.
75 llvm::TypeDesc *getOrCreateCVRType(QualType type,
76 llvm::CompileUnitDesc *unit);
77 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
78 llvm::CompileUnitDesc *unit);
79 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
80 llvm::CompileUnitDesc *unit);
81 llvm::TypeDesc *getOrCreatePointerType(QualType type,
82 llvm::CompileUnitDesc *unit);
83 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
84 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000085
86public:
87 CGDebugInfo(CodeGenModule *m);
88 ~CGDebugInfo();
89
Eli Friedman6a03c262008-05-29 11:08:17 +000090 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000091
92 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
93 /// source line.
94 void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000095
96 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
97 /// start of a new function
98 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
99 llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000100
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000101 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000102 /// of a new block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000103 void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000104
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000105 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000106 /// block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000107 void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +0000108
109 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
110 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
111 llvm::IRBuilder &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000112
113 /// EmitGlobalVariable - Emit information about a global variable.
114 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000115
116 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
117 /// new one if necessary.
118 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
119
120 /// getOrCreateType - Get the type from the cache or create a new type if
121 /// necessary.
122 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
123
124 /// getCastValueFor - Return a llvm representation for a given debug
125 /// information descriptor cast to an empty struct pointer.
126 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
127
128 /// getValueFor - Return a llvm representation for a given debug information
129 /// descriptor.
130 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000131};
132} // namespace CodeGen
133} // namespace clang
134
135#endif