blob: 22a45ce8b5042a758b9ee21c6b51ecfa1bc87fbf [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"
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +000019#include "llvm/Support/IRBuilder.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000020#include <map>
21#include <vector>
22
23
24namespace llvm {
25 class Function;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000026 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 Guptab1e662e2008-06-09 10:47:41 +000038 class SubrangeDesc;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000039}
40
41namespace clang {
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000042 class FunctionDecl;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000043 class VarDecl;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000044namespace CodeGen {
45 class CodeGenModule;
46
Sanjiv Gupta93eb8252008-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 Gupta40e56a12008-05-08 08:54:20 +000050class CGDebugInfo {
51private:
52 CodeGenModule *M;
53 llvm::DISerializer *SR;
54 SourceLocation CurLoc;
55 SourceLocation PrevLoc;
56
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +000057 typedef llvm::IRBuilder<> BuilderType;
58
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000059 /// CompileUnitCache - Cache of previously constructed CompileUnits.
60 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000061
62 /// TypeCache - Cache of previously constructed Types.
63 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000064
65 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000066 llvm::Function *FuncStartFn;
67 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000068 llvm::Function *RegionStartFn;
69 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000070 llvm::AnchorDesc *CompileUnitAnchor;
71 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000072 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000073 std::vector<llvm::DebugInfoDesc *> RegionStack;
74 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000075 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000076 std::vector<llvm::EnumeratorDesc *> EnumDescList;
Sanjiv Guptab1e662e2008-06-09 10:47:41 +000077 std::vector<llvm::SubrangeDesc *> SubrangeDescList;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000078 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000079
Sanjiv Gupta93eb8252008-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 Gupta0f805bd2008-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 Guptab1e662e2008-06-09 10:47:41 +000097 llvm::TypeDesc *getOrCreateArrayType(QualType type,
98 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000099
100public:
101 CGDebugInfo(CodeGenModule *m);
102 ~CGDebugInfo();
103
Daniel Dunbar6fc1f972008-10-17 16:15:48 +0000104 /// setLocation - Update the current source location. If \arg loc is
105 /// invalid it is ignored.
Eli Friedman6a03c262008-05-29 11:08:17 +0000106 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000107
108 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
109 /// source line.
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +0000110 void EmitStopPoint(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000111
112 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
113 /// start of a new function
114 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +0000115 BuilderType &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000116
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000117 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000118 /// of a new block.
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +0000119 void EmitRegionStart(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000120
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000121 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000122 /// block.
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +0000123 void EmitRegionEnd(llvm::Function *Fn, BuilderType &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +0000124
125 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
126 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +0000127 BuilderType &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000128
129 /// EmitGlobalVariable - Emit information about a global variable.
130 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000131
132 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
133 /// new one if necessary.
134 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
135
136 /// getOrCreateType - Get the type from the cache or create a new type if
137 /// necessary.
138 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
139
140 /// getCastValueFor - Return a llvm representation for a given debug
141 /// information descriptor cast to an empty struct pointer.
142 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
143
144 /// getValueFor - Return a llvm representation for a given debug information
145 /// descriptor.
146 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000147};
148} // namespace CodeGen
149} // namespace clang
150
151#endif