blob: 88702dd60a02bf24370322fc797251f0f8a86c4b [file] [log] [blame]
Daniel Dunbar3845f862008-10-31 03:54:29 +00001//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
Sanjiv Guptae8b9f5b2008-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 Gupta1c6a38b2008-05-25 05:15:42 +000017#include "clang/AST/Type.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000018#include "clang/Basic/SourceLocation.h"
Chris Lattner9c85ba32008-11-10 06:08:34 +000019#include "llvm/ADT/DenseMap.h"
20#include "llvm/Analysis/DebugInfo.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000021#include <map>
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000022
Daniel Dunbar45d196b2008-11-01 01:53:16 +000023#include "CGBuilder.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000024
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000025namespace clang {
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000026 class VarDecl;
Daniel Dunbar45d196b2008-11-01 01:53:16 +000027
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000028namespace CodeGen {
29 class CodeGenModule;
30
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000031/// CGDebugInfo - This class gathers all debug information during compilation
32/// and is responsible for emitting to llvm globals or pass directly to
33/// the backend.
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000034class CGDebugInfo {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000035 CodeGenModule *M;
Chris Lattner9c85ba32008-11-10 06:08:34 +000036 llvm::DIFactory DebugFactory;
37
38 SourceLocation CurLoc, PrevLoc;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000039
40 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Chris Lattner9c85ba32008-11-10 06:08:34 +000041 llvm::DenseMap<const FileEntry*, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000042
43 /// TypeCache - Cache of previously constructed Types.
Chris Lattner9c85ba32008-11-10 06:08:34 +000044 // FIXME: Eliminate this map. Be careful of iterator invalidation.
45 std::map<void *, llvm::DIType> TypeCache;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000046
Chris Lattner9c85ba32008-11-10 06:08:34 +000047 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman3f2af102008-05-22 01:40:10 +000048
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000049 /// Helper functions for getOrCreateType.
Chris Lattner9c85ba32008-11-10 06:08:34 +000050 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
51 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
52 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
53 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
54 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
55 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
56 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
57 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
58 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000059
60public:
61 CGDebugInfo(CodeGenModule *m);
62 ~CGDebugInfo();
63
Daniel Dunbar66031a52008-10-17 16:15:48 +000064 /// setLocation - Update the current source location. If \arg loc is
65 /// invalid it is ignored.
Chris Lattner9c85ba32008-11-10 06:08:34 +000066 void setLocation(SourceLocation Loc);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000067
68 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
69 /// source line.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000070 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000071
72 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar2284ac92008-10-18 18:22:23 +000073 /// start of a new function.
74 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbar45d196b2008-11-01 01:53:16 +000075 llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000076
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000077 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000078 /// of a new block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000079 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000080
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000081 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000082 /// block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000083 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000084
Chris Lattner9c85ba32008-11-10 06:08:34 +000085 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
86 /// variable declaration.
87 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
88 CGBuilderTy &Builder);
Sanjiv Gupta686226b2008-06-05 08:59:10 +000089
Chris Lattner9c85ba32008-11-10 06:08:34 +000090 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
91 /// variable declaration.
92 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
93 CGBuilderTy &Builder);
94
Sanjiv Gupta686226b2008-06-05 08:59:10 +000095 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner9c85ba32008-11-10 06:08:34 +000096 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000097
Chris Lattner86cd8af2008-11-03 09:11:11 +000098
99private:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000100 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
101 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
102 CGBuilderTy &Builder);
103
Chris Lattner86cd8af2008-11-03 09:11:11 +0000104
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000105 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
106 /// new one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000107 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000108
109 /// getOrCreateType - Get the type from the cache or create a new type if
110 /// necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000111 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000112};
113} // namespace CodeGen
114} // namespace clang
115
116#endif