1//===--- CodeGenModule.h - Per-Module state 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 internal per-translation-unit state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
16
17#include "CGVTables.h"
18#include "CodeGenTypes.h"
19#include "SanitizerMetadata.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/DeclCXX.h"
22#include "clang/AST/DeclObjC.h"
23#include "clang/AST/GlobalDecl.h"
24#include "clang/AST/Mangle.h"
25#include "clang/Basic/ABI.h"
26#include "clang/Basic/LangOptions.h"
27#include "clang/Basic/Module.h"
28#include "clang/Basic/SanitizerBlacklist.h"
29#include "llvm/ADT/DenseMap.h"
30#include "llvm/ADT/SetVector.h"
31#include "llvm/ADT/SmallPtrSet.h"
32#include "llvm/ADT/StringMap.h"
33#include "llvm/IR/CallingConv.h"
34#include "llvm/IR/Module.h"
35#include "llvm/IR/ValueHandle.h"
36
37namespace llvm {
38class Module;
39class Constant;
40class ConstantInt;
41class Function;
42class GlobalValue;
43class DataLayout;
44class FunctionType;
45class LLVMContext;
46class IndexedInstrProfReader;
47}
48
49namespace clang {
50class TargetCodeGenInfo;
51class ASTContext;
52class AtomicType;
53class FunctionDecl;
54class IdentifierInfo;
55class ObjCMethodDecl;
56class ObjCImplementationDecl;
57class ObjCCategoryImplDecl;
58class ObjCProtocolDecl;
59class ObjCEncodeExpr;
60class BlockExpr;
61class CharUnits;
62class Decl;
63class Expr;
64class Stmt;
65class InitListExpr;
66class StringLiteral;
67class NamedDecl;
68class ValueDecl;
69class VarDecl;
70class LangOptions;
71class CodeGenOptions;
72class DiagnosticsEngine;
73class AnnotateAttr;
74class CXXDestructorDecl;
75class Module;
76class CoverageSourceInfo;
77
78namespace CodeGen {
79
80class CallArgList;
81class CodeGenFunction;
82class CodeGenTBAA;
83class CGCXXABI;
84class CGDebugInfo;
85class CGObjCRuntime;
86class CGOpenCLRuntime;
87class CGOpenMPRuntime;
88class CGCUDARuntime;
89class BlockFieldFlags;
90class FunctionArgList;
91class CoverageMappingModuleGen;
92
93struct OrderGlobalInits {
94  unsigned int priority;
95  unsigned int lex_order;
96  OrderGlobalInits(unsigned int p, unsigned int l)
97      : priority(p), lex_order(l) {}
98
99  bool operator==(const OrderGlobalInits &RHS) const {
100    return priority == RHS.priority && lex_order == RHS.lex_order;
101  }
102
103  bool operator<(const OrderGlobalInits &RHS) const {
104    return std::tie(priority, lex_order) <
105           std::tie(RHS.priority, RHS.lex_order);
106  }
107};
108
109struct CodeGenTypeCache {
110  /// void
111  llvm::Type *VoidTy;
112
113  /// i8, i16, i32, and i64
114  llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
115  /// float, double
116  llvm::Type *FloatTy, *DoubleTy;
117
118  /// int
119  llvm::IntegerType *IntTy;
120
121  /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
122  union {
123    llvm::IntegerType *IntPtrTy;
124    llvm::IntegerType *SizeTy;
125    llvm::IntegerType *PtrDiffTy;
126  };
127
128  /// void* in address space 0
129  union {
130    llvm::PointerType *VoidPtrTy;
131    llvm::PointerType *Int8PtrTy;
132  };
133
134  /// void** in address space 0
135  union {
136    llvm::PointerType *VoidPtrPtrTy;
137    llvm::PointerType *Int8PtrPtrTy;
138  };
139
140  /// The width of a pointer into the generic address space.
141  unsigned char PointerWidthInBits;
142
143  /// The size and alignment of a pointer into the generic address
144  /// space.
145  union {
146    unsigned char PointerAlignInBytes;
147    unsigned char PointerSizeInBytes;
148    unsigned char SizeSizeInBytes; // sizeof(size_t)
149  };
150
151  llvm::CallingConv::ID RuntimeCC;
152  llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
153  llvm::CallingConv::ID BuiltinCC;
154  llvm::CallingConv::ID getBuiltinCC() const { return BuiltinCC; }
155};
156
157struct RREntrypoints {
158  RREntrypoints() { memset(this, 0, sizeof(*this)); }
159  /// void objc_autoreleasePoolPop(void*);
160  llvm::Constant *objc_autoreleasePoolPop;
161
162  /// void *objc_autoreleasePoolPush(void);
163  llvm::Constant *objc_autoreleasePoolPush;
164};
165
166struct ARCEntrypoints {
167  ARCEntrypoints() { memset(this, 0, sizeof(*this)); }
168
169  /// id objc_autorelease(id);
170  llvm::Constant *objc_autorelease;
171
172  /// id objc_autoreleaseReturnValue(id);
173  llvm::Constant *objc_autoreleaseReturnValue;
174
175  /// void objc_copyWeak(id *dest, id *src);
176  llvm::Constant *objc_copyWeak;
177
178  /// void objc_destroyWeak(id*);
179  llvm::Constant *objc_destroyWeak;
180
181  /// id objc_initWeak(id*, id);
182  llvm::Constant *objc_initWeak;
183
184  /// id objc_loadWeak(id*);
185  llvm::Constant *objc_loadWeak;
186
187  /// id objc_loadWeakRetained(id*);
188  llvm::Constant *objc_loadWeakRetained;
189
190  /// void objc_moveWeak(id *dest, id *src);
191  llvm::Constant *objc_moveWeak;
192
193  /// id objc_retain(id);
194  llvm::Constant *objc_retain;
195
196  /// id objc_retainAutorelease(id);
197  llvm::Constant *objc_retainAutorelease;
198
199  /// id objc_retainAutoreleaseReturnValue(id);
200  llvm::Constant *objc_retainAutoreleaseReturnValue;
201
202  /// id objc_retainAutoreleasedReturnValue(id);
203  llvm::Constant *objc_retainAutoreleasedReturnValue;
204
205  /// id objc_retainBlock(id);
206  llvm::Constant *objc_retainBlock;
207
208  /// void objc_release(id);
209  llvm::Constant *objc_release;
210
211  /// id objc_storeStrong(id*, id);
212  llvm::Constant *objc_storeStrong;
213
214  /// id objc_storeWeak(id*, id);
215  llvm::Constant *objc_storeWeak;
216
217  /// A void(void) inline asm to use to mark that the return value of
218  /// a call will be immediately retain.
219  llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
220
221  /// void clang.arc.use(...);
222  llvm::Constant *clang_arc_use;
223};
224
225/// This class records statistics on instrumentation based profiling.
226class InstrProfStats {
227  uint32_t VisitedInMainFile;
228  uint32_t MissingInMainFile;
229  uint32_t Visited;
230  uint32_t Missing;
231  uint32_t Mismatched;
232
233public:
234  InstrProfStats()
235      : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
236        Mismatched(0) {}
237  /// Record that we've visited a function and whether or not that function was
238  /// in the main source file.
239  void addVisited(bool MainFile) {
240    if (MainFile)
241      ++VisitedInMainFile;
242    ++Visited;
243  }
244  /// Record that a function we've visited has no profile data.
245  void addMissing(bool MainFile) {
246    if (MainFile)
247      ++MissingInMainFile;
248    ++Missing;
249  }
250  /// Record that a function we've visited has mismatched profile data.
251  void addMismatched(bool MainFile) { ++Mismatched; }
252  /// Whether or not the stats we've gathered indicate any potential problems.
253  bool hasDiagnostics() { return Missing || Mismatched; }
254  /// Report potential problems we've found to \c Diags.
255  void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
256};
257
258/// This class organizes the cross-function state that is used while generating
259/// LLVM code.
260class CodeGenModule : public CodeGenTypeCache {
261  CodeGenModule(const CodeGenModule &) = delete;
262  void operator=(const CodeGenModule &) = delete;
263
264public:
265  struct Structor {
266    Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
267    Structor(int Priority, llvm::Constant *Initializer,
268             llvm::Constant *AssociatedData)
269        : Priority(Priority), Initializer(Initializer),
270          AssociatedData(AssociatedData) {}
271    int Priority;
272    llvm::Constant *Initializer;
273    llvm::Constant *AssociatedData;
274  };
275
276  typedef std::vector<Structor> CtorList;
277
278private:
279  ASTContext &Context;
280  const LangOptions &LangOpts;
281  const CodeGenOptions &CodeGenOpts;
282  llvm::Module &TheModule;
283  DiagnosticsEngine &Diags;
284  const llvm::DataLayout &TheDataLayout;
285  const TargetInfo &Target;
286  std::unique_ptr<CGCXXABI> ABI;
287  llvm::LLVMContext &VMContext;
288
289  CodeGenTBAA *TBAA;
290
291  mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
292
293  // This should not be moved earlier, since its initialization depends on some
294  // of the previous reference members being already initialized and also checks
295  // if TheTargetCodeGenInfo is NULL
296  CodeGenTypes Types;
297
298  /// Holds information about C++ vtables.
299  CodeGenVTables VTables;
300
301  CGObjCRuntime* ObjCRuntime;
302  CGOpenCLRuntime* OpenCLRuntime;
303  CGOpenMPRuntime* OpenMPRuntime;
304  CGCUDARuntime* CUDARuntime;
305  CGDebugInfo* DebugInfo;
306  ARCEntrypoints *ARCData;
307  llvm::MDNode *NoObjCARCExceptionsMetadata;
308  RREntrypoints *RRData;
309  std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
310  InstrProfStats PGOStats;
311
312  // A set of references that have only been seen via a weakref so far. This is
313  // used to remove the weak of the reference if we ever see a direct reference
314  // or a definition.
315  llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
316
317  /// This contains all the decls which have definitions but/ which are deferred
318  /// for emission and therefore should only be output if they are actually
319  /// used. If a decl is in this, then it is known to have not been referenced
320  /// yet.
321  std::map<StringRef, GlobalDecl> DeferredDecls;
322
323  /// This is a list of deferred decls which we have seen that *are* actually
324  /// referenced. These get code generated when the module is done.
325  struct DeferredGlobal {
326    DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
327    llvm::TrackingVH<llvm::GlobalValue> GV;
328    GlobalDecl GD;
329  };
330  std::vector<DeferredGlobal> DeferredDeclsToEmit;
331  void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
332    DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD));
333  }
334
335  /// List of alias we have emitted. Used to make sure that what they point to
336  /// is defined once we get to the end of the of the translation unit.
337  std::vector<GlobalDecl> Aliases;
338
339  typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
340  ReplacementsTy Replacements;
341
342  /// A queue of (optional) vtables to consider emitting.
343  std::vector<const CXXRecordDecl*> DeferredVTables;
344
345  /// List of global values which are required to be present in the object file;
346  /// bitcast to i8*. This is used for forcing visibility of symbols which may
347  /// otherwise be optimized out.
348  std::vector<llvm::WeakVH> LLVMUsed;
349  std::vector<llvm::WeakVH> LLVMCompilerUsed;
350
351  /// Store the list of global constructors and their respective priorities to
352  /// be emitted when the translation unit is complete.
353  CtorList GlobalCtors;
354
355  /// Store the list of global destructors and their respective priorities to be
356  /// emitted when the translation unit is complete.
357  CtorList GlobalDtors;
358
359  /// An ordered map of canonical GlobalDecls to their mangled names.
360  llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
361  llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
362
363  /// Global annotations.
364  std::vector<llvm::Constant*> Annotations;
365
366  /// Map used to get unique annotation strings.
367  llvm::StringMap<llvm::Constant*> AnnotationStrings;
368
369  llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
370
371  llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
372  llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
373  llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
374  llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
375
376  llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
377  llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
378
379  /// Map used to get unique type descriptor constants for sanitizers.
380  llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
381
382  /// Map used to track internal linkage functions declared within
383  /// extern "C" regions.
384  typedef llvm::MapVector<IdentifierInfo *,
385                          llvm::GlobalValue *> StaticExternCMap;
386  StaticExternCMap StaticExternCValues;
387
388  /// \brief thread_local variables defined or used in this TU.
389  std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> >
390    CXXThreadLocals;
391
392  /// \brief thread_local variables with initializers that need to run
393  /// before any thread_local variable in this TU is odr-used.
394  std::vector<llvm::Function *> CXXThreadLocalInits;
395  std::vector<llvm::GlobalVariable *> CXXThreadLocalInitVars;
396
397  /// Global variables with initializers that need to run before main.
398  std::vector<llvm::Function *> CXXGlobalInits;
399
400  /// When a C++ decl with an initializer is deferred, null is
401  /// appended to CXXGlobalInits, and the index of that null is placed
402  /// here so that the initializer will be performed in the correct
403  /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
404  /// that we don't re-emit the initializer.
405  llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
406
407  typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
408
409  struct GlobalInitPriorityCmp {
410    bool operator()(const GlobalInitData &LHS,
411                    const GlobalInitData &RHS) const {
412      return LHS.first.priority < RHS.first.priority;
413    }
414  };
415
416  /// Global variables with initializers whose order of initialization is set by
417  /// init_priority attribute.
418  SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
419
420  /// Global destructor functions and arguments that need to run on termination.
421  std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
422
423  /// \brief The complete set of modules that has been imported.
424  llvm::SetVector<clang::Module *> ImportedModules;
425
426  /// \brief A vector of metadata strings.
427  SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
428
429  /// @name Cache for Objective-C runtime types
430  /// @{
431
432  /// Cached reference to the class for constant strings. This value has type
433  /// int * but is actually an Obj-C class pointer.
434  llvm::WeakVH CFConstantStringClassRef;
435
436  /// Cached reference to the class for constant strings. This value has type
437  /// int * but is actually an Obj-C class pointer.
438  llvm::WeakVH ConstantStringClassRef;
439
440  /// \brief The LLVM type corresponding to NSConstantString.
441  llvm::StructType *NSConstantStringType;
442
443  /// \brief The type used to describe the state of a fast enumeration in
444  /// Objective-C's for..in loop.
445  QualType ObjCFastEnumerationStateType;
446
447  /// @}
448
449  /// Lazily create the Objective-C runtime
450  void createObjCRuntime();
451
452  void createOpenCLRuntime();
453  void createOpenMPRuntime();
454  void createCUDARuntime();
455
456  bool isTriviallyRecursive(const FunctionDecl *F);
457  bool shouldEmitFunction(GlobalDecl GD);
458
459  /// @name Cache for Blocks Runtime Globals
460  /// @{
461
462  llvm::Constant *NSConcreteGlobalBlock;
463  llvm::Constant *NSConcreteStackBlock;
464
465  llvm::Constant *BlockObjectAssign;
466  llvm::Constant *BlockObjectDispose;
467
468  llvm::Type *BlockDescriptorType;
469  llvm::Type *GenericBlockLiteralType;
470
471  struct {
472    int GlobalUniqueCount;
473  } Block;
474
475  /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
476  llvm::Constant *LifetimeStartFn;
477
478  /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
479  llvm::Constant *LifetimeEndFn;
480
481  GlobalDecl initializedGlobalDecl;
482
483  std::unique_ptr<SanitizerMetadata> SanitizerMD;
484
485  /// @}
486
487  llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
488
489  std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
490public:
491  CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
492                llvm::Module &M, const llvm::DataLayout &TD,
493                DiagnosticsEngine &Diags,
494                CoverageSourceInfo *CoverageInfo = nullptr);
495
496  ~CodeGenModule();
497
498  void clear();
499
500  /// Finalize LLVM code generation.
501  void Release();
502
503  /// Return a reference to the configured Objective-C runtime.
504  CGObjCRuntime &getObjCRuntime() {
505    if (!ObjCRuntime) createObjCRuntime();
506    return *ObjCRuntime;
507  }
508
509  /// Return true iff an Objective-C runtime has been configured.
510  bool hasObjCRuntime() { return !!ObjCRuntime; }
511
512  /// Return a reference to the configured OpenCL runtime.
513  CGOpenCLRuntime &getOpenCLRuntime() {
514    assert(OpenCLRuntime != nullptr);
515    return *OpenCLRuntime;
516  }
517
518  /// Return a reference to the configured OpenMP runtime.
519  CGOpenMPRuntime &getOpenMPRuntime() {
520    assert(OpenMPRuntime != nullptr);
521    return *OpenMPRuntime;
522  }
523
524  /// Return a reference to the configured CUDA runtime.
525  CGCUDARuntime &getCUDARuntime() {
526    assert(CUDARuntime != nullptr);
527    return *CUDARuntime;
528  }
529
530  ARCEntrypoints &getARCEntrypoints() const {
531    assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr);
532    return *ARCData;
533  }
534
535  RREntrypoints &getRREntrypoints() const {
536    assert(RRData != nullptr);
537    return *RRData;
538  }
539
540  InstrProfStats &getPGOStats() { return PGOStats; }
541  llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
542
543  CoverageMappingModuleGen *getCoverageMapping() const {
544    return CoverageMapping.get();
545  }
546
547  llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
548    return StaticLocalDeclMap[D];
549  }
550  void setStaticLocalDeclAddress(const VarDecl *D,
551                                 llvm::Constant *C) {
552    StaticLocalDeclMap[D] = C;
553  }
554
555  llvm::Constant *
556  getOrCreateStaticVarDecl(const VarDecl &D,
557                           llvm::GlobalValue::LinkageTypes Linkage);
558
559  llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
560    return StaticLocalDeclGuardMap[D];
561  }
562  void setStaticLocalDeclGuardAddress(const VarDecl *D,
563                                      llvm::GlobalVariable *C) {
564    StaticLocalDeclGuardMap[D] = C;
565  }
566
567  bool lookupRepresentativeDecl(StringRef MangledName,
568                                GlobalDecl &Result) const;
569
570  llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
571    return AtomicSetterHelperFnMap[Ty];
572  }
573  void setAtomicSetterHelperFnMap(QualType Ty,
574                            llvm::Constant *Fn) {
575    AtomicSetterHelperFnMap[Ty] = Fn;
576  }
577
578  llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
579    return AtomicGetterHelperFnMap[Ty];
580  }
581  void setAtomicGetterHelperFnMap(QualType Ty,
582                            llvm::Constant *Fn) {
583    AtomicGetterHelperFnMap[Ty] = Fn;
584  }
585
586  llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
587    return TypeDescriptorMap[Ty];
588  }
589  void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
590    TypeDescriptorMap[Ty] = C;
591  }
592
593  CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
594
595  llvm::MDNode *getNoObjCARCExceptionsMetadata() {
596    if (!NoObjCARCExceptionsMetadata)
597      NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
598    return NoObjCARCExceptionsMetadata;
599  }
600
601  ASTContext &getContext() const { return Context; }
602  const LangOptions &getLangOpts() const { return LangOpts; }
603  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
604  llvm::Module &getModule() const { return TheModule; }
605  DiagnosticsEngine &getDiags() const { return Diags; }
606  const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
607  const TargetInfo &getTarget() const { return Target; }
608  const llvm::Triple &getTriple() const;
609  bool supportsCOMDAT() const;
610  void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
611
612  CGCXXABI &getCXXABI() const { return *ABI; }
613  llvm::LLVMContext &getLLVMContext() { return VMContext; }
614
615  bool shouldUseTBAA() const { return TBAA != nullptr; }
616
617  const TargetCodeGenInfo &getTargetCodeGenInfo();
618
619  CodeGenTypes &getTypes() { return Types; }
620
621  CodeGenVTables &getVTables() { return VTables; }
622
623  ItaniumVTableContext &getItaniumVTableContext() {
624    return VTables.getItaniumVTableContext();
625  }
626
627  MicrosoftVTableContext &getMicrosoftVTableContext() {
628    return VTables.getMicrosoftVTableContext();
629  }
630
631  CtorList &getGlobalCtors() { return GlobalCtors; }
632  CtorList &getGlobalDtors() { return GlobalDtors; }
633
634  llvm::MDNode *getTBAAInfo(QualType QTy);
635  llvm::MDNode *getTBAAInfoForVTablePtr();
636  llvm::MDNode *getTBAAStructInfo(QualType QTy);
637  /// Return the MDNode in the type DAG for the given struct type.
638  llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
639  /// Return the path-aware tag for given base type, access node and offset.
640  llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
641                                     uint64_t O);
642
643  bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
644
645  bool isPaddedAtomicType(QualType type);
646  bool isPaddedAtomicType(const AtomicType *type);
647
648  /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
649  /// is the same as the type. For struct-path aware TBAA, the tag
650  /// is different from the type: base type, access type and offset.
651  /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
652  void DecorateInstruction(llvm::Instruction *Inst,
653                           llvm::MDNode *TBAAInfo,
654                           bool ConvertTypeToTag = true);
655
656  /// Emit the given number of characters as a value of type size_t.
657  llvm::ConstantInt *getSize(CharUnits numChars);
658
659  /// Set the visibility for the given LLVM GlobalValue.
660  void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
661
662  /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
663  /// variable declaration D.
664  void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
665
666  static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
667    switch (V) {
668    case DefaultVisibility:   return llvm::GlobalValue::DefaultVisibility;
669    case HiddenVisibility:    return llvm::GlobalValue::HiddenVisibility;
670    case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
671    }
672    llvm_unreachable("unknown visibility!");
673  }
674
675  llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
676    if (isa<CXXConstructorDecl>(GD.getDecl()))
677      return getAddrOfCXXStructor(cast<CXXConstructorDecl>(GD.getDecl()),
678                                  getFromCtorType(GD.getCtorType()));
679    else if (isa<CXXDestructorDecl>(GD.getDecl()))
680      return getAddrOfCXXStructor(cast<CXXDestructorDecl>(GD.getDecl()),
681                                  getFromDtorType(GD.getDtorType()));
682    else if (isa<FunctionDecl>(GD.getDecl()))
683      return GetAddrOfFunction(GD);
684    else
685      return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
686  }
687
688  /// Will return a global variable of the given type. If a variable with a
689  /// different type already exists then a new  variable with the right type
690  /// will be created and all uses of the old variable will be replaced with a
691  /// bitcast to the new variable.
692  llvm::GlobalVariable *
693  CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
694                                    llvm::GlobalValue::LinkageTypes Linkage);
695
696  llvm::Function *
697  CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
698                                     SourceLocation Loc = SourceLocation(),
699                                     bool TLS = false);
700
701  /// Return the address space of the underlying global variable for D, as
702  /// determined by its declaration. Normally this is the same as the address
703  /// space of D's type, but in CUDA, address spaces are associated with
704  /// declarations, not types.
705  unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
706
707  /// Return the llvm::Constant for the address of the given global variable.
708  /// If Ty is non-null and if the global doesn't exist, then it will be greated
709  /// with the specified type instead of whatever the normal requested type
710  /// would be.
711  llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
712                                     llvm::Type *Ty = nullptr);
713
714  /// Return the address of the given function. If Ty is non-null, then this
715  /// function will use the specified type if it has to create it.
716  llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0,
717                                    bool ForVTable = false,
718                                    bool DontDefer = false);
719
720  /// Get the address of the RTTI descriptor for the given type.
721  llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
722
723  llvm::Constant *getAddrOfCXXCatchHandlerType(QualType Ty,
724                                               QualType CatchHandlerType);
725
726  /// Get the address of a uuid descriptor .
727  llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
728
729  /// Get the address of the thunk for the given global decl.
730  llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
731
732  /// Get a reference to the target of VD.
733  llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
734
735  /// Returns the offset from a derived class to  a class. Returns null if the
736  /// offset is 0.
737  llvm::Constant *
738  GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
739                               CastExpr::path_const_iterator PathBegin,
740                               CastExpr::path_const_iterator PathEnd);
741
742  /// A pair of helper functions for a __block variable.
743  class ByrefHelpers : public llvm::FoldingSetNode {
744  public:
745    llvm::Constant *CopyHelper;
746    llvm::Constant *DisposeHelper;
747
748    /// The alignment of the field.  This is important because
749    /// different offsets to the field within the byref struct need to
750    /// have different helper functions.
751    CharUnits Alignment;
752
753    ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
754    virtual ~ByrefHelpers();
755
756    void Profile(llvm::FoldingSetNodeID &id) const {
757      id.AddInteger(Alignment.getQuantity());
758      profileImpl(id);
759    }
760    virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
761
762    virtual bool needsCopy() const { return true; }
763    virtual void emitCopy(CodeGenFunction &CGF,
764                          llvm::Value *dest, llvm::Value *src) = 0;
765
766    virtual bool needsDispose() const { return true; }
767    virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
768  };
769
770  llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
771
772  /// Fetches the global unique block count.
773  int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
774
775  /// Fetches the type of a generic block descriptor.
776  llvm::Type *getBlockDescriptorType();
777
778  /// The type of a generic block literal.
779  llvm::Type *getGenericBlockLiteralType();
780
781  /// Gets the address of a block which requires no captures.
782  llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
783
784  /// Return a pointer to a constant CFString object for the given string.
785  llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
786
787  /// Return a pointer to a constant NSString object for the given string. Or a
788  /// user defined String object as defined via
789  /// -fconstant-string-class=class_name option.
790  llvm::GlobalVariable *GetAddrOfConstantString(const StringLiteral *Literal);
791
792  /// Return a constant array for the given string.
793  llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
794
795  /// Return a pointer to a constant array for the given string literal.
796  llvm::GlobalVariable *
797  GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
798                                     StringRef Name = ".str");
799
800  /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
801  llvm::GlobalVariable *
802  GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
803
804  /// Returns a pointer to a character array containing the literal and a
805  /// terminating '\0' character. The result has pointer to array type.
806  ///
807  /// \param GlobalName If provided, the name to use for the global (if one is
808  /// created).
809  llvm::GlobalVariable *
810  GetAddrOfConstantCString(const std::string &Str,
811                           const char *GlobalName = nullptr,
812                           unsigned Alignment = 0);
813
814  /// Returns a pointer to a constant global variable for the given file-scope
815  /// compound literal expression.
816  llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
817
818  /// \brief Returns a pointer to a global variable representing a temporary
819  /// with static or thread storage duration.
820  llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
821                                           const Expr *Inner);
822
823  /// \brief Retrieve the record type that describes the state of an
824  /// Objective-C fast enumeration loop (for..in).
825  QualType getObjCFastEnumerationStateType();
826
827  // Produce code for this constructor/destructor. This method doesn't try
828  // to apply any ABI rules about which other constructors/destructors
829  // are needed or if they are alias to each other.
830  llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
831                                     StructorType Type);
832
833  /// Return the address of the constructor/destructor of the given type.
834  llvm::GlobalValue *
835  getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
836                       const CGFunctionInfo *FnInfo = nullptr,
837                       llvm::FunctionType *FnType = nullptr,
838                       bool DontDefer = false);
839
840  /// Given a builtin id for a function like "__builtin_fabsf", return a
841  /// Function* for "fabsf".
842  llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
843                                     unsigned BuiltinID);
844
845  llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
846
847  /// Emit code for a single top level declaration.
848  void EmitTopLevelDecl(Decl *D);
849
850  /// \brief Stored a deferred empty coverage mapping for an unused
851  /// and thus uninstrumented top level declaration.
852  void AddDeferredUnusedCoverageMapping(Decl *D);
853
854  /// \brief Remove the deferred empty coverage mapping as this
855  /// declaration is actually instrumented.
856  void ClearUnusedCoverageMapping(const Decl *D);
857
858  /// \brief Emit all the deferred coverage mappings
859  /// for the uninstrumented functions.
860  void EmitDeferredUnusedCoverageMappings();
861
862  /// Tell the consumer that this variable has been instantiated.
863  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
864
865  /// \brief If the declaration has internal linkage but is inside an
866  /// extern "C" linkage specification, prepare to emit an alias for it
867  /// to the expected name.
868  template<typename SomeDecl>
869  void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
870
871  /// Add a global to a list to be added to the llvm.used metadata.
872  void addUsedGlobal(llvm::GlobalValue *GV);
873
874  /// Add a global to a list to be added to the llvm.compiler.used metadata.
875  void addCompilerUsedGlobal(llvm::GlobalValue *GV);
876
877  /// Add a destructor and object to add to the C++ global destructor function.
878  void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
879    CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
880  }
881
882  /// Create a new runtime function with the specified type and name.
883  llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
884                                        StringRef Name,
885                                        llvm::AttributeSet ExtraAttrs =
886                                          llvm::AttributeSet());
887  /// Create a new compiler builtin function with the specified type and name.
888  llvm::Constant *CreateBuiltinFunction(llvm::FunctionType *Ty,
889                                        StringRef Name,
890                                        llvm::AttributeSet ExtraAttrs =
891                                          llvm::AttributeSet());
892  /// Create a new runtime global variable with the specified type and name.
893  llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
894                                        StringRef Name);
895
896  ///@name Custom Blocks Runtime Interfaces
897  ///@{
898
899  llvm::Constant *getNSConcreteGlobalBlock();
900  llvm::Constant *getNSConcreteStackBlock();
901  llvm::Constant *getBlockObjectAssign();
902  llvm::Constant *getBlockObjectDispose();
903
904  ///@}
905
906  llvm::Constant *getLLVMLifetimeStartFn();
907  llvm::Constant *getLLVMLifetimeEndFn();
908
909  // Make sure that this type is translated.
910  void UpdateCompletedType(const TagDecl *TD);
911
912  llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
913
914  /// Try to emit the initializer for the given declaration as a constant;
915  /// returns 0 if the expression cannot be emitted as a constant.
916  llvm::Constant *EmitConstantInit(const VarDecl &D,
917                                   CodeGenFunction *CGF = nullptr);
918
919  /// Try to emit the given expression as a constant; returns 0 if the
920  /// expression cannot be emitted as a constant.
921  llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
922                                   CodeGenFunction *CGF = nullptr);
923
924  /// Emit the given constant value as a constant, in the type's scalar
925  /// representation.
926  llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
927                                    CodeGenFunction *CGF = nullptr);
928
929  /// Emit the given constant value as a constant, in the type's memory
930  /// representation.
931  llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
932                                             QualType DestType,
933                                             CodeGenFunction *CGF = nullptr);
934
935  /// Return the result of value-initializing the given type, i.e. a null
936  /// expression of the given type.  This is usually, but not always, an LLVM
937  /// null constant.
938  llvm::Constant *EmitNullConstant(QualType T);
939
940  /// Return a null constant appropriate for zero-initializing a base class with
941  /// the given type. This is usually, but not always, an LLVM null constant.
942  llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
943
944  /// Emit a general error that something can't be done.
945  void Error(SourceLocation loc, StringRef error);
946
947  /// Print out an error that codegen doesn't support the specified stmt yet.
948  void ErrorUnsupported(const Stmt *S, const char *Type);
949
950  /// Print out an error that codegen doesn't support the specified decl yet.
951  void ErrorUnsupported(const Decl *D, const char *Type);
952
953  /// Set the attributes on the LLVM function for the given decl and function
954  /// info. This applies attributes necessary for handling the ABI as well as
955  /// user specified attributes like section.
956  void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
957                                     const CGFunctionInfo &FI);
958
959  /// Set the LLVM function attributes (sext, zext, etc).
960  void SetLLVMFunctionAttributes(const Decl *D,
961                                 const CGFunctionInfo &Info,
962                                 llvm::Function *F);
963
964  /// Set the LLVM function attributes which only apply to a function
965  /// definition.
966  void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
967
968  /// Return true iff the given type uses 'sret' when used as a return type.
969  bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
970
971  /// Return true iff the given type uses an argument slot when 'sret' is used
972  /// as a return type.
973  bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
974
975  /// Return true iff the given type uses 'fpret' when used as a return type.
976  bool ReturnTypeUsesFPRet(QualType ResultType);
977
978  /// Return true iff the given type uses 'fp2ret' when used as a return type.
979  bool ReturnTypeUsesFP2Ret(QualType ResultType);
980
981  /// Get the LLVM attributes and calling convention to use for a particular
982  /// function type.
983  ///
984  /// \param Info - The function type information.
985  /// \param TargetDecl - The decl these attributes are being constructed
986  /// for. If supplied the attributes applied to this decl may contribute to the
987  /// function attributes and calling convention.
988  /// \param PAL [out] - On return, the attribute list to use.
989  /// \param CallingConv [out] - On return, the LLVM calling convention to use.
990  void ConstructAttributeList(const CGFunctionInfo &Info,
991                              const Decl *TargetDecl,
992                              AttributeListType &PAL,
993                              unsigned &CallingConv,
994                              bool AttrOnCallSite);
995
996  StringRef getMangledName(GlobalDecl GD);
997  StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
998
999  void EmitTentativeDefinition(const VarDecl *D);
1000
1001  void EmitVTable(CXXRecordDecl *Class);
1002
1003  /// Emit the RTTI descriptors for the builtin types.
1004  void EmitFundamentalRTTIDescriptors();
1005
1006  /// \brief Appends Opts to the "Linker Options" metadata value.
1007  void AppendLinkerOptions(StringRef Opts);
1008
1009  /// \brief Appends a detect mismatch command to the linker options.
1010  void AddDetectMismatch(StringRef Name, StringRef Value);
1011
1012  /// \brief Appends a dependent lib to the "Linker Options" metadata value.
1013  void AddDependentLib(StringRef Lib);
1014
1015  llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1016
1017  void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1018    F->setLinkage(getFunctionLinkage(GD));
1019  }
1020
1021  /// Return the appropriate linkage for the vtable, VTT, and type information
1022  /// of the given class.
1023  llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1024
1025  /// Return the store size, in character units, of the given LLVM type.
1026  CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1027
1028  /// Returns LLVM linkage for a declarator.
1029  llvm::GlobalValue::LinkageTypes
1030  getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
1031                              bool IsConstantVariable);
1032
1033  /// Returns LLVM linkage for a declarator.
1034  llvm::GlobalValue::LinkageTypes
1035  getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1036
1037  /// Emit all the global annotations.
1038  void EmitGlobalAnnotations();
1039
1040  /// Emit an annotation string.
1041  llvm::Constant *EmitAnnotationString(StringRef Str);
1042
1043  /// Emit the annotation's translation unit.
1044  llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1045
1046  /// Emit the annotation line number.
1047  llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1048
1049  /// Generate the llvm::ConstantStruct which contains the annotation
1050  /// information for a given GlobalValue. The annotation struct is
1051  /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1052  /// GlobalValue being annotated. The second field is the constant string
1053  /// created from the AnnotateAttr's annotation. The third field is a constant
1054  /// string containing the name of the translation unit. The fourth field is
1055  /// the line number in the file of the annotated value declaration.
1056  llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1057                                   const AnnotateAttr *AA,
1058                                   SourceLocation L);
1059
1060  /// Add global annotations that are set on D, for the global GV. Those
1061  /// annotations are emitted during finalization of the LLVM code.
1062  void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1063
1064  bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
1065
1066  bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1067                              QualType Ty,
1068                              StringRef Category = StringRef()) const;
1069
1070  SanitizerMetadata *getSanitizerMetadata() {
1071    return SanitizerMD.get();
1072  }
1073
1074  void addDeferredVTable(const CXXRecordDecl *RD) {
1075    DeferredVTables.push_back(RD);
1076  }
1077
1078  /// Emit code for a singal global function or var decl. Forward declarations
1079  /// are emitted lazily.
1080  void EmitGlobal(GlobalDecl D);
1081
1082  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1083                                bool InEveryTU);
1084  bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1085
1086  /// Set attributes for a global definition.
1087  void setFunctionDefinitionAttributes(const FunctionDecl *D,
1088                                       llvm::Function *F);
1089
1090  llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1091
1092  /// Set attributes which are common to any form of a global definition (alias,
1093  /// Objective-C method, function, global variable).
1094  ///
1095  /// NOTE: This should only be called for definitions.
1096  void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1097
1098  /// Set attributes which must be preserved by an alias. This includes common
1099  /// attributes (i.e. it includes a call to SetCommonAttributes).
1100  ///
1101  /// NOTE: This should only be called for definitions.
1102  void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1103
1104  void addReplacement(StringRef Name, llvm::Constant *C);
1105
1106  /// \brief Emit a code for threadprivate directive.
1107  /// \param D Threadprivate declaration.
1108  void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
1109
1110  /// Emit bit set entries for the given vtable using the given layout if
1111  /// vptr CFI is enabled.
1112  void EmitVTableBitSetEntries(llvm::GlobalVariable *VTable,
1113                               const VTableLayout &VTLayout);
1114
1115  /// \breif Get the declaration of std::terminate for the platform.
1116  llvm::Constant *getTerminateFn();
1117
1118private:
1119  llvm::Constant *
1120  GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
1121                          bool ForVTable, bool DontDefer = false,
1122                          bool IsThunk = false,
1123                          llvm::AttributeSet ExtraAttrs = llvm::AttributeSet());
1124
1125  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
1126                                        llvm::PointerType *PTy,
1127                                        const VarDecl *D);
1128
1129  void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
1130
1131  /// Set function attributes for a function declaration.
1132  void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1133                             bool IsIncompleteFunction, bool IsThunk);
1134
1135  void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1136
1137  void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1138  void EmitGlobalVarDefinition(const VarDecl *D);
1139  void EmitAliasDefinition(GlobalDecl GD);
1140  void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1141  void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1142
1143  // C++ related functions.
1144
1145  void EmitNamespace(const NamespaceDecl *D);
1146  void EmitLinkageSpec(const LinkageSpecDecl *D);
1147  void CompleteDIClassType(const CXXMethodDecl* D);
1148
1149  /// \brief Emit the function that initializes C++ thread_local variables.
1150  void EmitCXXThreadLocalInitFunc();
1151
1152  /// Emit the function that initializes C++ globals.
1153  void EmitCXXGlobalInitFunc();
1154
1155  /// Emit the function that destroys C++ globals.
1156  void EmitCXXGlobalDtorFunc();
1157
1158  /// Emit the function that initializes the specified global (if PerformInit is
1159  /// true) and registers its destructor.
1160  void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1161                                    llvm::GlobalVariable *Addr,
1162                                    bool PerformInit);
1163
1164  void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1165                             llvm::Function *InitFunc, InitSegAttr *ISA);
1166
1167  // FIXME: Hardcoding priority here is gross.
1168  void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1169                     llvm::Constant *AssociatedData = 0);
1170  void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
1171
1172  /// Generates a global array of functions and priorities using the given list
1173  /// and name. This array will have appending linkage and is suitable for use
1174  /// as a LLVM constructor or destructor array.
1175  void EmitCtorList(const CtorList &Fns, const char *GlobalName);
1176
1177  /// Emit the RTTI descriptors for the given type.
1178  void EmitFundamentalRTTIDescriptor(QualType Type);
1179
1180  /// Emit any needed decls for which code generation was deferred.
1181  void EmitDeferred();
1182
1183  /// Call replaceAllUsesWith on all pairs in Replacements.
1184  void applyReplacements();
1185
1186  void checkAliases();
1187
1188  /// Emit any vtables which we deferred and still have a use for.
1189  void EmitDeferredVTables();
1190
1191  /// Emit the llvm.used and llvm.compiler.used metadata.
1192  void emitLLVMUsed();
1193
1194  /// \brief Emit the link options introduced by imported modules.
1195  void EmitModuleLinkOptions();
1196
1197  /// \brief Emit aliases for internal-linkage declarations inside "C" language
1198  /// linkage specifications, giving them the "expected" name where possible.
1199  void EmitStaticExternCAliases();
1200
1201  void EmitDeclMetadata();
1202
1203  /// \brief Emit the Clang version as llvm.ident metadata.
1204  void EmitVersionIdentMetadata();
1205
1206  /// Emits target specific Metadata for global declarations.
1207  void EmitTargetMetadata();
1208
1209  /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1210  /// .gcda files in a way that persists in .bc files.
1211  void EmitCoverageFile();
1212
1213  /// Emits the initializer for a uuidof string.
1214  llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
1215
1216  /// Determine whether the definition must be emitted; if this returns \c
1217  /// false, the definition can be emitted lazily if it's used.
1218  bool MustBeEmitted(const ValueDecl *D);
1219
1220  /// Determine whether the definition can be emitted eagerly, or should be
1221  /// delayed until the end of the translation unit. This is relevant for
1222  /// definitions whose linkage can change, e.g. implicit function instantions
1223  /// which may later be explicitly instantiated.
1224  bool MayBeEmittedEagerly(const ValueDecl *D);
1225
1226  /// Check whether we can use a "simpler", more core exceptions personality
1227  /// function.
1228  void SimplifyPersonality();
1229};
1230}  // end namespace CodeGen
1231}  // end namespace clang
1232
1233#endif
1234