blob: ac28e5b879ed5820046cd8be36500894b2c72c94 [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;
Devang Patel9ca36b62009-02-26 21:10:26 +000027 class ObjCInterfaceDecl;
Daniel Dunbar45d196b2008-11-01 01:53:16 +000028
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000029namespace CodeGen {
30 class CodeGenModule;
31
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000032/// CGDebugInfo - This class gathers all debug information during compilation
33/// and is responsible for emitting to llvm globals or pass directly to
34/// the backend.
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000035class CGDebugInfo {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000036 CodeGenModule *M;
Devang Patel87de6492009-04-23 18:09:16 +000037 bool isMainCompileUnitCreated;
Chris Lattner9c85ba32008-11-10 06:08:34 +000038 llvm::DIFactory DebugFactory;
39
40 SourceLocation CurLoc, PrevLoc;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000041
42 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Devang Patel446c6192009-04-17 21:06:59 +000043 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000044
45 /// TypeCache - Cache of previously constructed Types.
Chris Lattner9c85ba32008-11-10 06:08:34 +000046 // FIXME: Eliminate this map. Be careful of iterator invalidation.
47 std::map<void *, llvm::DIType> TypeCache;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000048
Mike Stump9bc093c2009-05-14 02:03:51 +000049 bool BlockLiteralGenericSet;
50 llvm::DIType BlockLiteralGeneric;
51
Chris Lattner9c85ba32008-11-10 06:08:34 +000052 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman3f2af102008-05-22 01:40:10 +000053
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000054 /// Helper functions for getOrCreateType.
Chris Lattner9c85ba32008-11-10 06:08:34 +000055 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
Chris Lattnerb7003772009-04-23 06:13:01 +000056 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000057 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
58 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
Daniel Dunbar9df4bb32009-07-14 01:20:56 +000059 llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
60 llvm::DICompileUnit Unit);
Chris Lattner9c85ba32008-11-10 06:08:34 +000061 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
Mike Stump9bc093c2009-05-14 02:03:51 +000062 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000063 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
64 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
65 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
Devang Patel9ca36b62009-02-26 21:10:26 +000066 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000067 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
68 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000069
70public:
71 CGDebugInfo(CodeGenModule *m);
72 ~CGDebugInfo();
73
Daniel Dunbar66031a52008-10-17 16:15:48 +000074 /// setLocation - Update the current source location. If \arg loc is
75 /// invalid it is ignored.
Chris Lattner9c85ba32008-11-10 06:08:34 +000076 void setLocation(SourceLocation Loc);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000077
78 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
79 /// source line.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000080 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000081
82 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar2284ac92008-10-18 18:22:23 +000083 /// start of a new function.
84 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbar45d196b2008-11-01 01:53:16 +000085 llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000086
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000087 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000088 /// of a new block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000089 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000090
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000091 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000092 /// block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000093 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000094
Chris Lattner9c85ba32008-11-10 06:08:34 +000095 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
96 /// variable declaration.
97 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
98 CGBuilderTy &Builder);
Sanjiv Gupta686226b2008-06-05 08:59:10 +000099
Chris Lattner9c85ba32008-11-10 06:08:34 +0000100 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
101 /// variable declaration.
102 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
103 CGBuilderTy &Builder);
104
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000105 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000106 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Devang Patel9ca36b62009-02-26 21:10:26 +0000107
108 /// EmitGlobalVariable - Emit information about an objective-c interface.
109 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
110
Chris Lattner86cd8af2008-11-03 09:11:11 +0000111private:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000112 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
113 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
114 CGBuilderTy &Builder);
115
Devang Patel72240d72009-06-26 18:32:22 +0000116
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000117 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
118 /// new one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000119 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000120
121 /// getOrCreateType - Get the type from the cache or create a new type if
122 /// necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000123 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000124};
125} // namespace CodeGen
126} // namespace clang
127
128#endif