blob: 61664a696256afc2898ab2c9f2bdc4451e974857 [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"
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 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
57 /// CompileUnitCache - Cache of previously constructed CompileUnits.
58 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000059
60 /// TypeCache - Cache of previously constructed Types.
61 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000062
63 llvm::Function *StopPointFn;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000064 llvm::Function *FuncStartFn;
65 llvm::Function *DeclareFn;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000066 llvm::Function *RegionStartFn;
67 llvm::Function *RegionEndFn;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000068 llvm::AnchorDesc *CompileUnitAnchor;
69 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta686226b2008-06-05 08:59:10 +000070 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000071 std::vector<llvm::DebugInfoDesc *> RegionStack;
72 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta686226b2008-06-05 08:59:10 +000073 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +000074 std::vector<llvm::EnumeratorDesc *> EnumDescList;
Sanjiv Gupta507de852008-06-09 10:47:41 +000075 std::vector<llvm::SubrangeDesc *> SubrangeDescList;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000076 llvm::SubprogramDesc *Subprogram;
Eli Friedman3f2af102008-05-22 01:40:10 +000077
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000078 /// 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 Guptaf58c27a2008-06-07 04:46:53 +000089 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 Gupta507de852008-06-09 10:47:41 +000095 llvm::TypeDesc *getOrCreateArrayType(QualType type,
96 llvm::CompileUnitDesc *unit);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000097
98public:
99 CGDebugInfo(CodeGenModule *m);
100 ~CGDebugInfo();
101
Eli Friedman32ea35f2008-05-29 11:08:17 +0000102 void setLocation(SourceLocation loc);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000103
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 Gupta1c6a38b2008-05-25 05:15:42 +0000107
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 Guptae8b9f5b2008-05-08 08:54:20 +0000112
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000113 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000114 /// of a new block.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000115 void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000116
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000117 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000118 /// block.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000119 void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000120
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 Gupta686226b2008-06-05 08:59:10 +0000124
125 /// EmitGlobalVariable - Emit information about a global variable.
126 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000127
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 Guptae8b9f5b2008-05-08 08:54:20 +0000143};
144} // namespace CodeGen
145} // namespace clang
146
147#endif