clang 19.0.0git
CodeGenModule.h
Go to the documentation of this file.
1//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the internal per-translation-unit state used for llvm translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
14#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15
16#include "CGVTables.h"
17#include "CodeGenTypeCache.h"
18#include "CodeGenTypes.h"
19#include "SanitizerMetadata.h"
20#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclObjC.h"
24#include "clang/AST/Mangle.h"
25#include "clang/Basic/ABI.h"
27#include "clang/Basic/Module.h"
33#include "llvm/ADT/DenseMap.h"
34#include "llvm/ADT/MapVector.h"
35#include "llvm/ADT/SetVector.h"
36#include "llvm/ADT/SmallPtrSet.h"
37#include "llvm/ADT/StringMap.h"
38#include "llvm/IR/Module.h"
39#include "llvm/IR/ValueHandle.h"
40#include "llvm/Transforms/Utils/SanitizerStats.h"
41#include <optional>
42
43namespace llvm {
44class Module;
45class Constant;
46class ConstantInt;
47class Function;
48class GlobalValue;
49class DataLayout;
50class FunctionType;
51class LLVMContext;
52class IndexedInstrProfReader;
53
54namespace vfs {
55class FileSystem;
56}
57}
58
59namespace clang {
60class ASTContext;
61class AtomicType;
62class FunctionDecl;
63class IdentifierInfo;
64class ObjCImplementationDecl;
65class ObjCEncodeExpr;
66class BlockExpr;
67class CharUnits;
68class Decl;
69class Expr;
70class Stmt;
71class StringLiteral;
72class NamedDecl;
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 /// This is a list of deferred decls which we have seen that *are* actually
352 /// referenced. These get code generated when the module is done.
353 std::vector<GlobalDecl> DeferredDeclsToEmit;
354 void addDeferredDeclToEmit(GlobalDecl GD) {
355 DeferredDeclsToEmit.emplace_back(GD);
356 addEmittedDeferredDecl(GD);
357 }
358
359 /// Decls that were DeferredDecls and have now been emitted.
360 llvm::DenseMap<llvm::StringRef, GlobalDecl> EmittedDeferredDecls;
361
362 void addEmittedDeferredDecl(GlobalDecl GD) {
363 // Reemission is only needed in incremental mode.
364 if (!Context.getLangOpts().IncrementalExtensions)
365 return;
366
367 // Assume a linkage by default that does not need reemission.
368 auto L = llvm::GlobalValue::ExternalLinkage;
369 if (llvm::isa<FunctionDecl>(GD.getDecl()))
370 L = getFunctionLinkage(GD);
371 else if (auto *VD = llvm::dyn_cast<VarDecl>(GD.getDecl()))
373
374 if (llvm::GlobalValue::isInternalLinkage(L) ||
375 llvm::GlobalValue::isLinkOnceLinkage(L) ||
376 llvm::GlobalValue::isWeakLinkage(L)) {
377 EmittedDeferredDecls[getMangledName(GD)] = GD;
378 }
379 }
380
381 /// List of alias we have emitted. Used to make sure that what they point to
382 /// is defined once we get to the end of the of the translation unit.
383 std::vector<GlobalDecl> Aliases;
384
385 /// List of multiversion functions to be emitted. This list is processed in
386 /// conjunction with other deferred symbols and is used to ensure that
387 /// multiversion function resolvers and ifuncs are defined and emitted.
388 std::vector<GlobalDecl> MultiVersionFuncs;
389
390 llvm::MapVector<StringRef, llvm::TrackingVH<llvm::Constant>> Replacements;
391
392 /// List of global values to be replaced with something else. Used when we
393 /// want to replace a GlobalValue but can't identify it by its mangled name
394 /// anymore (because the name is already taken).
396 GlobalValReplacements;
397
398 /// Variables for which we've emitted globals containing their constant
399 /// values along with the corresponding globals, for opportunistic reuse.
400 llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants;
401
402 /// Set of global decls for which we already diagnosed mangled name conflict.
403 /// Required to not issue a warning (on a mangling conflict) multiple times
404 /// for the same decl.
405 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
406
407 /// A queue of (optional) vtables to consider emitting.
408 std::vector<const CXXRecordDecl*> DeferredVTables;
409
410 /// A queue of (optional) vtables that may be emitted opportunistically.
411 std::vector<const CXXRecordDecl *> OpportunisticVTables;
412
413 /// List of global values which are required to be present in the object file;
414 /// bitcast to i8*. This is used for forcing visibility of symbols which may
415 /// otherwise be optimized out.
416 std::vector<llvm::WeakTrackingVH> LLVMUsed;
417 std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
418
419 /// Store the list of global constructors and their respective priorities to
420 /// be emitted when the translation unit is complete.
421 CtorList GlobalCtors;
422
423 /// Store the list of global destructors and their respective priorities to be
424 /// emitted when the translation unit is complete.
425 CtorList GlobalDtors;
426
427 /// An ordered map of canonical GlobalDecls to their mangled names.
428 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
429 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
430
431 /// Global annotations.
432 std::vector<llvm::Constant*> Annotations;
433
434 // Store deferred function annotations so they can be emitted at the end with
435 // most up to date ValueDecl that will have all the inherited annotations.
436 llvm::DenseMap<StringRef, const ValueDecl *> DeferredAnnotations;
437
438 /// Map used to get unique annotation strings.
439 llvm::StringMap<llvm::Constant*> AnnotationStrings;
440
441 /// Used for uniquing of annotation arguments.
442 llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
443
444 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
445
446 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
447 llvm::DenseMap<const UnnamedGlobalConstantDecl *, llvm::GlobalVariable *>
448 UnnamedGlobalConstantDeclMap;
449 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
450 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
451 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
452
453 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
454 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
455
456 /// Map used to get unique type descriptor constants for sanitizers.
457 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
458
459 /// Map used to track internal linkage functions declared within
460 /// extern "C" regions.
461 typedef llvm::MapVector<IdentifierInfo *,
462 llvm::GlobalValue *> StaticExternCMap;
463 StaticExternCMap StaticExternCValues;
464
465 /// thread_local variables defined or used in this TU.
466 std::vector<const VarDecl *> CXXThreadLocals;
467
468 /// thread_local variables with initializers that need to run
469 /// before any thread_local variable in this TU is odr-used.
470 std::vector<llvm::Function *> CXXThreadLocalInits;
471 std::vector<const VarDecl *> CXXThreadLocalInitVars;
472
473 /// Global variables with initializers that need to run before main.
474 std::vector<llvm::Function *> CXXGlobalInits;
475
476 /// When a C++ decl with an initializer is deferred, null is
477 /// appended to CXXGlobalInits, and the index of that null is placed
478 /// here so that the initializer will be performed in the correct
479 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
480 /// that we don't re-emit the initializer.
481 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
482
483 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
484 GlobalInitData;
485
486 struct GlobalInitPriorityCmp {
487 bool operator()(const GlobalInitData &LHS,
488 const GlobalInitData &RHS) const {
489 return LHS.first.priority < RHS.first.priority;
490 }
491 };
492
493 /// Global variables with initializers whose order of initialization is set by
494 /// init_priority attribute.
495 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
496
497 /// Global destructor functions and arguments that need to run on termination.
498 /// When UseSinitAndSterm is set, it instead contains sterm finalizer
499 /// functions, which also run on unloading a shared library.
500 typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
501 llvm::Constant *>
502 CXXGlobalDtorsOrStermFinalizer_t;
503 SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8>
504 CXXGlobalDtorsOrStermFinalizers;
505
506 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
507 StermFinalizerData;
508
509 struct StermFinalizerPriorityCmp {
510 bool operator()(const StermFinalizerData &LHS,
511 const StermFinalizerData &RHS) const {
512 return LHS.first.priority < RHS.first.priority;
513 }
514 };
515
516 /// Global variables with sterm finalizers whose order of initialization is
517 /// set by init_priority attribute.
518 SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers;
519
520 /// The complete set of modules that has been imported.
521 llvm::SetVector<clang::Module *> ImportedModules;
522
523 /// The set of modules for which the module initializers
524 /// have been emitted.
525 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
526
527 /// A vector of metadata strings for linker options.
528 SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
529
530 /// A vector of metadata strings for dependent libraries for ELF.
531 SmallVector<llvm::MDNode *, 16> ELFDependentLibraries;
532
533 /// @name Cache for Objective-C runtime types
534 /// @{
535
536 /// Cached reference to the class for constant strings. This value has type
537 /// int * but is actually an Obj-C class pointer.
538 llvm::WeakTrackingVH CFConstantStringClassRef;
539
540 /// The type used to describe the state of a fast enumeration in
541 /// Objective-C's for..in loop.
542 QualType ObjCFastEnumerationStateType;
543
544 /// @}
545
546 /// Lazily create the Objective-C runtime
547 void createObjCRuntime();
548
549 void createOpenCLRuntime();
550 void createOpenMPRuntime();
551 void createCUDARuntime();
552 void createHLSLRuntime();
553
554 bool isTriviallyRecursive(const FunctionDecl *F);
555 bool shouldEmitFunction(GlobalDecl GD);
556 bool shouldOpportunisticallyEmitVTables();
557 /// Map used to be sure we don't emit the same CompoundLiteral twice.
558 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
559 EmittedCompoundLiterals;
560
561 /// Map of the global blocks we've emitted, so that we don't have to re-emit
562 /// them if the constexpr evaluator gets aggressive.
563 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
564
565 /// @name Cache for Blocks Runtime Globals
566 /// @{
567
568 llvm::Constant *NSConcreteGlobalBlock = nullptr;
569 llvm::Constant *NSConcreteStackBlock = nullptr;
570
571 llvm::FunctionCallee BlockObjectAssign = nullptr;
572 llvm::FunctionCallee BlockObjectDispose = nullptr;
573
574 llvm::Type *BlockDescriptorType = nullptr;
575 llvm::Type *GenericBlockLiteralType = nullptr;
576
577 struct {
579 } Block;
580
581 GlobalDecl initializedGlobalDecl;
582
583 /// @}
584
585 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
586 llvm::Function *LifetimeStartFn = nullptr;
587
588 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
589 llvm::Function *LifetimeEndFn = nullptr;
590
591 std::unique_ptr<SanitizerMetadata> SanitizerMD;
592
593 llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
594
595 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
596
597 /// Mapping from canonical types to their metadata identifiers. We need to
598 /// maintain this mapping because identifiers may be formed from distinct
599 /// MDNodes.
600 typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap;
601 MetadataTypeMap MetadataIdMap;
602 MetadataTypeMap VirtualMetadataIdMap;
603 MetadataTypeMap GeneralizedMetadataIdMap;
604
605 // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
606 // when used with -fincremental-extensions.
607 std::pair<std::unique_ptr<CodeGenFunction>, const TopLevelStmtDecl *>
608 GlobalTopLevelStmtBlockInFlight;
609
610public:
612 const HeaderSearchOptions &headersearchopts,
613 const PreprocessorOptions &ppopts,
614 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
615 DiagnosticsEngine &Diags,
616 CoverageSourceInfo *CoverageInfo = nullptr);
617
619
620 void clear();
621
622 /// Finalize LLVM code generation.
623 void Release();
624
625 /// Return true if we should emit location information for expressions.
627
628 /// Return a reference to the configured Objective-C runtime.
630 if (!ObjCRuntime) createObjCRuntime();
631 return *ObjCRuntime;
632 }
633
634 /// Return true iff an Objective-C runtime has been configured.
635 bool hasObjCRuntime() { return !!ObjCRuntime; }
636
637 const std::string &getModuleNameHash() const { return ModuleNameHash; }
638
639 /// Return a reference to the configured OpenCL runtime.
641 assert(OpenCLRuntime != nullptr);
642 return *OpenCLRuntime;
643 }
644
645 /// Return a reference to the configured OpenMP runtime.
647 assert(OpenMPRuntime != nullptr);
648 return *OpenMPRuntime;
649 }
650
651 /// Return a reference to the configured CUDA runtime.
653 assert(CUDARuntime != nullptr);
654 return *CUDARuntime;
655 }
656
657 /// Return a reference to the configured HLSL runtime.
659 assert(HLSLRuntime != nullptr);
660 return *HLSLRuntime;
661 }
662
664 assert(ObjCData != nullptr);
665 return *ObjCData;
666 }
667
668 // Version checking functions, used to implement ObjC's @available:
669 // i32 @__isOSVersionAtLeast(i32, i32, i32)
670 llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr;
671 // i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32)
672 llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr;
673
674 InstrProfStats &getPGOStats() { return PGOStats; }
675 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
676
678 return CoverageMapping.get();
679 }
680
681 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
682 return StaticLocalDeclMap[D];
683 }
685 llvm::Constant *C) {
686 StaticLocalDeclMap[D] = C;
687 }
688
689 llvm::Constant *
691 llvm::GlobalValue::LinkageTypes Linkage);
692
693 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
694 return StaticLocalDeclGuardMap[D];
695 }
697 llvm::GlobalVariable *C) {
698 StaticLocalDeclGuardMap[D] = C;
699 }
700
701 Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant,
702 CharUnits Align);
703
704 bool lookupRepresentativeDecl(StringRef MangledName,
705 GlobalDecl &Result) const;
706
708 return AtomicSetterHelperFnMap[Ty];
709 }
711 llvm::Constant *Fn) {
712 AtomicSetterHelperFnMap[Ty] = Fn;
713 }
714
716 return AtomicGetterHelperFnMap[Ty];
717 }
719 llvm::Constant *Fn) {
720 AtomicGetterHelperFnMap[Ty] = Fn;
721 }
722
723 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
724 return TypeDescriptorMap[Ty];
725 }
726 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
727 TypeDescriptorMap[Ty] = C;
728 }
729
730 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
731
733 if (!NoObjCARCExceptionsMetadata)
734 NoObjCARCExceptionsMetadata =
735 llvm::MDNode::get(getLLVMContext(), std::nullopt);
736 return NoObjCARCExceptionsMetadata;
737 }
738
739 ASTContext &getContext() const { return Context; }
740 const LangOptions &getLangOpts() const { return LangOpts; }
742 return FS;
743 }
745 const { return HeaderSearchOpts; }
747 const { return PreprocessorOpts; }
748 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
749 llvm::Module &getModule() const { return TheModule; }
750 DiagnosticsEngine &getDiags() const { return Diags; }
751 const llvm::DataLayout &getDataLayout() const {
752 return TheModule.getDataLayout();
753 }
754 const TargetInfo &getTarget() const { return Target; }
755 const llvm::Triple &getTriple() const { return Target.getTriple(); }
756 bool supportsCOMDAT() const;
757 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
758
759 CGCXXABI &getCXXABI() const { return *ABI; }
760 llvm::LLVMContext &getLLVMContext() { return VMContext; }
761
762 bool shouldUseTBAA() const { return TBAA != nullptr; }
763
765
766 CodeGenTypes &getTypes() { return Types; }
767
768 CodeGenVTables &getVTables() { return VTables; }
769
771 return VTables.getItaniumVTableContext();
772 }
773
775 return VTables.getItaniumVTableContext();
776 }
777
779 return VTables.getMicrosoftVTableContext();
780 }
781
782 CtorList &getGlobalCtors() { return GlobalCtors; }
783 CtorList &getGlobalDtors() { return GlobalDtors; }
784
785 /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
786 /// the given type.
787 llvm::MDNode *getTBAATypeInfo(QualType QTy);
788
789 /// getTBAAAccessInfo - Get TBAA information that describes an access to
790 /// an object of the given type.
792
793 /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
794 /// access to a virtual table pointer.
795 TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
796
797 llvm::MDNode *getTBAAStructInfo(QualType QTy);
798
799 /// getTBAABaseTypeInfo - Get metadata that describes the given base access
800 /// type. Return null if the type is not suitable for use in TBAA access tags.
801 llvm::MDNode *getTBAABaseTypeInfo(QualType QTy);
802
803 /// getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
804 llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info);
805
806 /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of
807 /// type casts.
810
811 /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
812 /// purposes of conditional operator.
814 TBAAAccessInfo InfoB);
815
816 /// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the
817 /// purposes of memory transfer calls.
819 TBAAAccessInfo SrcInfo);
820
821 /// getTBAAInfoForSubobject - Get TBAA information for an access with a given
822 /// base lvalue.
824 if (Base.getTBAAInfo().isMayAlias())
826 return getTBAAAccessInfo(AccessType);
827 }
828
831
832 /// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
833 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
834 TBAAAccessInfo TBAAInfo);
835
836 /// Adds !invariant.barrier !tag to instruction
837 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
838 const CXXRecordDecl *RD);
839
840 /// Emit the given number of characters as a value of type size_t.
841 llvm::ConstantInt *getSize(CharUnits numChars);
842
843 /// Set the visibility for the given LLVM GlobalValue.
844 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
845
846 void setDSOLocal(llvm::GlobalValue *GV) const;
847
855 }
856 void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
857 void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const;
858 /// Set visibility, dllimport/dllexport and dso_local.
859 /// This must be called after dllimport/dllexport is set.
860 void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
861 void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
862
863 void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
864
865 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
866 /// variable declaration D.
867 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
868
869 /// Get LLVM TLS mode from CodeGenOptions.
870 llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const;
871
872 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
873 switch (V) {
874 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
875 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
876 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
877 }
878 llvm_unreachable("unknown visibility!");
879 }
880
881 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
882 ForDefinition_t IsForDefinition
884
885 /// Will return a global variable of the given type. If a variable with a
886 /// different type already exists then a new variable with the right type
887 /// will be created and all uses of the old variable will be replaced with a
888 /// bitcast to the new variable.
889 llvm::GlobalVariable *
890 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
891 llvm::GlobalValue::LinkageTypes Linkage,
892 llvm::Align Alignment);
893
894 llvm::Function *CreateGlobalInitOrCleanUpFunction(
895 llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI,
896 SourceLocation Loc = SourceLocation(), bool TLS = false,
897 llvm::GlobalVariable::LinkageTypes Linkage =
898 llvm::GlobalVariable::InternalLinkage);
899
900 /// Return the AST address space of the underlying global variable for D, as
901 /// determined by its declaration. Normally this is the same as the address
902 /// space of D's type, but in CUDA, address spaces are associated with
903 /// declarations, not types. If D is nullptr, return the default address
904 /// space for global variable.
905 ///
906 /// For languages without explicit address spaces, if D has default address
907 /// space, target-specific global or constant address space may be returned.
909
910 /// Return the AST address space of constant literal, which is used to emit
911 /// the constant literal as global variable in LLVM IR.
912 /// Note: This is not necessarily the address space of the constant literal
913 /// in AST. For address space agnostic language, e.g. C++, constant literal
914 /// in AST is always in default address space.
916
917 /// Return the llvm::Constant for the address of the given global variable.
918 /// If Ty is non-null and if the global doesn't exist, then it will be created
919 /// with the specified type instead of whatever the normal requested type
920 /// would be. If IsForDefinition is true, it is guaranteed that an actual
921 /// global with type Ty will be returned, not conversion of a variable with
922 /// the same mangled name but some other type.
923 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
924 llvm::Type *Ty = nullptr,
925 ForDefinition_t IsForDefinition
927
928 /// Return the address of the given function. If Ty is non-null, then this
929 /// function will use the specified type if it has to create it.
930 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
931 bool ForVTable = false,
932 bool DontDefer = false,
933 ForDefinition_t IsForDefinition
935
936 // Return the function body address of the given function.
937 llvm::Constant *GetFunctionStart(const ValueDecl *Decl);
938
939 // Return whether RTTI information should be emitted for this target.
940 bool shouldEmitRTTI(bool ForEH = false) {
941 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
942 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
943 getTriple().isNVPTX());
944 }
945
946 /// Get the address of the RTTI descriptor for the given type.
947 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
948
949 /// Get the address of a GUID.
951
952 /// Get the address of a UnnamedGlobalConstant
955
956 /// Get the address of a template parameter object.
959
960 /// Get the address of the thunk for the given global decl.
961 llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
962 GlobalDecl GD);
963
964 /// Get a reference to the target of VD.
966
967 /// Returns the assumed alignment of an opaque pointer to the given class.
969
970 /// Returns the minimum object size for an object of the given class type
971 /// (or a class derived from it).
973
974 /// Returns the minimum object size for an object of the given type.
976 if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
977 return getMinimumClassObjectSize(RD);
978 return getContext().getTypeSizeInChars(Ty);
979 }
980
981 /// Returns the assumed alignment of a virtual base of a class.
983 const CXXRecordDecl *Derived,
984 const CXXRecordDecl *VBase);
985
986 /// Given a class pointer with an actual known alignment, and the
987 /// expected alignment of an object at a dynamic offset w.r.t that
988 /// pointer, return the alignment to assume at the offset.
990 const CXXRecordDecl *Class,
991 CharUnits ExpectedTargetAlign);
992
997
998 /// Returns the offset from a derived class to a class. Returns null if the
999 /// offset is 0.
1000 llvm::Constant *
1004
1005 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
1006
1007 /// Fetches the global unique block count.
1008 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
1009
1010 /// Fetches the type of a generic block descriptor.
1011 llvm::Type *getBlockDescriptorType();
1012
1013 /// The type of a generic block literal.
1014 llvm::Type *getGenericBlockLiteralType();
1015
1016 /// Gets the address of a block which requires no captures.
1017 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
1018
1019 /// Returns the address of a block which requires no caputres, or null if
1020 /// we've yet to emit the block for BE.
1021 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
1022 return EmittedGlobalBlocks.lookup(BE);
1023 }
1024
1025 /// Notes that BE's global block is available via Addr. Asserts that BE
1026 /// isn't already emitted.
1027 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
1028
1029 /// Return a pointer to a constant CFString object for the given string.
1031
1032 /// Return a constant array for the given string.
1033 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
1034
1035 /// Return a pointer to a constant array for the given string literal.
1038 StringRef Name = ".str");
1039
1040 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
1043
1044 /// Returns a pointer to a character array containing the literal and a
1045 /// terminating '\0' character. The result has pointer to array type.
1046 ///
1047 /// \param GlobalName If provided, the name to use for the global (if one is
1048 /// created).
1050 GetAddrOfConstantCString(const std::string &Str,
1051 const char *GlobalName = nullptr);
1052
1053 /// Returns a pointer to a constant global variable for the given file-scope
1054 /// compound literal expression.
1056
1057 /// If it's been emitted already, returns the GlobalVariable corresponding to
1058 /// a compound literal. Otherwise, returns null.
1059 llvm::GlobalVariable *
1061
1062 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
1063 /// emitted.
1065 llvm::GlobalVariable *GV);
1066
1067 /// Returns a pointer to a global variable representing a temporary
1068 /// with static or thread storage duration.
1070 const Expr *Inner);
1071
1072 /// Retrieve the record type that describes the state of an
1073 /// Objective-C fast enumeration loop (for..in).
1075
1076 // Produce code for this constructor/destructor. This method doesn't try
1077 // to apply any ABI rules about which other constructors/destructors
1078 // are needed or if they are alias to each other.
1079 llvm::Function *codegenCXXStructor(GlobalDecl GD);
1080
1081 /// Return the address of the constructor/destructor of the given type.
1082 llvm::Constant *
1084 llvm::FunctionType *FnType = nullptr,
1085 bool DontDefer = false,
1086 ForDefinition_t IsForDefinition = NotForDefinition) {
1087 return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType,
1088 DontDefer,
1089 IsForDefinition)
1090 .getCallee());
1091 }
1092
1093 llvm::FunctionCallee getAddrAndTypeOfCXXStructor(
1094 GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
1095 llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
1096 ForDefinition_t IsForDefinition = NotForDefinition);
1097
1098 /// Given a builtin id for a function like "__builtin_fabsf", return a
1099 /// Function* for "fabsf".
1100 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
1101 unsigned BuiltinID);
1102
1103 llvm::Function *getIntrinsic(unsigned IID,
1104 ArrayRef<llvm::Type *> Tys = std::nullopt);
1105
1106 /// Emit code for a single top level declaration.
1107 void EmitTopLevelDecl(Decl *D);
1108
1109 /// Stored a deferred empty coverage mapping for an unused
1110 /// and thus uninstrumented top level declaration.
1112
1113 /// Remove the deferred empty coverage mapping as this
1114 /// declaration is actually instrumented.
1115 void ClearUnusedCoverageMapping(const Decl *D);
1116
1117 /// Emit all the deferred coverage mappings
1118 /// for the uninstrumented functions.
1120
1121 /// Emit an alias for "main" if it has no arguments (needed for wasm).
1122 void EmitMainVoidAlias();
1123
1124 /// Tell the consumer that this variable has been instantiated.
1126
1127 /// If the declaration has internal linkage but is inside an
1128 /// extern "C" linkage specification, prepare to emit an alias for it
1129 /// to the expected name.
1130 template<typename SomeDecl>
1131 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
1132
1133 /// Add a global to a list to be added to the llvm.used metadata.
1134 void addUsedGlobal(llvm::GlobalValue *GV);
1135
1136 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1137 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
1138
1139 /// Add a global to a list to be added to the llvm.compiler.used metadata.
1140 void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
1141
1142 /// Add a destructor and object to add to the C++ global destructor function.
1143 void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
1144 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1145 DtorFn.getCallee(), Object);
1146 }
1147
1148 /// Add an sterm finalizer to the C++ global cleanup function.
1149 void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) {
1150 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
1151 DtorFn.getCallee(), nullptr);
1152 }
1153
1154 /// Add an sterm finalizer to its own llvm.global_dtors entry.
1155 void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer,
1156 int Priority) {
1157 AddGlobalDtor(StermFinalizer, Priority);
1158 }
1159
1160 void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer,
1161 int Priority) {
1163 PrioritizedCXXStermFinalizers.size());
1164 PrioritizedCXXStermFinalizers.push_back(
1165 std::make_pair(Key, StermFinalizer));
1166 }
1167
1168 /// Create or return a runtime function declaration with the specified type
1169 /// and name. If \p AssumeConvergent is true, the call will have the
1170 /// convergent attribute added.
1171 llvm::FunctionCallee
1172 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
1173 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1174 bool Local = false, bool AssumeConvergent = false);
1175
1176 /// Create a new runtime global variable with the specified type and name.
1177 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
1178 StringRef Name);
1179
1180 ///@name Custom Blocks Runtime Interfaces
1181 ///@{
1182
1183 llvm::Constant *getNSConcreteGlobalBlock();
1184 llvm::Constant *getNSConcreteStackBlock();
1185 llvm::FunctionCallee getBlockObjectAssign();
1186 llvm::FunctionCallee getBlockObjectDispose();
1187
1188 ///@}
1189
1190 llvm::Function *getLLVMLifetimeStartFn();
1191 llvm::Function *getLLVMLifetimeEndFn();
1192
1193 // Make sure that this type is translated.
1194 void UpdateCompletedType(const TagDecl *TD);
1195
1196 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
1197
1198 /// Emit type info if type of an expression is a variably modified
1199 /// type. Also emit proper debug info for cast types.
1201 CodeGenFunction *CGF = nullptr);
1202
1203 /// Return the result of value-initializing the given type, i.e. a null
1204 /// expression of the given type. This is usually, but not always, an LLVM
1205 /// null constant.
1206 llvm::Constant *EmitNullConstant(QualType T);
1207
1208 /// Return a null constant appropriate for zero-initializing a base class with
1209 /// the given type. This is usually, but not always, an LLVM null constant.
1210 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
1211
1212 /// Emit a general error that something can't be done.
1213 void Error(SourceLocation loc, StringRef error);
1214
1215 /// Print out an error that codegen doesn't support the specified stmt yet.
1216 void ErrorUnsupported(const Stmt *S, const char *Type);
1217
1218 /// Print out an error that codegen doesn't support the specified decl yet.
1219 void ErrorUnsupported(const Decl *D, const char *Type);
1220
1221 /// Set the attributes on the LLVM function for the given decl and function
1222 /// info. This applies attributes necessary for handling the ABI as well as
1223 /// user specified attributes like section.
1224 void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1225 const CGFunctionInfo &FI);
1226
1227 /// Set the LLVM function attributes (sext, zext, etc).
1229 llvm::Function *F, bool IsThunk);
1230
1231 /// Set the LLVM function attributes which only apply to a function
1232 /// definition.
1233 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
1234
1235 /// Set the LLVM function attributes that represent floating point
1236 /// environment.
1237 void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F);
1238
1239 /// Return true iff the given type uses 'sret' when used as a return type.
1240 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1241
1242 /// Return true iff the given type uses an argument slot when 'sret' is used
1243 /// as a return type.
1245
1246 /// Return true iff the given type uses 'fpret' when used as a return type.
1247 bool ReturnTypeUsesFPRet(QualType ResultType);
1248
1249 /// Return true iff the given type uses 'fp2ret' when used as a return type.
1250 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1251
1252 /// Get the LLVM attributes and calling convention to use for a particular
1253 /// function type.
1254 ///
1255 /// \param Name - The function name.
1256 /// \param Info - The function type information.
1257 /// \param CalleeInfo - The callee information these attributes are being
1258 /// constructed for. If valid, the attributes applied to this decl may
1259 /// contribute to the function attributes and calling convention.
1260 /// \param Attrs [out] - On return, the attribute list to use.
1261 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
1262 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
1263 CGCalleeInfo CalleeInfo,
1264 llvm::AttributeList &Attrs, unsigned &CallingConv,
1265 bool AttrOnCallSite, bool IsThunk);
1266
1267 /// Adjust Memory attribute to ensure that the BE gets the right attribute
1268 // in order to generate the library call or the intrinsic for the function
1269 // name 'Name'.
1270 void AdjustMemoryAttribute(StringRef Name, CGCalleeInfo CalleeInfo,
1271 llvm::AttributeList &Attrs);
1272
1273 /// Like the overload taking a `Function &`, but intended specifically
1274 /// for frontends that want to build on Clang's target-configuration logic.
1275 void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);
1276
1277 StringRef getMangledName(GlobalDecl GD);
1278 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
1279 const GlobalDecl getMangledNameDecl(StringRef);
1280
1281 void EmitTentativeDefinition(const VarDecl *D);
1282
1283 void EmitExternalDeclaration(const VarDecl *D);
1284
1286
1288
1289 /// Appends Opts to the "llvm.linker.options" metadata value.
1290 void AppendLinkerOptions(StringRef Opts);
1291
1292 /// Appends a detect mismatch command to the linker options.
1293 void AddDetectMismatch(StringRef Name, StringRef Value);
1294
1295 /// Appends a dependent lib to the appropriate metadata value.
1296 void AddDependentLib(StringRef Lib);
1297
1298
1299 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1300
1301 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1302 F->setLinkage(getFunctionLinkage(GD));
1303 }
1304
1305 /// Return the appropriate linkage for the vtable, VTT, and type information
1306 /// of the given class.
1307 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1308
1309 /// Return the store size, in character units, of the given LLVM type.
1310 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
1311
1312 /// Returns LLVM linkage for a declarator.
1313 llvm::GlobalValue::LinkageTypes
1315
1316 /// Returns LLVM linkage for a declarator.
1317 llvm::GlobalValue::LinkageTypes
1319
1320 /// Emit all the global annotations.
1321 void EmitGlobalAnnotations();
1322
1323 /// Emit an annotation string.
1324 llvm::Constant *EmitAnnotationString(StringRef Str);
1325
1326 /// Emit the annotation's translation unit.
1327 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1328
1329 /// Emit the annotation line number.
1330 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1331
1332 /// Emit additional args of the annotation.
1333 llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr);
1334
1335 /// Generate the llvm::ConstantStruct which contains the annotation
1336 /// information for a given GlobalValue. The annotation struct is
1337 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1338 /// GlobalValue being annotated. The second field is the constant string
1339 /// created from the AnnotateAttr's annotation. The third field is a constant
1340 /// string containing the name of the translation unit. The fourth field is
1341 /// the line number in the file of the annotated value declaration.
1342 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1343 const AnnotateAttr *AA,
1344 SourceLocation L);
1345
1346 /// Add global annotations that are set on D, for the global GV. Those
1347 /// annotations are emitted during finalization of the LLVM code.
1348 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1349
1350 bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
1351 SourceLocation Loc) const;
1352
1353 bool isInNoSanitizeList(SanitizerMask Kind, llvm::GlobalVariable *GV,
1354 SourceLocation Loc, QualType Ty,
1355 StringRef Category = StringRef()) const;
1356
1357 /// Imbue XRay attributes to a function, applying the always/never attribute
1358 /// lists in the process. Returns true if we did imbue attributes this way,
1359 /// false otherwise.
1360 bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
1361 StringRef Category = StringRef()) const;
1362
1363 /// \returns true if \p Fn at \p Loc should be excluded from profile
1364 /// instrumentation by the SCL passed by \p -fprofile-list.
1366 isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
1367
1368 /// \returns true if \p Fn at \p Loc should be excluded from profile
1369 /// instrumentation.
1371 isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
1372 SourceLocation Loc) const;
1373
1375 return SanitizerMD.get();
1376 }
1377
1379 DeferredVTables.push_back(RD);
1380 }
1381
1382 /// Emit code for a single global function or var decl. Forward declarations
1383 /// are emitted lazily.
1384 void EmitGlobal(GlobalDecl D);
1385
1387
1388 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1389
1390 /// Set attributes which are common to any form of a global definition (alias,
1391 /// Objective-C method, function, global variable).
1392 ///
1393 /// NOTE: This should only be called for definitions.
1394 void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV);
1395
1396 void addReplacement(StringRef Name, llvm::Constant *C);
1397
1398 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1399
1400 /// Emit a code for threadprivate directive.
1401 /// \param D Threadprivate declaration.
1403
1404 /// Emit a code for declare reduction construct.
1406 CodeGenFunction *CGF = nullptr);
1407
1408 /// Emit a code for declare mapper construct.
1410 CodeGenFunction *CGF = nullptr);
1411
1412 /// Emit a code for requires directive.
1413 /// \param D Requires declaration
1414 void EmitOMPRequiresDecl(const OMPRequiresDecl *D);
1415
1416 /// Emit a code for the allocate directive.
1417 /// \param D The allocate declaration
1418 void EmitOMPAllocateDecl(const OMPAllocateDecl *D);
1419
1420 /// Return the alignment specified in an allocate directive, if present.
1421 std::optional<CharUnits> getOMPAllocateAlignment(const VarDecl *VD);
1422
1423 /// Returns whether the given record has hidden LTO visibility and therefore
1424 /// may participate in (single-module) CFI and whole-program vtable
1425 /// optimization.
1426 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
1427
1428 /// Returns whether the given record has public LTO visibility (regardless of
1429 /// -lto-whole-program-visibility) and therefore may not participate in
1430 /// (single-module) CFI and whole-program vtable optimization.
1432
1433 /// Returns the vcall visibility of the given type. This is the scope in which
1434 /// a virtual function call could be made which ends up being dispatched to a
1435 /// member function of this class. This scope can be wider than the visibility
1436 /// of the class itself when the class has a more-visible dynamic base class.
1437 /// The client should pass in an empty Visited set, which is used to prevent
1438 /// redundant recursive processing.
1439 llvm::GlobalObject::VCallVisibility
1442
1443 /// Emit type metadata for the given vtable using the given layout.
1445 llvm::GlobalVariable *VTable,
1446 const VTableLayout &VTLayout);
1447
1448 llvm::Type *getVTableComponentType() const;
1449
1450 /// Generate a cross-DSO type identifier for MD.
1451 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
1452
1453 /// Generate a KCFI type identifier for T.
1454 llvm::ConstantInt *CreateKCFITypeId(QualType T);
1455
1456 /// Create a metadata identifier for the given type. This may either be an
1457 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1458 /// internal identifiers).
1459 llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1460
1461 /// Create a metadata identifier that is intended to be used to check virtual
1462 /// calls via a member function pointer.
1464
1465 /// Create a metadata identifier for the generalization of the given type.
1466 /// This may either be an MDString (for external identifiers) or a distinct
1467 /// unnamed MDNode (for internal identifiers).
1469
1470 /// Create and attach type metadata to the given function.
1472 llvm::Function *F);
1473
1474 /// Set type metadata to the given function.
1475 void setKCFIType(const FunctionDecl *FD, llvm::Function *F);
1476
1477 /// Emit KCFI type identifier constants and remove unused identifiers.
1478 void finalizeKCFITypes();
1479
1480 /// Whether this function's return type has no side effects, and thus may
1481 /// be trivially discarded if it is unused.
1482 bool MayDropFunctionReturn(const ASTContext &Context,
1483 QualType ReturnType) const;
1484
1485 /// Returns whether this module needs the "all-vtables" type identifier.
1486 bool NeedAllVtablesTypeId() const;
1487
1488 /// Create and attach type metadata for the given vtable.
1489 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1490 const CXXRecordDecl *RD);
1491
1492 /// Return a vector of most-base classes for RD. This is used to implement
1493 /// control flow integrity checks for member function pointers.
1494 ///
1495 /// A most-base class of a class C is defined as a recursive base class of C,
1496 /// including C itself, that does not have any bases.
1499
1500 /// Get the declaration of std::terminate for the platform.
1501 llvm::FunctionCallee getTerminateFn();
1502
1503 llvm::SanitizerStatReport &getSanStats();
1504
1505 llvm::Value *
1507
1508 /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
1509 /// information in the program executable. The argument information stored
1510 /// includes the argument name, its type, the address and access qualifiers
1511 /// used. This helper can be used to generate metadata for source code kernel
1512 /// function as well as generated implicitly kernels. If a kernel is generated
1513 /// implicitly null value has to be passed to the last two parameters,
1514 /// otherwise all parameters must have valid non-null values.
1515 /// \param FN is a pointer to IR function being generated.
1516 /// \param FD is a pointer to function declaration if any.
1517 /// \param CGF is a pointer to CodeGenFunction that generates this function.
1518 void GenKernelArgMetadata(llvm::Function *FN,
1519 const FunctionDecl *FD = nullptr,
1520 CodeGenFunction *CGF = nullptr);
1521
1522 /// Get target specific null pointer.
1523 /// \param T is the LLVM type of the null pointer.
1524 /// \param QT is the clang QualType of the null pointer.
1525 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1526
1528 LValueBaseInfo *BaseInfo = nullptr,
1529 TBAAAccessInfo *TBAAInfo = nullptr,
1530 bool forPointeeType = false);
1532 LValueBaseInfo *BaseInfo = nullptr,
1533 TBAAAccessInfo *TBAAInfo = nullptr);
1534 bool stopAutoInit();
1535
1536 /// Print the postfix for externalized static variable or kernels for single
1537 /// source offloading languages CUDA and HIP. The unique postfix is created
1538 /// using either the CUID argument, or the file's UniqueID and active macros.
1539 /// The fallback method without a CUID requires that the offloading toolchain
1540 /// does not define separate macros via the -cc1 options.
1541 void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
1542 const Decl *D) const;
1543
1544 /// Move some lazily-emitted states to the NewBuilder. This is especially
1545 /// essential for the incremental parsing environment like Clang Interpreter,
1546 /// because we'll lose all important information after each repl.
1547 void moveLazyEmissionStates(CodeGenModule *NewBuilder);
1548
1549 /// Emit the IR encoding to attach the CUDA launch bounds attribute to \p F.
1550 /// If \p MaxThreadsVal is not nullptr, the max threads value is stored in it,
1551 /// if a valid one was found.
1552 void handleCUDALaunchBoundsAttr(llvm::Function *F,
1553 const CUDALaunchBoundsAttr *A,
1554 int32_t *MaxThreadsVal = nullptr,
1555 int32_t *MinBlocksVal = nullptr,
1556 int32_t *MaxClusterRankVal = nullptr);
1557
1558 /// Emit the IR encoding to attach the AMD GPU flat-work-group-size attribute
1559 /// to \p F. Alternatively, the work group size can be taken from a \p
1560 /// ReqdWGS. If \p MinThreadsVal is not nullptr, the min threads value is
1561 /// stored in it, if a valid one was found. If \p MaxThreadsVal is not
1562 /// nullptr, the max threads value is stored in it, if a valid one was found.
1564 llvm::Function *F, const AMDGPUFlatWorkGroupSizeAttr *A,
1565 const ReqdWorkGroupSizeAttr *ReqdWGS = nullptr,
1566 int32_t *MinThreadsVal = nullptr, int32_t *MaxThreadsVal = nullptr);
1567
1568 /// Emit the IR encoding to attach the AMD GPU waves-per-eu attribute to \p F.
1569 void handleAMDGPUWavesPerEUAttr(llvm::Function *F,
1570 const AMDGPUWavesPerEUAttr *A);
1571
1572 llvm::Constant *
1573 GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, LangAS AddrSpace,
1574 const VarDecl *D,
1575 ForDefinition_t IsForDefinition = NotForDefinition);
1576
1577 // FIXME: Hardcoding priority here is gross.
1578 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1579 unsigned LexOrder = ~0U,
1580 llvm::Constant *AssociatedData = nullptr);
1581 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
1582 bool IsDtorAttrFunc = false);
1583
1584private:
1585 llvm::Constant *GetOrCreateLLVMFunction(
1586 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1587 bool DontDefer = false, bool IsThunk = false,
1588 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1589 ForDefinition_t IsForDefinition = NotForDefinition);
1590
1591 // References to multiversion functions are resolved through an implicitly
1592 // defined resolver function. This function is responsible for creating
1593 // the resolver symbol for the provided declaration. The value returned
1594 // will be for an ifunc (llvm::GlobalIFunc) if the current target supports
1595 // that feature and for a regular function (llvm::GlobalValue) otherwise.
1596 llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD);
1597
1598 // In scenarios where a function is not known to be a multiversion function
1599 // until a later declaration, it is sometimes necessary to change the
1600 // previously created mangled name to align with requirements of whatever
1601 // multiversion function kind the function is now known to be. This function
1602 // is responsible for performing such mangled name updates.
1603 void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD,
1604 StringRef &CurName);
1605
1606 bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
1607 llvm::AttrBuilder &AttrBuilder,
1608 bool SetTargetFeatures = true);
1609 void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
1610
1611 /// Set function attributes for a function declaration.
1612 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1613 bool IsIncompleteFunction, bool IsThunk);
1614
1615 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1616
1617 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1618 void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1619
1620 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1621 void EmitExternalVarDeclaration(const VarDecl *D);
1622 void EmitAliasDefinition(GlobalDecl GD);
1623 void emitIFuncDefinition(GlobalDecl GD);
1624 void emitCPUDispatchDefinition(GlobalDecl GD);
1625 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1626 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1627
1628 // C++ related functions.
1629
1630 void EmitDeclContext(const DeclContext *DC);
1631 void EmitLinkageSpec(const LinkageSpecDecl *D);
1632 void EmitTopLevelStmt(const TopLevelStmtDecl *D);
1633
1634 /// Emit the function that initializes C++ thread_local variables.
1635 void EmitCXXThreadLocalInitFunc();
1636
1637 /// Emit the function that initializes global variables for a C++ Module.
1638 void EmitCXXModuleInitFunc(clang::Module *Primary);
1639
1640 /// Emit the function that initializes C++ globals.
1641 void EmitCXXGlobalInitFunc();
1642
1643 /// Emit the function that performs cleanup associated with C++ globals.
1644 void EmitCXXGlobalCleanUpFunc();
1645
1646 /// Emit the function that initializes the specified global (if PerformInit is
1647 /// true) and registers its destructor.
1648 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1649 llvm::GlobalVariable *Addr,
1650 bool PerformInit);
1651
1652 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1653 llvm::Function *InitFunc, InitSegAttr *ISA);
1654
1655 /// EmitCtorList - Generates a global array of functions and priorities using
1656 /// the given list and name. This array will have appending linkage and is
1657 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1658 void EmitCtorList(CtorList &Fns, const char *GlobalName);
1659
1660 /// Emit any needed decls for which code generation was deferred.
1661 void EmitDeferred();
1662
1663 /// Try to emit external vtables as available_externally if they have emitted
1664 /// all inlined virtual functions. It runs after EmitDeferred() and therefore
1665 /// is not allowed to create new references to things that need to be emitted
1666 /// lazily.
1667 void EmitVTablesOpportunistically();
1668
1669 /// Call replaceAllUsesWith on all pairs in Replacements.
1670 void applyReplacements();
1671
1672 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1673 void applyGlobalValReplacements();
1674
1675 void checkAliases();
1676
1677 std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit;
1678
1679 /// Register functions annotated with __attribute__((destructor)) using
1680 /// __cxa_atexit, if it is available, or atexit otherwise.
1681 void registerGlobalDtorsWithAtExit();
1682
1683 // When using sinit and sterm functions, unregister
1684 // __attribute__((destructor)) annotated functions which were previously
1685 // registered by the atexit subroutine using unatexit.
1686 void unregisterGlobalDtorsWithUnAtExit();
1687
1688 /// Emit deferred multiversion function resolvers and associated variants.
1689 void emitMultiVersionFunctions();
1690
1691 /// Emit any vtables which we deferred and still have a use for.
1692 void EmitDeferredVTables();
1693
1694 /// Emit a dummy function that reference a CoreFoundation symbol when
1695 /// @available is used on Darwin.
1696 void emitAtAvailableLinkGuard();
1697
1698 /// Emit the llvm.used and llvm.compiler.used metadata.
1699 void emitLLVMUsed();
1700
1701 /// For C++20 Itanium ABI, emit the initializers for the module.
1702 void EmitModuleInitializers(clang::Module *Primary);
1703
1704 /// Emit the link options introduced by imported modules.
1705 void EmitModuleLinkOptions();
1706
1707 /// Helper function for EmitStaticExternCAliases() to redirect ifuncs that
1708 /// have a resolver name that matches 'Elem' to instead resolve to the name of
1709 /// 'CppFunc'. This redirection is necessary in cases where 'Elem' has a name
1710 /// that will be emitted as an alias of the name bound to 'CppFunc'; ifuncs
1711 /// may not reference aliases. Redirection is only performed if 'Elem' is only
1712 /// used by ifuncs in which case, 'Elem' is destroyed. 'true' is returned if
1713 /// redirection is successful, and 'false' is returned otherwise.
1714 bool CheckAndReplaceExternCIFuncs(llvm::GlobalValue *Elem,
1715 llvm::GlobalValue *CppFunc);
1716
1717 /// Emit aliases for internal-linkage declarations inside "C" language
1718 /// linkage specifications, giving them the "expected" name where possible.
1719 void EmitStaticExternCAliases();
1720
1721 void EmitDeclMetadata();
1722
1723 /// Emit the Clang version as llvm.ident metadata.
1724 void EmitVersionIdentMetadata();
1725
1726 /// Emit the Clang commandline as llvm.commandline metadata.
1727 void EmitCommandLineMetadata();
1728
1729 /// Emit the module flag metadata used to pass options controlling the
1730 /// the backend to LLVM.
1731 void EmitBackendOptionsMetadata(const CodeGenOptions &CodeGenOpts);
1732
1733 /// Emits OpenCL specific Metadata e.g. OpenCL version.
1734 void EmitOpenCLMetadata();
1735
1736 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1737 /// .gcda files in a way that persists in .bc files.
1738 void EmitCoverageFile();
1739
1740 /// Determine whether the definition must be emitted; if this returns \c
1741 /// false, the definition can be emitted lazily if it's used.
1742 bool MustBeEmitted(const ValueDecl *D);
1743
1744 /// Determine whether the definition can be emitted eagerly, or should be
1745 /// delayed until the end of the translation unit. This is relevant for
1746 /// definitions whose linkage can change, e.g. implicit function instantions
1747 /// which may later be explicitly instantiated.
1748 bool MayBeEmittedEagerly(const ValueDecl *D);
1749
1750 /// Check whether we can use a "simpler", more core exceptions personality
1751 /// function.
1752 void SimplifyPersonality();
1753
1754 /// Helper function for getDefaultFunctionAttributes. Builds a set of function
1755 /// attributes which can be simply added to a function.
1756 void getTrivialDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1757 bool AttrOnCallSite,
1758 llvm::AttrBuilder &FuncAttrs);
1759
1760 /// Helper function for ConstructAttributeList and
1761 /// addDefaultFunctionDefinitionAttributes. Builds a set of function
1762 /// attributes to add to a function with the given properties.
1763 void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
1764 bool AttrOnCallSite,
1765 llvm::AttrBuilder &FuncAttrs);
1766
1767 llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
1768 StringRef Suffix);
1769};
1770
1771} // end namespace CodeGen
1772} // end namespace clang
1773
1774#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:3259
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:2956
int Category
Definition: Format.cpp:2955
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:146
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:40
llvm::MachO::Record Record
Definition: MachO.h:28
Defines the clang::Module class, which describes a module in the source code.
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Attr - This represents one attribute.
Definition: Attr.h:42
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4459
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6167
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2792
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3556
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
An aligned address.
Definition: Address.h:29
A pair of helper functions for a __block variable.
void Profile(llvm::FoldingSetNodeID &id) const
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src)=0
BlockByrefHelpers(CharUnits alignment)
virtual bool needsCopy() const
CharUnits Alignment
The alignment of the field.
virtual void emitDispose(CodeGenFunction &CGF, Address field)=0
BlockByrefHelpers(const BlockByrefHelpers &)=default
virtual bool needsDispose() const
virtual void profileImpl(llvm::FoldingSetNodeID &id) const =0
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
Abstract information about a function or function prototype.
Definition: CGCall.h:40
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
CGFunctionInfo - Class to encapsulate the information about a function definition.
Implements runtime-specific code generation functions.
Definition: CGObjCRuntime.h:65
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
llvm::FunctionCallee getBlockObjectAssign()
Definition: CGBlocks.cpp:2831
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:308
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:1247
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:1271
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:2465
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:654
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:59
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C)
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Definition: CGCXX.cpp: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:1131
void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const
const IntrusiveRefCntPtr< llvm::vfs::FileSystem > & getFileSystem() const
void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr)
Notes that BE's global block is available via Addr.
Definition: CGBlocks.cpp:1248
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:1591
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:96
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:1087
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
Definition: CGBlocks.cpp:1256
llvm::Constant * getAtomicGetterHelperFnMap(QualType Ty)
const LangOptions & getLangOpts() const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
int getUniqueBlockCount()
Fetches the global unique block count.
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
QualType getObjCFastEnumerationStateType()
Retrieve the record type that describes the state of an Objective-C fast enumeration loop (for....
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
bool shouldMapVisibilityToDLLExport(const NamedDecl *D) const
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
const std::string & getModuleNameHash() const
const TargetInfo & getTarget() const
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::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:627
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "llvm.linker.options" metadata value.
bool hasObjCRuntime()
Return true iff an Objective-C runtime has been configured.
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the appropriate metadata value.
void Release()
Finalize LLVM code generation.
llvm::FunctionCallee IsOSVersionAtLeastFn
ProfileList::ExclusionType isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
void EmitVTableTypeMetadata(const CXXRecordDecl *RD, llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
Definition: CGVTables.cpp:1305
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
void EmitOMPAllocateDecl(const OMPAllocateDecl *D)
Emit a code for the allocate directive.
Definition: CGDecl.cpp:2722
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:199
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:1259
const llvm::DataLayout & getDataLayout() const
llvm::Constant * getNSConcreteGlobalBlock()
Definition: CGBlocks.cpp:2844
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
Definition: CGClass.cpp:171
ObjCEntrypoints & getObjCEntrypoints() const
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table poi...
CGCXXABI & getCXXABI() const
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
Definition: CGClass.cpp:76
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:1608
void EmitDeferredUnusedCoverageMappings()
Emit all the deferred coverage mappings for the uninstrumented functions.
void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process.
SanitizerMetadata * getSanitizerMetadata()
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
void EmitGlobalAnnotations()
Emit all the global annotations.
llvm::Constant * getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE)
Returns the address of a block which requires no caputres, or null if we've yet to emit the block for...
llvm::Function * codegenCXXStructor(GlobalDecl GD)
Definition: CGCXX.cpp:206
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:40
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:243
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:1235
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV)
If the declaration has internal linkage but is inside an extern "C" linkage specification,...
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
llvm::Constant * getAtomicSetterHelperFnMap(QualType Ty)
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType)
getTBAAInfoForSubobject - Get TBAA information for an access with a given base lvalue.
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
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:1586
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:1138
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:2294
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:2322
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:91
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:2854
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:692
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
Definition: CGDecl.cpp:2710
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the @llvm.lifetime.end intrinsic.
Definition: CGDecl.cpp:2474
void EmitExternalDeclaration(const VarDecl *D)
void RefreshTypeCacheForClass(const CXXRecordDecl *Class)
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, llvm::GlobalVariable *GV)
Notes that CLE's GlobalVariable is GV.
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
Definition: CGDecl.cpp:2718
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:1581
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:2147
std::optional< CharUnits > getOMPAllocateAlignment(const VarDecl *VD)
Return the alignment specified in an allocate directive, if present.
Definition: CGDecl.cpp:2777
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:2818
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:2703
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:1045
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:1119
CharUnits getMinimumObjectSize(QualType Ty)
Returns the minimum object size for an object of the given type.
void addReplacement(StringRef Name, llvm::Constant *C)
llvm::ConstantInt * CreateKCFITypeId(QualType T)
Generate a KCFI type identifier for T.
llvm::FunctionCallee IsPlatformVersionAtLeastFn
void 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.
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:1814
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:436
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character.
std::vector< Structor > CtorList
void printPostfixForExternalizedDecl(llvm::raw_ostream &OS, const Decl *D) const
Print the postfix for externalized static variable or kernels for single source offloading languages ...
llvm::Constant * GetAddrOfThunk(StringRef Name, llvm::Type *FnTy, GlobalDecl GD)
Get the address of the thunk for the given global decl.
Definition: CGVTables.cpp: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:120
Organizes the cross-function state that is used while generating code coverage mapping data.
This class records statistics on instrumentation based profiling.
bool hasDiagnostics()
Whether or not the stats we've gathered indicate any potential problems.
void addMissing(bool MainFile)
Record that a function we've visited has no profile data.
void addMismatched(bool MainFile)
Record that a function we've visited has mismatched profile data.
void addVisited(bool MainFile)
Record that we've visited a function and whether or not that function was in the main source file.
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile)
Report potential problems we've found to Diags.
LValue - This represents an lvalue references.
Definition: CGValue.h:171
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:46
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3419
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:1446
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
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:3724
This represents one expression.
Definition: Expr.h:110
Represents a function declaration or definition.
Definition: Decl.h:1959
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:418
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:667
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:672
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:677
Visibility getVisibility() const
Definition: Visibility.h:89
bool isVisibilityExplicit() const
Definition: Visibility.h:90
Represents a linkage specification.
Definition: DeclCXX.h:2927
A global _GUID constant.
Definition: DeclCXX.h:4282
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4679
Describes a module or submodule.
Definition: Module.h:105
This represents a decl that may have a name.
Definition: Decl.h:249
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1220
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:473
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:287
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:177
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:416
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2595
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:737
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:1773
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
Exposes information about the current target.
Definition: TargetInfo.h:213
A template parameter object.
A declaration that models statements at global scope.
Definition: Decl.h:4422
The base class of the type hierarchy.
Definition: Type.h:1606
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2182
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4339
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
Represents a variable declaration or definition.
Definition: Decl.h:918
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
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
@ 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
YAML serialization mapping.
Definition: Dominators.h:30
Structor(int Priority, unsigned LexOrder, llvm::Constant *Initializer, llvm::Constant *AssociatedData)
This structure provides a set of types that are commonly used during IR emission.
llvm::Function * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
llvm::Function * objc_retainAutoreleaseReturnValue
id objc_retainAutoreleaseReturnValue(id);
llvm::FunctionCallee objc_alloc
void objc_alloc(id);
llvm::Function * objc_retain
id objc_retain(id);
llvm::FunctionCallee objc_alloc_init
void objc_alloc_init(id);
llvm::Function * objc_autorelease
id objc_autorelease(id);
llvm::Function * objc_moveWeak
void objc_moveWeak(id *dest, id *src);
llvm::FunctionCallee objc_autoreleasePoolPopInvoke
void objc_autoreleasePoolPop(void*); Note this method is used when we are using exception handling
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain.
llvm::Function * clang_arc_use
void clang.arc.use(...);
llvm::Function * objc_initWeak
id objc_initWeak(id*, id);
llvm::FunctionCallee objc_retainRuntimeFunction
id objc_retain(id); Note this is the runtime method not the intrinsic.
llvm::Function * objc_copyWeak
void objc_copyWeak(id *dest, id *src);
llvm::Function * objc_destroyWeak
void objc_destroyWeak(id*);
llvm::Function * objc_retainAutorelease
id objc_retainAutorelease(id);
llvm::Function * objc_autoreleasePoolPush
void *objc_autoreleasePoolPush(void);
llvm::Function * objc_retainBlock
id objc_retainBlock(id);
llvm::Function * objc_storeStrong
void objc_storeStrong(id*, id);
llvm::Function * objc_loadWeak
id objc_loadWeak(id*);
llvm::Function * clang_arc_noop_use
void clang.arc.noop.use(...);
llvm::Function * objc_loadWeakRetained
id objc_loadWeakRetained(id*);
llvm::Function * objc_release
void objc_release(id);
llvm::FunctionCallee objc_autoreleaseRuntimeFunction
id objc_autorelease(id); Note this is the runtime method not the intrinsic.
llvm::Function * objc_autoreleaseReturnValue
id objc_autoreleaseReturnValue(id);
llvm::FunctionCallee objc_releaseRuntimeFunction
void objc_release(id); Note this is the runtime method not the intrinsic.
llvm::FunctionCallee objc_allocWithZone
void objc_allocWithZone(id);
llvm::FunctionCallee objc_autoreleasePoolPop
void objc_autoreleasePoolPop(void*);
llvm::Function * objc_storeWeak
id objc_storeWeak(id*, id);
llvm::Function * objc_unsafeClaimAutoreleasedReturnValue
id objc_unsafeClaimAutoreleasedReturnValue(id);
bool operator<(const OrderGlobalInitsOrStermFinalizers &RHS) const
bool operator==(const OrderGlobalInitsOrStermFinalizers &RHS) const
OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:63