blob: 4e6626fc4d9269afecc40cc3d4be114113c576c1 [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;
33 class SubprogramDesc;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000034}
35
36namespace clang {
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000037 class FunctionDecl;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000038namespace CodeGen {
39 class CodeGenModule;
40
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000041/// CGDebugInfo - This class gathers all debug information during compilation
42/// and is responsible for emitting to llvm globals or pass directly to
43/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000044class CGDebugInfo {
45private:
46 CodeGenModule *M;
47 llvm::DISerializer *SR;
48 SourceLocation CurLoc;
49 SourceLocation PrevLoc;
50
51 /// CompileUnitCache - Cache of previously constructed CompileUnits.
52 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000053
54 /// TypeCache - Cache of previously constructed Types.
55 std::map<void *, llvm::TypeDesc *> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000056
57 llvm::Function *StopPointFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000058 llvm::Function *FuncStartFn;
59 llvm::Function *DeclareFn;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000060 llvm::Function *RegionStartFn;
61 llvm::Function *RegionEndFn;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000062 llvm::AnchorDesc *CompileUnitAnchor;
63 llvm::AnchorDesc *SubprogramAnchor;
64 std::vector<llvm::DebugInfoDesc *> RegionStack;
65 llvm::SubprogramDesc *Subprogram;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000066
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000067 /// Helper functions for getOrCreateType.
68 llvm::TypeDesc *getOrCreateCVRType(QualType type,
69 llvm::CompileUnitDesc *unit);
70 llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
71 llvm::CompileUnitDesc *unit);
72 llvm::TypeDesc *getOrCreateTypedefType(QualType type,
73 llvm::CompileUnitDesc *unit);
74 llvm::TypeDesc *getOrCreatePointerType(QualType type,
75 llvm::CompileUnitDesc *unit);
76 llvm::TypeDesc *getOrCreateFunctionType(QualType type,
77 llvm::CompileUnitDesc *unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000078
79public:
80 CGDebugInfo(CodeGenModule *m);
81 ~CGDebugInfo();
82
Eli Friedman6a03c262008-05-29 11:08:17 +000083 void setLocation(SourceLocation loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000084
85 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
86 /// source line.
87 void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000088
89 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
90 /// start of a new function
91 void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
92 llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000093
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000094 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000095 /// of a new block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000096 void EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000097
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000098 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000099 /// block.
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000100 void EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
101
102 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
103 /// new one if necessary.
104 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
105
106 /// getOrCreateType - Get the type from the cache or create a new type if
107 /// necessary.
108 llvm::TypeDesc *getOrCreateType(QualType type, llvm::CompileUnitDesc *unit);
109
110 /// getCastValueFor - Return a llvm representation for a given debug
111 /// information descriptor cast to an empty struct pointer.
112 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
113
114 /// getValueFor - Return a llvm representation for a given debug information
115 /// descriptor.
116 llvm::Value *getValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000117};
118} // namespace CodeGen
119} // namespace clang
120
121#endif