blob: ca933021a6dc972c378883ec95b27da6fc84c4cf [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
17#include "clang/Basic/SourceLocation.h"
18#include <map>
19#include <vector>
20
21
22namespace llvm {
23 class Function;
24 class IRBuilder;
25 class DISerializer;
26 class CompileUnitDesc;
27 class BasicBlock;
28 class AnchorDesc;
29 class DebugInfoDesc;
30 class Value;
31}
32
33namespace clang {
34namespace CodeGen {
35 class CodeGenModule;
36
37/// DebugInfo - This class gathers all debug information during compilation and
38/// is responsible for emitting to llvm globals or pass directly to the backend.
39class CGDebugInfo {
40private:
41 CodeGenModule *M;
42 llvm::DISerializer *SR;
43 SourceLocation CurLoc;
44 SourceLocation PrevLoc;
45
46 /// CompileUnitCache - Cache of previously constructed CompileUnits.
47 std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000048 std::vector<llvm::DebugInfoDesc*> DebugAllocationList;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000049
50 llvm::Function *StopPointFn;
51 llvm::AnchorDesc *CompileUnitAnchor;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000052 llvm::AnchorDesc *SubProgramAnchor;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000053 llvm::Function *RegionStartFn;
54 llvm::Function *RegionEndFn;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000055 llvm::Function *FuncStartFn;
56 llvm::Value *CurFuncDesc;
57
58 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
59 /// new one if necessary.
60 llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc);
61
62 /// getCastValueFor - Return a llvm representation for a given debug
63 /// information descriptor cast to an empty struct pointer.
64 llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000065
66public:
67 CGDebugInfo(CodeGenModule *m);
68 ~CGDebugInfo();
69
70 void setLocation(SourceLocation loc) { CurLoc = loc; };
71
72 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
73 /// source line.
74 void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder);
75
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000076 /// EmitFunctionStart - Emit a call to llvm.dbg.func.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000077 /// of a new block.
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000078 void EmitFunctionStart(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000079
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000080 /// EmitFunctionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000081 /// block.
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000082 void EmitFunctionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000083};
84} // namespace CodeGen
85} // namespace clang
86
87#endif