blob: 9f2581240637498497ad07023807a65ef6cf8a77 [file] [log] [blame]
Daniel Dunbar44252b42008-10-31 03:54:29 +00001//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
Sanjiv Gupta40e56a12008-05-08 08:54:20 +00002//
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
Daniel Dunbard916e6e2008-11-01 01:53:16 +000022#include "CGBuilder.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000023
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;
Daniel Dunbard916e6e2008-11-01 01:53:16 +000044
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000045namespace CodeGen {
46 class CodeGenModule;
47
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000048/// CGDebugInfo - This class gathers all debug information during compilation
49/// and is responsible for emitting to llvm globals or pass directly to
50/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000051class CGDebugInfo {
52private:
53 CodeGenModule *M;
54 llvm::DISerializer *SR;
55 SourceLocation CurLoc;
56 SourceLocation PrevLoc;
57
58 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Daniel Dunbar9865e6f2008-10-24 00:46:51 +000059 std::map<const FileEntry*, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000060
61 /// TypeCache - Cache of previously constructed Types.
62 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000063
64 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000065 llvm::Function *FuncStartFn;
66 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000067 llvm::Function *RegionStartFn;
68 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000069 llvm::AnchorDesc *CompileUnitAnchor;
70 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000071 llvm::AnchorDesc *GlobalVariableAnchor;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000072 std::vector<llvm::DebugInfoDesc *> RegionStack;
73 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta54d97542008-06-05 08:59:10 +000074 std::vector<llvm::GlobalVariableDesc *> GlobalVarDescList;
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000075 std::vector<llvm::EnumeratorDesc *> EnumDescList;
Sanjiv Guptab1e662e2008-06-09 10:47:41 +000076 std::vector<llvm::SubrangeDesc *> SubrangeDescList;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000077 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000078
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000079 /// Helper functions for getOrCreateType.
80 llvm::TypeDesc *getOrCreateCVRType(QualType type,
81 llvm::CompileUnitDesc *unit);
82 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000083 llvm::CompileUnitDesc *unit);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000084 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000085 llvm::CompileUnitDesc *unit);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000086 llvm::TypeDesc *getOrCreatePointerType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000087 llvm::CompileUnitDesc *unit);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000088 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000089 llvm::CompileUnitDesc *unit);
Daniel Dunbar8b4aa902008-10-31 04:04:54 +000090 void getOrCreateRecordType(QualType type,
91 llvm::CompileUnitDesc *unit,
92 llvm::TypeDesc *&Slot);
Sanjiv Gupta0f805bd2008-06-07 04:46:53 +000093 llvm::TypeDesc *getOrCreateEnumType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000094 llvm::CompileUnitDesc *unit);
Daniel Dunbar8b4aa902008-10-31 04:04:54 +000095 void getOrCreateTaggedType(QualType type,
96 llvm::CompileUnitDesc *unit,
97 llvm::TypeDesc *&Slot);
Sanjiv Guptab1e662e2008-06-09 10:47:41 +000098 llvm::TypeDesc *getOrCreateArrayType(QualType type,
Daniel Dunbar44252b42008-10-31 03:54:29 +000099 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000100
101public:
102 CGDebugInfo(CodeGenModule *m);
103 ~CGDebugInfo();
104
Daniel Dunbar6fc1f972008-10-17 16:15:48 +0000105 /// setLocation - Update the current source location. If \arg loc is
106 /// invalid it is ignored.
Eli Friedman6a03c262008-05-29 11:08:17 +0000107 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000108
109 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
110 /// source line.
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000111 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000112
113 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar54968bf2008-10-18 18:22:23 +0000114 /// start of a new function.
115 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000116 llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000117
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000118 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000119 /// of a new block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000120 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000121
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000122 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000123 /// block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000124 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +0000125
126 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
127 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000128 CGBuilderTy &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000129
130 /// EmitGlobalVariable - Emit information about a global variable.
131 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *decl);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000132
133 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
134 /// new one if necessary.
135 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
136
137 /// getOrCreateType - Get the type from the cache or create a new type if
138 /// necessary.
139 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
140
141 /// getCastValueFor - Return a llvm representation for a given debug
142 /// information descriptor cast to an empty struct pointer.
143 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
144
145 /// getValueFor - Return a llvm representation for a given debug information
146 /// descriptor.
147 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000148};
149} // namespace CodeGen
150} // namespace clang
151
152#endif