blob: 17237ddfc650ccd6fa9fe8c3245da7bcb6da7884 [file] [log] [blame]
Daniel Dunbara290ded2008-10-31 03:54:29 +00001//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
Sanjiv Gupta15cb6692008-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//
Mike Stump11289f42009-09-09 15:08:12 +000010// This is the source level debug info generator for llvm translation.
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
15#define CLANG_CODEGEN_CGDEBUGINFO_H
16
Sanjiv Gupta98070572008-05-25 05:15:42 +000017#include "clang/AST/Type.h"
Mike Stump2e722b92009-09-30 02:43:10 +000018#include "clang/AST/Expr.h"
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000019#include "clang/Basic/SourceLocation.h"
Chris Lattneraffb3732008-11-10 06:08:34 +000020#include "llvm/ADT/DenseMap.h"
21#include "llvm/Analysis/DebugInfo.h"
Daniel Dunbar1cbaae52009-09-19 19:27:24 +000022#include "llvm/Support/ValueHandle.h"
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000023#include <map>
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000024
Daniel Dunbarcb463852008-11-01 01:53:16 +000025#include "CGBuilder.h"
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000026
Daniel Dunbar1cbaae52009-09-19 19:27:24 +000027namespace llvm {
28 class MDNode;
29}
30
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000031namespace clang {
Sanjiv Gupta18de6242008-05-30 10:30:31 +000032 class VarDecl;
Devang Patelf4c205b2009-02-26 21:10:26 +000033 class ObjCInterfaceDecl;
Daniel Dunbarcb463852008-11-01 01:53:16 +000034
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000035namespace CodeGen {
36 class CodeGenModule;
Mike Stump2e722b92009-09-30 02:43:10 +000037 class CodeGenFunction;
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000038
Mike Stump11289f42009-09-09 15:08:12 +000039/// CGDebugInfo - This class gathers all debug information during compilation
40/// and is responsible for emitting to llvm globals or pass directly to
Sanjiv Gupta98070572008-05-25 05:15:42 +000041/// the backend.
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000042class CGDebugInfo {
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000043 CodeGenModule *M;
Devang Patela6acb392009-04-23 18:09:16 +000044 bool isMainCompileUnitCreated;
Chris Lattneraffb3732008-11-10 06:08:34 +000045 llvm::DIFactory DebugFactory;
Mike Stump11289f42009-09-09 15:08:12 +000046
Chris Lattneraffb3732008-11-10 06:08:34 +000047 SourceLocation CurLoc, PrevLoc;
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000048
49 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Devang Patel75009452009-04-17 21:06:59 +000050 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta98070572008-05-25 05:15:42 +000051
52 /// TypeCache - Cache of previously constructed Types.
Chris Lattneraffb3732008-11-10 06:08:34 +000053 // FIXME: Eliminate this map. Be careful of iterator invalidation.
Daniel Dunbar99961382009-09-19 20:17:48 +000054 std::map<void *, llvm::WeakVH> TypeCache;
Mike Stump11289f42009-09-09 15:08:12 +000055
Mike Stump31f099c2009-05-14 02:03:51 +000056 bool BlockLiteralGenericSet;
57 llvm::DIType BlockLiteralGeneric;
58
Chris Lattneraffb3732008-11-10 06:08:34 +000059 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman17630752008-05-22 01:40:10 +000060
Sanjiv Gupta98070572008-05-25 05:15:42 +000061 /// Helper functions for getOrCreateType.
Chris Lattneraffb3732008-11-10 06:08:34 +000062 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
Chris Lattner7b0344f2009-04-23 06:13:01 +000063 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
John McCall0cf15512009-09-25 01:40:47 +000064 llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U);
Chris Lattneraffb3732008-11-10 06:08:34 +000065 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
Mike Stump11289f42009-09-09 15:08:12 +000066 llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
Daniel Dunbarf5c79702009-07-14 01:20:56 +000067 llvm::DICompileUnit Unit);
Chris Lattneraffb3732008-11-10 06:08:34 +000068 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
Mike Stump31f099c2009-05-14 02:03:51 +000069 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
Chris Lattneraffb3732008-11-10 06:08:34 +000070 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
71 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
72 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
Devang Patelf4c205b2009-02-26 21:10:26 +000073 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
Chris Lattneraffb3732008-11-10 06:08:34 +000074 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
75 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000076
77public:
Devang Patel9be7b202009-07-14 21:31:22 +000078 CGDebugInfo(CodeGenModule *m);
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000079 ~CGDebugInfo();
80
Daniel Dunbarb9fd9022008-10-17 16:15:48 +000081 /// setLocation - Update the current source location. If \arg loc is
82 /// invalid it is ignored.
Chris Lattneraffb3732008-11-10 06:08:34 +000083 void setLocation(SourceLocation Loc);
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000084
85 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
86 /// source line.
Daniel Dunbarcb463852008-11-01 01:53:16 +000087 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta98070572008-05-25 05:15:42 +000088
89 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar354d2782008-10-18 18:22:23 +000090 /// start of a new function.
91 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbarcb463852008-11-01 01:53:16 +000092 llvm::Function *Fn, CGBuilderTy &Builder);
Mike Stump11289f42009-09-09 15:08:12 +000093
Sanjiv Gupta98070572008-05-25 05:15:42 +000094 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Mike Stump11289f42009-09-09 15:08:12 +000095 /// of a new block.
Daniel Dunbarcb463852008-11-01 01:53:16 +000096 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Mike Stump11289f42009-09-09 15:08:12 +000097
98 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta15cb6692008-05-08 08:54:20 +000099 /// block.
Daniel Dunbarcb463852008-11-01 01:53:16 +0000100 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta18de6242008-05-30 10:30:31 +0000101
Chris Lattneraffb3732008-11-10 06:08:34 +0000102 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
103 /// variable declaration.
104 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
105 CGBuilderTy &Builder);
Sanjiv Gupta158143a2008-06-05 08:59:10 +0000106
Mike Stump2e722b92009-09-30 02:43:10 +0000107 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
108 /// imported variable declaration in a block.
109 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE,
110 llvm::Value *AI,
111 CGBuilderTy &Builder,
112 CodeGenFunction *CGF);
113
Chris Lattneraffb3732008-11-10 06:08:34 +0000114 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
115 /// variable declaration.
116 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
117 CGBuilderTy &Builder);
Mike Stump11289f42009-09-09 15:08:12 +0000118
Sanjiv Gupta158143a2008-06-05 08:59:10 +0000119 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattneraffb3732008-11-10 06:08:34 +0000120 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Devang Patelf4c205b2009-02-26 21:10:26 +0000121
122 /// EmitGlobalVariable - Emit information about an objective-c interface.
123 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
Mike Stump11289f42009-09-09 15:08:12 +0000124
Chris Lattner7d7fff22008-11-03 09:11:11 +0000125private:
Chris Lattneraffb3732008-11-10 06:08:34 +0000126 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
127 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
128 CGBuilderTy &Builder);
Mike Stump11289f42009-09-09 15:08:12 +0000129
Mike Stump2e722b92009-09-30 02:43:10 +0000130 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
131 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI,
132 CGBuilderTy &Builder, CodeGenFunction *CGF);
Mike Stump11289f42009-09-09 15:08:12 +0000133
Sanjiv Gupta98070572008-05-25 05:15:42 +0000134 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
135 /// new one if necessary.
Chris Lattneraffb3732008-11-10 06:08:34 +0000136 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta98070572008-05-25 05:15:42 +0000137
138 /// getOrCreateType - Get the type from the cache or create a new type if
139 /// necessary.
Chris Lattneraffb3732008-11-10 06:08:34 +0000140 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Daniel Dunbarde870bd2009-09-19 19:27:14 +0000141
142 /// CreateTypeNode - Create type metadata for a source language type.
143 llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Gupta15cb6692008-05-08 08:54:20 +0000144};
145} // namespace CodeGen
146} // namespace clang
147
148#endif