clang 17.0.0git
CodeGenModule.h
Go to the documentation of this file.
1//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the internal per-translation-unit state used for llvm translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
14#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15
16#include "CGVTables.h"
17#include "CodeGenTypeCache.h"
18#include "CodeGenTypes.h"
19#include "SanitizerMetadata.h"
20#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclObjC.h"
24#include "clang/AST/Mangle.h"
25#include "clang/Basic/ABI.h"
27#include "clang/Basic/Module.h"
32#include "llvm/ADT/DenseMap.h"
33#include "llvm/ADT/SetVector.h"
34#include "llvm/ADT/SmallPtrSet.h"
35#include "llvm/ADT/StringMap.h"
36#include "llvm/IR/Module.h"
37#include "llvm/IR/ValueHandle.h"
38#include "llvm/Transforms/Utils/SanitizerStats.h"
39#include <optional>
40
41namespace llvm {
42class Module;
43class Constant;
44class ConstantInt;
45class Function;
46class GlobalValue;
47class DataLayout;
48class FunctionType;
49class LLVMContext;
50class IndexedInstrProfReader;
51
52namespace vfs {
53class FileSystem;
54}
55}
56
57namespace clang {
58class ASTContext;
59class AtomicType;
60class FunctionDecl;
61class IdentifierInfo;
62class ObjCImplementationDecl;
63class ObjCEncodeExpr;
64class BlockExpr;
65class CharUnits;
66class Decl;
67class Expr;
68class Stmt;
69class StringLiteral;
70class NamedDecl;
71class ValueDecl;
72class VarDecl;
73class LangOptions;
74class CodeGenOptions;
75class HeaderSearchOptions;
76class DiagnosticsEngine;
77class AnnotateAttr;
78class CXXDestructorDecl;
79class Module;
80class CoverageSourceInfo;
81class InitSegAttr;
82
83namespace CodeGen {
84
85class CodeGenFunction;
86class CodeGenTBAA;
87class CGCXXABI;
88class CGDebugInfo;
89class CGObjCRuntime;
90class CGOpenCLRuntime;
91class CGOpenMPRuntime;
92class CGCUDARuntime;
93class CGHLSLRuntime;
94class CoverageMappingModuleGen;
95class TargetCodeGenInfo;
96
97enum ForDefinition_t : bool {
99 ForDefinition = true
101
103 unsigned int priority;
104 unsigned int lex_order;
105 OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
106 : priority(p), lex_order(l) {}
107
109 return priority == RHS.priority && lex_order == RHS.lex_order;
110 }
111
113 return std::tie(priority, lex_order) <
114 std::tie(RHS.priority, RHS.lex_order);
115 }
116};
117
119 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
120
121 /// void objc_alloc(id);
122 llvm::FunctionCallee objc_alloc;
123
124 /// void objc_allocWithZone(id);
125 llvm::FunctionCallee objc_allocWithZone;
126
127 /// void objc_alloc_init(id);
128 llvm::FunctionCallee objc_alloc_init;
129
130 /// void objc_autoreleasePoolPop(void*);
131 llvm::FunctionCallee objc_autoreleasePoolPop;
132
133 /// void objc_autoreleasePoolPop(void*);
134 /// Note this method is used when we are using exception handling
135 llvm::FunctionCallee objc_autoreleasePoolPopInvoke;
136
137 /// void *objc_autoreleasePoolPush(void);
139
140 /// id objc_autorelease(id);
141 llvm::Function *objc_autorelease;
142
143 /// id objc_autorelease(id);
144 /// Note this is the runtime method not the intrinsic.
146
147 /// id objc_autoreleaseReturnValue(id);
149
150 /// void objc_copyWeak(id *dest, id *src);
151 llvm::Function *objc_copyWeak;
152
153 /// void objc_destroyWeak(id*);
154 llvm::Function *objc_destroyWeak;
155
156 /// id objc_initWeak(id*, id);
157 llvm::Function *objc_initWeak;
158
159 /// id objc_loadWeak(id*);
160 llvm::Function *objc_loadWeak;
161
162 /// id objc_loadWeakRetained(id*);
163 llvm::Function *objc_loadWeakRetained;
164
165 /// void objc_moveWeak(id *dest, id *src);
166 llvm::Function *objc_moveWeak;
167
168 /// id objc_retain(id);
169 llvm::Function *objc_retain;
170
171 /// id objc_retain(id);
172 /// Note this is the runtime method not the intrinsic.
173 llvm::FunctionCallee objc_retainRuntimeFunction;
174
175 /// id objc_retainAutorelease(id);
176 llvm::Function *objc_retainAutorelease;
177
178 /// id objc_retainAutoreleaseReturnValue(id);
180
181 /// id objc_retainAutoreleasedReturnValue(id);
183
184 /// id objc_retainBlock(id);
185 llvm::Function *objc_retainBlock;
186
187 /// void objc_release(id);
188 llvm::Function *objc_release;
189
190 /// void objc_release(id);
191 /// Note this is the runtime method not the intrinsic.
192 llvm::FunctionCallee objc_releaseRuntimeFunction;
193
194 /// void objc_storeStrong(id*, id);
195 llvm::Function *objc_storeStrong;
196
197 /// id objc_storeWeak(id*, id);
198 llvm::Function *objc_storeWeak;
199
200 /// id objc_unsafeClaimAutoreleasedReturnValue(id);
202
203 /// A void(void) inline asm to use to mark that the return value of
204 /// a call will be immediately retain.
206
207 /// void clang.arc.use(...);
208 llvm::Function *clang_arc_use;
209
210 /// void clang.arc.noop.use(...);
211 llvm::Function *clang_arc_noop_use;
212};
213
214/// This class records statistics on instrumentation based profiling.
216 uint32_t VisitedInMainFile;
217 uint32_t MissingInMainFile;
218 uint32_t Visited;
219 uint32_t Missing;
220 uint32_t Mismatched;
221
222public:
224 : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
225 Mismatched(0) {}
226 /// Record that we've visited a function and whether or not that function was
227 /// in the main source file.
228 void addVisited(bool MainFile) {
229 if (MainFile)
230 ++VisitedInMainFile;
231 ++Visited;
232 }
233 /// Record that a function we've visited has no profile data.
234 void addMissing(bool MainFile) {
235 if (MainFile)
236 ++MissingInMainFile;
237 ++Missing;
238 }
239 /// Record that a function we've visited has mismatched profile data.
240 void addMismatched(bool MainFile) { ++Mismatched; }
241 /// Whether or not the stats we've gathered indicate any potential problems.
242 bool hasDiagnostics() { return Missing || Mismatched; }
243 /// Report potential problems we've found to \c Diags.
244 void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
245};
246
247/// A pair of helper functions for a __block variable.
248class BlockByrefHelpers : public llvm::FoldingSetNode {
249 // MSVC requires this type to be complete in order to process this
250 // header.
251public:
252 llvm::Constant *CopyHelper;
253 llvm::Constant *DisposeHelper;
254
255 /// The alignment of the field. This is important because
256 /// different offsets to the field within the byref struct need to
257 /// have different helper functions.
259
261 : CopyHelper(nullptr), DisposeHelper(nullptr), Alignment(alignment) {}
263 virtual ~BlockByrefHelpers();
264
265 void Profile(llvm::FoldingSetNodeID &id) const {
266 id.AddInteger(Alignment.getQuantity());
267 profileImpl(id);
268 }
269 virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
270
271 virtual bool needsCopy() const { return true; }
272 virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
273
274 virtual bool needsDispose() const { return true; }
275 virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
276};
277
278/// This class organizes the cross-function state that is used while generating
279/// LLVM code.
281 CodeGenModule(const CodeGenModule &) = delete;
282 void operator=(const CodeGenModule &) = delete;
283
284public:
285 struct Structor {
287 : Priority(0), LexOrder(~0u), Initializer(nullptr),
288 AssociatedData(nullptr) {}
289 Structor(int Priority, unsigned LexOrder, llvm::Constant *Initializer,
290 llvm::Constant *AssociatedData)
294 unsigned LexOrder;
295 llvm::Constant *Initializer;
296 llvm::Constant *AssociatedData;
297 };
298
299 typedef std::vector<Structor> CtorList;
300
301private:
302 ASTContext &Context;
303 const LangOptions &LangOpts;
304 IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS; // Only used for debug info.
305 const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
306 const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
307 const CodeGenOptions &CodeGenOpts;
308 unsigned NumAutoVarInit = 0;
309 llvm::Module &TheModule;
310 DiagnosticsEngine &Diags;
311 const TargetInfo &Target;
312 std::unique_ptr<CGCXXABI> ABI;
313 llvm::LLVMContext &VMContext;
314 std::string ModuleNameHash;
315 bool CXX20ModuleInits = false;
316 std::unique_ptr<CodeGenTBAA> TBAA;
317
318 mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
319
320 // This should not be moved earlier, since its initialization depends on some
321 // of the previous reference members being already initialized and also checks
322 // if TheTargetCodeGenInfo is NULL
323 CodeGenTypes Types;
324
325 /// Holds information about C++ vtables.
326 CodeGenVTables VTables;
327
328 std::unique_ptr<CGObjCRuntime> ObjCRuntime;
329 std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
330 std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
331 std::unique_ptr<CGCUDARuntime> CUDARuntime;
332 std::unique_ptr<CGHLSLRuntime> HLSLRuntime;
333 std::unique_ptr<CGDebugInfo> DebugInfo;
334 std::unique_ptr<ObjCEntrypoints> ObjCData;
335 llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
336 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
337 InstrProfStats PGOStats;
338 std::unique_ptr<llvm::SanitizerStatReport> SanStats;
339
340 // A set of references that have only been seen via a weakref so far. This is
341 // used to remove the weak of the reference if we ever see a direct reference
342 // or a definition.
344
345 /// This contains all the decls which have definitions but/ which are deferred
346 /// for emission and therefore should only be output if they are actually
347 /// used. If a decl is in this, then it is known to have not been referenced
348 /// yet.
349 llvm::DenseMap<StringRef, GlobalDecl> DeferredDecls;
350
351 /// This is a list of deferred decls which we have seen that *are* actually
352 /// referenced. These get code generated when the module is done.
353 std::vector<GlobalDecl> DeferredDeclsToEmit;
354 void addDeferredDeclToEmit(GlobalDecl GD) {
355 DeferredDeclsToEmit.emplace_back(GD);
356 addEmittedDeferredDecl(GD);
357 }
358
359 /// Decls that were DeferredDecls and have now been emitted.
360 llvm::DenseMap<llvm::StringRef, GlobalDecl> EmittedDeferredDecls;
361
362 void addEmittedDeferredDecl(GlobalDecl GD) {
363 if (!llvm::isa<FunctionDecl>(GD.getDecl()))
364 return;
365 llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
366 if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
367 llvm::GlobalValue::isWeakLinkage(L)) {
368 EmittedDeferredDecls[getMangledName(GD)] = GD;
369 }
370 }
371
372 /// List of alias we have emitted. Used to make sure that what they point to
373 /// is defined once we get to the end of the of the translation unit.
374 std::vector<GlobalDecl> Aliases;
375
376 /// List of multiversion functions to be emitted. This list is processed in
377 /// conjunction with other deferred symbols and is used to ensure that
378 /// multiversion function resolvers and ifuncs are defined and emitted.
379 std::vector<GlobalDecl> MultiVersionFuncs;
380
381 typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
382 ReplacementsTy Replacements;
383
384 /// List of global values to be replaced with something else. Used when we
385 /// want to replace a GlobalValue but can't identify it by its mangled name
386 /// anymore (because the name is already taken).
388 GlobalValReplacements;
389
390 /// Variables for which we've emitted globals containing their constant
391 /// values along with the corresponding globals, for opportunistic reuse.
392 llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants;
393
394 /// Set of global decls for which we already diagnosed mangled name conflict.
395 /// Required to not issue a warning (on a mangling conflict) multiple times
396 /// for the same decl.
397 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
398
399 /// A queue of (optional) vtables to consider emitting.
400 std::vector<const CXXRecordDecl*> DeferredVTables;
401
402 /// A queue of (optional) vtables that may be emitted opportunistically.
403 std::vector<const CXXRecordDecl *> OpportunisticVTables;
404
405 /// List of global values which are required to be present in the object file;
406 /// bitcast to i8*. This is used for forcing visibility of symbols which may
407 /// otherwise be optimized out.
408 std::vector<llvm::WeakTrackingVH> LLVMUsed;
409 std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
410
411 /// Store the list of global constructors and their respective priorities to
412 /// be emitted when the translation unit is complete.
413 CtorList GlobalCtors;
414
415 /// Store the list of global destructors and their respective priorities to be
416 /// emitted when the translation unit is complete.
417 CtorList GlobalDtors;
418
419 /// An ordered map of canonical GlobalDecls to their mangled names.
420 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
421 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
422
423 /// Global annotations.
424 std::vector<llvm::Constant*> Annotations;
425
426 /// Map used to get unique annotation strings.
427 llvm::StringMap<llvm::Constant*> AnnotationStrings;
428
429 /// Used for uniquing of annotation arguments.
430 llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
431
432 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
433
434 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
435 llvm::DenseMap<const UnnamedGlobalConstantDecl *, llvm::GlobalVariable *>
436 UnnamedGlobalConstantDeclMap;
437 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
438 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
439 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
440
441 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
442 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
443
444 /// Map used to get unique type descriptor constants for sanitizers.
445 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
446
447 /// Map used to track internal linkage functions declared within
448 /// extern "C" regions.
449 typedef llvm::MapVector<IdentifierInfo *,
450 llvm::GlobalValue *> StaticExternCMap;
451 StaticExternCMap StaticExternCValues;
452
453 /// thread_local variables defined or used in this TU.
454 std::vector<const VarDecl *> CXXThreadLocals;
455
456 /// thread_local variables with initializers that need to run
457 /// before any thread_local variable in this TU is odr-used.
458 std::vector<llvm::Function *> CXXThreadLocalInits;
459 std::vector<const VarDecl *> CXXThreadLocalInitVars;
460
461 /// Global variables with initializers that need to run before main.
462 std::vector<llvm::Function *> CXXGlobalInits;
463
464 /// When a C++ decl with an initializer is deferred, null is
465 /// appended to CXXGlobalInits, and the index of that null is placed
466 /// here so that the initializer will be performed in the correct
467 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
468 /// that we don't re-emit the initializer.
469 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
470
471 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
472 GlobalInitData;
473
474 struct GlobalInitPriorityCmp {
475 bool operator()(const GlobalInitData &LHS,
476 const GlobalInitData &RHS) const {
477 return LHS.first.priority < RHS.first.priority;
478 }
479 };
480
481 /// Global variables with initializers whose order of initialization is set by
482 /// init_priority attribute.
483 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
484
485 /// Global destructor functions and arguments that need to run on termination.
486 /// When UseSinitAndSterm is set, it instead contains sterm finalizer
487 /// functions, which also run on unloading a shared library.
488 typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
489 llvm::Constant *>
490 CXXGlobalDtorsOrStermFinalizer_t;
491 SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8>
492 CXXGlobalDtorsOrStermFinalizers;
493
494 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
495 StermFinalizerData;
496
497 struct StermFinalizerPriorityCmp {
498 bool operator()(const StermFinalizerData &LHS,
499 const StermFinalizerData &RHS) const {
500 return LHS.first.priority < RHS.first.priority;
501 }
502 };
503
504 /// Global variables with sterm finalizers whose order of initialization is
505 /// set by init_priority attribute.
506 SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers;
507
508 /// The complete set of modules that has been imported.
509 llvm::SetVector<clang::Module *> ImportedModules;
510
511 /// The set of modules for which the module initializers
512 /// have been emitted.
513 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
514
515 /// A vector of metadata strings for linker options.
516 SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
517
518 /// A vector of metadata strings for dependent libraries for ELF.
519 SmallVector<llvm::MDNode *, 16> ELFDependentLibraries;
520
521 /// @name Cache for Objective-C runtime types
522 /// @{
523
524 /// Cached reference to the class for constant strings. This value has type
525 /// int * but is actually an Obj-C class pointer.
526 llvm::WeakTrackingVH CFConstantStringClassRef;
527
528 /// The type used to describe the state of a fast enumeration in
529 /// Objective-C's for..in loop.
530 QualType ObjCFastEnumerationStateType;
531
532 /// @}
533
534 /// Lazily create the Objective-C runtime
535 void createObjCRuntime();
536
537 void createOpenCLRuntime();
538 void createOpenMPRuntime();
539 void createCUDARuntime();
540 void createHLSLRuntime();
541
542 bool isTriviallyRecursive(const FunctionDecl *F);
543 bool shouldEmitFunction(GlobalDecl GD);
544 bool shouldOpportunisticallyEmitVTables();
545 /// Map used to be sure we don't emit the same CompoundLiteral twice.
546 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
547 EmittedCompoundLiterals;
548
549 /// Map of the global blocks we've emitted, so that we don't have to re-emit
550 /// them if the constexpr evaluator gets aggressive.
551 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
552
553 /// @name Cache for Blocks Runtime Globals
554 /// @{
555
556 llvm::Constant *NSConcreteGlobalBlock = nullptr;
557 llvm::Constant *NSConcreteStackBlock = nullptr;
558
559 llvm::FunctionCallee BlockObjectAssign = nullptr;
560 llvm::FunctionCallee BlockObjectDispose = nullptr;
561
562 llvm::Type *BlockDescriptorType = nullptr;
563 llvm::Type *GenericBlockLiteralType = nullptr;
564
565 struct {
567 } Block;
568
569 GlobalDecl initializedGlobalDecl;
570
571 /// @}
572
573 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
574 llvm::Function *LifetimeStartFn = nullptr;
575
576 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
577 llvm::Function *LifetimeEndFn = nullptr;
578
579 std::unique_ptr<SanitizerMetadata> SanitizerMD;
580
581 llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
582
583 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
584
585 /// Mapping from canonical types to their metadata identifiers. We need to
586 /// maintain this mapping because identifiers may be formed from distinct
587 /// MDNodes.
588 typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap;
589 MetadataTypeMap MetadataIdMap;
590 MetadataTypeMap VirtualMetadataIdMap;
591 MetadataTypeMap GeneralizedMetadataIdMap;
592
593 llvm::DenseMap<const llvm::Constant *, llvm::GlobalVariable *> RTTIProxyMap;
594
595 // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
596 // when used with -fincremental-extensions.
597 std::pair<std::unique_ptr<CodeGenFunction>, const TopLevelStmtDecl *>
598 GlobalTopLevelStmtBlockInFlight;
599
600public:
602 const HeaderSearchOptions &headersearchopts,
603 const PreprocessorOptions &ppopts,
604 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
605 DiagnosticsEngine &Diags,
606 CoverageSourceInfo *CoverageInfo = nullptr);
607
609
610 void clear();
611
612 /// Finalize LLVM code generation.
613 void Release();
614
615 /// Return true if we should emit location information for expressions.
617
618 /// Return a reference to the configured Objective-C runtime.
620 if (!ObjCRuntime) createObjCRuntime();
621 return *ObjCRuntime;
622 }
623
624 /// Return true iff an Objective-C runtime has been configured.
625 bool hasObjCRuntime() { return !!ObjCRuntime; }
626
627 const std::string &getModuleNameHash() const { return ModuleNameHash; }
628
629 /// Return a reference to the configured OpenCL runtime.
631 assert(OpenCLRuntime != nullptr);
632 return *OpenCLRuntime;
633 }
634
635 /// Return a reference to the configured OpenMP runtime.
637 assert(OpenMPRuntime != nullptr);
638 return *OpenMPRuntime;
639 }
640
641 /// Return a reference to the configured CUDA runtime.
643 assert(CUDARuntime != nullptr);
644 return *CUDARuntime;
645 }
646
647 /// Return a reference to the configured HLSL runtime.
649 assert(HLSLRuntime != nullptr);
650 return *HLSLRuntime;
651 }
652
654 assert(ObjCData != nullptr);
655 return *ObjCData;
656 }
657
658 // Version checking functions, used to implement ObjC's @available:
659 // i32 @__isOSVersionAtLeast(i32, i32, i32)
660 llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr;
661 // i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32)
662 llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr;
663
664 InstrProfStats &getPGOStats() { return PGOStats; }
665 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
666
668 return CoverageMapping.get();
669 }
670
671 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
672 return StaticLocalDeclMap[D];
673 }
675 llvm::Constant *C) {
676 StaticLocalDeclMap[D] = C;
677 }
678
679 llvm::Constant *
681 llvm::GlobalValue::LinkageTypes Linkage);
682
683 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
684 return StaticLocalDeclGuardMap[D];
685 }
687 llvm::GlobalVariable *C) {
688 StaticLocalDeclGuardMap[D] = C;
689 }
690
691 Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant,
692 CharUnits Align);
693
694 bool lookupRepresentativeDecl(StringRef MangledName,
695 GlobalDecl &Result) const;
696
698 return AtomicSetterHelperFnMap[Ty];
699 }
701 llvm::Constant *Fn) {
702 AtomicSetterHelperFnMap[Ty] = Fn;
703 }
704
706 return AtomicGetterHelperFnMap[Ty];
707 }
709 llvm::Constant *Fn) {
710 AtomicGetterHelperFnMap[Ty] = Fn;
711 }
712
713 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
714 return TypeDescriptorMap[Ty];
715 }
716 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
717 TypeDescriptorMap[Ty] = C;
718 }
719
720 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
721
723 if (!NoObjCARCExceptionsMetadata)
724 NoObjCARCExceptionsMetadata =
725 llvm::MDNode::get(getLLVMContext(), std::nullopt);
726 return NoObjCARCExceptionsMetadata;
727 }
728
729 ASTContext &getContext() const { return Context; }
730 const LangOptions &getLangOpts() const { return LangOpts; }
732 return FS;
733 }
735 const { return HeaderSearchOpts; }
737 const { return PreprocessorOpts; }
738 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
739 llvm::Module &getModule() const { return TheModule; }
740 DiagnosticsEngine &getDiags() const { return Diags; }
741 const llvm::DataLayout &getDataLayout() const {
742 return TheModule.getDataLayout();
743 }
744 const TargetInfo &getTarget() const { return Target; }
745 const llvm::Triple &getTriple() const { return Target.getTriple(); }
746 bool supportsCOMDAT() const;
747 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
748
749 CGCXXABI &getCXXABI() const { return *ABI; }
750 llvm::LLVMContext &getLLVMContext() { return VMContext; }
751
752 bool shouldUseTBAA() const { return TBAA != nullptr; }
753
755
756 CodeGenTypes &getTypes() { return Types; }
757
758 CodeGenVTables &getVTables() { return VTables; }
759
761 return VTables.getItaniumVTableContext();
762 }
763
765 return VTables.getItaniumVTableContext();
766 }
767
769 return VTables.getMicrosoftVTableContext();
770 }
771
772 CtorList &getGlobalCtors() { return GlobalCtors; }
773 CtorList &getGlobalDtors() { return GlobalDtors; }
774
775 /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
776 /// the given type.
777 llvm::MDNode *getTBAATypeInfo(QualType QTy);
778
779 /// getTBAAAccessInfo - Get TBAA information that describes an access to
780 /// an object of the given type.
782
783 /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
784 /// access to a virtual table pointer.
785 TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
786
787 llvm::MDNode *getTBAAStructInfo(QualType QTy);
788
789 /// getTBAABaseTypeInfo - Get metadata that describes the given base access
790 /// type. Return null if the type is not suitable for use in TBAA access tags.
791 llvm::MDNode *getTBAABaseTypeInfo(QualType QTy);
792
793 /// getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
794 llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info);
795
796 /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of
797 /// type casts.
800
801 /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
802 /// purposes of conditional operator.
804 TBAAAccessInfo InfoB);
805
806 /// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the
807 /// purposes of memory transfer calls.
809 TBAAAccessInfo SrcInfo);
810
811 /// getTBAAInfoForSubobject - Get TBAA information for an access with a given
812 /// base lvalue.
814 if (Base.getTBAAInfo().isMayAlias())
816 return getTBAAAccessInfo(AccessType);
817 }
818
819 bool isTypeConstant(QualType QTy, bool ExcludeCtor, bool ExcludeDtor);
820
823
824 /// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
825 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
826 TBAAAccessInfo TBAAInfo);
827
828 /// Adds !invariant.barrier !tag to instruction
829 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
830 const CXXRecordDecl *RD);
831
832 /// Emit the given number of characters as a value of type size_t.
833 llvm::ConstantInt *getSize(CharUnits numChars);
834
835 /// Set the visibility for the given LLVM GlobalValue.
836 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
837
838 void setDSOLocal(llvm::GlobalValue *GV) const;
839
847 }
848 void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
849 void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const;
850 /// Set visibility, dllimport/dllexport and dso_local.
851 /// This must be called after dllimport/dllexport is set.
852 void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
853 void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
854
855 void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
856
857 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
858 /// variable declaration D.
859 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
860
861 /// Get LLVM TLS mode from CodeGenOptions.
862 llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const;
863
864 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
865 switch (V) {
866 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
867 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
868 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
869 }
870 llvm_unreachable("unknown visibility!");
871 }
872
873 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
874 ForDefinition_t IsForDefinition
876
877 /// Will return a global variable of the given type. If a variable with a
878 /// different type already exists then a new variable with the right type
879 /// will be created and all uses of the old variable will be replaced with a
880 /// bitcast to the new variable.
881 llvm::GlobalVariable *
882 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
883 llvm::GlobalValue::LinkageTypes Linkage,
884 llvm::Align Alignment);
885
886 llvm::Function *CreateGlobalInitOrCleanUpFunction(
887 llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI,
888 SourceLocation Loc = SourceLocation(), bool TLS = false,
889 llvm::GlobalVariable::LinkageTypes Linkage =
890 llvm::GlobalVariable::InternalLinkage);
891
892 /// Return the AST address space of the underlying global variable for D, as
893 /// determined by its declaration. Normally this is the same as the address
894 /// space of D's type, but in CUDA, address spaces are associated with
895 /// declarations, not types. If D is nullptr, return the default address
896 /// space for global variable.
897 ///
898 /// For languages without explicit address spaces, if D has default address
899 /// space, target-specific global or constant address space may be returned.
901
902 /// Return the AST address space of constant literal, which is used to emit
903 /// the constant literal as global variable in LLVM IR.
904 /// Note: This is not necessarily the address space of the constant literal
905 /// in AST. For address space agnostic language, e.g. C++, constant literal
906 /// in AST is always in default address space.
908
909 /// Return the llvm::Constant for the address of the given global variable.
910 /// If Ty is non-null and if the global doesn't exist, then it will be created
911 /// with the specified type instead of whatever the normal requested type
912 /// would be. If IsForDefinition is true, it is guaranteed that an actual
913 /// global with type Ty will be returned, not conversion of a variable with
914 /// the same mangled name but some other type.
915 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
916 llvm::Type *Ty = nullptr,
917 ForDefinition_t IsForDefinition
919
920 /// Return the address of the given function. If Ty is non-null, then this
921 /// function will use the specified type if it has to create it.
922 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
923 bool ForVTable = false,
924 bool DontDefer = false,
925 ForDefinition_t IsForDefinition
927
928 // Return the function body address of the given function.
929 llvm::Constant *GetFunctionStart(const ValueDecl *Decl);
930
931 /// Get the address of the RTTI descriptor for the given type.
932 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
933
934 /// Get the address of a GUID.
936
937 /// Get the address of a UnnamedGlobalConstant
940
941 /// Get the address of a template parameter object.
944
945 /// Get the address of the thunk for the given global decl.
946 llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
947 GlobalDecl GD);
948
949 /// Get a reference to the target of VD.
951
952 /// Returns the assumed alignment of an opaque pointer to the given class.
954
955 /// Returns the minimum object size for an object of the given class type
956 /// (or a class derived from it).
958
959 /// Returns the minimum object size for an object of the given type.
961 if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
962 return getMinimumClassObjectSize(RD);
963 return getContext().getTypeSizeInChars(Ty);
964 }
965
966 /// Returns the assumed alignment of a virtual base of a class.
968 const CXXRecordDecl *Derived,
969 const CXXRecordDecl *VBase);
970
971 /// Given a class pointer with an actual known alignment, and the
972 /// expected alignment of an object at a dynamic offset w.r.t that
973 /// pointer, return the alignment to assume at the offset.
975 const CXXRecordDecl *Class,
976 CharUnits ExpectedTargetAlign);
977
982
983 /// Returns the offset from a derived class to a class. Returns null if the
984 /// offset is 0.
985 llvm::Constant *
989
990 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
991
992 /// Fetches the global unique block count.
993 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
994
995 /// Fetches the type of a generic block descriptor.
996 llvm::Type *getBlockDescriptorType();
997
998 /// The type of a generic block literal.
999 llvm::Type *getGenericBlockLiteralType();
1000
1001 /// Gets the address of a block which requires no captures.
1002 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
1003
1004 /// Returns the address of a block which requires no caputres, or null if
1005 /// we've yet to emit the block for BE.
1006 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
1007 return EmittedGlobalBlocks.lookup(BE);
1008 }
1009
1010 /// Notes that BE's global block is available via Addr. Asserts that BE
1011 /// isn't already emitted.
1012 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
1013
1014 /// Return a pointer to a constant CFString object for the given string.
1016
1017 /// Return a pointer to a constant NSString object for the given string. Or a
1018 /// user defined String object as defined via
1019 /// -fconstant-string-class=class_name option.
1021
1022 /// Return a constant array for the given string.
1023 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
1024
1025 /// Return a pointer to a constant array for the given string literal.
1028 StringRef Name = ".str");
1029
1030 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
1033
1034 /// Returns a pointer to a character array containing the literal and a
1035 /// terminating '\0' character. The result has pointer to array type.
1036 ///
1037 /// \param GlobalName If provided, the name to use for the global (if one is
1038 /// created).
1040 GetAddrOfConstantCString(const std::string &Str,
1041 const char *GlobalName = nullptr);
1042
1043 /// Returns a pointer to a constant global variable for the given file-scope
1044 /// compound literal expression.
1046
1047 /// If it's been emitted already, returns the GlobalVariable corresponding to
1048 /// a compound literal. Otherwise, returns null.
1049 llvm::GlobalVariable *
1051
1052 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
1053 /// emitted.
1055 llvm::GlobalVariable *GV);
1056
1057 /// Returns a pointer to a global variable representing a temporary
1058 /// with static or thread storage duration.
1060 const Expr *Inner);
1061
1062 /// Retrieve the record type that describes the state of an
1063 /// Objective-C fast enumeration loop (for..in).
1065
1066 // Produce code for this constructor/destructor. This method doesn't try
1067 // to apply any ABI rules about which other constructors/destructors
1068 // are needed or if they are alias to each other.
1069 llvm::Function *codegenCXXStructor(GlobalDecl GD);
1070
1071 /// Return the address of the constructor/destructor of the given type.
1072 llvm::Constant *
1074 llvm::FunctionType *FnType = nullptr,
1075 bool DontDefer = false,
1076 ForDefinition_t IsForDefinition = NotForDefinition) {
1077 return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType,
1078 DontDefer,
1079 IsForDefinition)
1080 .getCallee());
1081 }
1082
1083 llvm::FunctionCallee getAddrAndTypeOfCXXStructor(
1084 GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
1085 llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
1086 ForDefinition_t IsForDefinition = NotForDefinition);
1087
1088 /// Given a builtin id for a function like "__builtin_fabsf", return a
1089 /// Function* for "fabsf".
1090 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
1091 unsigned BuiltinID);
1092
1093 llvm::Function *getIntrinsic(unsigned IID,
1094 ArrayRef<llvm::Type *> Tys = std::nullopt);
1095
1096 /// Emit code for a single top level declaration.
1097 void EmitTopLevelDecl(Decl *D);
1098
1099 /// Stored a deferred empty coverage mapping for an unused
1100 /// and thus uninstrumented top level declaration.
1102
1103 /// Remove the deferred empty coverage mapping as this
1104 /// declaration is actually instrumented.
1105 void ClearUnusedCoverageMapping(const Decl *D);
1106
1107 /// Emit all the deferred coverage mappings
1108 /// for the uninstrumented functions.
1110
1111 /// Emit an alias for "main" if it has no arguments (needed for wasm).
1112 void EmitMainVoidAlias();
1113
1114 /// Tell the consumer that this variable has been instantiated.
1116
1117 /// If the declaration has internal linkage but is inside an
1118 /// extern "C" linkage specification, prepare to emit an alias for it
1119 /// to the expected name.
1120 template<typename SomeDecl>
1121 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
1122
1123 /// Add a global to a list to be added to the llvm.used metadata.
1124 void addUsedGlobal(llvm::GlobalValue *GV);
1125
1126 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1127 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
1128
1129 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1130 void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
1131
1132 /// Add a destructor and object to add to the C++ global destructor function.
1133 void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
1134 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1135 DtorFn.getCallee(), Object);
1136 }
1137
1138 /// Add an sterm finalizer to the C++ global cleanup function.
1139 void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) {
1140 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1141 DtorFn.getCallee(), nullptr);
1142 }
1143
1144 /// Add an sterm finalizer to its own llvm.global_dtors entry.
1145 void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer,
1146 int Priority) {
1147 AddGlobalDtor(StermFinalizer, Priority);
1148 }
1149
1150 void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer,
1151 int Priority) {
1153 PrioritizedCXXStermFinalizers.size());
1154 PrioritizedCXXStermFinalizers.push_back(
1155 std::make_pair(Key, StermFinalizer));
1156 }
1157
1158 /// Create or return a runtime function declaration with the specified type
1159 /// and name. If \p AssumeConvergent is true, the call will have the
1160 /// convergent attribute added.
1161 llvm::FunctionCallee
1162 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
1163 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1164 bool Local = false, bool AssumeConvergent = false);
1165
1166 /// Create a new runtime global variable with the specified type and name.
1167 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
1168 StringRef Name);
1169
1170 ///@name Custom Blocks Runtime Interfaces
1171 ///@{
1172
1173 llvm::Constant *getNSConcreteGlobalBlock();
1174 llvm::Constant *getNSConcreteStackBlock();
1175 llvm::FunctionCallee getBlockObjectAssign();
1176 llvm::FunctionCallee getBlockObjectDispose();
1177
1178 ///@}
1179
1180 llvm::Function *getLLVMLifetimeStartFn();
1181 llvm::Function *getLLVMLifetimeEndFn();
1182
1183 // Make sure that this type is translated.
1184 void UpdateCompletedType(const TagDecl *TD);
1185
1186 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
1187
1188 /// Emit type info if type of an expression is a variably modified
1189 /// type. Also emit proper debug info for cast types.
1191 CodeGenFunction *CGF = nullptr);
1192
1193 /// Return the result of value-initializing the given type, i.e. a null
1194 /// expression of the given type. This is usually, but not always, an LLVM
1195 /// null constant.
1196 llvm::Constant *EmitNullConstant(QualType T);
1197
1198 /// Return a null constant appropriate for zero-initializing a base class with
1199 /// the given type. This is usually, but not always, an LLVM null constant.
1200 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
1201
1202 /// Emit a general error that something can't be done.
1203 void Error(SourceLocation loc, StringRef error);
1204
1205 /// Print out an error that codegen doesn't support the specified stmt yet.
1206 void ErrorUnsupported(const Stmt *S, const char *Type);
1207
1208 /// Print out an error that codegen doesn't support the specified decl yet.
1209 void ErrorUnsupported(const Decl *D, const char *Type);
1210
1211 /// Set the attributes on the LLVM function for the given decl and function
1212 /// info. This applies attributes necessary for handling the ABI as well as
1213 /// user specified attributes like section.
1214 void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1215 const CGFunctionInfo &FI);
1216
1217 /// Set the LLVM function attributes (sext, zext, etc).
1219 llvm::Function *F, bool IsThunk);
1220
1221 /// Set the LLVM function attributes which only apply to a function
1222 /// definition.
1223 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
1224
1225 /// Set the LLVM function attributes that represent floating point
1226 /// environment.
1227 void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F);
1228
1229 /// Return true iff the given type uses 'sret' when used as a return type.
1230 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1231
1232 /// Return true iff the given type uses an argument slot when 'sret' is used
1233 /// as a return type.
1235
1236 /// Return true iff the given type uses 'fpret' when used as a return type.
1237 bool ReturnTypeUsesFPRet(QualType ResultType);
1238
1239 /// Return true iff the given type uses 'fp2ret' when used as a return type.
1240 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1241
1242 /// Get the LLVM attributes and calling convention to use for a particular
1243 /// function type.
1244 ///
1245 /// \param Name - The function name.
1246 /// \param Info - The function type information.
1247 /// \param CalleeInfo - The callee information these attributes are being
1248 /// constructed for. If valid, the attributes applied to this decl may
1249 /// contribute to the function attributes and calling convention.
1250 /// \param Attrs [out] - On return, the attribute list to use.
1251 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
1252 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
1253 CGCalleeInfo CalleeInfo,
1254 llvm::AttributeList &Attrs, unsigned &CallingConv,
1255 bool AttrOnCallSite, bool IsThunk);
1256
1257 /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
1258 /// though we had emitted it ourselves. We remove any attributes on F that
1259 /// conflict with the attributes we add here.
1260 ///
1261 /// This is useful for adding attrs to bitcode modules that you want to link
1262 /// with but don't control, such as CUDA's libdevice. When linking with such
1263 /// a bitcode library, you might want to set e.g. its functions'
1264 /// "unsafe-fp-math" attribute to match the attr of the functions you're
1265 /// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
1266 /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
1267 /// will propagate unsafe-fp-math=false up to every transitive caller of a
1268 /// function in the bitcode library!
1269 ///
1270 /// With the exception of fast-math attrs, this will only make the attributes
1271 /// on the function more conservative. But it's unsafe to call this on a
1272 /// function which relies on particular fast-math attributes for correctness.
1273 /// It's up to you to ensure that this is safe.
1274 void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
1275 void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
1276 bool WillInternalize);
1277
1278 /// Like the overload taking a `Function &`, but intended specifically
1279 /// for frontends that want to build on Clang's target-configuration logic.
1280 void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);
1281
1282 StringRef getMangledName(GlobalDecl GD);
1283 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
1284 const GlobalDecl getMangledNameDecl(StringRef);
1285
1286 void EmitTentativeDefinition(const VarDecl *D);
1287
1288 void EmitExternalDeclaration(const VarDecl *D);
1289
1290 void EmitVTable(CXXRecordDecl *Class);
1291
1292 void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
1293
1294 /// Appends Opts to the "llvm.linker.options" metadata value.
1295 void AppendLinkerOptions(StringRef Opts);
1296
1297 /// Appends a detect mismatch command to the linker options.
1298 void AddDetectMismatch(StringRef Name, StringRef Value);
1299
1300 /// Appends a dependent lib to the appropriate metadata value.
1301 void AddDependentLib(StringRef Lib);
1302
1303
1304 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1305
1306 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1307 F->setLinkage(getFunctionLinkage(GD));
1308 }
1309
1310 /// Return the appropriate linkage for the vtable, VTT, and type information
1311 /// of the given class.
1312 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1313
1314 /// Return the store size, in character units, of the given LLVM type.
1315 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1316
1317 /// Returns LLVM linkage for a declarator.
1318 llvm::GlobalValue::LinkageTypes
1320 bool IsConstantVariable);
1321
1322 /// Returns LLVM linkage for a declarator.
1323 llvm::GlobalValue::LinkageTypes
1324 getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1325
1326 /// Emit all the global annotations.
1327 void EmitGlobalAnnotations();
1328
1329 /// Emit an annotation string.
1330 llvm::Constant *EmitAnnotationString(StringRef Str);
1331
1332 /// Emit the annotation's translation unit.
1333 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1334
1335 /// Emit the annotation line number.
1336 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1337
1338 /// Emit additional args of the annotation.
1339 llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr);
1340
1341 /// Generate the llvm::ConstantStruct which contains the annotation
1342 /// information for a given GlobalValue. The annotation struct is
1343 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1344 /// GlobalValue being annotated. The second field is the constant string
1345 /// created from the AnnotateAttr's annotation. The third field is a constant
1346 /// string containing the name of the translation unit. The fourth field is
1347 /// the line number in the file of the annotated value declaration.
1348 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1349 const AnnotateAttr *AA,
1350 SourceLocation L);
1351
1352 /// Add global annotations that are set on D, for the global GV. Those
1353 /// annotations are emitted during finalization of the LLVM code.
1354 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1355
1356 bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
1357 SourceLocation Loc) const;
1358
1359 bool isInNoSanitizeList(SanitizerMask Kind, llvm::GlobalVariable *GV,
1360 SourceLocation Loc, QualType Ty,
1361 StringRef Category = StringRef()) const;
1362
1363 /// Imbue XRay attributes to a function, applying the always/never attribute
1364 /// lists in the process. Returns true if we did imbue attributes this way,
1365 /// false otherwise.
1366 bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
1367 StringRef Category = StringRef()) const;
1368
1369 /// \returns true if \p Fn at \p Loc should be excluded from profile
1370 /// instrumentation by the SCL passed by \p -fprofile-list.
1372 isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
1373
1374 /// \returns true if \p Fn at \p Loc should be excluded from profile
1375 /// instrumentation.
1377 isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
1378 SourceLocation Loc) const;
1379
1381 return SanitizerMD.get();
1382 }
1383
1385 DeferredVTables.push_back(RD);
1386 }
1387
1388 /// Emit code for a single global function or var decl. Forward declarations
1389 /// are emitted lazily.
1390 void EmitGlobal(GlobalDecl D);
1391
1393
1394 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1395
1396 /// Set attributes which are common to any form of a global definition (alias,
1397 /// Objective-C method, function, global variable).
1398 ///
1399 /// NOTE: This should only be called for definitions.
1400 void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV);
1401
1402 void addReplacement(StringRef Name, llvm::Constant *C);
1403
1404 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1405
1406 /// Emit a code for threadprivate directive.
1407 /// \param D Threadprivate declaration.
1409
1410 /// Emit a code for declare reduction construct.
1412 CodeGenFunction *CGF = nullptr);
1413
1414 /// Emit a code for declare mapper construct.
1416 CodeGenFunction *CGF = nullptr);
1417
1418 /// Emit a code for requires directive.
1419 /// \param D Requires declaration
1420 void EmitOMPRequiresDecl(const OMPRequiresDecl *D);
1421
1422 /// Emit a code for the allocate directive.
1423 /// \param D The allocate declaration
1424 void EmitOMPAllocateDecl(const OMPAllocateDecl *D);
1425
1426 /// Return the alignment specified in an allocate directive, if present.
1427 std::optional<CharUnits> getOMPAllocateAlignment(const VarDecl *VD);
1428
1429 /// Returns whether the given record has hidden LTO visibility and therefore
1430 /// may participate in (single-module) CFI and whole-program vtable
1431 /// optimization.
1432 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
1433
1434 /// Returns whether the given record has public LTO visibility (regardless of
1435 /// -lto-whole-program-visibility) and therefore may not participate in
1436 /// (single-module) CFI and whole-program vtable optimization.
1438
1439 /// Returns the vcall visibility of the given type. This is the scope in which
1440 /// a virtual function call could be made which ends up being dispatched to a
1441 /// member function of this class. This scope can be wider than the visibility
1442 /// of the class itself when the class has a more-visible dynamic base class.
1443 /// The client should pass in an empty Visited set, which is used to prevent
1444 /// redundant recursive processing.
1445 llvm::GlobalObject::VCallVisibility
1448
1449 /// Emit type metadata for the given vtable using the given layout.
1451 llvm::GlobalVariable *VTable,
1452 const VTableLayout &VTLayout);
1453
1454 llvm::Type *getVTableComponentType() const;
1455
1456 /// Generate a cross-DSO type identifier for MD.
1457 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
1458
1459 /// Generate a KCFI type identifier for T.
1460 llvm::ConstantInt *CreateKCFITypeId(QualType T);
1461
1462 /// Create a metadata identifier for the given type. This may either be an
1463 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1464 /// internal identifiers).
1465 llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1466
1467 /// Create a metadata identifier that is intended to be used to check virtual
1468 /// calls via a member function pointer.
1470
1471 /// Create a metadata identifier for the generalization of the given type.
1472 /// This may either be an MDString (for external identifiers) or a distinct
1473 /// unnamed MDNode (for internal identifiers).
1475
1476 /// Create and attach type metadata to the given function.
1478 llvm::Function *F);
1479
1480 /// Set type metadata to the given function.
1481 void setKCFIType(const FunctionDecl *FD, llvm::Function *F);
1482
1483 /// Emit KCFI type identifier constants and remove unused identifiers.
1484 void finalizeKCFITypes();
1485
1486 /// Whether this function's return type has no side effects, and thus may
1487 /// be trivially discarded if it is unused.
1488 bool MayDropFunctionReturn(const ASTContext &Context,
1489 QualType ReturnType) const;
1490
1491 /// Returns whether this module needs the "all-vtables" type identifier.
1492 bool NeedAllVtablesTypeId() const;
1493
1494 /// Create and attach type metadata for the given vtable.
1495 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1496 const CXXRecordDecl *RD);
1497
1498 /// Return a vector of most-base classes for RD. This is used to implement
1499 /// control flow integrity checks for member function pointers.
1500 ///
1501 /// A most-base class of a class C is defined as a recursive base class of C,
1502 /// including C itself, that does not have any bases.
1503 std::vector<const CXXRecordDecl *>
1505
1506 llvm::GlobalVariable *
1507 GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr);
1508
1509 /// Get the declaration of std::terminate for the platform.
1510 llvm::FunctionCallee getTerminateFn();
1511
1512 llvm::SanitizerStatReport &getSanStats();
1513
1514 llvm::Value *
1516
1517 /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
1518 /// information in the program executable. The argument information stored
1519 /// includes the argument name, its type, the address and access qualifiers
1520 /// used. This helper can be used to generate metadata for source code kernel
1521 /// function as well as generated implicitly kernels. If a kernel is generated
1522 /// implicitly null value has to be passed to the last two parameters,
1523 /// otherwise all parameters must have valid non-null values.
1524 /// \param FN is a pointer to IR function being generated.
1525 /// \param FD is a pointer to function declaration if any.
1526 /// \param CGF is a pointer to CodeGenFunction that generates this function.
1527 void GenKernelArgMetadata(llvm::Function *FN,
1528 const FunctionDecl *FD = nullptr,
1529 CodeGenFunction *CGF = nullptr);
1530
1531 /// Get target specific null pointer.
1532 /// \param T is the LLVM type of the null pointer.
1533 /// \param QT is the clang QualType of the null pointer.
1534 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1535
1537 LValueBaseInfo *BaseInfo = nullptr,
1538 TBAAAccessInfo *TBAAInfo = nullptr,
1539 bool forPointeeType = false);
1541 LValueBaseInfo *BaseInfo = nullptr,
1542 TBAAAccessInfo *TBAAInfo = nullptr);
1543 bool stopAutoInit();
1544
1545 /// Print the postfix for externalized static variable or kernels for single
1546 /// source offloading languages CUDA and HIP. The unique postfix is created
1547 /// using either the CUID argument, or the file's UniqueID and active macros.
1548 /// The fallback method without a CUID requires that the offloading toolchain
1549 /// does not define separate macros via the -cc1 options.
1550 void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
1551 const Decl *D) const;
1552
1553 /// Move some lazily-emitted states to the NewBuilder. This is especially
1554 /// essential for the incremental parsing environment like Clang Interpreter,
1555 /// because we'll lose all important information after each repl.
1556 void moveLazyEmissionStates(CodeGenModule *NewBuilder);
1557
1558private:
1559 llvm::Constant *GetOrCreateLLVMFunction(
1560 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1561 bool DontDefer = false, bool IsThunk = false,
1562 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1563 ForDefinition_t IsForDefinition = NotForDefinition);
1564
1565 // References to multiversion functions are resolved through an implicitly
1566 // defined resolver function. This function is responsible for creating
1567 // the resolver symbol for the provided declaration. The value returned
1568 // will be for an ifunc (llvm::GlobalIFunc) if the current target supports
1569 // that feature and for a regular function (llvm::GlobalValue) otherwise.
1570 llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD);
1571
1572 // In scenarios where a function is not known to be a multiversion function
1573 // until a later declaration, it is sometimes necessary to change the
1574 // previously created mangled name to align with requirements of whatever
1575 // multiversion function kind the function is now known to be. This function
1576 // is responsible for performing such mangled name updates.
1577 void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD,
1578 StringRef &CurName);
1579
1580 llvm::Constant *
1581 GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, LangAS AddrSpace,
1582 const VarDecl *D,
1583 ForDefinition_t IsForDefinition = NotForDefinition);
1584
1585 bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
1586 llvm::AttrBuilder &AttrBuilder);
1587 void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
1588
1589 /// Set function attributes for a function declaration.
1590 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1591 bool IsIncompleteFunction, bool IsThunk);
1592
1593 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1594
1595 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1596 void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1597
1598 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1599 void EmitExternalVarDeclaration(const VarDecl *D);
1600 void EmitAliasDefinition(GlobalDecl GD);
1601 void emitIFuncDefinition(GlobalDecl GD);
1602 void emitCPUDispatchDefinition(GlobalDecl GD);
1603 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1604 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1605
1606 // C++ related functions.
1607
1608 void EmitDeclContext(const DeclContext *DC);
1609 void EmitLinkageSpec(const LinkageSpecDecl *D);
1610 void EmitTopLevelStmt(const TopLevelStmtDecl *D);
1611
1612 /// Emit the function that initializes C++ thread_local variables.
1613 void EmitCXXThreadLocalInitFunc();
1614
1615 /// Emit the function that initializes global variables for a C++ Module.
1616 void EmitCXXModuleInitFunc(clang::Module *Primary);
1617
1618 /// Emit the function that initializes C++ globals.
1619 void EmitCXXGlobalInitFunc();
1620
1621 /// Emit the function that performs cleanup associated with C++ globals.
1622 void EmitCXXGlobalCleanUpFunc();
1623
1624 /// Emit the function that initializes the specified global (if PerformInit is
1625 /// true) and registers its destructor.
1626 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1627 llvm::GlobalVariable *Addr,
1628 bool PerformInit);
1629
1630 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1631 llvm::Function *InitFunc, InitSegAttr *ISA);
1632
1633 // FIXME: Hardcoding priority here is gross.
1634 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1635 unsigned LexOrder = ~0U,
1636 llvm::Constant *AssociatedData = nullptr);
1637 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
1638 bool IsDtorAttrFunc = false);
1639
1640 /// EmitCtorList - Generates a global array of functions and priorities using
1641 /// the given list and name. This array will have appending linkage and is
1642 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1643 void EmitCtorList(CtorList &Fns, const char *GlobalName);
1644
1645 /// Emit any needed decls for which code generation was deferred.
1646 void EmitDeferred();
1647
1648 /// Try to emit external vtables as available_externally if they have emitted
1649 /// all inlined virtual functions. It runs after EmitDeferred() and therefore
1650 /// is not allowed to create new references to things that need to be emitted
1651 /// lazily.
1652 void EmitVTablesOpportunistically();
1653
1654 /// Call replaceAllUsesWith on all pairs in Replacements.
1655 void applyReplacements();
1656
1657 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1658 void applyGlobalValReplacements();
1659
1660 void checkAliases();
1661
1662 std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit;
1663
1664 /// Register functions annotated with __attribute__((destructor)) using
1665 /// __cxa_atexit, if it is available, or atexit otherwise.
1666 void registerGlobalDtorsWithAtExit();
1667
1668 // When using sinit and sterm functions, unregister
1669 // __attribute__((destructor)) annotated functions which were previously
1670 // registered by the atexit subroutine using unatexit.
1671 void unregisterGlobalDtorsWithUnAtExit();
1672
1673 /// Emit deferred multiversion function resolvers and associated variants.
1674 void emitMultiVersionFunctions();
1675
1676 /// Emit any vtables which we deferred and still have a use for.
1677 void EmitDeferredVTables();
1678
1679 /// Emit a dummy function that reference a CoreFoundation symbol when
1680 /// @available is used on Darwin.
1681 void emitAtAvailableLinkGuard();
1682
1683 /// Emit the llvm.used and llvm.compiler.used metadata.
1684 void emitLLVMUsed();
1685
1686 /// For C++20 Itanium ABI, emit the initializers for the module.
1687 void EmitModuleInitializers(clang::Module *Primary);
1688
1689 /// Emit the link options introduced by imported modules.
1690 void EmitModuleLinkOptions();
1691
1692 /// Helper function for EmitStaticExternCAliases() to redirect ifuncs that
1693 /// have a resolver name that matches 'Elem' to instead resolve to the name of
1694 /// 'CppFunc'. This redirection is necessary in cases where 'Elem' has a name
1695 /// that will be emitted as an alias of the name bound to 'CppFunc'; ifuncs
1696 /// may not reference aliases. Redirection is only performed if 'Elem' is only
1697 /// used by ifuncs in which case, 'Elem' is destroyed. 'true' is returned if
1698 /// redirection is successful, and 'false' is returned otherwise.
1699 bool CheckAndReplaceExternCIFuncs(llvm::GlobalValue *Elem,
1700 llvm::GlobalValue *CppFunc);
1701
1702 /// Emit aliases for internal-linkage declarations inside "C" language
1703 /// linkage specifications, giving them the "expected" name where possible.
1704 void EmitStaticExternCAliases();
1705
1706 void EmitDeclMetadata();
1707
1708 /// Emit the Clang version as llvm.ident metadata.
1709 void EmitVersionIdentMetadata();
1710
1711 /// Emit the Clang commandline as llvm.commandline metadata.
1712 void EmitCommandLineMetadata();
1713
1714 /// Emit the module flag metadata used to pass options controlling the
1715 /// the backend to LLVM.
1716 void EmitBackendOptionsMetadata(const CodeGenOptions &CodeGenOpts);
1717
1718 /// Emits OpenCL specific Metadata e.g. OpenCL version.
1719 void EmitOpenCLMetadata();
1720
1721 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1722 /// .gcda files in a way that persists in .bc files.
1723 void EmitCoverageFile();
1724
1725 /// Determine whether the definition must be emitted; if this returns \c
1726 /// false, the definition can be emitted lazily if it's used.
1727 bool MustBeEmitted(const ValueDecl *D);
1728
1729 /// Determine whether the definition can be emitted eagerly, or should be
1730 /// delayed until the end of the translation unit. This is relevant for
1731 /// definitions whose linkage can change, e.g. implicit function instantions
1732 /// which may later be explicitly instantiated.
1733 bool MayBeEmittedEagerly(const ValueDecl *D);
1734
1735 /// Check whether we can use a "simpler", more core exceptions personality
1736 /// function.
1737 void SimplifyPersonality();
1738
1739 /// Helper function for getDefaultFunctionAttributes. Builds a set of function
1740 /// attributes which can be simply added to a function.
1741 void getTrivialDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1742 bool AttrOnCallSite,
1743 llvm::AttrBuilder &FuncAttrs);
1744
1745 /// Helper function for ConstructAttributeList and
1746 /// addDefaultFunctionDefinitionAttributes. Builds a set of function
1747 /// attributes to add to a function with the given properties.
1748 void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1749 bool AttrOnCallSite,
1750 llvm::AttrBuilder &FuncAttrs);
1751
1752 llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
1753 StringRef Suffix);
1754};
1755
1756} // end namespace CodeGen
1757} // end namespace clang
1758
1759#endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
Enums/classes describing ABI related information about constructors, destructors and thunks.
#define V(N, I)
Definition: ASTContext.h:3230
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
int Priority
Definition: Format.cpp:2800
unsigned Offset
Definition: Format.cpp:2798
int Category
Definition: Format.cpp:2799
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:168
Defines the clang::LangOptions interface.
Defines the clang::Module class, which describes a module in the source code.
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Attr - This represents one attribute.
Definition: Attr.h:40
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4355
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6025
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2755
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3554
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
An aligned address.
Definition: Address.h:29
A pair of helper functions for a __block variable.
void Profile(llvm::FoldingSetNodeID &id) const
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src)=0
BlockByrefHelpers(CharUnits alignment)
virtual bool needsCopy() const
CharUnits Alignment
The alignment of the field.
virtual void emitDispose(CodeGenFunction &CGF, Address field)=0
BlockByrefHelpers(const BlockByrefHelpers &)=default
virtual bool needsDispose() const
virtual void profileImpl(llvm::FoldingSetNodeID &id) const =0
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
Abstract information about a function or function prototype.
Definition: CGCall.h:38
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
CGFunctionInfo - Class to encapsulate the information about a function definition.
Implements runtime-specific code generation functions.
Definition: CGObjCRuntime.h:65
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
llvm::FunctionCallee getBlockObjectAssign()
Definition: CGBlocks.cpp:2872
const PreprocessorOptions & getPreprocessorOpts() const
ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD)
Get the address of a GUID.
void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer, int Priority)
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object)
Add a destructor and object to add to the C++ global destructor function.
llvm::FoldingSet< BlockByrefHelpers > ByrefHelpersCache
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
void UpdateCompletedType(const TagDecl *TD)
llvm::MDNode * getTBAAAccessTagInfo(TBAAAccessInfo Info)
getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
llvm::MDNode * getNoObjCARCExceptionsMetadata()
void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer, int Priority)
Add an sterm finalizer to its own llvm.global_dtors entry.
llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const
Get LLVM TLS mode from CodeGenOptions.
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
Definition: CGExpr.cpp:1029
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::GlobalObject::VCallVisibility GetVCallVisibilityLevel(const CXXRecordDecl *RD, llvm::DenseSet< const CXXRecordDecl * > &Visited)
Returns the vcall visibility of the given type.
Definition: CGVTables.cpp:1250
llvm::MDNode * getTBAAStructInfo(QualType QTy)
CGHLSLRuntime & getHLSLRuntime()
Return a reference to the configured HLSL runtime.
llvm::Constant * EmitAnnotationArgs(const AnnotateAttr *Attr)
Emit additional args of the annotation.
llvm::Module & getModule() const
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CGDebugInfo * getModuleDebugInfo()
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression.
bool NeedAllVtablesTypeId() const
Returns whether this module needs the "all-vtables" type identifier.
void addCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
std::vector< const CXXRecordDecl * > getMostBaseClasses(const CXXRecordDecl *RD)
Return a vector of most-base classes for RD.
CodeGenVTables & getVTables()
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type.
llvm::Function * getLLVMLifetimeStartFn()
Lazily declare the @llvm.lifetime.start intrinsic.
Definition: CGDecl.cpp:2413
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn)
Add an sterm finalizer to the C++ global cleanup function.
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C)
bool getExpressionLocationsEnabled() const
Return true if we should emit location information for expressions.
CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD)
Returns the minimum object size for an object of the given class type (or a class derived from it).
Definition: CGClass.cpp:58
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C)
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Definition: CGCXX.cpp:221
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
Definition: CGDecl.cpp:1119
void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const
const IntrusiveRefCntPtr< llvm::vfs::FileSystem > & getFileSystem() const
void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr)
Notes that BE's global block is available via Addr.
Definition: CGBlocks.cpp:1280
void setStaticLocalDeclGuardAddress(const VarDecl *D, llvm::GlobalVariable *C)
bool ReturnTypeUsesFPRet(QualType ResultType)
Return true iff the given type uses 'fpret' when used as a return type.
Definition: CGCall.cpp:1584
void EmitMainVoidAlias()
Emit an alias for "main" if it has no arguments (needed for wasm).
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, const CXXRecordDecl *RD)
Adds !invariant.barrier !tag to instruction.
llvm::Constant * getBuiltinLibFunction(const FunctionDecl *FD, unsigned BuiltinID)
Given a builtin id for a function like "__builtin_fabsf", return a Function* for "fabsf".
Definition: CGBuiltin.cpp:92
DiagnosticsEngine & getDiags() const
bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
bool isPaddedAtomicType(QualType type)
ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal)
Return a pointer to a constant NSString object for the given string.
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
llvm::Constant * EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, SourceLocation L)
Generate the llvm::ConstantStruct which contains the annotation information for a given GlobalValue.
llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, bool IsConstantVariable)
Returns LLVM linkage for a declarator.
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, TBAAAccessInfo SrcInfo)
mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the purposes of memory transfer call...
llvm::Type * getBlockDescriptorType()
Fetches the type of a generic block descriptor.
Definition: CGBlocks.cpp:1112
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
Definition: CGBlocks.cpp:1288
llvm::Constant * getAtomicGetterHelperFnMap(QualType Ty)
const LangOptions & getLangOpts() const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
int getUniqueBlockCount()
Fetches the global unique block count.
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
QualType getObjCFastEnumerationStateType()
Retrieve the record type that describes the state of an Objective-C fast enumeration loop (for....
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
bool shouldMapVisibilityToDLLExport(const NamedDecl *D) const
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
const std::string & getModuleNameHash() const
const TargetInfo & getTarget() const
void EmitGlobal(GlobalDecl D)
Emit code for a single global function or var decl.
llvm::GlobalVariable * getStaticLocalDeclGuardAddress(const VarDecl *D)
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
llvm::Constant * getTypeDescriptorFromMap(QualType Ty)
llvm::IndexedInstrProfReader * getPGOReader() const
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "llvm.linker.options" metadata value.
bool hasObjCRuntime()
Return true iff an Objective-C runtime has been configured.
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the appropriate metadata value.
void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F, bool WillInternalize)
Apply default attributes to F, accounting for merge semantics of attributes that should not overwrite...
Definition: CGCall.cpp:2023
void Release()
Finalize LLVM code generation.
llvm::FunctionCallee IsOSVersionAtLeastFn
ProfileList::ExclusionType isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
void EmitVTableTypeMetadata(const CXXRecordDecl *RD, llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
Definition: CGVTables.cpp:1284
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
void EmitOMPAllocateDecl(const OMPAllocateDecl *D)
Emit a code for the allocate directive.
Definition: CGDecl.cpp:2669
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
CoverageMappingModuleGen * getCoverageMapping() const
llvm::Constant * GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd)
Returns the offset from a derived class to a class.
Definition: CGClass.cpp:198
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
Definition: CGCXX.cpp:34
llvm::Constant * getMemberPointerConstant(const UnaryOperator *e)
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Definition: CGVTables.cpp:1238
const llvm::DataLayout & getDataLayout() const
llvm::Constant * getNSConcreteGlobalBlock()
Definition: CGBlocks.cpp:2885
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
Definition: CGClass.cpp:170
ObjCEntrypoints & getObjCEntrypoints() const
void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F)
Set the LLVM function attributes that represent floating point environment.
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table poi...
CGCXXABI & getCXXABI() const
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
Definition: CGClass.cpp:75
llvm::Constant * GetFunctionStart(const ValueDecl *Decl)
llvm::GlobalVariable * getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E)
If it's been emitted already, returns the GlobalVariable corresponding to a compound literal.
llvm::GlobalVariable * GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr)
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
void EmitTentativeDefinition(const VarDecl *D)
bool ReturnTypeUsesFP2Ret(QualType ResultType)
Return true iff the given type uses 'fp2ret' when used as a return type.
Definition: CGCall.cpp:1601
void EmitDeferredUnusedCoverageMappings()
Emit all the deferred coverage mappings for the uninstrumented functions.
void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process.
SanitizerMetadata * getSanitizerMetadata()
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
void addDefaultFunctionDefinitionAttributes(llvm::Function &F)
Adds attributes to F according to our CodeGenOptions and LangOptions, as though we had emitted it our...
Definition: CGCall.cpp:2013
void EmitGlobalAnnotations()
Emit all the global annotations.
llvm::Constant * getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE)
Returns the address of a block which requires no caputres, or null if we've yet to emit the block for...
llvm::Function * codegenCXXStructor(GlobalDecl GD)
Definition: CGCXX.cpp:207
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:39
const llvm::Triple & getTriple() const
void setAtomicSetterHelperFnMap(QualType Ty, llvm::Constant *Fn)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition: CGDecl.cpp:244
void AddDeferredUnusedCoverageMapping(Decl *D)
Stored a deferred empty coverage mapping for an unused and thus uninstrumented top level declaration.
bool AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD)
Returns whether the given record has public LTO visibility (regardless of -lto-whole-program-visibili...
Definition: CGVTables.cpp:1214
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV)
If the declaration has internal linkage but is inside an extern "C" linkage specification,...
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
llvm::Constant * getAtomicSetterHelperFnMap(QualType Ty)
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType)
getTBAAInfoForSubobject - Get TBAA information for an access with a given base lvalue.
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI)
Return true iff the given type uses an argument slot when 'sret' is used as a return type.
Definition: CGCall.cpp:1579
void EmitVTable(CXXRecordDecl *Class)
This is a callback from Sema to tell us that a particular vtable is required to be emitted in this tr...
Definition: CGVTables.cpp:1124
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite, bool IsThunk)
Get the LLVM attributes and calling convention to use for a particular function type.
Definition: CGCall.cpp:2236
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, const CXXRecordDecl *Class, CharUnits ExpectedTargetAlign)
Given a class pointer with an actual known alignment, and the expected alignment of an object at a dy...
Definition: CGClass.cpp:90
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
InstrProfStats & getPGOStats()
ProfileList::ExclusionType isFunctionBlockedFromProfileInstr(llvm::Function *Fn, SourceLocation Loc) const
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D.
ItaniumVTableContext & getItaniumVTableContext()
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
ASTContext & getContext() const
ConstantAddress GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO)
Get the address of a template parameter object.
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D)
Emit a code for threadprivate directive.
llvm::Constant * getNSConcreteStackBlock()
Definition: CGBlocks.cpp:2895
ConstantAddress GetAddrOfUnnamedGlobalConstantDecl(const UnnamedGlobalConstantDecl *GCD)
Get the address of a UnnamedGlobalConstant.
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purposes of type casts.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
MicrosoftVTableContext & getMicrosoftVTableContext()
const HeaderSearchOptions & getHeaderSearchOpts() const
llvm::SanitizerStatReport & getSanStats()
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
llvm::Type * getVTableComponentType() const
Definition: CGVTables.cpp:690
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
Definition: CGDecl.cpp:2657
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the @llvm.lifetime.end intrinsic.
Definition: CGDecl.cpp:2422
void EmitExternalDeclaration(const VarDecl *D)
void RefreshTypeCacheForClass(const CXXRecordDecl *Class)
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, llvm::GlobalVariable *GV)
Notes that CLE's GlobalVariable is GV.
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
Definition: CGDecl.cpp:2665
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD)
Tell the consumer that this variable has been instantiated.
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
Definition: CGCall.cpp:1574
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
std::optional< CharUnits > getOMPAllocateAlignment(const VarDecl *VD)
Return the alignment specified in an allocate directive, if present.
Definition: CGDecl.cpp:2724
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, llvm::Align Alignment)
Will return a global variable of the given type.
llvm::FunctionCallee getTerminateFn()
Get the declaration of std::terminate for the platform.
Definition: CGException.cpp:63
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
llvm::FunctionCallee getBlockObjectDispose()
Definition: CGBlocks.cpp:2859
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purposes of conditional ope...
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void GenKernelArgMetadata(llvm::Function *FN, const FunctionDecl *FD=nullptr, CodeGenFunction *CGF=nullptr)
OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument information in the program executab...
void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F)
Create and attach type metadata to the given function.
void setKCFIType(const FunctionDecl *FD, llvm::Function *F)
Set type metadata to the given function.
void setAtomicGetterHelperFnMap(QualType Ty, llvm::Constant *Fn)
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
Definition: CGDecl.cpp:2650
const ItaniumVTableContext & getItaniumVTableContext() const
void AddDetectMismatch(StringRef Name, StringRef Value)
Appends a detect mismatch command to the linker options.
void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const
bool isTypeConstant(QualType QTy, bool ExcludeCtor, bool ExcludeDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
llvm::Value * createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF)
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
Definition: CGVTables.cpp:1031
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
void addDeferredVTable(const CXXRecordDecl *RD)
llvm::Type * getGenericBlockLiteralType()
The type of a generic block literal.
Definition: CGBlocks.cpp:1144
CharUnits getMinimumObjectSize(QualType Ty)
Returns the minimum object size for an object of the given type.
void addReplacement(StringRef Name, llvm::Constant *C)
llvm::ConstantInt * CreateKCFITypeId(QualType T)
Generate a KCFI type identifier for T.
llvm::FunctionCallee IsPlatformVersionAtLeastFn
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::Metadata * CreateMetadataIdentifierForVirtualMemPtrType(QualType T)
Create a metadata identifier that is intended to be used to check virtual calls via a member function...
llvm::Constant * getStaticLocalDeclAddress(const VarDecl *D)
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType) const
Whether this function's return type has no side effects, and thus may be trivially discarded if it is...
Definition: CGCall.cpp:1788
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
const GlobalDecl getMangledNameDecl(StringRef)
void ClearUnusedCoverageMapping(const Decl *D)
Remove the deferred empty coverage mapping as this declaration is actually instrumented.
void EmitTopLevelDecl(Decl *D)
Emit code for a single top level declaration.
llvm::Function * CreateGlobalInitOrCleanUpFunction(llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, SourceLocation Loc=SourceLocation(), bool TLS=false, llvm::GlobalVariable::LinkageTypes Linkage=llvm::GlobalVariable::InternalLinkage)
Definition: CGDeclCXX.cpp:429
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character.
std::vector< Structor > CtorList
void printPostfixForExternalizedDecl(llvm::raw_ostream &OS, const Decl *D) const
Print the postfix for externalized static variable or kernels for single source offloading languages ...
llvm::Constant * GetAddrOfThunk(StringRef Name, llvm::Type *FnTy, GlobalDecl GD)
Get the address of the thunk for the given global decl.
Definition: CGVTables.cpp:34
void moveLazyEmissionStates(CodeGenModule *NewBuilder)
Move some lazily-emitted states to the NewBuilder.
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
void finalizeKCFITypes()
Emit KCFI type identifier constants and remove unused identifiers.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
ItaniumVTableContext & getItaniumVTableContext()
Definition: CGVTables.h:91
MicrosoftVTableContext & getMicrosoftVTableContext()
Definition: CGVTables.h:99
A specialization of Address that requires the address to be an LLVM Constant.
Definition: Address.h:117
Organizes the cross-function state that is used while generating code coverage mapping data.
This class records statistics on instrumentation based profiling.
bool hasDiagnostics()
Whether or not the stats we've gathered indicate any potential problems.
void addMissing(bool MainFile)
Record that a function we've visited has no profile data.
void addMismatched(bool MainFile)
Record that a function we've visited has mismatched profile data.
void addVisited(bool MainFile)
Record that we've visited a function and whether or not that function was in the main source file.
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile)
Report potential problems we've found to Diags.
LValue - This represents an lvalue references.
Definition: CGValue.h:171
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:46
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3417
Stores additional source code information like skipped ranges which is required by the coverage mappi...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1402
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:765
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3709
This represents one expression.
Definition: Expr.h:110
Represents a function declaration or definition.
Definition: Decl.h:1917
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
const Decl * getDecl() const
Definition: GlobalDecl.h:103
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:82
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:624
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:629
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:634
Visibility getVisibility() const
Definition: Visibility.h:84
bool isVisibilityExplicit() const
Definition: Visibility.h:85
Represents a linkage specification.
Definition: DeclCXX.h:2884
A global _GUID constant.
Definition: DeclCXX.h:4242
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4564
Describes a module or submodule.
Definition: Module.h:98
This represents a decl that may have a name.
Definition: Decl.h:247
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1183
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:473
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:287
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:171
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:416
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:409
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2584
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
ExclusionType
Represents if an how something should be excluded from profiling.
Definition: ProfileList.h:31
A (possibly-)qualified type.
Definition: Type.h:736
Encodes a location in the source.
Stmt - This represents one statement.
Definition: Stmt.h:72
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1780
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3454
Exposes information about the current target.
Definition: TargetInfo.h:206
A template parameter object.
A declaration that models statements at global scope.
Definition: Decl.h:4322
The base class of the type hierarchy.
Definition: Type.h:1568
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1799
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2181
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4299
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
Represents a variable declaration or definition.
Definition: Decl.h:913
Defines the clang::TargetInfo interface.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:68
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:23
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:269
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:33
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:36
@ ProtectedVisibility
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition: Visibility.h:41
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
Definition: Visibility.h:45
YAML serialization mapping.
Definition: Dominators.h:30
Structor(int Priority, unsigned LexOrder, llvm::Constant *Initializer, llvm::Constant *AssociatedData)
This structure provides a set of types that are commonly used during IR emission.
llvm::Function * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
llvm::Function * objc_retainAutoreleaseReturnValue
id objc_retainAutoreleaseReturnValue(id);
llvm::FunctionCallee objc_alloc
void objc_alloc(id);
llvm::Function * objc_retain
id objc_retain(id);
llvm::FunctionCallee objc_alloc_init
void objc_alloc_init(id);
llvm::Function * objc_autorelease
id objc_autorelease(id);
llvm::Function * objc_moveWeak
void objc_moveWeak(id *dest, id *src);
llvm::FunctionCallee objc_autoreleasePoolPopInvoke
void objc_autoreleasePoolPop(void*); Note this method is used when we are using exception handling
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain.
llvm::Function * clang_arc_use
void clang.arc.use(...);
llvm::Function * objc_initWeak
id objc_initWeak(id*, id);
llvm::FunctionCallee objc_retainRuntimeFunction
id objc_retain(id); Note this is the runtime method not the intrinsic.
llvm::Function * objc_copyWeak
void objc_copyWeak(id *dest, id *src);
llvm::Function * objc_destroyWeak
void objc_destroyWeak(id*);
llvm::Function * objc_retainAutorelease
id objc_retainAutorelease(id);
llvm::Function * objc_autoreleasePoolPush
void *objc_autoreleasePoolPush(void);
llvm::Function * objc_retainBlock
id objc_retainBlock(id);
llvm::Function * objc_storeStrong
void objc_storeStrong(id*, id);
llvm::Function * objc_loadWeak
id objc_loadWeak(id*);
llvm::Function * clang_arc_noop_use
void clang.arc.noop.use(...);
llvm::Function * objc_loadWeakRetained
id objc_loadWeakRetained(id*);
llvm::Function * objc_release
void objc_release(id);
llvm::FunctionCallee objc_autoreleaseRuntimeFunction
id objc_autorelease(id); Note this is the runtime method not the intrinsic.
llvm::Function * objc_autoreleaseReturnValue
id objc_autoreleaseReturnValue(id);
llvm::FunctionCallee objc_releaseRuntimeFunction
void objc_release(id); Note this is the runtime method not the intrinsic.
llvm::FunctionCallee objc_allocWithZone
void objc_allocWithZone(id);
llvm::FunctionCallee objc_autoreleasePoolPop
void objc_autoreleasePoolPop(void*);
llvm::Function * objc_storeWeak
id objc_storeWeak(id*, id);
llvm::Function * objc_unsafeClaimAutoreleasedReturnValue
id objc_unsafeClaimAutoreleasedReturnValue(id);
bool operator<(const OrderGlobalInitsOrStermFinalizers &RHS) const
bool operator==(const OrderGlobalInitsOrStermFinalizers &RHS) const
OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:62