1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the source level debug info generator for llvm translation.
//
//===----------------------------------------------------------------------===//
#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
#define CLANG_CODEGEN_CGDEBUGINFO_H
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/Support/IRBuilder.h"
#include <map>
#include <vector>
namespace llvm {
class Function;
class DISerializer;
class CompileUnitDesc;
class BasicBlock;
class AnchorDesc;
class DebugInfoDesc;
class Value;
class TypeDesc;
class VariableDesc;
class SubprogramDesc;
class GlobalVariable;
class GlobalVariableDesc;
class EnumeratorDesc;
class SubrangeDesc;
}
namespace clang {
class FunctionDecl;
class VarDecl;
namespace CodeGen {
class CodeGenModule;
/// CGDebugInfo - This class gathers all debug information during compilation
/// and is responsible for emitting to llvm globals or pass directly to
/// the backend.
class CGDebugInfo {
private:
CodeGenModule *M;
llvm::DISerializer *SR;
SourceLocation CurLoc;
SourceLocation PrevLoc;
typedef llvm::IRBuilder<> BuilderType;
/// CompileUnitCache - Cache of previously constructed CompileUnits.
std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
/// TypeCache - Cache of previously constructed Types.
std::map<void *, llvm::TypeDesc *> TypeCache;
llvm::Function *StopPointFn;
llvm::Function *FuncStartFn;
llvm::Function *DeclareFn;
llvm::Function *RegionStartFn;
llvm::Function *RegionEndFn;
llvm::AnchorDesc *CompileUnitAnchor;
llvm::AnchorDesc *SubprogramAnchor;
llvm::AnchorDesc *GlobalVariableAnchor;
std::vector<llvm::DebugInfoDesc *> RegionStack;
std::vector<llvm::VariableDesc *> VariableDescList;
std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
std::vector<llvm::EnumeratorDesc *> EnumDescList;
std::vector<llvm::SubrangeDesc *> SubrangeDescList;
llvm::SubprogramDesc *Subprogram;
/// Helper functions for getOrCreateType.
llvm::TypeDesc *getOrCreateCVRType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateTypedefType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreatePointerType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateFunctionType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateRecordType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateEnumType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateTaggedType(QualType type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateArrayType(QualType type,
llvm::CompileUnitDesc *unit);
public:
CGDebugInfo(CodeGenModule *m);
~CGDebugInfo();
void setLocation(SourceLocation loc);
/// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
/// source line.
void EmitStopPoint(llvm::Function *Fn, BuilderType &Builder);
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
/// start of a new function
void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
BuilderType &Builder);
/// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
/// of a new block.
void EmitRegionStart(llvm::Function *Fn, BuilderType &Builder);
/// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
/// block.
void EmitRegionEnd(llvm::Function *Fn, BuilderType &Builder);
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
BuilderType &Builder);
/// EmitGlobalVariable - Emit information about a global variable.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
/// getOrCreateCompileUnit - Get the compile unit from the cache or create a
/// new one if necessary.
llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
/// getOrCreateType - Get the type from the cache or create a new type if
/// necessary.
llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
/// getCastValueFor - Return a llvm representation for a given debug
/// information descriptor cast to an empty struct pointer.
llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
/// getValueFor - Return a llvm representation for a given debug information
/// descriptor.
llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
};
} // namespace CodeGen
} // namespace clang
#endif
|