clang 22.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/CharUnits.h"
25#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
30#include "clang/AST/StmtSYCL.h"
31#include "clang/AST/Type.h"
32#include "clang/Basic/ABI.h"
37#include "llvm/ADT/ArrayRef.h"
38#include "llvm/ADT/DenseMap.h"
39#include "llvm/ADT/MapVector.h"
40#include "llvm/ADT/SmallVector.h"
41#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
42#include "llvm/IR/Instructions.h"
43#include "llvm/IR/ValueHandle.h"
44#include "llvm/Support/Debug.h"
45#include "llvm/Transforms/Utils/SanitizerStats.h"
46#include <optional>
47
48namespace llvm {
49class BasicBlock;
50class ConvergenceControlInst;
51class LLVMContext;
52class MDNode;
53class SwitchInst;
54class Twine;
55class Value;
56class CanonicalLoopInfo;
57} // namespace llvm
58
59namespace clang {
60class ASTContext;
62class CXXForRangeStmt;
63class CXXTryStmt;
64class Decl;
65class LabelDecl;
66class FunctionDecl;
68class LabelStmt;
71class ObjCIvarDecl;
72class ObjCMethodDecl;
75class TargetInfo;
76class VarDecl;
78class ObjCAtTryStmt;
79class ObjCAtThrowStmt;
84class SVETypeFlags;
85class OMPExecutableDirective;
86
87namespace analyze_os_log {
89}
90
91namespace CodeGen {
92class CodeGenTypes;
93class CodeGenPGO;
94class CGCallee;
95class CGFunctionInfo;
96class CGBlockInfo;
97class CGCXXABI;
99class BlockByrefInfo;
100class BlockFieldFlags;
101class RegionCodeGenTy;
103struct OMPTaskDataTy;
104struct CGCoroData;
105
106// clang-format off
107/// The kind of evaluation to perform on values of a particular
108/// type. Basically, is the code in CGExprScalar, CGExprComplex, or
109/// CGExprAgg?
110///
111/// TODO: should vectors maybe be split out into their own thing?
117// clang-format on
118
119/// Helper class with most of the code for saving a value for a
120/// conditional expression cleanup.
122 typedef llvm::PointerIntPair<llvm::Value *, 1, bool> saved_type;
123
124 /// Answer whether the given value needs extra work to be saved.
125 static bool needsSaving(llvm::Value *value) {
126 if (!value)
127 return false;
128
129 // If it's not an instruction, we don't need to save.
130 if (!isa<llvm::Instruction>(value))
131 return false;
132
133 // If it's an instruction in the entry block, we don't need to save.
134 llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent();
135 return (block != &block->getParent()->getEntryBlock());
136 }
137
138 static saved_type save(CodeGenFunction &CGF, llvm::Value *value);
139 static llvm::Value *restore(CodeGenFunction &CGF, saved_type value);
140};
141
142/// A partial specialization of DominatingValue for llvm::Values that
143/// might be llvm::Instructions.
144template <class T> struct DominatingPointer<T, true> : DominatingLLVMValue {
145 typedef T *type;
147 return static_cast<T *>(DominatingLLVMValue::restore(CGF, value));
148 }
149};
150
151/// A specialization of DominatingValue for Address.
152template <> struct DominatingValue<Address> {
153 typedef Address type;
154
162
163 static bool needsSaving(type value) {
166 return true;
167 return false;
168 }
169 static saved_type save(CodeGenFunction &CGF, type value) {
170 return {DominatingLLVMValue::save(CGF, value.getBasePointer()),
171 value.getElementType(), value.getAlignment(),
172 DominatingLLVMValue::save(CGF, value.getOffset()), value.getType()};
173 }
178 }
179};
180
181/// A specialization of DominatingValue for RValue.
182template <> struct DominatingValue<RValue> {
183 typedef RValue type;
184 class saved_type {
185 enum Kind {
186 ScalarLiteral,
187 ScalarAddress,
188 AggregateLiteral,
189 AggregateAddress,
190 ComplexAddress
191 };
192 union {
193 struct {
195 } Vals;
197 };
198 LLVM_PREFERRED_TYPE(Kind)
199 unsigned K : 3;
200
202 : Vals{Val1, DominatingLLVMValue::saved_type()}, K(K) {}
203
206 : Vals{Val1, Val2}, K(ComplexAddress) {}
207
208 saved_type(DominatingValue<Address>::saved_type AggregateAddr, unsigned K)
209 : AggregateAddr(AggregateAddr), K(K) {}
210
211 public:
212 static bool needsSaving(RValue value);
213 static saved_type save(CodeGenFunction &CGF, RValue value);
215
216 // implementations in CGCleanup.cpp
217 };
218
219 static bool needsSaving(type value) { return saved_type::needsSaving(value); }
220 static saved_type save(CodeGenFunction &CGF, type value) {
221 return saved_type::save(CGF, value);
222 }
224 return value.restore(CGF);
225 }
226};
227
228/// A scoped helper to set the current source atom group for
229/// CGDebugInfo::addInstToCurrentSourceAtom. A source atom is a source construct
230/// that is "interesting" for debug stepping purposes. We use an atom group
231/// number to track the instruction(s) that implement the functionality for the
232/// atom, plus backup instructions/source locations.
233class ApplyAtomGroup {
234 uint64_t OriginalAtom = 0;
235 CGDebugInfo *DI = nullptr;
236
237 ApplyAtomGroup(const ApplyAtomGroup &) = delete;
238 void operator=(const ApplyAtomGroup &) = delete;
239
240public:
241 ApplyAtomGroup(CGDebugInfo *DI);
243};
244
245/// CodeGenFunction - This class organizes the per-function state that is used
246/// while generating LLVM code.
247class CodeGenFunction : public CodeGenTypeCache {
248 CodeGenFunction(const CodeGenFunction &) = delete;
249 void operator=(const CodeGenFunction &) = delete;
250
251 friend class CGCXXABI;
252
253public:
254 /// A jump destination is an abstract label, branching to which may
255 /// require a jump out through normal cleanups.
256 struct JumpDest {
257 JumpDest() : Block(nullptr), Index(0) {}
258 JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth,
259 unsigned Index)
260 : Block(Block), ScopeDepth(Depth), Index(Index) {}
261
262 bool isValid() const { return Block != nullptr; }
263 llvm::BasicBlock *getBlock() const { return Block; }
264 EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
265 unsigned getDestIndex() const { return Index; }
266
267 // This should be used cautiously.
269 ScopeDepth = depth;
270 }
271
272 private:
273 llvm::BasicBlock *Block;
275 unsigned Index;
276 };
277
278 CodeGenModule &CGM; // Per-module state.
280
281 // For EH/SEH outlined funclets, this field points to parent's CGF
282 CodeGenFunction *ParentCGF = nullptr;
283
284 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
287
288 // Stores variables for which we can't generate correct lifetime markers
289 // because of jumps.
291
292 /// List of recently emitted OMPCanonicalLoops.
293 ///
294 /// Since OMPCanonicalLoops are nested inside other statements (in particular
295 /// CapturedStmt generated by OMPExecutableDirective and non-perfectly nested
296 /// loops), we cannot directly call OMPEmitOMPCanonicalLoop and receive its
297 /// llvm::CanonicalLoopInfo. Instead, we call EmitStmt and any
298 /// OMPEmitOMPCanonicalLoop called by it will add its CanonicalLoopInfo to
299 /// this stack when done. Entering a new loop requires clearing this list; it
300 /// either means we start parsing a new loop nest (in which case the previous
301 /// loop nest goes out of scope) or a second loop in the same level in which
302 /// case it would be ambiguous into which of the two (or more) loops the loop
303 /// nest would extend.
305
306 /// Stack to track the Logical Operator recursion nest for MC/DC.
308
309 /// Stack to track the controlled convergence tokens.
311
312 /// Number of nested loop to be consumed by the last surrounding
313 /// loop-associated directive.
315
316 // CodeGen lambda for loops and support for ordered clause
317 typedef llvm::function_ref<void(CodeGenFunction &, const OMPLoopDirective &,
318 JumpDest)>
320 typedef llvm::function_ref<void(CodeGenFunction &, SourceLocation,
321 const unsigned, const bool)>
323
324 // Codegen lambda for loop bounds in worksharing loop constructs
325 typedef llvm::function_ref<std::pair<LValue, LValue>(
326 CodeGenFunction &, const OMPExecutableDirective &S)>
328
329 // Codegen lambda for loop bounds in dispatch-based loop implementation
330 typedef llvm::function_ref<std::pair<llvm::Value *, llvm::Value *>(
331 CodeGenFunction &, const OMPExecutableDirective &S, Address LB,
332 Address UB)>
334
335 /// CGBuilder insert helper. This function is called after an
336 /// instruction is created using Builder.
337 void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
338 llvm::BasicBlock::iterator InsertPt) const;
339
340 /// CurFuncDecl - Holds the Decl for the current outermost
341 /// non-closure context.
342 const Decl *CurFuncDecl = nullptr;
343 /// CurCodeDecl - This is the inner-most code context, which includes blocks.
344 const Decl *CurCodeDecl = nullptr;
345 const CGFunctionInfo *CurFnInfo = nullptr;
347 llvm::Function *CurFn = nullptr;
348
349 /// Save Parameter Decl for coroutine.
351
352 // Holds coroutine data if the current function is a coroutine. We use a
353 // wrapper to manage its lifetime, so that we don't have to define CGCoroData
354 // in this header.
355 struct CGCoroInfo {
356 std::unique_ptr<CGCoroData> Data;
357 bool InSuspendBlock = false;
358 CGCoroInfo();
359 ~CGCoroInfo();
360 };
362
363 bool isCoroutine() const { return CurCoro.Data != nullptr; }
364
365 bool inSuspendBlock() const {
366 return isCoroutine() && CurCoro.InSuspendBlock;
367 }
368
369 // Holds FramePtr for await_suspend wrapper generation,
370 // so that __builtin_coro_frame call can be lowered
371 // directly to value of its second argument
373 llvm::Value *FramePtr = nullptr;
374 };
376
377 // Generates wrapper function for `llvm.coro.await.suspend.*` intrinisics.
378 // It encapsulates SuspendExpr in a function, to separate it's body
379 // from the main coroutine to avoid miscompilations. Intrinisic
380 // is lowered to this function call in CoroSplit pass
381 // Function signature is:
382 // <type> __await_suspend_wrapper_<name>(ptr %awaiter, ptr %hdl)
383 // where type is one of (void, i1, ptr)
384 llvm::Function *generateAwaitSuspendWrapper(Twine const &CoroName,
385 Twine const &SuspendPointName,
386 CoroutineSuspendExpr const &S);
387
388 /// CurGD - The GlobalDecl for the current function being compiled.
390
391 /// PrologueCleanupDepth - The cleanup depth enclosing all the
392 /// cleanups associated with the parameters.
394
395 /// ReturnBlock - Unified return block.
397
398 /// ReturnValue - The temporary alloca to hold the return
399 /// value. This is invalid iff the function has no return value.
401
402 /// ReturnValuePointer - The temporary alloca to hold a pointer to sret.
403 /// This is invalid if sret is not in use.
405
406 /// If a return statement is being visited, this holds the return statment's
407 /// result expression.
408 const Expr *RetExpr = nullptr;
409
410 /// Return true if a label was seen in the current scope.
412 if (CurLexicalScope)
413 return CurLexicalScope->hasLabels();
414 return !LabelMap.empty();
415 }
416
417 /// AllocaInsertPoint - This is an instruction in the entry block before which
418 /// we prefer to insert allocas.
419 llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
420
421private:
422 /// PostAllocaInsertPt - This is a place in the prologue where code can be
423 /// inserted that will be dominated by all the static allocas. This helps
424 /// achieve two things:
425 /// 1. Contiguity of all static allocas (within the prologue) is maintained.
426 /// 2. All other prologue code (which are dominated by static allocas) do
427 /// appear in the source order immediately after all static allocas.
428 ///
429 /// PostAllocaInsertPt will be lazily created when it is *really* required.
430 llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr;
431
432public:
433 /// Return PostAllocaInsertPt. If it is not yet created, then insert it
434 /// immediately after AllocaInsertPt.
435 llvm::Instruction *getPostAllocaInsertPoint() {
436 if (!PostAllocaInsertPt) {
437 assert(AllocaInsertPt &&
438 "Expected static alloca insertion point at function prologue");
439 assert(AllocaInsertPt->getParent()->isEntryBlock() &&
440 "EBB should be entry block of the current code gen function");
441 PostAllocaInsertPt = AllocaInsertPt->clone();
442 PostAllocaInsertPt->setName("postallocapt");
443 PostAllocaInsertPt->insertAfter(AllocaInsertPt->getIterator());
444 }
445
446 return PostAllocaInsertPt;
447 }
448
449 /// API for captured statement code generation.
451 public:
453 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {}
456 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {
457
459 S.getCapturedRecordDecl()->field_begin();
461 E = S.capture_end();
462 I != E; ++I, ++Field) {
463 if (I->capturesThis())
464 CXXThisFieldDecl = *Field;
465 else if (I->capturesVariable())
466 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
467 else if (I->capturesVariableByCopy())
468 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
469 }
470 }
471
472 virtual ~CGCapturedStmtInfo();
473
474 CapturedRegionKind getKind() const { return Kind; }
475
476 virtual void setContextValue(llvm::Value *V) { ThisValue = V; }
477 // Retrieve the value of the context parameter.
478 virtual llvm::Value *getContextValue() const { return ThisValue; }
479
480 /// Lookup the captured field decl for a variable.
481 virtual const FieldDecl *lookup(const VarDecl *VD) const {
482 return CaptureFields.lookup(VD->getCanonicalDecl());
483 }
484
485 bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; }
486 virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; }
487
488 static bool classof(const CGCapturedStmtInfo *) { return true; }
489
490 /// Emit the captured statement body.
491 virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) {
493 CGF.EmitStmt(S);
494 }
495
496 /// Get the name of the capture helper.
497 virtual StringRef getHelperName() const { return "__captured_stmt"; }
498
499 /// Get the CaptureFields
500 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> getCaptureFields() {
501 return CaptureFields;
502 }
503
504 private:
505 /// The kind of captured statement being generated.
507
508 /// Keep the map between VarDecl and FieldDecl.
509 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields;
510
511 /// The base address of the captured record, passed in as the first
512 /// argument of the parallel region function.
513 llvm::Value *ThisValue;
514
515 /// Captured 'this' type.
516 FieldDecl *CXXThisFieldDecl;
517 };
519
520 /// RAII for correct setting/restoring of CapturedStmtInfo.
522 private:
523 CodeGenFunction &CGF;
524 CGCapturedStmtInfo *PrevCapturedStmtInfo;
525
526 public:
527 CGCapturedStmtRAII(CodeGenFunction &CGF,
528 CGCapturedStmtInfo *NewCapturedStmtInfo)
529 : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) {
530 CGF.CapturedStmtInfo = NewCapturedStmtInfo;
531 }
532 ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; }
533 };
534
535 /// An abstract representation of regular/ObjC call/message targets.
537 /// The function declaration of the callee.
538 const Decl *CalleeDecl;
539
540 public:
541 AbstractCallee() : CalleeDecl(nullptr) {}
542 AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {}
543 AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {}
544 bool hasFunctionDecl() const {
545 return isa_and_nonnull<FunctionDecl>(CalleeDecl);
546 }
547 const Decl *getDecl() const { return CalleeDecl; }
548 unsigned getNumParams() const {
549 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
550 return FD->getNumParams();
551 return cast<ObjCMethodDecl>(CalleeDecl)->param_size();
552 }
553 const ParmVarDecl *getParamDecl(unsigned I) const {
554 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
555 return FD->getParamDecl(I);
556 return *(cast<ObjCMethodDecl>(CalleeDecl)->param_begin() + I);
557 }
558 };
559
560 /// Sanitizers enabled for this function.
562
563 /// True if CodeGen currently emits code implementing sanitizer checks.
564 bool IsSanitizerScope = false;
565
566 /// RAII object to set/unset CodeGenFunction::IsSanitizerScope.
568 CodeGenFunction *CGF;
569
570 public:
571 SanitizerScope(CodeGenFunction *CGF);
573 };
574
575 /// In C++, whether we are code generating a thunk. This controls whether we
576 /// should emit cleanups.
577 bool CurFuncIsThunk = false;
578
579 /// In ARC, whether we should autorelease the return value.
580 bool AutoreleaseResult = false;
581
582 /// Whether we processed a Microsoft-style asm block during CodeGen. These can
583 /// potentially set the return value.
584 bool SawAsmBlock = false;
585
587
588 /// True if the current function is an outlined SEH helper. This can be a
589 /// finally block or filter expression.
591
592 /// True if CodeGen currently emits code inside presereved access index
593 /// region.
595
596 /// True if the current statement has nomerge attribute.
598
599 /// True if the current statement has noinline attribute.
601
602 /// True if the current statement has always_inline attribute.
604
605 /// True if the current statement has noconvergent attribute.
607
608 /// HLSL Branch attribute.
609 HLSLControlFlowHintAttr::Spelling HLSLControlFlowAttr =
610 HLSLControlFlowHintAttr::SpellingNotCalculated;
611
612 // The CallExpr within the current statement that the musttail attribute
613 // applies to. nullptr if there is no 'musttail' on the current statement.
614 const CallExpr *MustTailCall = nullptr;
615
616 /// Returns true if a function must make progress, which means the
617 /// mustprogress attribute can be added.
619 if (CGM.getCodeGenOpts().getFiniteLoops() ==
621 return false;
622
623 // C++11 and later guarantees that a thread eventually will do one of the
624 // following (C++11 [intro.multithread]p24 and C++17 [intro.progress]p1):
625 // - terminate,
626 // - make a call to a library I/O function,
627 // - perform an access through a volatile glvalue, or
628 // - perform a synchronization operation or an atomic operation.
629 //
630 // Hence each function is 'mustprogress' in C++11 or later.
631 return getLangOpts().CPlusPlus11;
632 }
633
634 /// Returns true if a loop must make progress, which means the mustprogress
635 /// attribute can be added. \p HasConstantCond indicates whether the branch
636 /// condition is a known constant.
637 bool checkIfLoopMustProgress(const Expr *, bool HasEmptyBody);
638
640 llvm::Value *BlockPointer = nullptr;
641
642 llvm::DenseMap<const ValueDecl *, FieldDecl *> LambdaCaptureFields;
644
645 /// A mapping from NRVO variables to the flags used to indicate
646 /// when the NRVO has been applied to this variable.
647 llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
648
651
652 // A stack of cleanups which were added to EHStack but have to be deactivated
653 // later before being popped or emitted. These are usually deactivated on
654 // exiting a `CleanupDeactivationScope` scope. For instance, after a
655 // full-expr.
656 //
657 // These are specially useful for correctly emitting cleanups while
658 // encountering branches out of expression (through stmt-expr or coroutine
659 // suspensions).
665
666 // Enters a new scope for capturing cleanups which are deferred to be
667 // deactivated, all of which will be deactivated once the scope is exited.
669 CodeGenFunction &CGF;
676
678 assert(!Deactivated && "Deactivating already deactivated scope");
679 auto &Stack = CGF.DeferredDeactivationCleanupStack;
680 for (size_t I = Stack.size(); I > OldDeactivateCleanupStackSize; I--) {
681 CGF.DeactivateCleanupBlock(Stack[I - 1].Cleanup,
682 Stack[I - 1].DominatingIP);
683 Stack[I - 1].DominatingIP->eraseFromParent();
684 }
685 Stack.resize(OldDeactivateCleanupStackSize);
686 Deactivated = true;
687 }
688
690 if (Deactivated)
691 return;
693 }
694 };
695
697
698 llvm::Instruction *CurrentFuncletPad = nullptr;
699
700 class CallLifetimeEnd final : public EHScopeStack::Cleanup {
701 bool isRedundantBeforeReturn() override { return true; }
702
703 llvm::Value *Addr;
704
705 public:
706 CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
707
708 void Emit(CodeGenFunction &CGF, Flags flags) override {
709 CGF.EmitLifetimeEnd(Addr);
710 }
711 };
712
713 // We are using objects of this 'cleanup' class to emit fake.use calls
714 // for -fextend-variable-liveness. They are placed at the end of a variable's
715 // scope analogous to lifetime markers.
716 class FakeUse final : public EHScopeStack::Cleanup {
717 Address Addr;
718
719 public:
720 FakeUse(Address addr) : Addr(addr) {}
721
722 void Emit(CodeGenFunction &CGF, Flags flags) override {
723 CGF.EmitFakeUse(Addr);
724 }
725 };
726
727 /// Header for data within LifetimeExtendedCleanupStack.
728 struct alignas(uint64_t) LifetimeExtendedCleanupHeader {
729 /// The size of the following cleanup object.
730 unsigned Size;
731 /// The kind of cleanup to push.
732 LLVM_PREFERRED_TYPE(CleanupKind)
734 /// Whether this is a conditional cleanup.
735 LLVM_PREFERRED_TYPE(bool)
736 unsigned IsConditional : 1;
737
738 size_t getSize() const { return Size; }
739 CleanupKind getKind() const { return (CleanupKind)Kind; }
740 bool isConditional() const { return IsConditional; }
741 };
742
743 /// i32s containing the indexes of the cleanup destinations.
745
747
748 /// EHResumeBlock - Unified block containing a call to llvm.eh.resume.
749 llvm::BasicBlock *EHResumeBlock = nullptr;
750
751 /// The exception slot. All landing pads write the current exception pointer
752 /// into this alloca.
753 llvm::Value *ExceptionSlot = nullptr;
754
755 /// The selector slot. Under the MandatoryCleanup model, all landing pads
756 /// write the current selector value into this alloca.
757 llvm::AllocaInst *EHSelectorSlot = nullptr;
758
759 /// A stack of exception code slots. Entering an __except block pushes a slot
760 /// on the stack and leaving pops one. The __exception_code() intrinsic loads
761 /// a value from the top of the stack.
763
764 /// Value returned by __exception_info intrinsic.
765 llvm::Value *SEHInfo = nullptr;
766
767 /// Emits a landing pad for the current EH stack.
768 llvm::BasicBlock *EmitLandingPad();
769
770 llvm::BasicBlock *getInvokeDestImpl();
771
772 /// Parent loop-based directive for scan directive.
774 llvm::BasicBlock *OMPBeforeScanBlock = nullptr;
775 llvm::BasicBlock *OMPAfterScanBlock = nullptr;
776 llvm::BasicBlock *OMPScanExitBlock = nullptr;
777 llvm::BasicBlock *OMPScanDispatch = nullptr;
778 bool OMPFirstScanLoop = false;
779
780 /// Manages parent directive for scan directives.
782 CodeGenFunction &CGF;
783 const OMPExecutableDirective *ParentLoopDirectiveForScan;
784
785 public:
787 CodeGenFunction &CGF,
788 const OMPExecutableDirective &ParentLoopDirectiveForScan)
789 : CGF(CGF),
790 ParentLoopDirectiveForScan(CGF.OMPParentLoopDirectiveForScan) {
791 CGF.OMPParentLoopDirectiveForScan = &ParentLoopDirectiveForScan;
792 }
794 CGF.OMPParentLoopDirectiveForScan = ParentLoopDirectiveForScan;
795 }
796 };
797
798 template <class T>
800 return DominatingValue<T>::save(*this, value);
801 }
802
804 public:
805 CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures);
806 CGFPOptionsRAII(CodeGenFunction &CGF, const Expr *E);
808
809 private:
810 void ConstructorHelper(FPOptions FPFeatures);
811 CodeGenFunction &CGF;
812 FPOptions OldFPFeatures;
813 llvm::fp::ExceptionBehavior OldExcept;
814 llvm::RoundingMode OldRounding;
815 std::optional<CGBuilderTy::FastMathFlagGuard> FMFGuard;
816 };
818
820 public:
822 : CGM(CGM_), SavedAtomicOpts(CGM.getAtomicOpts()) {
823 CGM.setAtomicOpts(AO);
824 }
825 CGAtomicOptionsRAII(CodeGenModule &CGM_, const AtomicAttr *AA)
826 : CGM(CGM_), SavedAtomicOpts(CGM.getAtomicOpts()) {
827 if (!AA)
828 return;
829 AtomicOptions AO = SavedAtomicOpts;
830 for (auto Option : AA->atomicOptions()) {
831 switch (Option) {
832 case AtomicAttr::remote_memory:
833 AO.remote_memory = true;
834 break;
835 case AtomicAttr::no_remote_memory:
836 AO.remote_memory = false;
837 break;
838 case AtomicAttr::fine_grained_memory:
839 AO.fine_grained_memory = true;
840 break;
841 case AtomicAttr::no_fine_grained_memory:
842 AO.fine_grained_memory = false;
843 break;
844 case AtomicAttr::ignore_denormal_mode:
845 AO.ignore_denormal_mode = true;
846 break;
847 case AtomicAttr::no_ignore_denormal_mode:
848 AO.ignore_denormal_mode = false;
849 break;
850 }
851 }
852 CGM.setAtomicOpts(AO);
853 }
854
857 ~CGAtomicOptionsRAII() { CGM.setAtomicOpts(SavedAtomicOpts); }
858
859 private:
861 AtomicOptions SavedAtomicOpts;
862 };
863
864public:
865 /// ObjCEHValueStack - Stack of Objective-C exception values, used for
866 /// rethrows.
868
869 /// A class controlling the emission of a finally block.
871 /// Where the catchall's edge through the cleanup should go.
872 JumpDest RethrowDest;
873
874 /// A function to call to enter the catch.
875 llvm::FunctionCallee BeginCatchFn;
876
877 /// An i1 variable indicating whether or not the @finally is
878 /// running for an exception.
879 llvm::AllocaInst *ForEHVar = nullptr;
880
881 /// An i8* variable into which the exception pointer to rethrow
882 /// has been saved.
883 llvm::AllocaInst *SavedExnVar = nullptr;
884
885 public:
886 void enter(CodeGenFunction &CGF, const Stmt *Finally,
887 llvm::FunctionCallee beginCatchFn,
888 llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn);
889 void exit(CodeGenFunction &CGF);
890 };
891
892 /// Returns true inside SEH __try blocks.
893 bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); }
894
895 /// Returns true while emitting a cleanuppad.
899
900 /// pushFullExprCleanup - Push a cleanup to be run at the end of the
901 /// current full-expression. Safe against the possibility that
902 /// we're currently inside a conditionally-evaluated expression.
903 template <class T, class... As>
904 void pushFullExprCleanup(CleanupKind kind, As... A) {
905 // If we're not in a conditional branch, or if none of the
906 // arguments requires saving, then use the unconditional cleanup.
908 return EHStack.pushCleanup<T>(kind, A...);
909
910 // Stash values in a tuple so we can guarantee the order of saves.
911 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
912 SavedTuple Saved{saveValueInCond(A)...};
913
914 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
915 EHStack.pushCleanupTuple<CleanupType>(kind, Saved);
917 }
918
919 /// Queue a cleanup to be pushed after finishing the current full-expression,
920 /// potentially with an active flag.
921 template <class T, class... As>
925 Kind, RawAddress::invalid(), A...);
926
927 RawAddress ActiveFlag = createCleanupActiveFlag();
928 assert(!DominatingValue<Address>::needsSaving(ActiveFlag) &&
929 "cleanup active flag should never need saving");
930
931 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
932 SavedTuple Saved{saveValueInCond(A)...};
933
934 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
936 Saved);
937 }
938
939 template <class T, class... As>
941 RawAddress ActiveFlag, As... A) {
942 LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind,
943 ActiveFlag.isValid()};
944
945 size_t OldSize = LifetimeExtendedCleanupStack.size();
947 LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size +
948 (Header.IsConditional ? sizeof(ActiveFlag) : 0));
949
950 static_assert((alignof(LifetimeExtendedCleanupHeader) == alignof(T)) &&
951 (alignof(T) == alignof(RawAddress)),
952 "Cleanup will be allocated on misaligned address");
953 char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
954 new (Buffer) LifetimeExtendedCleanupHeader(Header);
955 new (Buffer + sizeof(Header)) T(A...);
956 if (Header.IsConditional)
957 new (Buffer + sizeof(Header) + sizeof(T)) RawAddress(ActiveFlag);
958 }
959
960 // Push a cleanup onto EHStack and deactivate it later. It is usually
961 // deactivated when exiting a `CleanupDeactivationScope` (for example: after a
962 // full expression).
963 template <class T, class... As>
965 // Placeholder dominating IP for this cleanup.
966 llvm::Instruction *DominatingIP =
967 Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
968 EHStack.pushCleanup<T>(Kind, A...);
970 {EHStack.stable_begin(), DominatingIP});
971 }
972
973 /// Set up the last cleanup that was pushed as a conditional
974 /// full-expression cleanup.
978
981
982 /// PushDestructorCleanup - Push a cleanup to call the
983 /// complete-object destructor of an object of the given type at the
984 /// given address. Does nothing if T is not a C++ class type with a
985 /// non-trivial destructor.
987
988 /// PushDestructorCleanup - Push a cleanup to call the
989 /// complete-object variant of the given destructor on the object at
990 /// the given address.
992 Address Addr);
993
994 /// PopCleanupBlock - Will pop the cleanup entry on the stack and
995 /// process all branch fixups.
996 void PopCleanupBlock(bool FallThroughIsBranchThrough = false,
997 bool ForDeactivation = false);
998
999 /// DeactivateCleanupBlock - Deactivates the given cleanup block.
1000 /// The block cannot be reactivated. Pops it if it's the top of the
1001 /// stack.
1002 ///
1003 /// \param DominatingIP - An instruction which is known to
1004 /// dominate the current IP (if set) and which lies along
1005 /// all paths of execution between the current IP and the
1006 /// the point at which the cleanup comes into scope.
1008 llvm::Instruction *DominatingIP);
1009
1010 /// ActivateCleanupBlock - Activates an initially-inactive cleanup.
1011 /// Cannot be used to resurrect a deactivated cleanup.
1012 ///
1013 /// \param DominatingIP - An instruction which is known to
1014 /// dominate the current IP (if set) and which lies along
1015 /// all paths of execution between the current IP and the
1016 /// the point at which the cleanup comes into scope.
1018 llvm::Instruction *DominatingIP);
1019
1020 /// Enters a new scope for capturing cleanups, all of which
1021 /// will be executed once the scope is exited.
1022 class RunCleanupsScope {
1023 EHScopeStack::stable_iterator CleanupStackDepth, OldCleanupScopeDepth;
1024 size_t LifetimeExtendedCleanupStackSize;
1025 CleanupDeactivationScope DeactivateCleanups;
1026 bool OldDidCallStackSave;
1027
1028 protected:
1030
1031 private:
1032 RunCleanupsScope(const RunCleanupsScope &) = delete;
1033 void operator=(const RunCleanupsScope &) = delete;
1034
1035 protected:
1036 CodeGenFunction &CGF;
1037
1038 public:
1039 /// Enter a new cleanup scope.
1040 explicit RunCleanupsScope(CodeGenFunction &CGF)
1041 : DeactivateCleanups(CGF), PerformCleanup(true), CGF(CGF) {
1042 CleanupStackDepth = CGF.EHStack.stable_begin();
1043 LifetimeExtendedCleanupStackSize =
1044 CGF.LifetimeExtendedCleanupStack.size();
1045 OldDidCallStackSave = CGF.DidCallStackSave;
1046 CGF.DidCallStackSave = false;
1047 OldCleanupScopeDepth = CGF.CurrentCleanupScopeDepth;
1048 CGF.CurrentCleanupScopeDepth = CleanupStackDepth;
1049 }
1050
1051 /// Exit this cleanup scope, emitting any accumulated cleanups.
1053 if (PerformCleanup)
1054 ForceCleanup();
1055 }
1056
1057 /// Determine whether this scope requires any cleanups.
1058 bool requiresCleanups() const {
1059 return CGF.EHStack.stable_begin() != CleanupStackDepth;
1060 }
1061
1062 /// Force the emission of cleanups now, instead of waiting
1063 /// until this object is destroyed.
1064 /// \param ValuesToReload - A list of values that need to be available at
1065 /// the insertion point after cleanup emission. If cleanup emission created
1066 /// a shared cleanup block, these value pointers will be rewritten.
1067 /// Otherwise, they not will be modified.
1068 void
1069 ForceCleanup(std::initializer_list<llvm::Value **> ValuesToReload = {}) {
1070 assert(PerformCleanup && "Already forced cleanup");
1071 CGF.DidCallStackSave = OldDidCallStackSave;
1072 DeactivateCleanups.ForceDeactivate();
1073 CGF.PopCleanupBlocks(CleanupStackDepth, LifetimeExtendedCleanupStackSize,
1074 ValuesToReload);
1075 PerformCleanup = false;
1076 CGF.CurrentCleanupScopeDepth = OldCleanupScopeDepth;
1077 }
1078 };
1079
1080 // Cleanup stack depth of the RunCleanupsScope that was pushed most recently.
1083
1084 class LexicalScope : public RunCleanupsScope {
1085 SourceRange Range;
1087 LexicalScope *ParentScope;
1088
1089 LexicalScope(const LexicalScope &) = delete;
1090 void operator=(const LexicalScope &) = delete;
1091
1092 public:
1093 /// Enter a new cleanup scope.
1094 explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range);
1095
1096 void addLabel(const LabelDecl *label) {
1097 assert(PerformCleanup && "adding label to dead scope?");
1098 Labels.push_back(label);
1099 }
1100
1101 /// Exit this cleanup scope, emitting any accumulated
1102 /// cleanups.
1103 ~LexicalScope();
1104
1105 /// Force the emission of cleanups now, instead of waiting
1106 /// until this object is destroyed.
1108 CGF.CurLexicalScope = ParentScope;
1110
1111 if (!Labels.empty())
1112 rescopeLabels();
1113 }
1114
1115 bool hasLabels() const { return !Labels.empty(); }
1116
1117 void rescopeLabels();
1118 };
1119
1120 typedef llvm::DenseMap<const Decl *, Address> DeclMapTy;
1121
1122 /// The class used to assign some variables some temporarily addresses.
1123 class OMPMapVars {
1124 DeclMapTy SavedLocals;
1125 DeclMapTy SavedTempAddresses;
1126 OMPMapVars(const OMPMapVars &) = delete;
1127 void operator=(const OMPMapVars &) = delete;
1128
1129 public:
1130 explicit OMPMapVars() = default;
1132 assert(SavedLocals.empty() && "Did not restored original addresses.");
1133 };
1134
1135 /// Sets the address of the variable \p LocalVD to be \p TempAddr in
1136 /// function \p CGF.
1137 /// \return true if at least one variable was set already, false otherwise.
1138 bool setVarAddr(CodeGenFunction &CGF, const VarDecl *LocalVD,
1139 Address TempAddr) {
1140 LocalVD = LocalVD->getCanonicalDecl();
1141 // Only save it once.
1142 if (SavedLocals.count(LocalVD))
1143 return false;
1144
1145 // Copy the existing local entry to SavedLocals.
1146 auto it = CGF.LocalDeclMap.find(LocalVD);
1147 if (it != CGF.LocalDeclMap.end())
1148 SavedLocals.try_emplace(LocalVD, it->second);
1149 else
1150 SavedLocals.try_emplace(LocalVD, Address::invalid());
1151
1152 // Generate the private entry.
1153 QualType VarTy = LocalVD->getType();
1154 if (VarTy->isReferenceType()) {
1155 Address Temp = CGF.CreateMemTemp(VarTy);
1156 CGF.Builder.CreateStore(TempAddr.emitRawPointer(CGF), Temp);
1157 TempAddr = Temp;
1158 }
1159 SavedTempAddresses.try_emplace(LocalVD, TempAddr);
1160
1161 return true;
1162 }
1163
1164 /// Applies new addresses to the list of the variables.
1165 /// \return true if at least one variable is using new address, false
1166 /// otherwise.
1167 bool apply(CodeGenFunction &CGF) {
1168 copyInto(SavedTempAddresses, CGF.LocalDeclMap);
1169 SavedTempAddresses.clear();
1170 return !SavedLocals.empty();
1171 }
1172
1173 /// Restores original addresses of the variables.
1174 void restore(CodeGenFunction &CGF) {
1175 if (!SavedLocals.empty()) {
1176 copyInto(SavedLocals, CGF.LocalDeclMap);
1177 SavedLocals.clear();
1178 }
1179 }
1180
1181 private:
1182 /// Copy all the entries in the source map over the corresponding
1183 /// entries in the destination, which must exist.
1184 static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) {
1185 for (auto &[Decl, Addr] : Src) {
1186 if (!Addr.isValid())
1187 Dest.erase(Decl);
1188 else
1189 Dest.insert_or_assign(Decl, Addr);
1190 }
1191 }
1192 };
1193
1194 /// The scope used to remap some variables as private in the OpenMP loop body
1195 /// (or other captured region emitted without outlining), and to restore old
1196 /// vars back on exit.
1197 class OMPPrivateScope : public RunCleanupsScope {
1198 OMPMapVars MappedVars;
1199 OMPPrivateScope(const OMPPrivateScope &) = delete;
1200 void operator=(const OMPPrivateScope &) = delete;
1201
1202 public:
1203 /// Enter a new OpenMP private scope.
1204 explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {}
1205
1206 /// Registers \p LocalVD variable as a private with \p Addr as the address
1207 /// of the corresponding private variable. \p
1208 /// PrivateGen is the address of the generated private variable.
1209 /// \return true if the variable is registered as private, false if it has
1210 /// been privatized already.
1211 bool addPrivate(const VarDecl *LocalVD, Address Addr) {
1212 assert(PerformCleanup && "adding private to dead scope");
1213 return MappedVars.setVarAddr(CGF, LocalVD, Addr);
1214 }
1215
1216 /// Privatizes local variables previously registered as private.
1217 /// Registration is separate from the actual privatization to allow
1218 /// initializers use values of the original variables, not the private one.
1219 /// This is important, for example, if the private variable is a class
1220 /// variable initialized by a constructor that references other private
1221 /// variables. But at initialization original variables must be used, not
1222 /// private copies.
1223 /// \return true if at least one variable was privatized, false otherwise.
1224 bool Privatize() { return MappedVars.apply(CGF); }
1225
1230
1231 /// Exit scope - all the mapped variables are restored.
1233 if (PerformCleanup)
1234 ForceCleanup();
1235 }
1236
1237 /// Checks if the global variable is captured in current function.
1238 bool isGlobalVarCaptured(const VarDecl *VD) const {
1239 VD = VD->getCanonicalDecl();
1240 return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0;
1241 }
1242
1243 /// Restore all mapped variables w/o clean up. This is usefully when we want
1244 /// to reference the original variables but don't want the clean up because
1245 /// that could emit lifetime end too early, causing backend issue #56913.
1246 void restoreMap() { MappedVars.restore(CGF); }
1247 };
1248
1249 /// Save/restore original map of previously emitted local vars in case when we
1250 /// need to duplicate emission of the same code several times in the same
1251 /// function for OpenMP code.
1253 CodeGenFunction &CGF;
1254 DeclMapTy SavedMap;
1255
1256 public:
1257 OMPLocalDeclMapRAII(CodeGenFunction &CGF)
1258 : CGF(CGF), SavedMap(CGF.LocalDeclMap) {}
1259 ~OMPLocalDeclMapRAII() { SavedMap.swap(CGF.LocalDeclMap); }
1260 };
1261
1262 /// Takes the old cleanup stack size and emits the cleanup blocks
1263 /// that have been added.
1264 void
1266 std::initializer_list<llvm::Value **> ValuesToReload = {});
1267
1268 /// Takes the old cleanup stack size and emits the cleanup blocks
1269 /// that have been added, then adds all lifetime-extended cleanups from
1270 /// the given position to the stack.
1271 void
1272 PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize,
1273 size_t OldLifetimeExtendedStackSize,
1274 std::initializer_list<llvm::Value **> ValuesToReload = {});
1275
1276 void ResolveBranchFixups(llvm::BasicBlock *Target);
1277
1278 /// The given basic block lies in the current EH scope, but may be a
1279 /// target of a potentially scope-crossing jump; get a stable handle
1280 /// to which we can perform this jump later.
1282 return JumpDest(Target, EHStack.getInnermostNormalCleanup(),
1284 }
1285
1286 /// The given basic block lies in the current EH scope, but may be a
1287 /// target of a potentially scope-crossing jump; get a stable handle
1288 /// to which we can perform this jump later.
1289 JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) {
1291 }
1292
1293 /// EmitBranchThroughCleanup - Emit a branch from the current insert
1294 /// block through the normal cleanup handling code (if any) and then
1295 /// on to \arg Dest.
1296 void EmitBranchThroughCleanup(JumpDest Dest);
1297
1298 /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
1299 /// specified destination obviously has no cleanups to run. 'false' is always
1300 /// a conservatively correct answer for this method.
1301 bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const;
1302
1303 /// popCatchScope - Pops the catch scope at the top of the EHScope
1304 /// stack, emitting any required code (other than the catch handlers
1305 /// themselves).
1306 void popCatchScope();
1307
1308 llvm::BasicBlock *getEHResumeBlock(bool isCleanup);
1309 llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope);
1310 llvm::BasicBlock *
1312
1313 /// An object to manage conditionally-evaluated expressions.
1315 llvm::BasicBlock *StartBB;
1316
1317 public:
1318 ConditionalEvaluation(CodeGenFunction &CGF)
1319 : StartBB(CGF.Builder.GetInsertBlock()) {}
1320
1321 void begin(CodeGenFunction &CGF) {
1322 assert(CGF.OutermostConditional != this);
1323 if (!CGF.OutermostConditional)
1324 CGF.OutermostConditional = this;
1325 }
1326
1327 void end(CodeGenFunction &CGF) {
1328 assert(CGF.OutermostConditional != nullptr);
1329 if (CGF.OutermostConditional == this)
1330 CGF.OutermostConditional = nullptr;
1331 }
1332
1333 /// Returns a block which will be executed prior to each
1334 /// evaluation of the conditional code.
1335 llvm::BasicBlock *getStartingBlock() const { return StartBB; }
1336 };
1337
1338 /// isInConditionalBranch - Return true if we're currently emitting
1339 /// one branch or the other of a conditional expression.
1340 bool isInConditionalBranch() const { return OutermostConditional != nullptr; }
1341
1342 void setBeforeOutermostConditional(llvm::Value *value, Address addr,
1343 CodeGenFunction &CGF) {
1344 assert(isInConditionalBranch());
1345 llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
1346 auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
1347 block->back().getIterator());
1348 store->setAlignment(addr.getAlignment().getAsAlign());
1349 }
1350
1351 /// An RAII object to record that we're evaluating a statement
1352 /// expression.
1354 CodeGenFunction &CGF;
1355
1356 /// We have to save the outermost conditional: cleanups in a
1357 /// statement expression aren't conditional just because the
1358 /// StmtExpr is.
1359 ConditionalEvaluation *SavedOutermostConditional;
1360
1361 public:
1362 StmtExprEvaluation(CodeGenFunction &CGF)
1363 : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) {
1364 CGF.OutermostConditional = nullptr;
1365 }
1366
1368 CGF.OutermostConditional = SavedOutermostConditional;
1369 CGF.EnsureInsertPoint();
1370 }
1371 };
1372
1373 /// An object which temporarily prevents a value from being
1374 /// destroyed by aggressive peephole optimizations that assume that
1375 /// all uses of a value have been realized in the IR.
1377 llvm::Instruction *Inst = nullptr;
1378 friend class CodeGenFunction;
1379
1380 public:
1382 };
1383
1384 /// A non-RAII class containing all the information about a bound
1385 /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
1386 /// this which makes individual mappings very simple; using this
1387 /// class directly is useful when you have a variable number of
1388 /// opaque values or don't want the RAII functionality for some
1389 /// reason.
1390 class OpaqueValueMappingData {
1391 const OpaqueValueExpr *OpaqueValue;
1392 bool BoundLValue;
1394
1395 OpaqueValueMappingData(const OpaqueValueExpr *ov, bool boundLValue)
1396 : OpaqueValue(ov), BoundLValue(boundLValue) {}
1397
1398 public:
1400
1401 static bool shouldBindAsLValue(const Expr *expr) {
1402 // gl-values should be bound as l-values for obvious reasons.
1403 // Records should be bound as l-values because IR generation
1404 // always keeps them in memory. Expressions of function type
1405 // act exactly like l-values but are formally required to be
1406 // r-values in C.
1407 return expr->isGLValue() || expr->getType()->isFunctionType() ||
1408 hasAggregateEvaluationKind(expr->getType());
1409 }
1410
1412 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e) {
1413 if (shouldBindAsLValue(ov))
1414 return bind(CGF, ov, CGF.EmitLValue(e));
1415 return bind(CGF, ov, CGF.EmitAnyExpr(e));
1416 }
1417
1419 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const LValue &lv) {
1420 assert(shouldBindAsLValue(ov));
1421 CGF.OpaqueLValues.insert(std::make_pair(ov, lv));
1422 return OpaqueValueMappingData(ov, true);
1423 }
1424
1426 bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const RValue &rv) {
1427 assert(!shouldBindAsLValue(ov));
1428 CGF.OpaqueRValues.insert(std::make_pair(ov, rv));
1429
1430 OpaqueValueMappingData data(ov, false);
1431
1432 // Work around an extremely aggressive peephole optimization in
1433 // EmitScalarConversion which assumes that all other uses of a
1434 // value are extant.
1435 data.Protection = CGF.protectFromPeepholes(rv);
1436
1437 return data;
1438 }
1439
1440 bool isValid() const { return OpaqueValue != nullptr; }
1441 void clear() { OpaqueValue = nullptr; }
1442
1443 void unbind(CodeGenFunction &CGF) {
1444 assert(OpaqueValue && "no data to unbind!");
1445
1446 if (BoundLValue) {
1447 CGF.OpaqueLValues.erase(OpaqueValue);
1448 } else {
1449 CGF.OpaqueRValues.erase(OpaqueValue);
1450 CGF.unprotectFromPeepholes(Protection);
1451 }
1452 }
1453 };
1454
1455 /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
1457 CodeGenFunction &CGF;
1459
1460 public:
1464
1465 /// Build the opaque value mapping for the given conditional
1466 /// operator if it's the GNU ?: extension. This is a common
1467 /// enough pattern that the convenience operator is really
1468 /// helpful.
1469 ///
1470 OpaqueValueMapping(CodeGenFunction &CGF,
1472 : CGF(CGF) {
1474 // Leave Data empty.
1475 return;
1476
1479 e->getCommon());
1480 }
1481
1482 /// Build the opaque value mapping for an OpaqueValueExpr whose source
1483 /// expression is set to the expression the OVE represents.
1484 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *OV)
1485 : CGF(CGF) {
1486 if (OV) {
1487 assert(OV->getSourceExpr() && "wrong form of OpaqueValueMapping used "
1488 "for OVE with no source expression");
1489 Data = OpaqueValueMappingData::bind(CGF, OV, OV->getSourceExpr());
1490 }
1491 }
1492
1493 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue,
1494 LValue lvalue)
1495 : CGF(CGF),
1496 Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {}
1497
1498 OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue,
1499 RValue rvalue)
1500 : CGF(CGF),
1501 Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {}
1502
1503 void pop() {
1504 Data.unbind(CGF);
1505 Data.clear();
1506 }
1507
1509 if (Data.isValid())
1510 Data.unbind(CGF);
1511 }
1512 };
1513
1514private:
1515 CGDebugInfo *DebugInfo;
1516 /// Used to create unique names for artificial VLA size debug info variables.
1517 unsigned VLAExprCounter = 0;
1518 bool DisableDebugInfo = false;
1519
1520 /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
1521 /// calling llvm.stacksave for multiple VLAs in the same scope.
1522 bool DidCallStackSave = false;
1523
1524 /// IndirectBranch - The first time an indirect goto is seen we create a block
1525 /// with an indirect branch. Every time we see the address of a label taken,
1526 /// we add the label to the indirect goto. Every subsequent indirect goto is
1527 /// codegen'd as a jump to the IndirectBranch's basic block.
1528 llvm::IndirectBrInst *IndirectBranch = nullptr;
1529
1530 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1531 /// decls.
1532 DeclMapTy LocalDeclMap;
1533
1534 // Keep track of the cleanups for callee-destructed parameters pushed to the
1535 // cleanup stack so that they can be deactivated later.
1536 llvm::DenseMap<const ParmVarDecl *, EHScopeStack::stable_iterator>
1537 CalleeDestructedParamCleanups;
1538
1539 /// SizeArguments - If a ParmVarDecl had the pass_object_size attribute, this
1540 /// will contain a mapping from said ParmVarDecl to its implicit "object_size"
1541 /// parameter.
1542 llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2>
1543 SizeArguments;
1544
1545 /// Track escaped local variables with auto storage. Used during SEH
1546 /// outlining to produce a call to llvm.localescape.
1547 llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals;
1548
1549 /// LabelMap - This keeps track of the LLVM basic block for each C label.
1550 llvm::DenseMap<const LabelDecl *, JumpDest> LabelMap;
1551
1552 // BreakContinueStack - This keeps track of where break and continue
1553 // statements should jump to.
1554 struct BreakContinue {
1555 BreakContinue(const Stmt &LoopOrSwitch, JumpDest Break, JumpDest Continue)
1556 : LoopOrSwitch(&LoopOrSwitch), BreakBlock(Break),
1557 ContinueBlock(Continue) {}
1558
1559 const Stmt *LoopOrSwitch;
1560 JumpDest BreakBlock;
1561 JumpDest ContinueBlock;
1562 };
1563 SmallVector<BreakContinue, 8> BreakContinueStack;
1564
1565 /// Handles cancellation exit points in OpenMP-related constructs.
1566 class OpenMPCancelExitStack {
1567 /// Tracks cancellation exit point and join point for cancel-related exit
1568 /// and normal exit.
1569 struct CancelExit {
1570 CancelExit() = default;
1571 CancelExit(OpenMPDirectiveKind Kind, JumpDest ExitBlock,
1572 JumpDest ContBlock)
1573 : Kind(Kind), ExitBlock(ExitBlock), ContBlock(ContBlock) {}
1574 OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown;
1575 /// true if the exit block has been emitted already by the special
1576 /// emitExit() call, false if the default codegen is used.
1577 bool HasBeenEmitted = false;
1578 JumpDest ExitBlock;
1579 JumpDest ContBlock;
1580 };
1581
1582 SmallVector<CancelExit, 8> Stack;
1583
1584 public:
1585 OpenMPCancelExitStack() : Stack(1) {}
1586 ~OpenMPCancelExitStack() = default;
1587 /// Fetches the exit block for the current OpenMP construct.
1588 JumpDest getExitBlock() const { return Stack.back().ExitBlock; }
1589 /// Emits exit block with special codegen procedure specific for the related
1590 /// OpenMP construct + emits code for normal construct cleanup.
1591 void emitExit(CodeGenFunction &CGF, OpenMPDirectiveKind Kind,
1592 const llvm::function_ref<void(CodeGenFunction &)> CodeGen) {
1593 if (Stack.back().Kind == Kind && getExitBlock().isValid()) {
1594 assert(CGF.getOMPCancelDestination(Kind).isValid());
1595 assert(CGF.HaveInsertPoint());
1596 assert(!Stack.back().HasBeenEmitted);
1597 auto IP = CGF.Builder.saveAndClearIP();
1598 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1599 CodeGen(CGF);
1600 CGF.EmitBranch(Stack.back().ContBlock.getBlock());
1601 CGF.Builder.restoreIP(IP);
1602 Stack.back().HasBeenEmitted = true;
1603 }
1604 CodeGen(CGF);
1605 }
1606 /// Enter the cancel supporting \a Kind construct.
1607 /// \param Kind OpenMP directive that supports cancel constructs.
1608 /// \param HasCancel true, if the construct has inner cancel directive,
1609 /// false otherwise.
1610 void enter(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel) {
1611 Stack.push_back({Kind,
1612 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.exit")
1613 : JumpDest(),
1614 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.cont")
1615 : JumpDest()});
1616 }
1617 /// Emits default exit point for the cancel construct (if the special one
1618 /// has not be used) + join point for cancel/normal exits.
1619 void exit(CodeGenFunction &CGF) {
1620 if (getExitBlock().isValid()) {
1621 assert(CGF.getOMPCancelDestination(Stack.back().Kind).isValid());
1622 bool HaveIP = CGF.HaveInsertPoint();
1623 if (!Stack.back().HasBeenEmitted) {
1624 if (HaveIP)
1625 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1626 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1627 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1628 }
1629 CGF.EmitBlock(Stack.back().ContBlock.getBlock());
1630 if (!HaveIP) {
1631 CGF.Builder.CreateUnreachable();
1632 CGF.Builder.ClearInsertionPoint();
1633 }
1634 }
1635 Stack.pop_back();
1636 }
1637 };
1638 OpenMPCancelExitStack OMPCancelStack;
1639
1640 /// Lower the Likelihood knowledge about the \p Cond via llvm.expect intrin.
1641 llvm::Value *emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond,
1642 Stmt::Likelihood LH);
1643
1644 std::unique_ptr<CodeGenPGO> PGO;
1645
1646 /// Bitmap used by MC/DC to track condition outcomes of a boolean expression.
1647 Address MCDCCondBitmapAddr = Address::invalid();
1648
1649 /// Calculate branch weights appropriate for PGO data
1650 llvm::MDNode *createProfileWeights(uint64_t TrueCount,
1651 uint64_t FalseCount) const;
1652 llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights) const;
1653 llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond,
1654 uint64_t LoopCount) const;
1655
1656public:
1657 std::pair<bool, bool> getIsCounterPair(const Stmt *S) const;
1658 void markStmtAsUsed(bool Skipped, const Stmt *S);
1659 void markStmtMaybeUsed(const Stmt *S);
1660
1661 /// Increment the profiler's counter for the given statement by \p StepV.
1662 /// If \p StepV is null, the default increment is 1.
1663 void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr);
1664
1666 return (CGM.getCodeGenOpts().hasProfileClangInstr() &&
1667 CGM.getCodeGenOpts().MCDCCoverage &&
1668 !CurFn->hasFnAttribute(llvm::Attribute::NoProfile));
1669 }
1670
1671 /// Allocate a temp value on the stack that MCDC can use to track condition
1672 /// results.
1674
1675 bool isBinaryLogicalOp(const Expr *E) const {
1676 const BinaryOperator *BOp = dyn_cast<BinaryOperator>(E->IgnoreParens());
1677 return (BOp && BOp->isLogicalOp());
1678 }
1679
1680 /// Zero-init the MCDC temp value.
1681 void maybeResetMCDCCondBitmap(const Expr *E);
1682
1683 /// Increment the profiler's counter for the given expression by \p StepV.
1684 /// If \p StepV is null, the default increment is 1.
1686
1687 /// Update the MCDC temp value with the condition's evaluated result.
1688 void maybeUpdateMCDCCondBitmap(const Expr *E, llvm::Value *Val);
1689
1690 /// Get the profiler's count for the given statement.
1691 uint64_t getProfileCount(const Stmt *S);
1692
1693 /// Set the profiler's current count.
1694 void setCurrentProfileCount(uint64_t Count);
1695
1696 /// Get the profiler's current count. This is generally the count for the most
1697 /// recently incremented counter.
1698 uint64_t getCurrentProfileCount();
1699
1700 /// See CGDebugInfo::addInstToCurrentSourceAtom.
1701 void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction,
1702 llvm::Value *Backup);
1703
1704 /// See CGDebugInfo::addInstToSpecificSourceAtom.
1705 void addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
1706 llvm::Value *Backup, uint64_t Atom);
1707
1708 /// Add \p KeyInstruction and an optional \p Backup instruction to a new atom
1709 /// group (See ApplyAtomGroup for more info).
1710 void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction,
1711 llvm::Value *Backup);
1712
1713private:
1714 /// SwitchInsn - This is nearest current switch instruction. It is null if
1715 /// current context is not in a switch.
1716 llvm::SwitchInst *SwitchInsn = nullptr;
1717 /// The branch weights of SwitchInsn when doing instrumentation based PGO.
1718 SmallVector<uint64_t, 16> *SwitchWeights = nullptr;
1719
1720 /// The likelihood attributes of the SwitchCase.
1721 SmallVector<Stmt::Likelihood, 16> *SwitchLikelihood = nullptr;
1722
1723 /// CaseRangeBlock - This block holds if condition check for last case
1724 /// statement range in current switch instruction.
1725 llvm::BasicBlock *CaseRangeBlock = nullptr;
1726
1727 /// OpaqueLValues - Keeps track of the current set of opaque value
1728 /// expressions.
1729 llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
1730 llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;
1731
1732 // VLASizeMap - This keeps track of the associated size for each VLA type.
1733 // We track this by the size expression rather than the type itself because
1734 // in certain situations, like a const qualifier applied to an VLA typedef,
1735 // multiple VLA types can share the same size expression.
1736 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
1737 // enter/leave scopes.
1738 llvm::DenseMap<const Expr *, llvm::Value *> VLASizeMap;
1739
1740 /// A block containing a single 'unreachable' instruction. Created
1741 /// lazily by getUnreachableBlock().
1742 llvm::BasicBlock *UnreachableBlock = nullptr;
1743
1744 /// Counts of the number return expressions in the function.
1745 unsigned NumReturnExprs = 0;
1746
1747 /// Count the number of simple (constant) return expressions in the function.
1748 unsigned NumSimpleReturnExprs = 0;
1749
1750 /// The last regular (non-return) debug location (breakpoint) in the function.
1751 SourceLocation LastStopPoint;
1752
1753public:
1754 /// Source location information about the default argument or member
1755 /// initializer expression we're evaluating, if any.
1759
1760 /// A scope within which we are constructing the fields of an object which
1761 /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use
1762 /// if we need to evaluate a CXXDefaultInitExpr within the evaluation.
1764 public:
1765 FieldConstructionScope(CodeGenFunction &CGF, Address This)
1766 : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) {
1767 CGF.CXXDefaultInitExprThis = This;
1768 }
1770 CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis;
1771 }
1772
1773 private:
1774 CodeGenFunction &CGF;
1775 Address OldCXXDefaultInitExprThis;
1776 };
1777
1778 /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
1779 /// is overridden to be the object under construction.
1781 public:
1783 : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue),
1784 OldCXXThisAlignment(CGF.CXXThisAlignment),
1786 CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getBasePointer();
1787 CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment();
1788 }
1790 CGF.CXXThisValue = OldCXXThisValue;
1791 CGF.CXXThisAlignment = OldCXXThisAlignment;
1792 }
1793
1794 public:
1795 CodeGenFunction &CGF;
1796 llvm::Value *OldCXXThisValue;
1799 };
1800
1805
1806 /// The scope of an ArrayInitLoopExpr. Within this scope, the value of the
1807 /// current loop index is overridden.
1809 public:
1810 ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index)
1811 : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) {
1812 CGF.ArrayInitIndex = Index;
1813 }
1814 ~ArrayInitLoopExprScope() { CGF.ArrayInitIndex = OldArrayInitIndex; }
1815
1816 private:
1817 CodeGenFunction &CGF;
1818 llvm::Value *OldArrayInitIndex;
1819 };
1820
1822 public:
1824 : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl),
1825 OldCurCodeDecl(CGF.CurCodeDecl),
1826 OldCXXABIThisDecl(CGF.CXXABIThisDecl),
1827 OldCXXABIThisValue(CGF.CXXABIThisValue),
1828 OldCXXThisValue(CGF.CXXThisValue),
1829 OldCXXABIThisAlignment(CGF.CXXABIThisAlignment),
1830 OldCXXThisAlignment(CGF.CXXThisAlignment),
1831 OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy),
1832 OldCXXInheritedCtorInitExprArgs(
1833 std::move(CGF.CXXInheritedCtorInitExprArgs)) {
1834 CGF.CurGD = GD;
1835 CGF.CurFuncDecl = CGF.CurCodeDecl =
1837 CGF.CXXABIThisDecl = nullptr;
1838 CGF.CXXABIThisValue = nullptr;
1839 CGF.CXXThisValue = nullptr;
1840 CGF.CXXABIThisAlignment = CharUnits();
1841 CGF.CXXThisAlignment = CharUnits();
1842 CGF.ReturnValue = Address::invalid();
1843 CGF.FnRetTy = QualType();
1844 CGF.CXXInheritedCtorInitExprArgs.clear();
1845 }
1847 CGF.CurGD = OldCurGD;
1848 CGF.CurFuncDecl = OldCurFuncDecl;
1849 CGF.CurCodeDecl = OldCurCodeDecl;
1850 CGF.CXXABIThisDecl = OldCXXABIThisDecl;
1851 CGF.CXXABIThisValue = OldCXXABIThisValue;
1852 CGF.CXXThisValue = OldCXXThisValue;
1853 CGF.CXXABIThisAlignment = OldCXXABIThisAlignment;
1854 CGF.CXXThisAlignment = OldCXXThisAlignment;
1855 CGF.ReturnValue = OldReturnValue;
1856 CGF.FnRetTy = OldFnRetTy;
1857 CGF.CXXInheritedCtorInitExprArgs =
1858 std::move(OldCXXInheritedCtorInitExprArgs);
1859 }
1860
1861 private:
1862 CodeGenFunction &CGF;
1863 GlobalDecl OldCurGD;
1864 const Decl *OldCurFuncDecl;
1865 const Decl *OldCurCodeDecl;
1866 ImplicitParamDecl *OldCXXABIThisDecl;
1867 llvm::Value *OldCXXABIThisValue;
1868 llvm::Value *OldCXXThisValue;
1869 CharUnits OldCXXABIThisAlignment;
1870 CharUnits OldCXXThisAlignment;
1871 Address OldReturnValue;
1872 QualType OldFnRetTy;
1873 CallArgList OldCXXInheritedCtorInitExprArgs;
1874 };
1875
1876 // Helper class for the OpenMP IR Builder. Allows reusability of code used for
1877 // region body, and finalization codegen callbacks. This will class will also
1878 // contain privatization functions used by the privatization call backs
1879 //
1880 // TODO: this is temporary class for things that are being moved out of
1881 // CGOpenMPRuntime, new versions of current CodeGenFunction methods, or
1882 // utility function for use with the OMPBuilder. Once that move to use the
1883 // OMPBuilder is done, everything here will either become part of CodeGenFunc.
1884 // directly, or a new helper class that will contain functions used by both
1885 // this and the OMPBuilder
1886
1888
1892
1893 using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
1894
1895 /// Cleanup action for allocate support.
1896 class OMPAllocateCleanupTy final : public EHScopeStack::Cleanup {
1897
1898 private:
1899 llvm::CallInst *RTLFnCI;
1900
1901 public:
1902 OMPAllocateCleanupTy(llvm::CallInst *RLFnCI) : RTLFnCI(RLFnCI) {
1903 RLFnCI->removeFromParent();
1904 }
1905
1906 void Emit(CodeGenFunction &CGF, Flags /*flags*/) override {
1907 if (!CGF.HaveInsertPoint())
1908 return;
1909 CGF.Builder.Insert(RTLFnCI);
1910 }
1911 };
1912
1913 /// Returns address of the threadprivate variable for the current
1914 /// thread. This Also create any necessary OMP runtime calls.
1915 ///
1916 /// \param VD VarDecl for Threadprivate variable.
1917 /// \param VDAddr Address of the Vardecl
1918 /// \param Loc The location where the barrier directive was encountered
1919 static Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
1920 const VarDecl *VD, Address VDAddr,
1921 SourceLocation Loc);
1922
1923 /// Gets the OpenMP-specific address of the local variable /p VD.
1924 static Address getAddressOfLocalVariable(CodeGenFunction &CGF,
1925 const VarDecl *VD);
1926 /// Get the platform-specific name separator.
1927 /// \param Parts different parts of the final name that needs separation
1928 /// \param FirstSeparator First separator used between the initial two
1929 /// parts of the name.
1930 /// \param Separator separator used between all of the rest consecutinve
1931 /// parts of the name
1932 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
1933 StringRef FirstSeparator = ".",
1934 StringRef Separator = ".");
1935 /// Emit the Finalization for an OMP region
1936 /// \param CGF The Codegen function this belongs to
1937 /// \param IP Insertion point for generating the finalization code.
1938 static void FinalizeOMPRegion(CodeGenFunction &CGF, InsertPointTy IP) {
1939 CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
1940 assert(IP.getBlock()->end() != IP.getPoint() &&
1941 "OpenMP IR Builder should cause terminated block!");
1942
1943 llvm::BasicBlock *IPBB = IP.getBlock();
1944 llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
1945 assert(DestBB && "Finalization block should have one successor!");
1946
1947 // erase and replace with cleanup branch.
1948 IPBB->getTerminator()->eraseFromParent();
1949 CGF.Builder.SetInsertPoint(IPBB);
1951 CGF.EmitBranchThroughCleanup(Dest);
1952 }
1953
1954 /// Emit the body of an OMP region
1955 /// \param CGF The Codegen function this belongs to
1956 /// \param RegionBodyStmt The body statement for the OpenMP region being
1957 /// generated
1958 /// \param AllocaIP Where to insert alloca instructions
1959 /// \param CodeGenIP Where to insert the region code
1960 /// \param RegionName Name to be used for new blocks
1961 static void EmitOMPInlinedRegionBody(CodeGenFunction &CGF,
1962 const Stmt *RegionBodyStmt,
1963 InsertPointTy AllocaIP,
1964 InsertPointTy CodeGenIP,
1965 Twine RegionName);
1966
1967 static void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP,
1968 llvm::BasicBlock &FiniBB, llvm::Function *Fn,
1970 llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
1971 if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminator())
1972 CodeGenIPBBTI->eraseFromParent();
1973
1974 CGF.Builder.SetInsertPoint(CodeGenIPBB);
1975
1976 if (Fn->doesNotThrow())
1977 CGF.EmitNounwindRuntimeCall(Fn, Args);
1978 else
1979 CGF.EmitRuntimeCall(Fn, Args);
1980
1981 if (CGF.Builder.saveIP().isSet())
1982 CGF.Builder.CreateBr(&FiniBB);
1983 }
1984
1985 /// Emit the body of an OMP region that will be outlined in
1986 /// OpenMPIRBuilder::finalize().
1987 /// \param CGF The Codegen function this belongs to
1988 /// \param RegionBodyStmt The body statement for the OpenMP region being
1989 /// generated
1990 /// \param AllocaIP Where to insert alloca instructions
1991 /// \param CodeGenIP Where to insert the region code
1992 /// \param RegionName Name to be used for new blocks
1993 static void EmitOMPOutlinedRegionBody(CodeGenFunction &CGF,
1994 const Stmt *RegionBodyStmt,
1995 InsertPointTy AllocaIP,
1996 InsertPointTy CodeGenIP,
1997 Twine RegionName);
1998
1999 /// RAII for preserving necessary info during Outlined region body codegen.
2001
2002 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
2003 CodeGenFunction::JumpDest OldReturnBlock;
2004 CodeGenFunction &CGF;
2005
2006 public:
2007 OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP,
2008 llvm::BasicBlock &RetBB)
2009 : CGF(cgf) {
2010 assert(AllocaIP.isSet() &&
2011 "Must specify Insertion point for allocas of outlined function");
2012 OldAllocaIP = CGF.AllocaInsertPt;
2013 CGF.AllocaInsertPt = &*AllocaIP.getPoint();
2014
2015 OldReturnBlock = CGF.ReturnBlock;
2016 CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
2017 }
2018
2020 CGF.AllocaInsertPt = OldAllocaIP;
2021 CGF.ReturnBlock = OldReturnBlock;
2022 }
2023 };
2024
2025 /// RAII for preserving necessary info during inlined region body codegen.
2027
2028 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
2029 CodeGenFunction &CGF;
2030
2031 public:
2032 InlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP,
2033 llvm::BasicBlock &FiniBB)
2034 : CGF(cgf) {
2035 // Alloca insertion block should be in the entry block of the containing
2036 // function so it expects an empty AllocaIP in which case will reuse the
2037 // old alloca insertion point, or a new AllocaIP in the same block as
2038 // the old one
2039 assert((!AllocaIP.isSet() ||
2040 CGF.AllocaInsertPt->getParent() == AllocaIP.getBlock()) &&
2041 "Insertion point should be in the entry block of containing "
2042 "function!");
2043 OldAllocaIP = CGF.AllocaInsertPt;
2044 if (AllocaIP.isSet())
2045 CGF.AllocaInsertPt = &*AllocaIP.getPoint();
2046
2047 // TODO: Remove the call, after making sure the counter is not used by
2048 // the EHStack.
2049 // Since this is an inlined region, it should not modify the
2050 // ReturnBlock, and should reuse the one for the enclosing outlined
2051 // region. So, the JumpDest being return by the function is discarded
2052 (void)CGF.getJumpDestInCurrentScope(&FiniBB);
2053 }
2054
2055 ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; }
2056 };
2057 };
2058
2059private:
2060 /// CXXThisDecl - When generating code for a C++ member function,
2061 /// this will hold the implicit 'this' declaration.
2062 ImplicitParamDecl *CXXABIThisDecl = nullptr;
2063 llvm::Value *CXXABIThisValue = nullptr;
2064 llvm::Value *CXXThisValue = nullptr;
2065 CharUnits CXXABIThisAlignment;
2066 CharUnits CXXThisAlignment;
2067
2068 /// The value of 'this' to use when evaluating CXXDefaultInitExprs within
2069 /// this expression.
2070 Address CXXDefaultInitExprThis = Address::invalid();
2071
2072 /// The current array initialization index when evaluating an
2073 /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
2074 llvm::Value *ArrayInitIndex = nullptr;
2075
2076 /// The values of function arguments to use when evaluating
2077 /// CXXInheritedCtorInitExprs within this context.
2078 CallArgList CXXInheritedCtorInitExprArgs;
2079
2080 /// CXXStructorImplicitParamDecl - When generating code for a constructor or
2081 /// destructor, this will hold the implicit argument (e.g. VTT).
2082 ImplicitParamDecl *CXXStructorImplicitParamDecl = nullptr;
2083 llvm::Value *CXXStructorImplicitParamValue = nullptr;
2084
2085 /// OutermostConditional - Points to the outermost active
2086 /// conditional control. This is used so that we know if a
2087 /// temporary should be destroyed conditionally.
2088 ConditionalEvaluation *OutermostConditional = nullptr;
2089
2090 /// The current lexical scope.
2091 LexicalScope *CurLexicalScope = nullptr;
2092
2093 /// The current source location that should be used for exception
2094 /// handling code.
2095 SourceLocation CurEHLocation;
2096
2097 /// BlockByrefInfos - For each __block variable, contains
2098 /// information about the layout of the variable.
2099 llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos;
2100
2101 /// Used by -fsanitize=nullability-return to determine whether the return
2102 /// value can be checked.
2103 llvm::Value *RetValNullabilityPrecondition = nullptr;
2104
2105 /// Check if -fsanitize=nullability-return instrumentation is required for
2106 /// this function.
2107 bool requiresReturnValueNullabilityCheck() const {
2108 return RetValNullabilityPrecondition;
2109 }
2110
2111 /// Used to store precise source locations for return statements by the
2112 /// runtime return value checks.
2113 Address ReturnLocation = Address::invalid();
2114
2115 /// Check if the return value of this function requires sanitization.
2116 bool requiresReturnValueCheck() const;
2117
2118 bool isInAllocaArgument(CGCXXABI &ABI, QualType Ty);
2119 bool hasInAllocaArg(const CXXMethodDecl *MD);
2120
2121 llvm::BasicBlock *TerminateLandingPad = nullptr;
2122 llvm::BasicBlock *TerminateHandler = nullptr;
2124
2125 /// Terminate funclets keyed by parent funclet pad.
2126 llvm::MapVector<llvm::Value *, llvm::BasicBlock *> TerminateFunclets;
2127
2128 /// Largest vector width used in ths function. Will be used to create a
2129 /// function attribute.
2130 unsigned LargestVectorWidth = 0;
2131
2132 /// True if we need emit the life-time markers. This is initially set in
2133 /// the constructor, but could be overwritten to true if this is a coroutine.
2134 bool ShouldEmitLifetimeMarkers;
2135
2136 /// Add OpenCL kernel arg metadata and the kernel attribute metadata to
2137 /// the function metadata.
2138 void EmitKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn);
2139
2140public:
2141 CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext = false);
2143
2144 CodeGenTypes &getTypes() const { return CGM.getTypes(); }
2145 ASTContext &getContext() const { return CGM.getContext(); }
2147 if (DisableDebugInfo)
2148 return nullptr;
2149 return DebugInfo;
2150 }
2151 void disableDebugInfo() { DisableDebugInfo = true; }
2152 void enableDebugInfo() { DisableDebugInfo = false; }
2153
2155 return CGM.getCodeGenOpts().OptimizationLevel == 0;
2156 }
2157
2158 const LangOptions &getLangOpts() const { return CGM.getLangOpts(); }
2159
2160 /// Returns a pointer to the function's exception object and selector slot,
2161 /// which is assigned in every landing pad.
2164
2165 /// Returns the contents of the function's exception object and selector
2166 /// slots.
2167 llvm::Value *getExceptionFromSlot();
2168 llvm::Value *getSelectorFromSlot();
2169
2171
2172 llvm::BasicBlock *getUnreachableBlock() {
2173 if (!UnreachableBlock) {
2174 UnreachableBlock = createBasicBlock("unreachable");
2175 new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
2176 }
2177 return UnreachableBlock;
2178 }
2179
2180 llvm::BasicBlock *getInvokeDest() {
2181 if (!EHStack.requiresLandingPad())
2182 return nullptr;
2183 return getInvokeDestImpl();
2184 }
2185
2186 bool currentFunctionUsesSEHTry() const { return !!CurSEHParent; }
2187
2188 const TargetInfo &getTarget() const { return Target; }
2189 llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); }
2191 return CGM.getTargetCodeGenInfo();
2192 }
2193
2194 //===--------------------------------------------------------------------===//
2195 // Cleanups
2196 //===--------------------------------------------------------------------===//
2197
2198 typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty);
2199
2200 void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin,
2201 Address arrayEndPointer,
2202 QualType elementType,
2203 CharUnits elementAlignment,
2204 Destroyer *destroyer);
2205 void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
2206 llvm::Value *arrayEnd,
2207 QualType elementType,
2208 CharUnits elementAlignment,
2209 Destroyer *destroyer);
2210
2211 void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
2212 QualType type);
2214 QualType type);
2215 void pushDestroy(CleanupKind kind, Address addr, QualType type,
2216 Destroyer *destroyer, bool useEHCleanupForArray);
2218 Address addr, QualType type);
2220 QualType type, Destroyer *destroyer,
2221 bool useEHCleanupForArray);
2223 QualType type, Destroyer *destroyer,
2224 bool useEHCleanupForArray);
2226 Address addr, QualType type);
2227 void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete,
2228 llvm::Value *CompletePtr,
2229 QualType ElementType);
2230 void pushStackRestore(CleanupKind kind, Address SPMem);
2232 std::pair<llvm::Value *, llvm::Value *> AddrSizePair);
2233 void emitDestroy(Address addr, QualType type, Destroyer *destroyer,
2234 bool useEHCleanupForArray);
2235 llvm::Function *generateDestroyHelper(Address addr, QualType type,
2236 Destroyer *destroyer,
2237 bool useEHCleanupForArray,
2238 const VarDecl *VD);
2239 void emitArrayDestroy(llvm::Value *begin, llvm::Value *end,
2240 QualType elementType, CharUnits elementAlign,
2241 Destroyer *destroyer, bool checkZeroLength,
2242 bool useEHCleanup);
2243
2245
2246 /// Determines whether an EH cleanup is required to destroy a type
2247 /// with the given destruction kind.
2249 switch (kind) {
2250 case QualType::DK_none:
2251 return false;
2255 return getLangOpts().Exceptions;
2257 return getLangOpts().Exceptions &&
2258 CGM.getCodeGenOpts().ObjCAutoRefCountExceptions;
2259 }
2260 llvm_unreachable("bad destruction kind");
2261 }
2262
2266
2267 //===--------------------------------------------------------------------===//
2268 // Objective-C
2269 //===--------------------------------------------------------------------===//
2270
2271 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
2272
2273 void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD);
2274
2275 /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
2277 const ObjCPropertyImplDecl *PID);
2278 void generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
2279 const ObjCPropertyImplDecl *propImpl,
2280 const ObjCMethodDecl *GetterMothodDecl,
2281 llvm::Constant *AtomicHelperFn);
2282
2284 ObjCMethodDecl *MD, bool ctor);
2285
2286 /// GenerateObjCSetter - Synthesize an Objective-C property setter function
2287 /// for the given property.
2289 const ObjCPropertyImplDecl *PID);
2290 void generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
2291 const ObjCPropertyImplDecl *propImpl,
2292 llvm::Constant *AtomicHelperFn);
2293
2294 //===--------------------------------------------------------------------===//
2295 // Block Bits
2296 //===--------------------------------------------------------------------===//
2297
2298 /// Emit block literal.
2299 /// \return an LLVM value which is a pointer to a struct which contains
2300 /// information about the block, including the block invoke function, the
2301 /// captured variables, etc.
2302 llvm::Value *EmitBlockLiteral(const BlockExpr *);
2303
2304 llvm::Function *GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info,
2305 const DeclMapTy &ldm,
2306 bool IsLambdaConversionToBlock,
2307 bool BuildGlobalBlock);
2308
2309 /// Check if \p T is a C++ class that has a destructor that can throw.
2310 static bool cxxDestructorCanThrow(QualType T);
2311
2312 llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo);
2313 llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo);
2314 llvm::Constant *
2316 llvm::Constant *
2318 llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
2319
2320 void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags,
2321 bool CanThrow);
2322
2323 class AutoVarEmission;
2324
2325 void emitByrefStructureInit(const AutoVarEmission &emission);
2326
2327 /// Enter a cleanup to destroy a __block variable. Note that this
2328 /// cleanup should be a no-op if the variable hasn't left the stack
2329 /// yet; if a cleanup is required for the variable itself, that needs
2330 /// to be done externally.
2331 ///
2332 /// \param Kind Cleanup kind.
2333 ///
2334 /// \param Addr When \p LoadBlockVarAddr is false, the address of the __block
2335 /// structure that will be passed to _Block_object_dispose. When
2336 /// \p LoadBlockVarAddr is true, the address of the field of the block
2337 /// structure that holds the address of the __block structure.
2338 ///
2339 /// \param Flags The flag that will be passed to _Block_object_dispose.
2340 ///
2341 /// \param LoadBlockVarAddr Indicates whether we need to emit a load from
2342 /// \p Addr to get the address of the __block structure.
2344 bool LoadBlockVarAddr, bool CanThrow);
2345
2346 void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum,
2347 llvm::Value *ptr);
2348
2351
2352 /// BuildBlockByrefAddress - Computes the location of the
2353 /// data in a variable which is declared as __block.
2355 bool followForward = true);
2357 bool followForward, const llvm::Twine &name);
2358
2359 const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var);
2360
2362
2363 void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
2364 const CGFunctionInfo &FnInfo);
2365
2366 /// Annotate the function with an attribute that disables TSan checking at
2367 /// runtime.
2368 void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn);
2369
2370 /// Emit code for the start of a function.
2371 /// \param Loc The location to be associated with the function.
2372 /// \param StartLoc The location of the function body.
2373 void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn,
2374 const CGFunctionInfo &FnInfo, const FunctionArgList &Args,
2376 SourceLocation StartLoc = SourceLocation());
2377
2378 static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor);
2379
2383 void EmitFunctionBody(const Stmt *Body);
2384 void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S);
2385
2386 void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator,
2387 CallArgList &CallArgs,
2388 const CGFunctionInfo *CallOpFnInfo = nullptr,
2389 llvm::Constant *CallOpFn = nullptr);
2393 CallArgList &CallArgs);
2394 void EmitLambdaInAllocaImplFn(const CXXMethodDecl *CallOp,
2395 const CGFunctionInfo **ImplFnInfo,
2396 llvm::Function **ImplFn);
2399 EmitStoreThroughLValue(RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV);
2400 }
2401 void EmitAsanPrologueOrEpilogue(bool Prologue);
2402
2403 /// Emit the unified return block, trying to avoid its emission when
2404 /// possible.
2405 /// \return The debug location of the user written return statement if the
2406 /// return block is avoided.
2407 llvm::DebugLoc EmitReturnBlock();
2408
2409 /// FinishFunction - Complete IR generation of the current function. It is
2410 /// legal to call this function even if there is no current insertion point.
2412
2413 void StartThunk(llvm::Function *Fn, GlobalDecl GD,
2414 const CGFunctionInfo &FnInfo, bool IsUnprototyped);
2415
2416 void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
2417 const ThunkInfo *Thunk, bool IsUnprototyped);
2418
2419 void FinishThunk();
2420
2421 /// Emit a musttail call for a thunk with a potentially adjusted this pointer.
2422 void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr,
2423 llvm::FunctionCallee Callee);
2424
2425 /// Generate a thunk for the given method.
2426 void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
2427 GlobalDecl GD, const ThunkInfo &Thunk,
2428 bool IsUnprototyped);
2429
2430 llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn,
2431 const CGFunctionInfo &FnInfo,
2432 GlobalDecl GD, const ThunkInfo &Thunk);
2433
2435 FunctionArgList &Args);
2436
2437 void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init);
2438
2439 /// Struct with all information about dynamic [sub]class needed to set vptr.
2446
2447 /// Initialize the vtable pointer of the given subobject.
2448 void InitializeVTablePointer(const VPtr &vptr);
2449
2451
2453 VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass);
2454
2455 void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase,
2456 CharUnits OffsetFromNearestVBase,
2457 bool BaseIsNonVirtualPrimaryBase,
2458 const CXXRecordDecl *VTableClass,
2459 VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs);
2460
2461 void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
2462
2463 // VTableTrapMode - whether we guarantee that loading the
2464 // vtable is guaranteed to trap on authentication failure,
2465 // even if the resulting vtable pointer is unused.
2466 enum class VTableAuthMode {
2469 UnsafeUbsanStrip // Should only be used for Vptr UBSan check
2470 };
2471 /// GetVTablePtr - Return the Value of the vtable pointer member pointed
2472 /// to by This.
2473 llvm::Value *
2474 GetVTablePtr(Address This, llvm::Type *VTableTy,
2475 const CXXRecordDecl *VTableClass,
2477
2487
2488 /// Derived is the presumed address of an object of type T after a
2489 /// cast. If T is a polymorphic class type, emit a check that the virtual
2490 /// table for Derived belongs to a class derived from T.
2491 void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull,
2493
2494 /// EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
2495 /// If vptr CFI is enabled, emit a check that VTable is valid.
2496 void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable,
2498
2499 /// EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for
2500 /// RD using llvm.type.test.
2501 void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable,
2503
2504 /// If whole-program virtual table optimization is enabled, emit an assumption
2505 /// that VTable is a member of RD's type identifier. Or, if vptr CFI is
2506 /// enabled, emit a check that VTable is a member of RD's type identifier.
2508 llvm::Value *VTable, SourceLocation Loc);
2509
2510 /// Returns whether we should perform a type checked load when loading a
2511 /// virtual function for virtual calls to members of RD. This is generally
2512 /// true when both vcall CFI and whole-program-vtables are enabled.
2514
2515 /// Emit a type checked load from the given vtable.
2516 llvm::Value *EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD,
2517 llvm::Value *VTable,
2518 llvm::Type *VTableTy,
2519 uint64_t VTableByteOffset);
2520
2521 /// EnterDtorCleanups - Enter the cleanups necessary to complete the
2522 /// given phase of destruction for a destructor. The end result
2523 /// should call destructors on members and base classes in reverse
2524 /// order of their construction.
2526
2527 /// ShouldInstrumentFunction - Return true if the current function should be
2528 /// instrumented with __cyg_profile_func_* calls
2530
2531 /// ShouldSkipSanitizerInstrumentation - Return true if the current function
2532 /// should not be instrumented with sanitizers.
2534
2535 /// ShouldXRayInstrument - Return true if the current function should be
2536 /// instrumented with XRay nop sleds.
2537 bool ShouldXRayInstrumentFunction() const;
2538
2539 /// AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit
2540 /// XRay custom event handling calls.
2541 bool AlwaysEmitXRayCustomEvents() const;
2542
2543 /// AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit
2544 /// XRay typed event handling calls.
2545 bool AlwaysEmitXRayTypedEvents() const;
2546
2547 /// Return a type hash constant for a function instrumented by
2548 /// -fsanitize=function.
2549 llvm::ConstantInt *getUBSanFunctionTypeHash(QualType T) const;
2550
2551 /// EmitFunctionProlog - Emit the target specific LLVM code to load the
2552 /// arguments for the given function. This is also responsible for naming the
2553 /// LLVM function arguments.
2554 void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn,
2555 const FunctionArgList &Args);
2556
2557 /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2558 /// given temporary. Specify the source location atom group (Key Instructions
2559 /// debug info feature) for the `ret` using \p RetKeyInstructionsSourceAtom.
2560 /// If it's 0, the `ret` will get added to a new source atom group.
2561 void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc,
2562 SourceLocation EndLoc,
2563 uint64_t RetKeyInstructionsSourceAtom);
2564
2565 /// Emit a test that checks if the return value \p RV is nonnull.
2566 void EmitReturnValueCheck(llvm::Value *RV);
2567
2568 /// EmitStartEHSpec - Emit the start of the exception spec.
2569 void EmitStartEHSpec(const Decl *D);
2570
2571 /// EmitEndEHSpec - Emit the end of the exception spec.
2572 void EmitEndEHSpec(const Decl *D);
2573
2574 /// getTerminateLandingPad - Return a landing pad that just calls terminate.
2575 llvm::BasicBlock *getTerminateLandingPad();
2576
2577 /// getTerminateLandingPad - Return a cleanup funclet that just calls
2578 /// terminate.
2579 llvm::BasicBlock *getTerminateFunclet();
2580
2581 /// getTerminateHandler - Return a handler (not a landing pad, just
2582 /// a catch handler) that just calls terminate. This is used when
2583 /// a terminate scope encloses a try.
2584 llvm::BasicBlock *getTerminateHandler();
2585
2586 llvm::Type *ConvertTypeForMem(QualType T);
2587 llvm::Type *ConvertType(QualType T);
2588 llvm::Type *convertTypeForLoadStore(QualType ASTTy,
2589 llvm::Type *LLVMTy = nullptr);
2590 llvm::Type *ConvertType(const TypeDecl *T) {
2591 return ConvertType(getContext().getTypeDeclType(T));
2592 }
2593
2594 /// LoadObjCSelf - Load the value of self. This function is only valid while
2595 /// generating code for an Objective-C method.
2596 llvm::Value *LoadObjCSelf();
2597
2598 /// TypeOfSelfObject - Return type of object that this self represents.
2600
2601 /// getEvaluationKind - Return the TypeEvaluationKind of QualType \c T.
2603
2605 return getEvaluationKind(T) == TEK_Scalar;
2606 }
2607
2611
2612 /// createBasicBlock - Create an LLVM basic block.
2613 llvm::BasicBlock *createBasicBlock(const Twine &name = "",
2614 llvm::Function *parent = nullptr,
2615 llvm::BasicBlock *before = nullptr) {
2616 return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before);
2617 }
2618
2619 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
2620 /// label maps to.
2621 JumpDest getJumpDestForLabel(const LabelDecl *S);
2622
2623 /// SimplifyForwardingBlocks - If the given basic block is only a branch to
2624 /// another basic block, simplify it. This assumes that no other code could
2625 /// potentially reference the basic block.
2626 void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
2627
2628 /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
2629 /// adding a fall-through branch from the current insert block if
2630 /// necessary. It is legal to call this function even if there is no current
2631 /// insertion point.
2632 ///
2633 /// IsFinished - If true, indicates that the caller has finished emitting
2634 /// branches to the given block and does not expect to emit code into it. This
2635 /// means the block can be ignored if it is unreachable.
2636 void EmitBlock(llvm::BasicBlock *BB, bool IsFinished = false);
2637
2638 /// EmitBlockAfterUses - Emit the given block somewhere hopefully
2639 /// near its uses, and leave the insertion point in it.
2640 void EmitBlockAfterUses(llvm::BasicBlock *BB);
2641
2642 /// EmitBranch - Emit a branch to the specified basic block from the current
2643 /// insert block, taking care to avoid creation of branches from dummy
2644 /// blocks. It is legal to call this function even if there is no current
2645 /// insertion point.
2646 ///
2647 /// This function clears the current insertion point. The caller should follow
2648 /// calls to this function with calls to Emit*Block prior to generation new
2649 /// code.
2650 void EmitBranch(llvm::BasicBlock *Block);
2651
2652 /// HaveInsertPoint - True if an insertion point is defined. If not, this
2653 /// indicates that the current code being emitted is unreachable.
2654 bool HaveInsertPoint() const { return Builder.GetInsertBlock() != nullptr; }
2655
2656 /// EnsureInsertPoint - Ensure that an insertion point is defined so that
2657 /// emitted IR has a place to go. Note that by definition, if this function
2658 /// creates a block then that block is unreachable; callers may do better to
2659 /// detect when no insertion point is defined and simply skip IR generation.
2661 if (!HaveInsertPoint())
2663 }
2664
2665 /// ErrorUnsupported - Print out an error that codegen doesn't support the
2666 /// specified stmt yet.
2667 void ErrorUnsupported(const Stmt *S, const char *Type);
2668
2669 //===--------------------------------------------------------------------===//
2670 // Helpers
2671 //===--------------------------------------------------------------------===//
2672
2674 llvm::BasicBlock *LHSBlock,
2675 llvm::BasicBlock *RHSBlock,
2676 llvm::BasicBlock *MergeBlock,
2677 QualType MergedType) {
2678 Builder.SetInsertPoint(MergeBlock);
2679 llvm::PHINode *PtrPhi = Builder.CreatePHI(LHS.getType(), 2, "cond");
2680 PtrPhi->addIncoming(LHS.getBasePointer(), LHSBlock);
2681 PtrPhi->addIncoming(RHS.getBasePointer(), RHSBlock);
2682 LHS.replaceBasePointer(PtrPhi);
2683 LHS.setAlignment(std::min(LHS.getAlignment(), RHS.getAlignment()));
2684 return LHS;
2685 }
2686
2687 /// Construct an address with the natural alignment of T. If a pointer to T
2688 /// is expected to be signed, the pointer passed to this function must have
2689 /// been signed, and the returned Address will have the pointer authentication
2690 /// information needed to authenticate the signed pointer.
2692 llvm::Value *Ptr, QualType T, CharUnits Alignment = CharUnits::Zero(),
2693 bool ForPointeeType = false, LValueBaseInfo *BaseInfo = nullptr,
2694 TBAAAccessInfo *TBAAInfo = nullptr,
2695 KnownNonNull_t IsKnownNonNull = NotKnownNonNull) {
2696 if (Alignment.isZero())
2697 Alignment =
2698 CGM.getNaturalTypeAlignment(T, BaseInfo, TBAAInfo, ForPointeeType);
2699 return Address(Ptr, ConvertTypeForMem(T), Alignment,
2700 CGM.getPointerAuthInfoForPointeeType(T), /*Offset=*/nullptr,
2701 IsKnownNonNull);
2702 }
2703
2706 return MakeAddrLValue(Addr, T, LValueBaseInfo(Source),
2707 CGM.getTBAAAccessInfo(T));
2708 }
2709
2711 TBAAAccessInfo TBAAInfo) {
2712 return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
2713 }
2714
2715 LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2717 return MakeAddrLValue(makeNaturalAddressForPointer(V, T, Alignment), T,
2718 LValueBaseInfo(Source), CGM.getTBAAAccessInfo(T));
2719 }
2720
2721 /// Same as MakeAddrLValue above except that the pointer is known to be
2722 /// unsigned.
2723 LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2725 Address Addr(V, ConvertTypeForMem(T), Alignment);
2726 return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
2727 CGM.getTBAAAccessInfo(T));
2728 }
2729
2730 LValue
2736
2737 /// Given a value of type T* that may not be to a complete object, construct
2738 /// an l-value with the natural pointee alignment of T.
2740
2741 LValue
2742 MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T,
2743 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
2744
2745 /// Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known
2746 /// to be unsigned.
2748
2750
2752 LValueBaseInfo *PointeeBaseInfo = nullptr,
2753 TBAAAccessInfo *PointeeTBAAInfo = nullptr);
2755 LValue
2758 LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source),
2759 CGM.getTBAAAccessInfo(RefTy));
2760 return EmitLoadOfReferenceLValue(RefLVal);
2761 }
2762
2763 /// Load a pointer with type \p PtrTy stored at address \p Ptr.
2764 /// Note that \p PtrTy is the type of the loaded pointer, not the addresses
2765 /// it is loaded from.
2766 Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
2767 LValueBaseInfo *BaseInfo = nullptr,
2768 TBAAAccessInfo *TBAAInfo = nullptr);
2770
2771private:
2772 struct AllocaTracker {
2773 void Add(llvm::AllocaInst *I) { Allocas.push_back(I); }
2774 llvm::SmallVector<llvm::AllocaInst *> Take() { return std::move(Allocas); }
2775
2776 private:
2778 };
2779 AllocaTracker *Allocas = nullptr;
2780
2781 /// CGDecl helper.
2782 void emitStoresForConstant(const VarDecl &D, Address Loc, bool isVolatile,
2783 llvm::Constant *constant, bool IsAutoInit);
2784 /// CGDecl helper.
2785 void emitStoresForZeroInit(const VarDecl &D, Address Loc, bool isVolatile);
2786 /// CGDecl helper.
2787 void emitStoresForPatternInit(const VarDecl &D, Address Loc, bool isVolatile);
2788 /// CGDecl helper.
2789 void emitStoresForInitAfterBZero(llvm::Constant *Init, Address Loc,
2790 bool isVolatile, bool IsAutoInit);
2791
2792public:
2793 // Captures all the allocas created during the scope of its RAII object.
2795 AllocaTrackerRAII(CodeGenFunction &CGF)
2796 : CGF(CGF), OldTracker(CGF.Allocas) {
2797 CGF.Allocas = &Tracker;
2798 }
2799 ~AllocaTrackerRAII() { CGF.Allocas = OldTracker; }
2800
2801 llvm::SmallVector<llvm::AllocaInst *> Take() { return Tracker.Take(); }
2802
2803 private:
2804 CodeGenFunction &CGF;
2805 AllocaTracker *OldTracker;
2806 AllocaTracker Tracker;
2807 };
2808
2809private:
2810 /// If \p Alloca is not in the same address space as \p DestLangAS, insert an
2811 /// address space cast and return a new RawAddress based on this value.
2812 RawAddress MaybeCastStackAddressSpace(RawAddress Alloca, LangAS DestLangAS,
2813 llvm::Value *ArraySize = nullptr);
2814
2815public:
2816 /// CreateTempAlloca - This creates an alloca and inserts it into the entry
2817 /// block if \p ArraySize is nullptr, otherwise inserts it at the current
2818 /// insertion point of the builder. The caller is responsible for setting an
2819 /// appropriate alignment on
2820 /// the alloca.
2821 ///
2822 /// \p ArraySize is the number of array elements to be allocated if it
2823 /// is not nullptr.
2824 ///
2825 /// LangAS::Default is the address space of pointers to local variables and
2826 /// temporaries, as exposed in the source language. In certain
2827 /// configurations, this is not the same as the alloca address space, and a
2828 /// cast is needed to lift the pointer from the alloca AS into
2829 /// LangAS::Default. This can happen when the target uses a restricted
2830 /// address space for the stack but the source language requires
2831 /// LangAS::Default to be a generic address space. The latter condition is
2832 /// common for most programming languages; OpenCL is an exception in that
2833 /// LangAS::Default is the private address space, which naturally maps
2834 /// to the stack.
2835 ///
2836 /// Because the address of a temporary is often exposed to the program in
2837 /// various ways, this function will perform the cast. The original alloca
2838 /// instruction is returned through \p Alloca if it is not nullptr.
2839 ///
2840 /// The cast is not performaed in CreateTempAllocaWithoutCast. This is
2841 /// more efficient if the caller knows that the address will not be exposed.
2842 llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp",
2843 llvm::Value *ArraySize = nullptr);
2844
2845 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
2846 /// block. The alloca is casted to the address space of \p UseAddrSpace if
2847 /// necessary.
2848 RawAddress CreateTempAlloca(llvm::Type *Ty, LangAS UseAddrSpace,
2849 CharUnits align, const Twine &Name = "tmp",
2850 llvm::Value *ArraySize = nullptr,
2851 RawAddress *Alloca = nullptr);
2852
2853 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
2854 /// block. The alloca is casted to default address space if necessary.
2855 ///
2856 /// FIXME: This version should be removed, and context should provide the
2857 /// context use address space used instead of default.
2859 const Twine &Name = "tmp",
2860 llvm::Value *ArraySize = nullptr,
2861 RawAddress *Alloca = nullptr) {
2862 return CreateTempAlloca(Ty, LangAS::Default, align, Name, ArraySize,
2863 Alloca);
2864 }
2865
2866 RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align,
2867 const Twine &Name = "tmp",
2868 llvm::Value *ArraySize = nullptr);
2869
2870 /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
2871 /// default ABI alignment of the given LLVM type.
2872 ///
2873 /// IMPORTANT NOTE: This is *not* generally the right alignment for
2874 /// any given AST type that happens to have been lowered to the
2875 /// given IR type. This should only ever be used for function-local,
2876 /// IR-driven manipulations like saving and restoring a value. Do
2877 /// not hand this address off to arbitrary IRGen routines, and especially
2878 /// do not pass it as an argument to a function that might expect a
2879 /// properly ABI-aligned value.
2881 const Twine &Name = "tmp");
2882
2883 /// CreateIRTemp - Create a temporary IR object of the given type, with
2884 /// appropriate alignment. This routine should only be used when an temporary
2885 /// value needs to be stored into an alloca (for example, to avoid explicit
2886 /// PHI construction), but the type is the IR type, not the type appropriate
2887 /// for storing in memory.
2888 ///
2889 /// That is, this is exactly equivalent to CreateMemTemp, but calling
2890 /// ConvertType instead of ConvertTypeForMem.
2891 RawAddress CreateIRTemp(QualType T, const Twine &Name = "tmp");
2892
2893 /// CreateMemTemp - Create a temporary memory object of the given type, with
2894 /// appropriate alignmen and cast it to the default address space. Returns
2895 /// the original alloca instruction by \p Alloca if it is not nullptr.
2896 RawAddress CreateMemTemp(QualType T, const Twine &Name = "tmp",
2897 RawAddress *Alloca = nullptr);
2899 const Twine &Name = "tmp",
2900 RawAddress *Alloca = nullptr);
2901
2902 /// CreateMemTemp - Create a temporary memory object of the given type, with
2903 /// appropriate alignmen without casting it to the default address space.
2904 RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp");
2906 const Twine &Name = "tmp");
2907
2908 /// CreateAggTemp - Create a temporary memory object for the given
2909 /// aggregate type.
2910 AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp",
2911 RawAddress *Alloca = nullptr) {
2912 return AggValueSlot::forAddr(
2913 CreateMemTemp(T, Name, Alloca), T.getQualifiers(),
2916 }
2917
2918 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
2919 /// expression and compare the result against zero, returning an Int1Ty value.
2920 llvm::Value *EvaluateExprAsBool(const Expr *E);
2921
2922 /// Retrieve the implicit cast expression of the rhs in a binary operator
2923 /// expression by passing pointers to Value and QualType
2924 /// This is used for implicit bitfield conversion checks, which
2925 /// must compare with the value before potential truncation.
2927 llvm::Value **Previous,
2928 QualType *SrcType);
2929
2930 /// Emit a check that an [implicit] conversion of a bitfield. It is not UB,
2931 /// so we use the value after conversion.
2932 void EmitBitfieldConversionCheck(llvm::Value *Src, QualType SrcType,
2933 llvm::Value *Dst, QualType DstType,
2934 const CGBitFieldInfo &Info,
2935 SourceLocation Loc);
2936
2937 /// EmitIgnoredExpr - Emit an expression in a context which ignores the
2938 /// result.
2939 void EmitIgnoredExpr(const Expr *E);
2940
2941 /// EmitAnyExpr - Emit code to compute the specified expression which can have
2942 /// any type. The result is returned as an RValue struct. If this is an
2943 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
2944 /// the result should be returned.
2945 ///
2946 /// \param ignoreResult True if the resulting value isn't used.
2947 RValue EmitAnyExpr(const Expr *E,
2949 bool ignoreResult = false);
2950
2951 // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
2952 // or the value of the expression, depending on how va_list is defined.
2953 Address EmitVAListRef(const Expr *E);
2954
2955 /// Emit a "reference" to a __builtin_ms_va_list; this is
2956 /// always the value of the expression, because a __builtin_ms_va_list is a
2957 /// pointer to a char.
2958 Address EmitMSVAListRef(const Expr *E);
2959
2960 /// EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will
2961 /// always be accessible even if no aggregate location is provided.
2962 RValue EmitAnyExprToTemp(const Expr *E);
2963
2964 /// EmitAnyExprToMem - Emits the code necessary to evaluate an
2965 /// arbitrary expression into the given memory location.
2966 void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals,
2967 bool IsInitializer);
2968
2969 void EmitAnyExprToExn(const Expr *E, Address Addr);
2970
2971 /// EmitInitializationToLValue - Emit an initializer to an LValue.
2973 const Expr *E, LValue LV,
2975
2976 /// EmitExprAsInit - Emits the code necessary to initialize a
2977 /// location in memory with the given initializer.
2978 void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue,
2979 bool capturedByInit);
2980
2981 /// hasVolatileMember - returns true if aggregate type has a volatile
2982 /// member.
2984 if (const auto *RD = T->getAsRecordDecl())
2985 return RD->hasVolatileMember();
2986 return false;
2987 }
2988
2989 /// Determine whether a return value slot may overlap some other object.
2991 // FIXME: Assuming no overlap here breaks guaranteed copy elision for base
2992 // class subobjects. These cases may need to be revisited depending on the
2993 // resolution of the relevant core issue.
2995 }
2996
2997 /// Determine whether a field initialization may overlap some other object.
2999
3000 /// Determine whether a base class initialization may overlap some other
3001 /// object.
3003 const CXXRecordDecl *BaseRD,
3004 bool IsVirtual);
3005
3006 /// Emit an aggregate assignment.
3009 bool IsVolatile = hasVolatileMember(EltTy);
3010 EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
3011 }
3012
3014 AggValueSlot::Overlap_t MayOverlap) {
3015 EmitAggregateCopy(Dest, Src, Src.getType(), MayOverlap);
3016 }
3017
3018 /// EmitAggregateCopy - Emit an aggregate copy.
3019 ///
3020 /// \param isVolatile \c true iff either the source or the destination is
3021 /// volatile.
3022 /// \param MayOverlap Whether the tail padding of the destination might be
3023 /// occupied by some other object. More efficient code can often be
3024 /// generated if not.
3025 void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy,
3026 AggValueSlot::Overlap_t MayOverlap,
3027 bool isVolatile = false);
3028
3029 /// GetAddrOfLocalVar - Return the address of a local variable.
3031 auto it = LocalDeclMap.find(VD);
3032 assert(it != LocalDeclMap.end() &&
3033 "Invalid argument to GetAddrOfLocalVar(), no decl!");
3034 return it->second;
3035 }
3036
3037 /// Given an opaque value expression, return its LValue mapping if it exists,
3038 /// otherwise create one.
3040
3041 /// Given an opaque value expression, return its RValue mapping if it exists,
3042 /// otherwise create one.
3044
3045 /// isOpaqueValueEmitted - Return true if the opaque value expression has
3046 /// already been emitted.
3048
3049 /// Get the index of the current ArrayInitLoopExpr, if any.
3050 llvm::Value *getArrayInitIndex() { return ArrayInitIndex; }
3051
3052 /// getAccessedFieldNo - Given an encoded value and a result number, return
3053 /// the input field number being accessed.
3054 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
3055
3056 llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
3057 llvm::BasicBlock *GetIndirectGotoBlock();
3058
3059 /// Check if \p E is a C++ "this" pointer wrapped in value-preserving casts.
3060 static bool IsWrappedCXXThis(const Expr *E);
3061
3062 /// EmitNullInitialization - Generate code to set a value of the given type to
3063 /// null, If the type contains data member pointers, they will be initialized
3064 /// to -1 in accordance with the Itanium C++ ABI.
3065 void EmitNullInitialization(Address DestPtr, QualType Ty);
3066
3067 /// Emits a call to an LLVM variable-argument intrinsic, either
3068 /// \c llvm.va_start or \c llvm.va_end.
3069 /// \param ArgValue A reference to the \c va_list as emitted by either
3070 /// \c EmitVAListRef or \c EmitMSVAListRef.
3071 /// \param IsStart If \c true, emits a call to \c llvm.va_start; otherwise,
3072 /// calls \c llvm.va_end.
3073 llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart);
3074
3075 /// Generate code to get an argument from the passed in pointer
3076 /// and update it accordingly.
3077 /// \param VE The \c VAArgExpr for which to generate code.
3078 /// \param VAListAddr Receives a reference to the \c va_list as emitted by
3079 /// either \c EmitVAListRef or \c EmitMSVAListRef.
3080 /// \returns A pointer to the argument.
3081 // FIXME: We should be able to get rid of this method and use the va_arg
3082 // instruction in LLVM instead once it works well enough.
3083 RValue EmitVAArg(VAArgExpr *VE, Address &VAListAddr,
3085
3086 /// emitArrayLength - Compute the length of an array, even if it's a
3087 /// VLA, and drill down to the base element type.
3088 llvm::Value *emitArrayLength(const ArrayType *arrayType, QualType &baseType,
3089 Address &addr);
3090
3091 /// EmitVLASize - Capture all the sizes for the VLA expressions in
3092 /// the given variably-modified type and store them in the VLASizeMap.
3093 ///
3094 /// This function can be called with a null (unreachable) insert point.
3096
3098 llvm::Value *NumElts;
3100
3101 VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {}
3102 };
3103
3104 /// Return the number of elements for a single dimension
3105 /// for the given array type.
3106 VlaSizePair getVLAElements1D(const VariableArrayType *vla);
3107 VlaSizePair getVLAElements1D(QualType vla);
3108
3109 /// Returns an LLVM value that corresponds to the size,
3110 /// in non-variably-sized elements, of a variable length array type,
3111 /// plus that largest non-variably-sized element type. Assumes that
3112 /// the type has already been emitted with EmitVariablyModifiedType.
3113 VlaSizePair getVLASize(const VariableArrayType *vla);
3114 VlaSizePair getVLASize(QualType vla);
3115
3116 /// LoadCXXThis - Load the value of 'this'. This function is only valid while
3117 /// generating code for an C++ member function.
3118 llvm::Value *LoadCXXThis() {
3119 assert(CXXThisValue && "no 'this' value for this function");
3120 return CXXThisValue;
3121 }
3123
3124 /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
3125 /// virtual bases.
3126 // FIXME: Every place that calls LoadCXXVTT is something
3127 // that needs to be abstracted properly.
3128 llvm::Value *LoadCXXVTT() {
3129 assert(CXXStructorImplicitParamValue && "no VTT value for this function");
3130 return CXXStructorImplicitParamValue;
3131 }
3132
3133 /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
3134 /// complete class to the given direct base.
3136 const CXXRecordDecl *Derived,
3137 const CXXRecordDecl *Base,
3138 bool BaseIsVirtual);
3139
3140 static bool ShouldNullCheckClassCastValue(const CastExpr *Cast);
3141
3142 /// GetAddressOfBaseClass - This function will add the necessary delta to the
3143 /// load of 'this' and returns address of the base class.
3147 bool NullCheckValue, SourceLocation Loc);
3148
3152 bool NullCheckValue);
3153
3154 /// GetVTTParameter - Return the VTT parameter that should be passed to a
3155 /// base constructor/destructor with virtual bases.
3156 /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
3157 /// to ItaniumCXXABI.cpp together with all the references to VTT.
3158 llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase,
3159 bool Delegating);
3160
3162 CXXCtorType CtorType,
3163 const FunctionArgList &Args,
3164 SourceLocation Loc);
3165 // It's important not to confuse this and the previous function. Delegating
3166 // constructors are the C++0x feature. The constructor delegate optimization
3167 // is used to reduce duplication in the base and complete consturctors where
3168 // they are substantially the same.
3170 const FunctionArgList &Args);
3171
3172 /// Emit a call to an inheriting constructor (that is, one that invokes a
3173 /// constructor inherited from a base class) by inlining its definition. This
3174 /// is necessary if the ABI does not support forwarding the arguments to the
3175 /// base class constructor (because they're variadic or similar).
3177 CXXCtorType CtorType,
3178 bool ForVirtualBase,
3179 bool Delegating,
3180 CallArgList &Args);
3181
3182 /// Emit a call to a constructor inherited from a base class, passing the
3183 /// current constructor's arguments along unmodified (without even making
3184 /// a copy).
3186 bool ForVirtualBase, Address This,
3187 bool InheritedFromVBase,
3188 const CXXInheritedCtorInitExpr *E);
3189
3191 bool ForVirtualBase, bool Delegating,
3192 AggValueSlot ThisAVS, const CXXConstructExpr *E);
3193
3195 bool ForVirtualBase, bool Delegating,
3196 Address This, CallArgList &Args,
3198 SourceLocation Loc, bool NewPointerIsChecked,
3199 llvm::CallBase **CallOrInvoke = nullptr);
3200
3201 /// Emit assumption load for all bases. Requires to be called only on
3202 /// most-derived class and not under construction of the object.
3203 void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This);
3204
3205 /// Emit assumption that vptr load == global vtable.
3206 void EmitVTableAssumptionLoad(const VPtr &vptr, Address This);
3207
3209 Address Src, const CXXConstructExpr *E);
3210
3212 const ArrayType *ArrayTy, Address ArrayPtr,
3213 const CXXConstructExpr *E,
3214 bool NewPointerIsChecked,
3215 bool ZeroInitialization = false);
3216
3218 llvm::Value *NumElements, Address ArrayPtr,
3219 const CXXConstructExpr *E,
3220 bool NewPointerIsChecked,
3221 bool ZeroInitialization = false);
3222
3224
3226 bool ForVirtualBase, bool Delegating, Address This,
3227 QualType ThisTy);
3228
3229 void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
3230 llvm::Type *ElementTy, Address NewPtr,
3231 llvm::Value *NumElements,
3232 llvm::Value *AllocSizeWithoutCookie);
3233
3234 void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
3235 Address Ptr);
3236
3237 void EmitSehCppScopeBegin();
3238 void EmitSehCppScopeEnd();
3239 void EmitSehTryScopeBegin();
3240 void EmitSehTryScopeEnd();
3241
3242 bool EmitLifetimeStart(llvm::Value *Addr);
3243 void EmitLifetimeEnd(llvm::Value *Addr);
3244
3245 llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
3246 void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
3247
3248 void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
3249 QualType DeleteTy, llvm::Value *NumElements = nullptr,
3250 CharUnits CookieSize = CharUnits());
3251
3253 const CallExpr *TheCallExpr, bool IsDelete);
3254
3255 llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E);
3256 llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE);
3258
3259 /// Situations in which we might emit a check for the suitability of a
3260 /// pointer or glvalue. Needs to be kept in sync with ubsan_handlers.cpp in
3261 /// compiler-rt.
3263 /// Checking the operand of a load. Must be suitably sized and aligned.
3265 /// Checking the destination of a store. Must be suitably sized and aligned.
3267 /// Checking the bound value in a reference binding. Must be suitably sized
3268 /// and aligned, but is not required to refer to an object (until the
3269 /// reference is used), per core issue 453.
3271 /// Checking the object expression in a non-static data member access. Must
3272 /// be an object within its lifetime.
3274 /// Checking the 'this' pointer for a call to a non-static member function.
3275 /// Must be an object within its lifetime.
3277 /// Checking the 'this' pointer for a constructor call.
3279 /// Checking the operand of a static_cast to a derived pointer type. Must be
3280 /// null or an object within its lifetime.
3282 /// Checking the operand of a static_cast to a derived reference type. Must
3283 /// be an object within its lifetime.
3285 /// Checking the operand of a cast to a base object. Must be suitably sized
3286 /// and aligned.
3288 /// Checking the operand of a cast to a virtual base object. Must be an
3289 /// object within its lifetime.
3291 /// Checking the value assigned to a _Nonnull pointer. Must not be null.
3293 /// Checking the operand of a dynamic_cast or a typeid expression. Must be
3294 /// null or an object within its lifetime.
3296 };
3297
3298 /// Determine whether the pointer type check \p TCK permits null pointers.
3299 static bool isNullPointerAllowed(TypeCheckKind TCK);
3300
3301 /// Determine whether the pointer type check \p TCK requires a vptr check.
3302 static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty);
3303
3304 /// Whether any type-checking sanitizers are enabled. If \c false,
3305 /// calls to EmitTypeCheck can be skipped.
3306 bool sanitizePerformTypeCheck() const;
3307
3309 QualType Type, SanitizerSet SkippedChecks = SanitizerSet(),
3310 llvm::Value *ArraySize = nullptr) {
3312 return;
3313 EmitTypeCheck(TCK, Loc, LV.emitRawPointer(*this), Type, LV.getAlignment(),
3314 SkippedChecks, ArraySize);
3315 }
3316
3318 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3319 SanitizerSet SkippedChecks = SanitizerSet(),
3320 llvm::Value *ArraySize = nullptr) {
3322 return;
3323 EmitTypeCheck(TCK, Loc, Addr.emitRawPointer(*this), Type, Alignment,
3324 SkippedChecks, ArraySize);
3325 }
3326
3327 /// Emit a check that \p V is the address of storage of the
3328 /// appropriate size and alignment for an object of type \p Type
3329 /// (or if ArraySize is provided, for an array of that bound).
3330 void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V,
3331 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3332 SanitizerSet SkippedChecks = SanitizerSet(),
3333 llvm::Value *ArraySize = nullptr);
3334
3335 /// Emit a check that \p Base points into an array object, which
3336 /// we can access at index \p Index. \p Accessed should be \c false if we
3337 /// this expression is used as an lvalue, for instance in "&Arr[Idx]".
3338 void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index,
3339 QualType IndexType, bool Accessed);
3340 void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound,
3341 llvm::Value *Index, QualType IndexType,
3342 QualType IndexedType, bool Accessed);
3343
3344 /// Returns debug info, with additional annotation if
3345 /// CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[Ordinal] is enabled for
3346 /// any of the ordinals.
3347 llvm::DILocation *
3349 SanitizerHandler Handler);
3350
3351 /// Emit additional metadata used by the AllocToken instrumentation.
3352 void EmitAllocToken(llvm::CallBase *CB, QualType AllocType);
3353
3354 llvm::Value *GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD,
3355 const FieldDecl *CountDecl);
3356
3357 /// Build an expression accessing the "counted_by" field.
3358 llvm::Value *EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FD,
3359 const FieldDecl *CountDecl);
3360
3361 // Emit bounds checking for flexible array and pointer members with the
3362 // counted_by attribute.
3363 void EmitCountedByBoundsChecking(const Expr *E, llvm::Value *Idx,
3364 Address Addr, QualType IdxTy,
3365 QualType ArrayTy, bool Accessed,
3366 bool FlexibleArray);
3367
3368 llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
3369 bool isInc, bool isPre);
3371 bool isInc, bool isPre);
3372
3373 /// Converts Location to a DebugLoc, if debug information is enabled.
3374 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
3375
3376 /// Get the record field index as represented in debug info.
3377 unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex);
3378
3379 //===--------------------------------------------------------------------===//
3380 // Declaration Emission
3381 //===--------------------------------------------------------------------===//
3382
3383 /// EmitDecl - Emit a declaration.
3384 ///
3385 /// This function can be called with a null (unreachable) insert point.
3386 void EmitDecl(const Decl &D, bool EvaluateConditionDecl = false);
3387
3388 /// EmitVarDecl - Emit a local variable declaration.
3389 ///
3390 /// This function can be called with a null (unreachable) insert point.
3391 void EmitVarDecl(const VarDecl &D);
3392
3393 void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,
3394 bool capturedByInit);
3395
3396 typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
3397 llvm::Value *Address);
3398
3399 /// Determine whether the given initializer is trivial in the sense
3400 /// that it requires no code to be generated.
3401 bool isTrivialInitializer(const Expr *Init);
3402
3403 /// EmitAutoVarDecl - Emit an auto variable declaration.
3404 ///
3405 /// This function can be called with a null (unreachable) insert point.
3406 void EmitAutoVarDecl(const VarDecl &D);
3407
3408 class AutoVarEmission {
3409 friend class CodeGenFunction;
3410
3411 const VarDecl *Variable;
3412
3413 /// The address of the alloca for languages with explicit address space
3414 /// (e.g. OpenCL) or alloca casted to generic pointer for address space
3415 /// agnostic languages (e.g. C++). Invalid if the variable was emitted
3416 /// as a global constant.
3417 Address Addr;
3418
3419 llvm::Value *NRVOFlag;
3420
3421 /// True if the variable is a __block variable that is captured by an
3422 /// escaping block.
3423 bool IsEscapingByRef;
3424
3425 /// True if the variable is of aggregate type and has a constant
3426 /// initializer.
3427 bool IsConstantAggregate;
3428
3429 /// True if lifetime markers should be used.
3430 bool UseLifetimeMarkers;
3431
3432 /// Address with original alloca instruction. Invalid if the variable was
3433 /// emitted as a global constant.
3434 RawAddress AllocaAddr;
3435
3436 struct Invalid {};
3438 : Variable(nullptr), Addr(Address::invalid()),
3439 AllocaAddr(RawAddress::invalid()) {}
3440
3441 AutoVarEmission(const VarDecl &variable)
3442 : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
3443 IsEscapingByRef(false), IsConstantAggregate(false),
3444 UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
3445
3446 bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
3447
3448 public:
3449 static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
3450
3451 bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
3452
3453 /// Returns the raw, allocated address, which is not necessarily
3454 /// the address of the object itself. It is casted to default
3455 /// address space for address space agnostic languages.
3456 Address getAllocatedAddress() const { return Addr; }
3457
3458 /// Returns the address for the original alloca instruction.
3459 RawAddress getOriginalAllocatedAddress() const { return AllocaAddr; }
3460
3461 /// Returns the address of the object within this declaration.
3462 /// Note that this does not chase the forwarding pointer for
3463 /// __block decls.
3465 if (!IsEscapingByRef)
3466 return Addr;
3467
3468 return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false);
3469 }
3470 };
3471 AutoVarEmission EmitAutoVarAlloca(const VarDecl &var);
3472 void EmitAutoVarInit(const AutoVarEmission &emission);
3473 void EmitAutoVarCleanups(const AutoVarEmission &emission);
3474 void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
3475 QualType::DestructionKind dtorKind);
3476
3477 void MaybeEmitDeferredVarDeclInit(const VarDecl *var);
3478
3479 /// Emits the alloca and debug information for the size expressions for each
3480 /// dimension of an array. It registers the association of its (1-dimensional)
3481 /// QualTypes and size expression's debug node, so that CGDebugInfo can
3482 /// reference this node when creating the DISubrange object to describe the
3483 /// array types.
3485 bool EmitDebugInfo);
3486
3487 void EmitStaticVarDecl(const VarDecl &D,
3488 llvm::GlobalValue::LinkageTypes Linkage);
3489
3490 class ParamValue {
3491 union {
3493 llvm::Value *Value;
3494 };
3495
3496 bool IsIndirect;
3497
3498 ParamValue(llvm::Value *V) : Value(V), IsIndirect(false) {}
3499 ParamValue(Address A) : Addr(A), IsIndirect(true) {}
3500
3501 public:
3502 static ParamValue forDirect(llvm::Value *value) {
3503 return ParamValue(value);
3504 }
3505 static ParamValue forIndirect(Address addr) {
3506 assert(!addr.getAlignment().isZero());
3507 return ParamValue(addr);
3508 }
3509
3510 bool isIndirect() const { return IsIndirect; }
3511 llvm::Value *getAnyValue() const {
3512 if (!isIndirect())
3513 return Value;
3514 assert(!Addr.hasOffset() && "unexpected offset");
3515 return Addr.getBasePointer();
3516 }
3517
3518 llvm::Value *getDirectValue() const {
3519 assert(!isIndirect());
3520 return Value;
3521 }
3522
3524 assert(isIndirect());
3525 return Addr;
3526 }
3527 };
3528
3529 /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
3530 void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo);
3531
3532 /// protectFromPeepholes - Protect a value that we're intending to
3533 /// store to the side, but which will probably be used later, from
3534 /// aggressive peepholing optimizations that might delete it.
3535 ///
3536 /// Pass the result to unprotectFromPeepholes to declare that
3537 /// protection is no longer required.
3538 ///
3539 /// There's no particular reason why this shouldn't apply to
3540 /// l-values, it's just that no existing peepholes work on pointers.
3541 PeepholeProtection protectFromPeepholes(RValue rvalue);
3542 void unprotectFromPeepholes(PeepholeProtection protection);
3543
3544 void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty,
3545 SourceLocation Loc,
3546 SourceLocation AssumptionLoc,
3547 llvm::Value *Alignment,
3548 llvm::Value *OffsetValue,
3549 llvm::Value *TheCheck,
3550 llvm::Instruction *Assumption);
3551
3552 void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty,
3553 SourceLocation Loc, SourceLocation AssumptionLoc,
3554 llvm::Value *Alignment,
3555 llvm::Value *OffsetValue = nullptr);
3556
3557 void emitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E,
3558 SourceLocation AssumptionLoc,
3559 llvm::Value *Alignment,
3560 llvm::Value *OffsetValue = nullptr);
3561
3562 //===--------------------------------------------------------------------===//
3563 // Statement Emission
3564 //===--------------------------------------------------------------------===//
3565
3566 /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
3567 void EmitStopPoint(const Stmt *S);
3568
3569 /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
3570 /// this function even if there is no current insertion point.
3571 ///
3572 /// This function may clear the current insertion point; callers should use
3573 /// EnsureInsertPoint if they wish to subsequently generate code without first
3574 /// calling EmitBlock, EmitBranch, or EmitStmt.
3575 void EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs = {});
3576
3577 /// EmitSimpleStmt - Try to emit a "simple" statement which does not
3578 /// necessarily require an insertion point or debug information; typically
3579 /// because the statement amounts to a jump or a container of other
3580 /// statements.
3581 ///
3582 /// \return True if the statement was handled.
3583 bool EmitSimpleStmt(const Stmt *S, ArrayRef<const Attr *> Attrs);
3584
3585 Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
3586 AggValueSlot AVS = AggValueSlot::ignored());
3587 Address
3588 EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast = false,
3589 AggValueSlot AVS = AggValueSlot::ignored());
3590
3591 /// EmitLabel - Emit the block for the given label. It is legal to call this
3592 /// function even if there is no current insertion point.
3593 void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt.
3594
3595 void EmitLabelStmt(const LabelStmt &S);
3596 void EmitAttributedStmt(const AttributedStmt &S);
3597 void EmitGotoStmt(const GotoStmt &S);
3599 void EmitIfStmt(const IfStmt &S);
3600
3601 void EmitWhileStmt(const WhileStmt &S, ArrayRef<const Attr *> Attrs = {});
3602 void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = {});
3603 void EmitForStmt(const ForStmt &S, ArrayRef<const Attr *> Attrs = {});
3604 void EmitReturnStmt(const ReturnStmt &S);
3605 void EmitDeclStmt(const DeclStmt &S);
3606 void EmitBreakStmt(const BreakStmt &S);
3607 void EmitContinueStmt(const ContinueStmt &S);
3608 void EmitSwitchStmt(const SwitchStmt &S);
3609 void EmitDefaultStmt(const DefaultStmt &S, ArrayRef<const Attr *> Attrs);
3610 void EmitCaseStmt(const CaseStmt &S, ArrayRef<const Attr *> Attrs);
3611 void EmitCaseStmtRange(const CaseStmt &S, ArrayRef<const Attr *> Attrs);
3612 void EmitAsmStmt(const AsmStmt &S);
3613
3614 const BreakContinue *GetDestForLoopControlStmt(const LoopControlStmt &S);
3615
3616 void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
3617 void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
3618 void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
3619 void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
3620 void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S);
3621
3622 void EmitCoroutineBody(const CoroutineBodyStmt &S);
3623 void EmitCoreturnStmt(const CoreturnStmt &S);
3624 RValue EmitCoawaitExpr(const CoawaitExpr &E,
3625 AggValueSlot aggSlot = AggValueSlot::ignored(),
3626 bool ignoreResult = false);
3627 LValue EmitCoawaitLValue(const CoawaitExpr *E);
3628 RValue EmitCoyieldExpr(const CoyieldExpr &E,
3629 AggValueSlot aggSlot = AggValueSlot::ignored(),
3630 bool ignoreResult = false);
3631 LValue EmitCoyieldLValue(const CoyieldExpr *E);
3632 RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID);
3633
3634 void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3635 void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3636
3637 void EmitCXXTryStmt(const CXXTryStmt &S);
3638 void EmitSEHTryStmt(const SEHTryStmt &S);
3639 void EmitSEHLeaveStmt(const SEHLeaveStmt &S);
3640 void EnterSEHTryStmt(const SEHTryStmt &S);
3641 void ExitSEHTryStmt(const SEHTryStmt &S);
3642 void VolatilizeTryBlocks(llvm::BasicBlock *BB,
3643 llvm::SmallPtrSet<llvm::BasicBlock *, 10> &V);
3644
3645 void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc);
3646 void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter,
3647 const Stmt *OutlinedStmt);
3648
3649 llvm::Function *GenerateSEHFilterFunction(CodeGenFunction &ParentCGF,
3650 const SEHExceptStmt &Except);
3651
3652 llvm::Function *GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF,
3653 const SEHFinallyStmt &Finally);
3654
3655 void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF,
3656 llvm::Value *ParentFP, llvm::Value *EntryEBP);
3657 llvm::Value *EmitSEHExceptionCode();
3658 llvm::Value *EmitSEHExceptionInfo();
3659 llvm::Value *EmitSEHAbnormalTermination();
3660
3661 /// Emit simple code for OpenMP directives in Simd-only mode.
3662 void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D);
3663
3664 /// Scan the outlined statement for captures from the parent function. For
3665 /// each capture, mark the capture as escaped and emit a call to
3666 /// llvm.localrecover. Insert the localrecover result into the LocalDeclMap.
3667 void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt,
3668 bool IsFilter);
3669
3670 /// Recovers the address of a local in a parent function. ParentVar is the
3671 /// address of the variable used in the immediate parent function. It can
3672 /// either be an alloca or a call to llvm.localrecover if there are nested
3673 /// outlined functions. ParentFP is the frame pointer of the outermost parent
3674 /// frame.
3675 Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
3676 Address ParentVar, llvm::Value *ParentFP);
3677
3678 void EmitCXXForRangeStmt(const CXXForRangeStmt &S,
3679 ArrayRef<const Attr *> Attrs = {});
3680
3681 /// Controls insertion of cancellation exit blocks in worksharing constructs.
3683 CodeGenFunction &CGF;
3684
3685 public:
3686 OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind,
3687 bool HasCancel)
3688 : CGF(CGF) {
3689 CGF.OMPCancelStack.enter(CGF, Kind, HasCancel);
3690 }
3691 ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); }
3692 };
3693
3694 /// Returns calculated size of the specified type.
3695 llvm::Value *getTypeSize(QualType Ty);
3697 llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K);
3698 llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S);
3700 llvm::Function *
3702 const OMPExecutableDirective &D);
3704 SmallVectorImpl<llvm::Value *> &CapturedVars);
3705 void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy,
3706 SourceLocation Loc);
3707 /// Perform element by element copying of arrays with type \a
3708 /// OriginalType from \a SrcAddr to \a DestAddr using copying procedure
3709 /// generated by \a CopyGen.
3710 ///
3711 /// \param DestAddr Address of the destination array.
3712 /// \param SrcAddr Address of the source array.
3713 /// \param OriginalType Type of destination and source arrays.
3714 /// \param CopyGen Copying procedure that copies value of single array element
3715 /// to another single array element.
3717 Address DestAddr, Address SrcAddr, QualType OriginalType,
3718 const llvm::function_ref<void(Address, Address)> CopyGen);
3719 /// Emit proper copying of data from one variable to another.
3720 ///
3721 /// \param OriginalType Original type of the copied variables.
3722 /// \param DestAddr Destination address.
3723 /// \param SrcAddr Source address.
3724 /// \param DestVD Destination variable used in \a CopyExpr (for arrays, has
3725 /// type of the base array element).
3726 /// \param SrcVD Source variable used in \a CopyExpr (for arrays, has type of
3727 /// the base array element).
3728 /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a
3729 /// DestVD.
3730 void EmitOMPCopy(QualType OriginalType, Address DestAddr, Address SrcAddr,
3731 const VarDecl *DestVD, const VarDecl *SrcVD,
3732 const Expr *Copy);
3733 /// Emit atomic update code for constructs: \a X = \a X \a BO \a E or
3734 /// \a X = \a E \a BO \a E.
3735 ///
3736 /// \param X Value to be updated.
3737 /// \param E Update value.
3738 /// \param BO Binary operation for update operation.
3739 /// \param IsXLHSInRHSPart true if \a X is LHS in RHS part of the update
3740 /// expression, false otherwise.
3741 /// \param AO Atomic ordering of the generated atomic instructions.
3742 /// \param CommonGen Code generator for complex expressions that cannot be
3743 /// expressed through atomicrmw instruction.
3744 /// \returns <true, OldAtomicValue> if simple 'atomicrmw' instruction was
3745 /// generated, <false, RValue::get(nullptr)> otherwise.
3746 std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr(
3748 llvm::AtomicOrdering AO, SourceLocation Loc,
3749 const llvm::function_ref<RValue(RValue)> CommonGen);
3751 OMPPrivateScope &PrivateScope);
3753 OMPPrivateScope &PrivateScope);
3755 const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope,
3756 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3757 CaptureDeviceAddrMap);
3759 const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope,
3760 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3761 CaptureDeviceAddrMap);
3762 /// Emit code for copyin clause in \a D directive. The next code is
3763 /// generated at the start of outlined functions for directives:
3764 /// \code
3765 /// threadprivate_var1 = master_threadprivate_var1;
3766 /// operator=(threadprivate_var2, master_threadprivate_var2);
3767 /// ...
3768 /// __kmpc_barrier(&loc, global_tid);
3769 /// \endcode
3770 ///
3771 /// \param D OpenMP directive possibly with 'copyin' clause(s).
3772 /// \returns true if at least one copyin variable is found, false otherwise.
3774 /// Emit initial code for lastprivate variables. If some variable is
3775 /// not also firstprivate, then the default initialization is used. Otherwise
3776 /// initialization of this variable is performed by EmitOMPFirstprivateClause
3777 /// method.
3778 ///
3779 /// \param D Directive that may have 'lastprivate' directives.
3780 /// \param PrivateScope Private scope for capturing lastprivate variables for
3781 /// proper codegen in internal captured statement.
3782 ///
3783 /// \returns true if there is at least one lastprivate variable, false
3784 /// otherwise.
3786 OMPPrivateScope &PrivateScope);
3787 /// Emit final copying of lastprivate values to original variables at
3788 /// the end of the worksharing or simd directive.
3789 ///
3790 /// \param D Directive that has at least one 'lastprivate' directives.
3791 /// \param IsLastIterCond Boolean condition that must be set to 'i1 true' if
3792 /// it is the last iteration of the loop code in associated directive, or to
3793 /// 'i1 false' otherwise. If this item is nullptr, no final check is required.
3795 bool NoFinals,
3796 llvm::Value *IsLastIterCond = nullptr);
3797 /// Emit initial code for linear clauses.
3799 CodeGenFunction::OMPPrivateScope &PrivateScope);
3800 /// Emit final code for linear clauses.
3801 /// \param CondGen Optional conditional code for final part of codegen for
3802 /// linear clause.
3804 const OMPLoopDirective &D,
3805 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
3806 /// Emit initial code for reduction variables. Creates reduction copies
3807 /// and initializes them with the values according to OpenMP standard.
3808 ///
3809 /// \param D Directive (possibly) with the 'reduction' clause.
3810 /// \param PrivateScope Private scope for capturing reduction variables for
3811 /// proper codegen in internal captured statement.
3812 ///
3814 OMPPrivateScope &PrivateScope,
3815 bool ForInscan = false);
3816 /// Emit final update of reduction values to original variables at
3817 /// the end of the directive.
3818 ///
3819 /// \param D Directive that has at least one 'reduction' directives.
3820 /// \param ReductionKind The kind of reduction to perform.
3822 const OpenMPDirectiveKind ReductionKind);
3823 /// Emit initial code for linear variables. Creates private copies
3824 /// and initializes them with the values according to OpenMP standard.
3825 ///
3826 /// \param D Directive (possibly) with the 'linear' clause.
3827 /// \return true if at least one linear variable is found that should be
3828 /// initialized with the value of the original variable, false otherwise.
3830
3831 typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/,
3832 llvm::Function * /*OutlinedFn*/,
3833 const OMPTaskDataTy & /*Data*/)>
3836 const OpenMPDirectiveKind CapturedRegion,
3837 const RegionCodeGenTy &BodyGen,
3838 const TaskGenTy &TaskGen, OMPTaskDataTy &Data);
3854 const RegionCodeGenTy &BodyGen,
3855 OMPTargetDataInfo &InputInfo);
3857 CodeGenFunction &CGF, const CapturedStmt *CS,
3858 OMPPrivateScope &Scope);
3860 void EmitOMPParallelDirective(const OMPParallelDirective &S);
3861 void EmitOMPSimdDirective(const OMPSimdDirective &S);
3868 void EmitOMPForDirective(const OMPForDirective &S);
3869 void EmitOMPForSimdDirective(const OMPForSimdDirective &S);
3870 void EmitOMPScopeDirective(const OMPScopeDirective &S);
3871 void EmitOMPSectionsDirective(const OMPSectionsDirective &S);
3872 void EmitOMPSectionDirective(const OMPSectionDirective &S);
3873 void EmitOMPSingleDirective(const OMPSingleDirective &S);
3874 void EmitOMPMasterDirective(const OMPMasterDirective &S);
3876 void EmitOMPCriticalDirective(const OMPCriticalDirective &S);
3877 void EmitOMPParallelForDirective(const OMPParallelForDirective &S);
3878 void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S);
3879 void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S);
3880 void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S);
3881 void EmitOMPTaskDirective(const OMPTaskDirective &S);
3882 void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S);
3884 void EmitOMPBarrierDirective(const OMPBarrierDirective &S);
3885 void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S);
3886 void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S);
3887 void EmitOMPFlushDirective(const OMPFlushDirective &S);
3888 void EmitOMPDepobjDirective(const OMPDepobjDirective &S);
3890 void EmitOMPOrderedDirective(const OMPOrderedDirective &S);
3891 void EmitOMPAtomicDirective(const OMPAtomicDirective &S);
3898 void
3901 void
3909 void
3911 void
3931 void
3954 void EmitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &S);
3956
3957 /// Emit device code for the target directive.
3959 StringRef ParentName,
3960 const OMPTargetDirective &S);
3961 static void
3964 /// Emit device code for the target parallel for directive.
3966 CodeGenModule &CGM, StringRef ParentName,
3968 /// Emit device code for the target parallel for simd directive.
3970 CodeGenModule &CGM, StringRef ParentName,
3972 /// Emit device code for the target teams directive.
3973 static void
3974 EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName,
3975 const OMPTargetTeamsDirective &S);
3976 /// Emit device code for the target teams distribute directive.
3978 CodeGenModule &CGM, StringRef ParentName,
3980 /// Emit device code for the target teams distribute simd directive.
3982 CodeGenModule &CGM, StringRef ParentName,
3984 /// Emit device code for the target simd directive.
3986 StringRef ParentName,
3987 const OMPTargetSimdDirective &S);
3988 /// Emit device code for the target teams distribute parallel for simd
3989 /// directive.
3991 CodeGenModule &CGM, StringRef ParentName,
3993
3994 /// Emit device code for the target teams loop directive.
3996 CodeGenModule &CGM, StringRef ParentName,
3998
3999 /// Emit device code for the target parallel loop directive.
4001 CodeGenModule &CGM, StringRef ParentName,
4003
4005 CodeGenModule &CGM, StringRef ParentName,
4007
4008 /// Emit the Stmt \p S and return its topmost canonical loop, if any.
4009 /// TODO: The \p Depth paramter is not yet implemented and must be 1. In the
4010 /// future it is meant to be the number of loops expected in the loop nests
4011 /// (usually specified by the "collapse" clause) that are collapsed to a
4012 /// single loop by this function.
4013 llvm::CanonicalLoopInfo *EmitOMPCollapsedCanonicalLoopNest(const Stmt *S,
4014 int Depth);
4015
4016 /// Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
4017 void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S);
4018
4019 /// Emit inner loop of the worksharing/simd construct.
4020 ///
4021 /// \param S Directive, for which the inner loop must be emitted.
4022 /// \param RequiresCleanup true, if directive has some associated private
4023 /// variables.
4024 /// \param LoopCond Bollean condition for loop continuation.
4025 /// \param IncExpr Increment expression for loop control variable.
4026 /// \param BodyGen Generator for the inner body of the inner loop.
4027 /// \param PostIncGen Genrator for post-increment code (required for ordered
4028 /// loop directvies).
4029 void EmitOMPInnerLoop(
4030 const OMPExecutableDirective &S, bool RequiresCleanup,
4031 const Expr *LoopCond, const Expr *IncExpr,
4032 const llvm::function_ref<void(CodeGenFunction &)> BodyGen,
4033 const llvm::function_ref<void(CodeGenFunction &)> PostIncGen);
4034
4036 /// Emit initial code for loop counters of loop-based directives.
4038 OMPPrivateScope &LoopScope);
4039
4040 /// Helper for the OpenMP loop directives.
4041 void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit);
4042
4043 /// Emit code for the worksharing loop-based directive.
4044 /// \return true, if this construct has any lastprivate clause, false -
4045 /// otherwise.
4046 bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB,
4047 const CodeGenLoopBoundsTy &CodeGenLoopBounds,
4048 const CodeGenDispatchBoundsTy &CGDispatchBounds);
4049
4050 /// Emit code for the distribute loop-based directive.
4052 const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr);
4053
4054 /// Helpers for the OpenMP loop directives.
4055 void EmitOMPSimdInit(const OMPLoopDirective &D);
4056 void EmitOMPSimdFinal(
4057 const OMPLoopDirective &D,
4058 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
4059
4060 /// Emits the lvalue for the expression with possibly captured variable.
4062
4063private:
4064 /// Helpers for blocks.
4065 llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info);
4066
4067 /// struct with the values to be passed to the OpenMP loop-related functions
4068 struct OMPLoopArguments {
4069 /// loop lower bound
4071 /// loop upper bound
4073 /// loop stride
4075 /// isLastIteration argument for runtime functions
4077 /// Chunk value generated by sema
4078 llvm::Value *Chunk = nullptr;
4079 /// EnsureUpperBound
4080 Expr *EUB = nullptr;
4081 /// IncrementExpression
4082 Expr *IncExpr = nullptr;
4083 /// Loop initialization
4084 Expr *Init = nullptr;
4085 /// Loop exit condition
4086 Expr *Cond = nullptr;
4087 /// Update of LB after a whole chunk has been executed
4088 Expr *NextLB = nullptr;
4089 /// Update of UB after a whole chunk has been executed
4090 Expr *NextUB = nullptr;
4091 /// Distinguish between the for distribute and sections
4092 OpenMPDirectiveKind DKind = llvm::omp::OMPD_unknown;
4093 OMPLoopArguments() = default;
4094 OMPLoopArguments(Address LB, Address UB, Address ST, Address IL,
4095 llvm::Value *Chunk = nullptr, Expr *EUB = nullptr,
4096 Expr *IncExpr = nullptr, Expr *Init = nullptr,
4097 Expr *Cond = nullptr, Expr *NextLB = nullptr,
4098 Expr *NextUB = nullptr)
4099 : LB(LB), UB(UB), ST(ST), IL(IL), Chunk(Chunk), EUB(EUB),
4100 IncExpr(IncExpr), Init(Init), Cond(Cond), NextLB(NextLB),
4101 NextUB(NextUB) {}
4102 };
4103 void EmitOMPOuterLoop(bool DynamicOrOrdered, bool IsMonotonic,
4104 const OMPLoopDirective &S, OMPPrivateScope &LoopScope,
4105 const OMPLoopArguments &LoopArgs,
4106 const CodeGenLoopTy &CodeGenLoop,
4107 const CodeGenOrderedTy &CodeGenOrdered);
4108 void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind,
4109 bool IsMonotonic, const OMPLoopDirective &S,
4110 OMPPrivateScope &LoopScope, bool Ordered,
4111 const OMPLoopArguments &LoopArgs,
4112 const CodeGenDispatchBoundsTy &CGDispatchBounds);
4113 void EmitOMPDistributeOuterLoop(OpenMPDistScheduleClauseKind ScheduleKind,
4114 const OMPLoopDirective &S,
4115 OMPPrivateScope &LoopScope,
4116 const OMPLoopArguments &LoopArgs,
4117 const CodeGenLoopTy &CodeGenLoopContent);
4118 /// Emit code for sections directive.
4119 void EmitSections(const OMPExecutableDirective &S);
4120
4121public:
4122 //===--------------------------------------------------------------------===//
4123 // OpenACC Emission
4124 //===--------------------------------------------------------------------===//
4126 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4127 // simply emitting its structured block, but in the future we will implement
4128 // some sort of IR.
4129 EmitStmt(S.getStructuredBlock());
4130 }
4131
4133 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4134 // simply emitting its loop, but in the future we will implement
4135 // some sort of IR.
4136 EmitStmt(S.getLoop());
4137 }
4138
4140 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4141 // simply emitting its loop, but in the future we will implement
4142 // some sort of IR.
4143 EmitStmt(S.getLoop());
4144 }
4145
4147 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4148 // simply emitting its structured block, but in the future we will implement
4149 // some sort of IR.
4151 }
4152
4154 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4155 // but in the future we will implement some sort of IR.
4156 }
4157
4159 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4160 // but in the future we will implement some sort of IR.
4161 }
4162
4164 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4165 // simply emitting its structured block, but in the future we will implement
4166 // some sort of IR.
4168 }
4169
4171 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4172 // but in the future we will implement some sort of IR.
4173 }
4174
4176 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4177 // but in the future we will implement some sort of IR.
4178 }
4179
4181 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4182 // but in the future we will implement some sort of IR.
4183 }
4184
4186 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4187 // but in the future we will implement some sort of IR.
4188 }
4189
4191 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4192 // but in the future we will implement some sort of IR.
4193 }
4194
4196 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4197 // simply emitting its associated stmt, but in the future we will implement
4198 // some sort of IR.
4200 }
4202 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
4203 // but in the future we will implement some sort of IR.
4204 }
4205
4206 //===--------------------------------------------------------------------===//
4207 // LValue Expression Emission
4208 //===--------------------------------------------------------------------===//
4209
4210 /// Create a check that a scalar RValue is non-null.
4211 llvm::Value *EmitNonNullRValueCheck(RValue RV, QualType T);
4212
4213 /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
4215
4216 /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
4217 /// and issue an ErrorUnsupported style diagnostic (using the
4218 /// provided Name).
4219 RValue EmitUnsupportedRValue(const Expr *E, const char *Name);
4220
4221 /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
4222 /// an ErrorUnsupported style diagnostic (using the provided Name).
4223 LValue EmitUnsupportedLValue(const Expr *E, const char *Name);
4224
4225 /// EmitLValue - Emit code to compute a designator that specifies the location
4226 /// of the expression.
4227 ///
4228 /// This can return one of two things: a simple address or a bitfield
4229 /// reference. In either case, the LLVM Value* in the LValue structure is
4230 /// guaranteed to be an LLVM pointer type.
4231 ///
4232 /// If this returns a bitfield reference, nothing about the pointee type of
4233 /// the LLVM value is known: For example, it may not be a pointer to an
4234 /// integer.
4235 ///
4236 /// If this returns a normal address, and if the lvalue's C type is fixed
4237 /// size, this method guarantees that the returned pointer type will point to
4238 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
4239 /// variable length type, this is not possible.
4240 ///
4241 LValue EmitLValue(const Expr *E,
4242 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
4243
4244private:
4245 LValue EmitLValueHelper(const Expr *E, KnownNonNull_t IsKnownNonNull);
4246
4247public:
4248 /// Same as EmitLValue but additionally we generate checking code to
4249 /// guard against undefined behavior. This is only suitable when we know
4250 /// that the address will be used to access the object.
4252
4254
4255 void EmitAtomicInit(Expr *E, LValue lvalue);
4256
4258
4261
4263 llvm::AtomicOrdering AO, bool IsVolatile = false,
4265
4266 void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit);
4267
4268 void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO,
4269 bool IsVolatile, bool isInit);
4270
4271 std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange(
4272 LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc,
4273 llvm::AtomicOrdering Success =
4274 llvm::AtomicOrdering::SequentiallyConsistent,
4275 llvm::AtomicOrdering Failure =
4276 llvm::AtomicOrdering::SequentiallyConsistent,
4277 bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored());
4278
4279 /// Emit an atomicrmw instruction, and applying relevant metadata when
4280 /// applicable.
4281 llvm::AtomicRMWInst *emitAtomicRMWInst(
4282 llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val,
4283 llvm::AtomicOrdering Order = llvm::AtomicOrdering::SequentiallyConsistent,
4284 llvm::SyncScope::ID SSID = llvm::SyncScope::System,
4285 const AtomicExpr *AE = nullptr);
4286
4287 void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO,
4288 const llvm::function_ref<RValue(RValue)> &UpdateOp,
4289 bool IsVolatile);
4290
4291 /// EmitToMemory - Change a scalar value from its value
4292 /// representation to its in-memory representation.
4293 llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty);
4294
4295 /// EmitFromMemory - Change a scalar value from its memory
4296 /// representation to its value representation.
4297 llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty);
4298
4299 /// Check if the scalar \p Value is within the valid range for the given
4300 /// type \p Ty.
4301 ///
4302 /// Returns true if a check is needed (even if the range is unknown).
4303 bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
4304 SourceLocation Loc);
4305
4306 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4307 /// care to appropriately convert from the memory representation to
4308 /// the LLVM value representation.
4309 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4310 SourceLocation Loc,
4312 bool isNontemporal = false) {
4313 return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source),
4314 CGM.getTBAAAccessInfo(Ty), isNontemporal);
4315 }
4316
4317 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4318 SourceLocation Loc, LValueBaseInfo BaseInfo,
4319 TBAAAccessInfo TBAAInfo,
4320 bool isNontemporal = false);
4321
4322 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4323 /// care to appropriately convert from the memory representation to
4324 /// the LLVM value representation. The l-value must be a simple
4325 /// l-value.
4326 llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc);
4327
4328 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4329 /// care to appropriately convert from the memory representation to
4330 /// the LLVM value representation.
4331 void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile,
4332 QualType Ty,
4334 bool isInit = false, bool isNontemporal = false) {
4335 EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source),
4336 CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
4337 }
4338
4339 void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile,
4340 QualType Ty, LValueBaseInfo BaseInfo,
4341 TBAAAccessInfo TBAAInfo, bool isInit = false,
4342 bool isNontemporal = false);
4343
4344 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4345 /// care to appropriately convert from the memory representation to
4346 /// the LLVM value representation. The l-value must be a simple
4347 /// l-value. The isInit flag indicates whether this is an initialization.
4348 /// If so, atomic qualifiers are ignored and the store is always non-atomic.
4349 void EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
4350 bool isInit = false);
4351
4352 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
4353 /// this method emits the address of the lvalue, then loads the result as an
4354 /// rvalue, returning the rvalue.
4359
4360 /// Like EmitLoadOfLValue but also handles complex and aggregate types.
4363 SourceLocation Loc = {});
4364
4365 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
4366 /// lvalue, where both are guaranteed to the have the same type, and that type
4367 /// is 'Ty'.
4368 void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false);
4369 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);
4370 void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst);
4371
4372 /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints
4373 /// as EmitStoreThroughLValue.
4374 ///
4375 /// \param Result [out] - If non-null, this will be set to a Value* for the
4376 /// bit-field contents after the store, appropriate for use as the result of
4377 /// an assignment to the bit-field.
4378 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
4379 llvm::Value **Result = nullptr);
4380
4381 /// Emit an l-value for an assignment (simple or compound) of complex type.
4385 llvm::Value *&Result);
4386
4387 // Note: only available for agg return types
4390 // Note: only available for agg return types
4391 LValue EmitCallExprLValue(const CallExpr *E,
4392 llvm::CallBase **CallOrInvoke = nullptr);
4393 // Note: only available for agg return types
4394 LValue EmitVAArgExprLValue(const VAArgExpr *E);
4395 LValue EmitDeclRefLValue(const DeclRefExpr *E);
4396 LValue EmitStringLiteralLValue(const StringLiteral *E);
4398 LValue EmitPredefinedLValue(const PredefinedExpr *E);
4399 LValue EmitUnaryOpLValue(const UnaryOperator *E);
4401 bool Accessed = false);
4402 llvm::Value *EmitMatrixIndexExpr(const Expr *E);
4404 LValue EmitArraySectionExpr(const ArraySectionExpr *E,
4405 bool IsLowerBound = true);
4407 LValue EmitMemberExpr(const MemberExpr *E);
4408 LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
4410 LValue EmitInitListLValue(const InitListExpr *E);
4413 LValue EmitCastLValue(const CastExpr *E);
4415 LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e);
4417
4418 std::pair<LValue, LValue> EmitHLSLOutArgLValues(const HLSLOutArgExpr *E,
4419 QualType Ty);
4420 LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args,
4421 QualType Ty);
4422
4423 Address EmitExtVectorElementLValue(LValue V);
4424
4425 RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);
4426
4427 Address EmitArrayToPointerDecay(const Expr *Array,
4428 LValueBaseInfo *BaseInfo = nullptr,
4429 TBAAAccessInfo *TBAAInfo = nullptr);
4430
4431 class ConstantEmission {
4432 llvm::PointerIntPair<llvm::Constant *, 1, bool> ValueAndIsReference;
4433 ConstantEmission(llvm::Constant *C, bool isReference)
4434 : ValueAndIsReference(C, isReference) {}
4435
4436 public:
4438 static ConstantEmission forReference(llvm::Constant *C) {
4439 return ConstantEmission(C, true);
4440 }
4441 static ConstantEmission forValue(llvm::Constant *C) {
4442 return ConstantEmission(C, false);
4443 }
4444
4445 explicit operator bool() const {
4446 return ValueAndIsReference.getOpaqueValue() != nullptr;
4447 }
4448
4449 bool isReference() const { return ValueAndIsReference.getInt(); }
4450 LValue getReferenceLValue(CodeGenFunction &CGF, const Expr *RefExpr) const {
4451 assert(isReference());
4452 return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
4453 RefExpr->getType());
4454 }
4455
4456 llvm::Constant *getValue() const {
4457 assert(!isReference());
4458 return ValueAndIsReference.getPointer();
4459 }
4460 };
4461
4462 ConstantEmission tryEmitAsConstant(const DeclRefExpr *RefExpr);
4463 ConstantEmission tryEmitAsConstant(const MemberExpr *ME);
4464 llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E);
4465
4469
4471 SmallVectorImpl<LValue> &AccessList);
4472
4473 llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
4474 const ObjCIvarDecl *Ivar);
4476 const ObjCIvarDecl *Ivar);
4478 bool IsInBounds = true);
4481 llvm::Value *ThisValue);
4482
4483 /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
4484 /// if the Field is a reference, this will return the address of the reference
4485 /// and not the address of the value stored in the reference.
4487
4488 LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base,
4489 const ObjCIvarDecl *Ivar, unsigned CVRQualifiers);
4490
4495
4501 void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init);
4502
4503 //===--------------------------------------------------------------------===//
4504 // Scalar Expression Emission
4505 //===--------------------------------------------------------------------===//
4506
4507 /// EmitCall - Generate a call of the given function, expecting the given
4508 /// result type, and using the given argument list which specifies both the
4509 /// LLVM arguments and the types they were derived from.
4510 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4512 llvm::CallBase **CallOrInvoke, bool IsMustTail,
4513 SourceLocation Loc,
4514 bool IsVirtualFunctionPointerThunk = false);
4515 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4517 llvm::CallBase **CallOrInvoke = nullptr,
4518 bool IsMustTail = false) {
4519 return EmitCall(CallInfo, Callee, ReturnValue, Args, CallOrInvoke,
4520 IsMustTail, SourceLocation());
4521 }
4522 RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E,
4523 ReturnValueSlot ReturnValue, llvm::Value *Chain = nullptr,
4524 llvm::CallBase **CallOrInvoke = nullptr,
4525 CGFunctionInfo const **ResolvedFnInfo = nullptr);
4526
4527 // If a Call or Invoke instruction was emitted for this CallExpr, this method
4528 // writes the pointer to `CallOrInvoke` if it's not null.
4529 RValue EmitCallExpr(const CallExpr *E,
4531 llvm::CallBase **CallOrInvoke = nullptr);
4533 llvm::CallBase **CallOrInvoke = nullptr);
4534 CGCallee EmitCallee(const Expr *E);
4535
4536 void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl);
4537 void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl);
4538
4539 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4540 const Twine &name = "");
4541 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4543 const Twine &name = "");
4544 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4545 const Twine &name = "");
4546 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4547 ArrayRef<Address> args,
4548 const Twine &name = "");
4549 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4551 const Twine &name = "");
4552
4554 getBundlesForFunclet(llvm::Value *Callee);
4555
4556 llvm::CallBase *EmitCallOrInvoke(llvm::FunctionCallee Callee,
4558 const Twine &Name = "");
4559 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4561 const Twine &name = "");
4562 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4563 const Twine &name = "");
4564 void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4566
4568 NestedNameSpecifier Qual, llvm::Type *Ty);
4569
4572 const CXXRecordDecl *RD);
4573
4574 bool isPointerKnownNonNull(const Expr *E);
4575 /// Check whether the underlying base pointer is a constant null.
4577
4578 /// Create the discriminator from the storage address and the entity hash.
4579 llvm::Value *EmitPointerAuthBlendDiscriminator(llvm::Value *StorageAddress,
4580 llvm::Value *Discriminator);
4582 llvm::Value *StorageAddress,
4583 GlobalDecl SchemaDecl,
4584 QualType SchemaType);
4585
4586 llvm::Value *EmitPointerAuthSign(const CGPointerAuthInfo &Info,
4587 llvm::Value *Pointer);
4588
4589 llvm::Value *EmitPointerAuthAuth(const CGPointerAuthInfo &Info,
4590 llvm::Value *Pointer);
4591
4592 llvm::Value *emitPointerAuthResign(llvm::Value *Pointer, QualType PointerType,
4593 const CGPointerAuthInfo &CurAuthInfo,
4594 const CGPointerAuthInfo &NewAuthInfo,
4595 bool IsKnownNonNull);
4596 llvm::Value *emitPointerAuthResignCall(llvm::Value *Pointer,
4597 const CGPointerAuthInfo &CurInfo,
4598 const CGPointerAuthInfo &NewInfo);
4599
4601 const CGPointerAuthInfo &Info,
4603
4605 Address StorageAddress);
4606 llvm::Value *EmitPointerAuthQualify(PointerAuthQualifier Qualifier,
4607 llvm::Value *Pointer, QualType ValueType,
4608 Address StorageAddress,
4609 bool IsKnownNonNull);
4610 llvm::Value *EmitPointerAuthQualify(PointerAuthQualifier Qualifier,
4611 const Expr *PointerExpr,
4612 Address StorageAddress);
4613 llvm::Value *EmitPointerAuthUnqualify(PointerAuthQualifier Qualifier,
4614 llvm::Value *Pointer,
4616 Address StorageAddress,
4617 bool IsKnownNonNull);
4619 Address DestField, Address SrcField);
4620
4621 std::pair<llvm::Value *, CGPointerAuthInfo>
4622 EmitOrigPointerRValue(const Expr *E);
4623
4624 llvm::Value *authPointerToPointerCast(llvm::Value *ResultPtr,
4625 QualType SourceType, QualType DestType);
4627 QualType DestType);
4628
4630
4631 llvm::Value *getAsNaturalPointerTo(Address Addr, QualType PointeeType) {
4632 return getAsNaturalAddressOf(Addr, PointeeType).getBasePointer();
4633 }
4634
4635 // Return the copy constructor name with the prefix "__copy_constructor_"
4636 // removed.
4637 static std::string getNonTrivialCopyConstructorStr(QualType QT,
4638 CharUnits Alignment,
4639 bool IsVolatile,
4640 ASTContext &Ctx);
4641
4642 // Return the destructor name with the prefix "__destructor_" removed.
4643 static std::string getNonTrivialDestructorStr(QualType QT,
4644 CharUnits Alignment,
4645 bool IsVolatile,
4646 ASTContext &Ctx);
4647
4648 // These functions emit calls to the special functions of non-trivial C
4649 // structs.
4652 void callCStructDestructor(LValue Dst);
4657
4659 const CXXMethodDecl *Method, const CGCallee &Callee,
4660 ReturnValueSlot ReturnValue, llvm::Value *This,
4661 llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E,
4662 CallArgList *RtlArgs, llvm::CallBase **CallOrInvoke);
4663 RValue EmitCXXDestructorCall(GlobalDecl Dtor, const CGCallee &Callee,
4664 llvm::Value *This, QualType ThisTy,
4665 llvm::Value *ImplicitParam,
4666 QualType ImplicitParamTy, const CallExpr *E,
4667 llvm::CallBase **CallOrInvoke = nullptr);
4670 llvm::CallBase **CallOrInvoke = nullptr);
4672 const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue,
4673 bool HasQualifier, NestedNameSpecifier Qualifier, bool IsArrow,
4674 const Expr *Base, llvm::CallBase **CallOrInvoke);
4675 // Compute the object pointer.
4677 const Expr *E, Address base, llvm::Value *memberPtr,
4678 const MemberPointerType *memberPtrType, bool IsInBounds,
4679 LValueBaseInfo *BaseInfo = nullptr, TBAAAccessInfo *TBAAInfo = nullptr);
4682 llvm::CallBase **CallOrInvoke);
4683
4685 const CXXMethodDecl *MD,
4687 llvm::CallBase **CallOrInvoke);
4689
4692 llvm::CallBase **CallOrInvoke);
4693
4696
4697 RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4699
4700 RValue emitRotate(const CallExpr *E, bool IsRotateRight);
4701
4702 /// Emit IR for __builtin_os_log_format.
4704
4705 /// Emit IR for __builtin_is_aligned.
4707 /// Emit IR for __builtin_align_up/__builtin_align_down.
4708 RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp);
4709
4710 llvm::Function *generateBuiltinOSLogHelperFunction(
4712 CharUnits BufferAlignment);
4713
4715 llvm::CallBase **CallOrInvoke);
4716
4717 /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
4718 /// is unhandled by the current target.
4719 llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4721
4722 llvm::Value *
4723 EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty,
4724 const llvm::CmpInst::Predicate Pred,
4725 const llvm::Twine &Name = "");
4726 llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4728 llvm::Triple::ArchType Arch);
4729 llvm::Value *EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4731 llvm::Triple::ArchType Arch);
4732 llvm::Value *EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4734 llvm::Triple::ArchType Arch);
4735 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy,
4736 QualType RTy);
4737 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy,
4738 QualType RTy);
4739
4740 llvm::Value *
4741 EmitCommonNeonBuiltinExpr(unsigned BuiltinID, unsigned LLVMIntrinsic,
4742 unsigned AltLLVMIntrinsic, const char *NameHint,
4743 unsigned Modifier, const CallExpr *E,
4745 Address PtrOp1, llvm::Triple::ArchType Arch);
4746
4747 llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID,
4748 unsigned Modifier, llvm::Type *ArgTy,
4749 const CallExpr *E);
4750 llvm::Value *EmitNeonCall(llvm::Function *F,
4751 SmallVectorImpl<llvm::Value *> &O, const char *name,
4752 unsigned shift = 0, bool rightshift = false);
4753 llvm::Value *EmitFP8NeonCall(unsigned IID, ArrayRef<llvm::Type *> Tys,
4755 const CallExpr *E, const char *name);
4756 llvm::Value *EmitFP8NeonCvtCall(unsigned IID, llvm::Type *Ty0,
4757 llvm::Type *Ty1, bool Extract,
4759 const CallExpr *E, const char *name);
4760 llvm::Value *EmitFP8NeonFDOTCall(unsigned IID, bool ExtendLaneArg,
4761 llvm::Type *RetTy,
4763 const CallExpr *E, const char *name);
4764 llvm::Value *EmitFP8NeonFMLACall(unsigned IID, bool ExtendLaneArg,
4765 llvm::Type *RetTy,
4767 const CallExpr *E, const char *name);
4768 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx,
4769 const llvm::ElementCount &Count);
4770 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
4771 llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty,
4772 bool negateForRightShift);
4773 llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt,
4774 llvm::Type *Ty, bool usgn, const char *name);
4775 llvm::Value *vectorWrapScalar16(llvm::Value *Op);
4776 /// SVEBuiltinMemEltTy - Returns the memory element type for this memory
4777 /// access builtin. Only required if it can't be inferred from the base
4778 /// pointer operand.
4779 llvm::Type *SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags);
4780
4782 getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType,
4784 llvm::Type *getEltType(const SVETypeFlags &TypeFlags);
4785 llvm::ScalableVectorType *getSVEType(const SVETypeFlags &TypeFlags);
4786 llvm::ScalableVectorType *getSVEPredType(const SVETypeFlags &TypeFlags);
4787 llvm::Value *EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags,
4789 llvm::Value *EmitSVETupleCreate(const SVETypeFlags &TypeFlags,
4790 llvm::Type *ReturnType,
4792 llvm::Value *EmitSVEAllTruePred(const SVETypeFlags &TypeFlags);
4793 llvm::Value *EmitSVEDupX(llvm::Value *Scalar);
4794 llvm::Value *EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty);
4795 llvm::Value *EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty);
4796 llvm::Value *EmitSVEPMull(const SVETypeFlags &TypeFlags,
4798 unsigned BuiltinID);
4799 llvm::Value *EmitSVEMovl(const SVETypeFlags &TypeFlags,
4801 unsigned BuiltinID);
4802 llvm::Value *EmitSVEPredicateCast(llvm::Value *Pred,
4803 llvm::ScalableVectorType *VTy);
4804 llvm::Value *EmitSVEPredicateTupleCast(llvm::Value *PredTuple,
4805 llvm::StructType *Ty);
4806 llvm::Value *EmitSVEGatherLoad(const SVETypeFlags &TypeFlags,
4808 unsigned IntID);
4809 llvm::Value *EmitSVEScatterStore(const SVETypeFlags &TypeFlags,
4811 unsigned IntID);
4812 llvm::Value *EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy,
4814 unsigned BuiltinID, bool IsZExtReturn);
4815 llvm::Value *EmitSVEMaskedStore(const CallExpr *,
4817 unsigned BuiltinID);
4818 llvm::Value *EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags,
4820 unsigned BuiltinID);
4821 llvm::Value *EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags,
4823 unsigned IntID);
4824 llvm::Value *EmitSVEStructLoad(const SVETypeFlags &TypeFlags,
4826 unsigned IntID);
4827 llvm::Value *EmitSVEStructStore(const SVETypeFlags &TypeFlags,
4829 unsigned IntID);
4830 llvm::Value *EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4831
4832 llvm::Value *EmitSMELd1St1(const SVETypeFlags &TypeFlags,
4834 unsigned IntID);
4835 llvm::Value *EmitSMEReadWrite(const SVETypeFlags &TypeFlags,
4837 unsigned IntID);
4838 llvm::Value *EmitSMEZero(const SVETypeFlags &TypeFlags,
4840 unsigned IntID);
4841 llvm::Value *EmitSMELdrStr(const SVETypeFlags &TypeFlags,
4843 unsigned IntID);
4844
4845 void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E,
4847 SVETypeFlags TypeFlags);
4848
4849 llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4850
4851 llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4852 llvm::Triple::ArchType Arch);
4853 llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4854
4855 llvm::Value *BuildVector(ArrayRef<llvm::Value *> Ops);
4856 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4857 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4858 llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4859 llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4861
4862 // Returns a builtin function that the SPIR-V backend will expand into a spec
4863 // constant.
4864 llvm::Function *
4865 getSpecConstantFunction(const clang::QualType &SpecConstantType);
4866
4867 llvm::Value *EmitDirectXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4868 llvm::Value *EmitSPIRVBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4869 llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
4870 const CallExpr *E);
4871 llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4872 llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4873 llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
4874 const CallExpr *E);
4875 llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4876 llvm::Value *EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4878
4879 llvm::Value *EmitRISCVCpuSupports(const CallExpr *E);
4880 llvm::Value *EmitRISCVCpuSupports(ArrayRef<StringRef> FeaturesStrs);
4881 llvm::Value *EmitRISCVCpuInit();
4882 llvm::Value *EmitRISCVCpuIs(const CallExpr *E);
4883 llvm::Value *EmitRISCVCpuIs(StringRef CPUStr);
4884
4885 void AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
4886 const CallExpr *E);
4887 void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope,
4888 llvm::AtomicOrdering &AO,
4889 llvm::SyncScope::ID &SSID);
4890
4891 enum class MSVCIntrin;
4892 llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E);
4893
4894 llvm::Value *EmitBuiltinAvailable(const VersionTuple &Version);
4895
4896 llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
4897 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
4898 llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E);
4899 llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E);
4900 llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E);
4901 llvm::Value *
4903 const ObjCMethodDecl *MethodWithObjects);
4904 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
4906 ReturnValueSlot Return = ReturnValueSlot());
4907
4908 /// Retrieves the default cleanup kind for an ARC cleanup.
4909 /// Except under -fobjc-arc-eh, ARC cleanups are normal-only.
4911 return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions ? NormalAndEHCleanup
4912 : NormalCleanup;
4913 }
4914
4915 // ARC primitives.
4916 void EmitARCInitWeak(Address addr, llvm::Value *value);
4917 void EmitARCDestroyWeak(Address addr);
4918 llvm::Value *EmitARCLoadWeak(Address addr);
4919 llvm::Value *EmitARCLoadWeakRetained(Address addr);
4920 llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored);
4921 void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
4922 void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
4923 void EmitARCCopyWeak(Address dst, Address src);
4924 void EmitARCMoveWeak(Address dst, Address src);
4925 llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);
4926 llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value);
4927 llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value,
4928 bool resultIgnored);
4929 llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value,
4930 bool resultIgnored);
4931 llvm::Value *EmitARCRetain(QualType type, llvm::Value *value);
4932 llvm::Value *EmitARCRetainNonBlock(llvm::Value *value);
4933 llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory);
4935 void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
4936 llvm::Value *EmitARCAutorelease(llvm::Value *value);
4937 llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value);
4938 llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value);
4939 llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
4940 llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value);
4941
4942 llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType);
4943 llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value,
4944 llvm::Type *returnType);
4945 void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
4946
4947 std::pair<LValue, llvm::Value *>
4949 std::pair<LValue, llvm::Value *> EmitARCStoreStrong(const BinaryOperator *e,
4950 bool ignored);
4951 std::pair<LValue, llvm::Value *>
4952 EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored);
4953
4954 llvm::Value *EmitObjCAlloc(llvm::Value *value, llvm::Type *returnType);
4955 llvm::Value *EmitObjCAllocWithZone(llvm::Value *value,
4956 llvm::Type *returnType);
4957 llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType);
4958
4959 llvm::Value *EmitObjCThrowOperand(const Expr *expr);
4960 llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr);
4961 llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr);
4962
4963 llvm::Value *EmitARCExtendBlockObject(const Expr *expr);
4964 llvm::Value *EmitARCReclaimReturnedObject(const Expr *e,
4965 bool allowUnsafeClaim);
4966 llvm::Value *EmitARCRetainScalarExpr(const Expr *expr);
4967 llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr);
4968 llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr);
4969
4971
4973
4979
4980 void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr);
4981 llvm::Value *EmitObjCAutoreleasePoolPush();
4982 llvm::Value *EmitObjCMRRAutoreleasePoolPush();
4983 void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
4984 void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr);
4985
4986 /// Emits a reference binding to the passed in expression.
4988
4989 //===--------------------------------------------------------------------===//
4990 // Expression Emission
4991 //===--------------------------------------------------------------------===//
4992
4993 // Expressions are broken into three classes: scalar, complex, aggregate.
4994
4995 /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
4996 /// scalar type, returning the result.
4997 llvm::Value *EmitScalarExpr(const Expr *E, bool IgnoreResultAssign = false);
4998
4999 /// Emit a conversion from the specified type to the specified destination
5000 /// type, both of which are LLVM scalar types.
5001 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
5002 QualType DstTy, SourceLocation Loc);
5003
5004 /// Emit a conversion from the specified complex type to the specified
5005 /// destination type, where the destination type is an LLVM scalar type.
5007 QualType DstTy,
5008 SourceLocation Loc);
5009
5010 /// EmitAggExpr - Emit the computation of the specified expression
5011 /// of aggregate type. The result is computed into the given slot,
5012 /// which may be null to indicate that the value is not needed.
5013 void EmitAggExpr(const Expr *E, AggValueSlot AS);
5014
5015 /// EmitAggExprToLValue - Emit the computation of the specified expression of
5016 /// aggregate type into a temporary LValue.
5018
5020
5021 /// EmitAggFinalDestCopy - Emit copy of the specified aggregate into
5022 /// destination address.
5023 void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src,
5024 ExprValueKind SrcKind);
5025
5026 /// Create a store to \arg DstPtr from \arg Src, truncating the stored value
5027 /// to at most \arg DstSize bytes.
5028 void CreateCoercedStore(llvm::Value *Src, Address Dst, llvm::TypeSize DstSize,
5029 bool DstIsVolatile);
5030
5031 /// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
5032 /// make sure it survives garbage collection until this point.
5033 void EmitExtendGCLifetime(llvm::Value *object);
5034
5035 /// EmitComplexExpr - Emit the computation of the specified expression of
5036 /// complex type, returning the result.
5037 ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
5038 bool IgnoreImag = false);
5039
5040 /// EmitComplexExprIntoLValue - Emit the given expression of complex
5041 /// type and place its result into the specified l-value.
5042 void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);
5043
5044 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
5045 void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);
5046
5047 /// EmitLoadOfComplex - Load a complex number from the specified l-value.
5049
5050 ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType);
5051 llvm::Value *EmitPromotedScalarExpr(const Expr *E, QualType PromotionType);
5054 QualType PromotionType);
5055
5058
5059 /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the
5060 /// global variable that has already been created for it. If the initializer
5061 /// has a different type than GV does, this may free GV and return a different
5062 /// one. Otherwise it just returns GV.
5063 llvm::GlobalVariable *AddInitializerToStaticVarDecl(const VarDecl &D,
5064 llvm::GlobalVariable *GV);
5065
5066 // Emit an @llvm.invariant.start call for the given memory region.
5067 void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size);
5068
5069 /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
5070 /// variable with global storage.
5071 void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV,
5072 bool PerformInit);
5073
5074 llvm::Constant *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor,
5075 llvm::Constant *Addr);
5076
5077 llvm::Function *createTLSAtExitStub(const VarDecl &VD,
5078 llvm::FunctionCallee Dtor,
5079 llvm::Constant *Addr,
5080 llvm::FunctionCallee &AtExit);
5081
5082 /// Call atexit() with a function that passes the given argument to
5083 /// the given function.
5084 void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn,
5085 llvm::Constant *addr);
5086
5087 /// Registers the dtor using 'llvm.global_dtors' for platforms that do not
5088 /// support an 'atexit()' function.
5089 void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn,
5090 llvm::Constant *addr);
5091
5092 /// Call atexit() with function dtorStub.
5093 void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub);
5094
5095 /// Call unatexit() with function dtorStub.
5096 llvm::Value *unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub);
5097
5098 /// Emit code in this function to perform a guarded variable
5099 /// initialization. Guarded initializations are used when it's not
5100 /// possible to prove that an initialization will be done exactly
5101 /// once, e.g. with a static local variable or a static data member
5102 /// of a class template.
5103 void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr,
5104 bool PerformInit);
5105
5107
5108 /// Emit a branch to select whether or not to perform guarded initialization.
5109 void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit,
5110 llvm::BasicBlock *InitBlock,
5111 llvm::BasicBlock *NoInitBlock, GuardKind Kind,
5112 const VarDecl *D);
5113
5114 /// GenerateCXXGlobalInitFunc - Generates code for initializing global
5115 /// variables.
5116 void
5117 GenerateCXXGlobalInitFunc(llvm::Function *Fn,
5118 ArrayRef<llvm::Function *> CXXThreadLocals,
5120
5121 /// GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global
5122 /// variables.
5124 llvm::Function *Fn,
5125 ArrayRef<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
5126 llvm::Constant *>>
5127 DtorsOrStermFinalizers);
5128
5129 void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D,
5130 llvm::GlobalVariable *Addr,
5131 bool PerformInit);
5132
5134
5135 void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp);
5136
5137 void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true);
5138
5140
5141 void EmitFakeUse(Address Addr);
5142
5143 //===--------------------------------------------------------------------===//
5144 // Annotations Emission
5145 //===--------------------------------------------------------------------===//
5146
5147 /// Emit an annotation call (intrinsic).
5148 llvm::Value *EmitAnnotationCall(llvm::Function *AnnotationFn,
5149 llvm::Value *AnnotatedVal,
5150 StringRef AnnotationStr,
5151 SourceLocation Location,
5152 const AnnotateAttr *Attr);
5153
5154 /// Emit local annotations for the local variable V, declared by D.
5155 void EmitVarAnnotations(const VarDecl *D, llvm::Value *V);
5156
5157 /// Emit field annotations for the given field & value. Returns the
5158 /// annotation result.
5160
5161 //===--------------------------------------------------------------------===//
5162 // Internal Helpers
5163 //===--------------------------------------------------------------------===//
5164
5165 /// ContainsLabel - Return true if the statement contains a label in it. If
5166 /// this statement is not executed normally, it not containing a label means
5167 /// that we can just remove the code.
5168 static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
5169
5170 /// containsBreak - Return true if the statement contains a break out of it.
5171 /// If the statement (recursively) contains a switch or loop with a break
5172 /// inside of it, this is fine.
5173 static bool containsBreak(const Stmt *S);
5174
5175 /// Determine if the given statement might introduce a declaration into the
5176 /// current scope, by being a (possibly-labelled) DeclStmt.
5177 static bool mightAddDeclToScope(const Stmt *S);
5178
5179 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
5180 /// to a constant, or if it does but contains a label, return false. If it
5181 /// constant folds return true and set the boolean result in Result.
5182 bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result,
5183 bool AllowLabels = false);
5184
5185 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
5186 /// to a constant, or if it does but contains a label, return false. If it
5187 /// constant folds return true and set the folded value.
5188 bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result,
5189 bool AllowLabels = false);
5190
5191 /// Ignore parentheses and logical-NOT to track conditions consistently.
5192 static const Expr *stripCond(const Expr *C);
5193
5194 /// isInstrumentedCondition - Determine whether the given condition is an
5195 /// instrumentable condition (i.e. no "&&" or "||").
5196 static bool isInstrumentedCondition(const Expr *C);
5197
5198 /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that
5199 /// increments a profile counter based on the semantics of the given logical
5200 /// operator opcode. This is used to instrument branch condition coverage
5201 /// for logical operators.
5203 llvm::BasicBlock *TrueBlock,
5204 llvm::BasicBlock *FalseBlock,
5205 uint64_t TrueCount = 0,
5207 const Expr *CntrIdx = nullptr);
5208
5209 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
5210 /// if statement) to the specified blocks. Based on the condition, this might
5211 /// try to simplify the codegen of the conditional based on the branch.
5212 /// TrueCount should be the number of times we expect the condition to
5213 /// evaluate to true based on PGO data.
5214 void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
5215 llvm::BasicBlock *FalseBlock, uint64_t TrueCount,
5217 const Expr *ConditionalOp = nullptr,
5218 const VarDecl *ConditionalDecl = nullptr);
5219
5220 /// Given an assignment `*LHS = RHS`, emit a test that checks if \p RHS is
5221 /// nonnull, if \p LHS is marked _Nonnull.
5222 void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc);
5223
5224 /// An enumeration which makes it easier to specify whether or not an
5225 /// operation is a subtraction.
5226 enum { NotSubtraction = false, IsSubtraction = true };
5227
5228 /// Emit pointer + index arithmetic.
5229 llvm::Value *EmitPointerArithmetic(const BinaryOperator *BO,
5230 Expr *pointerOperand, llvm::Value *pointer,
5231 Expr *indexOperand, llvm::Value *index,
5232 bool isSubtraction);
5233
5234 /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
5235 /// detect undefined behavior when the pointer overflow sanitizer is enabled.
5236 /// \p SignedIndices indicates whether any of the GEP indices are signed.
5237 /// \p IsSubtraction indicates whether the expression used to form the GEP
5238 /// is a subtraction.
5239 llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr,
5241 bool SignedIndices, bool IsSubtraction,
5242 SourceLocation Loc,
5243 const Twine &Name = "");
5244
5246 llvm::Type *elementType, bool SignedIndices,
5247 bool IsSubtraction, SourceLocation Loc,
5248 CharUnits Align, const Twine &Name = "");
5249
5250 /// Specifies which type of sanitizer check to apply when handling a
5251 /// particular builtin.
5257
5258 /// Emits an argument for a call to a builtin. If the builtin sanitizer is
5259 /// enabled, a runtime check specified by \p Kind is also emitted.
5260 llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind);
5261
5262 /// Emits an argument for a call to a `__builtin_assume`. If the builtin
5263 /// sanitizer is enabled, a runtime check is also emitted.
5264 llvm::Value *EmitCheckedArgForAssume(const Expr *E);
5265
5266 /// Emit a description of a type in a format suitable for passing to
5267 /// a runtime sanitizer handler.
5268 llvm::Constant *EmitCheckTypeDescriptor(QualType T);
5269
5270 /// Convert a value into a format suitable for passing to a runtime
5271 /// sanitizer handler.
5272 llvm::Value *EmitCheckValue(llvm::Value *V);
5273
5274 /// Emit a description of a source location in a format suitable for
5275 /// passing to a runtime sanitizer handler.
5276 llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc);
5277
5278 void EmitKCFIOperandBundle(const CGCallee &Callee,
5280
5281 /// Create a basic block that will either trap or call a handler function in
5282 /// the UBSan runtime with the provided arguments, and create a conditional
5283 /// branch to it.
5284 void
5285 EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerKind::SanitizerOrdinal>>
5286 Checked,
5288 ArrayRef<llvm::Value *> DynamicArgs,
5289 const TrapReason *TR = nullptr);
5290
5291 /// Emit a slow path cross-DSO CFI check which calls __cfi_slowpath
5292 /// if Cond if false.
5294 llvm::Value *Cond, llvm::ConstantInt *TypeId,
5295 llvm::Value *Ptr,
5296 ArrayRef<llvm::Constant *> StaticArgs);
5297
5298 /// Emit a reached-unreachable diagnostic if \p Loc is valid and runtime
5299 /// checking is enabled. Otherwise, just emit an unreachable instruction.
5301
5302 /// Create a basic block that will call the trap intrinsic, and emit a
5303 /// conditional branch to it, for the -ftrapv checks.
5304 void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID,
5305 bool NoMerge = false, const TrapReason *TR = nullptr);
5306
5307 /// Emit a call to trap or debugtrap and attach function attribute
5308 /// "trap-func-name" if specified.
5309 llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID);
5310
5311 /// Emit a stub for the cross-DSO CFI check function.
5312 void EmitCfiCheckStub();
5313
5314 /// Emit a cross-DSO CFI failure handling function.
5315 void EmitCfiCheckFail();
5316
5317 /// Create a check for a function parameter that may potentially be
5318 /// declared as non-null.
5319 void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc,
5320 AbstractCallee AC, unsigned ParmNum);
5321
5323 SourceLocation ArgLoc, AbstractCallee AC,
5324 unsigned ParmNum);
5325
5326 /// EmitWriteback - Emit callbacks for function.
5327 void EmitWritebacks(const CallArgList &Args);
5328
5329 /// EmitCallArg - Emit a single call argument.
5330 void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType);
5331
5332 /// EmitDelegateCallArg - We are performing a delegate call; that
5333 /// is, the current function is delegating to another one. Produce
5334 /// a r-value suitable for passing the given parameter.
5335 void EmitDelegateCallArg(CallArgList &args, const VarDecl *param,
5336 SourceLocation loc);
5337
5338 /// SetFPAccuracy - Set the minimum required accuracy of the given floating
5339 /// point operation, expressed as the maximum relative error in ulp.
5340 void SetFPAccuracy(llvm::Value *Val, float Accuracy);
5341
5342 /// Set the minimum required accuracy of the given sqrt operation
5343 /// based on CodeGenOpts.
5344 void SetSqrtFPAccuracy(llvm::Value *Val);
5345
5346 /// Set the minimum required accuracy of the given sqrt operation based on
5347 /// CodeGenOpts.
5348 void SetDivFPAccuracy(llvm::Value *Val);
5349
5350 /// Set the codegen fast-math flags.
5351 void SetFastMathFlags(FPOptions FPFeatures);
5352
5353 // Truncate or extend a boolean vector to the requested number of elements.
5354 llvm::Value *emitBoolVecConversion(llvm::Value *SrcVec,
5355 unsigned NumElementsDst,
5356 const llvm::Twine &Name = "");
5357
5358 void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty,
5359 SourceLocation Loc);
5360
5361private:
5362 // Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
5363 // as it's parent convergence instr.
5364 llvm::ConvergenceControlInst *emitConvergenceLoopToken(llvm::BasicBlock *BB);
5365
5366 // Adds a convergence_ctrl token with |ParentToken| as parent convergence
5367 // instr to the call |Input|.
5368 llvm::CallBase *addConvergenceControlToken(llvm::CallBase *Input);
5369
5370 // Find the convergence_entry instruction |F|, or emits ones if none exists.
5371 // Returns the convergence instruction.
5372 llvm::ConvergenceControlInst *
5373 getOrEmitConvergenceEntryToken(llvm::Function *F);
5374
5375private:
5376 llvm::MDNode *getRangeForLoadFromType(QualType Ty);
5377 void EmitReturnOfRValue(RValue RV, QualType Ty);
5378
5379 void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New);
5380
5382 DeferredReplacements;
5383
5384 /// Set the address of a local variable.
5385 void setAddrOfLocalVar(const VarDecl *VD, Address Addr) {
5386 assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!");
5387 LocalDeclMap.insert({VD, Addr});
5388 }
5389
5390 /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
5391 /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
5392 ///
5393 /// \param AI - The first function argument of the expansion.
5394 void ExpandTypeFromArgs(QualType Ty, LValue Dst,
5395 llvm::Function::arg_iterator &AI);
5396
5397 /// ExpandTypeToArgs - Expand an CallArg \arg Arg, with the LLVM type for \arg
5398 /// Ty, into individual arguments on the provided vector \arg IRCallArgs,
5399 /// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand.
5400 void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,
5401 SmallVectorImpl<llvm::Value *> &IRCallArgs,
5402 unsigned &IRCallArgPos);
5403
5404 std::pair<llvm::Value *, llvm::Type *>
5405 EmitAsmInput(const TargetInfo::ConstraintInfo &Info, const Expr *InputExpr,
5406 std::string &ConstraintStr);
5407
5408 std::pair<llvm::Value *, llvm::Type *>
5409 EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, LValue InputValue,
5410 QualType InputType, std::string &ConstraintStr,
5411 SourceLocation Loc);
5412
5413 /// Attempts to statically evaluate the object size of E. If that
5414 /// fails, emits code to figure the size of E out for us. This is
5415 /// pass_object_size aware.
5416 ///
5417 /// If EmittedExpr is non-null, this will use that instead of re-emitting E.
5418 llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
5419 llvm::IntegerType *ResType,
5420 llvm::Value *EmittedE,
5421 bool IsDynamic);
5422
5423 /// Emits the size of E, as required by __builtin_object_size. This
5424 /// function is aware of pass_object_size parameters, and will act accordingly
5425 /// if E is a parameter with the pass_object_size attribute.
5426 llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type,
5427 llvm::IntegerType *ResType,
5428 llvm::Value *EmittedE, bool IsDynamic);
5429
5430 llvm::Value *emitCountedBySize(const Expr *E, llvm::Value *EmittedE,
5431 unsigned Type, llvm::IntegerType *ResType);
5432
5433 llvm::Value *emitCountedByMemberSize(const MemberExpr *E, const Expr *Idx,
5434 llvm::Value *EmittedE,
5435 QualType CastedArrayElementTy,
5436 unsigned Type,
5437 llvm::IntegerType *ResType);
5438
5439 llvm::Value *emitCountedByPointerSize(const ImplicitCastExpr *E,
5440 const Expr *Idx, llvm::Value *EmittedE,
5441 QualType CastedArrayElementTy,
5442 unsigned Type,
5443 llvm::IntegerType *ResType);
5444
5445 void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D,
5446 Address Loc);
5447
5448public:
5449 enum class EvaluationOrder {
5450 ///! No language constraints on evaluation order.
5452 ///! Language semantics require left-to-right evaluation.
5454 ///! Language semantics require right-to-left evaluation.
5456 };
5457
5458 // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
5459 // an ObjCMethodDecl.
5461 llvm::PointerUnion<const FunctionProtoType *, const ObjCMethodDecl *> P;
5462
5465 };
5466
5467 void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype,
5468 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
5469 AbstractCallee AC = AbstractCallee(),
5470 unsigned ParamsToSkip = 0,
5472
5473 /// EmitPointerWithAlignment - Given an expression with a pointer type,
5474 /// emit the value and compute our best estimate of the alignment of the
5475 /// pointee.
5476 ///
5477 /// \param BaseInfo - If non-null, this will be initialized with
5478 /// information about the source of the alignment and the may-alias
5479 /// attribute. Note that this function will conservatively fall back on
5480 /// the type when it doesn't recognize the expression and may-alias will
5481 /// be set to false.
5482 ///
5483 /// One reasonable way to use this information is when there's a language
5484 /// guarantee that the pointer must be aligned to some stricter value, and
5485 /// we're simply trying to ensure that sufficiently obvious uses of under-
5486 /// aligned objects don't get miscompiled; for example, a placement new
5487 /// into the address of a local variable. In such a case, it's quite
5488 /// reasonable to just ignore the returned alignment when it isn't from an
5489 /// explicit source.
5490 Address
5491 EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo = nullptr,
5492 TBAAAccessInfo *TBAAInfo = nullptr,
5493 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
5494
5495 /// If \p E references a parameter with pass_object_size info or a constant
5496 /// array size modifier, emit the object size divided by the size of \p EltTy.
5497 /// Otherwise return null.
5498 llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy);
5499
5500 void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
5501
5503 llvm::Function *Function;
5505 std::optional<StringRef> Architecture;
5506
5507 FMVResolverOption(llvm::Function *F, ArrayRef<StringRef> Feats,
5508 std::optional<StringRef> Arch = std::nullopt)
5509 : Function(F), Features(Feats), Architecture(Arch) {}
5510 };
5511
5512 // Emits the body of a multiversion function's resolver. Assumes that the
5513 // options are already sorted in the proper order, with the 'default' option
5514 // last (if it exists).
5515 void EmitMultiVersionResolver(llvm::Function *Resolver,
5517 void EmitX86MultiVersionResolver(llvm::Function *Resolver,
5519 void EmitAArch64MultiVersionResolver(llvm::Function *Resolver,
5521 void EmitRISCVMultiVersionResolver(llvm::Function *Resolver,
5523
5524private:
5525 QualType getVarArgType(const Expr *Arg);
5526
5527 void EmitDeclMetadata();
5528
5529 BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType,
5530 const AutoVarEmission &emission);
5531
5532 void AddObjCARCExceptionMetadata(llvm::Instruction *Inst);
5533
5534 llvm::Value *GetValueForARMHint(unsigned BuiltinID);
5535 llvm::Value *EmitX86CpuIs(const CallExpr *E);
5536 llvm::Value *EmitX86CpuIs(StringRef CPUStr);
5537 llvm::Value *EmitX86CpuSupports(const CallExpr *E);
5538 llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs);
5539 llvm::Value *EmitX86CpuSupports(std::array<uint32_t, 4> FeatureMask);
5540 llvm::Value *EmitX86CpuInit();
5541 llvm::Value *FormX86ResolverCondition(const FMVResolverOption &RO);
5542 llvm::Value *EmitAArch64CpuInit();
5543 llvm::Value *FormAArch64ResolverCondition(const FMVResolverOption &RO);
5544 llvm::Value *EmitAArch64CpuSupports(const CallExpr *E);
5545 llvm::Value *EmitAArch64CpuSupports(ArrayRef<StringRef> FeatureStrs);
5546};
5547
5550 if (!needsSaving(value))
5551 return saved_type(value, false);
5552
5553 // Otherwise, we need an alloca.
5554 auto align = CharUnits::fromQuantity(
5555 CGF.CGM.getDataLayout().getPrefTypeAlign(value->getType()));
5556 Address alloca =
5557 CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save");
5558 CGF.Builder.CreateStore(value, alloca);
5559
5560 return saved_type(alloca.emitRawPointer(CGF), true);
5561}
5562
5564 saved_type value) {
5565 // If the value says it wasn't saved, trust that it's still dominating.
5566 if (!value.getInt())
5567 return value.getPointer();
5568
5569 // Otherwise, it should be an alloca instruction, as set up in save().
5570 auto alloca = cast<llvm::AllocaInst>(value.getPointer());
5571 return CGF.Builder.CreateAlignedLoad(alloca->getAllocatedType(), alloca,
5572 alloca->getAlign());
5573}
5574
5575} // end namespace CodeGen
5576
5577// Map the LangOption for floating point exception behavior into
5578// the corresponding enum in the IR.
5579llvm::fp::ExceptionBehavior
5581} // end namespace clang
5582
5583#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:2777
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:4271
@ 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
Defines some OpenMP-specific enums and functions.
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 cancel' directive.
This represents 'pragma omp cancellation point' 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 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 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 taskloop' directive.
This represents 'pragma omp master taskloop simd' directive.
This represents 'pragma omp metadirective' directive.
This represents 'pragma omp parallel masked taskloop' directive.
This represents 'pragma omp parallel masked taskloop simd' directive.
This represents 'pragma omp parallel master taskloop' directive.
This represents 'pragma omp parallel master taskloop simd' directive.
Represents the 'pragma omp reverse' loop transformation directive.
This represents 'pragma omp scan' 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 simd' 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 taskloop' directive.
This represents 'pragma omp taskloop simd' 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.
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:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4287
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7105
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6814
Attr - This represents one attribute.
Definition Attr.h:44
Represents an attribute applied to a statement.
Definition Stmt.h:2203
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4387
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4425
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4422
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
static bool isLogicalOp(Opcode Opc)
Definition Expr.h:4105
BinaryOperatorKind Opcode
Definition Expr.h:3977
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6558
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:234
Represents binding an expression to a temporary.
Definition ExprCXX.h:1494
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1271
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1378
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2628
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:481
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2357
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2747
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ temporary.
Definition ExprCXX.h:1460
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:848
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1069
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
This captures a statement into a function.
Definition Stmt.h:3886
const Capture * const_capture_iterator
Definition Stmt.h:4020
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of captures.
Definition Stmt.h:4037
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
Definition Stmt.h:4007
capture_iterator capture_begin()
Retrieve an iterator pointing to the first capture.
Definition Stmt.h:4032
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3610
const CXXBaseSpecifier *const * path_const_iterator
Definition Expr.h:3677
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition CharUnits.h:122
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
Definition CharUnits.h:189
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:63
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition CharUnits.h:53
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:504
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Definition CGValue.h:572
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:587
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:140
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition CGBuilder.h:132
Implements C++ ABI-specific code generation functions.
Definition CGCXXABI.h:43
All available information about a concrete callee.
Definition CGCall.h:63
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition CGDebugInfo.h:59
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:274
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:757
~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 apply(CodeGenFunction &CGF)
Applies new addresses to the list of the variables.
void restore(CodeGenFunction &CGF)
Restores original addresses of the variables.
bool setVarAddr(CodeGenFunction &CGF, const VarDecl *LocalVD, Address TempAddr)
Sets the address of the variable LocalVD to be TempAddr in function CGF.
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 VarDecl *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...
void CreateCoercedStore(llvm::Value *Src, Address Dst, llvm::TypeSize DstSize, bool DstIsVolatile)
Create a store to.
Definition CGCall.cpp:1398
EHScopeStack::stable_iterator CurrentCleanupScopeDepth
RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E)
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E)
Definition CGExpr.cpp:4857
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:2434
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:2752
void EmitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &S)
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E)
llvm::Value * EmitSVEPredicateCast(llvm::Value *Pred, llvm::ScalableVectorType *VTy)
Definition ARM.cpp:3877
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
Produce the code for a CK_ARCConsumeObject.
Definition CGObjC.cpp:2152
llvm::Value * EmitFP8NeonFMLACall(unsigned IID, bool ExtendLaneArg, llvm::Type *RetTy, SmallVectorImpl< llvm::Value * > &Ops, const CallExpr *E, const char *name)
Definition ARM.cpp:474
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
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:3111
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::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:2848
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
Definition CGObjC.cpp:573
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:2692
llvm::BasicBlock * getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope)
void EmitAArch64MultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, const FunctionArgList &Args)
Definition CGClass.cpp:2548
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:2599
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
Definition CGDecl.cpp:2394
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
Definition CGExpr.cpp:6358
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:8071
void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, const FunctionArgList &Args, SourceLocation Loc)
Definition CGClass.cpp:2489
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.
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:5675
llvm::Value * EmitARCReclaimReturnedObject(const Expr *e, bool allowUnsafeClaim)
Definition CGObjC.cpp:3089
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
Definition CGObjC.cpp:3679
void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S)
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
Definition CGExpr.cpp:1357
void SetDivFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
Definition CGExpr.cpp:6759
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
EmitARCUnsafeUnretainedScalarExpr - Semantically equivalent to immediately releasing the resut of Emi...
Definition CGObjC.cpp:3618
llvm::Value * EmitObjCSelectorExpr(const ObjCSelectorExpr *E)
Emit a selector.
Definition CGObjC.cpp:257
llvm::Value * EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx, const CallExpr *E)
Definition AMDGPU.cpp:274
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.
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:768
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:2386
void pushStackRestore(CleanupKind kind, Address SPMem)
Definition CGDecl.cpp:2322
LValue EmitInitListLValue(const InitListExpr *E)
Definition CGExpr.cpp:5559
bool isUnderlyingBasePointerConstantNull(const Expr *E)
Check whether the underlying base pointer is a constant null.
Definition CGExpr.cpp:5141
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:2663
RawAddress CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
Definition CGExpr.cpp:181
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:4643
llvm::Value * EmitSVEStructLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:4072
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:4180
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
bool ShouldSkipSanitizerInstrumentation()
ShouldSkipSanitizerInstrumentation - Return true if the current function should not be instrumented w...
llvm::Value * EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
Definition CGObjC.cpp:251
void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef< const Attr * > Attrs={})
Definition CGStmt.cpp:1451
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:448
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
Definition CGExpr.cpp:6390
llvm::Value * GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD, const FieldDecl *CountDecl)
Definition CGExpr.cpp:1185
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:970
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:960
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:6371
AwaitSuspendWrapperInfo CurAwaitSuspendWrapper
void EmitFakeUse(Address Addr)
Definition CGDecl.cpp:1379
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:3250
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:4039
llvm::Value * EmitObjCProtocolExpr(const ObjCProtocolExpr *E)
Definition CGObjC.cpp:265
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:5095
llvm::Value * EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition SystemZ.cpp:39
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:2268
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
Emits a call or invoke to the given noreturn runtime function.
Definition CGCall.cpp:5058
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:5085
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)
llvm::Value * EmitARCAutoreleaseReturnValue(llvm::Value *value)
Autorelease the given object.
Definition CGObjC.cpp:2589
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
Produce the code to do a retain.
Definition CGObjC.cpp:2328
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:2876
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
Definition CGClass.cpp:3113
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
llvm::Value * EmitARCAutorelease(llvm::Value *value)
Autorelease the given object.
Definition CGObjC.cpp:2580
void EmitOMPSimdInit(const OMPLoopDirective &D)
Helpers for the OpenMP loop directives.
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
Definition CGObjC.cpp:3508
llvm::Value * EmitSMEReadWrite(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:4327
llvm::Type * SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags)
SVEBuiltinMemEltTy - Returns the memory element type for this memory access builtin.
Definition ARM.cpp:3736
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:3982
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:3135
void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src, ExprValueKind SrcKind)
EmitAggFinalDestCopy - Emit copy of the specified aggregate into destination address.
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
Definition CGObjC.cpp:2681
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:286
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:2840
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:4237
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
Definition CGExpr.cpp:3577
bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
Definition CGObjC.cpp:2867
void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S)
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
Definition CGStmt.cpp:709
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:2594
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
SmallVector< llvm::ConvergenceControlInst *, 4 > ConvergenceTokenStack
Stack to track the controlled convergence tokens.
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:348
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
Definition CGExpr.cpp:5532
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:2805
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:2129
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:6712
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:2761
llvm::Value * EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition ARM.cpp:4894
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
Definition CGDecl.cpp:1348
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:3729
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
Definition CGObjC.cpp:2916
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
Definition CGExpr.cpp:6376
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:1929
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:6738
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:6062
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:6288
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
Definition CGExpr.cpp:721
void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, CallArgList &CallArgs, const CGFunctionInfo *CallOpFnInfo=nullptr, llvm::Constant *CallOpFn=nullptr)
Definition CGClass.cpp:3040
void EmitReturnValueCheck(llvm::Value *RV)
Emit a test that checks if the return value RV is nonnull.
Definition CGCall.cpp:4207
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:508
void EmitBoundsCheck(const Expr *E, const Expr *Base, 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:1236
RValue emitBuiltinOSLogFormat(const CallExpr &E)
Emit IR for __builtin_os_log_format.
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:6859
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:4294
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
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.
unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex)
Get the record field index as represented in debug info.
Definition CGExpr.cpp:5251
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:247
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:4100
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
Definition CGExpr.cpp:684
llvm::Value * EmitARCRetainAutorelease(QualType type, llvm::Value *value)
Do a fused retain/autorelease of the given object.
Definition CGObjC.cpp:2611
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
Store into a strong object.
Definition CGObjC.cpp:2545
llvm::Value * EmitARCRetainAutoreleasedReturnValue(llvm::Value *value)
Retain the given object which is the result of a function call.
Definition CGObjC.cpp:2463
bool isPointerKnownNonNull(const Expr *E)
void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD)
StartObjCMethod - Begin emission of an ObjCMethod.
Definition CGObjC.cpp:752
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:1482
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
Definition CGExpr.cpp:6689
llvm::Value * EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value)
Claim a possibly-autoreleased return value at +0.
Definition CGObjC.cpp:2475
llvm::Value * EmitObjCMRRAutoreleasePoolPush()
Produce the code to do an MRR version objc_autoreleasepool_push.
Definition CGObjC.cpp:2764
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:6424
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:720
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor)
Definition CGObjC.cpp:1752
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:394
llvm::Value * EmitObjCAllocWithZone(llvm::Value *value, llvm::Type *returnType)
Allocate the given objc object.
Definition CGObjC.cpp:2798
void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E)
Definition CGExpr.cpp:5657
void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, SVETypeFlags TypeFlags)
Definition ARM.cpp:4464
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:2937
llvm::Value * EmitSVEGatherLoad(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:3928
llvm::Function * GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info, const DeclMapTy &ldm, bool IsLambdaConversionToBlock, bool BuildGlobalBlock)
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
llvm::Function * LookupNeonLLVMIntrinsic(unsigned IntrinsicID, unsigned Modifier, llvm::Type *ArgTy, const CallExpr *E)
Definition ARM.cpp:1639
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:2278
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition CGDecl.cpp:787
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:765
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
Definition CGClass.cpp:830
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)
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:3120
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:3187
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:2049
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:692
RValue EmitLoadOfGlobalRegLValue(LValue LV)
Load of global named registers are always calls to intrinsics.
Definition CGExpr.cpp:2590
VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass)
Definition CGClass.cpp:2672
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:2890
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:3752
void SimplifyForwardingBlocks(llvm::BasicBlock *BB)
SimplifyForwardingBlocks - If the given basic block is only a branch to another basic block,...
Definition CGStmt.cpp:633
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:3542
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
Definition CGClass.cpp:2577
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:1740
llvm::Value * EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
Definition RISCV.cpp:1073
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
Definition CGExpr.cpp:6213
bool InNoMergeAttributedStmt
True if the current statement has nomerge attribute.
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:2578
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)
llvm::BasicBlock * getUnreachableBlock()
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition CGDecl.cpp:2251
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:2481
void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty, SourceLocation Loc)
Definition CGExpr.cpp:2093
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:2608
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:85
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:3629
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:6864
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:3619
void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::Value *Index, QualType IndexType, QualType IndexedType, bool Accessed)
Definition CGExpr.cpp:1250
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:5911
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:963
void EmitAnyExprToExn(const Expr *E, Address Addr)
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
@ Default
! No language constraints on evaluation order.
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
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::SmallPtrSet< const CXXRecordDecl *, 4 > VisitedVirtualBasesSetTy
void GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCGetter - Synthesize an Objective-C property getter function.
Definition CGObjC.cpp:1049
llvm::Value * EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
Definition CGExpr.cpp:6416
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:4584
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
Definition CGExpr.cpp:2399
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:5333
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:174
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:4507
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:404
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:495
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
Definition CGStmt.cpp:581
void pushKmpcAllocFree(CleanupKind Kind, std::pair< llvm::Value *, llvm::Value * > AddrSizePair)
Definition CGDecl.cpp:2326
void GenerateOpenMPCapturedVars(const CapturedStmt &S, SmallVectorImpl< llvm::Value * > &CapturedVars)
llvm::Value * EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty)
Definition CGObjC.cpp:3953
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:150
void EmitGotoStmt(const GotoStmt &S)
Definition CGStmt.cpp:845
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)
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:2664
LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args, QualType Ty)
Definition CGExpr.cpp:5934
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
Definition CGExpr.cpp:726
CGCallee EmitCallee(const Expr *E)
Definition CGExpr.cpp:6138
void EmitWritebacks(const CallArgList &Args)
EmitWriteback - Emit callbacks for function.
Definition CGCall.cpp:4875
void EmitOMPCriticalDirective(const OMPCriticalDirective &S)
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
Definition CGExpr.cpp:242
void EnterSEHTryStmt(const SEHTryStmt &S)
llvm::Value * EmitRISCVCpuIs(const CallExpr *E)
Definition RISCV.cpp:1032
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot(), llvm::CallBase **CallOrInvoke=nullptr)
Definition CGExpr.cpp:6012
llvm::ScalableVectorType * getSVEType(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3825
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:2417
void EmitOMPCancelDirective(const OMPCancelDirective &S)
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
Definition CGDecl.cpp:2303
LValue EmitArraySectionExpr(const ArraySectionExpr *E, bool IsLowerBound=true)
Definition CGExpr.cpp:4916
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 EmitOMPOrderedDirective(const OMPOrderedDirective &S)
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
Definition CGObjC.cpp:2510
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:4061
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:7962
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:1293
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:293
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:1913
llvm::Value * EmitSMELdrStr(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:4349
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:1796
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:3688
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 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:6727
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:4452
void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S)
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
Definition CGClass.cpp:2189
llvm::Value * EmitSVEPMull(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
Definition ARM.cpp:4135
llvm::Value * EmitObjCBoxedExpr(const ObjCBoxedExpr *E)
EmitObjCBoxedExpr - This routine generates code to call the appropriate expression boxing method.
Definition CGObjC.cpp:64
void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S)
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:223
void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType)
EmitCallArg - Emit a single call argument.
Definition CGCall.cpp:4880
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:1078
JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind)
void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, const ObjCPropertyImplDecl *propImpl, llvm::Constant *AtomicHelperFn)
Definition CGObjC.cpp:1468
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:73
LValue EmitPredefinedLValue(const PredefinedExpr *E)
Definition CGExpr.cpp:3582
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:3869
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:3716
void ResolveBranchFixups(llvm::BasicBlock *Target)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
Definition CGExpr.cpp:3286
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
void EmitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &S)
SmallVector< const BinaryOperator *, 16 > MCDCLogOpStack
Stack to track the Logical Operator recursion nest for MC/DC.
LValue EmitStringLiteralLValue(const StringLiteral *E)
Definition CGExpr.cpp:3572
llvm::Value * EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
Definition ARM.cpp:3469
void EmitOMPMaskedDirective(const OMPMaskedDirective &S)
Address getAsNaturalAddressOf(Address Addr, QualType PointeeTy)
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
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:1015
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
Definition CGExpr.cpp:5965
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 EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This)
Emit assumption load for all bases.
Definition CGClass.cpp:2452
llvm::Value * EmitARCRetainBlock(llvm::Value *value, bool mandatory)
Retain the given block, with _Block_copy semantics.
Definition CGObjC.cpp:2349
llvm::Value * EmitObjCCollectionLiteral(const Expr *E, const ObjCMethodDecl *MethodWithObjects)
Definition CGObjC.cpp:123
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:511
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:2048
void AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst, const CallExpr *E)
Definition AMDGPU.cpp:291
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S)
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
EmitARCRetainScalarExpr - Semantically equivalent to EmitARCRetainObject(e->getType(),...
Definition CGObjC.cpp:3493
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:1356
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:1645
void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S)
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
Definition CGClass.cpp:1446
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.
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:5507
llvm::Value * EmitBlockLiteral(const BlockExpr *)
Emit block literal.
Definition CGBlocks.cpp:764
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:2234
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:151
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
Definition CGObjC.cpp:2125
SmallVector< llvm::Type *, 2 > getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
Definition ARM.cpp:4416
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:5951
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:2107
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue, llvm::Value *TheCheck, llvm::Instruction *Assumption)
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:5241
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:1266
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:6328
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
void EmitLifetimeEnd(llvm::Value *Addr)
Definition CGDecl.cpp:1368
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:215
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...
void EmitPointerAuthCopy(PointerAuthQualifier Qualifier, QualType Type, Address DestField, Address SrcField)
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S)
LValue EmitVAArgExprLValue(const VAArgExpr *E)
Definition CGExpr.cpp:6353
bool InNoInlineAttributedStmt
True if the current statement has noinline attribute.
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
Definition CGCall.cpp:5023
void EmitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &S)
llvm::Value * EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::Value * EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, bool negateForRightShift)
Definition ARM.cpp:489
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:2825
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:2789
llvm::Value * LoadObjCSelf()
LoadObjCSelf - Load the value of self.
Definition CGObjC.cpp:1788
void GenerateObjCMethod(const ObjCMethodDecl *OMD)
Generate an Objective-C method.
Definition CGObjC.cpp:807
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:283
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:6456
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:2643
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:4974
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
Definition CGStmt.cpp:51
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:103
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)
llvm::Value * EmitFP8NeonFDOTCall(unsigned IID, bool ExtendLaneArg, llvm::Type *RetTy, SmallVectorImpl< llvm::Value * > &Ops, const CallExpr *E, const char *name)
Definition ARM.cpp:458
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< FMVResolverOption > Options)
void EmitIfStmt(const IfStmt &S)
Definition CGStmt.cpp:881
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
Definition CGDecl.cpp:2135
void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
Definition CGObjC.cpp:2714
llvm::Value * vectorWrapScalar16(llvm::Value *Op)
Definition ARM.cpp:3724
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:2202
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
Definition CGExpr.cpp:6432
llvm::Value * EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
Definition ARM.cpp:3570
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:1387
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:3106
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...
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:2614
SmallVector< llvm::CanonicalLoopInfo *, 4 > OMPLoopNestStack
List of recently emitted OMPCanonicalLoops.
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Definition CGExpr.cpp:4309
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:2331
llvm::Value * EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, const llvm::CmpInst::Predicate Pred, const llvm::Twine &Name="")
Definition ARM.cpp:2442
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:3733
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:2133
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
Definition CGStmt.cpp:569
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 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:1613
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Definition CGDecl.cpp:2653
llvm::Instruction * getPostAllocaInsertPoint()
Return PostAllocaInsertPt.
RValue EmitBuiltinIsAligned(const CallExpr *E)
Emit IR for __builtin_is_aligned.
void EmitAllocToken(llvm::CallBase *CB, QualType AllocType)
Emit additional metadata used by the AllocToken instrumentation.
Definition CGExpr.cpp:1324
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:2179
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:5725
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:682
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
Definition CGExpr.cpp:508
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
Definition CGExpr.cpp:3130
void EmitAsmStmt(const AsmStmt &S)
Definition CGStmt.cpp:2775
void EmitDefaultStmt(const DefaultStmt &S, ArrayRef< const Attr * > Attrs)
Definition CGStmt.cpp:1984
void EmitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &S)
void EmitLambdaInAllocaCallOpBody(const CXXMethodDecl *MD)
Definition CGClass.cpp:3169
void EmitSwitchStmt(const SwitchStmt &S)
Definition CGStmt.cpp:2294
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.
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:3691
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:293
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:264
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:5080
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs={})
EmitStmt - Emit the code for the statement.
Definition CGStmt.cpp:61
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:353
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:1639
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:5917
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
Definition CGExpr.cpp:6404
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
Definition CGObjC.cpp:2337
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:1135
LValue EmitCallExprLValue(const CallExpr *E, llvm::CallBase **CallOrInvoke=nullptr)
Definition CGExpr.cpp:6338
llvm::Value * EmitARCRetainAutoreleaseNonBlock(llvm::Value *value)
Do a fused retain/autorelease of the given object.
Definition CGObjC.cpp:2628
llvm::Value * EmitSVEMovl(const SVETypeFlags &TypeFlags, llvm::ArrayRef< llvm::Value * > Ops, unsigned BuiltinID)
Definition ARM.cpp:4153
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:2460
void GenerateCXXGlobalCleanUpFunc(llvm::Function *Fn, ArrayRef< std::tuple< llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant * > > DtorsOrStermFinalizers)
GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global variables.
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits())
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:2724
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
Definition CGExpr.cpp:2488
RValue EmitAtomicExpr(AtomicExpr *E)
Definition CGAtomic.cpp:855
void GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCSetter - Synthesize an Objective-C property setter function for the given property.
Definition CGObjC.cpp:1672
llvm::Value * EmitARCLoadWeak(Address addr)
i8* @objc_loadWeak(i8** addr) Essentially objc_autorelease(objc_loadWeakRetained(addr)).
Definition CGObjC.cpp:2636
void EmitOMPTargetDirective(const OMPTargetDirective &S)
void ExitSEHTryStmt(const SEHTryStmt &S)
void EmitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &S)
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Definition CGExpr.cpp:5245
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:3912
void markStmtMaybeUsed(const Stmt *S)
llvm::Value * EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition Hexagon.cpp:77
CodeGenTypes & getTypes() const
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:3276
llvm::Value * EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition X86.cpp:737
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:6410
llvm::Value * EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
Definition ARM.cpp:4160
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
void FlattenAccessAndTypeLValue(LValue LVal, SmallVectorImpl< LValue > &AccessList)
Definition CGExpr.cpp:6868
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:1563
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:1869
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:3833
void EmitOMPErrorDirective(const OMPErrorDirective &S)
void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, const RegionCodeGenTy &BodyGen, OMPTargetDataInfo &InputInfo)
void EmitBreakStmt(const BreakStmt &S)
Definition CGStmt.cpp:1755
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:4013
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:1205
void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S)
llvm::Value * EmitSMEZero(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Definition ARM.cpp:4339
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:3291
LValue EmitUnaryOpLValue(const UnaryOperator *E)
Definition CGExpr.cpp:3505
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:3993
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:1596
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:675
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:4087
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
Definition CGExpr.cpp:1677
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:2337
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:186
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
Definition CGExpr.cpp:3078
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:279
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
Definition CGExpr.cpp:5984
void EmitOMPParallelGenericLoopDirective(const OMPLoopDirective &S)
void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S)
RawAddress NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
Definition CGObjC.cpp:2160
SmallVector< llvm::Value *, 8 > ObjCEHValueStack
ObjCEHValueStack - Stack of Objective-C exception values, used for rethrows.
void EmitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &S)
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
Definition CGExpr.cpp:6382
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:4292
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:203
std::pair< bool, bool > getIsCounterPair(const Stmt *S) const
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:734
const BreakContinue * GetDestForLoopControlStmt(const LoopControlStmt &S)
Definition CGStmt.cpp:1741
Address EmitExtVectorElementLValue(LValue V)
Generates lvalue for partial ext_vector access.
Definition CGExpr.cpp:2572
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:323
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:4033
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:453
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,...
RValue EmitLoadOfExtVectorElementLValue(LValue V)
Definition CGExpr.cpp:2525
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:1654
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:4681
llvm::Value * EmitMatrixIndexExpr(const Expr *E)
Definition CGExpr.cpp:4849
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:1784
ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType)
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
Definition CGExpr.cpp:4294
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:4221
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:1616
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:2264
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:2524
static void EmitOMPTargetSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetSimdDirective &S)
Emit device code for the target simd directive.
llvm::Function * GenerateCapturedStmtFunction(const CapturedStmt &S)
Creates the outlined function for a CapturedStmt.
Definition CGStmt.cpp:3298
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:1228
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
llvm::Value * EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Definition NVPTX.cpp:414
llvm::Value * getArrayInitIndex()
Get the index of the current ArrayInitLoopExpr, if any.
void EmitDeclStmt(const DeclStmt &S)
Definition CGStmt.cpp:1731
void InitializeVTablePointer(const VPtr &vptr)
Initialize the vtable pointer of the given subobject.
Definition CGClass.cpp:2618
void EmitLabelStmt(const LabelStmt &S)
Definition CGStmt.cpp:778
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset)
Emit a type checked load from the given vtable.
Definition CGClass.cpp:3007
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
Definition CGExpr.cpp:4209
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:51
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
llvm::Value * EmitSVEAllTruePred(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3862
llvm::Value * EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty)
Definition ARM.cpp:4380
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:6367
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:5148
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:1945
void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr)
Produce the code to do a primitive release.
Definition CGObjC.cpp:2814
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:1712
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Store of global named registers are always calls to intrinsics.
Definition CGExpr.cpp:2920
void EmitAttributedStmt(const AttributedStmt &S)
Definition CGStmt.cpp:788
llvm::Value * EmitARCExtendBlockObject(const Expr *expr)
Definition CGObjC.cpp:3524
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:5978
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:2651
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:2990
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.
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S)
Definition CGObjC.cpp:1804
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:706
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:2734
void InitializeVTablePointers(const CXXRecordDecl *ClassDecl)
Definition CGClass.cpp:2738
llvm::Value * EmitObjCRetainNonBlock(llvm::Value *value, llvm::Type *returnType)
Retain the given object, with normal retain semantics.
Definition CGObjC.cpp:2858
void EmitARCCopyWeak(Address dst, Address src)
void @objc_copyWeak(i8** dest, i8** src) Disregards the current value in dest.
Definition CGObjC.cpp:2701
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...
void EmitIndirectGotoStmt(const IndirectGotoStmt &S)
Definition CGStmt.cpp:857
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:2431
llvm::Value * EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
void MaybeEmitDeferredVarDeclInit(const VarDecl *var)
Definition CGDecl.cpp:2074
void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope, llvm::AtomicOrdering &AO, llvm::SyncScope::ID &SSID)
Definition AMDGPU.cpp:209
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:1807
void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S)
llvm::ScalableVectorType * getSVEPredType(const SVETypeFlags &TypeFlags)
Definition ARM.cpp:3790
void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
Definition CGObjC.cpp:2707
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:1606
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:2167
void EmitCountedByBoundsChecking(const Expr *E, llvm::Value *Idx, Address Addr, QualType IdxTy, QualType ArrayTy, bool Accessed, bool FlexibleArray)
EmitCountedByBoundsChecking - If the array being accessed has a "counted_by" attribute,...
Definition CGExpr.cpp:4596
llvm::Value * EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy, QualType RTy)
Definition CGCall.cpp:3947
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:427
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:720
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:655
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:2092
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:4441
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
llvm::Value * EmitPointerAuthAuth(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
void EmitContinueStmt(const ContinueStmt &S)
Definition CGStmt.cpp:1768
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:375
LValue - This represents an lvalue references.
Definition CGValue.h:182
CharUnits getAlignment() const
Definition CGValue.h:343
static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Definition CGValue.h:432
QualType getType() const
Definition CGValue.h:291
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
A stack of loop information corresponding to loop nesting levels.
Definition CGLoopInfo.h:207
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:98
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:379
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition TargetInfo.h:47
The class detects jumps which bypass local variables declaration: goto L; int a; L:
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1720
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition ExprCXX.h:5257
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:1270
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:112
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3081
QualType getType() const
Definition Expr.h:144
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6498
Represents a member of a struct/union/class.
Definition Decl.h:3160
Represents a function declaration or definition.
Definition Decl.h:2000
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5266
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
const Decl * getDecl() const
Definition GlobalDecl.h:106
GotoStmt - This represents a direct goto.
Definition Stmt.h:2969
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7271
IfStmt - This represents an if/then/else.
Definition Stmt.h:2259
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3008
Describes an C or C++ initializer list.
Definition Expr.h:5233
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2146
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:4922
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2799
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3653
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:192
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:128
ObjCContainerDecl - Represents a container for method declarations.
Definition DeclObjC.h:948
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:308
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:409
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:2597
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition ExprObjC.h:1498
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:548
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:940
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:2805
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:504
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:454
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:52
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
Represents a parameter to a function.
Definition Decl.h:1790
Pointer-authentication qualifiers.
Definition TypeBase.h:152
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3328
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2005
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6690
A (possibly-)qualified type.
Definition TypeBase.h:937
The collection of all-type qualifiers we support.
Definition TypeBase.h:331
Represents a struct/union/class.
Definition Decl.h:4312
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4512
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:4529
Stmt - This represents one statement.
Definition Stmt.h:85
Likelihood
The likelihood of a branch being taken.
Definition Stmt.h:1415
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition Stmt.h:1417
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
Exposes information about the current target.
Definition TargetInfo.h:226
Represents a declaration of a type.
Definition Decl.h:3513
bool isReferenceType() const
Definition TypeBase.h:8555
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4891
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:2257
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition Decl.h:1262
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3966
Expr * getSizeExpr() const
Definition TypeBase.h:3980
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2697
#define bool
Definition gpuintrin.h:32
Defines the clang::TargetInfo interface.
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
Definition CGValue.h:141
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
Definition CGValue.h:154
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Definition CGValue.h:145
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:135
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.
The JSON file list parser is used to communicate input to InstallAPI.
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)
Expr * Cond
};
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:905
const FunctionProtoType * T
bool IsXLHSInRHSPart
True if UE has the first form and false if the second.
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:132
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:5870
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#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()
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.
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 void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP, llvm::BasicBlock &FiniBB, llvm::Function *Fn, ArrayRef< llvm::Value * > Args)
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.
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.
Helper class with most of the code for saving a value for a conditional expression cleanup.
llvm::PointerIntPair< llvm::Value *, 1, bool > saved_type
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