blob: 4a59ecaaa57d50e4fb300c772dcf5d7086a0163f [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"
Chris Lattner562ce0a2008-11-10 06:08:34 +000019#include "llvm/ADT/DenseMap.h"
20#include "llvm/Analysis/DebugInfo.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000021#include <map>
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000022
Daniel Dunbard916e6e2008-11-01 01:53:16 +000023#include "CGBuilder.h"
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000024
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000025namespace clang {
Sanjiv Guptab2a10452008-05-30 10:30:31 +000026 class VarDecl;
Devang Patel3fc13e32009-02-26 21:10:26 +000027 class ObjCInterfaceDecl;
Daniel Dunbard916e6e2008-11-01 01:53:16 +000028
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000029namespace CodeGen {
30 class CodeGenModule;
31
Sanjiv Gupta93eb8252008-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 Gupta40e56a12008-05-08 08:54:20 +000035class CGDebugInfo {
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000036 CodeGenModule *M;
Chris Lattner562ce0a2008-11-10 06:08:34 +000037 llvm::DIFactory DebugFactory;
38
39 SourceLocation CurLoc, PrevLoc;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000040
41 /// CompileUnitCache - Cache of previously constructed CompileUnits.
Devang Patel6fe2e152009-04-17 21:06:59 +000042 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000043
44 /// TypeCache - Cache of previously constructed Types.
Chris Lattner562ce0a2008-11-10 06:08:34 +000045 // FIXME: Eliminate this map. Be careful of iterator invalidation.
46 std::map<void *, llvm::DIType> TypeCache;
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000047
Chris Lattner562ce0a2008-11-10 06:08:34 +000048 std::vector<llvm::DIDescriptor> RegionStack;
Eli Friedman9bc7c8d2008-05-22 01:40:10 +000049
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000050 /// Helper functions for getOrCreateType.
Chris Lattner562ce0a2008-11-10 06:08:34 +000051 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
Chris Lattner016d55e2009-04-23 06:13:01 +000052 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
Chris Lattner562ce0a2008-11-10 06:08:34 +000053 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
54 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
55 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
56 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
57 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
58 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
Devang Patel3fc13e32009-02-26 21:10:26 +000059 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
Chris Lattner562ce0a2008-11-10 06:08:34 +000060 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
61 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000062
63public:
64 CGDebugInfo(CodeGenModule *m);
65 ~CGDebugInfo();
66
Daniel Dunbar6fc1f972008-10-17 16:15:48 +000067 /// setLocation - Update the current source location. If \arg loc is
68 /// invalid it is ignored.
Chris Lattner562ce0a2008-11-10 06:08:34 +000069 void setLocation(SourceLocation Loc);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000070
71 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
72 /// source line.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000073 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000074
75 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
Daniel Dunbar54968bf2008-10-18 18:22:23 +000076 /// start of a new function.
77 void EmitFunctionStart(const char *Name, QualType ReturnType,
Daniel Dunbard916e6e2008-11-01 01:53:16 +000078 llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000079
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000080 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000081 /// of a new block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000082 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000083
Sanjiv Gupta93eb8252008-05-25 05:15:42 +000084 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
Sanjiv Gupta40e56a12008-05-08 08:54:20 +000085 /// block.
Daniel Dunbard916e6e2008-11-01 01:53:16 +000086 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
Sanjiv Guptab2a10452008-05-30 10:30:31 +000087
Chris Lattner562ce0a2008-11-10 06:08:34 +000088 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
89 /// variable declaration.
90 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
91 CGBuilderTy &Builder);
Sanjiv Gupta54d97542008-06-05 08:59:10 +000092
Chris Lattner562ce0a2008-11-10 06:08:34 +000093 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
94 /// variable declaration.
95 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
96 CGBuilderTy &Builder);
97
Sanjiv Gupta54d97542008-06-05 08:59:10 +000098 /// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner562ce0a2008-11-10 06:08:34 +000099 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
Devang Patel3fc13e32009-02-26 21:10:26 +0000100
101 /// EmitGlobalVariable - Emit information about an objective-c interface.
102 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
103
Chris Lattner26cd09a2008-11-03 09:11:11 +0000104private:
Chris Lattner562ce0a2008-11-10 06:08:34 +0000105 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
106 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
107 CGBuilderTy &Builder);
108
Chris Lattner26cd09a2008-11-03 09:11:11 +0000109
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000110 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
111 /// new one if necessary.
Chris Lattner562ce0a2008-11-10 06:08:34 +0000112 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
Sanjiv Gupta93eb8252008-05-25 05:15:42 +0000113
114 /// getOrCreateType - Get the type from the cache or create a new type if
115 /// necessary.
Chris Lattner562ce0a2008-11-10 06:08:34 +0000116 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000117};
118} // namespace CodeGen
119} // namespace clang
120
121#endif