blob: 5cb5f09da821936a70ccb15e7500d54c164c0077 [file] [log] [blame]
Daniel Dunbar44252b42008-10-31 03:54:29 +00001//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
Sanjiv Gupta40e56a12008-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 Gupta93eb8252008-05-25 05:15:42 +000017#include "clang/AST/Type.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000018#include "clang/Basic/SourceLocation.h"
Devang Patelfa1e96c2009-07-14 02:47:58 +000019#include "llvm/Support/Mangler.h"
Chris Lattner562ce0a2008-11-10 06:08:34 +000020#include "llvm/ADT/DenseMap.h"
21#include "llvm/Analysis/DebugInfo.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000022#include <map>
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000023
Daniel Dunbard916e6e2008-11-01 01:53:16 +000024#include "CGBuilder.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000025
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000026namespace clang {
Sanjiv Guptab2a10452008-05-30 10:30:31 +000027 class VarDecl;
Devang Patel3fc13e32009-02-26 21:10:26 +000028 class ObjCInterfaceDecl;
Devang Patelfa1e96c2009-07-14 02:47:58 +000029 class TargetInfo;
Daniel Dunbard916e6e2008-11-01 01:53:16 +000030
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000031namespace CodeGen {
32 class CodeGenModule;
33
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000034/// CGDebugInfo - This class gathers all debug information during compilation
35/// and is responsible for emitting to llvm globals or pass directly to
36/// the backend.
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000037class CGDebugInfo {
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000038 CodeGenModule *M;
Devang Patelfa1e96c2009-07-14 02:47:58 +000039 llvm::Mangler *LLVMMangler;
Devang Patel2d6bb2b2009-04-23 18:09:16 +000040 bool isMainCompileUnitCreated;
Chris Lattner562ce0a2008-11-10 06:08:34 +000041 llvm::DIFactory DebugFactory;
42
43 SourceLocation CurLoc, PrevLoc;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000044
45 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Devang Patel6fe2e152009-04-17 21:06:59 +000046 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000047
48 /// TypeCache - Cache of previously constructed Types.
Chris Lattner562ce0a2008-11-10 06:08:34 +000049 // FIXME: Eliminate this map. Be careful of iterator invalidation.
50 std::map<void *, llvm::DIType> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000051
Mike Stump5e996f22009-05-14 02:03:51 +000052 bool BlockLiteralGenericSet;
53 llvm::DIType BlockLiteralGeneric;
54
Chris Lattner562ce0a2008-11-10 06:08:34 +000055 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000056
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000057 /// Helper functions for getOrCreateType.
Chris Lattner562ce0a2008-11-10 06:08:34 +000058 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
Chris Lattner016d55e2009-04-23 06:13:01 +000059 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
Chris Lattner562ce0a2008-11-10 06:08:34 +000060 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
61 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
Daniel Dunbaraba1cf02009-07-14 01:20:56 +000062 llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
63 llvm::DICompileUnit Unit);
Chris Lattner562ce0a2008-11-10 06:08:34 +000064 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
Mike Stump5e996f22009-05-14 02:03:51 +000065 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
Chris Lattner562ce0a2008-11-10 06:08:34 +000066 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
67 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
68 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
Devang Patel3fc13e32009-02-26 21:10:26 +000069 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
Chris Lattner562ce0a2008-11-10 06:08:34 +000070 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
71 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000072
73public:
Devang Patelfa1e96c2009-07-14 02:47:58 +000074 CGDebugInfo(CodeGenModule *m, TargetInfo *t);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000075 ~CGDebugInfo();
76
Daniel Dunbar6fc1f972008-10-17 16:15:48 +000077 /// setLocation - Update the current source location. If \arg loc is
78 /// invalid it is ignored.
Chris Lattner562ce0a2008-11-10 06:08:34 +000079 void setLocation(SourceLocation Loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000080
81 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
82 /// source line.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000083 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000084
85 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar54968bf2008-10-18 18:22:23 +000086 /// start of a new function.
87 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbard916e6e2008-11-01 01:53:16 +000088 llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000089
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000090 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000091 /// of a new block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000092 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000093
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000094 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000095 /// block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000096 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +000097
Chris Lattner562ce0a2008-11-10 06:08:34 +000098 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
99 /// variable declaration.
100 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
101 CGBuilderTy &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000102
Chris Lattner562ce0a2008-11-10 06:08:34 +0000103 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
104 /// variable declaration.
105 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
106 CGBuilderTy &Builder);
107
Sanjiv Gupta54d97542008-06-05 08:59:10 +0000108 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner562ce0a2008-11-10 06:08:34 +0000109 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Devang Patel3fc13e32009-02-26 21:10:26 +0000110
111 /// EmitGlobalVariable - Emit information about an objective-c interface.
112 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
113
Chris Lattner26cd09a2008-11-03 09:11:11 +0000114private:
Chris Lattner562ce0a2008-11-10 06:08:34 +0000115 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
116 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
117 CGBuilderTy &Builder);
118
Devang Patel3f376172009-06-26 18:32:22 +0000119
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000120 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
121 /// new one if necessary.
Chris Lattner562ce0a2008-11-10 06:08:34 +0000122 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000123
124 /// getOrCreateType - Get the type from the cache or create a new type if
125 /// necessary.
Chris Lattner562ce0a2008-11-10 06:08:34 +0000126 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000127};
128} // namespace CodeGen
129} // namespace clang
130
131#endif