2008-10-31 11:54:29 +08:00
|
|
|
//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
|
2008-05-08 16:54:20 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
// This is the source level debug info generator for llvm translation.
|
2008-05-08 16:54:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
#define CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2009-09-30 10:43:10 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2008-11-10 14:08:34 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-09-20 03:27:24 +08:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2010-01-14 08:36:21 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
#include <map>
|
|
|
|
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGBuilder.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
|
2009-09-20 03:27:24 +08:00
|
|
|
namespace llvm {
|
|
|
|
class MDNode;
|
|
|
|
}
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
namespace clang {
|
2008-05-30 18:30:31 +08:00
|
|
|
class VarDecl;
|
2009-02-27 05:10:26 +08:00
|
|
|
class ObjCInterfaceDecl;
|
2008-11-01 09:53:16 +08:00
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenModule;
|
2009-09-30 10:43:10 +08:00
|
|
|
class CodeGenFunction;
|
2010-01-14 08:36:21 +08:00
|
|
|
class GlobalDecl;
|
2008-05-08 16:54:20 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// CGDebugInfo - This class gathers all debug information during compilation
|
|
|
|
/// and is responsible for emitting to llvm globals or pass directly to
|
2008-05-25 13:15:42 +08:00
|
|
|
/// the backend.
|
2008-05-08 16:54:20 +08:00
|
|
|
class CGDebugInfo {
|
2009-12-07 02:00:51 +08:00
|
|
|
CodeGenModule &CGM;
|
2009-04-24 02:09:16 +08:00
|
|
|
bool isMainCompileUnitCreated;
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIFactory DebugFactory;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-10 14:08:34 +08:00
|
|
|
SourceLocation CurLoc, PrevLoc;
|
2010-01-29 02:11:52 +08:00
|
|
|
|
|
|
|
llvm::DIType VTablePtrType;
|
2008-05-08 16:54:20 +08:00
|
|
|
|
|
|
|
/// CompileUnitCache - Cache of previously constructed CompileUnits.
|
2009-04-18 05:06:59 +08:00
|
|
|
llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
|
2008-05-25 13:15:42 +08:00
|
|
|
|
|
|
|
/// TypeCache - Cache of previously constructed Types.
|
2008-11-10 14:08:34 +08:00
|
|
|
// FIXME: Eliminate this map. Be careful of iterator invalidation.
|
2009-09-20 04:17:48 +08:00
|
|
|
std::map<void *, llvm::WeakVH> TypeCache;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-14 10:03:51 +08:00
|
|
|
bool BlockLiteralGenericSet;
|
|
|
|
llvm::DIType BlockLiteralGeneric;
|
|
|
|
|
2009-11-14 03:10:24 +08:00
|
|
|
std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack;
|
2010-01-30 02:11:03 +08:00
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
|
2008-05-22 09:40:10 +08:00
|
|
|
|
2010-01-29 02:21:00 +08:00
|
|
|
/// DebugInfoNames - This is a storage for names that are
|
2010-01-14 08:36:21 +08:00
|
|
|
/// constructed on demand. For example, C++ destructors, C++ operators etc..
|
2010-01-29 02:21:00 +08:00
|
|
|
llvm::BumpPtrAllocator DebugInfoNames;
|
2010-01-14 08:36:21 +08:00
|
|
|
|
2010-01-19 09:54:44 +08:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
|
2010-02-02 03:16:32 +08:00
|
|
|
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
|
2010-01-19 09:54:44 +08:00
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
/// Helper functions for getOrCreateType.
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
|
2009-04-23 14:13:01 +08:00
|
|
|
llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
|
2009-09-25 09:40:47 +08:00
|
|
|
llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U);
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
|
2009-07-14 09:20:56 +08:00
|
|
|
llvm::DICompileUnit Unit);
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
|
2009-05-14 10:03:51 +08:00
|
|
|
llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
|
|
|
|
llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
|
|
|
|
llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
|
2009-02-27 05:10:26 +08:00
|
|
|
llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
|
|
|
|
llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
|
2009-11-07 03:19:55 +08:00
|
|
|
llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U);
|
2009-12-07 02:00:51 +08:00
|
|
|
llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U);
|
2010-01-28 08:28:01 +08:00
|
|
|
llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
|
|
|
|
llvm::DICompileUnit Unit);
|
2010-01-29 02:11:52 +08:00
|
|
|
llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit);
|
2010-02-02 03:16:32 +08:00
|
|
|
llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N,
|
|
|
|
llvm::DIDescriptor Unit);
|
|
|
|
|
2009-11-07 03:19:55 +08:00
|
|
|
llvm::DIType CreatePointerLikeType(unsigned Tag,
|
|
|
|
const Type *Ty, QualType PointeeTy,
|
|
|
|
llvm::DICompileUnit U);
|
2010-01-26 12:49:33 +08:00
|
|
|
|
2010-01-26 13:19:50 +08:00
|
|
|
llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
|
2010-01-26 12:49:33 +08:00
|
|
|
llvm::DICompileUnit Unit,
|
|
|
|
llvm::DICompositeType &RecordTy);
|
|
|
|
|
2010-01-19 09:54:44 +08:00
|
|
|
void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
|
|
|
|
llvm::DICompileUnit U,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E,
|
|
|
|
llvm::DICompositeType &T);
|
2010-01-26 07:32:18 +08:00
|
|
|
void CollectCXXBases(const CXXRecordDecl *Decl,
|
|
|
|
llvm::DICompileUnit Unit,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
|
|
|
|
llvm::DICompositeType &RecordTy);
|
|
|
|
|
|
|
|
|
2010-01-19 08:00:59 +08:00
|
|
|
void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
|
2010-01-29 02:11:52 +08:00
|
|
|
|
|
|
|
void CollectVtableInfo(const CXXRecordDecl *Decl,
|
|
|
|
llvm::DICompileUnit Unit,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
public:
|
2009-12-07 02:00:51 +08:00
|
|
|
CGDebugInfo(CodeGenModule &CGM);
|
2008-05-08 16:54:20 +08:00
|
|
|
~CGDebugInfo();
|
|
|
|
|
2008-10-18 00:15:48 +08:00
|
|
|
/// setLocation - Update the current source location. If \arg loc is
|
|
|
|
/// invalid it is ignored.
|
2008-11-10 14:08:34 +08:00
|
|
|
void setLocation(SourceLocation Loc);
|
2008-05-08 16:54:20 +08:00
|
|
|
|
|
|
|
/// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
|
|
|
|
/// source line.
|
2008-11-01 09:53:16 +08:00
|
|
|
void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
|
2008-05-25 13:15:42 +08:00
|
|
|
|
|
|
|
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
|
2008-10-19 02:22:23 +08:00
|
|
|
/// start of a new function.
|
2010-01-14 08:36:21 +08:00
|
|
|
void EmitFunctionStart(GlobalDecl GD, QualType FnType,
|
2008-11-01 09:53:16 +08:00
|
|
|
llvm::Function *Fn, CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
/// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
|
2009-09-09 23:08:12 +08:00
|
|
|
/// of a new block.
|
2008-11-01 09:53:16 +08:00
|
|
|
void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
/// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
|
2008-05-08 16:54:20 +08:00
|
|
|
/// block.
|
2008-11-01 09:53:16 +08:00
|
|
|
void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
|
2008-05-30 18:30:31 +08:00
|
|
|
|
2008-11-10 14:08:34 +08:00
|
|
|
/// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
|
|
|
|
/// variable declaration.
|
|
|
|
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2008-06-05 16:59:10 +08:00
|
|
|
|
2009-09-30 10:43:10 +08:00
|
|
|
/// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
|
|
|
|
/// imported variable declaration in a block.
|
|
|
|
void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE,
|
|
|
|
llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder,
|
|
|
|
CodeGenFunction *CGF);
|
|
|
|
|
2008-11-10 14:08:34 +08:00
|
|
|
/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
|
|
|
|
/// variable declaration.
|
|
|
|
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-05 16:59:10 +08:00
|
|
|
/// EmitGlobalVariable - Emit information about a global variable.
|
2008-11-10 14:08:34 +08:00
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
|
2009-02-27 05:10:26 +08:00
|
|
|
|
|
|
|
/// EmitGlobalVariable - Emit information about an objective-c interface.
|
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-03 17:11:11 +08:00
|
|
|
private:
|
2008-11-10 14:08:34 +08:00
|
|
|
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
|
|
|
|
void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-30 10:43:10 +08:00
|
|
|
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
|
|
|
|
void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder, CodeGenFunction *CGF);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-02-11 02:49:08 +08:00
|
|
|
// EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
|
|
|
|
// See BuildByRefType.
|
|
|
|
llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD,
|
|
|
|
uint64_t *OffSet);
|
|
|
|
|
2010-01-29 07:15:27 +08:00
|
|
|
/// getContextDescriptor - Get context info for the decl.
|
2010-01-30 02:11:03 +08:00
|
|
|
llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
|
2010-01-29 07:15:27 +08:00
|
|
|
llvm::DIDescriptor &CU);
|
2009-10-06 08:35:31 +08:00
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
/// getOrCreateCompileUnit - Get the compile unit from the cache or create a
|
|
|
|
/// new one if necessary.
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
|
2008-05-25 13:15:42 +08:00
|
|
|
|
|
|
|
/// getOrCreateType - Get the type from the cache or create a new type if
|
|
|
|
/// necessary.
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
|
2009-09-20 03:27:14 +08:00
|
|
|
|
|
|
|
/// CreateTypeNode - Create type metadata for a source language type.
|
|
|
|
llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit);
|
2010-01-14 08:36:21 +08:00
|
|
|
|
|
|
|
/// getFunctionName - Get function name for the given FunctionDecl. If the
|
|
|
|
/// name is constructred on demand (e.g. C++ destructor) then the name
|
|
|
|
/// is stored on the side.
|
|
|
|
llvm::StringRef getFunctionName(const FunctionDecl *FD);
|
2010-01-29 02:11:52 +08:00
|
|
|
|
|
|
|
/// getVtableName - Get vtable name for the given Class.
|
|
|
|
llvm::StringRef getVtableName(const CXXRecordDecl *Decl);
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
};
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace clang
|
|
|
|
|
2009-10-07 02:36:08 +08:00
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
#endif
|