clang 20.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"
32#include "llvm/ADT/DenseMap.h"
33#include "llvm/ADT/MapVector.h"
34#include "llvm/ADT/SetVector.h"
35#include "llvm/ADT/SmallPtrSet.h"
36#include "llvm/ADT/StringMap.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/ValueHandle.h"
39#include "llvm/Transforms/Utils/SanitizerStats.h"
40#include <optional>
41
42namespace llvm {
43class Module;
44class Constant;
45class ConstantInt;
46class Function;
47class GlobalValue;
48class DataLayout;
49class FunctionType;
50class LLVMContext;
51class IndexedInstrProfReader;
52
53namespace vfs {
54class FileSystem;
55}
56}
57
58namespace clang {
59class ASTContext;
60class AtomicType;
61class FunctionDecl;
62class IdentifierInfo;
63class ObjCImplementationDecl;
64class ObjCEncodeExpr;
65class BlockExpr;
66class CharUnits;
67class Decl;
68class Expr;
69class Stmt;
70class StringLiteral;
71class NamedDecl;
72class PointerAuthSchema;
73class ValueDecl;
74class VarDecl;
75class LangOptions;
76class CodeGenOptions;
77class HeaderSearchOptions;
78class DiagnosticsEngine;
79class AnnotateAttr;
80class CXXDestructorDecl;
81class Module;
82class CoverageSourceInfo;
83class InitSegAttr;
84
85namespace CodeGen {
86
87class CodeGenFunction;
88class CodeGenTBAA;
89class CGCXXABI;
90class CGDebugInfo;
91class CGObjCRuntime;
92class CGOpenCLRuntime;
93class CGOpenMPRuntime;
94class CGCUDARuntime;
95class CGHLSLRuntime;
96class CoverageMappingModuleGen;
97class TargetCodeGenInfo;
98
99enum ForDefinition_t : bool {
101 ForDefinition = true
103
105 unsigned int priority;
106 unsigned int lex_order;
107 OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
108 : priority(p), lex_order(l) {}
109
111 return priority == RHS.priority && lex_order == RHS.lex_order;
112 }
113
115 return std::tie(priority, lex_order) <
116 std::tie(RHS.priority, RHS.lex_order);
117 }
118};
119
121 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
122
123 /// void objc_alloc(id);
124 llvm::FunctionCallee objc_alloc;
125
126 /// void objc_allocWithZone(id);
127 llvm::FunctionCallee objc_allocWithZone;
128
129 /// void objc_alloc_init(id);
130 llvm::FunctionCallee objc_alloc_init;
131
132 /// void objc_autoreleasePoolPop(void*);
133 llvm::FunctionCallee objc_autoreleasePoolPop;
134
135 /// void objc_autoreleasePoolPop(void*);
136 /// Note this method is used when we are using exception handling
137 llvm::FunctionCallee objc_autoreleasePoolPopInvoke;
138
139 /// void *objc_autoreleasePoolPush(void);
141
142 /// id objc_autorelease(id);
143 llvm::Function *objc_autorelease;
144
145 /// id objc_autorelease(id);
146 /// Note this is the runtime method not the intrinsic.
148
149 /// id objc_autoreleaseReturnValue(id);
151
152 /// void objc_copyWeak(id *dest, id *src);
153 llvm::Function *objc_copyWeak;
154
155 /// void objc_destroyWeak(id*);
156 llvm::Function *objc_destroyWeak;
157
158 /// id objc_initWeak(id*, id);
159 llvm::Function *objc_initWeak;
160
161 /// id objc_loadWeak(id*);
162 llvm::Function *objc_loadWeak;
163
164 /// id objc_loadWeakRetained(id*);
165 llvm::Function *objc_loadWeakRetained;
166
167 /// void objc_moveWeak(id *dest, id *src);
168 llvm::Function *objc_moveWeak;
169
170 /// id objc_retain(id);
171 llvm::Function *objc_retain;
172
173 /// id objc_retain(id);
174 /// Note this is the runtime method not the intrinsic.
175 llvm::FunctionCallee objc_retainRuntimeFunction;
176
177 /// id objc_retainAutorelease(id);
178 llvm::Function *objc_retainAutorelease;
179
180 /// id objc_retainAutoreleaseReturnValue(id);
182
183 /// id objc_retainAutoreleasedReturnValue(id);
185
186 /// id objc_retainBlock(id);
187 llvm::Function *objc_retainBlock;
188
189 /// void objc_release(id);
190 llvm::Function *objc_release;
191
192 /// void objc_release(id);
193 /// Note this is the runtime method not the intrinsic.
194 llvm::FunctionCallee objc_releaseRuntimeFunction;
195
196 /// void objc_storeStrong(id*, id);
197 llvm::Function *objc_storeStrong;
198
199 /// id objc_storeWeak(id*, id);
200 llvm::Function *objc_storeWeak;
201
202 /// id objc_unsafeClaimAutoreleasedReturnValue(id);
204
205 /// A void(void) inline asm to use to mark that the return value of
206 /// a call will be immediately retain.
208
209 /// void clang.arc.use(...);
210 llvm::Function *clang_arc_use;
211
212 /// void clang.arc.noop.use(...);
213 llvm::Function *clang_arc_noop_use;
214};
215
216/// This class records statistics on instrumentation based profiling.
218 uint32_t VisitedInMainFile = 0;
219 uint32_t MissingInMainFile = 0;
220 uint32_t Visited = 0;
221 uint32_t Missing = 0;
222 uint32_t Mismatched = 0;
223
224public:
225 InstrProfStats() = default;
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 llvm::StringSet<llvm::BumpPtrAllocator> DeferredResolversToEmit;
352
353 /// This is a list of deferred decls which we have seen that *are* actually
354 /// referenced. These get code generated when the module is done.
355 std::vector<GlobalDecl> DeferredDeclsToEmit;
356 void addDeferredDeclToEmit(GlobalDecl GD) {
357 DeferredDeclsToEmit.emplace_back(GD);
358 addEmittedDeferredDecl(GD);
359 }
360
361 /// Decls that were DeferredDecls and have now been emitted.
362 llvm::DenseMap<llvm::StringRef, GlobalDecl> EmittedDeferredDecls;
363
364 void addEmittedDeferredDecl(GlobalDecl GD) {
365 // Reemission is only needed in incremental mode.
366 if (!Context.getLangOpts().IncrementalExtensions)
367 return;
368
369 // Assume a linkage by default that does not need reemission.
370 auto L = llvm::GlobalValue::ExternalLinkage;
371 if (llvm::isa<FunctionDecl>(GD.getDecl()))
372 L = getFunctionLinkage(GD);
373 else if (auto *VD = llvm::dyn_cast<VarDecl>(GD.getDecl()))
375
376 if (llvm::GlobalValue::isInternalLinkage(L) ||
377 llvm::GlobalValue::isLinkOnceLinkage(L) ||
378 llvm::GlobalValue::isWeakLinkage(L)) {
379 EmittedDeferredDecls[getMangledName(GD)] = GD;
380 }
381 }
382
383 /// List of alias we have emitted. Used to make sure that what they point to
384 /// is defined once we get to the end of the of the translation unit.
385 std::vector<GlobalDecl> Aliases;
386
387 /// List of multiversion functions to be emitted. This list is processed in
388 /// conjunction with other deferred symbols and is used to ensure that
389 /// multiversion function resolvers and ifuncs are defined and emitted.
390 std::vector<GlobalDecl> MultiVersionFuncs;
391
392 llvm::MapVector<StringRef, llvm::TrackingVH<llvm::Constant>> Replacements;
393
394 /// List of global values to be replaced with something else. Used when we
395 /// want to replace a GlobalValue but can't identify it by its mangled name
396 /// anymore (because the name is already taken).
398 GlobalValReplacements;
399
400 /// Variables for which we've emitted globals containing their constant
401 /// values along with the corresponding globals, for opportunistic reuse.
402 llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants;
403
404 /// Set of global decls for which we already diagnosed mangled name conflict.
405 /// Required to not issue a warning (on a mangling conflict) multiple times
406 /// for the same decl.
407 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
408
409 /// A queue of (optional) vtables to consider emitting.
410 std::vector<const CXXRecordDecl*> DeferredVTables;
411
412 /// A queue of (optional) vtables that may be emitted opportunistically.
413 std::vector<const CXXRecordDecl *> OpportunisticVTables;
414
415 /// List of global values which are required to be present in the object file;
416 /// bitcast to i8*. This is used for forcing visibility of symbols which may
417 /// otherwise be optimized out.
418 std::vector<llvm::WeakTrackingVH> LLVMUsed;
419 std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
420
421 /// Store the list of global constructors and their respective priorities to
422 /// be emitted when the translation unit is complete.
423 CtorList GlobalCtors;
424
425 /// Store the list of global destructors and their respective priorities to be
426 /// emitted when the translation unit is complete.
427 CtorList GlobalDtors;
428
429 /// An ordered map of canonical GlobalDecls to their mangled names.
430 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
431 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
432
433 /// Global annotations.
434 std::vector<llvm::Constant*> Annotations;
435
436 // Store deferred function annotations so they can be emitted at the end with
437 // most up to date ValueDecl that will have all the inherited annotations.
438 llvm::MapVector<StringRef, const ValueDecl *> DeferredAnnotations;
439
440 /// Map used to get unique annotation strings.
441 llvm::StringMap<llvm::Constant*> AnnotationStrings;
442
443 /// Used for uniquing of annotation arguments.
444 llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
445
446 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
447
448 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
449 llvm::DenseMap<const UnnamedGlobalConstantDecl *, llvm::GlobalVariable *>
450 UnnamedGlobalConstantDeclMap;
451 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
452 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
453 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
454
455 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
456 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
457
458 /// Map used to get unique type descriptor constants for sanitizers.
459 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
460
461 /// Map used to track internal linkage functions declared within
462 /// extern "C" regions.
463 typedef llvm::MapVector<IdentifierInfo *,
464 llvm::GlobalValue *> StaticExternCMap;
465 StaticExternCMap StaticExternCValues;
466
467 /// thread_local variables defined or used in this TU.
468 std::vector<const VarDecl *> CXXThreadLocals;
469
470 /// thread_local variables with initializers that need to run
471 /// before any thread_local variable in this TU is odr-used.
472 std::vector<llvm::Function *> CXXThreadLocalInits;
473 std::vector<const VarDecl *> CXXThreadLocalInitVars;
474
475 /// Global variables with initializers that need to run before main.
476 std::vector<llvm::Function *> CXXGlobalInits;
477
478 /// When a C++ decl with an initializer is deferred, null is
479 /// appended to CXXGlobalInits, and the index of that null is placed
480 /// here so that the initializer will be performed in the correct
481 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
482 /// that we don't re-emit the initializer.
483 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
484
485 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
486 GlobalInitData;
487
488 // When a tail call is performed on an "undefined" symbol, on PPC without pc
489 // relative feature, the tail call is not allowed. In "EmitCall" for such
490 // tail calls, the "undefined" symbols may be forward declarations, their
491 // definitions are provided in the module after the callsites. For such tail
492 // calls, diagnose message should not be emitted.
494 MustTailCallUndefinedGlobals;
495
496 struct GlobalInitPriorityCmp {
497 bool operator()(const GlobalInitData &LHS,
498 const GlobalInitData &RHS) const {
499 return LHS.first.priority < RHS.first.priority;
500 }
501 };
502
503 /// Global variables with initializers whose order of initialization is set by
504 /// init_priority attribute.
505 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
506
507 /// Global destructor functions and arguments that need to run on termination.
508 /// When UseSinitAndSterm is set, it instead contains sterm finalizer
509 /// functions, which also run on unloading a shared library.
510 typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
511 llvm::Constant *>
512 CXXGlobalDtorsOrStermFinalizer_t;
513 SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8>
514 CXXGlobalDtorsOrStermFinalizers;
515
516 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
517 StermFinalizerData;
518
519 struct StermFinalizerPriorityCmp {
520 bool operator()(const StermFinalizerData &LHS,
521 const StermFinalizerData &RHS) const {
522 return LHS.first.priority < RHS.first.priority;
523 }
524 };
525
526 /// Global variables with sterm finalizers whose order of initialization is
527 /// set by init_priority attribute.
528 SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers;
529
530 /// The complete set of modules that has been imported.
531 llvm::SetVector<clang::Module *> ImportedModules;
532
533 /// The set of modules for which the module initializers
534 /// have been emitted.
535 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
536
537 /// A vector of metadata strings for linker options.
538 SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
539
540 /// A vector of metadata strings for dependent libraries for ELF.
541 SmallVector<llvm::MDNode *, 16> ELFDependentLibraries;
542
543 /// @name Cache for Objective-C runtime types
544 /// @{
545
546 /// Cached reference to the class for constant strings. This value has type
547 /// int * but is actually an Obj-C class pointer.
548 llvm::WeakTrackingVH CFConstantStringClassRef;
549
550 /// The type used to describe the state of a fast enumeration in
551 /// Objective-C's for..in loop.
552 QualType ObjCFastEnumerationStateType;
553
554 /// @}
555
556 /// Lazily create the Objective-C runtime
557 void createObjCRuntime();
558
559 void createOpenCLRuntime();
560 void createOpenMPRuntime();
561 void createCUDARuntime();
562 void createHLSLRuntime();
563
564 bool isTriviallyRecursive(const FunctionDecl *F);
565 bool shouldEmitFunction(GlobalDecl GD);
566 // Whether a global variable should be emitted by CUDA/HIP host/device
567 // related attributes.
568 bool shouldEmitCUDAGlobalVar(const VarDecl *VD) const;
569 bool shouldOpportunisticallyEmitVTables();
570 /// Map used to be sure we don't emit the same CompoundLiteral twice.
571 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
572 EmittedCompoundLiterals;
573
574 /// Map of the global blocks we've emitted, so that we don't have to re-emit
575 /// them if the constexpr evaluator gets aggressive.
576 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
577
578 /// @name Cache for Blocks Runtime Globals
579 /// @{
580
581 llvm::Constant *NSConcreteGlobalBlock = nullptr;
582 llvm::Constant *NSConcreteStackBlock = nullptr;
583
584 llvm::FunctionCallee BlockObjectAssign = nullptr;
585 llvm::FunctionCallee BlockObjectDispose = nullptr;
586
587 llvm::Type *BlockDescriptorType = nullptr;
588 llvm::Type *GenericBlockLiteralType = nullptr;
589
590 struct {
592 } Block;
593
594 GlobalDecl initializedGlobalDecl;
595
596 /// @}
597
598 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
599 llvm::Function *LifetimeStartFn = nullptr;
600
601 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
602 llvm::Function *LifetimeEndFn = nullptr;
603
604 std::unique_ptr<SanitizerMetadata> SanitizerMD;
605
606 llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
607
608 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
609
610 /// Mapping from canonical types to their metadata identifiers. We need to
611 /// maintain this mapping because identifiers may be formed from distinct
612 /// MDNodes.
613 typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap;
614 MetadataTypeMap MetadataIdMap;
615 MetadataTypeMap VirtualMetadataIdMap;
616 MetadataTypeMap GeneralizedMetadataIdMap;
617
618 // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
619 // when used with -fincremental-extensions.
620 std::pair<std::unique_ptr<CodeGenFunction>, const TopLevelStmtDecl *>
621 GlobalTopLevelStmtBlockInFlight;
622
623 llvm::DenseMap<GlobalDecl, uint16_t> PtrAuthDiscriminatorHashes;
624
625 llvm::DenseMap<const CXXRecordDecl *, std::optional<PointerAuthQualifier>>
626 VTablePtrAuthInfos;
627 std::optional<PointerAuthQualifier>
628 computeVTPointerAuthentication(const CXXRecordDecl *ThisClass);
629
630public:
632 const HeaderSearchOptions &headersearchopts,
633 const PreprocessorOptions &ppopts,
634 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
635 DiagnosticsEngine &Diags,
636 CoverageSourceInfo *CoverageInfo = nullptr);
637
639
640 void clear();
641
642 /// Finalize LLVM code generation.
643 void Release();
644
645 /// Return true if we should emit location information for expressions.
647
648 /// Return a reference to the configured Objective-C runtime.
650 if (!ObjCRuntime) createObjCRuntime();
651 return *ObjCRuntime;
652 }
653
654 /// Return true iff an Objective-C runtime has been configured.
655 bool hasObjCRuntime() { return !!ObjCRuntime; }
656
657 const std::string &getModuleNameHash() const { return ModuleNameHash; }
658
659 /// Return a reference to the configured OpenCL runtime.
661 assert(OpenCLRuntime != nullptr);
662 return *OpenCLRuntime;
663 }
664
665 /// Return a reference to the configured OpenMP runtime.
667 assert(OpenMPRuntime != nullptr);
668 return *OpenMPRuntime;
669 }
670
671 /// Return a reference to the configured CUDA runtime.
673 assert(CUDARuntime != nullptr);
674 return *CUDARuntime;
675 }
676
677 /// Return a reference to the configured HLSL runtime.
679 assert(HLSLRuntime != nullptr);
680 return *HLSLRuntime;
681 }
682
684 assert(ObjCData != nullptr);
685 return *ObjCData;
686 }
687
688 // Version checking functions, used to implement ObjC's @available:
689 // i32 @__isOSVersionAtLeast(i32, i32, i32)
690 llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr;
691 // i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32)
692 llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr;
693
694 InstrProfStats &getPGOStats() { return PGOStats; }
695 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
696
698 return CoverageMapping.get();
699 }
700
701 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
702 return StaticLocalDeclMap[D];
703 }
705 llvm::Constant *C) {
706 StaticLocalDeclMap[D] = C;
707 }
708
709 llvm::Constant *
711 llvm::GlobalValue::LinkageTypes Linkage);
712
713 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
714 return StaticLocalDeclGuardMap[D];
715 }
717 llvm::GlobalVariable *C) {
718 StaticLocalDeclGuardMap[D] = C;
719 }
720
721 Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant,
722 CharUnits Align);
723
724 bool lookupRepresentativeDecl(StringRef MangledName,
725 GlobalDecl &Result) const;
726
728 return AtomicSetterHelperFnMap[Ty];
729 }
731 llvm::Constant *Fn) {
732 AtomicSetterHelperFnMap[Ty] = Fn;
733 }
734
736 return AtomicGetterHelperFnMap[Ty];
737 }
739 llvm::Constant *Fn) {
740 AtomicGetterHelperFnMap[Ty] = Fn;
741 }
742
743 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
744 return TypeDescriptorMap[Ty];
745 }
746 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
747 TypeDescriptorMap[Ty] = C;
748 }
749
750 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
751
753 if (!NoObjCARCExceptionsMetadata)
754 NoObjCARCExceptionsMetadata =
755 llvm::MDNode::get(getLLVMContext(), std::nullopt);
756 return NoObjCARCExceptionsMetadata;
757 }
758
759 ASTContext &getContext() const { return Context; }
760 const LangOptions &getLangOpts() const { return LangOpts; }
762 return FS;
763 }
765 const { return HeaderSearchOpts; }
767 const { return PreprocessorOpts; }
768 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
769 llvm::Module &getModule() const { return TheModule; }
770 DiagnosticsEngine &getDiags() const { return Diags; }
771 const llvm::DataLayout &getDataLayout() const {
772 return TheModule.getDataLayout();
773 }
774 const TargetInfo &getTarget() const { return Target; }
775 const llvm::Triple &getTriple() const { return Target.getTriple(); }
776 bool supportsCOMDAT() const;
777 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
778
779 CGCXXABI &getCXXABI() const { return *ABI; }
780 llvm::LLVMContext &getLLVMContext() { return VMContext; }
781
782 bool shouldUseTBAA() const { return TBAA != nullptr; }
783
785
786 CodeGenTypes &getTypes() { return Types; }
787
788 CodeGenVTables &getVTables() { return VTables; }
789
791 return VTables.getItaniumVTableContext();
792 }
793
795 return VTables.getItaniumVTableContext();
796 }
797
799 return VTables.getMicrosoftVTableContext();
800 }
801
802 CtorList &getGlobalCtors() { return GlobalCtors; }
803 CtorList &getGlobalDtors() { return GlobalDtors; }
804
805 /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
806 /// the given type.
807 llvm::MDNode *getTBAATypeInfo(QualType QTy);
808
809 /// getTBAAAccessInfo - Get TBAA information that describes an access to
810 /// an object of the given type.
812
813 /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
814 /// access to a virtual table pointer.
815 TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
816
817 llvm::MDNode *getTBAAStructInfo(QualType QTy);
818
819 /// getTBAABaseTypeInfo - Get metadata that describes the given base access
820 /// type. Return null if the type is not suitable for use in TBAA access tags.
821 llvm::MDNode *getTBAABaseTypeInfo(QualType QTy);
822
823 /// getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
824 llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info);
825
826 /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of
827 /// type casts.
830
831 /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
832 /// purposes of conditional operator.
834 TBAAAccessInfo InfoB);
835
836 /// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the
837 /// purposes of memory transfer calls.
839 TBAAAccessInfo SrcInfo);
840
841 /// getTBAAInfoForSubobject - Get TBAA information for an access with a given
842 /// base lvalue.
844 if (Base.getTBAAInfo().isMayAlias())
846 return getTBAAAccessInfo(AccessType);
847 }
848
851
852 /// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
853 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
854 TBAAAccessInfo TBAAInfo);
855
856 /// Adds !invariant.barrier !tag to instruction
857 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
858 const CXXRecordDecl *RD);
859
860 /// Emit the given number of characters as a value of type size_t.
861 llvm::ConstantInt *getSize(CharUnits numChars);
862
863 /// Set the visibility for the given LLVM GlobalValue.
864 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
865
866 void setDSOLocal(llvm::GlobalValue *GV) const;
867
870 (D->getLinkageAndVisibility().getVisibility() ==
874 D->getLinkageAndVisibility().isVisibilityExplicit()));
875 }
876 void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
877 void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const;
878 /// Set visibility, dllimport/dllexport and dso_local.
879 /// This must be called after dllimport/dllexport is set.
880 void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
881 void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
882
883 void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
884
885 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
886 /// variable declaration D.
887 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
888
889 /// Get LLVM TLS mode from CodeGenOptions.
890 llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const;
891
892 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
893 switch (V) {
894 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
895 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
896 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
897 }
898 llvm_unreachable("unknown visibility!");
899 }
900
901 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
902 ForDefinition_t IsForDefinition
904
905 /// Will return a global variable of the given type. If a variable with a
906 /// different type already exists then a new variable with the right type
907 /// will be created and all uses of the old variable will be replaced with a
908 /// bitcast to the new variable.
909 llvm::GlobalVariable *
910 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
911 llvm::GlobalValue::LinkageTypes Linkage,
912 llvm::Align Alignment);
913
914 llvm::Function *CreateGlobalInitOrCleanUpFunction(
915 llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI,
916 SourceLocation Loc = SourceLocation(), bool TLS = false,
917 llvm::GlobalVariable::LinkageTypes Linkage =
918 llvm::GlobalVariable::InternalLinkage);
919
920 /// Return the AST address space of the underlying global variable for D, as
921 /// determined by its declaration. Normally this is the same as the address
922 /// space of D's type, but in CUDA, address spaces are associated with
923 /// declarations, not types. If D is nullptr, return the default address
924 /// space for global variable.
925 ///
926 /// For languages without explicit address spaces, if D has default address
927 /// space, target-specific global or constant address space may be returned.
929
930 /// Return the AST address space of constant literal, which is used to emit
931 /// the constant literal as global variable in LLVM IR.
932 /// Note: This is not necessarily the address space of the constant literal
933 /// in AST. For address space agnostic language, e.g. C++, constant literal
934 /// in AST is always in default address space.
936
937 /// Return the llvm::Constant for the address of the given global variable.
938 /// If Ty is non-null and if the global doesn't exist, then it will be created
939 /// with the specified type instead of whatever the normal requested type
940 /// would be. If IsForDefinition is true, it is guaranteed that an actual
941 /// global with type Ty will be returned, not conversion of a variable with
942 /// the same mangled name but some other type.
943 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
944 llvm::Type *Ty = nullptr,
945 ForDefinition_t IsForDefinition
947
948 /// Return the address of the given function. If Ty is non-null, then this
949 /// function will use the specified type if it has to create it.
950 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
951 bool ForVTable = false,
952 bool DontDefer = false,
953 ForDefinition_t IsForDefinition
955
956 // Return the function body address of the given function.
957 llvm::Constant *GetFunctionStart(const ValueDecl *Decl);
958
959 /// Return a function pointer for a reference to the given function.
960 /// This correctly handles weak references, but does not apply a
961 /// pointer signature.
962 llvm::Constant *getRawFunctionPointer(GlobalDecl GD,
963 llvm::Type *Ty = nullptr);
964
965 /// Return the ABI-correct function pointer value for a reference
966 /// to the given function. This will apply a pointer signature if
967 /// necessary, caching the result for the given function.
968 llvm::Constant *getFunctionPointer(GlobalDecl GD, llvm::Type *Ty = nullptr);
969
970 /// Return the ABI-correct function pointer value for a reference
971 /// to the given function. This will apply a pointer signature if
972 /// necessary.
973 llvm::Constant *getFunctionPointer(llvm::Constant *Pointer,
975
976 llvm::Constant *getMemberFunctionPointer(const FunctionDecl *FD,
977 llvm::Type *Ty = nullptr);
978
979 llvm::Constant *getMemberFunctionPointer(llvm::Constant *Pointer,
980 QualType FT);
981
983
985
987
989
990 bool shouldSignPointer(const PointerAuthSchema &Schema);
991 llvm::Constant *getConstantSignedPointer(llvm::Constant *Pointer,
992 const PointerAuthSchema &Schema,
993 llvm::Constant *StorageAddress,
994 GlobalDecl SchemaDecl,
995 QualType SchemaType);
996
997 llvm::Constant *
998 getConstantSignedPointer(llvm::Constant *Pointer, unsigned Key,
999 llvm::Constant *StorageAddress,
1000 llvm::ConstantInt *OtherDiscriminator);
1001
1002 llvm::ConstantInt *
1004 GlobalDecl SchemaDecl, QualType SchemaType);
1005
1007 std::optional<CGPointerAuthInfo>
1009 const CXXRecordDecl *Record,
1010 llvm::Value *StorageAddress);
1011
1012 std::optional<PointerAuthQualifier>
1014
1016
1017 // Return whether RTTI information should be emitted for this target.
1018 bool shouldEmitRTTI(bool ForEH = false) {
1019 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
1020 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1021 (getTriple().isNVPTX() || getTriple().isAMDGPU()));
1022 }
1023
1024 /// Get the address of the RTTI descriptor for the given type.
1025 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
1026
1027 /// Get the address of a GUID.
1029
1030 /// Get the address of a UnnamedGlobalConstant
1033
1034 /// Get the address of a template parameter object.
1037
1038 /// Get the address of the thunk for the given global decl.
1039 llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
1040 GlobalDecl GD);
1041
1042 /// Get a reference to the target of VD.
1044
1045 /// Returns the assumed alignment of an opaque pointer to the given class.
1047
1048 /// Returns the minimum object size for an object of the given class type
1049 /// (or a class derived from it).
1051
1052 /// Returns the minimum object size for an object of the given type.
1054 if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
1055 return getMinimumClassObjectSize(RD);
1056 return getContext().getTypeSizeInChars(Ty);
1057 }
1058
1059 /// Returns the assumed alignment of a virtual base of a class.
1061 const CXXRecordDecl *Derived,
1062 const CXXRecordDecl *VBase);
1063
1064 /// Given a class pointer with an actual known alignment, and the
1065 /// expected alignment of an object at a dynamic offset w.r.t that
1066 /// pointer, return the alignment to assume at the offset.
1068 const CXXRecordDecl *Class,
1069 CharUnits ExpectedTargetAlign);
1070
1071 CharUnits
1075
1076 /// Returns the offset from a derived class to a class. Returns null if the
1077 /// offset is 0.
1078 llvm::Constant *
1082
1083 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
1084
1085 /// Fetches the global unique block count.
1086 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
1087
1088 /// Fetches the type of a generic block descriptor.
1089 llvm::Type *getBlockDescriptorType();
1090
1091 /// The type of a generic block literal.
1092 llvm::Type *getGenericBlockLiteralType();
1093
1094 /// Gets the address of a block which requires no captures.
1095 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
1096
1097 /// Returns the address of a block which requires no caputres, or null if
1098 /// we've yet to emit the block for BE.
1099 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
1100 return EmittedGlobalBlocks.lookup(BE);
1101 }
1102
1103 /// Notes that BE's global block is available via Addr. Asserts that BE
1104 /// isn't already emitted.
1105 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
1106
1107 /// Return a pointer to a constant CFString object for the given string.
1109
1110 /// Return a constant array for the given string.
1111 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
1112
1113 /// Return a pointer to a constant array for the given string literal.
1116 StringRef Name = ".str");
1117
1118 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
1121
1122 /// Returns a pointer to a character array containing the literal and a
1123 /// terminating '\0' character. The result has pointer to array type.
1124 ///
1125 /// \param GlobalName If provided, the name to use for the global (if one is
1126 /// created).
1128 GetAddrOfConstantCString(const std::string &Str,
1129 const char *GlobalName = nullptr);
1130
1131 /// Returns a pointer to a constant global variable for the given file-scope
1132 /// compound literal expression.
1134
1135 /// If it's been emitted already, returns the GlobalVariable corresponding to
1136 /// a compound literal. Otherwise, returns null.
1137 llvm::GlobalVariable *
1139
1140 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
1141 /// emitted.
1143 llvm::GlobalVariable *GV);
1144
1145 /// Returns a pointer to a global variable representing a temporary
1146 /// with static or thread storage duration.
1148 const Expr *Inner);
1149
1150 /// Retrieve the record type that describes the state of an
1151 /// Objective-C fast enumeration loop (for..in).
1153
1154 // Produce code for this constructor/destructor. This method doesn't try
1155 // to apply any ABI rules about which other constructors/destructors
1156 // are needed or if they are alias to each other.
1157 llvm::Function *codegenCXXStructor(GlobalDecl GD);
1158
1159 /// Return the address of the constructor/destructor of the given type.
1160 llvm::Constant *
1162 llvm::FunctionType *FnType = nullptr,
1163 bool DontDefer = false,
1164 ForDefinition_t IsForDefinition = NotForDefinition) {
1165 return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType,
1166 DontDefer,
1167 IsForDefinition)
1168 .getCallee());
1169 }
1170
1171 llvm::FunctionCallee getAddrAndTypeOfCXXStructor(
1172 GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
1173 llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
1174 ForDefinition_t IsForDefinition = NotForDefinition);
1175
1176 /// Given a builtin id for a function like "__builtin_fabsf", return a
1177 /// Function* for "fabsf".
1178 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
1179 unsigned BuiltinID);
1180
1181 llvm::Function *getIntrinsic(unsigned IID,
1182 ArrayRef<llvm::Type *> Tys = std::nullopt);
1183
1184 /// Emit code for a single top level declaration.
1185 void EmitTopLevelDecl(Decl *D);
1186
1187 /// Stored a deferred empty coverage mapping for an unused
1188 /// and thus uninstrumented top level declaration.
1190
1191 /// Remove the deferred empty coverage mapping as this
1192 /// declaration is actually instrumented.
1193 void ClearUnusedCoverageMapping(const Decl *D);
1194
1195 /// Emit all the deferred coverage mappings
1196 /// for the uninstrumented functions.
1198
1199 /// Emit an alias for "main" if it has no arguments (needed for wasm).
1200 void EmitMainVoidAlias();
1201
1202 /// Tell the consumer that this variable has been instantiated.
1204
1205 /// If the declaration has internal linkage but is inside an
1206 /// extern "C" linkage specification, prepare to emit an alias for it
1207 /// to the expected name.
1208 template<typename SomeDecl>
1209 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
1210
1211 /// Add a global to a list to be added to the llvm.used metadata.
1212 void addUsedGlobal(llvm::GlobalValue *GV);
1213
1214 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1215 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
1216
1217 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1218 void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
1219
1220 /// Add a destructor and object to add to the C++ global destructor function.
1221 void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
1222 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1223 DtorFn.getCallee(), Object);
1224 }
1225
1226 /// Add an sterm finalizer to the C++ global cleanup function.
1227 void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) {
1228 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1229 DtorFn.getCallee(), nullptr);
1230 }
1231
1232 /// Add an sterm finalizer to its own llvm.global_dtors entry.
1233 void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer,
1234 int Priority) {
1235 AddGlobalDtor(StermFinalizer, Priority);
1236 }
1237
1238 void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer,
1239 int Priority) {
1241 PrioritizedCXXStermFinalizers.size());
1242 PrioritizedCXXStermFinalizers.push_back(
1243 std::make_pair(Key, StermFinalizer));
1244 }
1245
1246 /// Create or return a runtime function declaration with the specified type
1247 /// and name. If \p AssumeConvergent is true, the call will have the
1248 /// convergent attribute added.
1249 llvm::FunctionCallee
1250 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
1251 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1252 bool Local = false, bool AssumeConvergent = false);
1253
1254 /// Create a new runtime global variable with the specified type and name.
1255 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
1256 StringRef Name);
1257
1258 ///@name Custom Blocks Runtime Interfaces
1259 ///@{
1260
1261 llvm::Constant *getNSConcreteGlobalBlock();
1262 llvm::Constant *getNSConcreteStackBlock();
1263 llvm::FunctionCallee getBlockObjectAssign();
1264 llvm::FunctionCallee getBlockObjectDispose();
1265
1266 ///@}
1267
1268 llvm::Function *getLLVMLifetimeStartFn();
1269 llvm::Function *getLLVMLifetimeEndFn();
1270
1271 // Make sure that this type is translated.
1272 void UpdateCompletedType(const TagDecl *TD);
1273
1274 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
1275
1276 /// Emit type info if type of an expression is a variably modified
1277 /// type. Also emit proper debug info for cast types.
1279 CodeGenFunction *CGF = nullptr);
1280
1281 /// Return the result of value-initializing the given type, i.e. a null
1282 /// expression of the given type. This is usually, but not always, an LLVM
1283 /// null constant.
1284 llvm::Constant *EmitNullConstant(QualType T);
1285
1286 /// Return a null constant appropriate for zero-initializing a base class with
1287 /// the given type. This is usually, but not always, an LLVM null constant.
1288 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
1289
1290 /// Emit a general error that something can't be done.
1291 void Error(SourceLocation loc, StringRef error);
1292
1293 /// Print out an error that codegen doesn't support the specified stmt yet.
1294 void ErrorUnsupported(const Stmt *S, const char *Type);
1295
1296 /// Print out an error that codegen doesn't support the specified decl yet.
1297 void ErrorUnsupported(const Decl *D, const char *Type);
1298
1299 /// Set the attributes on the LLVM function for the given decl and function
1300 /// info. This applies attributes necessary for handling the ABI as well as
1301 /// user specified attributes like section.
1302 void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1303 const CGFunctionInfo &FI);
1304
1305 /// Set the LLVM function attributes (sext, zext, etc).
1307 llvm::Function *F, bool IsThunk);
1308
1309 /// Set the LLVM function attributes which only apply to a function
1310 /// definition.
1311 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
1312
1313 /// Set the LLVM function attributes that represent floating point
1314 /// environment.
1315 void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F);
1316
1317 /// Return true iff the given type uses 'sret' when used as a return type.
1318 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1319
1320 /// Return true iff the given type has `inreg` set.
1321 bool ReturnTypeHasInReg(const CGFunctionInfo &FI);
1322
1323 /// Return true iff the given type uses an argument slot when 'sret' is used
1324 /// as a return type.
1326
1327 /// Return true iff the given type uses 'fpret' when used as a return type.
1328 bool ReturnTypeUsesFPRet(QualType ResultType);
1329
1330 /// Return true iff the given type uses 'fp2ret' when used as a return type.
1331 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1332
1333 /// Get the LLVM attributes and calling convention to use for a particular
1334 /// function type.
1335 ///
1336 /// \param Name - The function name.
1337 /// \param Info - The function type information.
1338 /// \param CalleeInfo - The callee information these attributes are being
1339 /// constructed for. If valid, the attributes applied to this decl may
1340 /// contribute to the function attributes and calling convention.
1341 /// \param Attrs [out] - On return, the attribute list to use.
1342 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
1343 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
1344 CGCalleeInfo CalleeInfo,
1345 llvm::AttributeList &Attrs, unsigned &CallingConv,
1346 bool AttrOnCallSite, bool IsThunk);
1347
1348 /// Adjust Memory attribute to ensure that the BE gets the right attribute
1349 // in order to generate the library call or the intrinsic for the function
1350 // name 'Name'.
1351 void AdjustMemoryAttribute(StringRef Name, CGCalleeInfo CalleeInfo,
1352 llvm::AttributeList &Attrs);
1353
1354 /// Like the overload taking a `Function &`, but intended specifically
1355 /// for frontends that want to build on Clang's target-configuration logic.
1356 void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);
1357
1358 StringRef getMangledName(GlobalDecl GD);
1359 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
1360 const GlobalDecl getMangledNameDecl(StringRef);
1361
1362 void EmitTentativeDefinition(const VarDecl *D);
1363
1365
1367
1369
1370 /// Appends Opts to the "llvm.linker.options" metadata value.
1371 void AppendLinkerOptions(StringRef Opts);
1372
1373 /// Appends a detect mismatch command to the linker options.
1374 void AddDetectMismatch(StringRef Name, StringRef Value);
1375
1376 /// Appends a dependent lib to the appropriate metadata value.
1377 void AddDependentLib(StringRef Lib);
1378
1379
1380 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1381
1382 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1383 F->setLinkage(getFunctionLinkage(GD));
1384 }
1385
1386 /// Return the appropriate linkage for the vtable, VTT, and type information
1387 /// of the given class.
1388 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1389
1390 /// Return the store size, in character units, of the given LLVM type.
1391 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1392
1393 /// Returns LLVM linkage for a declarator.
1394 llvm::GlobalValue::LinkageTypes
1396
1397 /// Returns LLVM linkage for a declarator.
1398 llvm::GlobalValue::LinkageTypes
1400
1401 /// Emit all the global annotations.
1402 void EmitGlobalAnnotations();
1403
1404 /// Emit an annotation string.
1405 llvm::Constant *EmitAnnotationString(StringRef Str);
1406
1407 /// Emit the annotation's translation unit.
1408 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1409
1410 /// Emit the annotation line number.
1411 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1412
1413 /// Emit additional args of the annotation.
1414 llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr);
1415
1416 /// Generate the llvm::ConstantStruct which contains the annotation
1417 /// information for a given GlobalValue. The annotation struct is
1418 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1419 /// GlobalValue being annotated. The second field is the constant string
1420 /// created from the AnnotateAttr's annotation. The third field is a constant
1421 /// string containing the name of the translation unit. The fourth field is
1422 /// the line number in the file of the annotated value declaration.
1423 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1424 const AnnotateAttr *AA,
1425 SourceLocation L);
1426
1427 /// Add global annotations that are set on D, for the global GV. Those
1428 /// annotations are emitted during finalization of the LLVM code.
1429 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1430
1431 bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
1432 SourceLocation Loc) const;
1433
1434 bool isInNoSanitizeList(SanitizerMask Kind, llvm::GlobalVariable *GV,
1436 StringRef Category = StringRef()) const;
1437
1438 /// Imbue XRay attributes to a function, applying the always/never attribute
1439 /// lists in the process. Returns true if we did imbue attributes this way,
1440 /// false otherwise.
1441 bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
1442 StringRef Category = StringRef()) const;
1443
1444 /// \returns true if \p Fn at \p Loc should be excluded from profile
1445 /// instrumentation by the SCL passed by \p -fprofile-list.
1447 isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
1448
1449 /// \returns true if \p Fn at \p Loc should be excluded from profile
1450 /// instrumentation.
1452 isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
1453 SourceLocation Loc) const;
1454
1456 return SanitizerMD.get();
1457 }
1458
1460 DeferredVTables.push_back(RD);
1461 }
1462
1463 /// Emit code for a single global function or var decl. Forward declarations
1464 /// are emitted lazily.
1465 void EmitGlobal(GlobalDecl D);
1466
1468
1469 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1470
1471 /// Set attributes which are common to any form of a global definition (alias,
1472 /// Objective-C method, function, global variable).
1473 ///
1474 /// NOTE: This should only be called for definitions.
1475 void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV);
1476
1477 void addReplacement(StringRef Name, llvm::Constant *C);
1478
1479 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1480
1481 /// Emit a code for threadprivate directive.
1482 /// \param D Threadprivate declaration.
1484
1485 /// Emit a code for declare reduction construct.
1487 CodeGenFunction *CGF = nullptr);
1488
1489 /// Emit a code for declare mapper construct.
1491 CodeGenFunction *CGF = nullptr);
1492
1493 /// Emit a code for requires directive.
1494 /// \param D Requires declaration
1496
1497 /// Emit a code for the allocate directive.
1498 /// \param D The allocate declaration
1500
1501 /// Return the alignment specified in an allocate directive, if present.
1502 std::optional<CharUnits> getOMPAllocateAlignment(const VarDecl *VD);
1503
1504 /// Returns whether the given record has hidden LTO visibility and therefore
1505 /// may participate in (single-module) CFI and whole-program vtable
1506 /// optimization.
1507 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
1508
1509 /// Returns whether the given record has public LTO visibility (regardless of
1510 /// -lto-whole-program-visibility) and therefore may not participate in
1511 /// (single-module) CFI and whole-program vtable optimization.
1513
1514 /// Returns the vcall visibility of the given type. This is the scope in which
1515 /// a virtual function call could be made which ends up being dispatched to a
1516 /// member function of this class. This scope can be wider than the visibility
1517 /// of the class itself when the class has a more-visible dynamic base class.
1518 /// The client should pass in an empty Visited set, which is used to prevent
1519 /// redundant recursive processing.
1520 llvm::GlobalObject::VCallVisibility
1522 llvm::DenseSet<const CXXRecordDecl *> &Visited);
1523
1524 /// Emit type metadata for the given vtable using the given layout.
1526 llvm::GlobalVariable *VTable,
1527 const VTableLayout &VTLayout);
1528
1529 llvm::Type *getVTableComponentType() const;
1530
1531 /// Generate a cross-DSO type identifier for MD.
1532 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
1533
1534 /// Generate a KCFI type identifier for T.
1535 llvm::ConstantInt *CreateKCFITypeId(QualType T);
1536
1537 /// Create a metadata identifier for the given type. This may either be an
1538 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1539 /// internal identifiers).
1541
1542 /// Create a metadata identifier that is intended to be used to check virtual
1543 /// calls via a member function pointer.
1545
1546 /// Create a metadata identifier for the generalization of the given type.
1547 /// This may either be an MDString (for external identifiers) or a distinct
1548 /// unnamed MDNode (for internal identifiers).
1550
1551 /// Create and attach type metadata to the given function.
1553 llvm::Function *F);
1554
1555 /// Set type metadata to the given function.
1556 void setKCFIType(const FunctionDecl *FD, llvm::Function *F);
1557
1558 /// Emit KCFI type identifier constants and remove unused identifiers.
1559 void finalizeKCFITypes();
1560
1561 /// Whether this function's return type has no side effects, and thus may
1562 /// be trivially discarded if it is unused.
1563 bool MayDropFunctionReturn(const ASTContext &Context,
1564 QualType ReturnType) const;
1565
1566 /// Returns whether this module needs the "all-vtables" type identifier.
1567 bool NeedAllVtablesTypeId() const;
1568
1569 /// Create and attach type metadata for the given vtable.
1570 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1571 const CXXRecordDecl *RD);
1572
1573 /// Return a vector of most-base classes for RD. This is used to implement
1574 /// control flow integrity checks for member function pointers.
1575 ///
1576 /// A most-base class of a class C is defined as a recursive base class of C,
1577 /// including C itself, that does not have any bases.
1580
1581 /// Get the declaration of std::terminate for the platform.
1582 llvm::FunctionCallee getTerminateFn();
1583
1584 llvm::SanitizerStatReport &getSanStats();
1585
1586 llvm::Value *
1588
1589 /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
1590 /// information in the program executable. The argument information stored
1591 /// includes the argument name, its type, the address and access qualifiers
1592 /// used. This helper can be used to generate metadata for source code kernel
1593 /// function as well as generated implicitly kernels. If a kernel is generated
1594 /// implicitly null value has to be passed to the last two parameters,
1595 /// otherwise all parameters must have valid non-null values.
1596 /// \param FN is a pointer to IR function being generated.
1597 /// \param FD is a pointer to function declaration if any.
1598 /// \param CGF is a pointer to CodeGenFunction that generates this function.
1599 void GenKernelArgMetadata(llvm::Function *FN,
1600 const FunctionDecl *FD = nullptr,
1601 CodeGenFunction *CGF = nullptr);
1602
1603 /// Get target specific null pointer.
1604 /// \param T is the LLVM type of the null pointer.
1605 /// \param QT is the clang QualType of the null pointer.
1606 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1607
1609 LValueBaseInfo *BaseInfo = nullptr,
1610 TBAAAccessInfo *TBAAInfo = nullptr,
1611 bool forPointeeType = false);
1613 LValueBaseInfo *BaseInfo = nullptr,
1614 TBAAAccessInfo *TBAAInfo = nullptr);
1615 bool stopAutoInit();
1616
1617 /// Print the postfix for externalized static variable or kernels for single
1618 /// source offloading languages CUDA and HIP. The unique postfix is created
1619 /// using either the CUID argument, or the file's UniqueID and active macros.
1620 /// The fallback method without a CUID requires that the offloading toolchain
1621 /// does not define separate macros via the -cc1 options.
1622 void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
1623 const Decl *D) const;
1624
1625 /// Move some lazily-emitted states to the NewBuilder. This is especially
1626 /// essential for the incremental parsing environment like Clang Interpreter,
1627 /// because we'll lose all important information after each repl.
1628 void moveLazyEmissionStates(CodeGenModule *NewBuilder);
1629
1630 /// Emit the IR encoding to attach the CUDA launch bounds attribute to \p F.
1631 /// If \p MaxThreadsVal is not nullptr, the max threads value is stored in it,
1632 /// if a valid one was found.
1633 void handleCUDALaunchBoundsAttr(llvm::Function *F,
1634 const CUDALaunchBoundsAttr *A,
1635 int32_t *MaxThreadsVal = nullptr,
1636 int32_t *MinBlocksVal = nullptr,
1637 int32_t *MaxClusterRankVal = nullptr);
1638
1639 /// Emit the IR encoding to attach the AMD GPU flat-work-group-size attribute
1640 /// to \p F. Alternatively, the work group size can be taken from a \p
1641 /// ReqdWGS. If \p MinThreadsVal is not nullptr, the min threads value is
1642 /// stored in it, if a valid one was found. If \p MaxThreadsVal is not
1643 /// nullptr, the max threads value is stored in it, if a valid one was found.
1645 llvm::Function *F, const AMDGPUFlatWorkGroupSizeAttr *A,
1646 const ReqdWorkGroupSizeAttr *ReqdWGS = nullptr,
1647 int32_t *MinThreadsVal = nullptr, int32_t *MaxThreadsVal = nullptr);
1648
1649 /// Emit the IR encoding to attach the AMD GPU waves-per-eu attribute to \p F.
1650 void handleAMDGPUWavesPerEUAttr(llvm::Function *F,
1651 const AMDGPUWavesPerEUAttr *A);
1652
1653 llvm::Constant *
1654 GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, LangAS AddrSpace,
1655 const VarDecl *D,
1656 ForDefinition_t IsForDefinition = NotForDefinition);
1657
1658 // FIXME: Hardcoding priority here is gross.
1659 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1660 unsigned LexOrder = ~0U,
1661 llvm::Constant *AssociatedData = nullptr);
1662 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
1663 bool IsDtorAttrFunc = false);
1664
1665 // Return whether structured convergence intrinsics should be generated for
1666 // this target.
1668 // TODO: this should probably become unconditional once the controlled
1669 // convergence becomes the norm.
1670 return getTriple().isSPIRVLogical();
1671 }
1672
1674 std::pair<const FunctionDecl *, SourceLocation> Global) {
1675 MustTailCallUndefinedGlobals.insert(Global);
1676 }
1677
1678private:
1679 bool shouldDropDLLAttribute(const Decl *D, const llvm::GlobalValue *GV) const;
1680
1681 llvm::Constant *GetOrCreateLLVMFunction(
1682 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1683 bool DontDefer = false, bool IsThunk = false,
1684 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1685 ForDefinition_t IsForDefinition = NotForDefinition);
1686
1687 // Adds a declaration to the list of multi version functions if not present.
1688 void AddDeferredMultiVersionResolverToEmit(GlobalDecl GD);
1689
1690 // References to multiversion functions are resolved through an implicitly
1691 // defined resolver function. This function is responsible for creating
1692 // the resolver symbol for the provided declaration. The value returned
1693 // will be for an ifunc (llvm::GlobalIFunc) if the current target supports
1694 // that feature and for a regular function (llvm::GlobalValue) otherwise.
1695 llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD);
1696
1697 // In scenarios where a function is not known to be a multiversion function
1698 // until a later declaration, it is sometimes necessary to change the
1699 // previously created mangled name to align with requirements of whatever
1700 // multiversion function kind the function is now known to be. This function
1701 // is responsible for performing such mangled name updates.
1702 void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD,
1703 StringRef &CurName);
1704
1705 bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
1706 llvm::AttrBuilder &AttrBuilder,
1707 bool SetTargetFeatures = true);
1708 void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
1709
1710 /// Set function attributes for a function declaration.
1711 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1712 bool IsIncompleteFunction, bool IsThunk);
1713
1714 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1715
1716 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1717 void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1718
1719 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1720 void EmitExternalVarDeclaration(const VarDecl *D);
1721 void EmitExternalFunctionDeclaration(const FunctionDecl *D);
1722 void EmitAliasDefinition(GlobalDecl GD);
1723 void emitIFuncDefinition(GlobalDecl GD);
1724 void emitCPUDispatchDefinition(GlobalDecl GD);
1725 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1726 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1727
1728 // C++ related functions.
1729
1730 void EmitDeclContext(const DeclContext *DC);
1731 void EmitLinkageSpec(const LinkageSpecDecl *D);
1732 void EmitTopLevelStmt(const TopLevelStmtDecl *D);
1733
1734 /// Emit the function that initializes C++ thread_local variables.
1735 void EmitCXXThreadLocalInitFunc();
1736
1737 /// Emit the function that initializes global variables for a C++ Module.
1738 void EmitCXXModuleInitFunc(clang::Module *Primary);
1739
1740 /// Emit the function that initializes C++ globals.
1741 void EmitCXXGlobalInitFunc();
1742
1743 /// Emit the function that performs cleanup associated with C++ globals.
1744 void EmitCXXGlobalCleanUpFunc();
1745
1746 /// Emit the function that initializes the specified global (if PerformInit is
1747 /// true) and registers its destructor.
1748 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1749 llvm::GlobalVariable *Addr,
1750 bool PerformInit);
1751
1752 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1753 llvm::Function *InitFunc, InitSegAttr *ISA);
1754
1755 /// EmitCtorList - Generates a global array of functions and priorities using
1756 /// the given list and name. This array will have appending linkage and is
1757 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1758 void EmitCtorList(CtorList &Fns, const char *GlobalName);
1759
1760 /// Emit any needed decls for which code generation was deferred.
1761 void EmitDeferred();
1762
1763 /// Try to emit external vtables as available_externally if they have emitted
1764 /// all inlined virtual functions. It runs after EmitDeferred() and therefore
1765 /// is not allowed to create new references to things that need to be emitted
1766 /// lazily.
1767 void EmitVTablesOpportunistically();
1768
1769 /// Call replaceAllUsesWith on all pairs in Replacements.
1770 void applyReplacements();
1771
1772 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1773 void applyGlobalValReplacements();
1774
1775 void checkAliases();
1776
1777 std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit;
1778
1779 /// Register functions annotated with __attribute__((destructor)) using
1780 /// __cxa_atexit, if it is available, or atexit otherwise.
1781 void registerGlobalDtorsWithAtExit();
1782
1783 // When using sinit and sterm functions, unregister
1784 // __attribute__((destructor)) annotated functions which were previously
1785 // registered by the atexit subroutine using unatexit.
1786 void unregisterGlobalDtorsWithUnAtExit();
1787
1788 /// Emit deferred multiversion function resolvers and associated variants.
1789 void emitMultiVersionFunctions();
1790
1791 /// Emit any vtables which we deferred and still have a use for.
1792 void EmitDeferredVTables();
1793
1794 /// Emit a dummy function that reference a CoreFoundation symbol when
1795 /// @available is used on Darwin.
1796 void emitAtAvailableLinkGuard();
1797
1798 /// Emit the llvm.used and llvm.compiler.used metadata.
1799 void emitLLVMUsed();
1800
1801 /// For C++20 Itanium ABI, emit the initializers for the module.
1802 void EmitModuleInitializers(clang::Module *Primary);
1803
1804 /// Emit the link options introduced by imported modules.
1805 void EmitModuleLinkOptions();
1806
1807 /// Helper function for EmitStaticExternCAliases() to redirect ifuncs that
1808 /// have a resolver name that matches 'Elem' to instead resolve to the name of
1809 /// 'CppFunc'. This redirection is necessary in cases where 'Elem' has a name
1810 /// that will be emitted as an alias of the name bound to 'CppFunc'; ifuncs
1811 /// may not reference aliases. Redirection is only performed if 'Elem' is only
1812 /// used by ifuncs in which case, 'Elem' is destroyed. 'true' is returned if
1813 /// redirection is successful, and 'false' is returned otherwise.
1814 bool CheckAndReplaceExternCIFuncs(llvm::GlobalValue *Elem,
1815 llvm::GlobalValue *CppFunc);
1816
1817 /// Emit aliases for internal-linkage declarations inside "C" language
1818 /// linkage specifications, giving them the "expected" name where possible.
1819 void EmitStaticExternCAliases();
1820
1821 void EmitDeclMetadata();
1822
1823 /// Emit the Clang version as llvm.ident metadata.
1824 void EmitVersionIdentMetadata();
1825
1826 /// Emit the Clang commandline as llvm.commandline metadata.
1827 void EmitCommandLineMetadata();
1828
1829 /// Emit the module flag metadata used to pass options controlling the
1830 /// the backend to LLVM.
1831 void EmitBackendOptionsMetadata(const CodeGenOptions &CodeGenOpts);
1832
1833 /// Emits OpenCL specific Metadata e.g. OpenCL version.
1834 void EmitOpenCLMetadata();
1835
1836 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1837 /// .gcda files in a way that persists in .bc files.
1838 void EmitCoverageFile();
1839
1840 /// Determine whether the definition must be emitted; if this returns \c
1841 /// false, the definition can be emitted lazily if it's used.
1842 bool MustBeEmitted(const ValueDecl *D);
1843
1844 /// Determine whether the definition can be emitted eagerly, or should be
1845 /// delayed until the end of the translation unit. This is relevant for
1846 /// definitions whose linkage can change, e.g. implicit function instantions
1847 /// which may later be explicitly instantiated.
1848 bool MayBeEmittedEagerly(const ValueDecl *D);
1849
1850 /// Check whether we can use a "simpler", more core exceptions personality
1851 /// function.
1852 void SimplifyPersonality();
1853
1854 /// Helper function for getDefaultFunctionAttributes. Builds a set of function
1855 /// attributes which can be simply added to a function.
1856 void getTrivialDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1857 bool AttrOnCallSite,
1858 llvm::AttrBuilder &FuncAttrs);
1859
1860 /// Helper function for ConstructAttributeList and
1861 /// addDefaultFunctionDefinitionAttributes. Builds a set of function
1862 /// attributes to add to a function with the given properties.
1863 void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1864 bool AttrOnCallSite,
1865 llvm::AttrBuilder &FuncAttrs);
1866
1867 llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
1868 StringRef Suffix);
1869};
1870
1871} // end namespace CodeGen
1872} // end namespace clang
1873
1874#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:3341
const Decl * D
enum clang::sema::@1653::IndirectLocalPathEntry::EntryKind Kind
Expr * E
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:3005
int Category
Definition: Format.cpp:3004
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:146
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
SourceLocation Loc
Definition: SemaObjC.cpp:759
__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:187
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Attr - This represents one attribute.
Definition: Attr.h:42
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4471
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6365
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2803
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3565
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...
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:128
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:41
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:58
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:2849
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)
void handleCUDALaunchBoundsAttr(llvm::Function *F, const CUDALaunchBoundsAttr *A, int32_t *MaxThreadsVal=nullptr, int32_t *MinBlocksVal=nullptr, int32_t *MaxClusterRankVal=nullptr)
Emit the IR encoding to attach the CUDA launch bounds attribute to F.
Definition: NVPTX.cpp:314
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:1244
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:1317
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.
void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F)
Set the LLVM function attributes that represent floating point environment.
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.
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:2509
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
void handleAMDGPUWavesPerEUAttr(llvm::Function *F, const AMDGPUWavesPerEUAttr *A)
Emit the IR encoding to attach the AMD GPU waves-per-eu attribute to F.
Definition: AMDGPU.cpp:690
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:60
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C)
llvm::Constant * getRawFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return a function pointer for a reference to the given function.
Definition: CGExpr.cpp:2879
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Definition: CGCXX.cpp:220
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:1106
void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const
llvm::Constant * getFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return the ABI-correct function pointer value for a reference to the given function.
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:1258
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:1573
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:100
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)
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)
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:1097
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
Definition: CGBlocks.cpp:1266
llvm::Constant * getAtomicGetterHelperFnMap(QualType Ty)
CGPointerAuthInfo getMemberFunctionPointerAuthInfo(QualType FT)
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
bool shouldEmitRTTI(bool ForEH=false)
void EmitGlobal(GlobalDecl D)
Emit code for a single global function or var decl.
llvm::GlobalVariable * getStaticLocalDeclGuardAddress(const VarDecl *D)
llvm::ConstantInt * getPointerAuthOtherDiscriminator(const PointerAuthSchema &Schema, GlobalDecl SchemaDecl, QualType SchemaType)
Given a pointer-authentication schema, return a concrete "other" discriminator for it.
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
llvm::Constant * getTypeDescriptorFromMap(QualType Ty)
llvm::IndexedInstrProfReader * getPGOReader() const
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void handleAMDGPUFlatWorkGroupSizeAttr(llvm::Function *F, const AMDGPUFlatWorkGroupSizeAttr *A, const ReqdWorkGroupSizeAttr *ReqdWGS=nullptr, int32_t *MinThreadsVal=nullptr, int32_t *MaxThreadsVal=nullptr)
Emit the IR encoding to attach the AMD GPU flat-work-group-size attribute to F.
Definition: AMDGPU.cpp:663
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 EmitExternalDeclaration(const DeclaratorDecl *D)
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the appropriate metadata value.
void Release()
Finalize LLVM code generation.
llvm::FunctionCallee IsOSVersionAtLeastFn
ProfileList::ExclusionType isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const
CGPointerAuthInfo getPointerAuthInfoForPointeeType(QualType type)
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
CGPointerAuthInfo EmitPointerAuthInfo(const RecordDecl *RD)
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:1351
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
void EmitOMPAllocateDecl(const OMPAllocateDecl *D)
Emit a code for the allocate directive.
Definition: CGDecl.cpp:2766
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:201
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::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
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:1305
const llvm::DataLayout & getDataLayout() const
llvm::Constant * getNSConcreteGlobalBlock()
Definition: CGBlocks.cpp:2862
void addUndefinedGlobalForTailCall(std::pair< const FunctionDecl *, SourceLocation > Global)
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
Definition: CGClass.cpp:173
ObjCEntrypoints & getObjCEntrypoints() const
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table poi...
bool shouldEmitConvergenceTokens() const
CGCXXABI & getCXXABI() const
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
CGPointerAuthInfo getFunctionPointerAuthInfo(QualType T)
Return the abstract pointer authentication schema for a pointer to the given function type.
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
Definition: CGClass.cpp:77
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.
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:1590
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.
llvm::Constant * getMemberFunctionPointer(const FunctionDecl *FD, llvm::Type *Ty=nullptr)
SanitizerMetadata * getSanitizerMetadata()
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
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...
std::optional< PointerAuthQualifier > getVTablePointerAuthentication(const CXXRecordDecl *thisClass)
llvm::Function * codegenCXXStructor(GlobalDecl GD)
Definition: CGCXX.cpp:206
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:41
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:246
SmallVector< const CXXRecordDecl *, 0 > getMostBaseClasses(const CXXRecordDecl *RD)
Return a vector of most-base classes for RD.
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:1281
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.
uint16_t getPointerAuthDeclDiscriminator(GlobalDecl GD)
Return the "other" decl-specific discriminator for the given decl.
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)
void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535, bool IsDtorAttrFunc=false)
AddGlobalDtor - Add a function to the list that will be called when the module is unloaded.
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:1568
bool ReturnTypeHasInReg(const CGFunctionInfo &FI)
Return true iff the given type has inreg set.
Definition: CGCall.cpp:1563
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:1186
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
void AdjustMemoryAttribute(StringRef Name, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs)
Adjust Memory attribute to ensure that the BE gets the right attribute.
Definition: CGCall.cpp:2283
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:2311
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:92
llvm::Constant * GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, LangAS AddrSpace, const VarDecl *D, ForDefinition_t IsForDefinition=NotForDefinition)
GetOrCreateLLVMGlobal - If the specified mangled name is not in the module, create and return an llvm...
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:2872
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:716
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
Definition: CGDecl.cpp:2754
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the @llvm.lifetime.end intrinsic.
Definition: CGDecl.cpp:2518
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:2762
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:1558
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,...
void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs)
Like the overload taking a Function &, but intended specifically for frontends that want to build on ...
Definition: CGCall.cpp:2136
std::optional< CharUnits > getOMPAllocateAlignment(const VarDecl *VD)
Return the alignment specified in an allocate directive, if present.
Definition: CGDecl.cpp:2821
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:2836
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:2747
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
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:1081
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:1129
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.
std::optional< CGPointerAuthInfo > getVTablePointerAuthInfo(CodeGenFunction *Context, const CXXRecordDecl *Record, llvm::Value *StorageAddress)
llvm::Constant * getConstantSignedPointer(llvm::Constant *Pointer, const PointerAuthSchema &Schema, llvm::Constant *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Sign a constant pointer using the given scheme, producing a constant with the same IR type.
llvm::FunctionCallee IsPlatformVersionAtLeastFn
void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535, unsigned LexOrder=~0U, llvm::Constant *AssociatedData=nullptr)
AddGlobalCtor - Add a function to the list that will be called before main() runs.
bool shouldSignPointer(const PointerAuthSchema &Schema)
Does a given PointerAuthScheme require us to sign a value.
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:1796
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:443
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
CGPointerAuthInfo getPointerAuthInfoForType(QualType type)
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:35
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:294
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:182
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:47
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3428
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:1436
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:731
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:3750
This represents one expression.
Definition: Expr.h:110
Represents a function declaration or definition.
Definition: Decl.h:1932
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4308
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:476
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:742
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:747
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:752
Represents a linkage specification.
Definition: DeclCXX.h:2938
A global _GUID constant.
Definition: DeclCXX.h:4293
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4727
Describes a module or submodule.
Definition: Module.h:105
This represents a decl that may have a name.
Definition: Decl.h:249
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:474
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:287
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:177
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:417
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2596
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:941
Represents a struct/union/class.
Definition: Decl.h:4145
Encodes a location in the source.
Stmt - This represents one statement.
Definition: Stmt.h:84
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3561
Exposes information about the current target.
Definition: TargetInfo.h:218
A template parameter object.
A declaration that models statements at global scope.
Definition: Decl.h:4434
The base class of the type hierarchy.
Definition: Type.h:1829
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1882
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2188
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4350
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
Represents a variable declaration or definition.
Definition: Decl.h:879
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.
The JSON file list parser is used to communicate input to InstallAPI.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:72
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ 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
const FunctionProtoType * T
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:278
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:37
@ ProtectedVisibility
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition: Visibility.h:42
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
Definition: Visibility.h:46
Diagnostic wrappers for TextAPI types for error reporting.
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:63