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