blob: 3e7835a2d07cb64bf422115df592486842f735f4 [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 Gupta40e56a12008-05-08 08:54:20 +000035}
36
37namespace clang {
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000038 class FunctionDecl;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000039 class VarDecl;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000040namespace CodeGen {
41 class CodeGenModule;
42
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000043/// CGDebugInfo - This class gathers all debug information during compilation
44/// and is responsible for emitting to llvm globals or pass directly to
45/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000046class CGDebugInfo {
47private:
48 CodeGenModule *M;
49 llvm::DISerializer *SR;
50 SourceLocation CurLoc;
51 SourceLocation PrevLoc;
52
53 /// CompileUnitCache - Cache of previously constructed CompileUnits.
54 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000055
56 /// TypeCache - Cache of previously constructed Types.
57 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000058
59 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000060 llvm::Function *FuncStartFn;
61 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000062 llvm::Function *RegionStartFn;
63 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000064 llvm::AnchorDesc *CompileUnitAnchor;
65 llvm::AnchorDesc *SubprogramAnchor;
Sanjiv Guptab2a10452008-05-30 10:30:31 +000066 std::vector<llvm::DebugInfoDesc *> RegionStack;
67 std::vector<llvm::VariableDesc *> VariableDescList;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000068 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000069
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000070 /// Helper functions for getOrCreateType.
71 llvm::TypeDesc *getOrCreateCVRType(QualType type,
72 llvm::CompileUnitDesc *unit);
73 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
74 llvm::CompileUnitDesc *unit);
75 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
76 llvm::CompileUnitDesc *unit);
77 llvm::TypeDesc *getOrCreatePointerType(QualType type,
78 llvm::CompileUnitDesc *unit);
79 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
80 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000081
82public:
83 CGDebugInfo(CodeGenModule *m);
84 ~CGDebugInfo();
85
Eli Friedman6a03c262008-05-29 11:08:17 +000086 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000087
88 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
89 /// source line.
90 void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000091
92 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
93 /// start of a new function
94 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
95 llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000096
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000097 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000098 /// of a new block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000099 void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000100
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000101 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000102 /// block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000103 void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +0000104
105 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
106 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
107 llvm::IRBuilder &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000108
109 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
110 /// new one if necessary.
111 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
112
113 /// getOrCreateType - Get the type from the cache or create a new type if
114 /// necessary.
115 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
116
117 /// getCastValueFor - Return a llvm representation for a given debug
118 /// information descriptor cast to an empty struct pointer.
119 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
120
121 /// getValueFor - Return a llvm representation for a given debug information
122 /// descriptor.
123 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000124};
125} // namespace CodeGen
126} // namespace clang
127
128#endif