CGDebugInfo.h revision 206084
117658Sjulian//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
217658Sjulian//
317658Sjulian//                     The LLVM Compiler Infrastructure
417658Sjulian//
517658Sjulian// This file is distributed under the University of Illinois Open Source
617658Sjulian// License. See LICENSE.TXT for details.
717658Sjulian//
817658Sjulian//===----------------------------------------------------------------------===//
917658Sjulian//
1017658Sjulian// This is the source level debug info generator for llvm translation.
1117658Sjulian//
1217658Sjulian//===----------------------------------------------------------------------===//
1317658Sjulian
1417658Sjulian#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
1517658Sjulian#define CLANG_CODEGEN_CGDEBUGINFO_H
1617658Sjulian
1717658Sjulian#include "clang/AST/Type.h"
1817658Sjulian#include "clang/AST/Expr.h"
1917658Sjulian#include "clang/Basic/SourceLocation.h"
2017658Sjulian#include "llvm/ADT/DenseMap.h"
2117658Sjulian#include "llvm/Analysis/DebugInfo.h"
2217658Sjulian#include "llvm/Support/ValueHandle.h"
2317658Sjulian#include "llvm/Support/Allocator.h"
2417658Sjulian
2517658Sjulian#include "CGBuilder.h"
2617658Sjulian
2717658Sjuliannamespace llvm {
2817658Sjulian  class MDNode;
2917658Sjulian}
3017658Sjulian
3117658Sjuliannamespace clang {
3217658Sjulian  class VarDecl;
3317658Sjulian  class ObjCInterfaceDecl;
3417658Sjulian
3517658Sjuliannamespace CodeGen {
3617658Sjulian  class CodeGenModule;
37116182Sobrien  class CodeGenFunction;
38116182Sobrien  class GlobalDecl;
39116182Sobrien
40174921Srwatson/// CGDebugInfo - This class gathers all debug information during compilation
41131927Smarcel/// and is responsible for emitting to llvm globals or pass directly to
4228976Sbde/// the backend.
43134649Sscottlclass CGDebugInfo {
44221173Sattilio  CodeGenModule &CGM;
4517658Sjulian  llvm::DIFactory DebugFactory;
4617658Sjulian  llvm::DICompileUnit TheCU;
4717658Sjulian  SourceLocation CurLoc, PrevLoc;
4860041Sphk  llvm::DIType VTablePtrType;
4931275Sbde  /// FwdDeclCount - This counter is used to ensure unique names for forward
5078767Sjhb  /// record decls.
5178767Sjhb  unsigned FwdDeclCount;
5278767Sjhb
53193066Sjamie  /// TypeCache - Cache of previously constructed Types.
54131927Smarcel  llvm::DenseMap<void *, llvm::WeakVH> TypeCache;
5517658Sjulian
56183527Speter  bool BlockLiteralGenericSet;
5755539Sluoqi  llvm::DIType BlockLiteralGeneric;
58243980Salfred
5989601Ssobomax  std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack;
6021776Sbde  llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
61164033Srwatson
6278767Sjhb  /// DebugInfoNames - This is a storage for names that are
6378767Sjhb  /// constructed on demand. For example, C++ destructors, C++ operators etc..
6478767Sjhb  llvm::BumpPtrAllocator DebugInfoNames;
65248084Sattilio
66137263Speter  llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
67206878Sattilio  llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
6817658Sjulian  llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
6917658Sjulian
70225448Sattilio  /// Helper functions for getOrCreateType.
71221173Sattilio  llvm::DIType CreateType(const BuiltinType *Ty, llvm::DIFile F);
7217658Sjulian  llvm::DIType CreateType(const ComplexType *Ty, llvm::DIFile F);
73174921Srwatson  llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F);
74174921Srwatson  llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F);
75118990Smarcel  llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
7694169Sphk                          llvm::DIFile F);
7791778Sjake  llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F);
7817658Sjulian  llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F);
79163606Srwatson  llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
80163606Srwatson  llvm::DIType CreateType(const TagType *Ty, llvm::DIFile F);
81157628Spjd  llvm::DIType CreateType(const RecordType *Ty, llvm::DIFile F);
82157628Spjd  llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
83157628Spjd  llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F);
84157628Spjd  llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F);
85157628Spjd  llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
86157628Spjd  llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
8717658Sjulian  llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
8817658Sjulian  llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
8917658Sjulian                                     llvm::DIFile F);
9017658Sjulian  llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
9117658Sjulian  llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N,
92258956Scperciva                                         llvm::DIDescriptor Unit);
93258893Scperciva
94258893Scperciva  llvm::DIType CreatePointerLikeType(unsigned Tag,
95258893Scperciva                                     const Type *Ty, QualType PointeeTy,
96258893Scperciva                                     llvm::DIFile F);
9717658Sjulian
9817658Sjulian  llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
9917658Sjulian                                             llvm::DIFile F,
10017658Sjulian                                             llvm::DICompositeType &RecordTy);
10117658Sjulian
10217658Sjulian  void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
10317658Sjulian                                 llvm::DIFile F,
104131927Smarcel                                 llvm::SmallVectorImpl<llvm::DIDescriptor> &E,
105131927Smarcel                                 llvm::DICompositeType &T);
10642135Smsmith  void CollectCXXBases(const CXXRecordDecl *Decl,
10717658Sjulian                       llvm::DIFile F,
10842135Smsmith                       llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
10917658Sjulian                       llvm::DICompositeType &RecordTy);
110228475Sobrien
111228487Sobrien
112228487Sobrien  void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
113213322Savg                           llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
114103647Sjhb
115131927Smarcel  void CollectVtableInfo(const CXXRecordDecl *Decl,
116213322Savg                         llvm::DIFile F,
117103647Sjhb                         llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
118213322Savg
11917658Sjulianpublic:
120228475Sobrien  CGDebugInfo(CodeGenModule &CGM);
121228487Sobrien  ~CGDebugInfo();
122228487Sobrien
123213322Savg  /// setLocation - Update the current source location. If \arg loc is
124131927Smarcel  /// invalid it is ignored.
12517658Sjulian  void setLocation(SourceLocation Loc);
126213322Savg
127213322Savg  /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
12885202Speter  /// source line.
129213322Savg  void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
13085202Speter
131227309Sed  /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
132227309Sed  /// start of a new function.
13343436Smsmith  void EmitFunctionStart(GlobalDecl GD, QualType FnType,
134225448Sattilio                         llvm::Function *Fn, CGBuilderTy &Builder);
135225448Sattilio
136225448Sattilio  /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
137225448Sattilio  /// of a new block.
138225448Sattilio  void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
139225448Sattilio
140225448Sattilio  /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
141225448Sattilio  /// block.
14217658Sjulian  void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
14317658Sjulian
14417658Sjulian  /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
14517658Sjulian  /// variable declaration.
14617658Sjulian  void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
14717658Sjulian                                 CGBuilderTy &Builder);
14893496Sphk
149155383Sjeff  /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
15093496Sphk  /// imported variable declaration in a block.
15167093Sps  void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE,
152131927Smarcel                                         llvm::Value *AI,
153131927Smarcel                                         CGBuilderTy &Builder,
154235777Sharti                                         CodeGenFunction *CGF);
155131927Smarcel
15665395Speter  /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
15765395Speter  /// variable declaration.
15865395Speter  void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
15965395Speter                                CGBuilderTy &Builder);
160243980Salfred
16117658Sjulian  /// EmitGlobalVariable - Emit information about a global variable.
16250107Smsmith  void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
163110859Salfred
16450107Smsmith  /// EmitGlobalVariable - Emit information about an objective-c interface.
16550107Smsmith  void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
166110859Salfred
167110859Salfredprivate:
168214279Sbrucec  /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
169110859Salfred  void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
170110859Salfred                   CGBuilderTy &Builder);
171110859Salfred
172110859Salfred  /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
173110859Salfred  void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI,
174110859Salfred                   CGBuilderTy &Builder, CodeGenFunction *CGF);
17550107Smsmith
17648868Sphk  // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
177177253Srwatson  // See BuildByRefType.
17850107Smsmith  llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD,
17917658Sjulian                                            uint64_t *OffSet);
180167211Srwatson
18117658Sjulian  /// getContextDescriptor - Get context info for the decl.
18282749Sdillon  llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
18317658Sjulian                                          llvm::DIDescriptor &CU);
184225617Skmacy
18517658Sjulian  /// CreateCompileUnit - Create new compile unit.
18617658Sjulian  void CreateCompileUnit();
18717658Sjulian
188106024Srwatson  /// getOrCreateFile - Get the file debug info descriptor for the input
189106024Srwatson  /// location.
190172930Srwatson  llvm::DIFile getOrCreateFile(SourceLocation Loc);
191106024Srwatson
192106024Srwatson  /// getOrCreateType - Get the type from the cache or create a new type if
193164033Srwatson  /// necessary.
194106024Srwatson  llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
195106024Srwatson
196214004Smarcel  /// CreateTypeNode - Create type metadata for a source language type.
197106024Srwatson  llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F);
198106024Srwatson
19982749Sdillon  /// getFunctionName - Get function name for the given FunctionDecl. If the
20017658Sjulian  /// name is constructred on demand (e.g. C++ destructor) then the name
20117658Sjulian  /// is stored on the side.
20217658Sjulian  llvm::StringRef getFunctionName(const FunctionDecl *FD);
20317658Sjulian
20417658Sjulian  /// getVtableName - Get vtable name for the given Class.
20517658Sjulian  llvm::StringRef getVtableName(const CXXRecordDecl *Decl);
20665268Smsmith
20717658Sjulian};
208110859Salfred} // namespace CodeGen
20917658Sjulian} // namespace clang
210264237Sed
21173913Sjhb
212264237Sed#endif
213264237Sed