1193326Sed//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10198092Srdivacky// This is the source level debug info generator for llvm translation.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
15193326Sed#define CLANG_CODEGEN_CGDEBUGINFO_H
16193326Sed
17249423Sdim#include "CGBuilder.h"
18249423Sdim#include "clang/AST/Expr.h"
19193326Sed#include "clang/AST/Type.h"
20193326Sed#include "clang/Basic/SourceLocation.h"
21263508Sdim#include "clang/Frontend/CodeGenOptions.h"
22249423Sdim#include "llvm/ADT/DenseMap.h"
23249423Sdim#include "llvm/DIBuilder.h"
24239462Sdim#include "llvm/DebugInfo.h"
25249423Sdim#include "llvm/Support/Allocator.h"
26198092Srdivacky#include "llvm/Support/ValueHandle.h"
27193326Sed
28198092Srdivackynamespace llvm {
29198092Srdivacky  class MDNode;
30198092Srdivacky}
31198092Srdivacky
32193326Sednamespace clang {
33239462Sdim  class CXXMethodDecl;
34193326Sed  class VarDecl;
35193326Sed  class ObjCInterfaceDecl;
36249423Sdim  class ObjCIvarDecl;
37221345Sdim  class ClassTemplateSpecializationDecl;
38224145Sdim  class GlobalDecl;
39263508Sdim  class UsingDecl;
40193326Sed
41193326Sednamespace CodeGen {
42193326Sed  class CodeGenModule;
43198092Srdivacky  class CodeGenFunction;
44218893Sdim  class CGBlockInfo;
45193326Sed
46198092Srdivacky/// CGDebugInfo - This class gathers all debug information during compilation
47198092Srdivacky/// and is responsible for emitting to llvm globals or pass directly to
48193326Sed/// the backend.
49193326Sedclass CGDebugInfo {
50263508Sdim  friend class NoLocation;
51263508Sdim  friend class ArtificialLocation;
52200583Srdivacky  CodeGenModule &CGM;
53263508Sdim  const CodeGenOptions::DebugInfoKind DebugKind;
54218893Sdim  llvm::DIBuilder DBuilder;
55204962Srdivacky  llvm::DICompileUnit TheCU;
56193326Sed  SourceLocation CurLoc, PrevLoc;
57204962Srdivacky  llvm::DIType VTablePtrType;
58243830Sdim  llvm::DIType ClassTy;
59249423Sdim  llvm::DICompositeType ObjTy;
60243830Sdim  llvm::DIType SelTy;
61249423Sdim  llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy;
62249423Sdim  llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy;
63249423Sdim  llvm::DIType OCLImage3dDITy;
64249423Sdim  llvm::DIType OCLEventDITy;
65263508Sdim  llvm::DIType BlockLiteralGeneric;
66263508Sdim
67193326Sed  /// TypeCache - Cache of previously constructed Types.
68206084Srdivacky  llvm::DenseMap<void *, llvm::WeakVH> TypeCache;
69198092Srdivacky
70249423Sdim  /// ObjCInterfaceCache - Cache of previously constructed interfaces
71249423Sdim  /// which may change. Storing a pair of DIType and checksum.
72263508Sdim  llvm::DenseMap<void *, std::pair<llvm::WeakVH, unsigned> > ObjCInterfaceCache;
73249423Sdim
74249423Sdim  /// RetainedTypes - list of interfaces we want to keep even if orphaned.
75249423Sdim  std::vector<void *> RetainedTypes;
76249423Sdim
77234353Sdim  /// CompleteTypeCache - Cache of previously constructed complete RecordTypes.
78234353Sdim  llvm::DenseMap<void *, llvm::WeakVH> CompletedTypeCache;
79234353Sdim
80234353Sdim  /// ReplaceMap - Cache of forward declared types to RAUW at the end of
81234353Sdim  /// compilation.
82234353Sdim  std::vector<std::pair<void *, llvm::WeakVH> >ReplaceMap;
83234353Sdim
84226633Sdim  // LexicalBlockStack - Keep track of our current nested lexical block.
85226633Sdim  std::vector<llvm::TrackingVH<llvm::MDNode> > LexicalBlockStack;
86203955Srdivacky  llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
87226633Sdim  // FnBeginRegionCount - Keep track of LexicalBlockStack counter at the
88226633Sdim  // beginning of a function. This is used to pop unbalanced regions at
89226633Sdim  // the end of a function.
90212904Sdim  std::vector<unsigned> FnBeginRegionCount;
91193326Sed
92203955Srdivacky  /// DebugInfoNames - This is a storage for names that are
93202379Srdivacky  /// constructed on demand. For example, C++ destructors, C++ operators etc..
94203955Srdivacky  llvm::BumpPtrAllocator DebugInfoNames;
95226633Sdim  StringRef CWDName;
96202379Srdivacky
97206084Srdivacky  llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
98202879Srdivacky  llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
99263508Sdim  /// \brief Cache declarations relevant to DW_TAG_imported_declarations (C++
100263508Sdim  /// using declarations) that aren't covered by other more specific caches.
101263508Sdim  llvm::DenseMap<const Decl *, llvm::WeakVH> DeclCache;
102203955Srdivacky  llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
103263508Sdim  llvm::DenseMap<const NamespaceAliasDecl *, llvm::WeakVH> NamespaceAliasCache;
104249423Sdim  llvm::DenseMap<const Decl *, llvm::WeakVH> StaticDataMemberCache;
105202879Srdivacky
106193326Sed  /// Helper functions for getOrCreateType.
107249423Sdim  unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl);
108218893Sdim  llvm::DIType CreateType(const BuiltinType *Ty);
109218893Sdim  llvm::DIType CreateType(const ComplexType *Ty);
110263508Sdim  llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile Fg);
111263508Sdim  llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile Fg);
112198092Srdivacky  llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
113204962Srdivacky                          llvm::DIFile F);
114204962Srdivacky  llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F);
115204962Srdivacky  llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F);
116204962Srdivacky  llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
117263508Sdim  llvm::DIType CreateType(const RecordType *Tyg);
118263508Sdim  llvm::DIType CreateTypeDefinition(const RecordType *Ty);
119263508Sdim  llvm::DICompositeType CreateLimitedType(const RecordType *Ty);
120263508Sdim  void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT);
121204962Srdivacky  llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
122208600Srdivacky  llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F);
123204962Srdivacky  llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F);
124204962Srdivacky  llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
125204962Srdivacky  llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
126218893Sdim  llvm::DIType CreateType(const RValueReferenceType *Ty, llvm::DIFile Unit);
127204962Srdivacky  llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
128226633Sdim  llvm::DIType CreateType(const AtomicType *Ty, llvm::DIFile F);
129263508Sdim  llvm::DIType CreateEnumType(const EnumType *Ty);
130249423Sdim  llvm::DIType CreateSelfType(const QualType &QualTy, llvm::DIType Ty);
131234353Sdim  llvm::DIType getTypeOrNull(const QualType);
132234353Sdim  llvm::DIType getCompletedTypeOrNull(const QualType);
133263508Sdim  llvm::DICompositeType getOrCreateMethodType(const CXXMethodDecl *Method,
134263508Sdim                                              llvm::DIFile F);
135263508Sdim  llvm::DICompositeType getOrCreateInstanceMethodType(
136249423Sdim      QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile Unit);
137263508Sdim  llvm::DICompositeType getOrCreateFunctionType(const Decl *D, QualType FnType,
138263508Sdim                                                llvm::DIFile F);
139204962Srdivacky  llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
140218893Sdim  llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N);
141263508Sdim  llvm::DIType getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile F);
142199482Srdivacky  llvm::DIType CreatePointerLikeType(unsigned Tag,
143199482Srdivacky                                     const Type *Ty, QualType PointeeTy,
144204962Srdivacky                                     llvm::DIFile F);
145249423Sdim
146249423Sdim  llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty);
147249423Sdim  llvm::DIType getOrCreateStructPtrType(StringRef Name, llvm::DIType &Cache);
148249423Sdim
149203955Srdivacky  llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
150204962Srdivacky                                             llvm::DIFile F,
151212904Sdim                                             llvm::DIType RecordTy);
152263508Sdim
153202879Srdivacky  void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
154204962Srdivacky                                 llvm::DIFile F,
155226633Sdim                                 SmallVectorImpl<llvm::Value *> &E,
156212904Sdim                                 llvm::DIType T);
157212904Sdim
158263508Sdim  void CollectCXXBases(const CXXRecordDecl *Decl,
159212904Sdim                       llvm::DIFile F,
160226633Sdim                       SmallVectorImpl<llvm::Value *> &EltTys,
161212904Sdim                       llvm::DIType RecordTy);
162212904Sdim
163221345Sdim  llvm::DIArray
164221345Sdim  CollectTemplateParams(const TemplateParameterList *TPList,
165263508Sdim                        ArrayRef<TemplateArgument> TAList,
166221345Sdim                        llvm::DIFile Unit);
167221345Sdim  llvm::DIArray
168221345Sdim  CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile Unit);
169263508Sdim  llvm::DIArray
170221345Sdim  CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
171221345Sdim                           llvm::DIFile F);
172203955Srdivacky
173226633Sdim  llvm::DIType createFieldType(StringRef name, QualType type,
174226633Sdim                               uint64_t sizeInBitsOverride, SourceLocation loc,
175219077Sdim                               AccessSpecifier AS, uint64_t offsetInBits,
176224145Sdim                               llvm::DIFile tunit,
177263508Sdim                               llvm::DIScope scope);
178249423Sdim
179249423Sdim  // Helpers for collecting fields of a record.
180249423Sdim  void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
181249423Sdim                                 SmallVectorImpl<llvm::Value *> &E,
182249423Sdim                                 llvm::DIType RecordTy);
183263508Sdim  llvm::DIDerivedType CreateRecordStaticField(const VarDecl *Var,
184263508Sdim                                              llvm::DIType RecordTy);
185249423Sdim  void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
186249423Sdim                                llvm::DIFile F,
187249423Sdim                                SmallVectorImpl<llvm::Value *> &E,
188249423Sdim                                llvm::DIType RecordTy);
189204962Srdivacky  void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
190226633Sdim                           SmallVectorImpl<llvm::Value *> &E,
191263508Sdim                           llvm::DICompositeType RecordTy);
192203955Srdivacky
193207619Srdivacky  void CollectVTableInfo(const CXXRecordDecl *Decl,
194204962Srdivacky                         llvm::DIFile F,
195226633Sdim                         SmallVectorImpl<llvm::Value *> &EltTys);
196203955Srdivacky
197226633Sdim  // CreateLexicalBlock - Create a new lexical block node and push it on
198226633Sdim  // the stack.
199226633Sdim  void CreateLexicalBlock(SourceLocation Loc);
200263508Sdim
201193326Sedpublic:
202200583Srdivacky  CGDebugInfo(CodeGenModule &CGM);
203193326Sed  ~CGDebugInfo();
204193326Sed
205249423Sdim  void finalize();
206234353Sdim
207193326Sed  /// setLocation - Update the current source location. If \arg loc is
208193326Sed  /// invalid it is ignored.
209193326Sed  void setLocation(SourceLocation Loc);
210193326Sed
211263508Sdim  /// getLocation - Return the current source location.
212263508Sdim  SourceLocation getLocation() const { return CurLoc; }
213263508Sdim
214226633Sdim  /// EmitLocation - Emit metadata to indicate a change in line/column
215226633Sdim  /// information in the source file.
216249423Sdim  /// \param ForceColumnInfo  Assume DebugColumnInfo option is true.
217249423Sdim  void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
218249423Sdim                    bool ForceColumnInfo = false);
219193326Sed
220193326Sed  /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
221193326Sed  /// start of a new function.
222202379Srdivacky  void EmitFunctionStart(GlobalDecl GD, QualType FnType,
223193326Sed                         llvm::Function *Fn, CGBuilderTy &Builder);
224198092Srdivacky
225212904Sdim  /// EmitFunctionEnd - Constructs the debug code for exiting a function.
226212904Sdim  void EmitFunctionEnd(CGBuilderTy &Builder);
227212904Sdim
228226633Sdim  /// EmitLexicalBlockStart - Emit metadata to indicate the beginning of a
229226633Sdim  /// new lexical block and push the block onto the stack.
230226633Sdim  void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
231198092Srdivacky
232226633Sdim  /// EmitLexicalBlockEnd - Emit metadata to indicate the end of a new lexical
233226633Sdim  /// block and pop the current block.
234226633Sdim  void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
235193326Sed
236193326Sed  /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
237193326Sed  /// variable declaration.
238193326Sed  void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
239193326Sed                                 CGBuilderTy &Builder);
240193326Sed
241198092Srdivacky  /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
242198092Srdivacky  /// imported variable declaration in a block.
243218893Sdim  void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
244218893Sdim                                         llvm::Value *storage,
245198092Srdivacky                                         CGBuilderTy &Builder,
246218893Sdim                                         const CGBlockInfo &blockInfo);
247198092Srdivacky
248193326Sed  /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
249193326Sed  /// variable declaration.
250193326Sed  void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
251221345Sdim                                unsigned ArgNo, CGBuilderTy &Builder);
252198092Srdivacky
253219077Sdim  /// EmitDeclareOfBlockLiteralArgVariable - Emit call to
254219077Sdim  /// llvm.dbg.declare for the block-literal argument to a block
255219077Sdim  /// invocation function.
256219077Sdim  void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
257249423Sdim                                            llvm::Value *Arg,
258249423Sdim                                            llvm::Value *LocalAddr,
259219077Sdim                                            CGBuilderTy &Builder);
260219077Sdim
261193326Sed  /// EmitGlobalVariable - Emit information about a global variable.
262193326Sed  void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
263193326Sed
264193326Sed  /// EmitGlobalVariable - Emit information about an objective-c interface.
265193326Sed  void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
266198092Srdivacky
267212904Sdim  /// EmitGlobalVariable - Emit global variable's debug info.
268218893Sdim  void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
269212904Sdim
270251662Sdim  /// \brief - Emit C++ using directive.
271251662Sdim  void EmitUsingDirective(const UsingDirectiveDecl &UD);
272251662Sdim
273263508Sdim  /// \brief - Emit C++ using declaration.
274263508Sdim  void EmitUsingDecl(const UsingDecl &UD);
275263508Sdim
276263508Sdim  /// \brief - Emit C++ namespace alias.
277263508Sdim  llvm::DIImportedEntity EmitNamespaceAlias(const NamespaceAliasDecl &NA);
278263508Sdim
279263508Sdim  /// getOrCreateRecordType - Emit record type's standalone debug info.
280218893Sdim  llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
281234353Sdim
282234353Sdim  /// getOrCreateInterfaceType - Emit an objective c interface type standalone
283234353Sdim  /// debug info.
284234353Sdim  llvm::DIType getOrCreateInterfaceType(QualType Ty,
285263508Sdim                                        SourceLocation Loc);
286234353Sdim
287263508Sdim  void completeType(const RecordDecl *RD);
288263508Sdim  void completeRequiredType(const RecordDecl *RD);
289263508Sdim  void completeClassData(const RecordDecl *RD);
290263508Sdim
291193326Sedprivate:
292193326Sed  /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
293193326Sed  void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
294221345Sdim                   unsigned ArgNo, CGBuilderTy &Builder);
295198092Srdivacky
296263508Sdim  // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
297203955Srdivacky  // See BuildByRefType.
298249423Sdim  llvm::DIType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
299203955Srdivacky                                            uint64_t *OffSet);
300198092Srdivacky
301203955Srdivacky  /// getContextDescriptor - Get context info for the decl.
302251662Sdim  llvm::DIScope getContextDescriptor(const Decl *Decl);
303203955Srdivacky
304263508Sdim  llvm::DIScope getCurrentContextDescriptor(const Decl *Decl);
305263508Sdim
306263508Sdim  /// \brief Create a forward decl for a RecordType in a given context.
307263508Sdim  llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordType *,
308263508Sdim                                                 llvm::DIDescriptor);
309263508Sdim
310234353Sdim  /// createContextChain - Create a set of decls for the context chain.
311234353Sdim  llvm::DIDescriptor createContextChain(const Decl *Decl);
312234353Sdim
313212904Sdim  /// getCurrentDirname - Return current directory name.
314226633Sdim  StringRef getCurrentDirname();
315212904Sdim
316204962Srdivacky  /// CreateCompileUnit - Create new compile unit.
317204962Srdivacky  void CreateCompileUnit();
318193326Sed
319263508Sdim  /// getOrCreateFile - Get the file debug info descriptor for the input
320204962Srdivacky  /// location.
321204962Srdivacky  llvm::DIFile getOrCreateFile(SourceLocation Loc);
322204962Srdivacky
323218893Sdim  /// getOrCreateMainFile - Get the file info for main compile unit.
324218893Sdim  llvm::DIFile getOrCreateMainFile();
325218893Sdim
326193326Sed  /// getOrCreateType - Get the type from the cache or create a new type if
327193326Sed  /// necessary.
328263508Sdim  llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile Fg);
329198092Srdivacky
330234353Sdim  /// getOrCreateLimitedType - Get the type from the cache or create a new
331234353Sdim  /// partial type if necessary.
332263508Sdim  llvm::DIType getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile F);
333234353Sdim
334198092Srdivacky  /// CreateTypeNode - Create type metadata for a source language type.
335263508Sdim  llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile Fg);
336202379Srdivacky
337249423Sdim  /// getObjCInterfaceDecl - return the underlying ObjCInterfaceDecl
338249423Sdim  /// if Ty is an ObjCInterface or a pointer to one.
339249423Sdim  ObjCInterfaceDecl* getObjCInterfaceDecl(QualType Ty);
340249423Sdim
341207619Srdivacky  /// CreateMemberType - Create new member and increase Offset by FType's size.
342207619Srdivacky  llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
343226633Sdim                                StringRef Name, uint64_t *Offset);
344207619Srdivacky
345263508Sdim  /// \brief Retrieve the DIDescriptor, if any, for the canonical form of this
346263508Sdim  /// declaration.
347263508Sdim  llvm::DIDescriptor getDeclarationOrDefinition(const Decl *D);
348263508Sdim
349221345Sdim  /// getFunctionDeclaration - Return debug info descriptor to describe method
350221345Sdim  /// declaration for the given method definition.
351221345Sdim  llvm::DISubprogram getFunctionDeclaration(const Decl *D);
352221345Sdim
353263508Sdim  /// Return debug info descriptor to describe in-class static data member
354263508Sdim  /// declaration for the given out-of-class definition.
355263508Sdim  llvm::DIDerivedType
356263508Sdim  getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
357249423Sdim
358202379Srdivacky  /// getFunctionName - Get function name for the given FunctionDecl. If the
359263508Sdim  /// name is constructed on demand (e.g. C++ destructor) then the name
360202379Srdivacky  /// is stored on the side.
361226633Sdim  StringRef getFunctionName(const FunctionDecl *FD);
362218893Sdim
363212904Sdim  /// getObjCMethodName - Returns the unmangled name of an Objective-C method.
364263508Sdim  /// This is the display name for the debugging info.
365226633Sdim  StringRef getObjCMethodName(const ObjCMethodDecl *FD);
366203955Srdivacky
367221345Sdim  /// getSelectorName - Return selector name. This is used for debugging
368221345Sdim  /// info.
369226633Sdim  StringRef getSelectorName(Selector S);
370221345Sdim
371212904Sdim  /// getClassName - Get class name including template argument list.
372234353Sdim  StringRef getClassName(const RecordDecl *RD);
373212904Sdim
374207619Srdivacky  /// getVTableName - Get vtable name for the given Class.
375226633Sdim  StringRef getVTableName(const CXXRecordDecl *Decl);
376203955Srdivacky
377208600Srdivacky  /// getLineNumber - Get line number for the location. If location is invalid
378208600Srdivacky  /// then use current location.
379208600Srdivacky  unsigned getLineNumber(SourceLocation Loc);
380208600Srdivacky
381263508Sdim  /// getColumnNumber - Get column number for the location. If location is
382208600Srdivacky  /// invalid then use current location.
383249423Sdim  /// \param Force  Assume DebugColumnInfo option is true.
384249423Sdim  unsigned getColumnNumber(SourceLocation Loc, bool Force=false);
385263508Sdim
386263508Sdim  /// internString - Allocate a copy of \p A using the DebugInfoNames allocator
387263508Sdim  /// and return a reference to it. If multiple arguments are given the strings
388263508Sdim  /// are concatenated.
389263508Sdim  StringRef internString(StringRef A, StringRef B = StringRef()) {
390263508Sdim    char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
391263508Sdim    std::memcpy(Data, A.data(), A.size());
392263508Sdim    std::memcpy(Data + A.size(), B.data(), B.size());
393263508Sdim    return StringRef(Data, A.size() + B.size());
394263508Sdim  }
395193326Sed};
396263508Sdim
397263508Sdim/// NoLocation - An RAII object that temporarily disables debug
398263508Sdim/// locations. This is useful for emitting instructions that should be
399263508Sdim/// counted towards the function prologue.
400263508Sdimclass NoLocation {
401263508Sdim  SourceLocation SavedLoc;
402263508Sdim  CGDebugInfo *DI;
403263508Sdim  CGBuilderTy &Builder;
404263508Sdimpublic:
405263508Sdim  NoLocation(CodeGenFunction &CGF, CGBuilderTy &B);
406263508Sdim  /// ~NoLocation - Autorestore everything back to normal.
407263508Sdim  ~NoLocation();
408263508Sdim};
409263508Sdim
410263508Sdim/// ArtificialLocation - An RAII object that temporarily switches to
411263508Sdim/// an artificial debug location that has a valid scope, but no line
412263508Sdim/// information. This is useful when emitting compiler-generated
413263508Sdim/// helper functions that have no source location associated with
414263508Sdim/// them. The DWARF specification allows the compiler to use the
415263508Sdim/// special line number 0 to indicate code that can not be attributed
416263508Sdim/// to any source location.
417263508Sdim///
418263508Sdim/// This is necessary because passing an empty SourceLocation to
419263508Sdim/// CGDebugInfo::setLocation() will result in the last valid location
420263508Sdim/// being reused.
421263508Sdimclass ArtificialLocation {
422263508Sdim  SourceLocation SavedLoc;
423263508Sdim  CGDebugInfo *DI;
424263508Sdim  CGBuilderTy &Builder;
425263508Sdimpublic:
426263508Sdim  ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B);
427263508Sdim
428263508Sdim  /// Set the current location to line 0, but within the current scope
429263508Sdim  /// (= the top of the LexicalBlockStack).
430263508Sdim  void Emit();
431263508Sdim
432263508Sdim  /// ~ArtificialLocation - Autorestore everything back to normal.
433263508Sdim  ~ArtificialLocation();
434263508Sdim};
435263508Sdim
436263508Sdim
437193326Sed} // namespace CodeGen
438193326Sed} // namespace clang
439193326Sed
440198092Srdivacky
441193326Sed#endif
442