blob: d0f0731d6b2f5fd6ec1b4b1fa74c5faa151c10b7 [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//
Mike Stump1eb44332009-09-09 15:08:12 +000010// This is the source level debug info generator for llvm translation.
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000011//
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"
Daniel Dunbar23e81ba2009-09-19 19:27:24 +000021#include "llvm/Support/ValueHandle.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000022#include <map>
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000023
Daniel Dunbar45d196b2008-11-01 01:53:16 +000024#include "CGBuilder.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000025
Daniel Dunbar23e81ba2009-09-19 19:27:24 +000026namespace llvm {
27 class MDNode;
28}
29
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000030namespace clang {
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000031 class VarDecl;
Devang Patel9ca36b62009-02-26 21:10:26 +000032 class ObjCInterfaceDecl;
Daniel Dunbar45d196b2008-11-01 01:53:16 +000033
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000034namespace CodeGen {
35 class CodeGenModule;
36
Mike Stump1eb44332009-09-09 15:08:12 +000037/// CGDebugInfo - This class gathers all debug information during compilation
38/// and is responsible for emitting to llvm globals or pass directly to
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000039/// the backend.
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000040class CGDebugInfo {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000041 CodeGenModule *M;
Devang Patel87de6492009-04-23 18:09:16 +000042 bool isMainCompileUnitCreated;
Chris Lattner9c85ba32008-11-10 06:08:34 +000043 llvm::DIFactory DebugFactory;
Mike Stump1eb44332009-09-09 15:08:12 +000044
Chris Lattner9c85ba32008-11-10 06:08:34 +000045 SourceLocation CurLoc, PrevLoc;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000046
47 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Devang Patel446c6192009-04-17 21:06:59 +000048 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000049
50 /// TypeCache - Cache of previously constructed Types.
Chris Lattner9c85ba32008-11-10 06:08:34 +000051 // FIXME: Eliminate this map. Be careful of iterator invalidation.
Daniel Dunbar23e81ba2009-09-19 19:27:24 +000052 std::map<void *, llvm::AssertingVH<llvm::MDNode> > TypeCache;
Mike Stump1eb44332009-09-09 15:08:12 +000053
Mike Stump9bc093c2009-05-14 02:03:51 +000054 bool BlockLiteralGenericSet;
55 llvm::DIType BlockLiteralGeneric;
56
Chris Lattner9c85ba32008-11-10 06:08:34 +000057 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman3f2af102008-05-22 01:40:10 +000058
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000059 /// Helper functions for getOrCreateType.
Chris Lattner9c85ba32008-11-10 06:08:34 +000060 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
Chris Lattnerb7003772009-04-23 06:13:01 +000061 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000062 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
63 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
Mike Stump1eb44332009-09-09 15:08:12 +000064 llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
Daniel Dunbar9df4bb32009-07-14 01:20:56 +000065 llvm::DICompileUnit Unit);
Chris Lattner9c85ba32008-11-10 06:08:34 +000066 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
Mike Stump9bc093c2009-05-14 02:03:51 +000067 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000068 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
69 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
70 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
Devang Patel9ca36b62009-02-26 21:10:26 +000071 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
Chris Lattner9c85ba32008-11-10 06:08:34 +000072 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
73 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000074
75public:
Devang Patel6dba4322009-07-14 21:31:22 +000076 CGDebugInfo(CodeGenModule *m);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000077 ~CGDebugInfo();
78
Daniel Dunbar66031a52008-10-17 16:15:48 +000079 /// setLocation - Update the current source location. If \arg loc is
80 /// invalid it is ignored.
Chris Lattner9c85ba32008-11-10 06:08:34 +000081 void setLocation(SourceLocation Loc);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000082
83 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
84 /// source line.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000085 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000086
87 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar2284ac92008-10-18 18:22:23 +000088 /// start of a new function.
89 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbar45d196b2008-11-01 01:53:16 +000090 llvm::Function *Fn, CGBuilderTy &Builder);
Mike Stump1eb44332009-09-09 15:08:12 +000091
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000092 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Mike Stump1eb44332009-09-09 15:08:12 +000093 /// of a new block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000094 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Mike Stump1eb44332009-09-09 15:08:12 +000095
96 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000097 /// block.
Daniel Dunbar45d196b2008-11-01 01:53:16 +000098 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptacc9b1632008-05-30 10:30:31 +000099
Chris Lattner9c85ba32008-11-10 06:08:34 +0000100 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
101 /// variable declaration.
102 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
103 CGBuilderTy &Builder);
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000104
Chris Lattner9c85ba32008-11-10 06:08:34 +0000105 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
106 /// variable declaration.
107 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
108 CGBuilderTy &Builder);
Mike Stump1eb44332009-09-09 15:08:12 +0000109
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000110 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000111 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Devang Patel9ca36b62009-02-26 21:10:26 +0000112
113 /// EmitGlobalVariable - Emit information about an objective-c interface.
114 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Chris Lattner86cd8af2008-11-03 09:11:11 +0000116private:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000117 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
118 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
119 CGBuilderTy &Builder);
Mike Stump1eb44332009-09-09 15:08:12 +0000120
121
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000122 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
123 /// new one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000124 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000125
126 /// getOrCreateType - Get the type from the cache or create a new type if
127 /// necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000128 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Daniel Dunbar03faac32009-09-19 19:27:14 +0000129
130 /// CreateTypeNode - Create type metadata for a source language type.
131 llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000132};
133} // namespace CodeGen
134} // namespace clang
135
136#endif