1 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the internal per-translation-unit state used for llvm translation.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15 #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
17 #include "CGVTables.h"
18 #include "CodeGenTypeCache.h"
19 #include "CodeGenTypes.h"
20 #include "SanitizerMetadata.h"
21 #include "clang/AST/Attr.h"
22 #include "clang/AST/DeclCXX.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/GlobalDecl.h"
26 #include "clang/AST/Mangle.h"
27 #include "clang/Basic/ABI.h"
28 #include "clang/Basic/LangOptions.h"
29 #include "clang/Basic/Module.h"
30 #include "clang/Basic/SanitizerBlacklist.h"
31 #include "llvm/ADT/DenseMap.h"
32 #include "llvm/ADT/SetVector.h"
33 #include "llvm/ADT/SmallPtrSet.h"
34 #include "llvm/ADT/StringMap.h"
35 #include "llvm/IR/Module.h"
36 #include "llvm/IR/ValueHandle.h"
37 #include "llvm/Transforms/Utils/SanitizerStats.h"
48 class IndexedInstrProfReader;
57 class ObjCImplementationDecl;
58 class ObjCCategoryImplDecl;
59 class ObjCProtocolDecl;
73 class HeaderSearchOptions;
74 class PreprocessorOptions;
75 class DiagnosticsEngine;
77 class CXXDestructorDecl;
79 class CoverageSourceInfo;
84 class CodeGenFunction;
89 class CGOpenCLRuntime;
90 class CGOpenMPRuntime;
92 class BlockFieldFlags;
93 class FunctionArgList;
94 class CoverageMappingModuleGen;
95 class TargetCodeGenInfo;
97 enum ForDefinition_t : bool {
98 NotForDefinition = false,
102 struct OrderGlobalInits {
103 unsigned int priority;
104 unsigned int lex_order;
105 OrderGlobalInits(unsigned int p, unsigned int l)
106 : priority(p), lex_order(l) {}
108 bool operator==(const OrderGlobalInits &RHS) const {
109 return priority == RHS.priority && lex_order == RHS.lex_order;
112 bool operator<(const OrderGlobalInits &RHS) const {
113 return std::tie(priority, lex_order) <
114 std::tie(RHS.priority, RHS.lex_order);
118 struct ObjCEntrypoints {
119 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
121 /// void objc_autoreleasePoolPop(void*);
122 llvm::Constant *objc_autoreleasePoolPop;
124 /// void *objc_autoreleasePoolPush(void);
125 llvm::Constant *objc_autoreleasePoolPush;
127 /// id objc_autorelease(id);
128 llvm::Constant *objc_autorelease;
130 /// id objc_autoreleaseReturnValue(id);
131 llvm::Constant *objc_autoreleaseReturnValue;
133 /// void objc_copyWeak(id *dest, id *src);
134 llvm::Constant *objc_copyWeak;
136 /// void objc_destroyWeak(id*);
137 llvm::Constant *objc_destroyWeak;
139 /// id objc_initWeak(id*, id);
140 llvm::Constant *objc_initWeak;
142 /// id objc_loadWeak(id*);
143 llvm::Constant *objc_loadWeak;
145 /// id objc_loadWeakRetained(id*);
146 llvm::Constant *objc_loadWeakRetained;
148 /// void objc_moveWeak(id *dest, id *src);
149 llvm::Constant *objc_moveWeak;
151 /// id objc_retain(id);
152 llvm::Constant *objc_retain;
154 /// id objc_retainAutorelease(id);
155 llvm::Constant *objc_retainAutorelease;
157 /// id objc_retainAutoreleaseReturnValue(id);
158 llvm::Constant *objc_retainAutoreleaseReturnValue;
160 /// id objc_retainAutoreleasedReturnValue(id);
161 llvm::Constant *objc_retainAutoreleasedReturnValue;
163 /// id objc_retainBlock(id);
164 llvm::Constant *objc_retainBlock;
166 /// void objc_release(id);
167 llvm::Constant *objc_release;
169 /// void objc_storeStrong(id*, id);
170 llvm::Constant *objc_storeStrong;
172 /// id objc_storeWeak(id*, id);
173 llvm::Constant *objc_storeWeak;
175 /// id objc_unsafeClaimAutoreleasedReturnValue(id);
176 llvm::Constant *objc_unsafeClaimAutoreleasedReturnValue;
178 /// A void(void) inline asm to use to mark that the return value of
179 /// a call will be immediately retain.
180 llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
182 /// void clang.arc.use(...);
183 llvm::Constant *clang_arc_use;
186 /// This class records statistics on instrumentation based profiling.
187 class InstrProfStats {
188 uint32_t VisitedInMainFile;
189 uint32_t MissingInMainFile;
196 : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
198 /// Record that we've visited a function and whether or not that function was
199 /// in the main source file.
200 void addVisited(bool MainFile) {
205 /// Record that a function we've visited has no profile data.
206 void addMissing(bool MainFile) {
211 /// Record that a function we've visited has mismatched profile data.
212 void addMismatched(bool MainFile) { ++Mismatched; }
213 /// Whether or not the stats we've gathered indicate any potential problems.
214 bool hasDiagnostics() { return Missing || Mismatched; }
215 /// Report potential problems we've found to \c Diags.
216 void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
219 /// A pair of helper functions for a __block variable.
220 class BlockByrefHelpers : public llvm::FoldingSetNode {
221 // MSVC requires this type to be complete in order to process this
224 llvm::Constant *CopyHelper;
225 llvm::Constant *DisposeHelper;
227 /// The alignment of the field. This is important because
228 /// different offsets to the field within the byref struct need to
229 /// have different helper functions.
232 BlockByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
233 BlockByrefHelpers(const BlockByrefHelpers &) = default;
234 virtual ~BlockByrefHelpers();
236 void Profile(llvm::FoldingSetNodeID &id) const {
237 id.AddInteger(Alignment.getQuantity());
240 virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
242 virtual bool needsCopy() const { return true; }
243 virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
245 virtual bool needsDispose() const { return true; }
246 virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
249 /// This class organizes the cross-function state that is used while generating
251 class CodeGenModule : public CodeGenTypeCache {
252 CodeGenModule(const CodeGenModule &) = delete;
253 void operator=(const CodeGenModule &) = delete;
257 Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
258 Structor(int Priority, llvm::Constant *Initializer,
259 llvm::Constant *AssociatedData)
260 : Priority(Priority), Initializer(Initializer),
261 AssociatedData(AssociatedData) {}
263 llvm::Constant *Initializer;
264 llvm::Constant *AssociatedData;
267 typedef std::vector<Structor> CtorList;
271 const LangOptions &LangOpts;
272 const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
273 const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
274 const CodeGenOptions &CodeGenOpts;
275 llvm::Module &TheModule;
276 DiagnosticsEngine &Diags;
277 const TargetInfo &Target;
278 std::unique_ptr<CGCXXABI> ABI;
279 llvm::LLVMContext &VMContext;
281 std::unique_ptr<CodeGenTBAA> TBAA;
283 mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
285 // This should not be moved earlier, since its initialization depends on some
286 // of the previous reference members being already initialized and also checks
287 // if TheTargetCodeGenInfo is NULL
290 /// Holds information about C++ vtables.
291 CodeGenVTables VTables;
293 std::unique_ptr<CGObjCRuntime> ObjCRuntime;
294 std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
295 std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
296 std::unique_ptr<CGCUDARuntime> CUDARuntime;
297 std::unique_ptr<CGDebugInfo> DebugInfo;
298 std::unique_ptr<ObjCEntrypoints> ObjCData;
299 llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
300 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
301 InstrProfStats PGOStats;
302 std::unique_ptr<llvm::SanitizerStatReport> SanStats;
304 // A set of references that have only been seen via a weakref so far. This is
305 // used to remove the weak of the reference if we ever see a direct reference
307 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
309 /// This contains all the decls which have definitions but/ which are deferred
310 /// for emission and therefore should only be output if they are actually
311 /// used. If a decl is in this, then it is known to have not been referenced
313 std::map<StringRef, GlobalDecl> DeferredDecls;
315 /// This is a list of deferred decls which we have seen that *are* actually
316 /// referenced. These get code generated when the module is done.
317 struct DeferredGlobal {
318 DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
319 llvm::TrackingVH<llvm::GlobalValue> GV;
322 std::vector<DeferredGlobal> DeferredDeclsToEmit;
323 void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
324 DeferredDeclsToEmit.emplace_back(GV, GD);
327 /// List of alias we have emitted. Used to make sure that what they point to
328 /// is defined once we get to the end of the of the translation unit.
329 std::vector<GlobalDecl> Aliases;
331 typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
332 ReplacementsTy Replacements;
334 /// List of global values to be replaced with something else. Used when we
335 /// want to replace a GlobalValue but can't identify it by its mangled name
336 /// anymore (because the name is already taken).
337 llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
338 GlobalValReplacements;
340 /// Set of global decls for which we already diagnosed mangled name conflict.
341 /// Required to not issue a warning (on a mangling conflict) multiple times
342 /// for the same decl.
343 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
345 /// A queue of (optional) vtables to consider emitting.
346 std::vector<const CXXRecordDecl*> DeferredVTables;
348 /// List of global values which are required to be present in the object file;
349 /// bitcast to i8*. This is used for forcing visibility of symbols which may
350 /// otherwise be optimized out.
351 std::vector<llvm::WeakVH> LLVMUsed;
352 std::vector<llvm::WeakVH> LLVMCompilerUsed;
354 /// Store the list of global constructors and their respective priorities to
355 /// be emitted when the translation unit is complete.
356 CtorList GlobalCtors;
358 /// Store the list of global destructors and their respective priorities to be
359 /// emitted when the translation unit is complete.
360 CtorList GlobalDtors;
362 /// An ordered map of canonical GlobalDecls to their mangled names.
363 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
364 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
366 /// Global annotations.
367 std::vector<llvm::Constant*> Annotations;
369 /// Map used to get unique annotation strings.
370 llvm::StringMap<llvm::Constant*> AnnotationStrings;
372 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
374 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
375 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
376 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
377 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
379 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
380 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
382 /// Map used to get unique type descriptor constants for sanitizers.
383 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
385 /// Map used to track internal linkage functions declared within
386 /// extern "C" regions.
387 typedef llvm::MapVector<IdentifierInfo *,
388 llvm::GlobalValue *> StaticExternCMap;
389 StaticExternCMap StaticExternCValues;
391 /// \brief thread_local variables defined or used in this TU.
392 std::vector<const VarDecl *> CXXThreadLocals;
394 /// \brief thread_local variables with initializers that need to run
395 /// before any thread_local variable in this TU is odr-used.
396 std::vector<llvm::Function *> CXXThreadLocalInits;
397 std::vector<const VarDecl *> CXXThreadLocalInitVars;
399 /// Global variables with initializers that need to run before main.
400 std::vector<llvm::Function *> CXXGlobalInits;
402 /// When a C++ decl with an initializer is deferred, null is
403 /// appended to CXXGlobalInits, and the index of that null is placed
404 /// here so that the initializer will be performed in the correct
405 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
406 /// that we don't re-emit the initializer.
407 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
409 typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
411 struct GlobalInitPriorityCmp {
412 bool operator()(const GlobalInitData &LHS,
413 const GlobalInitData &RHS) const {
414 return LHS.first.priority < RHS.first.priority;
418 /// Global variables with initializers whose order of initialization is set by
419 /// init_priority attribute.
420 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
422 /// Global destructor functions and arguments that need to run on termination.
423 std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
425 /// \brief The complete set of modules that has been imported.
426 llvm::SetVector<clang::Module *> ImportedModules;
428 /// \brief The set of modules for which the module initializers
429 /// have been emitted.
430 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
432 /// \brief A vector of metadata strings.
433 SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
435 /// @name Cache for Objective-C runtime types
438 /// Cached reference to the class for constant strings. This value has type
439 /// int * but is actually an Obj-C class pointer.
440 llvm::WeakVH CFConstantStringClassRef;
442 /// \brief The type used to describe the state of a fast enumeration in
443 /// Objective-C's for..in loop.
444 QualType ObjCFastEnumerationStateType;
448 /// Lazily create the Objective-C runtime
449 void createObjCRuntime();
451 void createOpenCLRuntime();
452 void createOpenMPRuntime();
453 void createCUDARuntime();
455 bool isTriviallyRecursive(const FunctionDecl *F);
456 bool shouldEmitFunction(GlobalDecl GD);
458 /// Map used to be sure we don't emit the same CompoundLiteral twice.
459 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
460 EmittedCompoundLiterals;
462 /// Map of the global blocks we've emitted, so that we don't have to re-emit
463 /// them if the constexpr evaluator gets aggressive.
464 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
466 /// @name Cache for Blocks Runtime Globals
469 llvm::Constant *NSConcreteGlobalBlock = nullptr;
470 llvm::Constant *NSConcreteStackBlock = nullptr;
472 llvm::Constant *BlockObjectAssign = nullptr;
473 llvm::Constant *BlockObjectDispose = nullptr;
475 llvm::Type *BlockDescriptorType = nullptr;
476 llvm::Type *GenericBlockLiteralType = nullptr;
479 int GlobalUniqueCount;
482 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
483 llvm::Constant *LifetimeStartFn = nullptr;
485 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
486 llvm::Constant *LifetimeEndFn = nullptr;
488 GlobalDecl initializedGlobalDecl;
490 std::unique_ptr<SanitizerMetadata> SanitizerMD;
494 llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
496 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
498 /// Mapping from canonical types to their metadata identifiers. We need to
499 /// maintain this mapping because identifiers may be formed from distinct
501 llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap;
504 CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
505 const PreprocessorOptions &ppopts,
506 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
507 DiagnosticsEngine &Diags,
508 CoverageSourceInfo *CoverageInfo = nullptr);
514 /// Finalize LLVM code generation.
517 /// Return a reference to the configured Objective-C runtime.
518 CGObjCRuntime &getObjCRuntime() {
519 if (!ObjCRuntime) createObjCRuntime();
523 /// Return true iff an Objective-C runtime has been configured.
524 bool hasObjCRuntime() { return !!ObjCRuntime; }
526 /// Return a reference to the configured OpenCL runtime.
527 CGOpenCLRuntime &getOpenCLRuntime() {
528 assert(OpenCLRuntime != nullptr);
529 return *OpenCLRuntime;
532 /// Return a reference to the configured OpenMP runtime.
533 CGOpenMPRuntime &getOpenMPRuntime() {
534 assert(OpenMPRuntime != nullptr);
535 return *OpenMPRuntime;
538 /// Return a reference to the configured CUDA runtime.
539 CGCUDARuntime &getCUDARuntime() {
540 assert(CUDARuntime != nullptr);
544 ObjCEntrypoints &getObjCEntrypoints() const {
545 assert(ObjCData != nullptr);
549 InstrProfStats &getPGOStats() { return PGOStats; }
550 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
552 CoverageMappingModuleGen *getCoverageMapping() const {
553 return CoverageMapping.get();
556 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
557 return StaticLocalDeclMap[D];
559 void setStaticLocalDeclAddress(const VarDecl *D,
561 StaticLocalDeclMap[D] = C;
565 getOrCreateStaticVarDecl(const VarDecl &D,
566 llvm::GlobalValue::LinkageTypes Linkage);
568 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
569 return StaticLocalDeclGuardMap[D];
571 void setStaticLocalDeclGuardAddress(const VarDecl *D,
572 llvm::GlobalVariable *C) {
573 StaticLocalDeclGuardMap[D] = C;
576 bool lookupRepresentativeDecl(StringRef MangledName,
577 GlobalDecl &Result) const;
579 llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
580 return AtomicSetterHelperFnMap[Ty];
582 void setAtomicSetterHelperFnMap(QualType Ty,
583 llvm::Constant *Fn) {
584 AtomicSetterHelperFnMap[Ty] = Fn;
587 llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
588 return AtomicGetterHelperFnMap[Ty];
590 void setAtomicGetterHelperFnMap(QualType Ty,
591 llvm::Constant *Fn) {
592 AtomicGetterHelperFnMap[Ty] = Fn;
595 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
596 return TypeDescriptorMap[Ty];
598 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
599 TypeDescriptorMap[Ty] = C;
602 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
604 llvm::MDNode *getNoObjCARCExceptionsMetadata() {
605 if (!NoObjCARCExceptionsMetadata)
606 NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
607 return NoObjCARCExceptionsMetadata;
610 ASTContext &getContext() const { return Context; }
611 const LangOptions &getLangOpts() const { return LangOpts; }
612 const HeaderSearchOptions &getHeaderSearchOpts()
613 const { return HeaderSearchOpts; }
614 const PreprocessorOptions &getPreprocessorOpts()
615 const { return PreprocessorOpts; }
616 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
617 llvm::Module &getModule() const { return TheModule; }
618 DiagnosticsEngine &getDiags() const { return Diags; }
619 const llvm::DataLayout &getDataLayout() const {
620 return TheModule.getDataLayout();
622 const TargetInfo &getTarget() const { return Target; }
623 const llvm::Triple &getTriple() const { return Target.getTriple(); }
624 bool supportsCOMDAT() const;
625 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
627 CGCXXABI &getCXXABI() const { return *ABI; }
628 llvm::LLVMContext &getLLVMContext() { return VMContext; }
630 bool shouldUseTBAA() const { return TBAA != nullptr; }
632 const TargetCodeGenInfo &getTargetCodeGenInfo();
634 CodeGenTypes &getTypes() { return Types; }
636 CodeGenVTables &getVTables() { return VTables; }
638 ItaniumVTableContext &getItaniumVTableContext() {
639 return VTables.getItaniumVTableContext();
642 MicrosoftVTableContext &getMicrosoftVTableContext() {
643 return VTables.getMicrosoftVTableContext();
646 CtorList &getGlobalCtors() { return GlobalCtors; }
647 CtorList &getGlobalDtors() { return GlobalDtors; }
649 llvm::MDNode *getTBAAInfo(QualType QTy);
650 llvm::MDNode *getTBAAInfoForVTablePtr();
651 llvm::MDNode *getTBAAStructInfo(QualType QTy);
652 /// Return the path-aware tag for given base type, access node and offset.
653 llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
656 bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
658 bool isPaddedAtomicType(QualType type);
659 bool isPaddedAtomicType(const AtomicType *type);
661 /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
662 /// is the same as the type. For struct-path aware TBAA, the tag
663 /// is different from the type: base type, access type and offset.
664 /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
665 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
666 llvm::MDNode *TBAAInfo,
667 bool ConvertTypeToTag = true);
669 /// Adds !invariant.barrier !tag to instruction
670 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
671 const CXXRecordDecl *RD);
673 /// Emit the given number of characters as a value of type size_t.
674 llvm::ConstantInt *getSize(CharUnits numChars);
676 /// Set the visibility for the given LLVM GlobalValue.
677 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
679 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
680 /// variable declaration D.
681 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
683 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
685 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
686 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
687 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
689 llvm_unreachable("unknown visibility!");
692 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
693 ForDefinition_t IsForDefinition
696 /// Will return a global variable of the given type. If a variable with a
697 /// different type already exists then a new variable with the right type
698 /// will be created and all uses of the old variable will be replaced with a
699 /// bitcast to the new variable.
700 llvm::GlobalVariable *
701 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
702 llvm::GlobalValue::LinkageTypes Linkage);
705 CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
706 const CGFunctionInfo &FI,
707 SourceLocation Loc = SourceLocation(),
710 /// Return the address space of the underlying global variable for D, as
711 /// determined by its declaration. Normally this is the same as the address
712 /// space of D's type, but in CUDA, address spaces are associated with
713 /// declarations, not types.
714 unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
716 /// Return the llvm::Constant for the address of the given global variable.
717 /// If Ty is non-null and if the global doesn't exist, then it will be created
718 /// with the specified type instead of whatever the normal requested type
719 /// would be. If IsForDefinition is true, it is guranteed that an actual
720 /// global with type Ty will be returned, not conversion of a variable with
721 /// the same mangled name but some other type.
722 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
723 llvm::Type *Ty = nullptr,
724 ForDefinition_t IsForDefinition
727 /// Return the address of the given function. If Ty is non-null, then this
728 /// function will use the specified type if it has to create it.
729 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
730 bool ForVTable = false,
731 bool DontDefer = false,
732 ForDefinition_t IsForDefinition
735 /// Get the address of the RTTI descriptor for the given type.
736 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
738 /// Get the address of a uuid descriptor .
739 ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
741 /// Get the address of the thunk for the given global decl.
742 llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
744 /// Get a reference to the target of VD.
745 ConstantAddress GetWeakRefReference(const ValueDecl *VD);
747 /// Returns the assumed alignment of an opaque pointer to the given class.
748 CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
750 /// Returns the assumed alignment of a virtual base of a class.
751 CharUnits getVBaseAlignment(CharUnits DerivedAlign,
752 const CXXRecordDecl *Derived,
753 const CXXRecordDecl *VBase);
755 /// Given a class pointer with an actual known alignment, and the
756 /// expected alignment of an object at a dynamic offset w.r.t that
757 /// pointer, return the alignment to assume at the offset.
758 CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
759 const CXXRecordDecl *Class,
760 CharUnits ExpectedTargetAlign);
763 computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
764 CastExpr::path_const_iterator Start,
765 CastExpr::path_const_iterator End);
767 /// Returns the offset from a derived class to a class. Returns null if the
770 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
771 CastExpr::path_const_iterator PathBegin,
772 CastExpr::path_const_iterator PathEnd);
774 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
776 /// Fetches the global unique block count.
777 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
779 /// Fetches the type of a generic block descriptor.
780 llvm::Type *getBlockDescriptorType();
782 /// The type of a generic block literal.
783 llvm::Type *getGenericBlockLiteralType();
785 /// Gets the address of a block which requires no captures.
786 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
788 /// Returns the address of a block which requires no caputres, or null if
789 /// we've yet to emit the block for BE.
790 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
791 return EmittedGlobalBlocks.lookup(BE);
794 /// Notes that BE's global block is available via Addr. Asserts that BE
795 /// isn't already emitted.
796 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
798 /// Return a pointer to a constant CFString object for the given string.
799 ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
801 /// Return a pointer to a constant NSString object for the given string. Or a
802 /// user defined String object as defined via
803 /// -fconstant-string-class=class_name option.
804 ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
806 /// Return a constant array for the given string.
807 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
809 /// Return a pointer to a constant array for the given string literal.
811 GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
812 StringRef Name = ".str");
814 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
816 GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
818 /// Returns a pointer to a character array containing the literal and a
819 /// terminating '\0' character. The result has pointer to array type.
821 /// \param GlobalName If provided, the name to use for the global (if one is
824 GetAddrOfConstantCString(const std::string &Str,
825 const char *GlobalName = nullptr);
827 /// Returns a pointer to a constant global variable for the given file-scope
828 /// compound literal expression.
829 ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
831 /// If it's been emitted already, returns the GlobalVariable corresponding to
832 /// a compound literal. Otherwise, returns null.
833 llvm::GlobalVariable *
834 getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E);
836 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
838 void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE,
839 llvm::GlobalVariable *GV);
841 /// \brief Returns a pointer to a global variable representing a temporary
842 /// with static or thread storage duration.
843 ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
846 /// \brief Retrieve the record type that describes the state of an
847 /// Objective-C fast enumeration loop (for..in).
848 QualType getObjCFastEnumerationStateType();
850 // Produce code for this constructor/destructor. This method doesn't try
851 // to apply any ABI rules about which other constructors/destructors
852 // are needed or if they are alias to each other.
853 llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
856 /// Return the address of the constructor/destructor of the given type.
858 getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
859 const CGFunctionInfo *FnInfo = nullptr,
860 llvm::FunctionType *FnType = nullptr,
861 bool DontDefer = false,
862 ForDefinition_t IsForDefinition = NotForDefinition);
864 /// Given a builtin id for a function like "__builtin_fabsf", return a
865 /// Function* for "fabsf".
866 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
869 llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
871 /// Emit code for a single top level declaration.
872 void EmitTopLevelDecl(Decl *D);
874 /// \brief Stored a deferred empty coverage mapping for an unused
875 /// and thus uninstrumented top level declaration.
876 void AddDeferredUnusedCoverageMapping(Decl *D);
878 /// \brief Remove the deferred empty coverage mapping as this
879 /// declaration is actually instrumented.
880 void ClearUnusedCoverageMapping(const Decl *D);
882 /// \brief Emit all the deferred coverage mappings
883 /// for the uninstrumented functions.
884 void EmitDeferredUnusedCoverageMappings();
886 /// Tell the consumer that this variable has been instantiated.
887 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
889 /// \brief If the declaration has internal linkage but is inside an
890 /// extern "C" linkage specification, prepare to emit an alias for it
891 /// to the expected name.
892 template<typename SomeDecl>
893 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
895 /// Add a global to a list to be added to the llvm.used metadata.
896 void addUsedGlobal(llvm::GlobalValue *GV);
898 /// Add a global to a list to be added to the llvm.compiler.used metadata.
899 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
901 /// Add a destructor and object to add to the C++ global destructor function.
902 void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
903 CXXGlobalDtors.emplace_back(DtorFn, Object);
906 /// Create a new runtime function with the specified type and name.
908 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
909 llvm::AttributeSet ExtraAttrs = llvm::AttributeSet(),
912 /// Create a new compiler builtin function with the specified type and name.
913 llvm::Constant *CreateBuiltinFunction(llvm::FunctionType *Ty,
915 llvm::AttributeSet ExtraAttrs =
916 llvm::AttributeSet());
917 /// Create a new runtime global variable with the specified type and name.
918 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
921 ///@name Custom Blocks Runtime Interfaces
924 llvm::Constant *getNSConcreteGlobalBlock();
925 llvm::Constant *getNSConcreteStackBlock();
926 llvm::Constant *getBlockObjectAssign();
927 llvm::Constant *getBlockObjectDispose();
931 llvm::Constant *getLLVMLifetimeStartFn();
932 llvm::Constant *getLLVMLifetimeEndFn();
934 // Make sure that this type is translated.
935 void UpdateCompletedType(const TagDecl *TD);
937 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
939 /// Try to emit the initializer for the given declaration as a constant;
940 /// returns 0 if the expression cannot be emitted as a constant.
941 llvm::Constant *EmitConstantInit(const VarDecl &D,
942 CodeGenFunction *CGF = nullptr);
944 /// Try to emit the given expression as a constant; returns 0 if the
945 /// expression cannot be emitted as a constant.
946 llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
947 CodeGenFunction *CGF = nullptr);
949 /// Emit the given constant value as a constant, in the type's scalar
951 llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
952 CodeGenFunction *CGF = nullptr);
954 /// Emit the given constant value as a constant, in the type's memory
956 llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
958 CodeGenFunction *CGF = nullptr);
960 /// \brief Emit type info if type of an expression is a variably modified
961 /// type. Also emit proper debug info for cast types.
962 void EmitExplicitCastExprType(const ExplicitCastExpr *E,
963 CodeGenFunction *CGF = nullptr);
965 /// Return the result of value-initializing the given type, i.e. a null
966 /// expression of the given type. This is usually, but not always, an LLVM
968 llvm::Constant *EmitNullConstant(QualType T);
970 /// Return a null constant appropriate for zero-initializing a base class with
971 /// the given type. This is usually, but not always, an LLVM null constant.
972 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
974 /// Emit a general error that something can't be done.
975 void Error(SourceLocation loc, StringRef error);
977 /// Print out an error that codegen doesn't support the specified stmt yet.
978 void ErrorUnsupported(const Stmt *S, const char *Type);
980 /// Print out an error that codegen doesn't support the specified decl yet.
981 void ErrorUnsupported(const Decl *D, const char *Type);
983 /// Set the attributes on the LLVM function for the given decl and function
984 /// info. This applies attributes necessary for handling the ABI as well as
985 /// user specified attributes like section.
986 void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
987 const CGFunctionInfo &FI);
989 /// Set the LLVM function attributes (sext, zext, etc).
990 void SetLLVMFunctionAttributes(const Decl *D,
991 const CGFunctionInfo &Info,
994 /// Set the LLVM function attributes which only apply to a function
996 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
998 /// Return true iff the given type uses 'sret' when used as a return type.
999 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1001 /// Return true iff the given type uses an argument slot when 'sret' is used
1002 /// as a return type.
1003 bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
1005 /// Return true iff the given type uses 'fpret' when used as a return type.
1006 bool ReturnTypeUsesFPRet(QualType ResultType);
1008 /// Return true iff the given type uses 'fp2ret' when used as a return type.
1009 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1011 /// Get the LLVM attributes and calling convention to use for a particular
1014 /// \param Name - The function name.
1015 /// \param Info - The function type information.
1016 /// \param CalleeInfo - The callee information these attributes are being
1017 /// constructed for. If valid, the attributes applied to this decl may
1018 /// contribute to the function attributes and calling convention.
1019 /// \param PAL [out] - On return, the attribute list to use.
1020 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
1021 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
1022 CGCalleeInfo CalleeInfo, AttributeListType &PAL,
1023 unsigned &CallingConv, bool AttrOnCallSite);
1025 // Fills in the supplied string map with the set of target features for the
1026 // passed in function.
1027 void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1028 const FunctionDecl *FD);
1030 StringRef getMangledName(GlobalDecl GD);
1031 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
1033 void EmitTentativeDefinition(const VarDecl *D);
1035 void EmitVTable(CXXRecordDecl *Class);
1037 void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
1039 /// \brief Appends Opts to the "Linker Options" metadata value.
1040 void AppendLinkerOptions(StringRef Opts);
1042 /// \brief Appends a detect mismatch command to the linker options.
1043 void AddDetectMismatch(StringRef Name, StringRef Value);
1045 /// \brief Appends a dependent lib to the "Linker Options" metadata value.
1046 void AddDependentLib(StringRef Lib);
1048 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1050 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1051 F->setLinkage(getFunctionLinkage(GD));
1054 /// Set the DLL storage class on F.
1055 void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F);
1057 /// Return the appropriate linkage for the vtable, VTT, and type information
1058 /// of the given class.
1059 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1061 /// Return the store size, in character units, of the given LLVM type.
1062 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1064 /// Returns LLVM linkage for a declarator.
1065 llvm::GlobalValue::LinkageTypes
1066 getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
1067 bool IsConstantVariable);
1069 /// Returns LLVM linkage for a declarator.
1070 llvm::GlobalValue::LinkageTypes
1071 getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1073 /// Emit all the global annotations.
1074 void EmitGlobalAnnotations();
1076 /// Emit an annotation string.
1077 llvm::Constant *EmitAnnotationString(StringRef Str);
1079 /// Emit the annotation's translation unit.
1080 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1082 /// Emit the annotation line number.
1083 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1085 /// Generate the llvm::ConstantStruct which contains the annotation
1086 /// information for a given GlobalValue. The annotation struct is
1087 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1088 /// GlobalValue being annotated. The second field is the constant string
1089 /// created from the AnnotateAttr's annotation. The third field is a constant
1090 /// string containing the name of the translation unit. The fourth field is
1091 /// the line number in the file of the annotated value declaration.
1092 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1093 const AnnotateAttr *AA,
1096 /// Add global annotations that are set on D, for the global GV. Those
1097 /// annotations are emitted during finalization of the LLVM code.
1098 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1100 bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
1102 bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1104 StringRef Category = StringRef()) const;
1106 SanitizerMetadata *getSanitizerMetadata() {
1107 return SanitizerMD.get();
1110 void addDeferredVTable(const CXXRecordDecl *RD) {
1111 DeferredVTables.push_back(RD);
1114 /// Emit code for a singal global function or var decl. Forward declarations
1115 /// are emitted lazily.
1116 void EmitGlobal(GlobalDecl D);
1118 bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1120 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1122 /// Set attributes for a global definition.
1123 void setFunctionDefinitionAttributes(const FunctionDecl *D,
1126 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1128 /// Set attributes which are common to any form of a global definition (alias,
1129 /// Objective-C method, function, global variable).
1131 /// NOTE: This should only be called for definitions.
1132 void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1134 /// Set attributes which must be preserved by an alias. This includes common
1135 /// attributes (i.e. it includes a call to SetCommonAttributes).
1137 /// NOTE: This should only be called for definitions.
1138 void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1140 void addReplacement(StringRef Name, llvm::Constant *C);
1142 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1144 /// \brief Emit a code for threadprivate directive.
1145 /// \param D Threadprivate declaration.
1146 void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
1148 /// \brief Emit a code for declare reduction construct.
1149 void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
1150 CodeGenFunction *CGF = nullptr);
1152 /// Returns whether the given record has hidden LTO visibility and therefore
1153 /// may participate in (single-module) CFI and whole-program vtable
1155 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
1157 /// Emit type metadata for the given vtable using the given layout.
1158 void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1159 const VTableLayout &VTLayout);
1161 /// Generate a cross-DSO type identifier for MD.
1162 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
1164 /// Create a metadata identifier for the given type. This may either be an
1165 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1166 /// internal identifiers).
1167 llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1169 /// Create and attach type metadata to the given function.
1170 void CreateFunctionTypeMetadata(const FunctionDecl *FD, llvm::Function *F);
1172 /// Returns whether this module needs the "all-vtables" type identifier.
1173 bool NeedAllVtablesTypeId() const;
1175 /// Create and attach type metadata for the given vtable.
1176 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1177 const CXXRecordDecl *RD);
1179 /// \breif Get the declaration of std::terminate for the platform.
1180 llvm::Constant *getTerminateFn();
1182 llvm::SanitizerStatReport &getSanStats();
1185 createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
1187 /// Get target specific null pointer.
1188 /// \param T is the LLVM type of the null pointer.
1189 /// \param QT is the clang QualType of the null pointer.
1190 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1194 GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
1195 bool ForVTable, bool DontDefer = false,
1196 bool IsThunk = false,
1197 llvm::AttributeSet ExtraAttrs = llvm::AttributeSet(),
1198 ForDefinition_t IsForDefinition = NotForDefinition);
1200 llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
1201 llvm::PointerType *PTy,
1203 ForDefinition_t IsForDefinition
1204 = NotForDefinition);
1206 void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
1208 /// Set function attributes for a function declaration.
1209 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1210 bool IsIncompleteFunction, bool IsThunk);
1212 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1214 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1215 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1216 void EmitAliasDefinition(GlobalDecl GD);
1217 void emitIFuncDefinition(GlobalDecl GD);
1218 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1219 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1221 // C++ related functions.
1223 void EmitDeclContext(const DeclContext *DC);
1224 void EmitLinkageSpec(const LinkageSpecDecl *D);
1225 void CompleteDIClassType(const CXXMethodDecl* D);
1227 /// \brief Emit the function that initializes C++ thread_local variables.
1228 void EmitCXXThreadLocalInitFunc();
1230 /// Emit the function that initializes C++ globals.
1231 void EmitCXXGlobalInitFunc();
1233 /// Emit the function that destroys C++ globals.
1234 void EmitCXXGlobalDtorFunc();
1236 /// Emit the function that initializes the specified global (if PerformInit is
1237 /// true) and registers its destructor.
1238 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1239 llvm::GlobalVariable *Addr,
1242 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1243 llvm::Function *InitFunc, InitSegAttr *ISA);
1245 // FIXME: Hardcoding priority here is gross.
1246 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1247 llvm::Constant *AssociatedData = nullptr);
1248 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
1250 /// EmitCtorList - Generates a global array of functions and priorities using
1251 /// the given list and name. This array will have appending linkage and is
1252 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1253 void EmitCtorList(CtorList &Fns, const char *GlobalName);
1255 /// Emit any needed decls for which code generation was deferred.
1256 void EmitDeferred();
1258 /// Call replaceAllUsesWith on all pairs in Replacements.
1259 void applyReplacements();
1261 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1262 void applyGlobalValReplacements();
1264 void checkAliases();
1266 /// Emit any vtables which we deferred and still have a use for.
1267 void EmitDeferredVTables();
1269 /// Emit the llvm.used and llvm.compiler.used metadata.
1270 void emitLLVMUsed();
1272 /// \brief Emit the link options introduced by imported modules.
1273 void EmitModuleLinkOptions();
1275 /// \brief Emit aliases for internal-linkage declarations inside "C" language
1276 /// linkage specifications, giving them the "expected" name where possible.
1277 void EmitStaticExternCAliases();
1279 void EmitDeclMetadata();
1281 /// \brief Emit the Clang version as llvm.ident metadata.
1282 void EmitVersionIdentMetadata();
1284 /// Emits target specific Metadata for global declarations.
1285 void EmitTargetMetadata();
1287 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1288 /// .gcda files in a way that persists in .bc files.
1289 void EmitCoverageFile();
1291 /// Emits the initializer for a uuidof string.
1292 llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
1294 /// Determine whether the definition must be emitted; if this returns \c
1295 /// false, the definition can be emitted lazily if it's used.
1296 bool MustBeEmitted(const ValueDecl *D);
1298 /// Determine whether the definition can be emitted eagerly, or should be
1299 /// delayed until the end of the translation unit. This is relevant for
1300 /// definitions whose linkage can change, e.g. implicit function instantions
1301 /// which may later be explicitly instantiated.
1302 bool MayBeEmittedEagerly(const ValueDecl *D);
1304 /// Check whether we can use a "simpler", more core exceptions personality
1306 void SimplifyPersonality();
1308 } // end namespace CodeGen
1309 } // end namespace clang
1311 #endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H