clang 24.0.0git
CodeGenFunction.h
Go to the documentation of this file.
1//===-- CodeGenFunction.h - Per-Function 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-function state used for llvm translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H
14#define LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H
15
16#include "CGBuilder.h"
17#include "CGLoopInfo.h"
18#include "CGValue.h"
19#include "CodeGenModule.h"
20#include "EHScopeStack.h"
21#include "SanitizerHandler.h"
22#include "VarBypassDetector.h"
23#include "clang/AST/Attr.h"
24#include "clang/AST/CharUnits.h"
26#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
31#include "clang/AST/StmtSYCL.h"
32#include "clang/AST/Type.h"
33#include "clang/Basic/ABI.h"
40#include "llvm/ADT/ArrayRef.h"
41#include "llvm/ADT/DenseMap.h"
42#include "llvm/ADT/MapVector.h"
43#include "llvm/ADT/SmallVector.h"
44#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
45#include "llvm/IR/Instructions.h"
46#include "llvm/IR/ValueHandle.h"
47#include "llvm/Support/Debug.h"
48#include "llvm/Transforms/Utils/SanitizerStats.h"
49#include <array>
50#include <optional>
51
52namespace llvm {
53class BasicBlock;
54class ConvergenceControlInst;
55class LLVMContext;
56class MDNode;
57class SwitchInst;
58class Twine;
59class Value;
60class CanonicalLoopInfo;
61} // namespace llvm
62
63namespace clang {
64class ASTContext;
67class CXXForRangeStmt;
68class CXXTryStmt;
69class Decl;
70class LabelDecl;
71class FunctionDecl;
73class LabelStmt;
76class ObjCIvarDecl;
77class ObjCMethodDecl;
80class TargetInfo;
81class VarDecl;
83class ObjCAtTryStmt;
84class ObjCAtThrowStmt;
87class OMPUseDevicePtrClause;
88class OMPUseDeviceAddrClause;
89class SVETypeFlags;
90class OMPExecutableDirective;
91
92namespace analyze_os_log {
94}
95
96namespace CodeGen {
97class CodeGenTypes;
98class CodeGenPGO;
99class CGCallee;
100class CGFunctionInfo;
101class CGBlockInfo;
102class CGCXXABI;
104class BlockByrefInfo;
105class BlockFieldFlags;
106class RegionCodeGenTy;
108struct OMPTaskDataTy;
109struct CGCoroData;
110
111// clang-format off
112/// The kind of evaluation to perform on values of a particular
113/// type. Basically, is the code in CGExprScalar, CGExprComplex, or
114/// CGExprAgg?
115///
116/// TODO: should vectors maybe be split out into their own thing?
122// clang-format on
123
124/// Helper class with most of the code for saving a value for a
125/// conditional expression cleanup.
127 struct saved_type {
128 llvm::Value *Value; // Original value if not saved, alloca if saved
129 llvm::Type *Type; // nullptr if not saved, element type if saved
130
132 saved_type(llvm::Value *V) : Value(V), Type(nullptr) {}
133 saved_type(llvm::AllocaInst *Alloca, llvm::Type *Ty)
134 : Value(Alloca), Type(Ty) {}
135
136 bool isSaved() const { return Type != nullptr; }
137 };
138
139 /// Answer whether the given value needs extra work to be saved.
140 static bool needsSaving(llvm::Value *value) {
141 if (!value)
142 return false;
143
144 // If it's not an instruction, we don't need to save.
145 if (!isa<llvm::Instruction>(value))
146 return false;
147
148 // If it's an instruction in the entry block, we don't need to save.
149 llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent();
150 return (block != &block->getParent()->getEntryBlock());
151 }
152
153 static saved_type save(CodeGenFunction &CGF, llvm::Value *value);
154 static llvm::Value *restore(CodeGenFunction &CGF, saved_type value);
155};
156
157/// A partial specialization of DominatingValue for llvm::Values that
158/// might be llvm::Instructions.
159template <class T> struct DominatingPointer<T, true> : DominatingLLVMValue {
160 typedef T *type;
162 return static_cast<T *>(DominatingLLVMValue::restore(CGF, value));
163 }
164};
165
166/// A specialization of DominatingValue for Address.
167template <> struct DominatingValue<Address> {
168 typedef Address type;
169
177
178 static bool needsSaving(type value) {
181 return true;
182 return false;
183 }
184 static saved_type save(CodeGenFunction &CGF, type value) {
185 return {DominatingLLVMValue::save(CGF, value.getBasePointer()),
186 value.getElementType(), value.getAlignment(),
187 DominatingLLVMValue::save(CGF, value.getOffset()), value.getType()};
188 }
193 }
194};
195
196/// A specialization of DominatingValue for RValue.
197template <> struct DominatingValue<RValue> {
198 typedef RValue type;
199 class saved_type {
200 enum Kind {
201 ScalarLiteral,
202 ScalarAddress,
203 AggregateLiteral,
204 AggregateAddress,
205 ComplexAddress
206 };
207 union {
208 struct {
210 } Vals;
212 };
213 LLVM_PREFERRED_TYPE(Kind)
214 unsigned K : 3;
215
217 : Vals{Val1, DominatingLLVMValue::saved_type()}, K(K) {}
218
221 : Vals{Val1, Val2}, K(ComplexAddress) {}
222
223 saved_type(DominatingValue<Address>::saved_type AggregateAddr, unsigned K)
224 : AggregateAddr(AggregateAddr), K(K) {}
225
226 public:
227 static bool needsSaving(RValue value);
228 static saved_type save(CodeGenFunction &CGF, RValue value);
230
231 // implementations in CGCleanup.cpp
232 };
233
234 static bool needsSaving(type value) { return saved_type::needsSaving(value); }
235 static saved_type save(CodeGenFunction &CGF, type value) {
236 return saved_type::save(CGF, value);
237 }
239 return value.restore(CGF);
240 }
241};
242
243/// A scoped helper to set the current source atom group for
244/// CGDebugInfo::addInstToCurrentSourceAtom. A source atom is a source construct
245/// that is "interesting" for debug stepping purposes. We use an atom group
246/// number to track the instruction(s) that implement the functionality for the
247/// atom, plus backup instructions/source locations.
248class ApplyAtomGroup {
249 uint64_t OriginalAtom = 0;
250 CGDebugInfo *DI = nullptr;
251
252 ApplyAtomGroup(const ApplyAtomGroup &) = delete;
253 void operator=(const ApplyAtomGroup &) = delete;
254
255public:
256 ApplyAtomGroup(CGDebugInfo *DI);
258};
259
260/// CodeGenFunction - This class organizes the per-function state that is used
261/// while generating LLVM code.
262class CodeGenFunction : public CodeGenTypeCache {
263 CodeGenFunction(const CodeGenFunction &) = delete;
264 void operator=(const CodeGenFunction &) = delete;
265
266 friend class CGCXXABI;
268
269public:
270 /// A jump destination is an abstract label, branching to which may
271 /// require a jump out through normal cleanups.
272 struct JumpDest {
273 JumpDest() : Block(nullptr), Index(0) {}
274 JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth,
275 unsigned Index)
276 : Block(Block), ScopeDepth(Depth), Index(Index) {}
277
278 bool isValid() const { return Block != nullptr; }
279 llvm::BasicBlock *getBlock() const { return Block; }
280 EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
281 unsigned getDestIndex() const { return Index; }
282
283 // This should be used cautiously.
285 ScopeDepth = depth;
286 }
287
288 private:
289 llvm::BasicBlock *Block;
291 unsigned Index;
292 };
293
294 CodeGenModule &CGM; // Per-module state.
296
297 // For EH/SEH outlined funclets, this field points to parent's CGF
298 CodeGenFunction *ParentCGF = nullptr;
299
300 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
303
304 // Stores variables for which we can't generate correct lifetime markers
305 // because of jumps.
307
308 // Addresses of bypassed variables, for re-emitting their
309 // trivial-auto-var-init at a jump that re-enters their scope.
310 llvm::SmallDenseMap<const VarDecl *, Address, 4> BypassedVarInits;
311
312 // Jumps, like gotos or switches, that may bypass a declaration that has not
313 // been emitted yet. EmitAutoVarAlloca patches the init in before the jump
314 // once the alloca exists.
316 llvm::AssertingVH<llvm::BasicBlock> Block;
317 const Stmt *Source;
318 };
320
321 /// List of recently emitted OMPCanonicalLoops.
322 ///
323 /// Since OMPCanonicalLoops are nested inside other statements (in particular
324 /// CapturedStmt generated by OMPExecutableDirective and non-perfectly nested
325 /// loops), we cannot directly call OMPEmitOMPCanonicalLoop and receive its
326 /// llvm::CanonicalLoopInfo. Instead, we call EmitStmt and any
327 /// OMPEmitOMPCanonicalLoop called by it will add its CanonicalLoopInfo to
328 /// this stack when done. Entering a new loop requires clearing this list; it
329 /// either means we start parsing a new loop nest (in which case the previous
330 /// loop nest goes out of scope) or a second loop in the same level in which
331 /// case it would be ambiguous into which of the two (or more) loops the loop
332 /// nest would extend.
334
335 /// Stack to track the controlled convergence tokens.
337
338 /// Number of nested loop to be consumed by the last surrounding
339 /// loop-associated directive.
341
342 // CodeGen lambda for loops and support for ordered clause
343 typedef llvm::function_ref<void(CodeGenFunction &, const OMPLoopDirective &,
344 JumpDest)>
346 typedef llvm::function_ref<void(CodeGenFunction &, SourceLocation,
347 const unsigned, const bool)>
349
350 // Codegen lambda for loop bounds in worksharing loop constructs
351 typedef llvm::function_ref<std::pair<LValue, LValue>(
352 CodeGenFunction &, const OMPExecutableDirective &S)>
354
355 // Codegen lambda for loop bounds in dispatch-based loop implementation
356 typedef llvm::function_ref<std::pair<llvm::Value *, llvm::Value *>(
357 CodeGenFunction &, const OMPExecutableDirective &S, Address LB,
358 Address UB)>
360
361 /// CGBuilder insert helper. This function is called after an
362 /// instruction is created using Builder.
363 void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
364 llvm::BasicBlock::iterator InsertPt) const;
365
366 /// CurFuncDecl - Holds the Decl for the current outermost
367 /// non-closure context.
368 const Decl *CurFuncDecl = nullptr;
369 /// CurCodeDecl - This is the inner-most code context, which includes blocks.
370 const Decl *CurCodeDecl = nullptr;
371 const CGFunctionInfo *CurFnInfo = nullptr;
373 llvm::Function *CurFn = nullptr;
374
375 /// If a cast expression is being visited, this holds the current cast's
376 /// expression.
377 const CastExpr *CurCast = nullptr;
378
379 /// Save Parameter Decl for coroutine.
381
382 // Holds coroutine data if the current function is a coroutine. We use a
383 // wrapper to manage its lifetime, so that we don't have to define CGCoroData
384 // in this header.
385 struct CGCoroInfo {
386 std::unique_ptr<CGCoroData> Data;
387 bool InSuspendBlock = false;
388 CGCoroInfo();
389 ~CGCoroInfo();
390 };
392
393 bool isCoroutine() const { return CurCoro.Data != nullptr; }
394
395 bool inSuspendBlock() const {
396 return isCoroutine() && CurCoro.InSuspendBlock;
397 }
398
399 // Holds FramePtr for await_suspend wrapper generation,
400 // so that __builtin_coro_frame call can be lowered
401 // directly to value of its second argument
403 llvm::Value *FramePtr = nullptr;
404 };
406
407 // Generates wrapper function for `llvm.coro.await.suspend.*` intrinisics.
408 // It encapsulates SuspendExpr in a function, to separate it's body
409 // from the main coroutine to avoid miscompilations. Intrinisic
410 // is lowered to this function call in CoroSplit pass
411 // Function signature is:
412 // <type> __await_suspend_wrapper_<name>(ptr %awaiter, ptr %hdl)
413 // where type is one of (void, i1, ptr)
414 llvm::Function *generateAwaitSuspendWrapper(Twine const &CoroName,
415 Twine const &SuspendPointName,
416 CoroutineSuspendExpr const &S);
417
418 /// CurGD - The GlobalDecl for the current function being compiled.
420
421 /// PrologueCleanupDepth - The cleanup depth enclosing all the
422 /// cleanups associated with the parameters.
424
425 /// ReturnBlock - Unified return block.
427
428 /// ReturnValue - The temporary alloca to hold the return
429 /// value. This is invalid iff the function has no return value.
431
432 /// ReturnValuePointer - The temporary alloca to hold a pointer to sret.
433 /// This is invalid if sret is not in use.
435
436 /// If a return statement is being visited, this holds the return statment's
437 /// result expression.
438 const Expr *RetExpr = nullptr;
439
440 /// Return true if a label was seen in the current scope.
442 if (CurLexicalScope)
443 return CurLexicalScope->hasLabels();
444 return !LabelMap.empty();
445 }
446
447 /// AllocaInsertPoint - This is an instruction in the entry block before which
448 /// we prefer to insert allocas.
449 llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
450
451private:
452 /// PostAllocaInsertPt - This is a place in the prologue where code can be
453 /// inserted that will be dominated by all the static allocas. This helps
454 /// achieve two things:
455 /// 1. Contiguity of all static allocas (within the prologue) is maintained.
456 /// 2. All other prologue code (which are dominated by static allocas) do
457 /// appear in the source order immediately after all static allocas.
458 ///
459 /// PostAllocaInsertPt will be lazily created when it is *really* required.
460 llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr;
461
462public:
463 /// Return PostAllocaInsertPt. If it is not yet created, then insert it
464 /// immediately after AllocaInsertPt.
465 llvm::Instruction *getPostAllocaInsertPoint() {
466 if (!PostAllocaInsertPt) {
467 assert(AllocaInsertPt &&
468 "Expected static alloca insertion point at function prologue");
469 assert(AllocaInsertPt->getParent()->isEntryBlock() &&
470 "EBB should be entry block of the current code gen function");
471 PostAllocaInsertPt = AllocaInsertPt->clone();
472 PostAllocaInsertPt->setName("postallocapt");
473 PostAllocaInsertPt->insertAfter(AllocaInsertPt->getIterator());
474 }
475
476 return PostAllocaInsertPt;
477 }
478
479 // Try to preserve the source's name to make IR more readable.
480 llvm::Value *performAddrSpaceCast(llvm::Value *Src, llvm::Type *DestTy) {
481 return Builder.CreateAddrSpaceCast(
482 Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
483 }
484
485 /// API for captured statement code generation.
487 public:
489 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {}
492 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {
493
495 S.getCapturedRecordDecl()->field_begin();
497 E = S.capture_end();
498 I != E; ++I, ++Field) {
499 if (I->capturesThis())
500 CXXThisFieldDecl = *Field;
501 else if (I->capturesVariable())
502 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
503 else if (I->capturesVariableByCopy())
504 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
505 }
506 }
507
508 virtual ~CGCapturedStmtInfo();
509
510 CapturedRegionKind getKind() const { return Kind; }
511
512 virtual void setContextValue(llvm::Value *V) { ThisValue = V; }
513 // Retrieve the value of the context parameter.
514 virtual llvm::Value *getContextValue() const { return ThisValue; }
515
516 /// Lookup the captured field decl for a variable.
517 virtual const FieldDecl *lookup(const VarDecl *VD) const {
518 return CaptureFields.lookup(VD->getCanonicalDecl());
519 }
520
521 bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; }
522 virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; }
523
524 static bool classof(const CGCapturedStmtInfo *) { return true; }
525
526 /// Emit the captured statement body.
527 virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) {
529 CGF.EmitStmt(S);
530 }
531
532 /// Get the name of the capture helper.
533 virtual StringRef getHelperName() const { return "__captured_stmt"; }
534
535 /// Get the CaptureFields
536 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> getCaptureFields() {
537 return CaptureFields;
538 }
539
540 private:
541 /// The kind of captured statement being generated.
543
544 /// Keep the map between VarDecl and FieldDecl.
545 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields;
546
547 /// The base address of the captured record, passed in as the first
548 /// argument of the parallel region function.
549 llvm::Value *ThisValue;
550
551 /// Captured 'this' type.
552 FieldDecl *CXXThisFieldDecl;
553 };
555
556 /// RAII for correct setting/restoring of CapturedStmtInfo.
558 private:
559 CodeGenFunction &CGF;
560 CGCapturedStmtInfo *PrevCapturedStmtInfo;
561
562 public:
563 CGCapturedStmtRAII(CodeGenFunction &CGF,
564 CGCapturedStmtInfo *NewCapturedStmtInfo)
565 : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) {
566 CGF.CapturedStmtInfo = NewCapturedStmtInfo;
567 }
568 ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; }
569 };
570
571 /// An abstract representation of regular/ObjC call/message targets.
573 /// The function declaration of the callee.
574 const Decl *CalleeDecl;
575
576 public:
577 AbstractCallee() : CalleeDecl(nullptr) {}
578 AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {}
579 AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {}
580 bool hasFunctionDecl() const {
581 return isa_and_nonnull<FunctionDecl>(CalleeDecl);
582 }
583 const Decl *getDecl() const { return CalleeDecl; }
584 unsigned getNumParams() const {
585 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
586 return FD->getNumParams();
587 return cast<ObjCMethodDecl>(CalleeDecl)->param_size();
588 }
589 const ParmVarDecl *getParamDecl(unsigned I) const {
590 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
591 return FD->getParamDecl(I);
592 return *(cast<ObjCMethodDecl>(CalleeDecl)->param_begin() + I);
593 }
594 };
595
596 /// Sanitizers enabled for this function.
598
599 /// True if CodeGen currently emits code implementing sanitizer checks.
600 bool IsSanitizerScope = false;
601
602 /// RAII object to set/unset CodeGenFunction::IsSanitizerScope.
604 CodeGenFunction *CGF;
605
606 public:
607 SanitizerScope(CodeGenFunction *CGF);
609 };
610
611 /// In C++, whether we are code generating a thunk. This controls whether we
612 /// should emit cleanups.
613 bool CurFuncIsThunk = false;
614
615 /// In ARC, whether we should autorelease the return value.
616 bool AutoreleaseResult = false;
617
618 /// Whether we processed a Microsoft-style asm block during CodeGen. These can
619 /// potentially set the return value.
620 bool SawAsmBlock = false;
621
623
624 /// True if the current function is an outlined SEH helper. This can be a
625 /// finally block or filter expression.
627
628 /// True if CodeGen currently emits code inside presereved access index
629 /// region.
631
632 /// True if CodeGen currently emits the argument of
633 /// __builtin_preserve_field_info.
635
636 /// True if the current statement has nomerge attribute.
638
639 /// True if the current statement has noinline attribute.
641
642 /// True if the current statement has always_inline attribute.
644
645 /// True if the current statement has noconvergent attribute.
647
648 /// The mode string from the amdgpu_av attribute on the current statement,
649 /// or empty if the attribute is not present.
651
652 /// HLSL Branch attribute.
653 HLSLControlFlowHintAttr::Spelling HLSLControlFlowAttr =
654 HLSLControlFlowHintAttr::SpellingNotCalculated;
655
656 // The CallExpr within the current statement that the musttail attribute
657 // applies to. nullptr if there is no 'musttail' on the current statement.
658 const CallExpr *MustTailCall = nullptr;
659
660 /// Records the l-value that ScalarExprEmitter loads from when it emits a
661 /// specific expression. EmitArraySubscriptExpr sets this while emitting the
662 /// base of a 'counted_by' pointer subscript, so that the bounds check can
663 /// locate the count from the pointer field's address without re-emitting
664 /// (and so re-evaluating) the base. Capturing the l-value, instead of
665 /// emitting the load separately, keeps everything else the scalar load path
666 /// does (debug locations, 'align_value' assumptions, pseudo variables for
667 /// -fdebug-info-for-profiling, etc.).
669 /// The expression whose l-value is recorded.
670 const Expr *E;
671 /// The recorded l-value, set if \c E was loaded by ScalarExprEmitter.
672 std::optional<LValue> LV;
673 };
675
676 /// Returns true if a function must make progress, which means the
677 /// mustprogress attribute can be added.
679 if (CGM.getCodeGenOpts().getFiniteLoops() ==
681 return false;
682
683 // C++11 and later guarantees that a thread eventually will do one of the
684 // following (C++11 [intro.multithread]p24 and C++17 [intro.progress]p1):
685 // - terminate,
686 // - make a call to a library I/O function,
687 // - perform an access through a volatile glvalue, or
688 // - perform a synchronization operation or an atomic operation.
689 //
690 // Hence each function is 'mustprogress' in C++11 or later.
691 return getLangOpts().CPlusPlus11;
692 }
693
694 /// Returns true if a loop must make progress, which means the mustprogress
695 /// attribute can be added. \p HasConstantCond indicates whether the branch
696 /// condition is a known constant.
697 bool checkIfLoopMustProgress(const Expr *, bool HasEmptyBody);
698
700 llvm::Value *BlockPointer = nullptr;
701
702 llvm::DenseMap<const ValueDecl *, FieldDecl *> LambdaCaptureFields;
704
705 /// A mapping from NRVO variables to the flags used to indicate
706 /// when the NRVO has been applied to this variable.
707 llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
708
711
712 // A stack of cleanups which were added to EHStack but have to be deactivated
713 // later before being popped or emitted. These are usually deactivated on
714 // exiting a `CleanupDeactivationScope` scope. For instance, after a
715 // full-expr.
716 //
717 // These are specially useful for correctly emitting cleanups while
718 // encountering branches out of expression (through stmt-expr or coroutine
719 // suspensions).
725
726 // Enters a new scope for capturing cleanups which are deferred to be
727 // deactivated, all of which will be deactivated once the scope is exited.
729 CodeGenFunction &CGF;
736
738 assert(!Deactivated && "Deactivating already deactivated scope");
739 auto &Stack = CGF.DeferredDeactivationCleanupStack;
740 for (size_t I = Stack.size(); I > OldDeactivateCleanupStackSize; I--) {
741 CGF.DeactivateCleanupBlock(Stack[I - 1].Cleanup,
742 Stack[I - 1].DominatingIP);
743 Stack[I - 1].DominatingIP->eraseFromParent();
744 }
745 Stack.resize(OldDeactivateCleanupStackSize);
746 Deactivated = true;
747 }
748
750 if (Deactivated)
751 return;
753 }
754 };
755
757
758 llvm::Instruction *CurrentFuncletPad = nullptr;
759
760 class CallLifetimeEnd final : public EHScopeStack::Cleanup {
761 llvm::Value *Addr;
762
763 public:
764 CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
765
766 void Emit(CodeGenFunction &CGF, Flags flags) override {
767 CGF.EmitLifetimeEnd(Addr);
768 }
769 };
770
771 // We are using objects of this 'cleanup' class to emit fake.use calls
772 // for -fextend-variable-liveness. They are placed at the end of a variable's
773 // scope analogous to lifetime markers.
774 class FakeUse final : public EHScopeStack::Cleanup {
775 Address Addr;
776
777 public:
778 FakeUse(Address addr) : Addr(addr) {}
779
780 void Emit(CodeGenFunction &CGF, Flags flags) override {
781 CGF.EmitFakeUse(Addr);
782 }
783 };
784
785 /// Header for data within LifetimeExtendedCleanupStack.
786 struct alignas(uint64_t) LifetimeExtendedCleanupHeader {
787 /// The size of the following cleanup object.
788 unsigned Size;
789 /// The kind of cleanup to push.
790 LLVM_PREFERRED_TYPE(CleanupKind)
792 /// Whether this is a conditional cleanup.
793 LLVM_PREFERRED_TYPE(bool)
794 unsigned IsConditional : 1;
795
796 size_t getSize() const { return Size; }
797 CleanupKind getKind() const { return (CleanupKind)Kind; }
798 bool isConditional() const { return IsConditional; }
799 };
800
801 /// i32s containing the indexes of the cleanup destinations.
803
805
806 /// EHResumeBlock - Unified block containing a call to llvm.eh.resume.
807 llvm::BasicBlock *EHResumeBlock = nullptr;
808
809 /// The exception slot. All landing pads write the current exception pointer
810 /// into this alloca.
811 llvm::Value *ExceptionSlot = nullptr;
812
813 /// The selector slot. Under the MandatoryCleanup model, all landing pads
814 /// write the current selector value into this alloca.
815 llvm::AllocaInst *EHSelectorSlot = nullptr;
816
817 /// A stack of exception code slots. Entering an __except block pushes a slot
818 /// on the stack and leaving pops one. The __exception_code() intrinsic loads
819 /// a value from the top of the stack.
821
822 /// Value returned by __exception_info intrinsic.
823 llvm::Value *SEHInfo = nullptr;
824
825 /// Emits a landing pad for the current EH stack.
826 llvm::BasicBlock *EmitLandingPad();
827
828 llvm::BasicBlock *getInvokeDestImpl();
829
830 /// Parent loop-based directive for scan directive.
832 llvm::BasicBlock *OMPBeforeScanBlock = nullptr;
833 llvm::BasicBlock *OMPAfterScanBlock = nullptr;
834 llvm::BasicBlock *OMPScanExitBlock = nullptr;
835 llvm::BasicBlock *OMPScanDispatch = nullptr;
836 bool OMPFirstScanLoop = false;
837
838 /// Manages parent directive for scan directives.
840 CodeGenFunction &CGF;
841 const OMPExecutableDirective *ParentLoopDirectiveForScan;
842
843 public:
845 CodeGenFunction &CGF,
846 const OMPExecutableDirective &ParentLoopDirectiveForScan)
847 : CGF(CGF),
848 ParentLoopDirectiveForScan(CGF.OMPParentLoopDirectiveForScan) {
849 CGF.OMPParentLoopDirectiveForScan = &ParentLoopDirectiveForScan;
850 }
852 CGF.OMPParentLoopDirectiveForScan = ParentLoopDirectiveForScan;
853 }
854 };
855
856 template <class T>
858 return DominatingValue<T>::save(*this, value);
859 }
860
862 public:
863 CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures);
864 CGFPOptionsRAII(CodeGenFunction &CGF, const Expr *E);
866
867 private:
868 void ConstructorHelper(FPOptions FPFeatures);
869 CodeGenFunction &CGF;
870 FPOptions OldFPFeatures;
871 llvm::fp::ExceptionBehavior OldExcept;
872 llvm::RoundingMode OldRounding;
873 std::optional<CGBuilderTy::FastMathFlagGuard> FMFGuard;
874 };
876
878 public:
880 : CGM(CGM_), SavedAtomicOpts(CGM.getAtomicOpts()) {
881 CGM.setAtomicOpts(AO);
882 }
883 CGAtomicOptionsRAII(CodeGenModule &CGM_, const AtomicAttr *AA)
884 : CGM(CGM_), SavedAtomicOpts(CGM.getAtomicOpts()) {
885 if (!AA)
886 return;
887 AtomicOptions AO = SavedAtomicOpts;
888 for (auto Option : AA->atomicOptions()) {
889 switch (Option) {
890 case AtomicAttr::remote_memory:
891 AO.remote_memory = true;
892 break;
893 case AtomicAttr::no_remote_memory:
894 AO.remote_memory = false;
895 break;
896 case AtomicAttr::fine_grained_memory:
897 AO.fine_grained_memory = true;
898 break;
899 case AtomicAttr::no_fine_grained_memory:
900 AO.fine_grained_memory = false;
901 break;
902 case AtomicAttr::ignore_denormal_mode:
903 AO.ignore_denormal_mode = true;
904 break;
905 case AtomicAttr::no_ignore_denormal_mode:
906 AO.ignore_denormal_mode = false;
907 break;
908 }
909 }
910 CGM.setAtomicOpts(AO);
911 }
912
915 ~CGAtomicOptionsRAII() { CGM.setAtomicOpts(SavedAtomicOpts); }
916
917 private:
919 AtomicOptions SavedAtomicOpts;
920 };
921
922public:
923 /// ObjCEHValueStack - Stack of Objective-C exception values, used for
924 /// rethrows.
926
927 /// A class controlling the emission of a finally block.
929 /// Where the catchall's edge through the cleanup should go.
930 JumpDest RethrowDest;
931
932 /// A function to call to enter the catch.
933 llvm::FunctionCallee BeginCatchFn;
934
935 /// An i1 variable indicating whether or not the @finally is
936 /// running for an exception.
937 llvm::AllocaInst *ForEHVar = nullptr;
938
939 /// An i8* variable into which the exception pointer to rethrow
940 /// has been saved.
941 llvm::AllocaInst *SavedExnVar = nullptr;
942
943 public:
944 void enter(CodeGenFunction &CGF, const Stmt *Finally,
945 llvm::FunctionCallee beginCatchFn,
946 llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn);
947 void exit(CodeGenFunction &CGF);
948 };
949
950 /// Returns true inside SEH __try blocks.
951 bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); }
952
953 /// Returns true while emitting a cleanuppad.
957
958 /// pushFullExprCleanup - Push a cleanup to be run at the end of the
959 /// current full-expression. Safe against the possibility that
960 /// we're currently inside a conditionally-evaluated expression.
961 template <class T, class... As>
963 // If we're not in a conditional branch, or if none of the
964 // arguments requires saving, then use the unconditional cleanup.
966 return EHStack.pushCleanup<T>(kind, A...);
967
968 // Stash values in a tuple so we can guarantee the order of saves.
969 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
970 SavedTuple Saved{saveValueInCond(A)...};
971
972 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
973 EHStack.pushCleanupTuple<CleanupType>(kind, Saved);
975 }
976
977 /// Queue a cleanup to be pushed after finishing the current full-expression,
978 /// potentially with an active flag.
979 template <class T, class... As>
983 Kind, RawAddress::invalid(), A...);
984
985 RawAddress ActiveFlag = createCleanupActiveFlag();
986 assert(!DominatingValue<Address>::needsSaving(ActiveFlag) &&
987 "cleanup active flag should never need saving");
988
989 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
990 SavedTuple Saved{saveValueInCond(A)...};
991
992 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
994 Saved);
995 }
996
997 template <class T, class... As>
999 RawAddress ActiveFlag, As... A) {
1000 LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind,
1001 ActiveFlag.isValid()};
1002
1003 size_t OldSize = LifetimeExtendedCleanupStack.size();
1005 LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size +
1006 (Header.IsConditional ? sizeof(ActiveFlag) : 0));
1007
1008 static_assert((alignof(LifetimeExtendedCleanupHeader) == alignof(T)) &&
1009 (alignof(T) == alignof(RawAddress)),
1010 "Cleanup will be allocated on misaligned address");
1011 char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
1012 new (Buffer) LifetimeExtendedCleanupHeader(Header);
1013 new (Buffer + sizeof(Header)) T(A...);
1014 if (Header.IsConditional)
1015 new (Buffer + sizeof(Header) + sizeof(T)) RawAddress(ActiveFlag);
1016 }
1017
1018 // Push a cleanup onto EHStack and deactivate it later. It is usually
1019 // deactivated when exiting a `CleanupDeactivationScope` (for example: after a
1020 // full expression).
1021 template <class T, class... As>
1023 // Placeholder dominating IP for this cleanup.
1024 llvm::Instruction *DominatingIP =
1025 Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
1026 EHStack.pushCleanup<T>(Kind, A...);
1028 {EHStack.stable_begin(), DominatingIP});
1029 }
1030
1031 /// Set up the last cleanup that was pushed as a conditional
1032 /// full-expression cleanup.
1036
1037 void initFullExprCleanupWithFlag(RawAddress ActiveFlag);
1039
1040 /// PushDestructorCleanup - Push a cleanup to call the
1041 /// complete-object destructor of an object of the given type at the
1042 /// given address. Does nothing if T is not a C++ class type with a
1043 /// non-trivial destructor.
1045
1046 /// PushDestructorCleanup - Push a cleanup to call the
1047 /// complete-object variant of the given destructor on the object at
1048 /// the given address.
1050 Address Addr);
1051
1052 /// PopCleanupBlock - Will pop the cleanup entry on the stack and
1053 /// process all branch fixups.
1054 void PopCleanupBlock(bool FallThroughIsBranchThrough = false,
1055 bool ForDeactivation = false);
1056
1057 /// DeactivateCleanupBlock - Deactivates the given cleanup block.
1058 /// The block cannot be reactivated. Pops it if it's the top of the
1059 /// stack.
1060 ///
1061 /// \param DominatingIP - An instruction which is known to
1062 /// dominate the current IP (if set) and which lies along
1063 /// all paths of execution between the current IP and the
1064 /// the point at which the cleanup comes into scope.
1066 llvm::Instruction *DominatingIP);
1067
1068 /// ActivateCleanupBlock - Activates an initially-inactive cleanup.
1069 /// Cannot be used to resurrect a deactivated cleanup.
1070 ///
1071 /// \param DominatingIP - An instruction which is known to
1072 /// dominate the current IP (if set) and which lies along
1073 /// all paths of execution between the current IP and the
1074 /// the point at which the cleanup comes into scope.
1076 llvm::Instruction *DominatingIP);
1077
1078 /// Enters a new scope for capturing cleanups, all of which
1079 /// will be executed once the scope is exited.
1080 class RunCleanupsScope {
1081 EHScopeStack::stable_iterator CleanupStackDepth, OldCleanupScopeDepth;
1082 size_t LifetimeExtendedCleanupStackSize;
1083 CleanupDeactivationScope DeactivateCleanups;
1084 bool OldDidCallStackSave;
1085
1086 protected:
1088
1089 private:
1090 RunCleanupsScope(const RunCleanupsScope &) = delete;
1091 void operator=(const RunCleanupsScope &) = delete;
1092
1093 protected:
1094 CodeGenFunction &CGF;
1095
1096 public:
1097 /// Enter a new cleanup scope.
1098 explicit RunCleanupsScope(CodeGenFunction &CGF)
1099 : DeactivateCleanups(CGF), PerformCleanup(true), CGF(CGF) {
1100 CleanupStackDepth = CGF.EHStack.stable_begin();
1101 LifetimeExtendedCleanupStackSize =
1102 CGF.LifetimeExtendedCleanupStack.size();
1103 OldDidCallStackSave = CGF.DidCallStackSave;
1104 CGF.DidCallStackSave = false;
1105 OldCleanupScopeDepth = CGF.CurrentCleanupScopeDepth;
1106 CGF.CurrentCleanupScopeDepth = CleanupStackDepth;
1107 }
1108
1109 /// Exit this cleanup scope, emitting any accumulated cleanups.
1111 if (PerformCleanup)
1112 ForceCleanup();
1113 }
1114
1115 /// Determine whether this scope requires any cleanups.
1116 bool requiresCleanups() const {
1117 return CGF.EHStack.stable_begin() != CleanupStackDepth;
1118 }
1119
1120 /// Force the emission of cleanups now, instead of waiting
1121 /// until this object is destroyed.
1122 /// \param ValuesToReload - A list of values that need to be available at
1123 /// the insertion point after cleanup emission. If cleanup emission created
1124 /// a shared cleanup block, these value pointers will be rewritten.
1125 /// Otherwise, they not will be modified.
1126 void
1127 ForceCleanup(std::initializer_list<llvm::Value **> ValuesToReload = {}) {
1128 assert(PerformCleanup && "Already forced cleanup");
1129 CGF.DidCallStackSave = OldDidCallStackSave;
1130 DeactivateCleanups.ForceDeactivate();
1131 CGF.PopCleanupBlocks(CleanupStackDepth, LifetimeExtendedCleanupStackSize,
1132 ValuesToReload);
1133 PerformCleanup = false;
1134 CGF.CurrentCleanupScopeDepth = OldCleanupScopeDepth;
1135 }
1136 };
1137
1138 // Cleanup stack depth of the RunCleanupsScope that was pushed most recently.
1141
1142 class LexicalScope : public RunCleanupsScope {
1143 SourceRange Range;
1145 LexicalScope *ParentScope;
1146
1147 LexicalScope(const LexicalScope &) = delete;
1148 void operator=(const LexicalScope &) = delete;
1149
1150 public:
1151 /// Enter a new cleanup scope.
1152 explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range);
1153
1154 void addLabel(const LabelDecl *label) {
1155 assert(PerformCleanup && "adding label to dead scope?");
1156 Labels.push_back(label);
1157 }
1158
1159 /// Exit this cleanup scope, emitting any accumulated
1160 /// cleanups.
1161 ~LexicalScope();
1162
1163 /// Force the emission of cleanups now, instead of waiting
1164 /// until this object is destroyed.
1166 CGF.CurLexicalScope = ParentScope;
1168
1169 if (!Labels.empty())
1170 rescopeLabels();
1171 }
1172
1173 bool hasLabels() const { return !Labels.empty(); }
1174
1175 void rescopeLabels();
1176 };
1177
1178 typedef llvm::DenseMap<const Decl *, Address> DeclMapTy;
1179
1180 /// The class used to assign some variables some temporarily addresses.
1181 class OMPMapVars {
1182 DeclMapTy SavedLocals;
1183 DeclMapTy SavedTempAddresses;
1184 OMPMapVars(const OMPMapVars &) = delete;
1185 void operator=(const OMPMapVars &) = delete;
1186
1187 public:
1188 explicit OMPMapVars() = default;
1190 assert(SavedLocals.empty() && "Did not restored original addresses.");
1191 };
1192
1193 /// Sets the address of the variable \p LocalVD to be \p TempAddr in
1194 /// function \p CGF.
1195 /// \return true if at least one variable was set already, false otherwise.
1196 bool setVarAddr(CodeGenFunction &CGF, const ValueDecl *LocalVD,
1197 Address TempAddr) {
1198 LocalVD = cast<ValueDecl>(LocalVD->getCanonicalDecl());
1199
1200 // Only save it once.
1201 if (SavedLocals.count(LocalVD))
1202 return false;
1203
1204 // Copy the existing local entry to SavedLocals.
1205 auto it = CGF.LocalDeclMap.find(LocalVD);
1206 if (it != CGF.LocalDeclMap.end())
1207 SavedLocals.try_emplace(LocalVD, it->second);
1208 else
1209 SavedLocals.try_emplace(LocalVD, Address::invalid());
1210
1211 // Generate the private entry.
1212 QualType VarTy = LocalVD->getType();
1213 if (VarTy->isReferenceType()) {
1214 Address Temp = CGF.CreateMemTemp(VarTy);
1215 CGF.Builder.CreateStore(TempAddr.emitRawPointer(CGF), Temp);
1216 TempAddr = Temp;
1217 }
1218 if (const auto *BD = dyn_cast<BindingDecl>(LocalVD))
1219 CGF.OMPPrivatizedBindings.insert_or_assign(BD, TempAddr);
1220 SavedTempAddresses.try_emplace(LocalVD, TempAddr);
1221
1222 return true;
1223 }
1224
1225 /// Applies new addresses to the list of the variables.
1226 /// \return true if at least one variable is using new address, false
1227 /// otherwise.
1228 bool apply(CodeGenFunction &CGF) {
1229 copyInto(SavedTempAddresses, CGF.LocalDeclMap);
1230 SavedTempAddresses.clear();
1231 return !SavedLocals.empty();
1232 }
1233
1234 /// Restores original addresses of the variables.
1235 void restore(CodeGenFunction &CGF) {
1236 if (!SavedLocals.empty()) {
1237 copyInto(SavedLocals, CGF.LocalDeclMap);
1238 SavedLocals.clear();
1239 }
1240 }
1241
1242 private:
1243 /// Copy all the entries in the source map over the corresponding
1244 /// entries in the destination, which must exist.
1245 static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) {
1246 for (auto &[Decl, Addr] : Src) {
1247 if (!Addr.isValid())
1248 Dest.erase(Decl);
1249 else
1250 Dest.insert_or_assign(Decl, Addr);
1251 }
1252 }
1253 };
1254
1255 /// The scope used to remap some variables as private in the OpenMP loop body
1256 /// (or other captured region emitted without outlining), and to restore old
1257 /// vars back on exit.
1258 class OMPPrivateScope : public RunCleanupsScope {
1259 OMPMapVars MappedVars;
1260 OMPPrivateScope(const OMPPrivateScope &) = delete;
1261 void operator=(const OMPPrivateScope &) = delete;
1262 llvm::DenseMap<const BindingDecl *, Address> BindingChanges;
1263
1264 public:
1265 /// Enter a new OpenMP private scope.
1266 explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {}
1267
1268 /// Registers \p LocalVD variable as a private with \p Addr as the address
1269 /// of the corresponding private variable. \p
1270 /// PrivateGen is the address of the generated private variable.
1271 /// \return true if the variable is registered as private, false if it has
1272 /// been privatized already.
1273 bool addPrivate(const ValueDecl *LocalVD, Address Addr) {
1274 assert(PerformCleanup && "adding private to dead scope");
1275 if (const auto *BD = dyn_cast<BindingDecl>(LocalVD->getCanonicalDecl())) {
1276 auto It = CGF.OMPPrivatizedBindings.find(BD);
1277 BindingChanges.insert({BD, It != CGF.OMPPrivatizedBindings.end()
1278 ? It->second
1279 : Address::invalid()});
1280 }
1281 return MappedVars.setVarAddr(CGF, LocalVD, Addr);
1282 }
1283
1284 /// Privatizes local variables previously registered as private.
1285 /// Registration is separate from the actual privatization to allow
1286 /// initializers use values of the original variables, not the private one.
1287 /// This is important, for example, if the private variable is a class
1288 /// variable initialized by a constructor that references other private
1289 /// variables. But at initialization original variables must be used, not
1290 /// private copies.
1291 /// \return true if at least one variable was privatized, false otherwise.
1292 bool Privatize() { return MappedVars.apply(CGF); }
1293
1298
1299 /// Exit scope - all the mapped variables are restored.
1301 if (PerformCleanup)
1302 ForceCleanup();
1303 for (auto &Change : BindingChanges) {
1304 if (Change.second.isValid()) {
1305 auto It = CGF.OMPPrivatizedBindings.find(Change.first);
1306 if (It != CGF.OMPPrivatizedBindings.end())
1307 It->second = Change.second;
1308 else
1309 CGF.OMPPrivatizedBindings.insert({Change.first, Change.second});
1310 } else {
1311 CGF.OMPPrivatizedBindings.erase(Change.first);
1312 }
1313 }
1314 }
1315
1316 /// Checks if the global variable is captured in current function.
1317 bool isGlobalVarCaptured(const VarDecl *VD) const {
1318 VD = VD->getCanonicalDecl();
1319 return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0;
1320 }
1321
1322 /// Restore all mapped variables w/o clean up. This is usefully when we want
1323 /// to reference the original variables but don't want the clean up because
1324 /// that could emit lifetime end too early, causing backend issue #56913.
1325 void restoreMap() { MappedVars.restore(CGF); }
1326 };
1327
1328 /// Save/restore original map of previously emitted local vars in case when we
1329 /// need to duplicate emission of the same code several times in the same
1330 /// function for OpenMP code.
1332 CodeGenFunction &CGF;
1333 DeclMapTy SavedMap;
1334
1335 public:
1336 OMPLocalDeclMapRAII(CodeGenFunction &CGF)
1337 : CGF(CGF), SavedMap(CGF.LocalDeclMap) {}
1338 ~OMPLocalDeclMapRAII() { SavedMap.swap(CGF.LocalDeclMap); }
1339 };
1340
1341 /// Takes the old cleanup stack size and emits the cleanup blocks
1342 /// that have been added.
1343 void
1345 std::initializer_list<llvm::Value **> ValuesToReload = {});
1346
1347 /// Takes the old cleanup stack size and emits the cleanup blocks
1348 /// that have been added, then adds all lifetime-extended cleanups from
1349 /// the given position to the stack.
1350 void
1351 PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize,
1352 size_t OldLifetimeExtendedStackSize,
1353 std::initializer_list<llvm::Value **> ValuesToReload = {});
1354
1355 void ResolveBranchFixups(llvm::BasicBlock *Target);
1356
1357 /// The given basic block lies in the current EH scope, but may be a
1358 /// target of a potentially scope-crossing jump; get a stable handle
1359 /// to which we can perform this jump later.
1361 return JumpDest(Target, EHStack.getInnermostNormalCleanup(),
1363 }
1364
1365 /// The given basic block lies in the current EH scope, but may be a
1366 /// target of a potentially scope-crossing jump; get a stable handle
1367 /// to which we can perform this jump later.
1368 JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) {
1370 }
1371
1372 /// EmitBranchThroughCleanup - Emit a branch from the current insert
1373 /// block through the normal cleanup handling code (if any) and then
1374 /// on to \arg Dest.
1375 void EmitBranchThroughCleanup(JumpDest Dest);
1376
1377 /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
1378 /// specified destination obviously has no cleanups to run. 'false' is always
1379 /// a conservatively correct answer for this method.
1380 bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const;
1381
1382 /// popCatchScope - Pops the catch scope at the top of the EHScope
1383 /// stack, emitting any required code (other than the catch handlers
1384 /// themselves).
1385 void popCatchScope();
1386
1387 // This function should be called after emitting all catch clauses and none
1388 // of them were 'catch-all' clauses.
1389 // Because in wasm we merge all catch clauses into one big catchpad, in case
1390 // none of the types in catch handlers matches after we test against each of
1391 // them, we should unwind to the next EH enclosing scope. We generate a call
1392 // to rethrow function here to do that.
1393 void WasmEmitFallthroughRethrow(llvm::BasicBlock *WasmCatchStartBlock);
1394
1395 llvm::BasicBlock *getEHResumeBlock(bool isCleanup);
1396 llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope);
1397 llvm::BasicBlock *
1399
1400 /// An object to manage conditionally-evaluated expressions.
1402 llvm::BasicBlock *StartBB;
1403
1404 public:
1405 ConditionalEvaluation(CodeGenFunction &CGF)
1406 : StartBB(CGF.Builder.GetInsertBlock()) {}
1407
1408 void begin(CodeGenFunction &CGF) {
1409 assert(CGF.OutermostConditional != this);
1410 if (!CGF.OutermostConditional)
1411 CGF.OutermostConditional = this;
1412 }
1413
1414 void end(CodeGenFunction &CGF) {
1415 assert(CGF.OutermostConditional != nullptr);
1416 if (CGF.OutermostConditional == this)
1417 CGF.OutermostConditional = nullptr;
1418 }
1419
1420 /// Returns a block which will be executed prior to each
1421 /// evaluation of the conditional code.
1422 llvm::BasicBlock *getStartingBlock() const { return StartBB; }
1423 };
1424
1425 /// isInConditionalBranch - Return true if we're currently emitting
1426 /// one branch or the other of a conditional expression.
1427 bool isInConditionalBranch() const { return OutermostConditional != nullptr; }
1428
1429 void setBeforeOutermostConditional(llvm::Value *value, Address addr,
1430 CodeGenFunction &CGF) {
1431 assert(isInConditionalBranch());
1432 llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
1433 auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
1434 block->back().getIterator());
1435 store->setAlignment(addr.getAlignment().getAsAlign());
1436 }
1437
1438 /// An RAII object to record that we're evaluating a statement
1439 /// expression.
1441 CodeGenFunction &CGF;
1442
1443 /// We have to save the outermost conditional: cleanups in a
1444 /// statement expression aren't conditional just because the
1445 /// StmtExpr is.
1446 ConditionalEvaluation *SavedOutermostConditional;
1447
1448 public:
1449 StmtExprEvaluation(CodeGenFunction &CGF)
1450 : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) {
1451 CGF.OutermostConditional = nullptr;
1452 }
1453
1455 CGF.OutermostConditional = SavedOutermostConditional;
1456 CGF.EnsureInsertPoint();
1457 }
1458 };
1459
1460 /// An object which temporarily prevents a value from being
1461 /// destroyed by aggressive peephole optimizations that assume that
1462 /// all uses of a value have been realized in the IR.
1464 llvm::Instruction *Inst = nullptr;
1465 friend class CodeGenFunction;
1466
1467 public:
1469 };
1470
1471 /// A non-RAII class containing all the information about a bound
1472 /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
1473 /// this which makes individual mappings very simple; using this
1474 /// class directly is useful when you have a variable number of
1475 /// opaque values or don't want the RAII functionality for some
1476 /// reason.
1477 class OpaqueValueMappingData {
1478 const OpaqueValueExpr *OpaqueValue;
1479 bool BoundLValue;
1481
1482 OpaqueValueMappingData(const OpaqueValueExpr *ov, bool boundLValue)
1483 : OpaqueValue(ov), BoundLValue(boundLValue) {}
1484
1485 public:
1487
1488 static bool shouldBindAsLValue(const Expr *expr) {
1489 // gl-values should be bound as l-values for obvious reasons.
1490 // Records should be bound as l-values because IR generation
1491 // always keeps them in memory. Expressions of function type
1492 // act exactly like l-values but are formally required to be
1493 // r-values in C.
1494 return expr->isGLValue() || expr->getType()->isFunctionType() ||
1495 hasAggregateEvaluationKind(expr->getType());
1496 }
1497
1499 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e) {
1500 if (shouldBindAsLValue(ov))
1501 return bind(CGF, ov, CGF.EmitLValue(e));
1502 return bind(CGF, ov, CGF.EmitAnyExpr(e));
1503 }
1504
1506 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const LValue &lv) {
1507 assert(shouldBindAsLValue(ov));
1508 CGF.OpaqueLValues.insert(std::make_pair(ov, lv));
1509 return OpaqueValueMappingData(ov, true);
1510 }
1511
1513 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const RValue &rv) {
1514 assert(!shouldBindAsLValue(ov));
1515 CGF.OpaqueRValues.insert(std::make_pair(ov, rv));
1516
1517 OpaqueValueMappingData data(ov, false);
1518
1519 // Work around an extremely aggressive peephole optimization in
1520 // EmitScalarConversion which assumes that all other uses of a
1521 // value are extant.
1522 data.Protection = CGF.protectFromPeepholes(rv);
1523
1524 return data;
1525 }
1526
1527 bool isValid() const { return OpaqueValue != nullptr; }
1528 void clear() { OpaqueValue = nullptr; }
1529
1530 void unbind(CodeGenFunction &CGF) {
1531 assert(OpaqueValue && "no data to unbind!");
1532
1533 if (BoundLValue) {
1534 CGF.OpaqueLValues.erase(OpaqueValue);
1535 } else {
1536 CGF.OpaqueRValues.erase(OpaqueValue);
1537 CGF.unprotectFromPeepholes(Protection);
1538 }
1539 }
1540 };
1541
1542 /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
1544 CodeGenFunction &CGF;
1546
1547 public:
1551
1552 /// Build the opaque value mapping for the given conditional
1553 /// operator if it's the GNU ?: extension. This is a common
1554 /// enough pattern that the convenience operator is really
1555 /// helpful.
1556 ///
1557 OpaqueValueMapping(CodeGenFunction &CGF,
1559 : CGF(CGF) {
1561 // Leave Data empty.
1562 return;
1563
1566 e->getCommon());
1567 }
1568
1569 /// Build the opaque value mapping for an OpaqueValueExpr whose source
1570 /// expression is set to the expression the OVE represents.
1571 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *OV)
1572 : CGF(CGF) {
1573 if (OV) {
1574 assert(OV->getSourceExpr() && "wrong form of OpaqueValueMapping used "
1575 "for OVE with no source expression");
1576 Data = OpaqueValueMappingData::bind(CGF, OV, OV->getSourceExpr());
1577 }
1578 }
1579
1580 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue,
1581 LValue lvalue)
1582 : CGF(CGF),
1583 Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {}
1584
1585 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue,
1586 RValue rvalue)
1587 : CGF(CGF),
1588 Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {}
1589
1590 void pop() {
1591 Data.unbind(CGF);
1592 Data.clear();
1593 }
1594
1596 if (Data.isValid())
1597 Data.unbind(CGF);
1598 }
1599 };
1600
1601private:
1602 CGDebugInfo *DebugInfo;
1603 /// Used to create unique names for artificial VLA size debug info variables.
1604 unsigned VLAExprCounter = 0;
1605 bool DisableDebugInfo = false;
1606
1607 /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
1608 /// calling llvm.stacksave for multiple VLAs in the same scope.
1609 bool DidCallStackSave = false;
1610
1611 /// IndirectBranch - The first time an indirect goto is seen we create a block
1612 /// with an indirect branch. Every time we see the address of a label taken,
1613 /// we add the label to the indirect goto. Every subsequent indirect goto is
1614 /// codegen'd as a jump to the IndirectBranch's basic block.
1615 llvm::IndirectBrInst *IndirectBranch = nullptr;
1616
1617 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1618 /// decls.
1619 DeclMapTy LocalDeclMap;
1620
1621 /// Lookup map for privatized BindingDecls.
1622 /// Used when BindingDecls are remapped during OpenMP outlining, since the
1623 /// remapped BindingDecl has a different pointer than the original.
1624 llvm::SmallDenseMap<const BindingDecl *, Address> OMPPrivatizedBindings;
1625
1626 // Keep track of the cleanups for callee-destructed parameters pushed to the
1627 // cleanup stack so that they can be deactivated later.
1628 llvm::DenseMap<const ParmVarDecl *, EHScopeStack::stable_iterator>
1629 CalleeDestructedParamCleanups;
1630
1631 /// SizeArguments - If a ParmVarDecl had the pass_object_size attribute, this
1632 /// will contain a mapping from said ParmVarDecl to its implicit "object_size"
1633 /// parameter.
1634 llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2>
1635 SizeArguments;
1636
1637 /// Track escaped local variables with auto storage. Used during SEH
1638 /// outlining to produce a call to llvm.localescape.
1639 llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals;
1640
1641 /// LabelMap - This keeps track of the LLVM basic block for each C label.
1642 llvm::DenseMap<const LabelDecl *, JumpDest> LabelMap;
1643
1644 // BreakContinueStack - This keeps track of where break and continue
1645 // statements should jump to.
1646 struct BreakContinue {
1647 BreakContinue(const Stmt &LoopOrSwitch, JumpDest Break, JumpDest Continue)
1648 : LoopOrSwitch(&LoopOrSwitch), BreakBlock(Break),
1649 ContinueBlock(Continue) {}
1650
1651 const Stmt *LoopOrSwitch;
1652 JumpDest BreakBlock;
1653 JumpDest ContinueBlock;
1654 };
1655 SmallVector<BreakContinue, 8> BreakContinueStack;
1656
1657 /// Handles cancellation exit points in OpenMP-related constructs.
1658 class OpenMPCancelExitStack {
1659 /// Tracks cancellation exit point and join point for cancel-related exit
1660 /// and normal exit.
1661 struct CancelExit {
1662 CancelExit() = default;
1663 CancelExit(OpenMPDirectiveKind Kind, JumpDest ExitBlock,
1664 JumpDest ContBlock)
1665 : Kind(Kind), ExitBlock(ExitBlock), ContBlock(ContBlock) {}
1666 OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown;
1667 /// true if the exit block has been emitted already by the special
1668 /// emitExit() call, false if the default codegen is used.
1669 bool HasBeenEmitted = false;
1670 JumpDest ExitBlock;
1671 JumpDest ContBlock;
1672 };
1673
1674 SmallVector<CancelExit, 8> Stack;
1675
1676 public:
1677 OpenMPCancelExitStack() : Stack(1) {}
1678 ~OpenMPCancelExitStack() = default;
1679 /// Fetches the exit block for the current OpenMP construct.
1680 JumpDest getExitBlock() const { return Stack.back().ExitBlock; }
1681 /// Emits exit block with special codegen procedure specific for the related
1682 /// OpenMP construct + emits code for normal construct cleanup.
1683 void emitExit(CodeGenFunction &CGF, OpenMPDirectiveKind Kind,
1684 const llvm::function_ref<void(CodeGenFunction &)> CodeGen) {
1685 if (Stack.back().Kind == Kind && getExitBlock().isValid()) {
1686 assert(CGF.getOMPCancelDestination(Kind).isValid());
1687 assert(CGF.HaveInsertPoint());
1688 assert(!Stack.back().HasBeenEmitted);
1689 auto IP = CGF.Builder.saveAndClearIP();
1690 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1691 CodeGen(CGF);
1692 CGF.EmitBranch(Stack.back().ContBlock.getBlock());
1693 CGF.Builder.restoreIP(IP);
1694 Stack.back().HasBeenEmitted = true;
1695 }
1696 CodeGen(CGF);
1697 }
1698 /// Enter the cancel supporting \a Kind construct.
1699 /// \param Kind OpenMP directive that supports cancel constructs.
1700 /// \param HasCancel true, if the construct has inner cancel directive,
1701 /// false otherwise.
1702 void enter(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel) {
1703 Stack.push_back({Kind,
1704 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.exit")
1705 : JumpDest(),
1706 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.cont")
1707 : JumpDest()});
1708 }
1709 /// Emits default exit point for the cancel construct (if the special one
1710 /// has not be used) + join point for cancel/normal exits.
1711 void exit(CodeGenFunction &CGF) {
1712 if (getExitBlock().isValid()) {
1713 assert(CGF.getOMPCancelDestination(Stack.back().Kind).isValid());
1714 bool HaveIP = CGF.HaveInsertPoint();
1715 if (!Stack.back().HasBeenEmitted) {
1716 if (HaveIP)
1717 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1718 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1719 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1720 }
1721 CGF.EmitBlock(Stack.back().ContBlock.getBlock());
1722 if (!HaveIP) {
1723 CGF.Builder.CreateUnreachable();
1724 CGF.Builder.ClearInsertionPoint();
1725 }
1726 }
1727 Stack.pop_back();
1728 }
1729 };
1730 OpenMPCancelExitStack OMPCancelStack;
1731
1732 /// Lower the Likelihood knowledge about the \p Cond via llvm.expect intrin.
1733 llvm::Value *emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond,
1734 Stmt::Likelihood LH);
1735
1736 std::unique_ptr<CodeGenPGO> PGO;
1737
1738 /// Calculate branch weights appropriate for PGO data
1739 llvm::MDNode *createProfileWeights(uint64_t TrueCount,
1740 uint64_t FalseCount) const;
1741 llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights) const;
1742 llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond,
1743 uint64_t LoopCount) const;
1744
1745public:
1746 bool hasSkipCounter(const Stmt *S) const;
1747
1748 void markStmtAsUsed(bool Skipped, const Stmt *S);
1749 void markStmtMaybeUsed(const Stmt *S);
1750
1751 /// Used to specify which counter in a pair shall be incremented.
1752 /// For non-binary counters, a skip counter is derived as (Parent - Exec).
1753 /// In contrast for binary counters, a skip counter cannot be computed from
1754 /// the Parent counter. In such cases, dedicated SkipPath counters must be
1755 /// allocated and marked (incremented as binary counters). (Parent can be
1756 /// synthesized with (Exec + Skip) in simple cases)
1758 UseExecPath = 0, ///< Exec (true)
1759 UseSkipPath, ///< Skip (false)
1760 };
1761
1762 /// Increment the profiler's counter for the given statement by \p StepV.
1763 /// If \p StepV is null, the default increment is 1.
1764 void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) {
1765 incrementProfileCounter(UseExecPath, S, false, StepV);
1766 }
1767
1768 /// Emit increment of Counter.
1769 /// \param ExecSkip Use `Skipped` Counter if UseSkipPath is specified.
1770 /// \param S The Stmt that Counter is associated.
1771 /// \param UseBoth Mark both Exec/Skip as used. (for verification)
1772 /// \param StepV The offset Value for adding to Counter.
1773 void incrementProfileCounter(CounterForIncrement ExecSkip, const Stmt *S,
1774 bool UseBoth = false,
1775 llvm::Value *StepV = nullptr);
1776
1778 return (CGM.getCodeGenOpts().hasProfileClangInstr() &&
1779 CGM.getCodeGenOpts().MCDCCoverage &&
1780 !CurFn->hasFnAttribute(llvm::Attribute::NoProfile));
1781 }
1782
1783 /// Allocate a temp value on the stack that MCDC can use to track condition
1784 /// results.
1786
1787 bool isBinaryLogicalOp(const Expr *E) const {
1788 const BinaryOperator *BOp = dyn_cast<BinaryOperator>(E->IgnoreParens());
1789 return (BOp && BOp->isLogicalOp());
1790 }
1791
1792 bool isMCDCDecisionExpr(const Expr *E) const;
1793 bool isMCDCBranchExpr(const Expr *E) const;
1794
1795 /// Zero-init the MCDC temp value.
1796 void maybeResetMCDCCondBitmap(const Expr *E);
1797
1798 /// Increment the profiler's counter for the given expression by \p StepV.
1799 /// If \p StepV is null, the default increment is 1.
1801
1802 /// Update the MCDC temp value with the condition's evaluated result.
1803 void maybeUpdateMCDCCondBitmap(const Expr *E, llvm::Value *Val);
1804
1805 /// Get the profiler's count for the given statement.
1806 uint64_t getProfileCount(const Stmt *S);
1807
1808 /// Set the profiler's current count.
1809 void setCurrentProfileCount(uint64_t Count);
1810
1811 /// Get the profiler's current count. This is generally the count for the most
1812 /// recently incremented counter.
1814
1815 /// See CGDebugInfo::addInstToCurrentSourceAtom.
1816 void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction,
1817 llvm::Value *Backup);
1818
1819 /// See CGDebugInfo::addInstToSpecificSourceAtom.
1820 void addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
1821 llvm::Value *Backup, uint64_t Atom);
1822
1823 /// Add \p KeyInstruction and an optional \p Backup instruction to a new atom
1824 /// group (See ApplyAtomGroup for more info).
1825 void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction,
1826 llvm::Value *Backup);
1827
1828 /// Copy all PFP fields from SrcPtr to DestPtr while updating signatures,
1829 /// assuming that DestPtr was already memcpy'd from SrcPtr.
1830 void emitPFPPostCopyUpdates(Address DestPtr, Address SrcPtr, QualType Ty);
1831
1832private:
1833 /// SwitchInsn - This is nearest current switch instruction. It is null if
1834 /// current context is not in a switch.
1835 llvm::SwitchInst *SwitchInsn = nullptr;
1836 /// The branch weights of SwitchInsn when doing instrumentation based PGO.
1837 SmallVector<uint64_t, 16> *SwitchWeights = nullptr;
1838
1839 /// The likelihood attributes of the SwitchCase.
1840 SmallVector<Stmt::Likelihood, 16> *SwitchLikelihood = nullptr;
1841
1842 /// CaseRangeBlock - This block holds if condition check for last case
1843 /// statement range in current switch instruction.
1844 llvm::BasicBlock *CaseRangeBlock = nullptr;
1845
1846 /// OpaqueLValues - Keeps track of the current set of opaque value
1847 /// expressions.
1848 llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
1849 llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;
1850
1851 // VLASizeMap - This keeps track of the associated size for each VLA type.
1852 // We track this by the size expression rather than the type itself because
1853 // in certain situations, like a const qualifier applied to an VLA typedef,
1854 // multiple VLA types can share the same size expression.
1855 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
1856 // enter/leave scopes.
1857 llvm::DenseMap<const Expr *, llvm::Value *> VLASizeMap;
1858
1859 /// A block containing a single 'unreachable' instruction. Created
1860 /// lazily by getUnreachableBlock().
1861 llvm::BasicBlock *UnreachableBlock = nullptr;
1862
1863 /// Counts of the number return expressions in the function.
1864 unsigned NumReturnExprs = 0;
1865
1866 /// Count the number of simple (constant) return expressions in the function.
1867 unsigned NumSimpleReturnExprs = 0;
1868
1869 /// The last regular (non-return) debug location (breakpoint) in the function.
1870 SourceLocation LastStopPoint;
1871
1872public:
1873 /// Source location information about the default argument or member
1874 /// initializer expression we're evaluating, if any.
1878
1879 /// A scope within which we are constructing the fields of an object which
1880 /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use
1881 /// if we need to evaluate a CXXDefaultInitExpr within the evaluation.
1883 public:
1884 FieldConstructionScope(CodeGenFunction &CGF, Address This)
1885 : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) {
1886 CGF.CXXDefaultInitExprThis = This;
1887 }
1889 CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis;
1890 }
1891
1892 private:
1893 CodeGenFunction &CGF;
1894 Address OldCXXDefaultInitExprThis;
1895 };
1896
1897 /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
1898 /// is overridden to be the object under construction.
1900 public:
1902 : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue),
1903 OldCXXThisAlignment(CGF.CXXThisAlignment),
1905 CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getBasePointer();
1906 CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment();
1907 }
1909 CGF.CXXThisValue = OldCXXThisValue;
1910 CGF.CXXThisAlignment = OldCXXThisAlignment;
1911 }
1912
1913 public:
1914 CodeGenFunction &CGF;
1915 llvm::Value *OldCXXThisValue;
1918 };
1919
1924
1925 /// The scope of an ArrayInitLoopExpr. Within this scope, the value of the
1926 /// current loop index is overridden.
1928 public:
1929 ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index)
1930 : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) {
1931 CGF.ArrayInitIndex = Index;
1932 }
1933 ~ArrayInitLoopExprScope() { CGF.ArrayInitIndex = OldArrayInitIndex; }
1934
1935 private:
1936 CodeGenFunction &CGF;
1937 llvm::Value *OldArrayInitIndex;
1938 };
1939
1941 public:
1943 : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl),
1944 OldCurCodeDecl(CGF.CurCodeDecl),
1945 OldCXXABIThisDecl(CGF.CXXABIThisDecl),
1946 OldCXXABIThisValue(CGF.CXXABIThisValue),
1947 OldCXXThisValue(CGF.CXXThisValue),
1948 OldCXXABIThisAlignment(CGF.CXXABIThisAlignment),
1949 OldCXXThisAlignment(CGF.CXXThisAlignment),
1950 OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy),
1951 OldCXXInheritedCtorInitExprArgs(
1952 std::move(CGF.CXXInheritedCtorInitExprArgs)) {
1953 CGF.CurGD = GD;
1954 CGF.CurFuncDecl = CGF.CurCodeDecl =
1956 CGF.CXXABIThisDecl = nullptr;
1957 CGF.CXXABIThisValue = nullptr;
1958 CGF.CXXThisValue = nullptr;
1959 CGF.CXXABIThisAlignment = CharUnits();
1960 CGF.CXXThisAlignment = CharUnits();
1961 CGF.ReturnValue = Address::invalid();
1962 CGF.FnRetTy = QualType();
1963 CGF.CXXInheritedCtorInitExprArgs.clear();
1964 }
1966 CGF.CurGD = OldCurGD;
1967 CGF.CurFuncDecl = OldCurFuncDecl;
1968 CGF.CurCodeDecl = OldCurCodeDecl;
1969 CGF.CXXABIThisDecl = OldCXXABIThisDecl;
1970 CGF.CXXABIThisValue = OldCXXABIThisValue;
1971 CGF.CXXThisValue = OldCXXThisValue;
1972 CGF.CXXABIThisAlignment = OldCXXABIThisAlignment;
1973 CGF.CXXThisAlignment = OldCXXThisAlignment;
1974 CGF.ReturnValue = OldReturnValue;
1975 CGF.FnRetTy = OldFnRetTy;
1976 CGF.CXXInheritedCtorInitExprArgs =
1977 std::move(OldCXXInheritedCtorInitExprArgs);
1978 }
1979
1980 private:
1981 CodeGenFunction &CGF;
1982 GlobalDecl OldCurGD;
1983 const Decl *OldCurFuncDecl;
1984 const Decl *OldCurCodeDecl;
1985 ImplicitParamDecl *OldCXXABIThisDecl;
1986 llvm::Value *OldCXXABIThisValue;
1987 llvm::Value *OldCXXThisValue;
1988 CharUnits OldCXXABIThisAlignment;
1989 CharUnits OldCXXThisAlignment;
1990 Address OldReturnValue;
1991 QualType OldFnRetTy;
1992 CallArgList OldCXXInheritedCtorInitExprArgs;
1993 };
1994
1995 // Helper class for the OpenMP IR Builder. Allows reusability of code used for
1996 // region body, and finalization codegen callbacks. This will class will also
1997 // contain privatization functions used by the privatization call backs
1998 //
1999 // TODO: this is temporary class for things that are being moved out of
2000 // CGOpenMPRuntime, new versions of current CodeGenFunction methods, or
2001 // utility function for use with the OMPBuilder. Once that move to use the
2002 // OMPBuilder is done, everything here will either become part of CodeGenFunc.
2003 // directly, or a new helper class that will contain functions used by both
2004 // this and the OMPBuilder
2005
2007
2011
2012 using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
2013
2014 /// Cleanup action for allocate support.
2015 class OMPAllocateCleanupTy final : public EHScopeStack::Cleanup {
2016
2017 private:
2018 llvm::CallInst *RTLFnCI;
2019
2020 public:
2021 OMPAllocateCleanupTy(llvm::CallInst *RLFnCI) : RTLFnCI(RLFnCI) {
2022 RLFnCI->removeFromParent();
2023 }
2024
2025 void Emit(CodeGenFunction &CGF, Flags /*flags*/) override {
2026 if (!CGF.HaveInsertPoint())
2027 return;
2028 CGF.Builder.Insert(RTLFnCI);
2029 }
2030 };
2031
2032 /// Returns address of the threadprivate variable for the current
2033 /// thread. This Also create any necessary OMP runtime calls.
2034 ///
2035 /// \param VD VarDecl for Threadprivate variable.
2036 /// \param VDAddr Address of the Vardecl
2037 /// \param Loc The location where the barrier directive was encountered
2038 static Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
2039 const VarDecl *VD, Address VDAddr,
2040 SourceLocation Loc);
2041
2042 /// Gets the OpenMP-specific address of the local variable /p VD.
2043 static Address getAddressOfLocalVariable(CodeGenFunction &CGF,
2044 const VarDecl *VD);
2045 /// Get the platform-specific name separator.
2046 /// \param Parts different parts of the final name that needs separation
2047 /// \param FirstSeparator First separator used between the initial two
2048 /// parts of the name.
2049 /// \param Separator separator used between all of the rest consecutinve
2050 /// parts of the name
2051 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
2052 StringRef FirstSeparator = ".",
2053 StringRef Separator = ".");
2054 /// Emit the Finalization for an OMP region
2055 /// \param CGF The Codegen function this belongs to
2056 /// \param IP Insertion point for generating the finalization code.
2057 static void FinalizeOMPRegion(CodeGenFunction &CGF, InsertPointTy IP) {
2058 CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
2059 llvm::BasicBlock *IPBB = IP.getNodeParent();
2060 assert(IPBB->end() != IP &&
2061 "OpenMP IR Builder should cause terminated block!");
2062
2063 llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
2064 assert(DestBB && "Finalization block should have one successor!");
2065
2066 // erase and replace with cleanup branch.
2067 IPBB->getTerminator()->eraseFromParent();
2068 CGF.Builder.SetInsertPoint(IPBB);
2070 CGF.EmitBranchThroughCleanup(Dest);
2071 }
2072
2073 /// Emit the body of an OMP region
2074 /// \param CGF The Codegen function this belongs to
2075 /// \param RegionBodyStmt The body statement for the OpenMP region being
2076 /// generated
2077 /// \param AllocaIP Where to insert alloca instructions
2078 /// \param CodeGenIP Where to insert the region code
2079 /// \param RegionName Name to be used for new blocks
2080 static void EmitOMPInlinedRegionBody(CodeGenFunction &CGF,
2081 const Stmt *RegionBodyStmt,
2082 InsertPointTy AllocaIP,
2083 InsertPointTy CodeGenIP,
2084 Twine RegionName);
2085
2086 static void EmitCaptureStmt(CodeGenFunction &CGF,
2087 llvm::BasicBlock *CodeGenIPBB,
2088 llvm::BasicBlock &FiniBB, llvm::Function *Fn,
2090 if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminatorOrNull())
2091 CodeGenIPBBTI->eraseFromParent();
2092
2093 CGF.Builder.SetInsertPoint(CodeGenIPBB);
2094
2095 if (Fn->doesNotThrow())
2096 CGF.EmitNounwindRuntimeCall(Fn, Args);
2097 else
2098 CGF.EmitRuntimeCall(Fn, Args);
2099
2100 if (CGF.Builder.saveIP().isValid())
2101 CGF.Builder.CreateBr(&FiniBB);
2102 }
2103
2104 /// Emit the body of an OMP region that will be outlined in
2105 /// OpenMPIRBuilder::finalize().
2106 /// \param CGF The Codegen function this belongs to
2107 /// \param RegionBodyStmt The body statement for the OpenMP region being
2108 /// generated
2109 /// \param AllocaIP Where to insert alloca instructions
2110 /// \param CodeGenIP Where to insert the region code
2111 /// \param RegionName Name to be used for new blocks
2112 static void EmitOMPOutlinedRegionBody(CodeGenFunction &CGF,
2113 const Stmt *RegionBodyStmt,
2114 InsertPointTy AllocaIP,
2115 InsertPointTy CodeGenIP,
2116 Twine RegionName);
2117
2118 /// RAII for preserving necessary info during Outlined region body codegen.
2120
2121 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
2122 CodeGenFunction::JumpDest OldReturnBlock;
2123 CodeGenFunction &CGF;
2124
2125 public:
2126 OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP,
2127 llvm::BasicBlock &RetBB)
2128 : CGF(cgf) {
2129 assert(AllocaIP.isValid() &&
2130 "Must specify Insertion point for allocas of outlined function");
2131 OldAllocaIP = CGF.AllocaInsertPt;
2132 CGF.AllocaInsertPt = &*AllocaIP;
2133
2134 OldReturnBlock = CGF.ReturnBlock;
2135 CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
2136 }
2137
2139 CGF.AllocaInsertPt = OldAllocaIP;
2140 CGF.ReturnBlock = OldReturnBlock;
2141 }
2142 };
2143
2144 /// RAII for preserving necessary info during inlined region body codegen.
2146
2147 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
2148 CodeGenFunction &CGF;
2149
2150 public:
2151 InlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP,
2152 llvm::BasicBlock &FiniBB)
2153 : CGF(cgf) {
2154 // Alloca insertion block should be in the entry block of the containing
2155 // function so it expects an empty AllocaIP in which case will reuse the
2156 // old alloca insertion point, or a new AllocaIP in the same block as
2157 // the old one
2158 assert((!AllocaIP.isValid() ||
2159 CGF.AllocaInsertPt->getParent() == AllocaIP.getNodeParent()) &&
2160 "Insertion point should be in the entry block of containing "
2161 "function!");
2162 OldAllocaIP = CGF.AllocaInsertPt;
2163 if (AllocaIP.isValid())
2164 CGF.AllocaInsertPt = &*AllocaIP;
2165
2166 // TODO: Remove the call, after making sure the counter is not used by
2167 // the EHStack.
2168 // Since this is an inlined region, it should not modify the
2169 // ReturnBlock, and should reuse the one for the enclosing outlined
2170 // region. So, the JumpDest being return by the function is discarded
2171 (void)CGF.getJumpDestInCurrentScope(&FiniBB);
2172 }
2173
2174 ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; }
2175 };
2176 };
2177
2178private:
2179 /// CXXThisDecl - When generating code for a C++ member function,
2180 /// this will hold the implicit 'this' declaration.
2181 ImplicitParamDecl *CXXABIThisDecl = nullptr;
2182 llvm::Value *CXXABIThisValue = nullptr;
2183 llvm::Value *CXXThisValue = nullptr;
2184 CharUnits CXXABIThisAlignment;
2185 CharUnits CXXThisAlignment;
2186
2187 /// The value of 'this' to use when evaluating CXXDefaultInitExprs within
2188 /// this expression.
2189 Address CXXDefaultInitExprThis = Address::invalid();
2190
2191 /// The current array initialization index when evaluating an
2192 /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
2193 llvm::Value *ArrayInitIndex = nullptr;
2194
2195 /// The values of function arguments to use when evaluating
2196 /// CXXInheritedCtorInitExprs within this context.
2197 CallArgList CXXInheritedCtorInitExprArgs;
2198
2199 /// CXXStructorImplicitParamDecl - When generating code for a constructor or
2200 /// destructor, this will hold the implicit argument (e.g. VTT).
2201 ImplicitParamDecl *CXXStructorImplicitParamDecl = nullptr;
2202 llvm::Value *CXXStructorImplicitParamValue = nullptr;
2203
2204 /// OutermostConditional - Points to the outermost active
2205 /// conditional control. This is used so that we know if a
2206 /// temporary should be destroyed conditionally.
2207 ConditionalEvaluation *OutermostConditional = nullptr;
2208
2209 /// The current lexical scope.
2210 LexicalScope *CurLexicalScope = nullptr;
2211
2212 /// The current source location that should be used for exception
2213 /// handling code.
2214 SourceLocation CurEHLocation;
2215
2216 /// BlockByrefInfos - For each __block variable, contains
2217 /// information about the layout of the variable.
2218 llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos;
2219
2220 /// Used by -fsanitize=nullability-return to determine whether the return
2221 /// value can be checked.
2222 llvm::Value *RetValNullabilityPrecondition = nullptr;
2223
2224 /// Check if -fsanitize=nullability-return instrumentation is required for
2225 /// this function.
2226 bool requiresReturnValueNullabilityCheck() const {
2227 return RetValNullabilityPrecondition;
2228 }
2229
2230 /// Used to store precise source locations for return statements by the
2231 /// runtime return value checks.
2232 Address ReturnLocation = Address::invalid();
2233
2234 /// Check if the return value of this function requires sanitization.
2235 bool requiresReturnValueCheck() const;
2236
2237 bool isInAllocaArgument(CGCXXABI &ABI, QualType Ty);
2238 bool hasInAllocaArg(const CXXMethodDecl *MD);
2239
2240 llvm::BasicBlock *TerminateLandingPad = nullptr;
2241 llvm::BasicBlock *TerminateHandler = nullptr;
2243
2244 /// Terminate funclets keyed by parent funclet pad.
2245 llvm::MapVector<llvm::Value *, llvm::BasicBlock *> TerminateFunclets;
2246
2247 /// Largest vector width used in ths function. Will be used to create a
2248 /// function attribute.
2249 unsigned LargestVectorWidth = 0;
2250
2251 /// True if we need emit the life-time markers. This is initially set in
2252 /// the constructor, but could be overwritten to true if this is a coroutine.
2253 bool ShouldEmitLifetimeMarkers;
2254
2255 /// Add OpenCL kernel arg metadata and the kernel attribute metadata to
2256 /// the function metadata.
2257 void EmitKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn);
2258
2259public:
2260 CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext = false);
2262
2263 CodeGenTypes &getTypes() const { return CGM.getTypes(); }
2264 ASTContext &getContext() const { return CGM.getContext(); }
2266 if (DisableDebugInfo)
2267 return nullptr;
2268 return DebugInfo;
2269 }
2270 void disableDebugInfo() { DisableDebugInfo = true; }
2271 void enableDebugInfo() { DisableDebugInfo = false; }
2272
2274 return CGM.getCodeGenOpts().OptimizationLevel == 0 &&
2275 !SanOpts.has(SanitizerKind::Thread);
2276 }
2277
2278 const LangOptions &getLangOpts() const { return CGM.getLangOpts(); }
2279
2280 /// Returns a pointer to the function's exception object and selector slot,
2281 /// which is assigned in every landing pad.
2284
2285 /// Returns the contents of the function's exception object and selector
2286 /// slots.
2287 llvm::Value *getExceptionFromSlot();
2288 llvm::Value *getSelectorFromSlot();
2289
2291
2292 llvm::BasicBlock *getUnreachableBlock() {
2293 if (!UnreachableBlock) {
2294 UnreachableBlock = createBasicBlock("unreachable");
2295 new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
2296 }
2297 return UnreachableBlock;
2298 }
2299
2300 llvm::BasicBlock *getInvokeDest() {
2301 if (!EHStack.requiresLandingPad())
2302 return nullptr;
2303 return getInvokeDestImpl();
2304 }
2305
2306 bool currentFunctionUsesSEHTry() const { return !!CurSEHParent; }
2307
2308 const TargetInfo &getTarget() const { return Target; }
2309 llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); }
2310
2311 /// Accessors for LocalDeclMap.
2312 DeclMapTy::iterator findLocalDecl(const Decl *D) {
2313 return LocalDeclMap.find(D);
2314 }
2315 DeclMapTy::iterator localDeclMapEnd() { return LocalDeclMap.end(); }
2316 std::pair<DeclMapTy::iterator, bool> insertLocalDecl(const Decl *D,
2317 Address Addr) {
2318 return LocalDeclMap.insert({D, Addr});
2319 }
2320 void eraseLocalDecl(const Decl *D) { LocalDeclMap.erase(D); }
2322 return CGM.getTargetCodeGenInfo();
2323 }
2324 const FunctionDecl *getCurrentFunctionDecl() const;
2325
2326 //===--------------------------------------------------------------------===//
2327 // Cleanups
2328 //===--------------------------------------------------------------------===//
2329
2330 typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty);
2331
2332 void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin,
2333 Address arrayEndPointer,
2334 QualType elementType,
2335 CharUnits elementAlignment,
2336 Destroyer *destroyer);
2337 void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
2338 llvm::Value *arrayEnd,
2339 QualType elementType,
2340 CharUnits elementAlignment,
2341 Destroyer *destroyer);
2342
2343 void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
2344 QualType type);
2346 QualType type);
2348 Destroyer *destroyer, bool useEHCleanupForArray);
2350 Address addr, QualType type);
2352 QualType type, Destroyer *destroyer,
2353 bool useEHCleanupForArray);
2355 QualType type, Destroyer *destroyer,
2356 bool useEHCleanupForArray);
2358 Address addr, QualType type);
2359 void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete,
2360 llvm::Value *CompletePtr,
2361 QualType ElementType);
2364 std::pair<llvm::Value *, llvm::Value *> AddrSizePair);
2365 void emitDestroy(Address addr, QualType type, Destroyer *destroyer,
2366 bool useEHCleanupForArray);
2367 llvm::Function *generateDestroyHelper(Address addr, QualType type,
2368 Destroyer *destroyer,
2369 bool useEHCleanupForArray,
2370 const VarDecl *VD);
2371 void emitArrayDestroy(llvm::Value *begin, llvm::Value *end,
2372 QualType elementType, CharUnits elementAlign,
2373 Destroyer *destroyer, bool checkZeroLength,
2374 bool useEHCleanup);
2375
2377
2378 /// Determines whether an EH cleanup is required to destroy a type
2379 /// with the given destruction kind.
2381 switch (kind) {
2382 case QualType::DK_none:
2383 return false;
2387 return getLangOpts().Exceptions;
2389 return getLangOpts().Exceptions &&
2390 CGM.getCodeGenOpts().ObjCAutoRefCountExceptions;
2391 }
2392 llvm_unreachable("bad destruction kind");
2393 }
2394
2398
2399 //===--------------------------------------------------------------------===//
2400 // Objective-C
2401 //===--------------------------------------------------------------------===//
2402
2403 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
2404
2405 void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD);
2406
2407 /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
2409 const ObjCPropertyImplDecl *PID);
2410 void generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
2411 const ObjCPropertyImplDecl *propImpl,
2412 const ObjCMethodDecl *GetterMothodDecl,
2413 llvm::Constant *AtomicHelperFn);
2414
2416 ObjCMethodDecl *MD, bool ctor);
2417
2418 /// GenerateObjCSetter - Synthesize an Objective-C property setter function
2419 /// for the given property.
2421 const ObjCPropertyImplDecl *PID);
2422 void generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
2423 const ObjCPropertyImplDecl *propImpl,
2424 llvm::Constant *AtomicHelperFn);
2425
2426 //===--------------------------------------------------------------------===//
2427 // Block Bits
2428 //===--------------------------------------------------------------------===//
2429
2430 /// Emit block literal.
2431 /// \return an LLVM value which is a pointer to a struct which contains
2432 /// information about the block, including the block invoke function, the
2433 /// captured variables, etc.
2434 llvm::Value *EmitBlockLiteral(const BlockExpr *);
2435
2436 llvm::Function *GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info,
2437 const DeclMapTy &ldm,
2438 bool IsLambdaConversionToBlock,
2439 bool BuildGlobalBlock);
2440
2441 /// Check if \p T is a C++ class that has a destructor that can throw.
2442 static bool cxxDestructorCanThrow(QualType T);
2443
2444 llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo);
2445 llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo);
2446 llvm::Constant *
2448 llvm::Constant *
2450 llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
2451
2452 void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags,
2453 bool CanThrow);
2454
2455 class AutoVarEmission;
2456
2457 void emitByrefStructureInit(const AutoVarEmission &emission);
2458
2459 /// Enter a cleanup to destroy a __block variable. Note that this
2460 /// cleanup should be a no-op if the variable hasn't left the stack
2461 /// yet; if a cleanup is required for the variable itself, that needs
2462 /// to be done externally.
2463 ///
2464 /// \param Kind Cleanup kind.
2465 ///
2466 /// \param Addr When \p LoadBlockVarAddr is false, the address of the __block
2467 /// structure that will be passed to _Block_object_dispose. When
2468 /// \p LoadBlockVarAddr is true, the address of the field of the block
2469 /// structure that holds the address of the __block structure.
2470 ///
2471 /// \param Flags The flag that will be passed to _Block_object_dispose.
2472 ///
2473 /// \param LoadBlockVarAddr Indicates whether we need to emit a load from
2474 /// \p Addr to get the address of the __block structure.
2476 bool LoadBlockVarAddr, bool CanThrow);
2477
2478 void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum,
2479 llvm::Value *ptr);
2480
2483
2484 /// BuildBlockByrefAddress - Computes the location of the
2485 /// data in a variable which is declared as __block.
2487 bool followForward = true);
2489 bool followForward, const llvm::Twine &name);
2490
2491 const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var);
2492
2494
2495 void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
2496 const CGFunctionInfo &FnInfo);
2497
2498 /// Annotate the function with an attribute that disables TSan checking at
2499 /// runtime.
2500 void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn);
2501
2502 /// Emit code for the start of a function.
2503 /// \param Loc The location to be associated with the function.
2504 /// \param StartLoc The location of the function body.
2505 void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn,
2506 const CGFunctionInfo &FnInfo, const FunctionArgList &Args,
2508 SourceLocation StartLoc = SourceLocation());
2509
2510 static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor);
2511
2515 void EmitFunctionBody(const Stmt *Body);
2516 void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S);
2517
2518 void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator,
2519 CallArgList &CallArgs,
2520 const CGFunctionInfo *CallOpFnInfo = nullptr,
2521 llvm::Constant *CallOpFn = nullptr);
2525 CallArgList &CallArgs);
2526 void EmitLambdaInAllocaImplFn(const CXXMethodDecl *CallOp,
2527 const CGFunctionInfo **ImplFnInfo,
2528 llvm::Function **ImplFn);
2531 EmitStoreThroughLValue(RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV);
2532 }
2533 void EmitAsanPrologueOrEpilogue(bool Prologue);
2534
2535 /// Emit the unified return block, trying to avoid its emission when
2536 /// possible.
2537 /// \return The debug location of the user written return statement if the
2538 /// return block is avoided.
2539 llvm::DebugLoc EmitReturnBlock();
2540
2541 /// FinishFunction - Complete IR generation of the current function. It is
2542 /// legal to call this function even if there is no current insertion point.
2544
2545 void StartThunk(llvm::Function *Fn, GlobalDecl GD,
2546 const CGFunctionInfo &FnInfo, bool IsUnprototyped);
2547
2548 void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
2549 const ThunkInfo *Thunk, bool IsUnprototyped);
2550
2551 void FinishThunk();
2552
2553 /// Start an Objective-C direct method thunk.
2555 llvm::Function *Fn,
2556 const CGFunctionInfo &FI);
2557
2558 /// Finish an Objective-C direct method thunk.
2560
2561 /// Emit a musttail call for a thunk with a potentially adjusted this pointer.
2562 void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr,
2563 llvm::FunctionCallee Callee);
2564
2565 /// Generate a thunk for the given method.
2566 void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
2567 GlobalDecl GD, const ThunkInfo &Thunk,
2568 bool IsUnprototyped);
2569
2570 llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn,
2571 const CGFunctionInfo &FnInfo,
2572 GlobalDecl GD, const ThunkInfo &Thunk);
2573
2575 FunctionArgList &Args);
2576
2577 void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init);
2578
2579 /// Struct with all information about dynamic [sub]class needed to set vptr.
2586
2587 /// Initialize the vtable pointer of the given subobject.
2588 void InitializeVTablePointer(const VPtr &vptr);
2589
2591
2593 VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass);
2594
2595 void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase,
2596 CharUnits OffsetFromNearestVBase,
2597 bool BaseIsNonVirtualPrimaryBase,
2598 const CXXRecordDecl *VTableClass,
2599 VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs);
2600
2601 void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
2602
2603 // VTableTrapMode - whether we guarantee that loading the
2604 // vtable is guaranteed to trap on authentication failure,
2605 // even if the resulting vtable pointer is unused.
2606 enum class VTableAuthMode {
2609 UnsafeUbsanStrip // Should only be used for Vptr UBSan check
2610 };
2611 /// GetVTablePtr - Return the Value of the vtable pointer member pointed
2612 /// to by This.
2613 llvm::Value *
2614 GetVTablePtr(Address This, llvm::Type *VTableTy,
2615 const CXXRecordDecl *VTableClass,
2617
2627
2628 /// Derived is the presumed address of an object of type T after a
2629 /// cast. If T is a polymorphic class type, emit a check that the virtual
2630 /// table for Derived belongs to a class derived from T.
2631 void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull,
2633
2634 /// EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
2635 /// If vptr CFI is enabled, emit a check that VTable is valid.
2636 void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable,
2638
2639 /// EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for
2640 /// RD using llvm.type.test.
2641 void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable,
2643
2644 /// Emit a CFI check failure handler or trap for a vtable type test result.
2645 void EmitVTableCheck(CFITypeCheckKind TCK, CanQualType T, llvm::Metadata *MD,
2646 llvm::Value *VTable, llvm::Value *TypeTest,
2647 SourceLocation Loc, bool UseCrossDsoSlowPath);
2648
2649 /// If whole-program virtual table optimization is enabled, emit an assumption
2650 /// that VTable is a member of RD's type identifier. Or, if vptr CFI is
2651 /// enabled, emit a check that VTable is a member of RD's type identifier.
2653 llvm::Value *VTable, SourceLocation Loc);
2654
2655 /// Returns whether we should perform a type checked load when loading a
2656 /// virtual function for virtual calls to members of RD. This is generally
2657 /// true when both vcall CFI and whole-program-vtables are enabled.
2659
2660 /// Emit a type checked load from the given vtable.
2661 llvm::Value *EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD,
2662 llvm::Value *VTable,
2663 llvm::Type *VTableTy,
2664 uint64_t VTableByteOffset,
2665 SourceLocation Loc);
2666
2667 /// EnterDtorCleanups - Enter the cleanups necessary to complete the
2668 /// given phase of destruction for a destructor. The end result
2669 /// should call destructors on members and base classes in reverse
2670 /// order of their construction.
2672
2673 /// ShouldInstrumentFunction - Return true if the current function should be
2674 /// instrumented with __cyg_profile_func_* calls
2676
2677 /// ShouldSkipSanitizerInstrumentation - Return true if the current function
2678 /// should not be instrumented with sanitizers.
2680
2681 /// ShouldXRayInstrument - Return true if the current function should be
2682 /// instrumented with XRay nop sleds.
2683 bool ShouldXRayInstrumentFunction() const;
2684
2685 /// AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit
2686 /// XRay custom event handling calls.
2687 bool AlwaysEmitXRayCustomEvents() const;
2688
2689 /// AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit
2690 /// XRay typed event handling calls.
2691 bool AlwaysEmitXRayTypedEvents() const;
2692
2693 /// Return a type hash constant for a function instrumented by
2694 /// -fsanitize=function.
2695 llvm::ConstantInt *getUBSanFunctionTypeHash(QualType T) const;
2696
2697 /// EmitFunctionProlog - Emit the target specific LLVM code to load the
2698 /// arguments for the given function. This is also responsible for naming the
2699 /// LLVM function arguments.
2700 void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn,
2701 const FunctionArgList &Args);
2702
2703 /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2704 /// given temporary. Specify the source location atom group (Key Instructions
2705 /// debug info feature) for the `ret` using \p RetKeyInstructionsSourceAtom.
2706 /// If it's 0, the `ret` will get added to a new source atom group.
2707 void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc,
2708 SourceLocation EndLoc,
2709 uint64_t RetKeyInstructionsSourceAtom);
2710
2711 /// Emit a test that checks if the return value \p RV is nonnull.
2712 void EmitReturnValueCheck(llvm::Value *RV);
2713
2714 /// EmitStartEHSpec - Emit the start of the exception spec.
2715 void EmitStartEHSpec(const Decl *D);
2716
2717 /// EmitEndEHSpec - Emit the end of the exception spec.
2718 void EmitEndEHSpec(const Decl *D);
2719
2720 /// getTerminateLandingPad - Return a landing pad that just calls terminate.
2721 llvm::BasicBlock *getTerminateLandingPad();
2722
2723 /// getTerminateLandingPad - Return a cleanup funclet that just calls
2724 /// terminate.
2725 llvm::BasicBlock *getTerminateFunclet();
2726
2727 /// getTerminateHandler - Return a handler (not a landing pad, just
2728 /// a catch handler) that just calls terminate. This is used when
2729 /// a terminate scope encloses a try.
2730 llvm::BasicBlock *getTerminateHandler();
2731
2732 llvm::Type *ConvertTypeForMem(QualType T);
2733 llvm::Type *ConvertType(QualType T);
2734 llvm::Type *convertTypeForLoadStore(QualType ASTTy,
2735 llvm::Type *LLVMTy = nullptr);
2736 llvm::Type *ConvertType(const TypeDecl *T) {
2737 return ConvertType(getContext().getTypeDeclType(T));
2738 }
2739
2740 /// LoadObjCSelf - Load the value of self. This function is only valid while
2741 /// generating code for an Objective-C method.
2742 llvm::Value *LoadObjCSelf();
2743
2744 /// TypeOfSelfObject - Return type of object that this self represents.
2746
2747 /// getEvaluationKind - Return the TypeEvaluationKind of QualType \c T.
2749
2751 return getEvaluationKind(T) == TEK_Scalar;
2752 }
2753
2757
2758 /// createBasicBlock - Create an LLVM basic block.
2759 llvm::BasicBlock *createBasicBlock(const Twine &name = "",
2760 llvm::Function *parent = nullptr,
2761 llvm::BasicBlock *before = nullptr) {
2762 return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before);
2763 }
2764
2765 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
2766 /// label maps to.
2767 JumpDest getJumpDestForLabel(const LabelDecl *S);
2768
2769 /// SimplifyForwardingBlocks - If the given basic block is only a branch to
2770 /// another basic block, simplify it. This assumes that no other code could
2771 /// potentially reference the basic block.
2772 void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
2773
2774 /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
2775 /// adding a fall-through branch from the current insert block if
2776 /// necessary. It is legal to call this function even if there is no current
2777 /// insertion point.
2778 ///
2779 /// IsFinished - If true, indicates that the caller has finished emitting
2780 /// branches to the given block and does not expect to emit code into it. This
2781 /// means the block can be ignored if it is unreachable.
2782 void EmitBlock(llvm::BasicBlock *BB, bool IsFinished = false);
2783
2784 /// EmitBlockAfterUses - Emit the given block somewhere hopefully
2785 /// near its uses, and leave the insertion point in it.
2786 void EmitBlockAfterUses(llvm::BasicBlock *BB);
2787
2788 /// EmitBranch - Emit a branch to the specified basic block from the current
2789 /// insert block, taking care to avoid creation of branches from dummy
2790 /// blocks. It is legal to call this function even if there is no current
2791 /// insertion point.
2792 ///
2793 /// This function clears the current insertion point. The caller should follow
2794 /// calls to this function with calls to Emit*Block prior to generation new
2795 /// code.
2796 void EmitBranch(llvm::BasicBlock *Block);
2797
2798 /// HaveInsertPoint - True if an insertion point is defined. If not, this
2799 /// indicates that the current code being emitted is unreachable.
2800 bool HaveInsertPoint() const { return Builder.GetInsertBlock() != nullptr; }
2801
2802 /// EnsureInsertPoint - Ensure that an insertion point is defined so that
2803 /// emitted IR has a place to go. Note that by definition, if this function
2804 /// creates a block then that block is unreachable; callers may do better to
2805 /// detect when no insertion point is defined and simply skip IR generation.
2807 if (!HaveInsertPoint())
2809 }
2810
2811 /// ErrorUnsupported - Print out an error that codegen doesn't support the
2812 /// specified stmt yet.
2813 void ErrorUnsupported(const Stmt *S, const char *Type);
2814
2815 //===--------------------------------------------------------------------===//
2816 // Helpers
2817 //===--------------------------------------------------------------------===//
2818
2820 llvm::BasicBlock *LHSBlock,
2821 llvm::BasicBlock *RHSBlock,
2822 llvm::BasicBlock *MergeBlock,
2823 QualType MergedType) {
2824 Builder.SetInsertPoint(MergeBlock);
2825 llvm::PHINode *PtrPhi = Builder.CreatePHI(LHS.getType(), 2, "cond");
2826 PtrPhi->addIncoming(LHS.getBasePointer(), LHSBlock);
2827 PtrPhi->addIncoming(RHS.getBasePointer(), RHSBlock);
2828 LHS.replaceBasePointer(PtrPhi);
2829 LHS.setAlignment(std::min(LHS.getAlignment(), RHS.getAlignment()));
2830 return LHS;
2831 }
2832
2833 /// Construct an address with the natural alignment of T. If a pointer to T
2834 /// is expected to be signed, the pointer passed to this function must have
2835 /// been signed, and the returned Address will have the pointer authentication
2836 /// information needed to authenticate the signed pointer.
2838 llvm::Value *Ptr, QualType T, CharUnits Alignment = CharUnits::Zero(),
2839 bool ForPointeeType = false, LValueBaseInfo *BaseInfo = nullptr,
2840 TBAAAccessInfo *TBAAInfo = nullptr,
2841 KnownNonNull_t IsKnownNonNull = NotKnownNonNull) {
2842 if (Alignment.isZero())
2843 Alignment =
2844 CGM.getNaturalTypeAlignment(T, BaseInfo, TBAAInfo, ForPointeeType);
2845 return Address(Ptr, ConvertTypeForMem(T), Alignment,
2846 CGM.getPointerAuthInfoForPointeeType(T), /*Offset=*/nullptr,
2847 IsKnownNonNull);
2848 }
2849
2852 return MakeAddrLValue(Addr, T, LValueBaseInfo(Source),
2853 CGM.getTBAAAccessInfo(T));
2854 }
2855
2857 TBAAAccessInfo TBAAInfo) {
2858 return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
2859 }
2860
2861 LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2863 return MakeAddrLValue(makeNaturalAddressForPointer(V, T, Alignment), T,
2864 LValueBaseInfo(Source), CGM.getTBAAAccessInfo(T));
2865 }
2866
2867 /// Same as MakeAddrLValue above except that the pointer is known to be
2868 /// unsigned.
2869 LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2871 Address Addr(V, ConvertTypeForMem(T), Alignment);
2872 return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
2873 CGM.getTBAAAccessInfo(T));
2874 }
2875
2876 LValue
2882
2883 /// Given a value of type T* that may not be to a complete object, construct
2884 /// an l-value with the natural pointee alignment of T.
2886
2887 LValue
2888 MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T,
2889 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
2890
2891 /// Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known
2892 /// to be unsigned.
2894
2896
2898 LValueBaseInfo *PointeeBaseInfo = nullptr,
2899 TBAAAccessInfo *PointeeTBAAInfo = nullptr);
2901 LValue
2904 LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source),
2905 CGM.getTBAAAccessInfo(RefTy));
2906 return EmitLoadOfReferenceLValue(RefLVal);
2907 }
2908
2909 /// Load a pointer with type \p PtrTy stored at address \p Ptr.
2910 /// Note that \p PtrTy is the type of the loaded pointer, not the addresses
2911 /// it is loaded from.
2912 Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
2913 LValueBaseInfo *BaseInfo = nullptr,
2914 TBAAAccessInfo *TBAAInfo = nullptr);
2916
2917private:
2918 struct AllocaTracker {
2919 void Add(llvm::AllocaInst *I) { Allocas.push_back(I); }
2920 llvm::SmallVector<llvm::AllocaInst *> Take() { return std::move(Allocas); }
2921
2922 private:
2924 };
2925 AllocaTracker *Allocas = nullptr;
2926
2927 /// CGDecl helper.
2928 void emitStoresForConstant(const VarDecl &D, Address Loc, bool isVolatile,
2929 llvm::Constant *constant, bool IsAutoInit);
2930 /// CGDecl helper.
2931 void emitStoresForZeroInit(const VarDecl &D, Address Loc, bool isVolatile);
2932 /// CGDecl helper.
2933 void emitStoresForPatternInit(const VarDecl &D, Address Loc, bool isVolatile);
2934 /// CGDecl helper.
2935 void emitStoresForInitAfterBZero(llvm::Constant *Init, Address Loc,
2936 bool isVolatile, bool IsAutoInit);
2937
2938public:
2939 // Captures all the allocas created during the scope of its RAII object.
2941 AllocaTrackerRAII(CodeGenFunction &CGF)
2942 : CGF(CGF), OldTracker(CGF.Allocas) {
2943 CGF.Allocas = &Tracker;
2944 }
2945 ~AllocaTrackerRAII() { CGF.Allocas = OldTracker; }
2946
2947 llvm::SmallVector<llvm::AllocaInst *> Take() { return Tracker.Take(); }
2948
2949 private:
2950 CodeGenFunction &CGF;
2951 AllocaTracker *OldTracker;
2952 AllocaTracker Tracker;
2953 };
2954
2955private:
2956 /// If \p Alloca is not in the same address space as \p DestLangAS, insert an
2957 /// address space cast and return a new RawAddress based on this value.
2958 RawAddress MaybeCastStackAddressSpace(RawAddress Alloca, LangAS DestLangAS,
2959 llvm::Value *ArraySize = nullptr);
2960
2961public:
2962 /// CreateTempAlloca - This creates an alloca and inserts it into the entry
2963 /// block if \p ArraySize is nullptr, otherwise inserts it at the current
2964 /// insertion point of the builder. The caller is responsible for setting an
2965 /// appropriate alignment on the alloca.
2966 ///
2967 /// \p ArraySize is the number of array elements to be allocated if it
2968 /// is not nullptr.
2969 ///
2970 /// LangAS::Default is the address space of pointers to local variables and
2971 /// temporaries, as exposed in the source language. In certain
2972 /// configurations, this is not the same as the alloca address space, and a
2973 /// cast is needed to lift the pointer from the alloca AS into
2974 /// LangAS::Default. This can happen when the target uses a restricted
2975 /// address space for the stack but the source language requires
2976 /// LangAS::Default to be a generic address space. The latter condition is
2977 /// common for most programming languages; OpenCL is an exception in that
2978 /// LangAS::Default is the private address space, which naturally maps
2979 /// to the stack.
2980 ///
2981 /// Because the address of a temporary is often exposed to the program in
2982 /// various ways, this function will perform the cast. The original alloca
2983 /// instruction is returned through \p Alloca if it is not nullptr.
2984 ///
2985 /// The cast is not performed in CreateTempAllocaWithoutCast. This is
2986 /// more efficient if the caller knows that the address will not be exposed.
2987 llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp",
2988 llvm::Value *ArraySize = nullptr);
2989
2990 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
2991 /// block. The alloca is casted to the address space of \p UseAddrSpace if
2992 /// necessary.
2993 RawAddress CreateTempAlloca(llvm::Type *Ty, LangAS UseAddrSpace,
2994 CharUnits align, const Twine &Name = "tmp",
2995 llvm::Value *ArraySize = nullptr,
2996 RawAddress *Alloca = nullptr);
2997
2998 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
2999 /// block. The alloca is casted to default address space if necessary.
3000 ///
3001 /// FIXME: This version should be removed, and context should provide the
3002 /// context use address space used instead of default.
3004 const Twine &Name = "tmp",
3005 llvm::Value *ArraySize = nullptr,
3006 RawAddress *Alloca = nullptr) {
3007 return CreateTempAlloca(Ty, LangAS::Default, align, Name, ArraySize,
3008 Alloca);
3009 }
3010
3011 RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align,
3012 const Twine &Name = "tmp",
3013 llvm::Value *ArraySize = nullptr);
3014
3015 /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
3016 /// default ABI alignment of the given LLVM type.
3017 ///
3018 /// IMPORTANT NOTE: This is *not* generally the right alignment for
3019 /// any given AST type that happens to have been lowered to the
3020 /// given IR type. This should only ever be used for function-local,
3021 /// IR-driven manipulations like saving and restoring a value. Do
3022 /// not hand this address off to arbitrary IRGen routines, and especially
3023 /// do not pass it as an argument to a function that might expect a
3024 /// properly ABI-aligned value.
3026 const Twine &Name = "tmp");
3027
3028 /// CreateIRTempWithoutCast - Create a temporary IR object of the given type,
3029 /// with appropriate alignment. This routine should only be used when an
3030 /// temporary value needs to be stored into an alloca (for example, to avoid
3031 /// explicit PHI construction), but the type is the IR type, not the type
3032 /// appropriate for storing in memory.
3033 ///
3034 /// That is, this is exactly equivalent to CreateMemTemp, but calling
3035 /// ConvertType instead of ConvertTypeForMem.
3036 RawAddress CreateIRTempWithoutCast(QualType T, const Twine &Name = "tmp");
3037
3038 /// CreateMemTemp - Create a temporary memory object of the given type, with
3039 /// appropriate alignmen and cast it to the default address space. Returns
3040 /// the original alloca instruction by \p Alloca if it is not nullptr.
3041 RawAddress CreateMemTemp(QualType T, const Twine &Name = "tmp",
3042 RawAddress *Alloca = nullptr);
3044 const Twine &Name = "tmp",
3045 RawAddress *Alloca = nullptr);
3046
3047 /// CreateMemTemp - Create a temporary memory object of the given type, with
3048 /// appropriate alignmen without casting it to the default address space.
3049 RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp");
3051 const Twine &Name = "tmp");
3052
3053 /// CreateAggTemp - Create a temporary memory object for the given
3054 /// aggregate type.
3055 AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp",
3056 RawAddress *Alloca = nullptr) {
3057 RawAddress Addr = CreateMemTemp(T, Name, Alloca);
3058 return AggValueSlot::forAddr(
3059 Addr, T.getQualifiers(), AggValueSlot::IsNotDestructed,
3062 }
3063
3064 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
3065 /// expression and compare the result against zero, returning an Int1Ty value.
3066 llvm::Value *EvaluateExprAsBool(const Expr *E);
3067
3068 /// Retrieve the implicit cast expression of the rhs in a binary operator
3069 /// expression by passing pointers to Value and QualType
3070 /// This is used for implicit bitfield conversion checks, which
3071 /// must compare with the value before potential truncation.
3073 llvm::Value **Previous,
3074 QualType *SrcType);
3075
3076 /// Emit a check that an [implicit] conversion of a bitfield. It is not UB,
3077 /// so we use the value after conversion.
3078 void EmitBitfieldConversionCheck(llvm::Value *Src, QualType SrcType,
3079 llvm::Value *Dst, QualType DstType,
3080 const CGBitFieldInfo &Info,
3081 SourceLocation Loc);
3082
3083 /// EmitIgnoredExpr - Emit an expression in a context which ignores the
3084 /// result.
3085 void EmitIgnoredExpr(const Expr *E);
3086
3087 /// EmitAnyExpr - Emit code to compute the specified expression which can have
3088 /// any type. The result is returned as an RValue struct. If this is an
3089 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
3090 /// the result should be returned.
3091 ///
3092 /// \param ignoreResult True if the resulting value isn't used.
3093 RValue EmitAnyExpr(const Expr *E,
3095 bool ignoreResult = false);
3096
3097 // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
3098 // or the value of the expression, depending on how va_list is defined.
3099 Address EmitVAListRef(const Expr *E);
3100
3101 /// Emit a "reference" to a __builtin_ms_va_list; this is
3102 /// always the value of the expression, because a __builtin_ms_va_list is a
3103 /// pointer to a char.
3104 Address EmitMSVAListRef(const Expr *E);
3105
3106 /// Emit a "reference" to a __builtin_zos_va_list; this is always the
3107 /// address of the expression, because a __builtin_zos_va_list is an
3108 /// array of pointer to a char.
3109 Address EmitZOSVAListRef(const Expr *E);
3110
3111 /// EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will
3112 /// always be accessible even if no aggregate location is provided.
3113 RValue EmitAnyExprToTemp(const Expr *E);
3114
3115 /// EmitAnyExprToMem - Emits the code necessary to evaluate an
3116 /// arbitrary expression into the given memory location.
3117 void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals,
3118 bool IsInitializer);
3119
3120 void EmitAnyExprToExn(const Expr *E, Address Addr);
3121
3122 /// EmitInitializationToLValue - Emit an initializer to an LValue.
3124 const Expr *E, LValue LV,
3126
3127 /// EmitExprAsInit - Emits the code necessary to initialize a
3128 /// location in memory with the given initializer.
3129 void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue,
3130 bool capturedByInit);
3131
3132 /// hasVolatileMember - returns true if aggregate type has a volatile
3133 /// member.
3135 if (const auto *RD = T->getAsRecordDecl())
3136 return RD->hasVolatileMember();
3137 return false;
3138 }
3139
3140 /// Determine whether a return value slot may overlap some other object.
3142 // FIXME: Assuming no overlap here breaks guaranteed copy elision for base
3143 // class subobjects. These cases may need to be revisited depending on the
3144 // resolution of the relevant core issue.
3146 }
3147
3148 /// Determine whether a field initialization may overlap some other object.
3150
3151 /// Determine whether a base class initialization may overlap some other
3152 /// object.
3154 const CXXRecordDecl *BaseRD,
3155 bool IsVirtual);
3156
3157 /// Emit an aggregate assignment.
3160 bool IsVolatile = hasVolatileMember(EltTy);
3161 EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
3162 }
3163
3165 AggValueSlot::Overlap_t MayOverlap) {
3166 EmitAggregateCopy(Dest, Src, Src.getType(), MayOverlap);
3167 }
3168
3169 /// EmitAggregateCopy - Emit an aggregate copy.
3170 ///
3171 /// \param isVolatile \c true iff either the source or the destination is
3172 /// volatile.
3173 /// \param MayOverlap Whether the tail padding of the destination might be
3174 /// occupied by some other object. More efficient code can often be
3175 /// generated if not.
3176 void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy,
3177 AggValueSlot::Overlap_t MayOverlap,
3178 bool isVolatile = false);
3179
3180 /// GetAddrOfLocalVar - Return the address of a local variable.
3182 auto it = LocalDeclMap.find(VD);
3183 assert(it != LocalDeclMap.end() &&
3184 "Invalid argument to GetAddrOfLocalVar(), no decl!");
3185 return it->second;
3186 }
3187
3188 /// Given an opaque value expression, return its LValue mapping if it exists,
3189 /// otherwise create one.
3191
3192 /// Given an opaque value expression, return its RValue mapping if it exists,
3193 /// otherwise create one.
3195
3196 /// isOpaqueValueEmitted - Return true if the opaque value expression has
3197 /// already been emitted.
3199
3200 /// Get the index of the current ArrayInitLoopExpr, if any.
3201 llvm::Value *getArrayInitIndex() { return ArrayInitIndex; }
3202
3203 /// getAccessedFieldNo - Given an encoded value and a result number, return
3204 /// the input field number being accessed.
3205 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
3206
3207 llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
3208 llvm::BasicBlock *GetIndirectGotoBlock();
3209
3210 /// Check if \p E is a C++ "this" pointer wrapped in value-preserving casts.
3211 static bool IsWrappedCXXThis(const Expr *E);
3212
3213 /// EmitNullInitialization - Generate code to set a value of the given type to
3214 /// null, If the type contains data member pointers, they will be initialized
3215 /// to -1 in accordance with the Itanium C++ ABI.
3216 void EmitNullInitialization(Address DestPtr, QualType Ty);
3217
3218 /// Emits a call to an LLVM variable-argument intrinsic, either
3219 /// \c llvm.va_start or \c llvm.va_end.
3220 /// \param ArgValue A reference to the \c va_list as emitted by either
3221 /// \c EmitVAListRef or \c EmitMSVAListRef.
3222 /// \param IsStart If \c true, emits a call to \c llvm.va_start; otherwise,
3223 /// calls \c llvm.va_end.
3224 llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart);
3225
3226 /// Generate code to get an argument from the passed in pointer
3227 /// and update it accordingly.
3228 /// \param VE The \c VAArgExpr for which to generate code.
3229 /// \param VAListAddr Receives a reference to the \c va_list as emitted by
3230 /// either \c EmitVAListRef or \c EmitMSVAListRef.
3231 /// \returns A pointer to the argument.
3232 // FIXME: We should be able to get rid of this method and use the va_arg
3233 // instruction in LLVM instead once it works well enough.
3234 RValue EmitVAArg(VAArgExpr *VE, Address &VAListAddr,
3236
3237 /// emitArrayLength - Compute the length of an array, even if it's a
3238 /// VLA, and drill down to the base element type.
3239 llvm::Value *emitArrayLength(const ArrayType *arrayType, QualType &baseType,
3240 Address &addr);
3241
3242 /// EmitVLASize - Capture all the sizes for the VLA expressions in
3243 /// the given variably-modified type and store them in the VLASizeMap.
3244 ///
3245 /// This function can be called with a null (unreachable) insert point.
3247
3249 llvm::Value *NumElts;
3251
3252 VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {}
3253 };
3254
3255 /// Return the number of elements for a single dimension
3256 /// for the given array type.
3257 VlaSizePair getVLAElements1D(const VariableArrayType *vla);
3258 VlaSizePair getVLAElements1D(QualType vla);
3259
3260 /// Returns an LLVM value that corresponds to the size,
3261 /// in non-variably-sized elements, of a variable length array type,
3262 /// plus that largest non-variably-sized element type. Assumes that
3263 /// the type has already been emitted with EmitVariablyModifiedType.
3264 VlaSizePair getVLASize(const VariableArrayType *vla);
3265 VlaSizePair getVLASize(QualType vla);
3266
3267 /// LoadCXXThis - Load the value of 'this'. This function is only valid while
3268 /// generating code for an C++ member function.
3269 llvm::Value *LoadCXXThis() {
3270 assert(CXXThisValue && "no 'this' value for this function");
3271 return CXXThisValue;
3272 }
3274
3275 /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
3276 /// virtual bases.
3277 // FIXME: Every place that calls LoadCXXVTT is something
3278 // that needs to be abstracted properly.
3279 llvm::Value *LoadCXXVTT() {
3280 assert(CXXStructorImplicitParamValue && "no VTT value for this function");
3281 return CXXStructorImplicitParamValue;
3282 }
3283
3284 /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
3285 /// complete class to the given direct base.
3287 const CXXRecordDecl *Derived,
3288 const CXXRecordDecl *Base,
3289 bool BaseIsVirtual);
3290
3291 static bool ShouldNullCheckClassCastValue(const CastExpr *Cast);
3292
3293 /// GetAddressOfBaseClass - This function will add the necessary delta to the
3294 /// load of 'this' and returns address of the base class.
3298 bool NullCheckValue, SourceLocation Loc);
3299
3303 bool NullCheckValue);
3304
3305 /// GetVTTParameter - Return the VTT parameter that should be passed to a
3306 /// base constructor/destructor with virtual bases.
3307 /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
3308 /// to ItaniumCXXABI.cpp together with all the references to VTT.
3309 llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase,
3310 bool Delegating);
3311
3313 CXXCtorType CtorType,
3314 const FunctionArgList &Args,
3315 SourceLocation Loc);
3316 // It's important not to confuse this and the previous function. Delegating
3317 // constructors are the C++0x feature. The constructor delegate optimization
3318 // is used to reduce duplication in the base and complete consturctors where
3319 // they are substantially the same.
3321 const FunctionArgList &Args);
3322
3323 /// Emit a call to an inheriting constructor (that is, one that invokes a
3324 /// constructor inherited from a base class) by inlining its definition. This
3325 /// is necessary if the ABI does not support forwarding the arguments to the
3326 /// base class constructor (because they're variadic or similar).
3328 CXXCtorType CtorType,
3329 bool ForVirtualBase,
3330 bool Delegating,
3331 CallArgList &Args);
3332
3333 /// Emit a call to a constructor inherited from a base class, passing the
3334 /// current constructor's arguments along unmodified (without even making
3335 /// a copy).
3337 bool ForVirtualBase, Address This,
3338 bool InheritedFromVBase,
3339 const CXXInheritedCtorInitExpr *E);
3340
3342 bool ForVirtualBase, bool Delegating,
3343 AggValueSlot ThisAVS, const CXXConstructExpr *E);
3344
3346 bool ForVirtualBase, bool Delegating,
3347 Address This, CallArgList &Args,
3349 SourceLocation Loc, bool NewPointerIsChecked,
3350 llvm::CallBase **CallOrInvoke = nullptr);
3351
3352 /// Emit assumption load for all bases. Requires to be called only on
3353 /// most-derived class and not under construction of the object.
3354 void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This);
3355
3356 /// Emit assumption that vptr load == global vtable.
3357 void EmitVTableAssumptionLoad(const VPtr &vptr, Address This);
3358
3360 Address Src, const CXXConstructExpr *E);
3361
3363 const ArrayType *ArrayTy, Address ArrayPtr,
3364 const CXXConstructExpr *E,
3365 bool NewPointerIsChecked,
3366 bool ZeroInitialization = false);
3367
3369 llvm::Value *NumElements, Address ArrayPtr,
3370 const CXXConstructExpr *E,
3371 bool NewPointerIsChecked,
3372 bool ZeroInitialization = false);
3373
3375
3377 bool ForVirtualBase, bool Delegating, Address This,
3378 QualType ThisTy);
3379
3380 void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
3381 llvm::Type *ElementTy, Address NewPtr,
3382 llvm::Value *NumElements,
3383 llvm::Value *AllocSizeWithoutCookie);
3384
3385 void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
3386 Address Ptr);
3387
3388 void EmitSehCppScopeBegin();
3389 void EmitSehCppScopeEnd();
3390 void EmitSehTryScopeBegin();
3391 void EmitSehTryScopeEnd();
3392
3393 bool EmitLifetimeStart(llvm::Value *Addr);
3394 void EmitLifetimeEnd(llvm::Value *Addr);
3395
3396 llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
3397 void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
3398
3399 void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
3400 QualType DeleteTy, llvm::Value *NumElements = nullptr,
3401 CharUnits CookieSize = CharUnits(),
3402 llvm::Constant *CalleeOverride = nullptr);
3403
3405 const CallExpr *TheCallExpr, bool IsDelete);
3406
3407 llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E);
3408 llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE);
3410
3411 /// Situations in which we might emit a check for the suitability of a
3412 /// pointer or glvalue. Needs to be kept in sync with ubsan_handlers.cpp in
3413 /// compiler-rt.
3415 /// Checking the operand of a load. Must be suitably sized and aligned.
3417 /// Checking the destination of a store. Must be suitably sized and aligned.
3419 /// Checking the bound value in a reference binding. Must be suitably sized
3420 /// and aligned, but is not required to refer to an object (until the
3421 /// reference is used), per core issue 453.
3423 /// Checking the object expression in a non-static data member access. Must
3424 /// be an object within its lifetime.
3426 /// Checking the 'this' pointer for a call to a non-static member function.
3427 /// Must be an object within its lifetime.
3429 /// Checking the 'this' pointer for a constructor call.
3431 /// Checking the operand of a static_cast to a derived pointer type. Must be
3432 /// null or an object within its lifetime.
3434 /// Checking the operand of a static_cast to a derived reference type. Must
3435 /// be an object within its lifetime.
3437 /// Checking the operand of a cast to a base object. Must be suitably sized
3438 /// and aligned.
3440 /// Checking the operand of a cast to a virtual base object. Must be an
3441 /// object within its lifetime.
3443 /// Checking the value assigned to a _Nonnull pointer. Must not be null.
3445 /// Checking the operand of a dynamic_cast or a typeid expression. Must be
3446 /// null or an object within its lifetime.
3448 };
3449
3450 /// Determine whether the pointer type check \p TCK permits null pointers.
3451 static bool isNullPointerAllowed(TypeCheckKind TCK);
3452
3453 /// Determine whether the pointer type check \p TCK requires a vptr check.
3454 static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty);
3455
3456 /// Whether any type-checking sanitizers are enabled. If \c false,
3457 /// calls to EmitTypeCheck can be skipped.
3458 bool sanitizePerformTypeCheck() const;
3459
3461 QualType Type, SanitizerSet SkippedChecks = SanitizerSet(),
3462 llvm::Value *ArraySize = nullptr) {
3464 return;
3465 EmitTypeCheck(TCK, Loc, LV.emitRawPointer(*this), Type, LV.getAlignment(),
3466 SkippedChecks, ArraySize);
3467 }
3468
3470 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3471 SanitizerSet SkippedChecks = SanitizerSet(),
3472 llvm::Value *ArraySize = nullptr) {
3474 return;
3475 EmitTypeCheck(TCK, Loc, Addr.emitRawPointer(*this), Type, Alignment,
3476 SkippedChecks, ArraySize);
3477 }
3478
3479 /// Emit a check that \p V is the address of storage of the
3480 /// appropriate size and alignment for an object of type \p Type
3481 /// (or if ArraySize is provided, for an array of that bound).
3482 void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V,
3483 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3484 SanitizerSet SkippedChecks = SanitizerSet(),
3485 llvm::Value *ArraySize = nullptr);
3486
3487 /// Emit a check that \p Base points into an array object, which
3488 /// we can access at index \p Index. \p Accessed should be \c false if we
3489 /// this expression is used as an lvalue, for instance in "&Arr[Idx]".
3490 void EmitBoundsCheck(const Expr *ArrayExpr, const Expr *ArrayExprBase,
3491 llvm::Value *Index, QualType IndexType, bool Accessed);
3492 void EmitBoundsCheckImpl(const Expr *ArrayExpr, QualType ArrayBaseType,
3493 llvm::Value *IndexVal, QualType IndexType,
3494 llvm::Value *BoundsVal, QualType BoundsType,
3495 bool Accessed);
3496
3497 /// Returns debug info, with additional annotation if
3498 /// CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[Ordinal] is enabled for
3499 /// any of the ordinals.
3500 llvm::DILocation *
3502 SanitizerHandler Handler);
3503
3504 /// Build metadata used by the AllocToken instrumentation.
3505 llvm::MDNode *buildAllocToken(QualType AllocType);
3506 /// Emit and set additional metadata used by the AllocToken instrumentation.
3507 void EmitAllocToken(llvm::CallBase *CB, QualType AllocType);
3508 /// Build additional metadata used by the AllocToken instrumentation,
3509 /// inferring the type from an allocation call expression.
3510 llvm::MDNode *buildAllocToken(const CallExpr *E);
3511 /// Emit and set additional metadata used by the AllocToken instrumentation,
3512 /// inferring the type from an allocation call expression.
3513 void EmitAllocToken(llvm::CallBase *CB, const CallExpr *E);
3514
3515 llvm::Value *GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD,
3516 const FieldDecl *CountDecl);
3517
3518 /// Build an expression accessing the "counted_by" field.
3519 llvm::Value *EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FD,
3520 const FieldDecl *CountDecl);
3521
3522 // Emit bounds checking for flexible array and pointer members with the
3523 // counted_by attribute.
3524 void EmitCountedByBoundsChecking(const Expr *ArrayExpr, QualType ArrayType,
3525 Address ArrayInst, QualType IndexType,
3526 llvm::Value *IndexVal, bool Accessed,
3527 bool FlexibleArray);
3528
3529 llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
3530 bool isInc, bool isPre);
3532 bool isInc, bool isPre);
3533
3534 /// Converts Location to a DebugLoc, if debug information is enabled.
3535 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
3536
3537 //===--------------------------------------------------------------------===//
3538 // Declaration Emission
3539 //===--------------------------------------------------------------------===//
3540
3541 /// EmitDecl - Emit a declaration.
3542 ///
3543 /// This function can be called with a null (unreachable) insert point.
3544 void EmitDecl(const Decl &D, bool EvaluateConditionDecl = false);
3545
3546 /// EmitVarDecl - Emit a local variable declaration.
3547 ///
3548 /// This function can be called with a null (unreachable) insert point.
3549 void EmitVarDecl(const VarDecl &D);
3550
3551 void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,
3552 bool capturedByInit);
3553
3554 typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
3555 llvm::Value *Address);
3556
3557 /// Determine whether the given initializer is trivial in the sense
3558 /// that it requires no code to be generated.
3559 bool isTrivialInitializer(const Expr *Init);
3560
3561 /// EmitAutoVarDecl - Emit an auto variable declaration.
3562 ///
3563 /// This function can be called with a null (unreachable) insert point.
3564 void EmitAutoVarDecl(const VarDecl &D);
3565
3566 class AutoVarEmission {
3567 friend class CodeGenFunction;
3568
3569 const VarDecl *Variable;
3570
3571 /// The address of the alloca for languages with explicit address space
3572 /// (e.g. OpenCL) or alloca casted to generic pointer for address space
3573 /// agnostic languages (e.g. C++). Invalid if the variable was emitted
3574 /// as a global constant.
3575 Address Addr;
3576
3577 llvm::Value *NRVOFlag;
3578
3579 /// True if the variable is a __block variable that is captured by an
3580 /// escaping block.
3581 bool IsEscapingByRef;
3582
3583 /// If the variable is of aggregate type and has a constant initializer,
3584 /// a constant representing that initializer.
3585 llvm::Constant *ConstantAggregateInitializer;
3586
3587 /// True if lifetime markers should be used.
3588 bool UseLifetimeMarkers;
3589
3590 /// Address with original alloca instruction. Invalid if the variable was
3591 /// emitted as a global constant.
3592 RawAddress AllocaAddr;
3593
3594 struct Invalid {};
3596 : Variable(nullptr), Addr(Address::invalid()),
3597 AllocaAddr(RawAddress::invalid()) {}
3598
3599 AutoVarEmission(const VarDecl &variable)
3600 : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
3601 IsEscapingByRef(false), ConstantAggregateInitializer(nullptr),
3602 UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
3603
3604 bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
3605
3606 public:
3607 static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
3608
3609 bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
3610
3611 /// Returns the raw, allocated address, which is not necessarily
3612 /// the address of the object itself. It is casted to default
3613 /// address space for address space agnostic languages.
3614 Address getAllocatedAddress() const { return Addr; }
3615
3616 /// Returns the address for the original alloca instruction.
3617 RawAddress getOriginalAllocatedAddress() const { return AllocaAddr; }
3618
3619 /// Returns the address of the object within this declaration.
3620 /// Note that this does not chase the forwarding pointer for
3621 /// __block decls.
3623 if (!IsEscapingByRef)
3624 return Addr;
3625
3626 return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false);
3627 }
3628 };
3629 AutoVarEmission EmitAutoVarAlloca(const VarDecl &var);
3630 void EmitAutoVarInit(const AutoVarEmission &emission);
3631 void EmitAutoVarCleanups(const AutoVarEmission &emission);
3632 void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
3633 QualType::DestructionKind dtorKind);
3634
3635 /// Re-emit trivial-auto-var-init stores for variables bypassed by the jump
3636 /// Source. No-op in a function containing a computed goto, where jump sources
3637 /// are unknown and a single function-scope init is used instead.
3638 void emitBypassedVarInitsForSource(const Stmt *Source);
3639
3640 void MaybeEmitDeferredVarDeclInit(const VarDecl *var);
3641
3642 /// Emits the alloca and debug information for the size expressions for each
3643 /// dimension of an array. It registers the association of its (1-dimensional)
3644 /// QualTypes and size expression's debug node, so that CGDebugInfo can
3645 /// reference this node when creating the DISubrange object to describe the
3646 /// array types.
3648 bool EmitDebugInfo);
3649
3650 void EmitStaticVarDecl(const VarDecl &D,
3651 llvm::GlobalValue::LinkageTypes Linkage);
3652
3653 class ParamValue {
3654 union {
3656 llvm::Value *Value;
3657 };
3658
3659 bool IsIndirect;
3660
3661 ParamValue(llvm::Value *V) : Value(V), IsIndirect(false) {}
3662 ParamValue(Address A) : Addr(A), IsIndirect(true) {}
3663
3664 public:
3665 static ParamValue forDirect(llvm::Value *value) {
3666 return ParamValue(value);
3667 }
3668 static ParamValue forIndirect(Address addr) {
3669 assert(!addr.getAlignment().isZero());
3670 return ParamValue(addr);
3671 }
3672
3673 bool isIndirect() const { return IsIndirect; }
3674 llvm::Value *getAnyValue() const {
3675 if (!isIndirect())
3676 return Value;
3677 assert(!Addr.hasOffset() && "unexpected offset");
3678 return Addr.getBasePointer();
3679 }
3680
3681 llvm::Value *getDirectValue() const {
3682 assert(!isIndirect());
3683 return Value;
3684 }
3685
3687 assert(isIndirect());
3688 return Addr;
3689 }
3690 };
3691
3692 /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
3693 void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo);
3694
3695 /// protectFromPeepholes - Protect a value that we're intending to
3696 /// store to the side, but which will probably be used later, from
3697 /// aggressive peepholing optimizations that might delete it.
3698 ///
3699 /// Pass the result to unprotectFromPeepholes to declare that
3700 /// protection is no longer required.
3701 ///
3702 /// There's no particular reason why this shouldn't apply to
3703 /// l-values, it's just that no existing peepholes work on pointers.
3704 PeepholeProtection protectFromPeepholes(RValue rvalue);
3705 void unprotectFromPeepholes(PeepholeProtection protection);
3706
3707 void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty,
3708 SourceLocation Loc,
3709 SourceLocation AssumptionLoc,
3710 llvm::Value *Alignment,
3711 llvm::Value *OffsetValue = nullptr);
3712
3713 void emitReturnAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty,
3714 SourceLocation AssumptionLoc,
3715 llvm::Value *Alignment,
3716 llvm::Value *OffsetValue = nullptr);
3717
3718 void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty,
3719 SourceLocation Loc, SourceLocation AssumptionLoc,
3720 llvm::Value *Alignment,
3721 llvm::Value *OffsetValue = nullptr);
3722
3723 void emitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E,
3724 SourceLocation AssumptionLoc,
3725 llvm::Value *Alignment,
3726 llvm::Value *OffsetValue = nullptr);
3727
3728 //===--------------------------------------------------------------------===//
3729 // Statement Emission
3730 //===--------------------------------------------------------------------===//
3731
3732 /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
3733 void EmitStopPoint(const Stmt *S);
3734
3735 /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
3736 /// this function even if there is no current insertion point.
3737 ///
3738 /// This function may clear the current insertion point; callers should use
3739 /// EnsureInsertPoint if they wish to subsequently generate code without first
3740 /// calling EmitBlock, EmitBranch, or EmitStmt.
3741 void EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs = {});
3742
3743 /// EmitSimpleStmt - Try to emit a "simple" statement which does not
3744 /// necessarily require an insertion point or debug information; typically
3745 /// because the statement amounts to a jump or a container of other
3746 /// statements.
3747 ///
3748 /// \return True if the statement was handled.
3749 bool EmitSimpleStmt(const Stmt *S, ArrayRef<const Attr *> Attrs);
3750
3751 Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
3752 AggValueSlot AVS = AggValueSlot::ignored());
3753 Address
3754 EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast = false,
3755 AggValueSlot AVS = AggValueSlot::ignored());
3756
3757 /// EmitLabel - Emit the block for the given label. It is legal to call this
3758 /// function even if there is no current insertion point.
3759 void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt.
3760
3761 void EmitLabelStmt(const LabelStmt &S);
3762 void EmitAttributedStmt(const AttributedStmt &S);
3763 void EmitGotoStmt(const GotoStmt &S);
3765 void EmitIfStmt(const IfStmt &S);
3766
3767 void EmitWhileStmt(const WhileStmt &S, ArrayRef<const Attr *> Attrs = {});
3768 void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = {});
3769 void EmitForStmt(const ForStmt &S, ArrayRef<const Attr *> Attrs = {});
3770 void EmitReturnStmt(const ReturnStmt &S);
3771 void EmitDeclStmt(const DeclStmt &S);
3772 void EmitBreakStmt(const BreakStmt &S);
3773 void EmitContinueStmt(const ContinueStmt &S);
3774 void EmitSwitchStmt(const SwitchStmt &S);
3775 void EmitDefaultStmt(const DefaultStmt &S, ArrayRef<const Attr *> Attrs);
3776 void EmitCaseStmt(const CaseStmt &S, ArrayRef<const Attr *> Attrs);
3777 void EmitCaseStmtRange(const CaseStmt &S, ArrayRef<const Attr *> Attrs);
3778 void EmitBPFRelocatedCaseStmt(const CaseStmt &S,
3779 ArrayRef<const Attr *> Attrs);
3780 void EmitDeferStmt(const DeferStmt &S);
3781 void EmitAsmStmt(const AsmStmt &S);
3782
3783 const BreakContinue *GetDestForLoopControlStmt(const LoopControlStmt &S);
3784
3785 void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
3786 void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
3787 void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
3788 void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
3789 void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S);
3790
3791 void EmitCoroutineBody(const CoroutineBodyStmt &S);
3792 void EmitCoreturnStmt(const CoreturnStmt &S);
3793 RValue EmitCoawaitExpr(const CoawaitExpr &E,
3794 AggValueSlot aggSlot = AggValueSlot::ignored(),
3795 bool ignoreResult = false);
3796 LValue EmitCoawaitLValue(const CoawaitExpr *E);
3797 RValue EmitCoyieldExpr(const CoyieldExpr &E,
3798 AggValueSlot aggSlot = AggValueSlot::ignored(),
3799 bool ignoreResult = false);
3800 LValue EmitCoyieldLValue(const CoyieldExpr *E);
3801 RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID);
3802
3803 void EmitSYCLKernelCallStmt(const SYCLKernelCallStmt &S);
3804
3805 void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3806 void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3807
3808 void EmitCXXTryStmt(const CXXTryStmt &S);
3809 void EmitSEHTryStmt(const SEHTryStmt &S);
3810 void EmitSEHLeaveStmt(const SEHLeaveStmt &S);
3811 void EnterSEHTryStmt(const SEHTryStmt &S);
3812 void ExitSEHTryStmt(const SEHTryStmt &S);
3813 void VolatilizeTryBlocks(llvm::BasicBlock *BB,
3814 llvm::SmallPtrSet<llvm::BasicBlock *, 10> &V);
3815
3816 void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc);
3817 void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter,
3818 const Stmt *OutlinedStmt);
3819
3820 llvm::Function *GenerateSEHFilterFunction(CodeGenFunction &ParentCGF,
3821 const SEHExceptStmt &Except);
3822
3823 llvm::Function *GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF,
3824 const SEHFinallyStmt &Finally);
3825
3826 void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF,
3827 llvm::Value *ParentFP, llvm::Value *EntryEBP);
3828 llvm::Value *EmitSEHExceptionCode();
3829 llvm::Value *EmitSEHExceptionInfo();
3830 llvm::Value *EmitSEHAbnormalTermination();
3831
3832 /// Emit simple code for OpenMP directives in Simd-only mode.
3833 void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D);
3834
3835 /// Scan the outlined statement for captures from the parent function. For
3836 /// each capture, mark the capture as escaped and emit a call to
3837 /// llvm.localrecover. Insert the localrecover result into the LocalDeclMap.
3838 void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt,
3839 bool IsFilter);
3840
3841 /// Recovers the address of a local in a parent function. ParentVar is the
3842 /// address of the variable used in the immediate parent function. It can
3843 /// either be an alloca or a call to llvm.localrecover if there are nested
3844 /// outlined functions. ParentFP is the frame pointer of the outermost parent
3845 /// frame.
3847 Address ParentVar, llvm::Value *ParentFP);
3848
3849 void EmitCXXForRangeStmt(const CXXForRangeStmt &S,
3850 ArrayRef<const Attr *> Attrs = {});
3851
3852 void
3853 EmitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation &S);
3854
3855 /// Controls insertion of cancellation exit blocks in worksharing constructs.
3857 CodeGenFunction &CGF;
3858
3859 public:
3860 OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind,
3861 bool HasCancel)
3862 : CGF(CGF) {
3863 CGF.OMPCancelStack.enter(CGF, Kind, HasCancel);
3864 }
3865 ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); }
3866 };
3867
3868 /// Returns calculated size of the specified type.
3869 llvm::Value *getTypeSize(QualType Ty);
3871 llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K);
3872 llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S);
3874 llvm::Function *
3876 const OMPExecutableDirective &D);
3877 llvm::Function *
3879 const OMPExecutableDirective &D);
3881 SmallVectorImpl<llvm::Value *> &CapturedVars);
3882 void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy,
3883 SourceLocation Loc);
3884 /// Perform element by element copying of arrays with type \a
3885 /// OriginalType from \a SrcAddr to \a DestAddr using copying procedure
3886 /// generated by \a CopyGen.
3887 ///
3888 /// \param DestAddr Address of the destination array.
3889 /// \param SrcAddr Address of the source array.
3890 /// \param OriginalType Type of destination and source arrays.
3891 /// \param CopyGen Copying procedure that copies value of single array element
3892 /// to another single array element.
3894 Address DestAddr, Address SrcAddr, QualType OriginalType,
3895 const llvm::function_ref<void(Address, Address)> CopyGen);
3896 /// Emit proper copying of data from one variable to another.
3897 ///
3898 /// \param OriginalType Original type of the copied variables.
3899 /// \param DestAddr Destination address.
3900 /// \param SrcAddr Source address.
3901 /// \param DestVD Destination variable used in \a CopyExpr (for arrays, has
3902 /// type of the base array element).
3903 /// \param SrcVD Source variable used in \a CopyExpr (for arrays, has type of
3904 /// the base array element).
3905 /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a
3906 /// DestVD.
3907 void EmitOMPCopy(QualType OriginalType, Address DestAddr, Address SrcAddr,
3908 const VarDecl *DestVD, const VarDecl *SrcVD,
3909 const Expr *Copy);
3910 /// Emit atomic update code for constructs: \a X = \a X \a BO \a E or
3911 /// \a X = \a E \a BO \a E.
3912 ///
3913 /// \param X Value to be updated.
3914 /// \param E Update value.
3915 /// \param BO Binary operation for update operation.
3916 /// \param IsXLHSInRHSPart true if \a X is LHS in RHS part of the update
3917 /// expression, false otherwise.
3918 /// \param AO Atomic ordering of the generated atomic instructions.
3919 /// \param CommonGen Code generator for complex expressions that cannot be
3920 /// expressed through atomicrmw instruction.
3921 /// \returns <true, OldAtomicValue> if simple 'atomicrmw' instruction was
3922 /// generated, <false, RValue::get(nullptr)> otherwise.
3923 std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr(
3924 LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart,
3925 llvm::AtomicOrdering AO, SourceLocation Loc,
3926 const llvm::function_ref<RValue(RValue)> CommonGen);
3928 OMPPrivateScope &PrivateScope);
3930 OMPPrivateScope &PrivateScope);
3932 const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope,
3933 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3934 CaptureDeviceAddrMap);
3936 const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope,
3937 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3938 CaptureDeviceAddrMap);
3939 /// Emit code for copyin clause in \a D directive. The next code is
3940 /// generated at the start of outlined functions for directives:
3941 /// \code
3942 /// threadprivate_var1 = master_threadprivate_var1;
3943 /// operator=(threadprivate_var2, master_threadprivate_var2);
3944 /// ...
3945 /// __kmpc_barrier(&loc, global_tid);
3946 /// \endcode
3947 ///
3948 /// \param D OpenMP directive possibly with 'copyin' clause(s).
3949 /// \returns true if at least one copyin variable is found, false otherwise.
3951 /// Emit initial code for lastprivate variables. If some variable is
3952 /// not also firstprivate, then the default initialization is used. Otherwise
3953 /// initialization of this variable is performed by EmitOMPFirstprivateClause
3954 /// method.
3955 ///
3956 /// \param D Directive that may have 'lastprivate' directives.
3957 /// \param PrivateScope Private scope for capturing lastprivate variables for
3958 /// proper codegen in internal captured statement.
3959 ///
3960 /// \returns true if there is at least one lastprivate variable, false
3961 /// otherwise.
3963 OMPPrivateScope &PrivateScope);
3964 /// Emit final copying of lastprivate values to original variables at
3965 /// the end of the worksharing or simd directive.
3966 ///
3967 /// \param D Directive that has at least one 'lastprivate' directives.
3968 /// \param IsLastIterCond Boolean condition that must be set to 'i1 true' if
3969 /// it is the last iteration of the loop code in associated directive, or to
3970 /// 'i1 false' otherwise. If this item is nullptr, no final check is required.
3972 bool NoFinals,
3973 llvm::Value *IsLastIterCond = nullptr);
3974 /// Emit initial code for linear clauses.
3976 CodeGenFunction::OMPPrivateScope &PrivateScope);
3977 /// Emit final code for linear clauses.
3978 /// \param CondGen Optional conditional code for final part of codegen for
3979 /// linear clause.
3981 const OMPLoopDirective &D,
3982 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
3983 /// Emit initial code for reduction variables. Creates reduction copies
3984 /// and initializes them with the values according to OpenMP standard.
3985 ///
3986 /// \param D Directive (possibly) with the 'reduction' clause.
3987 /// \param PrivateScope Private scope for capturing reduction variables for
3988 /// proper codegen in internal captured statement.
3989 ///
3991 OMPPrivateScope &PrivateScope,
3992 bool ForInscan = false);
3993 /// Emit final update of reduction values to original variables at
3994 /// the end of the directive.
3995 ///
3996 /// \param D Directive that has at least one 'reduction' directives.
3997 /// \param ReductionKind The kind of reduction to perform.
3999 const OpenMPDirectiveKind ReductionKind);
4000 /// Emit initial code for linear variables. Creates private copies
4001 /// and initializes them with the values according to OpenMP standard.
4002 ///
4003 /// \param D Directive (possibly) with the 'linear' clause.
4004 /// \return true if at least one linear variable is found that should be
4005 /// initialized with the value of the original variable, false otherwise.
4007
4008 typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/,
4009 llvm::Function * /*OutlinedFn*/,
4010 const OMPTaskDataTy & /*Data*/)>
4013 const OpenMPDirectiveKind CapturedRegion,
4014 const RegionCodeGenTy &BodyGen,
4015 const TaskGenTy &TaskGen, OMPTaskDataTy &Data);
4031 const RegionCodeGenTy &BodyGen,
4032 OMPTargetDataInfo &InputInfo);
4034 CodeGenFunction &CGF, const CapturedStmt *CS,
4035 OMPPrivateScope &Scope);
4037 void EmitOMPParallelDirective(const OMPParallelDirective &S);
4047 void EmitOMPForDirective(const OMPForDirective &S);
4069 void
4071 void
4080 void
4083 void
4091 void
4093 void
4111 /// Also emits 'target loop'.
4114 void
4139
4140 /// Emit device code for the target directive.
4142 StringRef ParentName,
4143 const OMPTargetDirective &S);
4144 static void
4147 /// Emit device code for the target parallel for directive.
4149 CodeGenModule &CGM, StringRef ParentName,
4151 /// Emit device code for the target parallel for simd directive.
4153 CodeGenModule &CGM, StringRef ParentName,
4155 /// Emit device code for the target teams directive.
4156 static void
4157 EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName,
4158 const OMPTargetTeamsDirective &S);
4159 /// Emit device code for the target teams distribute directive.
4161 CodeGenModule &CGM, StringRef ParentName,
4163 /// Emit device code for the target teams distribute simd directive.
4165 CodeGenModule &CGM, StringRef ParentName,
4167 /// Emit device code for the target simd and target loop directives.
4169 StringRef ParentName,
4170 const OMPLoopDirective &S);
4171 /// Emit device code for the target teams distribute parallel for simd
4172 /// directive.
4174 CodeGenModule &CGM, StringRef ParentName,
4176
4177 /// Emit device code for the target teams loop directive.
4179 CodeGenModule &CGM, StringRef ParentName,
4181
4182 /// Emit device code for the target parallel loop directive.
4184 CodeGenModule &CGM, StringRef ParentName,
4186
4188 CodeGenModule &CGM, StringRef ParentName,
4190
4191 /// Emit the Stmt \p S and return its topmost canonical loop, if any.
4192 /// TODO: The \p Depth paramter is not yet implemented and must be 1. In the
4193 /// future it is meant to be the number of loops expected in the loop nests
4194 /// (usually specified by the "collapse" clause) that are collapsed to a
4195 /// single loop by this function.
4196 llvm::CanonicalLoopInfo *EmitOMPCollapsedCanonicalLoopNest(const Stmt *S,
4197 int Depth);
4198
4199 /// Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
4200 void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S);
4201
4202 /// Emit inner loop of the worksharing/simd construct.
4203 ///
4204 /// \param S Directive, for which the inner loop must be emitted.
4205 /// \param RequiresCleanup true, if directive has some associated private
4206 /// variables.
4207 /// \param LoopCond Bollean condition for loop continuation.
4208 /// \param IncExpr Increment expression for loop control variable.
4209 /// \param BodyGen Generator for the inner body of the inner loop.
4210 /// \param PostIncGen Genrator for post-increment code (required for ordered
4211 /// loop directvies).
4212 void EmitOMPInnerLoop(
4213 const OMPExecutableDirective &S, bool RequiresCleanup,
4214 const Expr *LoopCond, const Expr *IncExpr,
4215 const llvm::function_ref<void(CodeGenFunction &)> BodyGen,
4216 const llvm::function_ref<void(CodeGenFunction &)> PostIncGen);
4217
4219 /// Emit initial code for loop counters of loop-based directives.
4221 OMPPrivateScope &LoopScope);
4222
4223 /// Helper for the OpenMP loop directives.
4224 void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit);
4225
4226 /// Emit code for the worksharing loop-based directive.
4227 /// \return true, if this construct has any lastprivate clause, false -
4228 /// otherwise.
4229 bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB,
4230 const CodeGenLoopBoundsTy &CodeGenLoopBounds,
4231 const CodeGenDispatchBoundsTy &CGDispatchBounds);
4232
4233 /// Emit code for the distribute loop-based directive.
4235 const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr);
4236
4237 /// Helpers for the OpenMP loop directives.
4238 void EmitOMPSimdInit(const OMPLoopDirective &D);
4239 void EmitOMPSimdFinal(
4240 const OMPLoopDirective &D,
4241 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
4242
4243 /// Emits the lvalue for the expression with possibly captured variable.
4245
4246 /// Emits the original address for a structured binding.
4248
4249private:
4250 /// Helpers for blocks.
4251 llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info);
4252
4253 /// struct with the values to be passed to the OpenMP loop-related functions
4254 struct OMPLoopArguments {
4255 /// loop lower bound
4257 /// loop upper bound
4259 /// loop stride
4261 /// isLastIteration argument for runtime functions
4263 /// Chunk value generated by sema
4264 llvm::Value *Chunk = nullptr;
4265 /// EnsureUpperBound
4266 Expr *EUB = nullptr;
4267 /// IncrementExpression
4268 Expr *IncExpr = nullptr;
4269 /// Loop initialization
4270 Expr *Init = nullptr;
4271 /// Loop exit condition
4272 Expr *Cond = nullptr;
4273 /// Update of LB after a whole chunk has been executed
4274 Expr *NextLB = nullptr;
4275 /// Update of UB after a whole chunk has been executed
4276 Expr *NextUB = nullptr;
4277 /// Distinguish between the for distribute and sections
4278 OpenMPDirectiveKind DKind = llvm::omp::OMPD_unknown;
4279 OMPLoopArguments() = default;
4280 OMPLoopArguments(Address LB, Address UB, Address ST, Address IL,
4281 llvm::Value *Chunk = nullptr, Expr *EUB = nullptr,
4282 Expr *IncExpr = nullptr, Expr *Init = nullptr,
4283 Expr *Cond = nullptr, Expr *NextLB = nullptr,
4284 Expr *NextUB = nullptr)
4285 : LB(LB), UB(UB), ST(ST), IL(IL), Chunk(Chunk), EUB(EUB),
4286 IncExpr(IncExpr), Init(Init), Cond(Cond), NextLB(NextLB),
4287 NextUB(NextUB) {}
4288 };
4289 void EmitOMPOuterLoop(bool DynamicOrOrdered, bool IsMonotonic,
4290 const OMPLoopDirective &S, OMPPrivateScope &LoopScope,
4291 const OMPLoopArguments &LoopArgs,
4292 const CodeGenLoopTy &CodeGenLoop,
4293 const CodeGenOrderedTy &CodeGenOrdered);
4294 void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind,
4295 bool IsMonotonic, const OMPLoopDirective &S,
4296 OMPPrivateScope &LoopScope, bool Ordered,
4297 const OMPLoopArguments &LoopArgs,
4298 const CodeGenDispatchBoundsTy &CGDispatchBounds);
4299 void EmitOMPDistributeOuterLoop(OpenMPDistScheduleClauseKind ScheduleKind,
4300 const OMPLoopDirective &S,
4301 OMPPrivateScope &LoopScope,
4302 const OMPLoopArguments &LoopArgs,
4303 const CodeGenLoopTy &CodeGenLoopContent);
4304 /// Emit code for sections directive.
4305 void EmitSections(const OMPExecutableDirective &S);
4306
4307public:
4308 //===--------------------------------------------------------------------===//
4309 // OpenACC Emission
4310 //===--------------------------------------------------------------------===//
4312 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4313 // simply emitting its structured block, but in the future we will implement
4314 // some sort of IR.
4315 if (S.getStructuredBlock())
4316 EmitStmt(S.getStructuredBlock());
4317 }
4318
4320 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4321 // simply emitting its loop, but in the future we will implement
4322 // some sort of IR.
4323 if (S.getLoop())
4324 EmitStmt(S.getLoop());
4325 }
4326
4328 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4329 // simply emitting its loop, but in the future we will implement
4330 // some sort of IR.
4331 if (S.getLoop())
4332 EmitStmt(S.getLoop());
4333 }
4334
4336 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4337 // simply emitting its structured block, but in the future we will implement
4338 // some sort of IR.
4339 if (S.getStructuredBlock())
4341 }
4342
4344 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4345 // but in the future we will implement some sort of IR.
4346 }
4347
4349 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4350 // but in the future we will implement some sort of IR.
4351 }
4352
4354 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4355 // simply emitting its structured block, but in the future we will implement
4356 // some sort of IR.
4357 if (S.getStructuredBlock())
4359 }
4360
4362 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4363 // but in the future we will implement some sort of IR.
4364 }
4365
4367 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4368 // but in the future we will implement some sort of IR.
4369 }
4370
4372 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4373 // but in the future we will implement some sort of IR.
4374 }
4375
4377 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4378 // but in the future we will implement some sort of IR.
4379 }
4380
4382 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4383 // but in the future we will implement some sort of IR.
4384 }
4385
4387 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4388 // simply emitting its associated stmt, but in the future we will implement
4389 // some sort of IR.
4390 if (S.getAssociatedStmt())
4392 }
4394 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4395 // but in the future we will implement some sort of IR.
4396 }
4397
4398 //===--------------------------------------------------------------------===//
4399 // LValue Expression Emission
4400 //===--------------------------------------------------------------------===//
4401
4402 /// Create a check that a scalar RValue is non-null.
4403 llvm::Value *EmitNonNullRValueCheck(RValue RV, QualType T);
4404
4405 /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
4407
4408 /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
4409 /// and issue an ErrorUnsupported style diagnostic (using the
4410 /// provided Name).
4411 RValue EmitUnsupportedRValue(const Expr *E, const char *Name);
4412
4413 /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
4414 /// an ErrorUnsupported style diagnostic (using the provided Name).
4415 LValue EmitUnsupportedLValue(const Expr *E, const char *Name);
4416
4417 /// EmitLValue - Emit code to compute a designator that specifies the location
4418 /// of the expression.
4419 ///
4420 /// This can return one of two things: a simple address or a bitfield
4421 /// reference. In either case, the LLVM Value* in the LValue structure is
4422 /// guaranteed to be an LLVM pointer type.
4423 ///
4424 /// If this returns a bitfield reference, nothing about the pointee type of
4425 /// the LLVM value is known: For example, it may not be a pointer to an
4426 /// integer.
4427 ///
4428 /// If this returns a normal address, and if the lvalue's C type is fixed
4429 /// size, this method guarantees that the returned pointer type will point to
4430 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
4431 /// variable length type, this is not possible.
4432 ///
4433 LValue EmitLValue(const Expr *E,
4434 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
4435
4436private:
4437 LValue EmitLValueHelper(const Expr *E, KnownNonNull_t IsKnownNonNull);
4438
4439public:
4440 /// Same as EmitLValue but additionally we generate checking code to
4441 /// guard against undefined behavior. This is only suitable when we know
4442 /// that the address will be used to access the object.
4444
4446
4447 void EmitAtomicInit(Expr *E, LValue lvalue);
4448
4450
4453
4455 llvm::AtomicOrdering AO, bool IsVolatile = false,
4457
4458 void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit);
4459
4460 void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO,
4461 bool IsVolatile, bool isInit);
4462
4463 std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange(
4464 LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc,
4465 llvm::AtomicOrdering Success =
4466 llvm::AtomicOrdering::SequentiallyConsistent,
4467 llvm::AtomicOrdering Failure =
4468 llvm::AtomicOrdering::SequentiallyConsistent,
4469 bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored());
4470
4471 /// Emit an atomicrmw instruction, and applying relevant metadata when
4472 /// applicable.
4473 llvm::AtomicRMWInst *emitAtomicRMWInst(
4474 llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val,
4475 llvm::AtomicOrdering Order = llvm::AtomicOrdering::SequentiallyConsistent,
4476 llvm::SyncScope::ID SSID = llvm::SyncScope::System,
4477 const AtomicExpr *AE = nullptr);
4478
4479 /// Emit a fence instruction, applying relevant target-specific metadata when
4480 /// applicable.
4481 llvm::FenceInst *
4482 emitAtomicFence(llvm::AtomicOrdering Order,
4483 llvm::SyncScope::ID SSID = llvm::SyncScope::System);
4484
4485 void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO,
4486 const llvm::function_ref<RValue(RValue)> &UpdateOp,
4487 bool IsVolatile);
4488
4489 /// EmitToMemory - Change a scalar value from its value
4490 /// representation to its in-memory representation.
4491 llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty);
4492
4493 /// EmitFromMemory - Change a scalar value from its memory
4494 /// representation to its value representation.
4495 llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty);
4496
4497 /// Check if the scalar \p Value is within the valid range for the given
4498 /// type \p Ty.
4499 ///
4500 /// Returns true if a check is needed (even if the range is unknown).
4501 bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
4502 SourceLocation Loc);
4503
4504 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4505 /// care to appropriately convert from the memory representation to
4506 /// the LLVM value representation.
4507 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4508 SourceLocation Loc,
4510 bool isNontemporal = false) {
4511 return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source),
4512 CGM.getTBAAAccessInfo(Ty), isNontemporal);
4513 }
4514
4515 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4516 SourceLocation Loc, LValueBaseInfo BaseInfo,
4517 TBAAAccessInfo TBAAInfo,
4518 bool isNontemporal = false);
4519
4520 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4521 /// care to appropriately convert from the memory representation to
4522 /// the LLVM value representation. The l-value must be a simple
4523 /// l-value.
4524 llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc);
4525
4526 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4527 /// care to appropriately convert from the memory representation to
4528 /// the LLVM value representation.
4529 void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile,
4530 QualType Ty,
4532 bool isInit = false, bool isNontemporal = false) {
4533 EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source),
4534 CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
4535 }
4536
4537 void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile,
4538 QualType Ty, LValueBaseInfo BaseInfo,
4539 TBAAAccessInfo TBAAInfo, bool isInit = false,
4540 bool isNontemporal = false);
4541
4542 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4543 /// care to appropriately convert from the memory representation to
4544 /// the LLVM value representation. The l-value must be a simple
4545 /// l-value. The isInit flag indicates whether this is an initialization.
4546 /// If so, atomic qualifiers are ignored and the store is always non-atomic.
4547 void EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
4548 bool isInit = false);
4549
4550 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
4551 /// this method emits the address of the lvalue, then loads the result as an
4552 /// rvalue, returning the rvalue.
4557
4558 /// Like EmitLoadOfLValue but also handles complex and aggregate types.
4561 SourceLocation Loc = {});
4562
4563 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
4564 /// lvalue, where both are guaranteed to the have the same type, and that type
4565 /// is 'Ty'.
4566 void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false);
4567 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);
4568 void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst);
4569
4570 /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints
4571 /// as EmitStoreThroughLValue.
4572 ///
4573 /// \param Result [out] - If non-null, this will be set to a Value* for the
4574 /// bit-field contents after the store, appropriate for use as the result of
4575 /// an assignment to the bit-field.
4576 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
4577 llvm::Value **Result = nullptr);
4578
4579 /// Emit an l-value for an assignment (simple or compound) of complex type.
4583 llvm::Value *&Result);
4584
4585 // Note: only available for agg return types
4588 // Note: only available for agg return types
4589 LValue EmitCallExprLValue(const CallExpr *E,
4590 llvm::CallBase **CallOrInvoke = nullptr);
4591 // Note: only available for agg return types
4592 LValue EmitVAArgExprLValue(const VAArgExpr *E);
4593 LValue EmitDeclRefLValue(const DeclRefExpr *E);
4594 LValue EmitOMPCapturedBindingLValue(const BindingDecl *BD);
4595 LValue EmitStringLiteralLValue(const StringLiteral *E);
4597 LValue EmitPredefinedLValue(const PredefinedExpr *E);
4598 LValue EmitUnaryOpLValue(const UnaryOperator *E);
4600 bool Accessed = false);
4601 llvm::Value *EmitMatrixIndexExpr(const Expr *E);
4604 LValue EmitArraySectionExpr(const ArraySectionExpr *E,
4605 bool IsLowerBound = true);
4608 LValue EmitMemberExpr(const MemberExpr *E);
4609 LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
4611 LValue EmitInitListLValue(const InitListExpr *E);
4614 LValue EmitCastLValue(const CastExpr *E);
4616 LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e);
4618
4619 std::pair<LValue, LValue> EmitHLSLOutArgLValues(const HLSLOutArgExpr *E,
4620 QualType Ty);
4621 LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args,
4622 QualType Ty, bool IsImplicitObject = false);
4623
4624 Address EmitExtVectorElementLValue(LValue V);
4625
4626 RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);
4627
4628 Address EmitArrayToPointerDecay(const Expr *Array,
4629 LValueBaseInfo *BaseInfo = nullptr,
4630 TBAAAccessInfo *TBAAInfo = nullptr);
4631
4632 class ConstantEmission {
4633 llvm::PointerIntPair<llvm::Constant *, 1, bool> ValueAndIsReference;
4634 ConstantEmission(llvm::Constant *C, bool isReference)
4635 : ValueAndIsReference(C, isReference) {}
4636
4637 public:
4639 static ConstantEmission forReference(llvm::Constant *C) {
4640 return ConstantEmission(C, true);
4641 }
4642 static ConstantEmission forValue(llvm::Constant *C) {
4643 return ConstantEmission(C, false);
4644 }
4645
4646 explicit operator bool() const {
4647 return ValueAndIsReference.getOpaqueValue() != nullptr;
4648 }
4649
4650 bool isReference() const { return ValueAndIsReference.getInt(); }
4651 LValue getReferenceLValue(CodeGenFunction &CGF, const Expr *RefExpr) const {
4652 assert(isReference());
4653 return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
4654 RefExpr->getType());
4655 }
4656
4657 llvm::Constant *getValue() const {
4658 assert(!isReference());
4659 return ValueAndIsReference.getPointer();
4660 }
4661 };
4662
4663 ConstantEmission tryEmitAsConstant(const DeclRefExpr *RefExpr);
4664 ConstantEmission tryEmitAsConstant(const MemberExpr *ME);
4665 llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E);
4666
4670
4672 SmallVectorImpl<LValue> &AccessList);
4673
4674 llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
4675 const ObjCIvarDecl *Ivar);
4677 const ObjCIvarDecl *Ivar);
4679 bool IsInBounds = true);
4682 llvm::Value *ThisValue);
4683
4684 /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
4685 /// if the Field is a reference, this will return the address of the reference
4686 /// and not the address of the value stored in the reference.
4688
4689 LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base,
4690 const ObjCIvarDecl *Ivar, unsigned CVRQualifiers);
4691
4696
4702 void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init);
4703
4704 //===--------------------------------------------------------------------===//
4705 // Scalar Expression Emission
4706 //===--------------------------------------------------------------------===//
4707
4708 /// EmitCall - Generate a call of the given function, expecting the given
4709 /// result type, and using the given argument list which specifies both the
4710 /// LLVM arguments and the types they were derived from.
4711 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4713 llvm::CallBase **CallOrInvoke, bool IsMustTail,
4714 SourceLocation Loc,
4715 bool IsVirtualFunctionPointerThunk = false);
4716 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4718 llvm::CallBase **CallOrInvoke = nullptr,
4719 bool IsMustTail = false) {
4720 return EmitCall(CallInfo, Callee, ReturnValue, Args, CallOrInvoke,
4721 IsMustTail, SourceLocation());
4722 }
4723 RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E,
4724 ReturnValueSlot ReturnValue, llvm::Value *Chain = nullptr,
4725 llvm::CallBase **CallOrInvoke = nullptr,
4726 CGFunctionInfo const **ResolvedFnInfo = nullptr);
4727
4728 // If a Call or Invoke instruction was emitted for this CallExpr, this method
4729 // writes the pointer to `CallOrInvoke` if it's not null.
4730 RValue EmitCallExpr(const CallExpr *E,
4732 llvm::CallBase **CallOrInvoke = nullptr);
4734 llvm::CallBase **CallOrInvoke = nullptr);
4735 CGCallee EmitCallee(const Expr *E);
4736
4737 void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl);
4738 void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl);
4739
4740 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4741 const Twine &name = "");
4742 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4744 const Twine &name = "",
4745 bool IsConvergent = false);
4746 llvm::CallInst *EmitIntrinsicCall(llvm::Intrinsic::ID ID,
4747 const Twine &Name = "");
4748 llvm::CallInst *EmitIntrinsicCall(llvm::Intrinsic::ID ID,
4750 const Twine &Name = "");
4751 llvm::CallInst *EmitIntrinsicCall(llvm::Intrinsic::ID ID,
4754 const Twine &Name = "");
4755 llvm::CallInst *EmitIntrinsicCall(llvm::Intrinsic::ID ID,
4757 llvm::Type *RetTy, const Twine &Name = "");
4758 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4759 const Twine &name = "");
4760 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4761 ArrayRef<Address> args,
4762 const Twine &name = "");
4763 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4765 const Twine &name = "");
4766
4768 getBundlesForFunclet(llvm::Value *Callee);
4769
4770 llvm::CallBase *EmitCallOrInvoke(llvm::FunctionCallee Callee,
4772 const Twine &Name = "");
4773 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4775 const Twine &name = "");
4776 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4777 const Twine &name = "");
4778 void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4780
4782 NestedNameSpecifier Qual, llvm::Type *Ty);
4783
4786 const CXXRecordDecl *RD);
4787
4788 bool isPointerKnownNonNull(const Expr *E);
4789 /// Check whether the underlying base pointer is a constant null.
4791
4792 /// Create the discriminator from the storage address and the entity hash.
4793 llvm::Value *EmitPointerAuthBlendDiscriminator(llvm::Value *StorageAddress,
4794 llvm::Value *Discriminator);
4796 llvm::Value *StorageAddress,
4797 GlobalDecl SchemaDecl,
4798 QualType SchemaType);
4799
4800 llvm::Value *EmitPointerAuthSign(const CGPointerAuthInfo &Info,
4801 llvm::Value *Pointer);
4802
4803 llvm::Value *EmitPointerAuthAuth(const CGPointerAuthInfo &Info,
4804 llvm::Value *Pointer);
4805
4806 llvm::Value *emitPointerAuthResign(llvm::Value *Pointer, QualType PointerType,
4807 const CGPointerAuthInfo &CurAuthInfo,
4808 const CGPointerAuthInfo &NewAuthInfo,
4809 bool IsKnownNonNull);
4810 llvm::Value *emitPointerAuthResignCall(llvm::Value *Pointer,
4811 const CGPointerAuthInfo &CurInfo,
4812 const CGPointerAuthInfo &NewInfo);
4813
4815 const CGPointerAuthInfo &Info,
4817
4819 Address StorageAddress);
4820 llvm::Value *EmitPointerAuthQualify(PointerAuthQualifier Qualifier,
4821 llvm::Value *Pointer, QualType ValueType,
4822 Address StorageAddress,
4823 bool IsKnownNonNull);
4824 llvm::Value *EmitPointerAuthQualify(PointerAuthQualifier Qualifier,
4825 const Expr *PointerExpr,
4826 Address StorageAddress);
4827 llvm::Value *EmitPointerAuthUnqualify(PointerAuthQualifier Qualifier,
4828 llvm::Value *Pointer,
4830 Address StorageAddress,
4831 bool IsKnownNonNull);
4833 Address DestField, Address SrcField);
4834
4835 std::pair<llvm::Value *, CGPointerAuthInfo>
4836 EmitOrigPointerRValue(const Expr *E);
4837
4838 llvm::Value *authPointerToPointerCast(llvm::Value *ResultPtr,
4839 QualType SourceType, QualType DestType);
4841 QualType DestType);
4842
4844
4845 llvm::Value *getAsNaturalPointerTo(Address Addr, QualType PointeeType) {
4846 return getAsNaturalAddressOf(Addr, PointeeType).getBasePointer();
4847 }
4848
4849 // Return the copy constructor name with the prefix "__copy_constructor_"
4850 // removed.
4851 static std::string getNonTrivialCopyConstructorStr(QualType QT,
4852 CharUnits Alignment,
4853 bool IsVolatile,
4854 ASTContext &Ctx);
4855
4856 // Return the destructor name with the prefix "__destructor_" removed.
4857 static std::string getNonTrivialDestructorStr(QualType QT,
4858 CharUnits Alignment,
4859 bool IsVolatile,
4860 ASTContext &Ctx);
4861
4862 // These functions emit calls to the special functions of non-trivial C
4863 // structs.
4866 void callCStructDestructor(LValue Dst);
4871
4873 const CXXMethodDecl *Method, const CGCallee &Callee,
4874 ReturnValueSlot ReturnValue, llvm::Value *This,
4875 llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E,
4876 CallArgList *RtlArgs, llvm::CallBase **CallOrInvoke);
4877 RValue EmitCXXDestructorCall(GlobalDecl Dtor, const CGCallee &Callee,
4878 llvm::Value *This, QualType ThisTy,
4879 llvm::Value *ImplicitParam,
4880 QualType ImplicitParamTy, const CallExpr *E,
4881 llvm::CallBase **CallOrInvoke = nullptr);
4884 llvm::CallBase **CallOrInvoke = nullptr);
4886 const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue,
4887 bool HasQualifier, NestedNameSpecifier Qualifier, bool IsArrow,
4888 const Expr *Base, llvm::CallBase **CallOrInvoke);
4889 // Compute the object pointer.
4891 const Expr *E, Address base, llvm::Value *memberPtr,
4892 const MemberPointerType *memberPtrType, bool IsInBounds,
4893 LValueBaseInfo *BaseInfo = nullptr, TBAAAccessInfo *TBAAInfo = nullptr);
4896 llvm::CallBase **CallOrInvoke);
4897
4899 const CXXMethodDecl *MD,
4901 llvm::CallBase **CallOrInvoke);
4903
4906 llvm::CallBase **CallOrInvoke);
4907
4910
4911 RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4913
4914 RValue emitRotate(const CallExpr *E, bool IsRotateRight);
4915
4916 RValue emitStdcCountIntrinsic(const CallExpr *E, llvm::Intrinsic::ID IntID,
4917 bool InvertArg, bool IsPop = false);
4918 RValue emitStdcBitWidthMinus(const CallExpr *E, llvm::Intrinsic::ID IntID,
4919 bool IsPop);
4920 RValue emitStdcFirstBit(const CallExpr *E, llvm::Intrinsic::ID IntID,
4921 bool InvertArg);
4922
4923 /// Emit IR for __builtin_os_log_format.
4925
4926 /// Emit IR for __builtin_is_aligned.
4928 /// Emit IR for __builtin_align_up/__builtin_align_down.
4929 RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp);
4930
4931 llvm::Function *generateBuiltinOSLogHelperFunction(
4933 CharUnits BufferAlignment);
4934
4936 llvm::CallBase **CallOrInvoke);
4937
4938 /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
4939 /// is unhandled by the current target.
4940 llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4942
4943 llvm::Value *
4944 EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty,
4945 const llvm::CmpInst::Predicate Pred,
4946 const llvm::Twine &Name = "");
4947 llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4949 llvm::Triple::ArchType Arch);
4950 llvm::Value *EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4952 llvm::Triple::ArchType Arch);
4953 llvm::Value *EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4955 llvm::Triple::ArchType Arch);
4956 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy,
4957 QualType RTy);
4958 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy,
4959 QualType RTy);
4960
4961 llvm::Value *
4962 EmitCommonNeonBuiltinExpr(unsigned BuiltinID, unsigned LLVMIntrinsic,
4963 unsigned AltLLVMIntrinsic, const char *NameHint,
4964 unsigned Modifier, const CallExpr *E,
4966 Address PtrOp1, llvm::Triple::ArchType Arch);
4967
4968 llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID,
4969 unsigned Modifier, llvm::Type *ArgTy,
4970 const CallExpr *E);
4971 llvm::Value *EmitNeonCall(llvm::Function *F,
4972 SmallVectorImpl<llvm::Value *> &O, const char *name,
4973 unsigned shift = 0, bool rightshift = false);
4974 llvm::Value *EmitFP8NeonCall(unsigned IID, ArrayRef<llvm::Type *> Tys,
4976 const CallExpr *E, const char *name);
4977 llvm::Value *EmitFP8NeonCvtCall(unsigned IID, llvm::Type *Ty0,
4978 llvm::Type *Ty1, bool Extract,
4980 const CallExpr *E, const char *name);
4981 llvm::Value *EmitFP8NeonFDOTCall(unsigned IID, bool ExtendLaneArg,
4982 llvm::Type *RetTy,
4984 const CallExpr *E, const char *name);
4985 llvm::Value *EmitFP8NeonFMLACall(unsigned IID, bool ExtendLaneArg,
4986 llvm::Type *RetTy,
4988 const CallExpr *E, const char *name);
4989 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx,
4990 const llvm::ElementCount &Count);
4991 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
4992 llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty,
4993 bool negateForRightShift);
4994 llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt,
4995 llvm::Type *Ty, bool usgn, const char *name);
4996 llvm::Value *vectorWrapScalar16(llvm::Value *Op);
4997 /// SVEBuiltinMemEltTy - Returns the memory element type for this memory
4998 /// access builtin. Only required if it can't be inferred from the base
4999 /// pointer operand.
5000 llvm::Type *SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags);
5001
5003 getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType,
5005 llvm::Type *getEltType(const SVETypeFlags &TypeFlags);
5006 llvm::ScalableVectorType *getSVEType(const SVETypeFlags &TypeFlags);
5007 llvm::ScalableVectorType *getSVEPredType(const SVETypeFlags &TypeFlags);
5008 llvm::Value *EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags,
5010 llvm::Value *EmitSVETupleCreate(const SVETypeFlags &TypeFlags,
5011 llvm::Type *ReturnType,
5013 llvm::Value *EmitSVEDupX(llvm::Value *Scalar);
5014 llvm::Value *EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty);
5015 llvm::Value *EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty);
5016 llvm::Value *EmitSVEPMull(const SVETypeFlags &TypeFlags,
5018 unsigned BuiltinID);
5019 llvm::Value *EmitSVEMovl(const SVETypeFlags &TypeFlags,
5021 unsigned BuiltinID);
5022 llvm::Value *EmitSVEPredicateCast(llvm::Value *Pred,
5023 llvm::ScalableVectorType *VTy);
5024 llvm::Value *EmitSVEPredicateTupleCast(llvm::Value *PredTuple,
5025 llvm::StructType *Ty);
5026 llvm::Value *EmitSVEGatherLoad(const SVETypeFlags &TypeFlags,
5028 unsigned IntID);
5029 llvm::Value *EmitSVEScatterStore(const SVETypeFlags &TypeFlags,
5031 unsigned IntID);
5032 llvm::Value *EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy,
5034 unsigned BuiltinID, bool IsZExtReturn);
5035 llvm::Value *EmitSVEMaskedStore(const CallExpr *,
5037 unsigned BuiltinID);
5038 llvm::Value *EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags,
5040 unsigned BuiltinID);
5041 llvm::Value *EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags,
5043 unsigned IntID);
5044 llvm::Value *EmitSVEStructLoad(const SVETypeFlags &TypeFlags,
5046 unsigned IntID);
5047 llvm::Value *EmitSVEStructStore(const SVETypeFlags &TypeFlags,
5049 unsigned IntID);
5050 llvm::Value *EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5051
5052 llvm::Value *EmitSMELd1St1(const SVETypeFlags &TypeFlags,
5054 unsigned IntID);
5055 llvm::Value *EmitSMEReadWrite(const SVETypeFlags &TypeFlags,
5057 unsigned IntID);
5058 llvm::Value *EmitSMEZero(const SVETypeFlags &TypeFlags,
5060 unsigned IntID);
5061 llvm::Value *EmitSMELdrStr(const SVETypeFlags &TypeFlags,
5063 unsigned IntID);
5064
5065 void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E,
5067 SVETypeFlags TypeFlags);
5068
5069 llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5070
5071 llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
5072 llvm::Triple::ArchType Arch);
5073 llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5074
5075 llvm::Value *BuildVector(ArrayRef<llvm::Value *> Ops);
5076 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5077 llvm::Value *EmitPPCBuiltinCpu(unsigned BuiltinID, llvm::Type *ReturnType,
5078 StringRef CPUStr);
5079 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5080 llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5081 llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
5083
5084 // Returns a builtin function that the SPIR-V backend will expand into a spec
5085 // constant.
5086 llvm::Function *
5087 getSpecConstantFunction(const clang::QualType &SpecConstantType);
5088
5089 llvm::Value *EmitDirectXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5090 llvm::Value *EmitSPIRVBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5091 llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
5092 const CallExpr *E);
5093 llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5094 llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5095 llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
5096 const CallExpr *E);
5097 llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5098 llvm::Value *EmitAVRBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
5099 llvm::Value *EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
5101
5102 llvm::Value *EmitRISCVCpuSupports(const CallExpr *E);
5103 llvm::Value *EmitRISCVCpuSupports(ArrayRef<StringRef> FeaturesStrs);
5104 llvm::Value *EmitRISCVCpuInit();
5105 llvm::Value *EmitRISCVCpuIs(const CallExpr *E);
5106 llvm::Value *EmitRISCVCpuIs(StringRef CPUStr);
5107
5108 void AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
5109 const CallExpr *E);
5110 /// Attach the AMDGPU availability/visibility MMRA to \p Inst when the
5111 /// amdgpu_av attribute is active on the current statement.
5112 void AddAMDGPUAvailableVisibleMMRA(llvm::Instruction *Inst);
5113 void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope,
5114 llvm::AtomicOrdering &AO,
5115 llvm::SyncScope::ID &SSID);
5116
5118 llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E);
5119
5120 llvm::Value *EmitBuiltinAvailable(const VersionTuple &Version);
5121
5122 llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
5123 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
5124 llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E);
5125 llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E);
5126 llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E);
5127 llvm::Value *
5129 const ObjCMethodDecl *MethodWithObjects);
5130 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
5132 ReturnValueSlot Return = ReturnValueSlot());
5133
5134 /// Retrieves the default cleanup kind for an ARC cleanup.
5135 /// Except under -fobjc-arc-eh, ARC cleanups are normal-only.
5137 return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions ? NormalAndEHCleanup
5138 : NormalCleanup;
5139 }
5140
5141 // ARC primitives.
5142 void EmitARCInitWeak(Address addr, llvm::Value *value);
5143 void EmitARCDestroyWeak(Address addr);
5144 llvm::Value *EmitARCLoadWeak(Address addr);
5145 llvm::Value *EmitARCLoadWeakRetained(Address addr);
5146 llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored);
5147 void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
5148 void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
5149 void EmitARCCopyWeak(Address dst, Address src);
5150 void EmitARCMoveWeak(Address dst, Address src);
5151 llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);
5152 llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value);
5153 llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value,
5154 bool resultIgnored);
5155 llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value,
5156 bool resultIgnored);
5157 llvm::Value *EmitARCRetain(QualType type, llvm::Value *value);
5158 llvm::Value *EmitARCRetainNonBlock(llvm::Value *value);
5159 llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory);
5161 void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
5162 llvm::Value *EmitARCAutorelease(llvm::Value *value);
5163 llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value);
5164 llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value);
5165 llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
5166 llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value);
5167
5168 llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType);
5169 llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value,
5170 llvm::Type *returnType);
5171 void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
5172
5173 std::pair<LValue, llvm::Value *>
5175 std::pair<LValue, llvm::Value *> EmitARCStoreStrong(const BinaryOperator *e,
5176 bool ignored);
5177 std::pair<LValue, llvm::Value *>
5178 EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored);
5179
5180 llvm::Value *EmitObjCAlloc(llvm::Value *value, llvm::Type *returnType);
5181 llvm::Value *EmitObjCAllocWithZone(llvm::Value *value,
5182 llvm::Type *returnType);
5183 llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType);
5184
5185 llvm::Value *EmitObjCThrowOperand(const Expr *expr);
5186 llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr);
5187 llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr);
5188
5189 llvm::Value *EmitARCExtendBlockObject(const Expr *expr);
5190 llvm::Value *EmitARCReclaimReturnedObject(const Expr *e,
5191 bool allowUnsafeClaim);
5192 llvm::Value *EmitARCRetainScalarExpr(const Expr *expr);
5193 llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr);
5194 llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr);
5195
5197
5199
5205
5206 void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr);
5207 llvm::Value *EmitObjCAutoreleasePoolPush();
5208 llvm::Value *EmitObjCMRRAutoreleasePoolPush();
5209 void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
5210 void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr);
5211
5212 /// Emits a reference binding to the passed in expression.
5214
5215 //===--------------------------------------------------------------------===//
5216 // Expression Emission
5217 //===--------------------------------------------------------------------===//
5218
5219 // Expressions are broken into three classes: scalar, complex, aggregate.
5220
5221 /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
5222 /// scalar type, returning the result.
5223 llvm::Value *EmitScalarExpr(const Expr *E, bool IgnoreResultAssign = false);
5224
5225 /// Emit a conversion from the specified type to the specified destination
5226 /// type, both of which are LLVM scalar types.
5227 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
5228 QualType DstTy, SourceLocation Loc);
5229
5230 /// Emit a conversion from the specified complex type to the specified
5231 /// destination type, where the destination type is an LLVM scalar type.
5233 QualType DstTy,
5234 SourceLocation Loc);
5235
5236 /// EmitAggExpr - Emit the computation of the specified expression
5237 /// of aggregate type. The result is computed into the given slot,
5238 /// which may be null to indicate that the value is not needed.
5239 void EmitAggExpr(const Expr *E, AggValueSlot AS);
5240
5241 /// EmitAggExprToLValue - Emit the computation of the specified expression of
5242 /// aggregate type into a temporary LValue.
5244
5246
5247 /// EmitAggFinalDestCopy - Emit copy of the specified aggregate into
5248 /// destination address.
5249 void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src,
5250 ExprValueKind SrcKind);
5251
5252 /// Create a store to \arg DstPtr from \arg Src, truncating the stored value
5253 /// to at most \arg DstSize bytes.
5254 void CreateCoercedStore(llvm::Value *Src, QualType SrcFETy, Address Dst,
5255 llvm::TypeSize DstSize, bool DstIsVolatile);
5256
5257 /// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
5258 /// make sure it survives garbage collection until this point.
5259 void EmitExtendGCLifetime(llvm::Value *object);
5260
5261 /// EmitComplexExpr - Emit the computation of the specified expression of
5262 /// complex type, returning the result.
5263 ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
5264 bool IgnoreImag = false);
5265
5266 /// EmitComplexExprIntoLValue - Emit the given expression of complex
5267 /// type and place its result into the specified l-value.
5268 void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);
5269
5270 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
5271 void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);
5272
5273 /// EmitLoadOfComplex - Load a complex number from the specified l-value.
5275
5276 ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType);
5277 llvm::Value *EmitPromotedScalarExpr(const Expr *E, QualType PromotionType);
5280 QualType PromotionType);
5281
5284
5285 /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the
5286 /// global variable that has already been created for it. If the initializer
5287 /// has a different type than GV does, this may free GV and return a different
5288 /// one. Otherwise it just returns GV.
5289 llvm::GlobalVariable *AddInitializerToStaticVarDecl(const VarDecl &D,
5290 llvm::GlobalVariable *GV);
5291
5292 // Emit an @llvm.invariant.start call for the given memory region.
5293 void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size);
5294
5295 /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
5296 /// variable with global storage.
5297 void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV,
5298 bool PerformInit);
5299
5300 llvm::Constant *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor,
5301 llvm::Constant *Addr);
5302
5303 llvm::Function *createTLSAtExitStub(const VarDecl &VD,
5304 llvm::FunctionCallee Dtor,
5305 llvm::Constant *Addr,
5306 llvm::FunctionCallee &AtExit);
5307
5308 /// Call atexit() with a function that passes the given argument to
5309 /// the given function.
5310 void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn,
5311 llvm::Constant *addr);
5312
5313 /// Registers the dtor using 'llvm.global_dtors' for platforms that do not
5314 /// support an 'atexit()' function.
5315 void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn,
5316 llvm::Constant *addr);
5317
5318 /// Call atexit() with function dtorStub.
5319 void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub);
5320
5321 /// Call unatexit() with function dtorStub.
5322 llvm::Value *unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub);
5323
5324 /// Emit code in this function to perform a guarded variable
5325 /// initialization. Guarded initializations are used when it's not
5326 /// possible to prove that an initialization will be done exactly
5327 /// once, e.g. with a static local variable or a static data member
5328 /// of a class template.
5329 void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr,
5330 bool PerformInit);
5331
5333
5334 /// Emit a branch to select whether or not to perform guarded initialization.
5335 void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit,
5336 llvm::BasicBlock *InitBlock,
5337 llvm::BasicBlock *NoInitBlock, GuardKind Kind,
5338 const VarDecl *D);
5339
5340 /// GenerateCXXGlobalInitFunc - Generates code for initializing global
5341 /// variables.
5342 void
5343 GenerateCXXGlobalInitFunc(llvm::Function *Fn,
5344 ArrayRef<llvm::Function *> CXXThreadLocals,
5346
5347 /// GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global
5348 /// variables.
5350 llvm::Function *Fn,
5351 ArrayRef<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
5352 llvm::Constant *>>
5353 DtorsOrStermFinalizers);
5354
5355 void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D,
5356 llvm::GlobalVariable *Addr,
5357 bool PerformInit);
5358
5360
5361 void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp);
5362
5363 void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true);
5364
5366
5367 void EmitFakeUse(Address Addr);
5368
5369 //===--------------------------------------------------------------------===//
5370 // Annotations Emission
5371 //===--------------------------------------------------------------------===//
5372
5373 /// Emit an annotation call (intrinsic).
5374 llvm::Value *EmitAnnotationCall(llvm::Function *AnnotationFn,
5375 llvm::Value *AnnotatedVal,
5376 StringRef AnnotationStr,
5377 SourceLocation Location,
5378 const AnnotateAttr *Attr);
5379
5380 /// Emit local annotations for the local variable V, declared by D.
5381 void EmitVarAnnotations(const VarDecl *D, llvm::Value *V);
5382
5383 /// Emit field annotations for the given field & value. Returns the
5384 /// annotation result.
5386
5387 //===--------------------------------------------------------------------===//
5388 // Internal Helpers
5389 //===--------------------------------------------------------------------===//
5390
5391 /// ContainsLabel - Return true if the statement contains a label in it. If
5392 /// this statement is not executed normally, it not containing a label means
5393 /// that we can just remove the code.
5394 static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
5395
5396 /// containsBreak - Return true if the statement contains a break out of it.
5397 /// If the statement (recursively) contains a switch or loop with a break
5398 /// inside of it, this is fine.
5399 static bool containsBreak(const Stmt *S);
5400
5401 /// Determine if the given statement might introduce a declaration into the
5402 /// current scope, by being a (possibly-labelled) DeclStmt.
5403 static bool mightAddDeclToScope(const Stmt *S);
5404
5405 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
5406 /// to a constant, or if it does but contains a label, return false. If it
5407 /// constant folds return true and set the boolean result in Result.
5408 bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result,
5409 bool AllowLabels = false);
5410
5411 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
5412 /// to a constant, or if it does but contains a label, return false. If it
5413 /// constant folds return true and set the folded value.
5414 bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result,
5415 bool AllowLabels = false);
5416
5417 /// Ignore parentheses and logical-NOT to track conditions consistently.
5418 static const Expr *stripCond(const Expr *C);
5419
5420 /// isInstrumentedCondition - Determine whether the given condition is an
5421 /// instrumentable condition (i.e. no "&&" or "||").
5422 static bool isInstrumentedCondition(const Expr *C);
5423
5424 /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that
5425 /// increments a profile counter based on the semantics of the given logical
5426 /// operator opcode. This is used to instrument branch condition coverage
5427 /// for logical operators.
5429 llvm::BasicBlock *TrueBlock,
5430 llvm::BasicBlock *FalseBlock,
5431 uint64_t TrueCount = 0,
5433 const Expr *CntrIdx = nullptr);
5434
5435 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
5436 /// if statement) to the specified blocks. Based on the condition, this might
5437 /// try to simplify the codegen of the conditional based on the branch.
5438 /// TrueCount should be the number of times we expect the condition to
5439 /// evaluate to true based on PGO data.
5440 void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
5441 llvm::BasicBlock *FalseBlock, uint64_t TrueCount,
5443 const Expr *ConditionalOp = nullptr,
5444 const VarDecl *ConditionalDecl = nullptr);
5445
5446 /// Given an assignment `*LHS = RHS`, emit a test that checks if \p RHS is
5447 /// nonnull, if \p LHS is marked _Nonnull.
5448 void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc);
5449
5450 /// An enumeration which makes it easier to specify whether or not an
5451 /// operation is a subtraction.
5452 enum { NotSubtraction = false, IsSubtraction = true };
5453
5454 /// Emit pointer + index arithmetic.
5455 llvm::Value *EmitPointerArithmetic(const BinaryOperator *BO,
5456 Expr *pointerOperand, llvm::Value *pointer,
5457 Expr *indexOperand, llvm::Value *index,
5458 bool isSubtraction);
5459
5460 /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
5461 /// detect undefined behavior when the pointer overflow sanitizer is enabled.
5462 /// \p SignedIndices indicates whether any of the GEP indices are signed.
5463 /// \p IsSubtraction indicates whether the expression used to form the GEP
5464 /// is a subtraction.
5465 llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr,
5467 bool SignedIndices, bool IsSubtraction,
5468 SourceLocation Loc,
5469 const Twine &Name = "");
5470
5472 llvm::Type *elementType, bool SignedIndices,
5473 bool IsSubtraction, SourceLocation Loc,
5474 CharUnits Align, const Twine &Name = "");
5475
5476 /// Specifies which type of sanitizer check to apply when handling a
5477 /// particular builtin.
5485
5486 /// Emits an argument for a call to a builtin. If the builtin sanitizer is
5487 /// enabled, a runtime check specified by \p Kind is also emitted.
5488 llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind);
5489
5490 /// Emits an argument for a call to a `__builtin_assume`. If the builtin
5491 /// sanitizer is enabled, a runtime check is also emitted.
5492 llvm::Value *EmitCheckedArgForAssume(const Expr *E);
5493
5494 /// Emit a description of a type in a format suitable for passing to
5495 /// a runtime sanitizer handler.
5496 llvm::Constant *EmitCheckTypeDescriptor(QualType T);
5497
5498 /// Convert a value into a format suitable for passing to a runtime
5499 /// sanitizer handler.
5500 llvm::Value *EmitCheckValue(llvm::Value *V);
5501
5502 /// Emit a description of a source location in a format suitable for
5503 /// passing to a runtime sanitizer handler.
5504 llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc);
5505
5506 /// Emit a private unnamed_addr non-constant global containing static
5507 /// arguments for a UBSan runtime check handler.
5508 llvm::GlobalVariable *
5510
5511 void EmitKCFIOperandBundle(const CGCallee &Callee,
5513
5514 /// Create a basic block that will either trap or call a handler function in
5515 /// the UBSan runtime with the provided arguments, and create a conditional
5516 /// branch to it.
5517 void
5518 EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerKind::SanitizerOrdinal>>
5519 Checked,
5521 ArrayRef<llvm::Value *> DynamicArgs,
5522 const TrapReason *TR = nullptr);
5523
5524 /// Emit a slow path cross-DSO CFI check which calls __cfi_slowpath
5525 /// if Cond if false.
5527 llvm::Value *Cond, llvm::ConstantInt *TypeId,
5528 llvm::Value *Ptr,
5529 ArrayRef<llvm::Constant *> StaticArgs);
5530
5531 /// Build the static argument array {CheckKind, SourceLocation,
5532 /// TypeDescriptor} for a UBSan CFICheckFail handler.
5533 std::array<llvm::Constant *, 3>
5535 QualType Type);
5536
5537 /// Emit a reached-unreachable diagnostic if \p Loc is valid and runtime
5538 /// checking is enabled. Otherwise, just emit an unreachable instruction.
5540
5541 /// Create a basic block that will call the trap intrinsic, and emit a
5542 /// conditional branch to it, for the -ftrapv checks.
5543 void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID,
5544 bool NoMerge = false, const TrapReason *TR = nullptr);
5545
5546 /// Emit a call to trap or debugtrap. If 'EnsureInsertPoint' is false, the
5547 /// IR builder need not have a valid insert point after this returns.
5548 llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID,
5549 bool EnsureInsertPoint = true);
5550
5551 /// Emit a call to '\@llvm.trap()' and clear the current insert point.
5553
5554 /// Emit a stub for the cross-DSO CFI check function.
5555 void EmitCfiCheckStub();
5556
5557 /// Emit a cross-DSO CFI failure handling function.
5558 void EmitCfiCheckFail();
5559
5560 /// Create a check for a function parameter that may potentially be
5561 /// declared as non-null.
5562 void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc,
5563 AbstractCallee AC, unsigned ParmNum);
5564
5566 SourceLocation ArgLoc, AbstractCallee AC,
5567 unsigned ParmNum);
5568
5569 /// EmitWriteback - Emit callbacks for function.
5570 void EmitWritebacks(const CallArgList &Args);
5571
5572 /// EmitCallArg - Emit a single call argument.
5573 void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType);
5574
5575 /// EmitDelegateCallArg - We are performing a delegate call; that
5576 /// is, the current function is delegating to another one. Produce
5577 /// a r-value suitable for passing the given parameter.
5578 void EmitDelegateCallArg(CallArgList &args, const VarDecl *param,
5579 SourceLocation loc);
5580
5581 /// SetFPAccuracy - Set the minimum required accuracy of the given floating
5582 /// point operation, expressed as the maximum relative error in ulp.
5583 void SetFPAccuracy(llvm::Value *Val, float Accuracy);
5584
5585 /// Set the minimum required accuracy of the given sqrt operation
5586 /// based on CodeGenOpts.
5587 void SetSqrtFPAccuracy(llvm::Value *Val);
5588
5589 /// Set the minimum required accuracy of the given sqrt operation based on
5590 /// CodeGenOpts.
5591 void SetDivFPAccuracy(llvm::Value *Val);
5592
5593 /// Set the codegen fast-math flags.
5594 void SetFastMathFlags(FPOptions FPFeatures);
5595
5596 // Truncate or extend a boolean vector to the requested number of elements.
5597 llvm::Value *emitBoolVecConversion(llvm::Value *SrcVec,
5598 unsigned NumElementsDst,
5599 const llvm::Twine &Name = "");
5600
5601 void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty,
5602 SourceLocation Loc);
5603
5604 // Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
5605 // as it's parent convergence instr.
5606 llvm::ConvergenceControlInst *emitConvergenceLoopToken(llvm::BasicBlock *BB);
5607
5608private:
5609 // Adds a convergencectrl bundle with the current convergence token to
5610 // |Bundles|, if convergence tokens are used.
5611 void
5612 addConvergenceControlBundle(SmallVectorImpl<llvm::OperandBundleDef> &Bundles);
5613
5614 // Marks |Call| convergent if |IsConvergent| and its callee does not already
5615 // imply it.
5616 void setConvergentCallSite(llvm::CallBase *Call, bool IsConvergent);
5617
5618 // Find the convergence_entry instruction |F|, or emits ones if none exists.
5619 // Returns the convergence instruction.
5620 llvm::ConvergenceControlInst *
5621 getOrEmitConvergenceEntryToken(llvm::Function *F);
5622
5623private:
5624 llvm::MDNode *getRangeForLoadFromType(QualType Ty);
5625 void EmitReturnOfRValue(RValue RV, QualType Ty);
5626
5627 void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New);
5628
5630 DeferredReplacements;
5631
5632 /// Set the address of a local variable.
5633 void setAddrOfLocalVar(const VarDecl *VD, Address Addr) {
5634 assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!");
5635 LocalDeclMap.insert({VD, Addr});
5636 }
5637
5638 /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
5639 /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
5640 ///
5641 /// \param AI - The first function argument of the expansion.
5642 void ExpandTypeFromArgs(QualType Ty, LValue Dst,
5643 llvm::Function::arg_iterator &AI);
5644
5645 /// ExpandTypeToArgs - Expand an CallArg \arg Arg, with the LLVM type for \arg
5646 /// Ty, into individual arguments on the provided vector \arg IRCallArgs,
5647 /// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand.
5648 void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,
5649 SmallVectorImpl<llvm::Value *> &IRCallArgs,
5650 unsigned &IRCallArgPos);
5651
5652 std::pair<llvm::Value *, llvm::Type *>
5653 EmitAsmInput(const TargetInfo::ConstraintInfo &Info, const Expr *InputExpr,
5654 std::string &ConstraintStr);
5655
5656 std::pair<llvm::Value *, llvm::Type *>
5657 EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, LValue InputValue,
5658 QualType InputType, std::string &ConstraintStr,
5659 SourceLocation Loc);
5660
5661 /// Attempts to statically evaluate the object size of E. If that
5662 /// fails, emits code to figure the size of E out for us. This is
5663 /// pass_object_size aware.
5664 ///
5665 /// If EmittedExpr is non-null, this will use that instead of re-emitting E.
5666 llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
5667 llvm::IntegerType *ResType,
5668 llvm::Value *EmittedE,
5669 bool IsDynamic);
5670
5671 /// Emits the size of E, as required by __builtin_object_size. This
5672 /// function is aware of pass_object_size parameters, and will act accordingly
5673 /// if E is a parameter with the pass_object_size attribute.
5674 llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type,
5675 llvm::IntegerType *ResType,
5676 llvm::Value *EmittedE, bool IsDynamic);
5677
5678 llvm::Value *emitCountedBySize(const Expr *E, llvm::Value *EmittedE,
5679 unsigned Type, llvm::IntegerType *ResType);
5680
5681 llvm::Value *emitCountedByMemberSize(const MemberExpr *E, const Expr *Idx,
5682 llvm::Value *EmittedE,
5683 QualType CastedArrayElementTy,
5684 unsigned Type,
5685 llvm::IntegerType *ResType);
5686
5687 llvm::Value *emitCountedByPointerSize(const ImplicitCastExpr *E,
5688 const Expr *Idx, llvm::Value *EmittedE,
5689 QualType CastedArrayElementTy,
5690 unsigned Type,
5691 llvm::IntegerType *ResType);
5692
5693 void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D,
5694 Address Loc);
5695 LangOptions::TrivialAutoVarInitKind getAutoVarInitKind(QualType Ty,
5696 const VarDecl &D);
5697
5698public:
5700
5701 // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
5702 // an ObjCMethodDecl.
5704 llvm::PointerUnion<const FunctionProtoType *, const ObjCMethodDecl *> P;
5705
5708 };
5709
5710 void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype,
5711 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
5712 AbstractCallee AC = AbstractCallee(),
5713 unsigned ParamsToSkip = 0,
5714 EvaluationOrder Order = EvaluationOrder::Default);
5715
5716 /// EmitPointerWithAlignment - Given an expression with a pointer type,
5717 /// emit the value and compute our best estimate of the alignment of the
5718 /// pointee.
5719 ///
5720 /// \param BaseInfo - If non-null, this will be initialized with
5721 /// information about the source of the alignment and the may-alias
5722 /// attribute. Note that this function will conservatively fall back on
5723 /// the type when it doesn't recognize the expression and may-alias will
5724 /// be set to false.
5725 ///
5726 /// One reasonable way to use this information is when there's a language
5727 /// guarantee that the pointer must be aligned to some stricter value, and
5728 /// we're simply trying to ensure that sufficiently obvious uses of under-
5729 /// aligned objects don't get miscompiled; for example, a placement new
5730 /// into the address of a local variable. In such a case, it's quite
5731 /// reasonable to just ignore the returned alignment when it isn't from an
5732 /// explicit source.
5733 Address
5734 EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo = nullptr,
5735 TBAAAccessInfo *TBAAInfo = nullptr,
5736 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
5737
5738 /// If \p E references a parameter with pass_object_size info or a constant
5739 /// array size modifier, emit the object size divided by the size of \p EltTy.
5740 /// Otherwise return null.
5741 llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy);
5742
5743 void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
5744
5746 llvm::Function *Function;
5748 std::optional<StringRef> Architecture;
5749
5750 FMVResolverOption(llvm::Function *F, ArrayRef<StringRef> Feats,
5751 std::optional<StringRef> Arch = std::nullopt)
5752 : Function(F), Features(Feats), Architecture(Arch) {}
5753 };
5754
5755 // Emits the body of a multiversion function's resolver. Assumes that the
5756 // options are already sorted in the proper order, with the 'default' option
5757 // last (if it exists).
5758 void EmitMultiVersionResolver(llvm::Function *Resolver,
5760 void EmitX86MultiVersionResolver(llvm::Function *Resolver,
5762 void EmitAArch64MultiVersionResolver(llvm::Function *Resolver,
5764 void EmitRISCVMultiVersionResolver(llvm::Function *Resolver,
5766 void EmitPPCAIXMultiVersionResolver(llvm::Function *Resolver,
5768
5769 Address EmitAddressOfPFPField(Address RecordPtr, const PFPField &Field);
5770 Address EmitAddressOfPFPField(Address RecordPtr, Address FieldPtr,
5771 const FieldDecl *Field);
5772
5773private:
5774 QualType getVarArgType(const Expr *Arg);
5775
5776 void EmitDeclMetadata();
5777
5778 BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType,
5779 const AutoVarEmission &emission);
5780
5781 void AddObjCARCExceptionMetadata(llvm::Instruction *Inst);
5782
5783 llvm::Value *GetValueForARMHint(unsigned BuiltinID);
5784 llvm::Value *EmitX86CpuIs(const CallExpr *E);
5785 llvm::Value *EmitX86CpuIs(StringRef CPUStr);
5786 llvm::Value *EmitX86CpuSupports(const CallExpr *E);
5787 llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs);
5788 llvm::Value *EmitX86CpuSupports(std::array<uint32_t, 4> FeatureMask);
5789 llvm::Value *EmitX86CpuInit();
5790 llvm::Value *FormX86ResolverCondition(const FMVResolverOption &RO);
5791 llvm::Value *EmitAArch64CpuInit();
5792 llvm::Value *FormAArch64ResolverCondition(const FMVResolverOption &RO);
5793 llvm::Value *EmitAArch64CpuSupports(const CallExpr *E);
5794 llvm::Value *EmitAArch64CpuSupports(ArrayRef<StringRef> FeatureStrs);
5795};
5796
5797inline DominatingLLVMValue::saved_type
5799 if (!needsSaving(value))
5800 return saved_type(value);
5801
5802 // Otherwise, we need an alloca.
5803 auto align = CharUnits::fromQuantity(
5804 CGF.CGM.getDataLayout().getPrefTypeAlign(value->getType()))
5805 .getAsAlign();
5806 llvm::AllocaInst *AI =
5807 CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save");
5808 AI->setAlignment(align);
5809 CGF.Builder.CreateAlignedStore(value, AI, align);
5810
5811 return saved_type(AI, value->getType());
5812}
5813
5815 saved_type value) {
5816 // If the value says it wasn't saved, trust that it's still dominating.
5817 if (!value.isSaved())
5818 return value.Value;
5819
5820 // Otherwise, it should be an alloca instruction, as set up in save().
5821 auto Alloca = cast<llvm::AllocaInst>(value.Value);
5822 return CGF.Builder.CreateAlignedLoad(value.Type, Alloca, Alloca->getAlign());
5823}
5824
5825} // end namespace CodeGen
5826
5827// Map the LangOption for floating point exception behavior into
5828// the corresponding enum in the IR.
5829llvm::fp::ExceptionBehavior
5831} // end namespace clang
5832
5833#endif
Enums/classes describing ABI related information about constructors, destructors and thunks.
#define V(N, I)
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition CFG.cpp:2822
static T * buildByrefHelpers(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo, T &&generator)
Lazily build the copy and dispose helpers for a __block variable with the given information.
static bool isInAllocaArgument(CGCXXABI &ABI, QualType type)
Definition CGCall.cpp:4706
@ ForDeactivation
CodeGenFunction::ComplexPairTy ComplexPairTy
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Previous
The previous token in the unwrapped line.
#define X(type, name)
Definition Value.h:97
llvm::MachO::Target Target
Definition MachO.h:51
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines some OpenMP-specific enums and functions.
llvm::json::Array Array
SanitizerHandler
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
C Language Family Type Representation.
This represents 'pragma omp atomic' directive.
This represents 'pragma omp barrier' directive.
This represents 'pragma omp cancel' directive.
This represents 'pragma omp cancellation point' directive.
This represents 'pragma omp critical' directive.
This represents 'pragma omp depobj' directive.
This represents 'pragma omp distribute' directive.
This represents 'pragma omp distribute parallel for' composite directive.
This represents 'pragma omp distribute parallel for simd' composite directive.
This represents 'pragma omp distribute simd' composite directive.
This represents 'pragma omp error' directive.
Represents the 'pragma omp flatten' loop transformation directive.
This represents 'pragma omp flush' directive.
This represents 'pragma omp for' directive.
This represents 'pragma omp for simd' directive.
Represents the 'pragma omp fuse' loop transformation directive.
This represents 'pragma omp loop' directive.
Represents the 'pragma omp interchange' loop transformation directive.
This represents 'pragma omp interop' directive.
This is a common base class for loop directives ('omp simd', 'omp for', 'omp for simd' etc....
This represents 'pragma omp masked' directive.
This represents 'pragma omp masked taskloop' directive.
This represents 'pragma omp masked taskloop simd' directive.
This represents 'pragma omp master' directive.
This represents 'pragma omp master taskloop' directive.
This represents 'pragma omp master taskloop simd' directive.
This represents 'pragma omp metadirective' directive.
This represents block-associated 'pragma omp ordered' directive.
This represents standalone 'pragma omp ordered' directive.
This represents 'pragma omp parallel for' directive.
This represents 'pragma omp parallel for simd' directive.
This represents 'pragma omp parallel masked' directive.
This represents 'pragma omp parallel masked taskloop' directive.
This represents 'pragma omp parallel masked taskloop simd' directive.
This represents 'pragma omp parallel master' directive.
This represents 'pragma omp parallel master taskloop' directive.
This represents 'pragma omp parallel master taskloop simd' directive.
This represents 'pragma omp parallel sections' directive.
Represents the 'pragma omp reverse' loop transformation directive.
This represents 'pragma omp scan' directive.
This represents 'pragma omp scope' directive.
This represents 'pragma omp section' directive.
This represents 'pragma omp sections' directive.
This represents 'pragma omp simd' directive.
This represents 'pragma omp single' directive.
Represents the 'pragma omp split' loop transformation directive.
This represents the 'pragma omp stripe' loop transformation directive.
This represents 'pragma omp target data' directive.
This represents 'pragma omp target' directive.
This represents 'pragma omp target enter data' directive.
This represents 'pragma omp target exit data' directive.
This represents 'pragma omp target parallel' directive.
This represents 'pragma omp target parallel for' directive.
This represents 'pragma omp target parallel for simd' directive.
This represents 'pragma omp target parallel loop' directive.
This represents 'pragma omp target teams' directive.
This represents 'pragma omp target teams distribute' combined directive.
This represents 'pragma omp target teams distribute parallel for' combined directive.
This represents 'pragma omp target teams distribute parallel for simd' combined directive.
This represents 'pragma omp target teams distribute simd' combined directive.
This represents 'pragma omp target teams loop' directive.
This represents 'pragma omp target update' directive.
This represents 'pragma omp task' directive.
This represents 'pragma omp taskloop' directive.
This represents 'pragma omp taskloop simd' directive.
This represents 'pragma omp taskgroup' directive.
This represents 'pragma omp taskwait' directive.
This represents 'pragma omp taskyield' directive.
This represents 'pragma omp teams' directive.
This represents 'pragma omp teams distribute' directive.
This represents 'pragma omp teams distribute parallel for' composite directive.
This represents 'pragma omp teams distribute parallel for simd' composite directive.
This represents 'pragma omp teams distribute simd' combined directive.
This represents 'pragma omp teams loop' directive.
This represents the 'pragma omp tile' loop transformation directive.
This represents the 'pragma omp unroll' loop transformation directive.
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
const Stmt * getAssociatedStmt() const
Stmt * getStructuredBlock()
This class represents a 'loop' construct. The 'loop' construct applies to a 'for' loop (or range-for ...
a trap message and trap category.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:158
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4422
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7305
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2790
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
This structure holds the information gathered about the constraints for an inline assembly statement.
Definition CGStmt.cpp:2761
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:7014
Attr - This represents one attribute.
Definition Attr.h:47
Represents an attribute applied to a statement.
Definition Stmt.h:2214
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4522
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4560
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4557
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4107
static bool isLogicalOp(Opcode Opc)
Definition Expr.h:4240
BinaryOperatorKind Opcode
Definition Expr.h:4112
A binding in a decomposition declaration.
Definition DeclCXX.h:4232
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6758
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:239
Represents binding an expression to a temporary.
Definition ExprCXX.h:1498
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
Represents a C++ constructor within a class.
Definition DeclCXX.h:2645
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1275
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1382
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2631
Represents a C++ destructor within a class.
Definition DeclCXX.h:2924
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:486
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:136
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1756
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:184
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2360
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:86
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2750
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ temporary.
Definition ExprCXX.h:1464
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1213
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:70
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:853
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1073
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
This captures a statement into a function.
Definition Stmt.h:3950
const Capture * const_capture_iterator
Definition Stmt.h:4084
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of captures.
Definition Stmt.h:4101
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
Definition Stmt.h:4071
capture_iterator capture_begin()
Retrieve an iterator pointing to the first capture.
Definition Stmt.h:4096
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3745
const CXXBaseSpecifier *const * path_const_iterator
Definition Expr.h:3812
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool isZero() const
Test whether the quantity equals zero.
Definition CharUnits.h:101
llvm::Align getAsAlign() const
Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
Definition CharUnits.h:159
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Definition CharUnits.h:52
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition Address.h:128
llvm::Value * getBasePointer() const
Definition Address.h:198
static Address invalid()
Definition Address.h:176
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:253
CharUnits getAlignment() const
Definition Address.h:194
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition Address.h:209
void setAlignment(CharUnits Value)
Definition Address.h:196
llvm::Value * getOffset() const
Definition Address.h:246
void replaceBasePointer(llvm::Value *P)
This function is used in situations where the caller is doing some sort of opaque "laundering" of the...
Definition Address.h:186
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition Address.h:204
An aggregate value slot.
Definition CGValue.h:551
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Definition CGValue.h:619
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
Definition CGValue.h:634
A scoped helper to set the current source atom group for CGDebugInfo::addInstToCurrentSourceAtom.
A pair of helper functions for a __block variable.
Information about the layout of a __block variable.
Definition CGBlocks.h:136
CGBlockInfo - Information to generate a block literal.
Definition CGBlocks.h:157
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition CGBuilder.h:156
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
Definition CGBuilder.h:163
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition CGBuilder.h:148
Implements C++ ABI-specific code generation functions.
Definition CGCXXABI.h:43
All available information about a concrete callee.
Definition CGCall.h:66
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition CGDebugInfo.h:60
CGFunctionInfo - Class to encapsulate the information about a function definition.
CallArgList - Type for representing both the value and type of arguments in a call.
Definition CGCall.h:277
const ParmVarDecl * getParamDecl(unsigned I) const
ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index)
Address getAllocatedAddress() const
Returns the raw, allocated address, which is not necessarily the address of the object itself.
RawAddress getOriginalAllocatedAddress() const
Returns the address for the original alloca instruction.
Address getObjectAddress(CodeGenFunction &CGF) const
Returns the address of the object within this declaration.
CGAtomicOptionsRAII(CodeGenModule &CGM_, AtomicOptions AO)
CGAtomicOptionsRAII(CodeGenModule &CGM_, const AtomicAttr *AA)
CGAtomicOptionsRAII(const CGAtomicOptionsRAII &)=delete
CGAtomicOptionsRAII & operator=(const CGAtomicOptionsRAII &)=delete
API for captured statement code generation.
static bool classof(const CGCapturedStmtInfo *)
llvm::SmallDenseMap< const VarDecl *, FieldDecl * > getCaptureFields()
Get the CaptureFields.
CGCapturedStmtInfo(CapturedRegionKind K=CR_Default)
virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S)
Emit the captured statement body.
virtual StringRef getHelperName() const
Get the name of the capture helper.
CGCapturedStmtInfo(const CapturedStmt &S, CapturedRegionKind K=CR_Default)
virtual const FieldDecl * lookup(const VarDecl *VD) const
Lookup the captured field decl for a variable.
CGCapturedStmtRAII(CodeGenFunction &CGF, CGCapturedStmtInfo *NewCapturedStmtInfo)
CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures)
CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E)
void Emit(CodeGenFunction &CGF, Flags flags) override
An object to manage conditionally-evaluated expressions.
llvm::BasicBlock * getStartingBlock() const
Returns a block which will be executed prior to each evaluation of the conditional code.
static ConstantEmission forValue(llvm::Constant *C)
static ConstantEmission forReference(llvm::Constant *C)
LValue getReferenceLValue(CodeGenFunction &CGF, const Expr *RefExpr) const
void Emit(CodeGenFunction &CGF, Flags flags) override
FieldConstructionScope(CodeGenFunction &CGF, Address This)
A class controlling the emission of a finally block.
void enter(CodeGenFunction &CGF, const Stmt *Finally, llvm::FunctionCallee beginCatchFn, llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn)
Enters a finally block for an implementation using zero-cost exceptions.
void rescopeLabels()
Change the cleanup scope of the labels in this lexical scope to match the scope of the enclosing cont...
Definition CGStmt.cpp:761
~LexicalScope()
Exit this cleanup scope, emitting any accumulated cleanups.
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
InlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, llvm::BasicBlock &FiniBB)
OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, llvm::BasicBlock &RetBB)
OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel)
The class used to assign some variables some temporarily addresses.
bool setVarAddr(CodeGenFunction &CGF, const ValueDecl *LocalVD, Address TempAddr)
Sets the address of the variable LocalVD to be TempAddr in function CGF.
bool apply(CodeGenFunction &CGF)
Applies new addresses to the list of the variables.
void restore(CodeGenFunction &CGF)
Restores original addresses of the variables.
The scope used to remap some variables as private in the OpenMP loop body (or other captured region e...
void restoreMap()
Restore all mapped variables w/o clean up.
bool Privatize()
Privatizes local variables previously registered as private.
bool isGlobalVarCaptured(const VarDecl *VD) const
Checks if the global variable is captured in current function.
OMPPrivateScope(CodeGenFunction &CGF)
Enter a new OpenMP private scope.
~OMPPrivateScope()
Exit scope - all the mapped variables are restored.
bool addPrivate(const ValueDecl *LocalVD, Address Addr)
Registers LocalVD variable as a private with Addr as the address of the corresponding private variabl...
A non-RAII class containing all the information about a bound opaque value.
static OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const LValue &lv)
static OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const RValue &rv)
static OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e)
OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *OV)
Build the opaque value mapping for an OpaqueValueExpr whose source expression is set to the expressio...
OpaqueValueMapping(CodeGenFunction &CGF, const AbstractConditionalOperator *op)
Build the opaque value mapping for the given conditional operator if it's the GNU ?
OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue, RValue rvalue)
OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue, LValue lvalue)
static ParamValue forIndirect(Address addr)
static ParamValue forDirect(llvm::Value *value)
ParentLoopDirectiveForScanRegion(CodeGenFunction &CGF, const OMPExecutableDirective &ParentLoopDirectiveForScan)
An object which temporarily prevents a value from being destroyed by aggressive peephole optimization...
RunCleanupsScope(CodeGenFunction &CGF)
Enter a new cleanup scope.
~RunCleanupsScope()
Exit this cleanup scope, emitting any accumulated cleanups.
void ForceCleanup(std::initializer_list< llvm::Value ** > ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
bool requiresCleanups() const
Determine whether this scope requires any cleanups.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
EHScopeStack::stable_iterator CurrentCleanupScopeDepth
llvm::CallInst * EmitIntrinsicCall(llvm::Intrinsic::ID ID, ArrayRef< llvm::Value * > Args, const Twine &Name="")
RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E)
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E)
Definition CGExpr.cpp:5444
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
emitArrayDestroy - Destroys all the elements of the given array, beginning from last to first.
Definition CGDecl.cpp:2527
LValue EmitCoawaitLValue(const CoawaitExpr *E)
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass, VTableAuthMode AuthMode=VTableAuthMode::Authenticate)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
Definition CGClass.cpp:2727
void EmitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &S)
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E)
llvm::Value * EmitSVEPredicateCast(llvm::Value *Pred, llvm::ScalableVectorType *VTy)
Definition ARM.cpp:3524
StringRef AMDGPUAvailableVisibleMode
The mode string from the amdgpu_av attribute on the current statement, or empty if the attribute is n...
llvm::Value * EmitAVRBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition AVR.cpp:22
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
Produce the code for a CK_ARCConsumeObject.
Definition CGObjC.cpp:2173
llvm::Value * EmitFP8NeonFMLACall(unsigned IID, bool ExtendLaneArg, llvm::Type *RetTy, SmallVectorImpl< llvm::Value * > &Ops, const CallExpr *E, const char *name)
Definition ARM.cpp:548
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
void EmitBoundsCheckImpl(const Expr *ArrayExpr, QualType ArrayBaseType, llvm::Value *IndexVal, QualType IndexType, llvm::Value *BoundsVal, QualType BoundsType, bool Accessed)
Definition CGExpr.cpp:1303
void EmitRISCVMultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
void EmitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &S)
void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S)
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
Definition CGExpr.cpp:3444
void EmitCXXTryStmt(const CXXTryStmt &S)
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr, const VarDecl *ConditionalDecl=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
void setCurrentProfileCount(uint64_t Count)
Set the profiler's current count.
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID, bool EnsureInsertPoint=true)
Emit a call to trap or debugtrap.
Definition CGExpr.cpp:4746
llvm::Constant * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
Create a stub function, suitable for being passed to atexit, which passes the given address to the gi...
llvm::Value * EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType)
Autorelease the given object.
Definition CGObjC.cpp:2869
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
Definition CGObjC.cpp:591
llvm::Value * emitBoolVecConversion(llvm::Value *SrcVec, unsigned NumElementsDst, const llvm::Twine &Name="")
void EmitOMPLastprivateClauseFinal(const OMPExecutableDirective &D, bool NoFinals, llvm::Value *IsLastIterCond=nullptr)
Emit final copying of lastprivate values to original variables at the end of the worksharing or simd ...
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
CurrentSourceLocExprScope CurSourceLocExprScope
Source location information about the default argument or member initializer expression we're evaluat...
void EmitARCMoveWeak(Address dst, Address src)
void @objc_moveWeak(i8** dest, i8** src) Disregards the current value in dest.
Definition CGObjC.cpp:2713
llvm::BasicBlock * getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope)
void EmitAArch64MultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
llvm::GlobalVariable * EmitCheckStaticData(ArrayRef< llvm::Constant * > StaticArgs)
Emit a private unnamed_addr non-constant global containing static arguments for a UBSan runtime check...
Definition CGExpr.cpp:4222
void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, const FunctionArgList &Args)
Definition CGClass.cpp:2525
void processInReduction(const OMPExecutableDirective &S, OMPTaskDataTy &Data, CodeGenFunction &CGF, const CapturedStmt *CS, OMPPrivateScope &Scope)
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
Do a fused retain/autorelease of the given object.
Definition CGObjC.cpp:2620
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
Definition CGDecl.cpp:2487
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
Definition CGExpr.cpp:7041
void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, llvm::FunctionCallee Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID)
bool isBinaryLogicalOp(const Expr *E) const
llvm::Value * BuildVector(ArrayRef< llvm::Value * > Ops)
Definition ARM.cpp:7405
void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, const FunctionArgList &Args, SourceLocation Loc)
Definition CGClass.cpp:2468
void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
ActivateCleanupBlock - Activates an initially-inactive cleanup.
void emitByrefStructureInit(const AutoVarEmission &emission)
Initialize the structural components of a __block variable, i.e.
llvm::CallInst * EmitIntrinsicCall(llvm::Intrinsic::ID ID, ArrayRef< llvm::Value * > Args, llvm::Type *RetTy, const Twine &Name="")
llvm::Value * performAddrSpaceCast(llvm::Value *Src, llvm::Type *DestTy)
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E)
Definition CGExpr.cpp:6330
llvm::Value * EmitARCReclaimReturnedObject(const Expr *e, bool allowUnsafeClaim)
Definition CGObjC.cpp:3109
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
Definition CGObjC.cpp:3699
void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S)
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
Definition CGExpr.cpp:1422
void SetDivFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
Definition CGExpr.cpp:7449
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
EmitARCUnsafeUnretainedScalarExpr - Semantically equivalent to immediately releasing the resut of Emi...
Definition CGObjC.cpp:3638
llvm::Value * EmitObjCSelectorExpr(const ObjCSelectorExpr *E)
Emit a selector.
Definition CGObjC.cpp:275
llvm::Value * EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx, const CallExpr *E)
void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, bool CanThrow)
llvm::Function * createTLSAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr, llvm::FunctionCallee &AtExit)
Create a stub function, suitable for being passed to __pt_atexit_np, which passes the given address t...
SanitizerSet SanOpts
Sanitizers enabled for this function.
CodeGenUtils::EvaluationOrder EvaluationOrder
void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy, SourceLocation Loc)
static void EmitOMPTargetParallelDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelDirective &S)
void EmitAsanPrologueOrEpilogue(bool Prologue)
Definition CGClass.cpp:718
CounterForIncrement
Used to specify which counter in a pair shall be incremented.
void callCStructMoveConstructor(LValue Dst, LValue Src)
void EmitInlinedInheritingCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, bool ForVirtualBase, bool Delegating, CallArgList &Args)
Emit a call to an inheriting constructor (that is, one that invokes a constructor inherited from a ba...
Definition CGClass.cpp:2367
void pushStackRestore(CleanupKind kind, Address SPMem)
Definition CGDecl.cpp:2414
LValue EmitInitListLValue(const InitListExpr *E)
Definition CGExpr.cpp:6212
bool isUnderlyingBasePointerConstantNull(const Expr *E)
Check whether the underlying base pointer is a constant null.
Definition CGExpr.cpp:5784
llvm::DenseMap< const VarDecl *, llvm::Value * > NRVOFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
bool IsOutlinedSEHHelper
True if the current function is an outlined SEH helper.
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
Definition CGObjC.cpp:2684
void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S)
Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
Definition CGExpr.cpp:5175
llvm::Value * EmitSVEStructLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3699
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
llvm::Value * EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID, bool IsZExtReturn)
Definition ARM.cpp:3808
void EmitPPCAIXMultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
define internal ptr @foo.resolver() { entry: is_version_1 = __builtin_cpu_supports(version_1) br i1 %...
bool ShouldSkipSanitizerInstrumentation()
ShouldSkipSanitizerInstrumentation - Return true if the current function should not be instrumented w...
llvm::Value * EmitPPCBuiltinCpu(unsigned BuiltinID, llvm::Type *ReturnType, StringRef CPUStr)
Definition PPC.cpp:73
llvm::Value * EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
Definition CGObjC.cpp:269
void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef< const Attr * > Attrs={})
Definition CGStmt.cpp:1402
void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective &S)
SmallVector< Address, 1 > SEHCodeSlotStack
A stack of exception code slots.
JumpDest getJumpDestInCurrentScope(StringRef Name=StringRef())
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
llvm::Value * EmitFP8NeonCall(unsigned IID, ArrayRef< llvm::Type * > Tys, SmallVectorImpl< llvm::Value * > &O, const CallExpr *E, const char *name)
Definition ARM.cpp:523
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
Definition CGExpr.cpp:7073
llvm::Value * GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD, const FieldDecl *CountDecl)
Definition CGExpr.cpp:1223
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
void VolatilizeTryBlocks(llvm::BasicBlock *BB, llvm::SmallPtrSet< llvm::BasicBlock *, 10 > &V)
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
llvm::Value * EmitRISCVCpuSupports(const CallExpr *E)
Definition RISCV.cpp:976
void EmitOMPScanDirective(const OMPScanDirective &S)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
llvm::BasicBlock * getInvokeDestImpl()
llvm::Value * EmitRISCVCpuInit()
Definition RISCV.cpp:966
const CastExpr * CurCast
If a cast expression is being visited, this holds the current cast's expression.
static bool hasScalarEvaluationKind(QualType T)
llvm::Type * ConvertType(QualType T)
bool isCleanupPadScope() const
Returns true while emitting a cleanuppad.
llvm::Value * EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx)
void EmitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &S)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
Address EmitCXXUuidofExpr(const CXXUuidofExpr *E)
Definition CGExpr.cpp:7054
AwaitSuspendWrapperInfo CurAwaitSuspendWrapper
void EmitFakeUse(Address Addr)
Definition CGDecl.cpp:1397
llvm::function_ref< std::pair< llvm::Value *, llvm::Value * >(CodeGenFunction &, const OMPExecutableDirective &S, Address LB, Address UB)> CodeGenDispatchBoundsTy
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
LValue InitCapturedStruct(const CapturedStmt &S)
Definition CGStmt.cpp:3552
void EmitOMPFlattenDirective(const OMPFlattenDirective &S)
void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
Add KeyInstruction and an optional Backup instruction to a new atom group (See ApplyAtomGroup for mor...
CGCapturedStmtInfo * CapturedStmtInfo
void EmitOMPDistributeDirective(const OMPDistributeDirective &S)
BuiltinCheckKind
Specifies which type of sanitizer check to apply when handling a particular builtin.
Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, Address ParentVar, llvm::Value *ParentFP)
Recovers the address of a local in a parent function.
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
llvm::Value * EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3663
llvm::Value * EmitObjCProtocolExpr(const ObjCProtocolExpr *E)
Definition CGObjC.cpp:283
void EmitOMPParallelForDirective(const OMPParallelForDirective &S)
llvm::CallBase * EmitCallOrInvoke(llvm::FunctionCallee Callee, ArrayRef< llvm::Value * > Args, const Twine &Name="")
Emits a call or invoke instruction to the given function, depending on the current state of the EH st...
Definition CGCall.cpp:5585
llvm::Value * EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition SystemZ.cpp:86
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroy - Push the standard destructor for the given type as an EH-only cleanup.
Definition CGDecl.cpp:2360
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
Emits a call or invoke to the given noreturn runtime function.
Definition CGCall.cpp:5548
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="", bool IsConvergent=false)
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
Definition CGCall.cpp:5575
RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, bool HasQualifier, NestedNameSpecifier Qualifier, bool IsArrow, const Expr *Base, llvm::CallBase **CallOrInvoke)
PeepholeProtection protectFromPeepholes(RValue rvalue)
protectFromPeepholes - Protect a value that we're intending to store to the side, but which will prob...
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
void EmitOMPMasterDirective(const OMPMasterDirective &S)
llvm::Value * EmitSEHAbnormalTermination()
void EmitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &S)
RValue emitStdcFirstBit(const CallExpr *E, llvm::Intrinsic::ID IntID, bool InvertArg)
llvm::Value * EmitARCAutoreleaseReturnValue(llvm::Value *value)
Autorelease the given object.
Definition CGObjC.cpp:2610
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
Produce the code to do a retain.
Definition CGObjC.cpp:2349
llvm::Value * EmitPointerAuthQualify(PointerAuthQualifier Qualifier, llvm::Value *Pointer, QualType ValueType, Address StorageAddress, bool IsKnownNonNull)
void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
Definition CGClass.cpp:2854
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
Definition CGClass.cpp:3107
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
llvm::Value * EmitARCAutorelease(llvm::Value *value)
Autorelease the given object.
Definition CGObjC.cpp:2601
void EmitOMPSimdInit(const OMPLoopDirective &D)
Helpers for the OpenMP loop directives.
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
Definition CGObjC.cpp:3528
llvm::Value * EmitSMEReadWrite(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3954
llvm::Type * SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags)
SVEBuiltinMemEltTy - Returns the memory element type for this memory access builtin.
Definition ARM.cpp:3390
const OMPExecutableDirective * OMPParentLoopDirectiveForScan
Parent loop-based directive for scan directive.
llvm::Value * EmitSVEScatterStore(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3617
void EmitOpenACCInitConstruct(const OpenACCInitConstruct &S)
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
void EmitAtomicInit(Expr *E, LValue lvalue)
void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD, CallArgList &CallArgs)
Definition CGClass.cpp:3129
void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src, ExprValueKind SrcKind)
EmitAggFinalDestCopy - Emit copy of the specified aggregate into destination address.
void AddAMDGPUAvailableVisibleMMRA(llvm::Instruction *Inst)
Attach the AMDGPU availability/visibility MMRA to Inst when the amdgpu_av attribute is active on the ...
Definition AMDGPU.cpp:517
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
Definition CGObjC.cpp:2702
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
Definition CGClass.cpp:283
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
void EmitOMPFlushDirective(const OMPFlushDirective &S)
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst)
Definition CGExpr.cpp:3141
llvm::Value * EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart)
Emits a call to an LLVM variable-argument intrinsic, either llvm.va_start or llvm....
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
static void EmitOMPTargetDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetDirective &S)
Emit device code for the target directive.
llvm::Value * EmitSVEMaskedStore(const CallExpr *, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
Definition ARM.cpp:3865
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
Definition CGExpr.cpp:4009
bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
Definition CGObjC.cpp:2888
void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S)
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
Definition CGStmt.cpp:713
void EmitCoreturnStmt(const CoreturnStmt &S)
void EmitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &S)
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
Definition CGDecl.cpp:2687
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
SmallVector< llvm::ConvergenceControlInst *, 4 > ConvergenceTokenStack
Stack to track the controlled convergence tokens.
RValue emitStdcBitWidthMinus(const CallExpr *E, llvm::Intrinsic::ID IntID, bool IsPop)
static void EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDirective &S)
Emit device code for the target teams directive.
llvm::Value * EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition AMDGPU.cpp:599
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
Definition CGExpr.cpp:6180
bool isSEHTryScope() const
Returns true inside SEH __try blocks.
void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Call atexit() with a function that passes the given argument to the given function.
llvm::Value * EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType)
Definition CGObjC.cpp:2826
void unprotectFromPeepholes(PeepholeProtection protection)
void EmitOMPReductionClauseInit(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope, bool ForInscan=false)
Emit initial code for reduction variables.
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S)
Definition CGObjC.cpp:2150
void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S)
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Given the address of a temporary variable, produce an r-value of its type.
Definition CGExpr.cpp:7401
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
Definition CGExpr.cpp:3062
llvm::Value * EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition ARM.cpp:4507
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
Definition CGDecl.cpp:1368
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
Definition CGExpr.cpp:4170
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
Definition CGObjC.cpp:2937
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
Definition CGExpr.cpp:7059
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
void EmitAutoVarInit(const AutoVarEmission &emission)
Definition CGDecl.cpp:2020
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
void SetSqrtFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
Definition CGExpr.cpp:7427
static void EmitOMPTargetTeamsDistributeDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeDirective &S)
Emit device code for the target teams distribute directive.
RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)
Emit a CallExpr without considering whether it might be a subclass.
Definition CGExpr.cpp:6724
llvm::SmallVector< BypassingForwardJump, 4 > BypassingForwardJumps
llvm::SmallVector< DeferredDeactivateCleanup > DeferredDeactivationCleanupStack
RValue EmitVAArg(VAArgExpr *VE, Address &VAListAddr, AggValueSlot Slot=AggValueSlot::ignored())
Generate code to get an argument from the passed in pointer and update it accordingly.
Definition CGCall.cpp:6957
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
Definition CGExpr.cpp:742
void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, CallArgList &CallArgs, const CGFunctionInfo *CallOpFnInfo=nullptr, llvm::Constant *CallOpFn=nullptr)
Definition CGClass.cpp:3034
void EmitReturnValueCheck(llvm::Value *RV)
Emit a test that checks if the return value RV is nonnull.
Definition CGCall.cpp:4619
llvm::Value * getAsNaturalPointerTo(Address Addr, QualType PointeeType)
bool EmitSimpleStmt(const Stmt *S, ArrayRef< const Attr * > Attrs)
EmitSimpleStmt - Try to emit a "simple" statement which does not necessarily require an insertion poi...
Definition CGStmt.cpp:526
RValue emitBuiltinOSLogFormat(const CallExpr &E)
Emit IR for __builtin_os_log_format.
llvm::Function * GenerateOpenMPCapturedStmtFunctionAggregate(const CapturedStmt &S, const OMPExecutableDirective &D)
llvm::Value * emitPointerAuthResignCall(llvm::Value *Pointer, const CGPointerAuthInfo &CurInfo, const CGPointerAuthInfo &NewInfo)
void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S)
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
Definition CGExpr.cpp:7560
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
Definition CGCall.cpp:4729
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void FinishObjCDirectPreconditionThunk()
Finish an Objective-C direct method thunk.
void EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S)
void maybeUpdateMCDCTestVectorBitmap(const Expr *E)
Increment the profiler's counter for the given expression by StepV.
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual)
Determine whether a base class initialization may overlap some other object.
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
llvm::Value * EmitObjCArrayLiteral(const ObjCArrayLiteral *E)
Definition CGObjC.cpp:265
llvm::Function * generateBuiltinOSLogHelperFunction(const analyze_os_log::OSLogBufferLayout &Layout, CharUnits BufferAlignment)
llvm::Value * EmitPromotedScalarExpr(const Expr *E, QualType PromotionType)
const LangOptions & getLangOpts() const
void addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup, uint64_t Atom)
See CGDebugInfo::addInstToSpecificSourceAtom.
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
Definition CGExpr.cpp:4551
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
Definition CGExpr.cpp:705
llvm::Value * EmitARCRetainAutorelease(QualType type, llvm::Value *value)
Do a fused retain/autorelease of the given object.
Definition CGObjC.cpp:2632
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
Store into a strong object.
Definition CGObjC.cpp:2566
llvm::Value * EmitARCRetainAutoreleasedReturnValue(llvm::Value *value)
Retain the given object which is the result of a function call.
Definition CGObjC.cpp:2484
bool isPointerKnownNonNull(const Expr *E)
void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD)
StartObjCMethod - Begin emission of an ObjCMethod.
Definition CGObjC.cpp:770
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
EmitAutoVarAlloca - Emit the alloca and debug information for a local variable.
Definition CGDecl.cpp:1499
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
Definition CGExpr.cpp:7378
llvm::Value * EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value)
Claim a possibly-autoreleased return value at +0.
Definition CGObjC.cpp:2496
llvm::Value * EmitObjCMRRAutoreleasePoolPush()
Produce the code to do an MRR version objc_autoreleasepool_push.
Definition CGObjC.cpp:2785
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
void EmitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &S)
LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)
Definition CGExpr.cpp:7107
void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, const llvm::function_ref< RValue(RValue)> &UpdateOp, bool IsVolatile)
bool InNoConvergentAttributedStmt
True if the current statement has noconvergent attribute.
static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
Definition CGClass.cpp:670
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor)
Definition CGObjC.cpp:1773
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, Address Addr, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
Definition CGClass.cpp:390
llvm::Value * EmitObjCAllocWithZone(llvm::Value *value, llvm::Type *returnType)
Allocate the given objc object.
Definition CGObjC.cpp:2819
void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E)
Definition CGExpr.cpp:6312
void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, SVETypeFlags TypeFlags)
Definition ARM.cpp:4093
void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for RD using llvm....
Definition CGClass.cpp:2915
llvm::Value * EmitSVEGatherLoad(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3575
llvm::Function * GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info, const DeclMapTy &ldm, bool IsLambdaConversionToBlock, bool BuildGlobalBlock)
void EmitCountedByBoundsChecking(const Expr *ArrayExpr, QualType ArrayType, Address ArrayInst, QualType IndexType, llvm::Value *IndexVal, bool Accessed, bool FlexibleArray)
EmitCountedByBoundsChecking - If the array being accessed has a "counted_by" attribute,...
Definition CGExpr.cpp:5101
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
bool IsInPreserveFieldInfo
True if CodeGen currently emits the argument of __builtin_preserve_field_info.
llvm::Function * LookupNeonLLVMIntrinsic(unsigned IntrinsicID, unsigned Modifier, llvm::Type *ArgTy, const CallExpr *E)
Definition ARM.cpp:1088
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
Definition CGDecl.cpp:2370
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition CGDecl.cpp:805
void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc)
Given an assignment *LHS = RHS, emit a test that checks if RHS is nonnull, if LHS is marked _Nonnull.
Definition CGDecl.cpp:778
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
Definition CGClass.cpp:781
const CodeGen::CGBlockInfo * BlockInfo
void EmitKCFIOperandBundle(const CGCallee &Callee, SmallVectorImpl< llvm::OperandBundleDef > &Bundles)
llvm::Value * EmitPointerAuthUnqualify(PointerAuthQualifier Qualifier, llvm::Value *Pointer, QualType PointerType, Address StorageAddress, bool IsKnownNonNull)
void EmitAggregateCopyCtor(LValue Dest, LValue Src, AggValueSlot::Overlap_t MayOverlap)
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
static void EmitOMPTargetSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPLoopDirective &S)
Emit device code for the target simd and target loop directives.
Address makeNaturalAddressForPointer(llvm::Value *Ptr, QualType T, CharUnits Alignment=CharUnits::Zero(), bool ForPointeeType=false, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
Construct an address with the natural alignment of T.
void EmitOpenACCWaitConstruct(const OpenACCWaitConstruct &S)
llvm::AllocaInst * EHSelectorSlot
The selector slot.
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Load a pointer with type PtrTy stored at address Ptr.
Definition CGExpr.cpp:3453
LValue MakeNaturalAlignPointeeRawAddrLValue(llvm::Value *V, QualType T)
Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known to be unsigned.
llvm::BasicBlock * EmitLandingPad()
Emits a landing pad for the current EH stack.
void EmitLambdaInAllocaImplFn(const CXXMethodDecl *CallOp, const CGFunctionInfo **ImplFnInfo, llvm::Function **ImplFn)
Definition CGClass.cpp:3183
llvm::Constant * GenerateCopyHelperFunction(const CGBlockInfo &blockInfo)
Generate the copy-helper function for a block closure object: static void block_copy_helper(block_t *...
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization=false)
EmitCXXAggrConstructorCall - Emit a loop to call a particular constructor for each of several members...
Definition CGClass.cpp:2034
std::pair< RValue, llvm::Value * > EmitAtomicCompareExchange(LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, llvm::AtomicOrdering Success=llvm::AtomicOrdering::SequentiallyConsistent, llvm::AtomicOrdering Failure=llvm::AtomicOrdering::SequentiallyConsistent, bool IsWeak=false, AggValueSlot Slot=AggValueSlot::ignored())
Emit a compare-and-exchange op for atomic type.
CurrentSourceLocExprScope::SourceLocExprScopeGuard SourceLocExprScopeGuard
void EmitBlockAfterUses(llvm::BasicBlock *BB)
EmitBlockAfterUses - Emit the given block somewhere hopefully near its uses, and leave the insertion ...
Definition CGStmt.cpp:696
RValue EmitLoadOfGlobalRegLValue(LValue LV)
Load of global named registers are always calls to intrinsics.
Definition CGExpr.cpp:2777
VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass)
Definition CGClass.cpp:2647
void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull, CFITypeCheckKind TCK, SourceLocation Loc)
Derived is the presumed address of an object of type T after a cast.
Definition CGClass.cpp:2868
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
@ TCK_DowncastPointer
Checking the operand of a static_cast to a derived pointer type.
@ TCK_DowncastReference
Checking the operand of a static_cast to a derived reference type.
@ TCK_MemberAccess
Checking the object expression in a non-static data member access.
@ TCK_ConstructorCall
Checking the 'this' pointer for a constructor call.
@ TCK_Store
Checking the destination of a store. Must be suitably sized and aligned.
@ TCK_NonnullAssign
Checking the value assigned to a _Nonnull pointer. Must not be null.
@ TCK_UpcastToVirtualBase
Checking the operand of a cast to a virtual base object.
@ TCK_MemberCall
Checking the 'this' pointer for a call to a non-static member function.
@ TCK_DynamicOperation
Checking the operand of a dynamic_cast or a typeid expression.
@ TCK_ReferenceBinding
Checking the bound value in a reference binding.
@ TCK_Load
Checking the operand of a load. Must be suitably sized and aligned.
@ TCK_Upcast
Checking the operand of a cast to a base object.
llvm::Type * getEltType(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3406
void SimplifyForwardingBlocks(llvm::BasicBlock *BB)
SimplifyForwardingBlocks - If the given basic block is only a branch to another basic block,...
Definition CGStmt.cpp:637
static std::string getNonTrivialDestructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
llvm::Value * EmitObjCThrowOperand(const Expr *expr)
Definition CGObjC.cpp:3562
void EmitOMPSplitDirective(const OMPSplitDirective &S)
DeclMapTy::iterator localDeclMapEnd()
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
Definition CGClass.cpp:2550
LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
BuildByrefInfo - This routine changes a __block variable declared as T x into:
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
void EmitOMPReductionClauseFinal(const OMPExecutableDirective &D, const OpenMPDirectiveKind ReductionKind)
Emit final update of reduction values to original variables at the end of the directive.
llvm::Value * EmitCommonNeonBuiltinExpr(unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, const char *NameHint, unsigned Modifier, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, Address PtrOp0, Address PtrOp1, llvm::Triple::ArchType Arch)
Definition ARM.cpp:1196
llvm::Value * EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
Definition RISCV.cpp:1079
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
Definition CGExpr.cpp:6884
bool InNoMergeAttributedStmt
True if the current statement has nomerge attribute.
void StartObjCDirectPreconditionThunk(const ObjCMethodDecl *OMD, llvm::Function *Fn, const CGFunctionInfo &FI)
Start an Objective-C direct method thunk.
llvm::Value * EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx, const llvm::ElementCount &Count)
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push a NormalAndEHCleanup to destroy already-constructed elements ...
Definition CGDecl.cpp:2671
llvm::Value * EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind)
Emits an argument for a call to a builtin.
void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit)
Helper for the OpenMP loop directives.
Address EmitCheckedInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *elementType, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, CharUnits Align, const Twine &Name="")
void EmitOMPScopeDirective(const OMPScopeDirective &S)
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
LValue MakeAddrLValueWithoutTBAA(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool hasSkipCounter(const Stmt *S) const
llvm::BasicBlock * getUnreachableBlock()
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition CGDecl.cpp:2343
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy)
Emit an aggregate assignment.
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
Definition CGObjC.cpp:2502
void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty, SourceLocation Loc)
Definition CGExpr.cpp:2119
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
void EmitBitfieldConversionCheck(llvm::Value *Src, QualType SrcType, llvm::Value *Dst, QualType DstType, const CGBitFieldInfo &Info, SourceLocation Loc)
Emit a check that an [implicit] conversion of a bitfield.
void PushDestructorCleanup(QualType T, Address Addr)
PushDestructorCleanup - Push a cleanup to call the complete-object destructor of an object of the giv...
Definition CGClass.cpp:2581
llvm::SmallVector< const JumpDest *, 2 > SEHTryEpilogueStack
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
void EmitFunctionBody(const Stmt *Body)
JumpDest ReturnBlock
ReturnBlock - Unified return block.
void EmitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &S)
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, const CGCallee &Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, CallArgList *RtlArgs, llvm::CallBase **CallOrInvoke)
Definition CGExprCXX.cpp:86
DominatingValue< T >::saved_type saveValueInCond(T value)
void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, llvm::Value *ParentFP, llvm::Value *EntryEBP)
const llvm::function_ref< void(CodeGenFunction &, llvm::Function *, const OMPTaskDataTy &)> TaskGenTy
std::pair< LValue, llvm::Value * > EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored)
Definition CGObjC.cpp:3649
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
llvm::Value * ExceptionSlot
The exception slot.
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
Definition CGExpr.cpp:7565
ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType)
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
Definition CGExpr.cpp:4051
void CreateCoercedStore(llvm::Value *Src, QualType SrcFETy, Address Dst, llvm::TypeSize DstSize, bool DstIsVolatile)
Create a store to.
Definition CGCall.cpp:1792
void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee, const ThunkInfo *Thunk, bool IsUnprototyped)
bool EmitOMPCopyinClause(const OMPExecutableDirective &D)
Emit code for copyin clause in D directive.
llvm::Value * EmitSVEDupX(llvm::Value *Scalar)
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
Definition CGExpr.cpp:6568
void EmitOMPLinearClause(const OMPLoopDirective &D, CodeGenFunction::OMPPrivateScope &PrivateScope)
Emit initial code for linear clauses.
llvm::Value * LoadPassedObjectSize(const Expr *E, QualType EltTy)
If E references a parameter with pass_object_size info or a constant array size modifier,...
Definition CGExpr.cpp:984
void EmitAnyExprToExn(const Expr *E, Address Addr)
LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, llvm::Value *&Result)
llvm::BasicBlock * OMPBeforeScanBlock
void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S)
void EmitOMPPrivateLoopCounters(const OMPLoopDirective &S, OMPPrivateScope &LoopScope)
Emit initial code for loop counters of loop-based directives.
llvm::ConvergenceControlInst * emitConvergenceLoopToken(llvm::BasicBlock *BB)
Definition CGStmt.cpp:3692
llvm::SmallPtrSet< const CXXRecordDecl *, 4 > VisitedVirtualBasesSetTy
void GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCGetter - Synthesize an Objective-C property getter function.
Definition CGObjC.cpp:1065
llvm::Value * EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
Definition CGExpr.cpp:7099
void initFullExprCleanupWithFlag(RawAddress ActiveFlag)
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
void pushCleanupAndDeferDeactivation(CleanupKind Kind, As... A)
llvm::DebugLoc EmitReturnBlock()
Emit the unified return block, trying to avoid its emission when possible.
void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, AbstractCallee AC, unsigned ParmNum)
Create a check for a function parameter that may potentially be declared as non-null.
Definition CGCall.cpp:5020
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
Definition CGExpr.cpp:2531
void EmitBPFRelocatedCaseStmt(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
Emit a case statement whose value is relocated: move the switch to a new block, and in its old block,...
Definition CGStmt.cpp:1802
llvm::BasicBlock * getEHResumeBlock(bool isCleanup)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
llvm::DenseMap< const Decl *, Address > DeclMapTy
LValue EmitLValueForField(LValue Base, const FieldDecl *Field, bool IsInBounds=true)
Definition CGExpr.cpp:5996
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
Definition CGExpr.cpp:187
const TargetInfo & getTarget() const
RValue emitRotate(const CallExpr *E, bool IsRotateRight)
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
llvm::Value * EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition ARM.cpp:4136
llvm::Function * getSpecConstantFunction(const clang::QualType &SpecConstantType)
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
llvm::Value * EmitAnnotationCall(llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location, const AnnotateAttr *Attr)
Emit an annotation call (intrinsic).
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition CGDecl.cpp:418
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
llvm::Value * EmitFP8NeonCvtCall(unsigned IID, llvm::Type *Ty0, llvm::Type *Ty1, bool Extract, SmallVectorImpl< llvm::Value * > &Ops, const CallExpr *E, const char *name)
Definition ARM.cpp:569
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
Definition CGStmt.cpp:588
void pushKmpcAllocFree(CleanupKind Kind, std::pair< llvm::Value *, llvm::Value * > AddrSizePair)
Definition CGDecl.cpp:2419
void GenerateOpenMPCapturedVars(const CapturedStmt &S, SmallVectorImpl< llvm::Value * > &CapturedVars)
llvm::Value * EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty)
Definition CGObjC.cpp:3973
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, bool IsInBounds, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Emit the address of a field using a member data pointer.
Definition CGClass.cpp:152
void EmitGotoStmt(const GotoStmt &S)
Definition CGStmt.cpp:859
llvm::BasicBlock * getTerminateHandler()
getTerminateHandler - Return a handler (not a landing pad, just a catch handler) that just calls term...
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, std::initializer_list< llvm::Value ** > ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
void EmitOMPDepobjDirective(const OMPDepobjDirective &S)
DeclMapTy::iterator findLocalDecl(const Decl *D)
Accessors for LocalDeclMap.
void maybeCreateMCDCCondBitmap()
Allocate a temp value on the stack that MCDC can use to track condition results.
void EmitOMPMetaDirective(const OMPMetaDirective &S)
llvm::Value * EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
Definition ARM.cpp:2257
void emitReturnAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
Definition CGExpr.cpp:747
CGCallee EmitCallee(const Expr *E)
Definition CGExpr.cpp:6792
void EmitWritebacks(const CallArgList &Args)
EmitWriteback - Emit callbacks for function.
Definition CGCall.cpp:5312
void EmitOMPCriticalDirective(const OMPCriticalDirective &S)
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
Definition CGExpr.cpp:263
void EnterSEHTryStmt(const SEHTryStmt &S)
llvm::Value * EmitRISCVCpuIs(const CallExpr *E)
Definition RISCV.cpp:1038
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot(), llvm::CallBase **CallOrInvoke=nullptr)
Definition CGExpr.cpp:6674
llvm::ScalableVectorType * getSVEType(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3479
void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
Definition CGExpr.cpp:2549
void EmitOMPCancelDirective(const OMPCancelDirective &S)
std::pair< DeclMapTy::iterator, bool > insertLocalDecl(const Decl *D, Address Addr)
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
Definition CGDecl.cpp:2395
LValue EmitMatrixSingleSubscriptExpr(const MatrixSingleSubscriptExpr *E)
Definition CGExpr.cpp:5429
LValue EmitArraySectionExpr(const ArraySectionExpr *E, bool IsLowerBound=true)
Definition CGExpr.cpp:5522
const Expr * RetExpr
If a return statement is being visited, this holds the return statment's result expression.
Address GetAddrOfBlockDecl(const VarDecl *var)
void EmitOMPBarrierDirective(const OMPBarrierDirective &S)
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
static bool isInstrumentedCondition(const Expr *C)
isInstrumentedCondition - Determine whether the given condition is an instrumentable condition (i....
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
Definition CGObjC.cpp:2531
void pushCleanupAfterFullExpr(CleanupKind Kind, As... A)
Queue a cleanup to be pushed after finishing the current full-expression, potentially with an active ...
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
Definition CGExpr.cpp:4513
void callCStructCopyAssignmentOperator(LValue Dst, LValue Src)
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
llvm::Value * EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition ARM.cpp:7291
RawAddress CreateIRTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateIRTempWithoutCast - Create a temporary IR object of the given type, with appropriate alignment.
Definition CGExpr.cpp:194
bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB, const CodeGenLoopBoundsTy &CodeGenLoopBounds, const CodeGenDispatchBoundsTy &CGDispatchBounds)
Emit code for the worksharing loop-based directive.
void EmitForStmt(const ForStmt &S, ArrayRef< const Attr * > Attrs={})
Definition CGStmt.cpp:1250
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
Definition CGCXX.cpp:359
void pushFullExprCleanup(CleanupKind kind, As... A)
pushFullExprCleanup - Push a cleanup to be run at the end of the current full-expression.
bool AlwaysEmitXRayCustomEvents() const
AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit XRay custom event handling c...
void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type)
EnterDtorCleanups - Enter the cleanups necessary to complete the given phase of destruction for a des...
Definition CGClass.cpp:1898
llvm::Value * EmitSMELdrStr(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3976
LValue EmitOMPSharedLValue(const Expr *E)
Emits the lvalue for the expression with possibly captured variable.
QualType TypeOfSelfObject()
TypeOfSelfObject - Return type of object that this self represents.
Definition CGObjC.cpp:1817
std::array< llvm::Constant *, 3 > EmitCFICheckFailStaticArgs(CFITypeCheckKind CheckKind, SourceLocation Loc, QualType Type)
Build the static argument array {CheckKind, SourceLocation, TypeDescriptor} for a UBSan CFICheckFail ...
Definition CGExpr.cpp:4502
llvm::CanonicalLoopInfo * EmitOMPCollapsedCanonicalLoopNest(const Stmt *S, int Depth)
Emit the Stmt S and return its topmost canonical loop, if any.
void EmitOMPSectionsDirective(const OMPSectionsDirective &S)
void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S)
Definition CGObjC.cpp:3708
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
void EmitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation &S)
Definition CGStmt.cpp:1506
void EmitOMPInteropDirective(const OMPInteropDirective &S)
void SetFPAccuracy(llvm::Value *Val, float Accuracy)
SetFPAccuracy - Set the minimum required accuracy of the given floating point operation,...
Definition CGExpr.cpp:7416
Address mergeAddressesInConditionalExpr(Address LHS, Address RHS, llvm::BasicBlock *LHSBlock, llvm::BasicBlock *RHSBlock, llvm::BasicBlock *MergeBlock, QualType MergedType)
Address emitAddrOfImagComponent(Address complex, QualType complexType)
llvm::Value * EmitPointerAuthSign(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
llvm::Value * EmitSVETupleCreate(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
Definition ARM.cpp:4081
void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S)
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
Definition CGClass.cpp:2172
llvm::Value * EmitSVEPMull(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
Definition ARM.cpp:3762
llvm::Value * EmitObjCBoxedExpr(const ObjCBoxedExpr *E)
EmitObjCBoxedExpr - This routine generates code to call the appropriate expression boxing method.
Definition CGObjC.cpp:65
void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S)
void EmitBoundsCheck(const Expr *ArrayExpr, const Expr *ArrayExprBase, llvm::Value *Index, QualType IndexType, bool Accessed)
Emit a check that Base points into an array object, which we can access at index Index.
Definition CGExpr.cpp:1287
void EmitOMPCopy(QualType OriginalType, Address DestAddr, Address SrcAddr, const VarDecl *DestVD, const VarDecl *SrcVD, const Expr *Copy)
Emit proper copying of data from one variable to another.
void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
Annotate the function with an attribute that disables TSan checking at runtime.
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
Definition CGExpr.cpp:244
void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType)
EmitCallArg - Emit a single call argument.
Definition CGCall.cpp:5317
void maybeResetMCDCCondBitmap(const Expr *E)
Zero-init the MCDC temp value.
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
void EmitWhileStmt(const WhileStmt &S, ArrayRef< const Attr * > Attrs={})
Definition CGStmt.cpp:1048
JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind)
void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, const ObjCPropertyImplDecl *propImpl, llvm::Constant *AtomicHelperFn)
Definition CGObjC.cpp:1489
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function * > CXXThreadLocals, ConstantAddress Guard=ConstantAddress::invalid())
GenerateCXXGlobalInitFunc - Generates code for initializing global variables.
llvm::Value * EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition PPC.cpp:205
LValue EmitPredefinedLValue(const PredefinedExpr *E)
Definition CGExpr.cpp:4014
void EmitPointerAuthOperandBundle(const CGPointerAuthInfo &Info, SmallVectorImpl< llvm::OperandBundleDef > &Bundles)
void EmitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &S)
void EmitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &S)
Emit combined directive 'target parallel loop' as if its constituent constructs are 'target',...
void EmitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &S)
void EmitOMPUseDeviceAddrClause(const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope, const llvm::DenseMap< const ValueDecl *, llvm::Value * > CaptureDeviceAddrMap)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerKind::SanitizerOrdinal > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs, const TrapReason *TR=nullptr)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
Definition CGExpr.cpp:4333
void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit)
Emit the code necessary to initialize the given global variable.
llvm::Value * EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty)
void EmitExtendGCLifetime(llvm::Value *object)
EmitExtendGCLifetime - Given a pointer to an Objective-C object, make sure it survives garbage collec...
Definition CGObjC.cpp:3736
void ResolveBranchFixups(llvm::BasicBlock *Target)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
Definition CGExpr.cpp:3691
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
void EmitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &S)
LValue EmitStringLiteralLValue(const StringLiteral *E)
Definition CGExpr.cpp:4004
llvm::Value * EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
Definition ARM.cpp:3123
void EmitOMPMaskedDirective(const OMPMaskedDirective &S)
Address getAsNaturalAddressOf(Address Addr, QualType PointeeTy)
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset, SourceLocation Loc)
Emit a type checked load from the given vtable.
Definition CGClass.cpp:3002
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
llvm::CallInst * EmitIntrinsicCall(llvm::Intrinsic::ID ID, const Twine &Name="")
bool checkIfLoopMustProgress(const Expr *, bool HasEmptyBody)
Returns true if a loop must make progress, which means the mustprogress attribute can be added.
Definition CGStmt.cpp:1040
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
Definition CGExpr.cpp:6627
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke=nullptr, bool IsMustTail=false)
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
void callCStructCopyConstructor(LValue Dst, LValue Src)
void EmitOMPAggregateAssign(Address DestAddr, Address SrcAddr, QualType OriginalType, const llvm::function_ref< void(Address, Address)> CopyGen)
Perform element by element copying of arrays with type OriginalType from SrcAddr to DestAddr using co...
Address getExceptionSlot()
Returns a pointer to the function's exception object and selector slot, which is assigned in every la...
void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, llvm::BasicBlock *InitBlock, llvm::BasicBlock *NoInitBlock, GuardKind Kind, const VarDecl *D)
Emit a branch to select whether or not to perform guarded initialization.
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
void EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S)
llvm::Function * GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
bool AlwaysEmitXRayTypedEvents() const
AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit XRay typed event handling ...
void EmitOMPOrderedBlockAssocDirective(const OMPOrderedBlockAssocDirective &S)
void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This)
Emit assumption load for all bases.
Definition CGClass.cpp:2433
llvm::Value * EmitARCRetainBlock(llvm::Value *value, bool mandatory)
Retain the given block, with _Block_copy semantics.
Definition CGObjC.cpp:2370
llvm::Value * EmitObjCCollectionLiteral(const Expr *E, const ObjCMethodDecl *MethodWithObjects)
Definition CGObjC.cpp:132
llvm::BasicBlock * getTerminateFunclet()
getTerminateLandingPad - Return a cleanup funclet that just calls terminate.
void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size)
llvm::Value * EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, llvm::Type *Ty, bool usgn, const char *name)
Definition ARM.cpp:585
llvm::BasicBlock * getTerminateLandingPad()
getTerminateLandingPad - Return a landing pad that just calls terminate.
void EmitOMPDistributeLoop(const OMPLoopDirective &S, const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr)
Emit code for the distribute loop-based directive.
llvm::Function * GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, const SEHFinallyStmt &Finally)
llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)
Definition CGExpr.cpp:2061
void AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst, const CallExpr *E)
Definition AMDGPU.cpp:497
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S)
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
EmitARCRetainScalarExpr - Semantically equivalent to EmitARCRetainObject(e->getType(),...
Definition CGObjC.cpp:3513
void EmitOMPReverseDirective(const OMPReverseDirective &S)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
bool EmitLifetimeStart(llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
Definition CGDecl.cpp:1376
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
void popCatchScope()
popCatchScope - Pops the catch scope at the top of the EHScope stack, emitting any required code (oth...
LValue EmitUnsupportedLValue(const Expr *E, const char *Name)
EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...
Definition CGExpr.cpp:1710
void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S)
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
Definition CGClass.cpp:1419
void EmitOpenACCDataConstruct(const OpenACCDataConstruct &S)
LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
Same as MakeAddrLValue above except that the pointer is known to be unsigned.
llvm::MDNode * buildAllocToken(QualType AllocType)
Build metadata used by the AllocToken instrumentation.
Definition CGExpr.cpp:1368
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)
void EmitX86MultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
Definition CGExpr.cpp:6155
llvm::Value * EmitBlockLiteral(const BlockExpr *)
Emit block literal.
Definition CGBlocks.cpp:762
void EmitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &S)
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
Definition CGExpr.cpp:2261
Address GetAddressOfDirectBaseInCompleteClass(Address Value, const CXXRecordDecl *Derived, const CXXRecordDecl *Base, bool BaseIsVirtual)
GetAddressOfBaseOfCompleteClass - Convert the given pointer to a complete class to the given direct b...
Definition CGClass.cpp:216
void EmitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &S)
Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward=true)
BuildBlockByrefAddress - Computes the location of the data in a variable which is declared as __block...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
Definition CGExpr.cpp:164
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
Definition CGObjC.cpp:2146
SmallVector< llvm::Type *, 2 > getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
Definition ARM.cpp:4043
bool ShouldInstrumentFunction()
ShouldInstrumentFunction - Return true if the current function should be instrumented with __cyg_prof...
void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt)
Arrange a function prototype that can be called by Windows exception handling personalities.
void maybeUpdateMCDCCondBitmap(const Expr *E, llvm::Value *Val)
Update the MCDC temp value with the condition's evaluated result.
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
Definition CGExpr.cpp:6613
llvm::function_ref< std::pair< LValue, LValue >(CodeGenFunction &, const OMPExecutableDirective &S)> CodeGenLoopBoundsTy
llvm::Function * generateAwaitSuspendWrapper(Twine const &CoroName, Twine const &SuspendPointName, CoroutineSuspendExpr const &S)
bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, SourceLocation Loc)
Check if the scalar Value is within the valid range for the given type Ty.
Definition CGExpr.cpp:2133
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
Definition CGCall.cpp:5753
const TargetCodeGenInfo & getTargetHooks() const
void setBeforeOutermostConditional(llvm::Value *value, Address addr, CodeGenFunction &CGF)
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Emit the concrete pointer authentication informaton for the given authentication schema.
void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S)
void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, FunctionArgList &Args)
EmitCtorPrologue - This routine generates necessary code to initialize base classes and non-static da...
Definition CGClass.cpp:1218
llvm::ConstantInt * getUBSanFunctionTypeHash(QualType T) const
Return a type hash constant for a function instrumented by -fsanitize=function.
RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp)
Emit IR for __builtin_align_up/__builtin_align_down.
LValue EmitHLSLArrayAssignLValue(const BinaryOperator *E)
Definition CGExpr.cpp:6999
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
void EmitLifetimeEnd(llvm::Value *Addr)
Definition CGDecl.cpp:1387
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
Definition CGExpr.cpp:236
void EmitBranchToCounterBlock(const Expr *Cond, BinaryOperator::Opcode LOp, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount=0, Stmt::Likelihood LH=Stmt::LH_None, const Expr *CntrIdx=nullptr)
EmitBranchToCounterBlock - Emit a conditional branch to a new block that increments a profile counter...
llvm::SmallDenseMap< const VarDecl *, Address, 4 > BypassedVarInits
void EmitPointerAuthCopy(PointerAuthQualifier Qualifier, QualType Type, Address DestField, Address SrcField)
void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S)
LValue EmitVAArgExprLValue(const VAArgExpr *E)
Definition CGExpr.cpp:7036
bool InNoInlineAttributedStmt
True if the current statement has noinline attribute.
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
Definition CGCall.cpp:5464
void EmitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &S)
llvm::Value * EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
llvm::Value * EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, bool negateForRightShift)
Definition ARM.cpp:563
void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, llvm::Value *VTable, SourceLocation Loc)
If whole-program virtual table optimization is enabled, emit an assumption that VTable is a member of...
Definition CGClass.cpp:2799
void EmitVTableCheck(CFITypeCheckKind TCK, CanQualType T, llvm::Metadata *MD, llvm::Value *VTable, llvm::Value *TypeTest, SourceLocation Loc, bool UseCrossDsoSlowPath)
Emit a CFI check failure handler or trap for a vtable type test result.
Definition CGClass.cpp:2940
void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, bool IsFilter)
Scan the outlined statement for captures from the parent function.
llvm::Value * EmitObjCAlloc(llvm::Value *value, llvm::Type *returnType)
Allocate the given objc object.
Definition CGObjC.cpp:2810
llvm::Value * LoadObjCSelf()
LoadObjCSelf - Load the value of self.
Definition CGObjC.cpp:1809
void GenerateObjCMethod(const ObjCMethodDecl *OMD)
Generate an Objective-C method.
Definition CGObjC.cpp:836
void callCStructMoveAssignmentOperator(LValue Dst, LValue Src)
std::pair< bool, RValue > EmitOMPAtomicSimpleUpdateExpr(LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart, llvm::AtomicOrdering AO, SourceLocation Loc, const llvm::function_ref< RValue(RValue)> CommonGen)
Emit atomic update code for constructs: X = X BO E or X = E BO E.
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
Definition CGExpr.cpp:304
llvm::FenceInst * emitAtomicFence(llvm::AtomicOrdering Order, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
Emit a fence instruction, applying relevant target-specific metadata when applicable.
void EmitCoroutineBody(const CoroutineBodyStmt &S)
void pushCleanupAfterFullExprWithActiveFlag(CleanupKind Kind, RawAddress ActiveFlag, As... A)
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
LValue EmitStmtExprLValue(const StmtExpr *E)
Definition CGExpr.cpp:7139
void EmitOMPParallelDirective(const OMPParallelDirective &S)
void EmitOMPTaskDirective(const OMPTaskDirective &S)
llvm::Value * unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub)
Call unatexit() with function dtorStub.
void EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S)
void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc)
llvm::Value * EmitARCLoadWeakRetained(Address addr)
i8* @objc_loadWeakRetained(i8** addr)
Definition CGObjC.cpp:2664
void EmitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &S)
void EmitOMPAssumeDirective(const OMPAssumeDirective &S)
llvm::Value * emitPointerAuthResign(llvm::Value *Pointer, QualType PointerType, const CGPointerAuthInfo &CurAuthInfo, const CGPointerAuthInfo &NewAuthInfo, bool IsKnownNonNull)
int ExpectedOMPLoopDepth
Number of nested loop to be consumed by the last surrounding loop-associated directive.
void EmitOMPPrivateClause(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S)
llvm::Value * EmitDirectXBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition DirectX.cpp:22
llvm::Value * EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E, llvm::Triple::ArchType Arch)
Definition ARM.cpp:4594
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
Definition CGStmt.cpp:50
RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
Definition CGExpr.cpp:113
void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S)
llvm::Value * EmitWithOriginalRHSBitfieldAssignment(const BinaryOperator *E, llvm::Value **Previous, QualType *SrcType)
Retrieve the implicit cast expression of the rhs in a binary operator expression by passing pointers ...
llvm::Value * EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E)
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void EmitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &S)
bool isMCDCBranchExpr(const Expr *E) const
llvm::Value * EmitFP8NeonFDOTCall(unsigned IID, bool ExtendLaneArg, llvm::Type *RetTy, SmallVectorImpl< llvm::Value * > &Ops, const CallExpr *E, const char *name)
Definition ARM.cpp:532
LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args, QualType Ty, bool IsImplicitObject=false)
Definition CGExpr.cpp:6596
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
void EmitIfStmt(const IfStmt &S)
Definition CGStmt.cpp:905
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
Definition CGDecl.cpp:2222
void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
Definition CGObjC.cpp:2735
llvm::Value * vectorWrapScalar16(llvm::Value *Op)
Definition ARM.cpp:3378
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
void EmitAutoVarCleanups(const AutoVarEmission &emission)
Definition CGDecl.cpp:2289
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
Definition CGExpr.cpp:7115
llvm::Value * EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
Definition ARM.cpp:3224
void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, const VarDecl &D, bool EmitDebugInfo)
Emits the alloca and debug information for the size expressions for each dimension of an array.
Definition CGDecl.cpp:1404
static const Expr * stripCond(const Expr *C)
Ignore parentheses and logical-NOT to track conditions consistently.
void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args)
EmitFunctionProlog - Emit the target specific LLVM code to load the arguments for the given function.
Definition CGCall.cpp:3508
void EmitDeferStmt(const DeferStmt &S)
Definition CGStmt.cpp:2155
void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Registers the dtor using 'llvm.global_dtors' for platforms that do not support an 'atexit()' function...
Address EmitAddressOfPFPField(Address RecordPtr, const PFPField &Field)
void emitBypassedVarInitsForSource(const Stmt *Source)
Re-emit trivial-auto-var-init stores for variables bypassed by the jump Source.
Definition CGDecl.cpp:1895
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
Definition CGExpr.cpp:2801
SmallVector< llvm::CanonicalLoopInfo *, 4 > OMPLoopNestStack
List of recently emitted OMPCanonicalLoops.
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Definition CGExpr.cpp:4777
void SetFastMathFlags(FPOptions FPFeatures)
Set the codegen fast-math flags.
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
Definition CGDecl.cpp:2424
llvm::Value * EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, const llvm::CmpInst::Predicate Pred, const llvm::Twine &Name="")
Definition ARM.cpp:1917
llvm::SmallVector< char, 256 > LifetimeExtendedCleanupStack
llvm::Constant * GenerateObjCAtomicSetterCopyHelperFunction(const ObjCPropertyImplDecl *PID)
GenerateObjCAtomicSetterCopyHelperFunction - Given a c++ object type with non-trivial copy assignment...
Definition CGObjC.cpp:3753
llvm::Value * EmitSPIRVBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition SPIR.cpp:22
void EmitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &S)
void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S)
Definition CGObjC.cpp:2154
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
Definition CGStmt.cpp:576
llvm::Value * LoadCXXVTT()
LoadCXXVTT - Load the VTT parameter to base constructors/destructors have virtual bases.
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
void EmitOpenACCCacheConstruct(const OpenACCCacheConstruct &S)
Address EmitOMPBindingOriginalAddr(const BindingDecl *BD, SourceLocation Loc)
Emits the original address for a structured binding.
Address EmitVAListRef(const Expr *E)
void EmitOpenACCLoopConstruct(const OpenACCLoopConstruct &S)
void EmitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &S)
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
Definition CGExpr.cpp:1678
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Definition CGDecl.cpp:2746
llvm::Instruction * getPostAllocaInsertPoint()
Return PostAllocaInsertPt.
RValue EmitBuiltinIsAligned(const CallExpr *E)
Emit IR for __builtin_is_aligned.
void EmitAllocToken(llvm::CallBase *CB, QualType AllocType)
Emit and set additional metadata used by the AllocToken instrumentation.
Definition CGExpr.cpp:1402
void EmitARCNoopIntrinsicUse(ArrayRef< llvm::Value * > values)
Emit a call to "clang.arc.noop.use", which consumes the result of a call that has operand bundle "cla...
Definition CGObjC.cpp:2200
llvm::AtomicRMWInst * emitAtomicRMWInst(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val, llvm::AtomicOrdering Order=llvm::AtomicOrdering::SequentiallyConsistent, llvm::SyncScope::ID SSID=llvm::SyncScope::System, const AtomicExpr *AE=nullptr)
Emit an atomicrmw instruction, and applying relevant metadata when applicable.
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
LValue EmitCastLValue(const CastExpr *E)
EmitCastLValue - Casts are never lvalues unless that cast is to a reference type.
Definition CGExpr.cpp:6380
void EmitOMPFuseDirective(const OMPFuseDirective &S)
llvm::Value * EmitPointerArithmetic(const BinaryOperator *BO, Expr *pointerOperand, llvm::Value *pointer, Expr *indexOperand, llvm::Value *index, bool isSubtraction)
Emit pointer + index arithmetic.
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init)
Definition CGClass.cpp:632
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
Definition CGExpr.cpp:529
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
Definition CGExpr.cpp:3463
void EmitAsmStmt(const AsmStmt &S)
Definition CGStmt.cpp:2862
void EmitDefaultStmt(const DefaultStmt &S, ArrayRef< const Attr * > Attrs)
Definition CGStmt.cpp:2056
void EmitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &S)
void EmitLambdaInAllocaCallOpBody(const CXXMethodDecl *MD)
Definition CGClass.cpp:3164
void EmitSwitchStmt(const SwitchStmt &S)
Definition CGStmt.cpp:2456
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
void EmitOMPUseDevicePtrClause(const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope, const llvm::DenseMap< const ValueDecl *, llvm::Value * > CaptureDeviceAddrMap)
llvm::Value * SEHInfo
Value returned by __exception_info intrinsic.
LValue EmitOMPCapturedBindingLValue(const BindingDecl *BD)
Emit an LValue for a structured binding captured in an OpenMP region.
Definition CGExpr.cpp:3631
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope,...
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
Definition CGExpr.cpp:4132
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
Definition CGExpr.cpp:314
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
Definition CGExpr.cpp:285
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E)
Definition CGExpr.cpp:5686
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs={})
EmitStmt - Emit the code for the statement.
Definition CGStmt.cpp:60
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
AddInitializerToStaticVarDecl - Add the initializer for 'D' to the global variable that has already b...
Definition CGDecl.cpp:367
llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
RValue EmitUnsupportedRValue(const Expr *E, const char *Name)
EmitUnsupportedRValue - Emit a dummy r-value using the type of E and issue an ErrorUnsupported style ...
Definition CGExpr.cpp:1704
void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S)
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
CleanupKind getCleanupKind(QualType::DestructionKind kind)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
uint64_t getCurrentProfileCount()
Get the profiler's current count.
std::pair< LValue, LValue > EmitHLSLOutArgLValues(const HLSLOutArgExpr *E, QualType Ty)
Definition CGExpr.cpp:6574
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
Definition CGExpr.cpp:7087
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
Definition CGObjC.cpp:2358
llvm::Type * ConvertTypeForMem(QualType T)
static std::string getNonTrivialCopyConstructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, const ObjCPropertyImplDecl *propImpl, const ObjCMethodDecl *GetterMothodDecl, llvm::Constant *AtomicHelperFn)
Definition CGObjC.cpp:1151
LValue EmitCallExprLValue(const CallExpr *E, llvm::CallBase **CallOrInvoke=nullptr)
Definition CGExpr.cpp:7021
llvm::Value * EmitARCRetainAutoreleaseNonBlock(llvm::Value *value)
Do a fused retain/autorelease of the given object.
Definition CGObjC.cpp:2649
llvm::Value * EmitSVEMovl(const SVETypeFlags &TypeFlags, llvm::ArrayRef< llvm::Value * > Ops, unsigned BuiltinID)
Definition ARM.cpp:3780
void EmitOMPInnerLoop(const OMPExecutableDirective &S, bool RequiresCleanup, const Expr *LoopCond, const Expr *IncExpr, const llvm::function_ref< void(CodeGenFunction &)> BodyGen, const llvm::function_ref< void(CodeGenFunction &)> PostIncGen)
Emit inner loop of the worksharing/simd construct.
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E)
Definition CGClass.cpp:2440
void GenerateCXXGlobalCleanUpFunc(llvm::Function *Fn, ArrayRef< std::tuple< llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant * > > DtorsOrStermFinalizers)
GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global variables.
void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S)
static void EmitOMPTargetTeamsDistributeParallelForDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeParallelForDirective &S)
llvm::Value * EmitObjCAutoreleasePoolPush()
Produce the code to do a objc_autoreleasepool_push.
Definition CGObjC.cpp:2745
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
Definition CGExpr.cpp:2663
void EmitSYCLKernelCallStmt(const SYCLKernelCallStmt &S)
RValue EmitAtomicExpr(AtomicExpr *E)
Definition CGAtomic.cpp:944
void GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCSetter - Synthesize an Objective-C property setter function for the given property.
Definition CGObjC.cpp:1693
llvm::Value * EmitARCLoadWeak(Address addr)
i8* @objc_loadWeak(i8** addr) Essentially objc_autorelease(objc_loadWeakRetained(addr)).
Definition CGObjC.cpp:2657
void EmitOMPTargetDirective(const OMPTargetDirective &S)
void ExitSEHTryStmt(const SEHTryStmt &S)
void EmitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &S)
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Definition CGExpr.cpp:5901
static void EmitOMPTargetParallelForSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelForSimdDirective &S)
Emit device code for the target parallel for simd directive.
llvm::Value * EmitSVEPredicateTupleCast(llvm::Value *PredTuple, llvm::StructType *Ty)
Definition ARM.cpp:3559
void markStmtMaybeUsed(const Stmt *S)
void emitPFPPostCopyUpdates(Address DestPtr, Address SrcPtr, QualType Ty)
Copy all PFP fields from SrcPtr to DestPtr while updating signatures, assuming that DestPtr was alrea...
llvm::Value * EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition Hexagon.cpp:77
Address EmitZOSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_zos_va_list; this is always the address of the expression,...
CodeGenTypes & getTypes() const
RValue emitStdcCountIntrinsic(const CallExpr *E, llvm::Intrinsic::ID IntID, bool InvertArg, bool IsPop=false)
llvm::Function * EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K)
Generate an outlined function for the body of a CapturedStmt, store any captured variables into the c...
Definition CGStmt.cpp:3578
llvm::Value * EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition X86.cpp:751
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk, bool IsUnprototyped)
Generate a thunk for the given method.
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
llvm::Value * EmitIvarOffset(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
Definition CGExpr.cpp:7093
CodeGenUtils::MSVCIntrin MSVCIntrin
llvm::Value * EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
Definition ARM.cpp:3787
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
void FlattenAccessAndTypeLValue(LValue LVal, SmallVectorImpl< LValue > &AccessList)
Definition CGExpr.cpp:7569
void EmitOMPTeamsDirective(const OMPTeamsDirective &S)
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
Definition CGClass.cpp:1538
void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D)
Emit simple code for OpenMP directives in Simd-only mode.
HLSLControlFlowHintAttr::Spelling HLSLControlFlowAttr
HLSL Branch attribute.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
bool InAlwaysInlineAttributedStmt
True if the current statement has always_inline attribute.
void EmitCaseStmt(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
Definition CGStmt.cpp:1939
RawAddress CreateTempAlloca(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr, RawAddress *Alloca=nullptr)
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
llvm::Constant * GenerateObjCAtomicGetterCopyHelperFunction(const ObjCPropertyImplDecl *PID)
Definition CGObjC.cpp:3853
void EmitOMPErrorDirective(const OMPErrorDirective &S)
void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, const RegionCodeGenTy &BodyGen, OMPTargetDataInfo &InputInfo)
void EmitBreakStmt(const BreakStmt &S)
Definition CGStmt.cpp:1725
void EmitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective &S)
void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S)
void EmitOpenACCComputeConstruct(const OpenACCComputeConstruct &S)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, LValue LV, QualType Type, SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
void EmitCfiSlowPathCheck(SanitizerKind::SanitizerOrdinal Ordinal, llvm::Value *Cond, llvm::ConstantInt *TypeId, llvm::Value *Ptr, ArrayRef< llvm::Constant * > StaticArgs)
Emit a slow path cross-DSO CFI check which calls __cfi_slowpath if Cond if false.
Definition CGExpr.cpp:4458
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
void EmitDoStmt(const DoStmt &S, ArrayRef< const Attr * > Attrs={})
Definition CGStmt.cpp:1165
void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S)
llvm::Value * EmitSMEZero(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3966
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
llvm::Value * authPointerToPointerCast(llvm::Value *ResultPtr, QualType SourceType, QualType DestType)
Address GenerateCapturedStmtArgument(const CapturedStmt &S)
Definition CGStmt.cpp:3593
LValue EmitUnaryOpLValue(const UnaryOperator *E)
Definition CGExpr.cpp:3937
bool EmitOMPLastprivateClauseInit(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
Emit initial code for lastprivate variables.
void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo, bool IsUnprototyped)
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc, uint64_t RetKeyInstructionsSourceAtom)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
Definition CGCall.cpp:4405
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
Definition CGExpr.cpp:1661
static void EmitOMPTargetTeamsDistributeParallelForSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeParallelForSimdDirective &S)
Emit device code for the target teams distribute parallel for simd directive.
llvm::BasicBlock * getEHDispatchBlock(EHScopeStack::stable_iterator scope)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Definition CGStmt.cpp:679
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
llvm::Function * GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S, const OMPExecutableDirective &D)
void EmitOMPSimdDirective(const OMPSimdDirective &S)
llvm::Value * EmitSVEStructStore(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3714
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
Definition CGExpr.cpp:1742
void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, bool ForVirtualBase, Address This, bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E)
Emit a call to a constructor inherited from a base class, passing the current constructor's arguments...
Definition CGClass.cpp:2318
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Definition CGExpr.cpp:200
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
Definition CGExpr.cpp:3411
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier Qual, llvm::Type *Ty)
BuildAppleKextVirtualCall - This routine is to support gcc's kext ABI making indirect call to virtual...
Definition CGCXX.cpp:345
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
Definition CGExpr.cpp:6646
void EmitOMPParallelGenericLoopDirective(const OMPLoopDirective &S)
RawAddress NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
Definition CGObjC.cpp:2181
SmallVector< llvm::Value *, 8 > ObjCEHValueStack
ObjCEHValueStack - Stack of Objective-C exception values, used for rethrows.
void WasmEmitFallthroughRethrow(llvm::BasicBlock *WasmCatchStartBlock)
void EmitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &S)
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
Definition CGExpr.cpp:7065
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
llvm::Type * convertTypeForLoadStore(QualType ASTTy, llvm::Type *LLVMTy=nullptr)
llvm::Value * EmitSMELd1St1(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3919
void EmitOMPTargetSimdDirective(const OMPLoopDirective &S)
Also emits 'target loop'.
void EmitOMPOrderedStandaloneDirective(const OMPOrderedStandaloneDirective &S)
llvm::Value * EmitPointerAuthBlendDiscriminator(llvm::Value *StorageAddress, llvm::Value *Discriminator)
Create the discriminator from the storage address and the entity hash.
void EmitVarDecl(const VarDecl &D)
EmitVarDecl - Emit a local variable declaration.
Definition CGDecl.cpp:217
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
Definition CGExpr.cpp:755
const BreakContinue * GetDestForLoopControlStmt(const LoopControlStmt &S)
Definition CGStmt.cpp:1711
Address EmitExtVectorElementLValue(LValue V)
Generates lvalue for partial ext_vector access.
Definition CGExpr.cpp:2759
bool EmitOMPLinearClauseInit(const OMPLoopDirective &D)
Emit initial code for linear variables.
void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, llvm::Value *Address)
llvm::Value * EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr, ArrayRef< llvm::Value * > IdxList, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, const Twine &Name="")
Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to detect undefined behavior whe...
void EmitInitializationToLValue(const Expr *E, LValue LV, AggValueSlot::IsZeroed_t IsZeroed=AggValueSlot::IsNotZeroed)
EmitInitializationToLValue - Emit an initializer to an LValue.
Definition CGExpr.cpp:344
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::BasicBlock * GetIndirectGotoBlock()
static void EmitOMPTargetParallelGenericLoopDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelGenericLoopDirective &S)
Emit device code for the target parallel loop directive.
llvm::Value * EmitBuiltinAvailable(const VersionTuple &Version)
Definition CGObjC.cpp:4053
void EmitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &S)
Address emitAddrOfRealComponent(Address complex, QualType complexType)
llvm::DILocation * SanitizerAnnotateDebugInfo(ArrayRef< SanitizerKind::SanitizerOrdinal > Ordinals, SanitizerHandler Handler)
Returns debug info, with additional annotation if CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[Ordi...
EHScopeStack::stable_iterator PrologueCleanupDepth
PrologueCleanupDepth - The cleanup depth enclosing all the cleanups associated with the parameters.
void EmitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &S)
llvm::Value * GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, bool Delegating)
GetVTTParameter - Return the VTT parameter that should be passed to a base constructor/destructor wit...
Definition CGClass.cpp:448
void EmitOMPUnrollDirective(const OMPUnrollDirective &S)
void EmitOMPStripeDirective(const OMPStripeDirective &S)
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression,...
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
const FunctionDecl * getCurrentFunctionDecl() const
RValue EmitLoadOfExtVectorElementLValue(LValue V)
Definition CGExpr.cpp:2701
static bool hasAggregateEvaluationKind(QualType T)
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
Definition CGExpr.cpp:1719
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits(), llvm::Constant *CalleeOverride=nullptr)
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
Definition CGCall.cpp:5117
llvm::Value * EmitMatrixIndexExpr(const Expr *E)
Definition CGExpr.cpp:5421
void EmitCaseStmtRange(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
EmitCaseStmtRange - If case statement range is not too big then add multiple cases to switch instruct...
Definition CGStmt.cpp:1853
ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitOMPSingleDirective(const OMPSingleDirective &S)
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, bool NoMerge=false, const TrapReason *TR=nullptr)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
Definition CGExpr.cpp:4670
void EmitReturnStmt(const ReturnStmt &S)
EmitReturnStmt - Note that due to GCC extensions, this can have an operand if the function returns vo...
Definition CGStmt.cpp:1586
void EmitTrapCallAndMakeUnreachable()
Emit a call to '@llvm.trap()' and clear the current insert point.
Definition CGExpr.cpp:4769
void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
llvm::function_ref< void(CodeGenFunction &, SourceLocation, const unsigned, const bool)> CodeGenOrderedTy
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
Definition CGExpr.cpp:2295
llvm::Value * EmitCheckedArgForAssume(const Expr *E)
Emits an argument for a call to a __builtin_assume.
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
Store into a strong object.
Definition CGObjC.cpp:2545
llvm::Function * GenerateCapturedStmtFunction(const CapturedStmt &S)
Creates the outlined function for a CapturedStmt.
Definition CGStmt.cpp:3600
static void EmitOMPTargetParallelForDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelForDirective &S)
Emit device code for the target parallel for directive.
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
const CGFunctionInfo * CurFnInfo
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
llvm::Value * EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FD, const FieldDecl *CountDecl)
Build an expression accessing the "counted_by" field.
Definition CGExpr.cpp:1279
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
llvm::Value * EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition NVPTX.cpp:468
llvm::Value * getArrayInitIndex()
Get the index of the current ArrayInitLoopExpr, if any.
void EmitDeclStmt(const DeclStmt &S)
Definition CGStmt.cpp:1701
void InitializeVTablePointer(const VPtr &vptr)
Initialize the vtable pointer of the given subobject.
Definition CGClass.cpp:2593
void EmitLabelStmt(const LabelStmt &S)
Definition CGStmt.cpp:782
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
Definition CGExpr.cpp:4658
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
static void EmitOMPTargetTeamsGenericLoopDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsGenericLoopDirective &S)
Emit device code for the target teams loop directive.
llvm::Value * EmitObjCStringLiteral(const ObjCStringLiteral *E)
Emits an instance of NSConstantString representing the object.
Definition CGObjC.cpp:52
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
llvm::Value * EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty)
Definition ARM.cpp:4007
void EmitOMPTileDirective(const OMPTileDirective &S)
void EmitDecl(const Decl &D, bool EvaluateConditionDecl=false)
EmitDecl - Emit a declaration.
Definition CGDecl.cpp:52
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E)
Definition CGExpr.cpp:7050
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
generateDestroyHelper - Generates a helper function which, when invoked, destroys the given object.
void EmitOMPAtomicDirective(const OMPAtomicDirective &S)
LValue EmitMemberExpr(const MemberExpr *E)
Definition CGExpr.cpp:5791
void EmitOpenACCSetConstruct(const OpenACCSetConstruct &S)
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
ConstantEmission tryEmitAsConstant(const DeclRefExpr *RefExpr)
Try to emit a reference to the given value without producing it as an l-value.
Definition CGExpr.cpp:1957
void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr)
Produce the code to do a primitive release.
Definition CGObjC.cpp:2835
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
Definition CGExpr.cpp:1777
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Store of global named registers are always calls to intrinsics.
Definition CGExpr.cpp:3251
void EmitAttributedStmt(const AttributedStmt &S)
Definition CGStmt.cpp:792
llvm::Value * EmitARCExtendBlockObject(const Expr *expr)
Definition CGObjC.cpp:3544
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
bool isOpaqueValueEmitted(const OpaqueValueExpr *E)
isOpaqueValueEmitted - Return true if the opaque value expression has already been emitted.
Definition CGExpr.cpp:6640
std::pair< llvm::Value *, CGPointerAuthInfo > EmitOrigPointerRValue(const Expr *E)
Retrieve a pointer rvalue and its ptrauth info.
void EmitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &S)
void EmitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &S)
void markStmtAsUsed(bool Skipped, const Stmt *S)
llvm::Instruction * CurrentFuncletPad
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
i8* @objc_storeWeak(i8** addr, i8* value) Returns value.
Definition CGObjC.cpp:2672
bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
Definition CGClass.cpp:2989
void EmitOMPSectionDirective(const OMPSectionDirective &S)
llvm::Constant * GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo)
Generate the destroy-helper function for a block closure object: static void block_destroy_helper(blo...
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
void EmitOMPForSimdDirective(const OMPForSimdDirective &S)
llvm::LLVMContext & getLLVMContext()
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
ComplexPairTy EmitPromotedValue(ComplexPairTy result, QualType PromotionType)
bool checkIfFunctionMustProgress()
Returns true if a function must make progress, which means the mustprogress attribute can be added.
LValue EmitMatrixElementExpr(const MatrixElementExpr *E)
Definition CGExpr.cpp:2374
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S)
Definition CGObjC.cpp:1825
llvm::SmallVector< VPtr, 4 > VPtrsVector
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)
getAccessedFieldNo - Given an encoded value and a result number, return the input field number being ...
Definition CGExpr.cpp:727
llvm::Value * EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
EmitTargetBuiltinExpr - Emit the given builtin call.
void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
static void EmitOMPTargetTeamsDistributeSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeSimdDirective &S)
Emit device code for the target teams distribute simd directive.
void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr)
Produce the code to do a primitive release.
Definition CGObjC.cpp:2755
void InitializeVTablePointers(const CXXRecordDecl *ClassDecl)
Definition CGClass.cpp:2713
llvm::Value * EmitObjCRetainNonBlock(llvm::Value *value, llvm::Type *returnType)
Retain the given object, with normal retain semantics.
Definition CGObjC.cpp:2879
void EmitARCCopyWeak(Address dst, Address src)
void @objc_copyWeak(i8** dest, i8** src) Disregards the current value in dest.
Definition CGObjC.cpp:2722
bool isMCDCDecisionExpr(const Expr *E) const
llvm::function_ref< void(CodeGenFunction &, const OMPLoopDirective &, JumpDest)> CodeGenLoopTy
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
LoadedLValueCapture * CurLoadedLValueCapture
void EmitIndirectGotoStmt(const IndirectGotoStmt &S)
Definition CGStmt.cpp:881
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
void EmitVTableAssumptionLoad(const VPtr &vptr, Address This)
Emit assumption that vptr load == global vtable.
Definition CGClass.cpp:2412
llvm::Value * EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
void MaybeEmitDeferredVarDeclInit(const VarDecl *var)
Definition CGDecl.cpp:2161
void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope, llvm::AtomicOrdering &AO, llvm::SyncScope::ID &SSID)
Definition AMDGPU.cpp:473
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const
isObviouslyBranchWithoutCleanups - Return true if a branch to the specified destination obviously has...
void EmitSEHTryStmt(const SEHTryStmt &S)
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
Definition CGDecl.cpp:1869
void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S)
llvm::ScalableVectorType * getSVEPredType(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3444
void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
Definition CGObjC.cpp:2728
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
When instrumenting to collect profile data, the counts for some blocks such as switch cases need to n...
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, ArrayRef< Address > args, const Twine &name="")
llvm::Value * EmitNonNullRValueCheck(RValue RV, QualType T)
Create a check that a scalar RValue is non-null.
Definition CGExpr.cpp:1671
void EmitARCIntrinsicUse(ArrayRef< llvm::Value * > values)
Given a number of pointers, inform the optimizer that they're being intrinsically used up until this ...
Definition CGObjC.cpp:2188
llvm::Value * EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy, QualType RTy)
Definition CGCall.cpp:4359
void EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, const OpenMPDirectiveKind CapturedRegion, const RegionCodeGenTy &BodyGen, const TaskGenTy &TaskGen, OMPTaskDataTy &Data)
llvm::Value * EmitNeonCall(llvm::Function *F, SmallVectorImpl< llvm::Value * > &O, const char *name, unsigned shift=0, bool rightshift=false)
Definition ARM.cpp:503
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitOMPForDirective(const OMPForDirective &S)
bool hasLabelBeenSeenInCurrentScope() const
Return true if a label was seen in the current scope.
llvm::Function * GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, const SEHExceptStmt &Except)
Create a stub filter function that will ultimately hold the code of the filter expression.
void EmitLabel(const LabelDecl *D)
EmitLabel - Emit the block for the given label.
Definition CGStmt.cpp:724
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
void EmitOMPLinearClauseFinal(const OMPLoopDirective &D, const llvm::function_ref< llvm::Value *(CodeGenFunction &)> CondGen)
Emit final code for linear clauses.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition CGStmt.cpp:659
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
EmitExprAsInit - Emits the code necessary to initialize a location in memory with the given initializ...
Definition CGDecl.cpp:2179
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, AlignmentSource Source=AlignmentSource::Type)
llvm::Value * EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, ArrayRef< llvm::Value * > Ops)
Definition ARM.cpp:4070
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
llvm::Value * EmitPointerAuthAuth(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
void EmitContinueStmt(const ContinueStmt &S)
Definition CGStmt.cpp:1738
llvm::CallInst * EmitIntrinsicCall(llvm::Intrinsic::ID ID, ArrayRef< llvm::Type * > Types, ArrayRef< llvm::Value * > Args, const Twine &Name="")
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
void EmitOMPSimdFinal(const OMPLoopDirective &D, const llvm::function_ref< llvm::Value *(CodeGenFunction &)> CondGen)
llvm::Type * ConvertType(const TypeDecl *T)
This class organizes the cross-function state that is used while generating LLVM code.
const llvm::DataLayout & getDataLayout() const
Per-function PGO state.
Definition CodeGenPGO.h:29
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
A specialization of Address that requires the address to be an LLVM Constant.
Definition Address.h:296
static ConstantAddress invalid()
Definition Address.h:304
DominatingValue< Address >::saved_type AggregateAddr
static saved_type save(CodeGenFunction &CGF, RValue value)
ConditionalCleanup stores the saved form of its parameters, then restores them and performs the clean...
A saved depth on the scope stack.
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition CGCall.h:378
LValue - This represents an lvalue references.
Definition CGValue.h:183
CharUnits getAlignment() const
Definition CGValue.h:355
static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Definition CGValue.h:454
QualType getType() const
Definition CGValue.h:303
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
A stack of loop information corresponding to loop nesting levels.
Definition CGLoopInfo.h:158
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition CGValue.h:42
static RValue get(llvm::Value *V)
Definition CGValue.h:99
An abstract representation of an aligned address.
Definition Address.h:42
static RawAddress invalid()
Definition Address.h:61
Class provides a way to call simple version of codegen for OpenMP region, or an advanced with possibl...
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition CGCall.h:384
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition TargetInfo.h:80
The class detects jumps which bypass local variables declaration: goto L; int a; L:
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4369
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3674
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1751
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition ExprCXX.h:5309
SourceLocExprScopeGuard(const Expr *DefaultExpr, CurrentSourceLocExprScope &Current)
Represents the current source location and context used to determine the value of the source location...
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:996
This represents one expression.
Definition Expr.h:114
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3125
QualType getType() const
Definition Expr.h:146
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6696
Represents a member of a struct/union/class.
Definition Decl.h:3341
Represents a function declaration or definition.
Definition Decl.h:2082
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:60
const Decl * getDecl() const
Definition GlobalDecl.h:115
GotoStmt - This represents a direct goto.
Definition Stmt.h:2980
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7483
IfStmt - This represents an if/then/else.
Definition Stmt.h:2270
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3019
Describes an C or C++ initializer list.
Definition Expr.h:5377
Represents the declaration of a label.
Definition Decl.h:526
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2157
FPExceptionModeKind
Possible floating point exception behavior.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a point when we exit a loop.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4974
MatrixSingleSubscriptExpr - Matrix single subscript expression for the MatrixType extension when you ...
Definition Expr.h:2864
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2934
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3433
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3751
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:219
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:158
ObjCContainerDecl - Represents a container for method declarations.
Definition DeclObjC.h:954
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:341
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:440
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2603
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition ExprObjC.h:1530
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:581
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:972
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2811
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:537
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:485
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:83
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1223
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1273
Represents a parameter to a function.
Definition Decl.h:1832
Pointer-authentication qualifiers.
Definition TypeBase.h:153
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3403
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2074
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6890
A (possibly-)qualified type.
Definition TypeBase.h:938
The collection of all-type qualifiers we support.
Definition TypeBase.h:332
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4706
Flags to identify the types for overloaded SVE builtins.
Scope - A scope is a transient data structure that is used while parsing the program.
Definition Scope.h:41
Encodes a location in the source.
A trivial tuple used to represent a source range.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4664
Stmt - This represents one statement.
Definition Stmt.h:85
Likelihood
The likelihood of a branch being taken.
Definition Stmt.h:1447
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition Stmt.h:1449
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1844
Exposes information about the current target.
Definition TargetInfo.h:228
Represents a declaration of a type.
Definition Decl.h:3694
bool isReferenceType() const
Definition TypeBase.h:8839
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2313
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:5026
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
QualType getType() const
Definition Decl.h:725
Represents a variable declaration or definition.
Definition Decl.h:934
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:2240
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition Decl.h:1287
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4064
Expr * getSizeExpr() const
Definition TypeBase.h:4078
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2708
Defines the clang::TargetInfo interface.
EvaluationOrder
The order in which the arguments of a call must be evaluated.
Definition CallUtils.h:29
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
Definition CGValue.h:142
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
Definition CGValue.h:155
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Definition CGValue.h:146
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
Definition CGValue.h:136
VE builtins.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
const AstTypeMatcher< ComplexType > complexType
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Success
Annotation was successful.
Definition Parser.h:65
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CapturedRegionKind
The different kinds of captured statement.
@ CR_Default
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition Linkage.h:24
@ Result
The result type of a method or function.
Definition TypeBase.h:906
const FunctionProtoType * T
CXXDtorType
C++ destructor types.
Definition ABI.h:34
LangAS
Defines the address space values used by the address space qualifier of QualType.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:136
llvm::fp::ExceptionBehavior ToConstrainedExceptMD(LangOptions::FPExceptionModeKind Kind)
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6151
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
Structure with information about how a bitfield should be accessed.
llvm::SmallVector< llvm::AllocaInst * > Take()
llvm::AssertingVH< llvm::BasicBlock > Block
CXXDefaultArgExprScope(CodeGenFunction &CGF, const CXXDefaultArgExpr *E)
FMVResolverOption(llvm::Function *F, ArrayRef< StringRef > Feats, std::optional< StringRef > Arch=std::nullopt)
A jump destination is an abstract label, branching to which may require a jump out through normal cle...
void setScopeDepth(EHScopeStack::stable_iterator depth)
EHScopeStack::stable_iterator getScopeDepth() const
JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth, unsigned Index)
Header for data within LifetimeExtendedCleanupStack.
unsigned Size
The size of the following cleanup object.
unsigned IsConditional
Whether this is a conditional cleanup.
Records the l-value that ScalarExprEmitter loads from when it emits a specific expression.
const Expr * E
The expression whose l-value is recorded.
std::optional< LValue > LV
The recorded l-value, set if E was loaded by ScalarExprEmitter.
static Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
llvm::OpenMPIRBuilder::InsertPointTy InsertPointTy
static void EmitOMPOutlinedRegionBody(CodeGenFunction &CGF, const Stmt *RegionBodyStmt, InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Twine RegionName)
Emit the body of an OMP region that will be outlined in OpenMPIRBuilder::finalize().
static Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable /p VD.
static std::string getNameWithSeparators(ArrayRef< StringRef > Parts, StringRef FirstSeparator=".", StringRef Separator=".")
Get the platform-specific name separator.
static void FinalizeOMPRegion(CodeGenFunction &CGF, InsertPointTy IP)
Emit the Finalization for an OMP region.
static void EmitOMPInlinedRegionBody(CodeGenFunction &CGF, const Stmt *RegionBodyStmt, InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Twine RegionName)
Emit the body of an OMP region.
static void EmitCaptureStmt(CodeGenFunction &CGF, llvm::BasicBlock *CodeGenIPBB, llvm::BasicBlock &FiniBB, llvm::Function *Fn, ArrayRef< llvm::Value * > Args)
OMPBuilderCBHelpers & operator=(const OMPBuilderCBHelpers &)=delete
OMPBuilderCBHelpers(const OMPBuilderCBHelpers &)=delete
OMPTargetDataInfo(Address BasePointersArray, Address PointersArray, Address SizesArray, Address MappersArray, unsigned NumberOfTargetItems)
llvm::PointerUnion< const FunctionProtoType *, const ObjCMethodDecl * > P
Struct with all information about dynamic [sub]class needed to set vptr.
This structure provides a set of types that are commonly used during IR emission.
saved_type(llvm::AllocaInst *Alloca, llvm::Type *Ty)
Helper class with most of the code for saving a value for a conditional expression cleanup.
static llvm::Value * restore(CodeGenFunction &CGF, saved_type value)
static saved_type save(CodeGenFunction &CGF, llvm::Value *value)
static bool needsSaving(llvm::Value *value)
Answer whether the given value needs extra work to be saved.
static type restore(CodeGenFunction &CGF, saved_type value)
static type restore(CodeGenFunction &CGF, saved_type value)
static saved_type save(CodeGenFunction &CGF, type value)
static saved_type save(CodeGenFunction &CGF, type value)
static type restore(CodeGenFunction &CGF, saved_type value)
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
static bool needsSaving(type value)
static saved_type save(CodeGenFunction &CGF, type value)
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition Thunk.h:157