CGDebugInfo.h revision 23e81bae8c91ccd408e31ca472dca25faed85028
1//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
2//
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
17#include "clang/AST/Type.h"
18#include "clang/Basic/SourceLocation.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/Analysis/DebugInfo.h"
21#include "llvm/Support/ValueHandle.h"
22#include <map>
23
24#include "CGBuilder.h"
25
26namespace llvm {
27  class MDNode;
28}
29
30namespace clang {
31  class VarDecl;
32  class ObjCInterfaceDecl;
33
34namespace CodeGen {
35  class CodeGenModule;
36
37/// CGDebugInfo - This class gathers all debug information during compilation
38/// and is responsible for emitting to llvm globals or pass directly to
39/// the backend.
40class CGDebugInfo {
41  CodeGenModule *M;
42  bool isMainCompileUnitCreated;
43  llvm::DIFactory DebugFactory;
44
45  SourceLocation CurLoc, PrevLoc;
46
47  /// CompileUnitCache - Cache of previously constructed CompileUnits.
48  llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
49
50  /// TypeCache - Cache of previously constructed Types.
51  // FIXME: Eliminate this map.  Be careful of iterator invalidation.
52  std::map<void *, llvm::AssertingVH<llvm::MDNode> > TypeCache;
53
54  bool BlockLiteralGenericSet;
55  llvm::DIType BlockLiteralGeneric;
56
57  std::vector<llvm::DIDescriptor> RegionStack;
58
59  /// Helper functions for getOrCreateType.
60  llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
61  llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
62  llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U);
63  llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
64  llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
65                          llvm::DICompileUnit Unit);
66  llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
67  llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
68  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);
71  llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
72  llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
73  llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
74
75public:
76  CGDebugInfo(CodeGenModule *m);
77  ~CGDebugInfo();
78
79  /// setLocation - Update the current source location. If \arg loc is
80  /// invalid it is ignored.
81  void setLocation(SourceLocation Loc);
82
83  /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
84  /// source line.
85  void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder);
86
87  /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
88  /// start of a new function.
89  void EmitFunctionStart(const char *Name, QualType ReturnType,
90                         llvm::Function *Fn, CGBuilderTy &Builder);
91
92  /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
93  /// of a new block.
94  void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder);
95
96  /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
97  /// block.
98  void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder);
99
100  /// 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);
104
105  /// 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);
109
110  /// EmitGlobalVariable - Emit information about a global variable.
111  void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
112
113  /// EmitGlobalVariable - Emit information about an objective-c interface.
114  void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
115
116private:
117  /// 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);
120
121
122  /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
123  /// new one if necessary.
124  llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
125
126  /// getOrCreateType - Get the type from the cache or create a new type if
127  /// necessary.
128  llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
129
130  /// CreateTypeNode - Create type metadata for a source language type.
131  llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit);
132};
133} // namespace CodeGen
134} // namespace clang
135
136#endif
137