]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/CodeGen/CodeGenModule.h
Merge ^/head r279163 through r279308.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / CodeGen / CodeGenModule.h
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
37 namespace llvm {
38 class Module;
39 class Constant;
40 class ConstantInt;
41 class Function;
42 class GlobalValue;
43 class DataLayout;
44 class FunctionType;
45 class LLVMContext;
46 class IndexedInstrProfReader;
47 }
48
49 namespace clang {
50 class TargetCodeGenInfo;
51 class ASTContext;
52 class AtomicType;
53 class FunctionDecl;
54 class IdentifierInfo;
55 class ObjCMethodDecl;
56 class ObjCImplementationDecl;
57 class ObjCCategoryImplDecl;
58 class ObjCProtocolDecl;
59 class ObjCEncodeExpr;
60 class BlockExpr;
61 class CharUnits;
62 class Decl;
63 class Expr;
64 class Stmt;
65 class InitListExpr;
66 class StringLiteral;
67 class NamedDecl;
68 class ValueDecl;
69 class VarDecl;
70 class LangOptions;
71 class CodeGenOptions;
72 class DiagnosticsEngine;
73 class AnnotateAttr;
74 class CXXDestructorDecl;
75 class Module;
76 class CoverageSourceInfo;
77
78 namespace CodeGen {
79
80 class CallArgList;
81 class CodeGenFunction;
82 class CodeGenTBAA;
83 class CGCXXABI;
84 class CGDebugInfo;
85 class CGObjCRuntime;
86 class CGOpenCLRuntime;
87 class CGOpenMPRuntime;
88 class CGCUDARuntime;
89 class BlockFieldFlags;
90 class FunctionArgList;
91 class CoverageMappingModuleGen;
92
93 struct 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
109 struct 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
157 struct 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
166 struct 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.
226 class InstrProfStats {
227   uint32_t VisitedInMainFile;
228   uint32_t MissingInMainFile;
229   uint32_t Visited;
230   uint32_t Missing;
231   uint32_t Mismatched;
232
233 public:
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.
260 class CodeGenModule : public CodeGenTypeCache {
261   CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION;
262   void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION;
263
264 public:
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
278 private:
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::Constant*> 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.
404   llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
405   
406   typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
407
408   struct GlobalInitPriorityCmp {
409     bool operator()(const GlobalInitData &LHS,
410                     const GlobalInitData &RHS) const {
411       return LHS.first.priority < RHS.first.priority;
412     }
413   };
414
415   /// Global variables with initializers whose order of initialization is set by
416   /// init_priority attribute.
417   SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
418
419   /// Global destructor functions and arguments that need to run on termination.
420   std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
421
422   /// \brief The complete set of modules that has been imported.
423   llvm::SetVector<clang::Module *> ImportedModules;
424
425   /// \brief A vector of metadata strings.
426   SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
427
428   /// @name Cache for Objective-C runtime types
429   /// @{
430
431   /// Cached reference to the class for constant strings. This value has type
432   /// int * but is actually an Obj-C class pointer.
433   llvm::WeakVH CFConstantStringClassRef;
434
435   /// Cached reference to the class for constant strings. This value has type
436   /// int * but is actually an Obj-C class pointer.
437   llvm::WeakVH ConstantStringClassRef;
438
439   /// \brief The LLVM type corresponding to NSConstantString.
440   llvm::StructType *NSConstantStringType;
441   
442   /// \brief The type used to describe the state of a fast enumeration in
443   /// Objective-C's for..in loop.
444   QualType ObjCFastEnumerationStateType;
445   
446   /// @}
447
448   /// Lazily create the Objective-C runtime
449   void createObjCRuntime();
450
451   void createOpenCLRuntime();
452   void createOpenMPRuntime();
453   void createCUDARuntime();
454
455   bool isTriviallyRecursive(const FunctionDecl *F);
456   bool shouldEmitFunction(GlobalDecl GD);
457
458   /// @name Cache for Blocks Runtime Globals
459   /// @{
460
461   llvm::Constant *NSConcreteGlobalBlock;
462   llvm::Constant *NSConcreteStackBlock;
463
464   llvm::Constant *BlockObjectAssign;
465   llvm::Constant *BlockObjectDispose;
466
467   llvm::Type *BlockDescriptorType;
468   llvm::Type *GenericBlockLiteralType;
469
470   struct {
471     int GlobalUniqueCount;
472   } Block;
473
474   /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
475   llvm::Constant *LifetimeStartFn;
476
477   /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
478   llvm::Constant *LifetimeEndFn;
479
480   GlobalDecl initializedGlobalDecl;
481
482   std::unique_ptr<SanitizerMetadata> SanitizerMD;
483
484   /// @}
485
486   llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
487
488   std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
489 public:
490   CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
491                 llvm::Module &M, const llvm::DataLayout &TD,
492                 DiagnosticsEngine &Diags,
493                 CoverageSourceInfo *CoverageInfo = nullptr);
494
495   ~CodeGenModule();
496
497   void clear();
498
499   /// Finalize LLVM code generation.
500   void Release();
501
502   /// Return a reference to the configured Objective-C runtime.
503   CGObjCRuntime &getObjCRuntime() {
504     if (!ObjCRuntime) createObjCRuntime();
505     return *ObjCRuntime;
506   }
507
508   /// Return true iff an Objective-C runtime has been configured.
509   bool hasObjCRuntime() { return !!ObjCRuntime; }
510
511   /// Return a reference to the configured OpenCL runtime.
512   CGOpenCLRuntime &getOpenCLRuntime() {
513     assert(OpenCLRuntime != nullptr);
514     return *OpenCLRuntime;
515   }
516
517   /// Return a reference to the configured OpenMP runtime.
518   CGOpenMPRuntime &getOpenMPRuntime() {
519     assert(OpenMPRuntime != nullptr);
520     return *OpenMPRuntime;
521   }
522
523   /// Return a reference to the configured CUDA runtime.
524   CGCUDARuntime &getCUDARuntime() {
525     assert(CUDARuntime != nullptr);
526     return *CUDARuntime;
527   }
528
529   ARCEntrypoints &getARCEntrypoints() const {
530     assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr);
531     return *ARCData;
532   }
533
534   RREntrypoints &getRREntrypoints() const {
535     assert(RRData != nullptr);
536     return *RRData;
537   }
538
539   InstrProfStats &getPGOStats() { return PGOStats; }
540   llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
541
542   CoverageMappingModuleGen *getCoverageMapping() const {
543     return CoverageMapping.get();
544   }
545
546   llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
547     return StaticLocalDeclMap[D];
548   }
549   void setStaticLocalDeclAddress(const VarDecl *D, 
550                                  llvm::Constant *C) {
551     StaticLocalDeclMap[D] = C;
552   }
553
554   llvm::Constant *
555   getOrCreateStaticVarDecl(const VarDecl &D,
556                            llvm::GlobalValue::LinkageTypes Linkage);
557
558   llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
559     return StaticLocalDeclGuardMap[D];
560   }
561   void setStaticLocalDeclGuardAddress(const VarDecl *D, 
562                                       llvm::GlobalVariable *C) {
563     StaticLocalDeclGuardMap[D] = C;
564   }
565
566   bool lookupRepresentativeDecl(StringRef MangledName,
567                                 GlobalDecl &Result) const;
568
569   llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
570     return AtomicSetterHelperFnMap[Ty];
571   }
572   void setAtomicSetterHelperFnMap(QualType Ty,
573                             llvm::Constant *Fn) {
574     AtomicSetterHelperFnMap[Ty] = Fn;
575   }
576
577   llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
578     return AtomicGetterHelperFnMap[Ty];
579   }
580   void setAtomicGetterHelperFnMap(QualType Ty,
581                             llvm::Constant *Fn) {
582     AtomicGetterHelperFnMap[Ty] = Fn;
583   }
584
585   llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
586     return TypeDescriptorMap[Ty];
587   }
588   void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
589     TypeDescriptorMap[Ty] = C;
590   }
591
592   CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
593
594   llvm::MDNode *getNoObjCARCExceptionsMetadata() {
595     if (!NoObjCARCExceptionsMetadata)
596       NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
597     return NoObjCARCExceptionsMetadata;
598   }
599
600   ASTContext &getContext() const { return Context; }
601   const LangOptions &getLangOpts() const { return LangOpts; }
602   const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
603   llvm::Module &getModule() const { return TheModule; }
604   DiagnosticsEngine &getDiags() const { return Diags; }
605   const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
606   const TargetInfo &getTarget() const { return Target; }
607   const llvm::Triple &getTriple() const;
608   bool supportsCOMDAT() const;
609
610   CGCXXABI &getCXXABI() const { return *ABI; }
611   llvm::LLVMContext &getLLVMContext() { return VMContext; }
612
613   bool shouldUseTBAA() const { return TBAA != nullptr; }
614
615   const TargetCodeGenInfo &getTargetCodeGenInfo(); 
616   
617   CodeGenTypes &getTypes() { return Types; }
618  
619   CodeGenVTables &getVTables() { return VTables; }
620
621   ItaniumVTableContext &getItaniumVTableContext() {
622     return VTables.getItaniumVTableContext();
623   }
624
625   MicrosoftVTableContext &getMicrosoftVTableContext() {
626     return VTables.getMicrosoftVTableContext();
627   }
628
629   CtorList &getGlobalCtors() { return GlobalCtors; }
630   CtorList &getGlobalDtors() { return GlobalDtors; }
631
632   llvm::MDNode *getTBAAInfo(QualType QTy);
633   llvm::MDNode *getTBAAInfoForVTablePtr();
634   llvm::MDNode *getTBAAStructInfo(QualType QTy);
635   /// Return the MDNode in the type DAG for the given struct type.
636   llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
637   /// Return the path-aware tag for given base type, access node and offset.
638   llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
639                                      uint64_t O);
640
641   bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
642
643   bool isPaddedAtomicType(QualType type);
644   bool isPaddedAtomicType(const AtomicType *type);
645
646   /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
647   /// is the same as the type. For struct-path aware TBAA, the tag
648   /// is different from the type: base type, access type and offset.
649   /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
650   void DecorateInstruction(llvm::Instruction *Inst,
651                            llvm::MDNode *TBAAInfo,
652                            bool ConvertTypeToTag = true);
653
654   /// Emit the given number of characters as a value of type size_t.
655   llvm::ConstantInt *getSize(CharUnits numChars);
656
657   /// Set the visibility for the given LLVM GlobalValue.
658   void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
659
660   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
661   /// variable declaration D.
662   void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
663
664   static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
665     switch (V) {
666     case DefaultVisibility:   return llvm::GlobalValue::DefaultVisibility;
667     case HiddenVisibility:    return llvm::GlobalValue::HiddenVisibility;
668     case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
669     }
670     llvm_unreachable("unknown visibility!");
671   }
672
673   llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
674     if (isa<CXXConstructorDecl>(GD.getDecl()))
675       return getAddrOfCXXStructor(cast<CXXConstructorDecl>(GD.getDecl()),
676                                   getFromCtorType(GD.getCtorType()));
677     else if (isa<CXXDestructorDecl>(GD.getDecl()))
678       return getAddrOfCXXStructor(cast<CXXDestructorDecl>(GD.getDecl()),
679                                   getFromDtorType(GD.getDtorType()));
680     else if (isa<FunctionDecl>(GD.getDecl()))
681       return GetAddrOfFunction(GD);
682     else
683       return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
684   }
685
686   /// Will return a global variable of the given type. If a variable with a
687   /// different type already exists then a new  variable with the right type
688   /// will be created and all uses of the old variable will be replaced with a
689   /// bitcast to the new variable.
690   llvm::GlobalVariable *
691   CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
692                                     llvm::GlobalValue::LinkageTypes Linkage);
693
694   llvm::Function *
695   CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
696                                      SourceLocation Loc = SourceLocation(),
697                                      bool TLS = false);
698
699   /// Return the address space of the underlying global variable for D, as
700   /// determined by its declaration. Normally this is the same as the address
701   /// space of D's type, but in CUDA, address spaces are associated with
702   /// declarations, not types.
703   unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
704
705   /// Return the llvm::Constant for the address of the given global variable.
706   /// If Ty is non-null and if the global doesn't exist, then it will be greated
707   /// with the specified type instead of whatever the normal requested type
708   /// would be.
709   llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
710                                      llvm::Type *Ty = nullptr);
711
712   /// Return the address of the given function. If Ty is non-null, then this
713   /// function will use the specified type if it has to create it.
714   llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0,
715                                     bool ForVTable = false,
716                                     bool DontDefer = false);
717
718   /// Get the address of the RTTI descriptor for the given type.
719   llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
720
721   /// Get the address of a uuid descriptor .
722   llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
723
724   /// Get the address of the thunk for the given global decl.
725   llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
726
727   /// Get a reference to the target of VD.
728   llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
729
730   /// Returns the offset from a derived class to  a class. Returns null if the
731   /// offset is 0.
732   llvm::Constant *
733   GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
734                                CastExpr::path_const_iterator PathBegin,
735                                CastExpr::path_const_iterator PathEnd);
736
737   /// A pair of helper functions for a __block variable.
738   class ByrefHelpers : public llvm::FoldingSetNode {
739   public:
740     llvm::Constant *CopyHelper;
741     llvm::Constant *DisposeHelper;
742
743     /// The alignment of the field.  This is important because
744     /// different offsets to the field within the byref struct need to
745     /// have different helper functions.
746     CharUnits Alignment;
747
748     ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
749     virtual ~ByrefHelpers();
750
751     void Profile(llvm::FoldingSetNodeID &id) const {
752       id.AddInteger(Alignment.getQuantity());
753       profileImpl(id);
754     }
755     virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
756
757     virtual bool needsCopy() const { return true; }
758     virtual void emitCopy(CodeGenFunction &CGF,
759                           llvm::Value *dest, llvm::Value *src) = 0;
760
761     virtual bool needsDispose() const { return true; }
762     virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
763   };
764
765   llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
766
767   /// Fetches the global unique block count.
768   int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
769   
770   /// Fetches the type of a generic block descriptor.
771   llvm::Type *getBlockDescriptorType();
772
773   /// The type of a generic block literal.
774   llvm::Type *getGenericBlockLiteralType();
775
776   /// Gets the address of a block which requires no captures.
777   llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
778   
779   /// Return a pointer to a constant CFString object for the given string.
780   llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
781
782   /// Return a pointer to a constant NSString object for the given string. Or a
783   /// user defined String object as defined via
784   /// -fconstant-string-class=class_name option.
785   llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
786
787   /// Return a constant array for the given string.
788   llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
789
790   /// Return a pointer to a constant array for the given string literal.
791   llvm::GlobalVariable *
792   GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
793                                      StringRef Name = ".str");
794
795   /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
796   llvm::GlobalVariable *
797   GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
798
799   /// Returns a pointer to a character array containing the literal and a
800   /// terminating '\0' character. The result has pointer to array type.
801   ///
802   /// \param GlobalName If provided, the name to use for the global (if one is
803   /// created).
804   llvm::GlobalVariable *
805   GetAddrOfConstantCString(const std::string &Str,
806                            const char *GlobalName = nullptr,
807                            unsigned Alignment = 0);
808
809   /// Returns a pointer to a constant global variable for the given file-scope
810   /// compound literal expression.
811   llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
812
813   /// \brief Returns a pointer to a global variable representing a temporary
814   /// with static or thread storage duration.
815   llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
816                                            const Expr *Inner);
817
818   /// \brief Retrieve the record type that describes the state of an
819   /// Objective-C fast enumeration loop (for..in).
820   QualType getObjCFastEnumerationStateType();
821
822   // Produce code for this constructor/destructor. This method doesn't try
823   // to apply any ABI rules about which other constructors/destructors
824   // are needed or if they are alias to each other.
825   llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
826                                      StructorType Type);
827
828   /// Return the address of the constructor/destructor of the given type.
829   llvm::GlobalValue *
830   getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
831                        const CGFunctionInfo *FnInfo = nullptr,
832                        llvm::FunctionType *FnType = nullptr,
833                        bool DontDefer = false);
834
835   /// Given a builtin id for a function like "__builtin_fabsf", return a
836   /// Function* for "fabsf".
837   llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
838                                      unsigned BuiltinID);
839
840   llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
841
842   /// Emit code for a single top level declaration.
843   void EmitTopLevelDecl(Decl *D);
844
845   /// \brief Stored a deferred empty coverage mapping for an unused
846   /// and thus uninstrumented top level declaration.
847   void AddDeferredUnusedCoverageMapping(Decl *D);
848
849   /// \brief Remove the deferred empty coverage mapping as this
850   /// declaration is actually instrumented.
851   void ClearUnusedCoverageMapping(const Decl *D);
852
853   /// \brief Emit all the deferred coverage mappings
854   /// for the uninstrumented functions.
855   void EmitDeferredUnusedCoverageMappings();
856
857   /// Tell the consumer that this variable has been instantiated.
858   void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
859
860   /// \brief If the declaration has internal linkage but is inside an
861   /// extern "C" linkage specification, prepare to emit an alias for it
862   /// to the expected name.
863   template<typename SomeDecl>
864   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
865
866   /// Add a global to a list to be added to the llvm.used metadata.
867   void addUsedGlobal(llvm::GlobalValue *GV);
868
869   /// Add a global to a list to be added to the llvm.compiler.used metadata.
870   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
871
872   /// Add a destructor and object to add to the C++ global destructor function.
873   void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
874     CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
875   }
876
877   /// Create a new runtime function with the specified type and name.
878   llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
879                                         StringRef Name,
880                                         llvm::AttributeSet ExtraAttrs =
881                                           llvm::AttributeSet());
882   /// Create a new compiler builtin function with the specified type and name.
883   llvm::Constant *CreateBuiltinFunction(llvm::FunctionType *Ty,
884                                         StringRef Name,
885                                         llvm::AttributeSet ExtraAttrs =
886                                           llvm::AttributeSet());
887   /// Create a new runtime global variable with the specified type and name.
888   llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
889                                         StringRef Name);
890
891   ///@name Custom Blocks Runtime Interfaces
892   ///@{
893
894   llvm::Constant *getNSConcreteGlobalBlock();
895   llvm::Constant *getNSConcreteStackBlock();
896   llvm::Constant *getBlockObjectAssign();
897   llvm::Constant *getBlockObjectDispose();
898
899   ///@}
900
901   llvm::Constant *getLLVMLifetimeStartFn();
902   llvm::Constant *getLLVMLifetimeEndFn();
903
904   // Make sure that this type is translated.
905   void UpdateCompletedType(const TagDecl *TD);
906
907   llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
908
909   /// Try to emit the initializer for the given declaration as a constant;
910   /// returns 0 if the expression cannot be emitted as a constant.
911   llvm::Constant *EmitConstantInit(const VarDecl &D,
912                                    CodeGenFunction *CGF = nullptr);
913
914   /// Try to emit the given expression as a constant; returns 0 if the
915   /// expression cannot be emitted as a constant.
916   llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
917                                    CodeGenFunction *CGF = nullptr);
918
919   /// Emit the given constant value as a constant, in the type's scalar
920   /// representation.
921   llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
922                                     CodeGenFunction *CGF = nullptr);
923
924   /// Emit the given constant value as a constant, in the type's memory
925   /// representation.
926   llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
927                                              QualType DestType,
928                                              CodeGenFunction *CGF = nullptr);
929
930   /// Return the result of value-initializing the given type, i.e. a null
931   /// expression of the given type.  This is usually, but not always, an LLVM
932   /// null constant.
933   llvm::Constant *EmitNullConstant(QualType T);
934
935   /// Return a null constant appropriate for zero-initializing a base class with
936   /// the given type. This is usually, but not always, an LLVM null constant.
937   llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
938
939   /// Emit a general error that something can't be done.
940   void Error(SourceLocation loc, StringRef error);
941
942   /// Print out an error that codegen doesn't support the specified stmt yet.
943   void ErrorUnsupported(const Stmt *S, const char *Type);
944
945   /// Print out an error that codegen doesn't support the specified decl yet.
946   void ErrorUnsupported(const Decl *D, const char *Type);
947
948   /// Set the attributes on the LLVM function for the given decl and function
949   /// info. This applies attributes necessary for handling the ABI as well as
950   /// user specified attributes like section.
951   void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
952                                      const CGFunctionInfo &FI);
953
954   /// Set the LLVM function attributes (sext, zext, etc).
955   void SetLLVMFunctionAttributes(const Decl *D,
956                                  const CGFunctionInfo &Info,
957                                  llvm::Function *F);
958
959   /// Set the LLVM function attributes which only apply to a function
960   /// definition.
961   void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
962
963   /// Return true iff the given type uses 'sret' when used as a return type.
964   bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
965
966   /// Return true iff the given type uses an argument slot when 'sret' is used
967   /// as a return type.
968   bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
969
970   /// Return true iff the given type uses 'fpret' when used as a return type.
971   bool ReturnTypeUsesFPRet(QualType ResultType);
972
973   /// Return true iff the given type uses 'fp2ret' when used as a return type.
974   bool ReturnTypeUsesFP2Ret(QualType ResultType);
975
976   /// Get the LLVM attributes and calling convention to use for a particular
977   /// function type.
978   ///
979   /// \param Info - The function type information.
980   /// \param TargetDecl - The decl these attributes are being constructed
981   /// for. If supplied the attributes applied to this decl may contribute to the
982   /// function attributes and calling convention.
983   /// \param PAL [out] - On return, the attribute list to use.
984   /// \param CallingConv [out] - On return, the LLVM calling convention to use.
985   void ConstructAttributeList(const CGFunctionInfo &Info,
986                               const Decl *TargetDecl,
987                               AttributeListType &PAL,
988                               unsigned &CallingConv,
989                               bool AttrOnCallSite);
990
991   StringRef getMangledName(GlobalDecl GD);
992   StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
993
994   void EmitTentativeDefinition(const VarDecl *D);
995
996   void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
997
998   /// Emit the RTTI descriptors for the builtin types.
999   void EmitFundamentalRTTIDescriptors();
1000
1001   /// \brief Appends Opts to the "Linker Options" metadata value.
1002   void AppendLinkerOptions(StringRef Opts);
1003
1004   /// \brief Appends a detect mismatch command to the linker options.
1005   void AddDetectMismatch(StringRef Name, StringRef Value);
1006
1007   /// \brief Appends a dependent lib to the "Linker Options" metadata value.
1008   void AddDependentLib(StringRef Lib);
1009
1010   llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1011
1012   void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1013     F->setLinkage(getFunctionLinkage(GD));
1014   }
1015
1016   /// Return the appropriate linkage for the vtable, VTT, and type information
1017   /// of the given class.
1018   llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1019
1020   /// Return the store size, in character units, of the given LLVM type.
1021   CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1022   
1023   /// Returns LLVM linkage for a declarator.
1024   llvm::GlobalValue::LinkageTypes
1025   getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
1026                               bool IsConstantVariable);
1027
1028   /// Returns LLVM linkage for a declarator.
1029   llvm::GlobalValue::LinkageTypes
1030   getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1031
1032   /// Emit all the global annotations.
1033   void EmitGlobalAnnotations();
1034
1035   /// Emit an annotation string.
1036   llvm::Constant *EmitAnnotationString(StringRef Str);
1037
1038   /// Emit the annotation's translation unit.
1039   llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1040
1041   /// Emit the annotation line number.
1042   llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1043
1044   /// Generate the llvm::ConstantStruct which contains the annotation
1045   /// information for a given GlobalValue. The annotation struct is
1046   /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1047   /// GlobalValue being annotated. The second field is the constant string
1048   /// created from the AnnotateAttr's annotation. The third field is a constant
1049   /// string containing the name of the translation unit. The fourth field is
1050   /// the line number in the file of the annotated value declaration.
1051   llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1052                                    const AnnotateAttr *AA,
1053                                    SourceLocation L);
1054
1055   /// Add global annotations that are set on D, for the global GV. Those
1056   /// annotations are emitted during finalization of the LLVM code.
1057   void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1058
1059   bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
1060
1061   bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1062                               QualType Ty,
1063                               StringRef Category = StringRef()) const;
1064
1065   SanitizerMetadata *getSanitizerMetadata() {
1066     return SanitizerMD.get();
1067   }
1068
1069   void addDeferredVTable(const CXXRecordDecl *RD) {
1070     DeferredVTables.push_back(RD);
1071   }
1072
1073   /// Emit code for a singal global function or var decl. Forward declarations
1074   /// are emitted lazily.
1075   void EmitGlobal(GlobalDecl D);
1076
1077   bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1078                                 bool InEveryTU);
1079   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1080
1081   /// Set attributes for a global definition.
1082   void setFunctionDefinitionAttributes(const FunctionDecl *D,
1083                                        llvm::Function *F);
1084
1085   llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1086
1087   /// Set attributes which are common to any form of a global definition (alias,
1088   /// Objective-C method, function, global variable).
1089   ///
1090   /// NOTE: This should only be called for definitions.
1091   void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1092
1093   /// Set attributes which must be preserved by an alias. This includes common
1094   /// attributes (i.e. it includes a call to SetCommonAttributes).
1095   ///
1096   /// NOTE: This should only be called for definitions.
1097   void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1098
1099   void addReplacement(StringRef Name, llvm::Constant *C);
1100
1101   /// \brief Emit a code for threadprivate directive.
1102   /// \param D Threadprivate declaration.
1103   void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
1104
1105 private:
1106   llvm::Constant *
1107   GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
1108                           bool ForVTable, bool DontDefer = false,
1109                           bool IsThunk = false,
1110                           llvm::AttributeSet ExtraAttrs = llvm::AttributeSet());
1111
1112   llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
1113                                         llvm::PointerType *PTy,
1114                                         const VarDecl *D);
1115
1116   void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
1117
1118   /// Set function attributes for a function declaration.
1119   void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1120                              bool IsIncompleteFunction, bool IsThunk);
1121
1122   void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1123
1124   void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1125   void EmitGlobalVarDefinition(const VarDecl *D);
1126   void EmitAliasDefinition(GlobalDecl GD);
1127   void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1128   void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1129   
1130   // C++ related functions.
1131
1132   void EmitNamespace(const NamespaceDecl *D);
1133   void EmitLinkageSpec(const LinkageSpecDecl *D);
1134   void CompleteDIClassType(const CXXMethodDecl* D);
1135
1136   /// \brief Emit the function that initializes C++ thread_local variables.
1137   void EmitCXXThreadLocalInitFunc();
1138
1139   /// Emit the function that initializes C++ globals.
1140   void EmitCXXGlobalInitFunc();
1141
1142   /// Emit the function that destroys C++ globals.
1143   void EmitCXXGlobalDtorFunc();
1144
1145   /// Emit the function that initializes the specified global (if PerformInit is
1146   /// true) and registers its destructor.
1147   void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1148                                     llvm::GlobalVariable *Addr,
1149                                     bool PerformInit);
1150
1151   void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1152                              llvm::Function *InitFunc, InitSegAttr *ISA);
1153
1154   // FIXME: Hardcoding priority here is gross.
1155   void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1156                      llvm::Constant *AssociatedData = 0);
1157   void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
1158
1159   /// Generates a global array of functions and priorities using the given list
1160   /// and name. This array will have appending linkage and is suitable for use
1161   /// as a LLVM constructor or destructor array.
1162   void EmitCtorList(const CtorList &Fns, const char *GlobalName);
1163
1164   /// Emit the RTTI descriptors for the given type.
1165   void EmitFundamentalRTTIDescriptor(QualType Type);
1166
1167   /// Emit any needed decls for which code generation was deferred.
1168   void EmitDeferred();
1169
1170   /// Call replaceAllUsesWith on all pairs in Replacements.
1171   void applyReplacements();
1172
1173   void checkAliases();
1174
1175   /// Emit any vtables which we deferred and still have a use for.
1176   void EmitDeferredVTables();
1177
1178   /// Emit the llvm.used and llvm.compiler.used metadata.
1179   void emitLLVMUsed();
1180
1181   /// \brief Emit the link options introduced by imported modules.
1182   void EmitModuleLinkOptions();
1183
1184   /// \brief Emit aliases for internal-linkage declarations inside "C" language
1185   /// linkage specifications, giving them the "expected" name where possible.
1186   void EmitStaticExternCAliases();
1187
1188   void EmitDeclMetadata();
1189
1190   /// \brief Emit the Clang version as llvm.ident metadata.
1191   void EmitVersionIdentMetadata();
1192
1193   /// Emits target specific Metadata for global declarations.
1194   void EmitTargetMetadata();
1195
1196   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1197   /// .gcda files in a way that persists in .bc files.
1198   void EmitCoverageFile();
1199
1200   /// Emits the initializer for a uuidof string.
1201   llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
1202
1203   /// Determine whether the definition must be emitted; if this returns \c
1204   /// false, the definition can be emitted lazily if it's used.
1205   bool MustBeEmitted(const ValueDecl *D);
1206
1207   /// Determine whether the definition can be emitted eagerly, or should be
1208   /// delayed until the end of the translation unit. This is relevant for
1209   /// definitions whose linkage can change, e.g. implicit function instantions
1210   /// which may later be explicitly instantiated.
1211   bool MayBeEmittedEagerly(const ValueDecl *D);
1212
1213   /// Check whether we can use a "simpler", more core exceptions personality
1214   /// function.
1215   void SimplifyPersonality();
1216 };
1217 }  // end namespace CodeGen
1218 }  // end namespace clang
1219
1220 #endif