clang 19.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 "CGDebugInfo.h"
18#include "CGLoopInfo.h"
19#include "CGValue.h"
20#include "CodeGenModule.h"
21#include "CodeGenPGO.h"
22#include "EHScopeStack.h"
23#include "VarBypassDetector.h"
24#include "clang/AST/CharUnits.h"
26#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.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/ValueHandle.h"
43#include "llvm/Support/Debug.h"
44#include "llvm/Transforms/Utils/SanitizerStats.h"
45#include <optional>
46
47namespace llvm {
48class BasicBlock;
49class LLVMContext;
50class MDNode;
51class SwitchInst;
52class Twine;
53class Value;
54class CanonicalLoopInfo;
55}
56
57namespace clang {
58class ASTContext;
59class CXXDestructorDecl;
60class CXXForRangeStmt;
61class CXXTryStmt;
62class Decl;
63class LabelDecl;
64class FunctionDecl;
65class FunctionProtoType;
66class LabelStmt;
67class ObjCContainerDecl;
68class ObjCInterfaceDecl;
69class ObjCIvarDecl;
70class ObjCMethodDecl;
71class ObjCImplementationDecl;
72class ObjCPropertyImplDecl;
73class TargetInfo;
74class VarDecl;
75class ObjCForCollectionStmt;
76class ObjCAtTryStmt;
77class ObjCAtThrowStmt;
78class ObjCAtSynchronizedStmt;
79class ObjCAutoreleasePoolStmt;
80class OMPUseDevicePtrClause;
81class OMPUseDeviceAddrClause;
82class SVETypeFlags;
83class OMPExecutableDirective;
84
85namespace analyze_os_log {
86class OSLogBufferLayout;
87}
88
89namespace CodeGen {
90class CodeGenTypes;
91class CGCallee;
92class CGFunctionInfo;
93class CGBlockInfo;
94class CGCXXABI;
95class BlockByrefHelpers;
96class BlockByrefInfo;
97class BlockFieldFlags;
98class RegionCodeGenTy;
99class TargetCodeGenInfo;
100struct OMPTaskDataTy;
101struct CGCoroData;
102
103/// The kind of evaluation to perform on values of a particular
104/// type. Basically, is the code in CGExprScalar, CGExprComplex, or
105/// CGExprAgg?
106///
107/// TODO: should vectors maybe be split out into their own thing?
113
114#define LIST_SANITIZER_CHECKS \
115 SANITIZER_CHECK(AddOverflow, add_overflow, 0) \
116 SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0) \
117 SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0) \
118 SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0) \
119 SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0) \
120 SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0) \
121 SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0) \
122 SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0) \
123 SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0) \
124 SANITIZER_CHECK(InvalidObjCCast, invalid_objc_cast, 0) \
125 SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) \
126 SANITIZER_CHECK(MissingReturn, missing_return, 0) \
127 SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \
128 SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \
129 SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \
130 SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \
131 SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \
132 SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \
133 SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \
134 SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \
135 SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \
136 SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \
137 SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \
138 SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \
139 SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0)
140
142#define SANITIZER_CHECK(Enum, Name, Version) Enum,
144#undef SANITIZER_CHECK
146
147/// Helper class with most of the code for saving a value for a
148/// conditional expression cleanup.
150 typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type;
151
152 /// Answer whether the given value needs extra work to be saved.
153 static bool needsSaving(llvm::Value *value) {
154 if (!value)
155 return false;
156
157 // If it's not an instruction, we don't need to save.
158 if (!isa<llvm::Instruction>(value)) return false;
159
160 // If it's an instruction in the entry block, we don't need to save.
161 llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent();
162 return (block != &block->getParent()->getEntryBlock());
163 }
164
165 static saved_type save(CodeGenFunction &CGF, llvm::Value *value);
166 static llvm::Value *restore(CodeGenFunction &CGF, saved_type value);
167};
168
169/// A partial specialization of DominatingValue for llvm::Values that
170/// might be llvm::Instructions.
171template <class T> struct DominatingPointer<T,true> : DominatingLLVMValue {
172 typedef T *type;
174 return static_cast<T*>(DominatingLLVMValue::restore(CGF, value));
175 }
176};
177
178/// A specialization of DominatingValue for Address.
179template <> struct DominatingValue<Address> {
180 typedef Address type;
181
182 struct saved_type {
184 llvm::Type *ElementType;
187 llvm::PointerType *EffectiveType;
188 };
189
190 static bool needsSaving(type value) {
193 return true;
194 return false;
195 }
196 static saved_type save(CodeGenFunction &CGF, type value) {
197 return {DominatingLLVMValue::save(CGF, value.getBasePointer()),
198 value.getElementType(), value.getAlignment(),
199 DominatingLLVMValue::save(CGF, value.getOffset()), value.getType()};
200 }
202 return Address(DominatingLLVMValue::restore(CGF, value.BasePtr),
203 value.ElementType, value.Alignment,
204 DominatingLLVMValue::restore(CGF, value.Offset));
205 }
206};
207
208/// A specialization of DominatingValue for RValue.
209template <> struct DominatingValue<RValue> {
210 typedef RValue type;
212 enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral,
213 AggregateAddress, ComplexAddress };
214 union {
215 struct {
217 } Vals;
219 };
220 LLVM_PREFERRED_TYPE(Kind)
221 unsigned K : 3;
222 unsigned IsVolatile : 1;
223
225 : Vals{Val1, DominatingLLVMValue::saved_type()}, K(K) {}
226
229 : Vals{Val1, Val2}, K(ComplexAddress) {}
230
232 bool IsVolatile, unsigned K)
233 : AggregateAddr(AggregateAddr), K(K) {}
234
235 public:
236 static bool needsSaving(RValue value);
239
240 // implementations in CGCleanup.cpp
241 };
242
243 static bool needsSaving(type value) {
244 return saved_type::needsSaving(value);
245 }
246 static saved_type save(CodeGenFunction &CGF, type value) {
247 return saved_type::save(CGF, value);
248 }
250 return value.restore(CGF);
251 }
252};
253
254/// CodeGenFunction - This class organizes the per-function state that is used
255/// while generating LLVM code.
257 CodeGenFunction(const CodeGenFunction &) = delete;
258 void operator=(const CodeGenFunction &) = delete;
259
260 friend class CGCXXABI;
261public:
262 /// A jump destination is an abstract label, branching to which may
263 /// require a jump out through normal cleanups.
264 struct JumpDest {
265 JumpDest() : Block(nullptr), Index(0) {}
266 JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth,
267 unsigned Index)
268 : Block(Block), ScopeDepth(Depth), Index(Index) {}
269
270 bool isValid() const { return Block != nullptr; }
271 llvm::BasicBlock *getBlock() const { return Block; }
272 EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
273 unsigned getDestIndex() const { return Index; }
274
275 // This should be used cautiously.
277 ScopeDepth = depth;
278 }
279
280 private:
281 llvm::BasicBlock *Block;
283 unsigned Index;
284 };
285
286 CodeGenModule &CGM; // Per-module state.
288
289 // For EH/SEH outlined funclets, this field points to parent's CGF
291
292 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
295
296 // Stores variables for which we can't generate correct lifetime markers
297 // because of jumps.
299
300 /// List of recently emitted OMPCanonicalLoops.
301 ///
302 /// Since OMPCanonicalLoops are nested inside other statements (in particular
303 /// CapturedStmt generated by OMPExecutableDirective and non-perfectly nested
304 /// loops), we cannot directly call OMPEmitOMPCanonicalLoop and receive its
305 /// llvm::CanonicalLoopInfo. Instead, we call EmitStmt and any
306 /// OMPEmitOMPCanonicalLoop called by it will add its CanonicalLoopInfo to
307 /// this stack when done. Entering a new loop requires clearing this list; it
308 /// either means we start parsing a new loop nest (in which case the previous
309 /// loop nest goes out of scope) or a second loop in the same level in which
310 /// case it would be ambiguous into which of the two (or more) loops the loop
311 /// nest would extend.
313
314 /// Stack to track the Logical Operator recursion nest for MC/DC.
316
317 /// Number of nested loop to be consumed by the last surrounding
318 /// loop-associated directive.
320
321 // CodeGen lambda for loops and support for ordered clause
322 typedef llvm::function_ref<void(CodeGenFunction &, const OMPLoopDirective &,
323 JumpDest)>
325 typedef llvm::function_ref<void(CodeGenFunction &, SourceLocation,
326 const unsigned, const bool)>
328
329 // Codegen lambda for loop bounds in worksharing loop constructs
330 typedef llvm::function_ref<std::pair<LValue, LValue>(
333
334 // Codegen lambda for loop bounds in dispatch-based loop implementation
335 typedef llvm::function_ref<std::pair<llvm::Value *, llvm::Value *>(
337 Address UB)>
339
340 /// CGBuilder insert helper. This function is called after an
341 /// instruction is created using Builder.
342 void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
343 llvm::BasicBlock *BB,
344 llvm::BasicBlock::iterator InsertPt) const;
345
346 /// CurFuncDecl - Holds the Decl for the current outermost
347 /// non-closure context.
348 const Decl *CurFuncDecl = nullptr;
349 /// CurCodeDecl - This is the inner-most code context, which includes blocks.
350 const Decl *CurCodeDecl = nullptr;
351 const CGFunctionInfo *CurFnInfo = nullptr;
353 llvm::Function *CurFn = nullptr;
354
355 /// Save Parameter Decl for coroutine.
357
358 // Holds coroutine data if the current function is a coroutine. We use a
359 // wrapper to manage its lifetime, so that we don't have to define CGCoroData
360 // in this header.
361 struct CGCoroInfo {
362 std::unique_ptr<CGCoroData> Data;
363 bool InSuspendBlock = false;
364 CGCoroInfo();
365 ~CGCoroInfo();
366 };
368
369 bool isCoroutine() const {
370 return CurCoro.Data != nullptr;
371 }
372
373 bool inSuspendBlock() const {
375 }
376
377 // Holds FramePtr for await_suspend wrapper generation,
378 // so that __builtin_coro_frame call can be lowered
379 // directly to value of its second argument
381 llvm::Value *FramePtr = nullptr;
382 };
384
385 // Generates wrapper function for `llvm.coro.await.suspend.*` intrinisics.
386 // It encapsulates SuspendExpr in a function, to separate it's body
387 // from the main coroutine to avoid miscompilations. Intrinisic
388 // is lowered to this function call in CoroSplit pass
389 // Function signature is:
390 // <type> __await_suspend_wrapper_<name>(ptr %awaiter, ptr %hdl)
391 // where type is one of (void, i1, ptr)
392 llvm::Function *generateAwaitSuspendWrapper(Twine const &CoroName,
393 Twine const &SuspendPointName,
394 CoroutineSuspendExpr const &S);
395
396 /// CurGD - The GlobalDecl for the current function being compiled.
398
399 /// PrologueCleanupDepth - The cleanup depth enclosing all the
400 /// cleanups associated with the parameters.
402
403 /// ReturnBlock - Unified return block.
405
406 /// ReturnValue - The temporary alloca to hold the return
407 /// value. This is invalid iff the function has no return value.
409
410 /// ReturnValuePointer - The temporary alloca to hold a pointer to sret.
411 /// This is invalid if sret is not in use.
413
414 /// If a return statement is being visited, this holds the return statment's
415 /// result expression.
416 const Expr *RetExpr = nullptr;
417
418 /// Return true if a label was seen in the current scope.
420 if (CurLexicalScope)
421 return CurLexicalScope->hasLabels();
422 return !LabelMap.empty();
423 }
424
425 /// AllocaInsertPoint - This is an instruction in the entry block before which
426 /// we prefer to insert allocas.
427 llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
428
429private:
430 /// PostAllocaInsertPt - This is a place in the prologue where code can be
431 /// inserted that will be dominated by all the static allocas. This helps
432 /// achieve two things:
433 /// 1. Contiguity of all static allocas (within the prologue) is maintained.
434 /// 2. All other prologue code (which are dominated by static allocas) do
435 /// appear in the source order immediately after all static allocas.
436 ///
437 /// PostAllocaInsertPt will be lazily created when it is *really* required.
438 llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr;
439
440public:
441 /// Return PostAllocaInsertPt. If it is not yet created, then insert it
442 /// immediately after AllocaInsertPt.
443 llvm::Instruction *getPostAllocaInsertPoint() {
444 if (!PostAllocaInsertPt) {
445 assert(AllocaInsertPt &&
446 "Expected static alloca insertion point at function prologue");
447 assert(AllocaInsertPt->getParent()->isEntryBlock() &&
448 "EBB should be entry block of the current code gen function");
449 PostAllocaInsertPt = AllocaInsertPt->clone();
450 PostAllocaInsertPt->setName("postallocapt");
451 PostAllocaInsertPt->insertAfter(AllocaInsertPt);
452 }
453
454 return PostAllocaInsertPt;
455 }
456
457 /// API for captured statement code generation.
459 public:
461 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {}
464 : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {
465
467 S.getCapturedRecordDecl()->field_begin();
468 for (CapturedStmt::const_capture_iterator I = S.capture_begin(),
469 E = S.capture_end();
470 I != E; ++I, ++Field) {
471 if (I->capturesThis())
472 CXXThisFieldDecl = *Field;
473 else if (I->capturesVariable())
474 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
475 else if (I->capturesVariableByCopy())
476 CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
477 }
478 }
479
480 virtual ~CGCapturedStmtInfo();
481
482 CapturedRegionKind getKind() const { return Kind; }
483
484 virtual void setContextValue(llvm::Value *V) { ThisValue = V; }
485 // Retrieve the value of the context parameter.
486 virtual llvm::Value *getContextValue() const { return ThisValue; }
487
488 /// Lookup the captured field decl for a variable.
489 virtual const FieldDecl *lookup(const VarDecl *VD) const {
490 return CaptureFields.lookup(VD->getCanonicalDecl());
491 }
492
493 bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; }
494 virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; }
495
496 static bool classof(const CGCapturedStmtInfo *) {
497 return true;
498 }
499
500 /// Emit the captured statement body.
501 virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) {
503 CGF.EmitStmt(S);
504 }
505
506 /// Get the name of the capture helper.
507 virtual StringRef getHelperName() const { return "__captured_stmt"; }
508
509 /// Get the CaptureFields
510 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> getCaptureFields() {
511 return CaptureFields;
512 }
513
514 private:
515 /// The kind of captured statement being generated.
517
518 /// Keep the map between VarDecl and FieldDecl.
519 llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields;
520
521 /// The base address of the captured record, passed in as the first
522 /// argument of the parallel region function.
523 llvm::Value *ThisValue;
524
525 /// Captured 'this' type.
526 FieldDecl *CXXThisFieldDecl;
527 };
529
530 /// RAII for correct setting/restoring of CapturedStmtInfo.
532 private:
533 CodeGenFunction &CGF;
534 CGCapturedStmtInfo *PrevCapturedStmtInfo;
535 public:
537 CGCapturedStmtInfo *NewCapturedStmtInfo)
538 : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) {
539 CGF.CapturedStmtInfo = NewCapturedStmtInfo;
540 }
541 ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; }
542 };
543
544 /// An abstract representation of regular/ObjC call/message targets.
546 /// The function declaration of the callee.
547 const Decl *CalleeDecl;
548
549 public:
550 AbstractCallee() : CalleeDecl(nullptr) {}
551 AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {}
552 AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {}
553 bool hasFunctionDecl() const {
554 return isa_and_nonnull<FunctionDecl>(CalleeDecl);
555 }
556 const Decl *getDecl() const { return CalleeDecl; }
557 unsigned getNumParams() const {
558 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
559 return FD->getNumParams();
560 return cast<ObjCMethodDecl>(CalleeDecl)->param_size();
561 }
562 const ParmVarDecl *getParamDecl(unsigned I) const {
563 if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl))
564 return FD->getParamDecl(I);
565 return *(cast<ObjCMethodDecl>(CalleeDecl)->param_begin() + I);
566 }
567 };
568
569 /// Sanitizers enabled for this function.
571
572 /// True if CodeGen currently emits code implementing sanitizer checks.
573 bool IsSanitizerScope = false;
574
575 /// RAII object to set/unset CodeGenFunction::IsSanitizerScope.
577 CodeGenFunction *CGF;
578 public:
581 };
582
583 /// In C++, whether we are code generating a thunk. This controls whether we
584 /// should emit cleanups.
585 bool CurFuncIsThunk = false;
586
587 /// In ARC, whether we should autorelease the return value.
588 bool AutoreleaseResult = false;
589
590 /// Whether we processed a Microsoft-style asm block during CodeGen. These can
591 /// potentially set the return value.
592 bool SawAsmBlock = false;
593
595
596 /// True if the current function is an outlined SEH helper. This can be a
597 /// finally block or filter expression.
599
600 /// True if CodeGen currently emits code inside presereved access index
601 /// region.
603
604 /// True if the current statement has nomerge attribute.
606
607 /// True if the current statement has noinline attribute.
609
610 /// True if the current statement has always_inline attribute.
612
613 // The CallExpr within the current statement that the musttail attribute
614 // applies to. nullptr if there is no 'musttail' on the current statement.
615 const CallExpr *MustTailCall = nullptr;
616
617 /// Returns true if a function must make progress, which means the
618 /// mustprogress attribute can be added.
620 if (CGM.getCodeGenOpts().getFiniteLoops() ==
622 return false;
623
624 // C++11 and later guarantees that a thread eventually will do one of the
625 // following (C++11 [intro.multithread]p24 and C++17 [intro.progress]p1):
626 // - terminate,
627 // - make a call to a library I/O function,
628 // - perform an access through a volatile glvalue, or
629 // - perform a synchronization operation or an atomic operation.
630 //
631 // Hence each function is 'mustprogress' in C++11 or later.
632 return getLangOpts().CPlusPlus11;
633 }
634
635 /// Returns true if a loop must make progress, which means the mustprogress
636 /// attribute can be added. \p HasConstantCond indicates whether the branch
637 /// condition is a known constant.
638 bool checkIfLoopMustProgress(bool HasConstantCond) {
639 if (CGM.getCodeGenOpts().getFiniteLoops() ==
641 return true;
642 if (CGM.getCodeGenOpts().getFiniteLoops() ==
644 return false;
645
646 // If the containing function must make progress, loops also must make
647 // progress (as in C++11 and later).
649 return true;
650
651 // Now apply rules for plain C (see 6.8.5.6 in C11).
652 // Loops with constant conditions do not have to make progress in any C
653 // version.
654 if (HasConstantCond)
655 return false;
656
657 // Loops with non-constant conditions must make progress in C11 and later.
658 return getLangOpts().C11;
659 }
660
662 llvm::Value *BlockPointer = nullptr;
663
664 llvm::DenseMap<const ValueDecl *, FieldDecl *> LambdaCaptureFields;
666
667 /// A mapping from NRVO variables to the flags used to indicate
668 /// when the NRVO has been applied to this variable.
669 llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
670
674
675 llvm::Instruction *CurrentFuncletPad = nullptr;
676
678 bool isRedundantBeforeReturn() override { return true; }
679
680 llvm::Value *Addr;
681 llvm::Value *Size;
682
683 public:
684 CallLifetimeEnd(RawAddress addr, llvm::Value *size)
685 : Addr(addr.getPointer()), Size(size) {}
686
687 void Emit(CodeGenFunction &CGF, Flags flags) override {
688 CGF.EmitLifetimeEnd(Size, Addr);
689 }
690 };
691
692 /// Header for data within LifetimeExtendedCleanupStack.
694 /// The size of the following cleanup object.
695 unsigned Size;
696 /// The kind of cleanup to push.
697 LLVM_PREFERRED_TYPE(CleanupKind)
699 /// Whether this is a conditional cleanup.
700 LLVM_PREFERRED_TYPE(bool)
701 unsigned IsConditional : 1;
702
703 size_t getSize() const { return Size; }
704 CleanupKind getKind() const { return (CleanupKind)Kind; }
705 bool isConditional() const { return IsConditional; }
706 };
707
708 /// i32s containing the indexes of the cleanup destinations.
710
712
713 /// EHResumeBlock - Unified block containing a call to llvm.eh.resume.
714 llvm::BasicBlock *EHResumeBlock = nullptr;
715
716 /// The exception slot. All landing pads write the current exception pointer
717 /// into this alloca.
718 llvm::Value *ExceptionSlot = nullptr;
719
720 /// The selector slot. Under the MandatoryCleanup model, all landing pads
721 /// write the current selector value into this alloca.
722 llvm::AllocaInst *EHSelectorSlot = nullptr;
723
724 /// A stack of exception code slots. Entering an __except block pushes a slot
725 /// on the stack and leaving pops one. The __exception_code() intrinsic loads
726 /// a value from the top of the stack.
728
729 /// Value returned by __exception_info intrinsic.
730 llvm::Value *SEHInfo = nullptr;
731
732 /// Emits a landing pad for the current EH stack.
733 llvm::BasicBlock *EmitLandingPad();
734
735 llvm::BasicBlock *getInvokeDestImpl();
736
737 /// Parent loop-based directive for scan directive.
739 llvm::BasicBlock *OMPBeforeScanBlock = nullptr;
740 llvm::BasicBlock *OMPAfterScanBlock = nullptr;
741 llvm::BasicBlock *OMPScanExitBlock = nullptr;
742 llvm::BasicBlock *OMPScanDispatch = nullptr;
743 bool OMPFirstScanLoop = false;
744
745 /// Manages parent directive for scan directives.
747 CodeGenFunction &CGF;
748 const OMPExecutableDirective *ParentLoopDirectiveForScan;
749
750 public:
752 CodeGenFunction &CGF,
753 const OMPExecutableDirective &ParentLoopDirectiveForScan)
754 : CGF(CGF),
755 ParentLoopDirectiveForScan(CGF.OMPParentLoopDirectiveForScan) {
756 CGF.OMPParentLoopDirectiveForScan = &ParentLoopDirectiveForScan;
757 }
759 CGF.OMPParentLoopDirectiveForScan = ParentLoopDirectiveForScan;
760 }
761 };
762
763 template <class T>
765 return DominatingValue<T>::save(*this, value);
766 }
767
769 public:
770 CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures);
771 CGFPOptionsRAII(CodeGenFunction &CGF, const Expr *E);
773
774 private:
775 void ConstructorHelper(FPOptions FPFeatures);
776 CodeGenFunction &CGF;
777 FPOptions OldFPFeatures;
778 llvm::fp::ExceptionBehavior OldExcept;
779 llvm::RoundingMode OldRounding;
780 std::optional<CGBuilderTy::FastMathFlagGuard> FMFGuard;
781 };
783
784public:
785 /// ObjCEHValueStack - Stack of Objective-C exception values, used for
786 /// rethrows.
788
789 /// A class controlling the emission of a finally block.
791 /// Where the catchall's edge through the cleanup should go.
792 JumpDest RethrowDest;
793
794 /// A function to call to enter the catch.
795 llvm::FunctionCallee BeginCatchFn;
796
797 /// An i1 variable indicating whether or not the @finally is
798 /// running for an exception.
799 llvm::AllocaInst *ForEHVar = nullptr;
800
801 /// An i8* variable into which the exception pointer to rethrow
802 /// has been saved.
803 llvm::AllocaInst *SavedExnVar = nullptr;
804
805 public:
806 void enter(CodeGenFunction &CGF, const Stmt *Finally,
807 llvm::FunctionCallee beginCatchFn,
808 llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn);
809 void exit(CodeGenFunction &CGF);
810 };
811
812 /// Returns true inside SEH __try blocks.
813 bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); }
814
815 /// Returns true while emitting a cleanuppad.
816 bool isCleanupPadScope() const {
817 return CurrentFuncletPad && isa<llvm::CleanupPadInst>(CurrentFuncletPad);
818 }
819
820 /// pushFullExprCleanup - Push a cleanup to be run at the end of the
821 /// current full-expression. Safe against the possibility that
822 /// we're currently inside a conditionally-evaluated expression.
823 template <class T, class... As>
824 void pushFullExprCleanup(CleanupKind kind, As... A) {
825 // If we're not in a conditional branch, or if none of the
826 // arguments requires saving, then use the unconditional cleanup.
828 return EHStack.pushCleanup<T>(kind, A...);
829
830 // Stash values in a tuple so we can guarantee the order of saves.
831 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
832 SavedTuple Saved{saveValueInCond(A)...};
833
834 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
835 EHStack.pushCleanupTuple<CleanupType>(kind, Saved);
837 }
838
839 /// Queue a cleanup to be pushed after finishing the current full-expression,
840 /// potentially with an active flag.
841 template <class T, class... As>
844 return pushCleanupAfterFullExprWithActiveFlag<T>(
845 Kind, RawAddress::invalid(), A...);
846
847 RawAddress ActiveFlag = createCleanupActiveFlag();
848 assert(!DominatingValue<Address>::needsSaving(ActiveFlag) &&
849 "cleanup active flag should never need saving");
850
851 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
852 SavedTuple Saved{saveValueInCond(A)...};
853
854 typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType;
855 pushCleanupAfterFullExprWithActiveFlag<CleanupType>(Kind, ActiveFlag, Saved);
856 }
857
858 template <class T, class... As>
860 RawAddress ActiveFlag, As... A) {
861 LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind,
862 ActiveFlag.isValid()};
863
864 size_t OldSize = LifetimeExtendedCleanupStack.size();
866 LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size +
867 (Header.IsConditional ? sizeof(ActiveFlag) : 0));
868
869 static_assert(sizeof(Header) % alignof(T) == 0,
870 "Cleanup will be allocated on misaligned address");
871 char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
872 new (Buffer) LifetimeExtendedCleanupHeader(Header);
873 new (Buffer + sizeof(Header)) T(A...);
874 if (Header.IsConditional)
875 new (Buffer + sizeof(Header) + sizeof(T)) RawAddress(ActiveFlag);
876 }
877
878 /// Set up the last cleanup that was pushed as a conditional
879 /// full-expression cleanup.
882 }
883
886
887 /// PushDestructorCleanup - Push a cleanup to call the
888 /// complete-object destructor of an object of the given type at the
889 /// given address. Does nothing if T is not a C++ class type with a
890 /// non-trivial destructor.
892
893 /// PushDestructorCleanup - Push a cleanup to call the
894 /// complete-object variant of the given destructor on the object at
895 /// the given address.
897 Address Addr);
898
899 /// PopCleanupBlock - Will pop the cleanup entry on the stack and
900 /// process all branch fixups.
901 void PopCleanupBlock(bool FallThroughIsBranchThrough = false);
902
903 /// DeactivateCleanupBlock - Deactivates the given cleanup block.
904 /// The block cannot be reactivated. Pops it if it's the top of the
905 /// stack.
906 ///
907 /// \param DominatingIP - An instruction which is known to
908 /// dominate the current IP (if set) and which lies along
909 /// all paths of execution between the current IP and the
910 /// the point at which the cleanup comes into scope.
912 llvm::Instruction *DominatingIP);
913
914 /// ActivateCleanupBlock - Activates an initially-inactive cleanup.
915 /// Cannot be used to resurrect a deactivated cleanup.
916 ///
917 /// \param DominatingIP - An instruction which is known to
918 /// dominate the current IP (if set) and which lies along
919 /// all paths of execution between the current IP and the
920 /// the point at which the cleanup comes into scope.
922 llvm::Instruction *DominatingIP);
923
924 /// Enters a new scope for capturing cleanups, all of which
925 /// will be executed once the scope is exited.
927 EHScopeStack::stable_iterator CleanupStackDepth, OldCleanupScopeDepth;
928 size_t LifetimeExtendedCleanupStackSize;
929 bool OldDidCallStackSave;
930 protected:
932 private:
933
934 RunCleanupsScope(const RunCleanupsScope &) = delete;
935 void operator=(const RunCleanupsScope &) = delete;
936
937 protected:
939
940 public:
941 /// Enter a new cleanup scope.
944 {
945 CleanupStackDepth = CGF.EHStack.stable_begin();
946 LifetimeExtendedCleanupStackSize =
948 OldDidCallStackSave = CGF.DidCallStackSave;
949 CGF.DidCallStackSave = false;
950 OldCleanupScopeDepth = CGF.CurrentCleanupScopeDepth;
951 CGF.CurrentCleanupScopeDepth = CleanupStackDepth;
952 }
953
954 /// Exit this cleanup scope, emitting any accumulated cleanups.
956 if (PerformCleanup)
957 ForceCleanup();
958 }
959
960 /// Determine whether this scope requires any cleanups.
961 bool requiresCleanups() const {
962 return CGF.EHStack.stable_begin() != CleanupStackDepth;
963 }
964
965 /// Force the emission of cleanups now, instead of waiting
966 /// until this object is destroyed.
967 /// \param ValuesToReload - A list of values that need to be available at
968 /// the insertion point after cleanup emission. If cleanup emission created
969 /// a shared cleanup block, these value pointers will be rewritten.
970 /// Otherwise, they not will be modified.
971 void ForceCleanup(std::initializer_list<llvm::Value**> ValuesToReload = {}) {
972 assert(PerformCleanup && "Already forced cleanup");
973 CGF.DidCallStackSave = OldDidCallStackSave;
974 CGF.PopCleanupBlocks(CleanupStackDepth, LifetimeExtendedCleanupStackSize,
975 ValuesToReload);
976 PerformCleanup = false;
977 CGF.CurrentCleanupScopeDepth = OldCleanupScopeDepth;
978 }
979 };
980
981 // Cleanup stack depth of the RunCleanupsScope that was pushed most recently.
984
986 SourceRange Range;
988 LexicalScope *ParentScope;
989
990 LexicalScope(const LexicalScope &) = delete;
991 void operator=(const LexicalScope &) = delete;
992
993 public:
994 /// Enter a new cleanup scope.
996 : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) {
997 CGF.CurLexicalScope = this;
998 if (CGDebugInfo *DI = CGF.getDebugInfo())
999 DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
1000 }
1001
1002 void addLabel(const LabelDecl *label) {
1003 assert(PerformCleanup && "adding label to dead scope?");
1004 Labels.push_back(label);
1005 }
1006
1007 /// Exit this cleanup scope, emitting any accumulated
1008 /// cleanups.
1010 if (CGDebugInfo *DI = CGF.getDebugInfo())
1011 DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
1012
1013 // If we should perform a cleanup, force them now. Note that
1014 // this ends the cleanup scope before rescoping any labels.
1015 if (PerformCleanup) {
1016 ApplyDebugLocation DL(CGF, Range.getEnd());
1017 ForceCleanup();
1018 }
1019 }
1020
1021 /// Force the emission of cleanups now, instead of waiting
1022 /// until this object is destroyed.
1024 CGF.CurLexicalScope = ParentScope;
1026
1027 if (!Labels.empty())
1028 rescopeLabels();
1029 }
1030
1031 bool hasLabels() const {
1032 return !Labels.empty();
1033 }
1034
1035 void rescopeLabels();
1036 };
1037
1038 typedef llvm::DenseMap<const Decl *, Address> DeclMapTy;
1039
1040 /// The class used to assign some variables some temporarily addresses.
1042 DeclMapTy SavedLocals;
1043 DeclMapTy SavedTempAddresses;
1044 OMPMapVars(const OMPMapVars &) = delete;
1045 void operator=(const OMPMapVars &) = delete;
1046
1047 public:
1048 explicit OMPMapVars() = default;
1050 assert(SavedLocals.empty() && "Did not restored original addresses.");
1051 };
1052
1053 /// Sets the address of the variable \p LocalVD to be \p TempAddr in
1054 /// function \p CGF.
1055 /// \return true if at least one variable was set already, false otherwise.
1056 bool setVarAddr(CodeGenFunction &CGF, const VarDecl *LocalVD,
1057 Address TempAddr) {
1058 LocalVD = LocalVD->getCanonicalDecl();
1059 // Only save it once.
1060 if (SavedLocals.count(LocalVD)) return false;
1061
1062 // Copy the existing local entry to SavedLocals.
1063 auto it = CGF.LocalDeclMap.find(LocalVD);
1064 if (it != CGF.LocalDeclMap.end())
1065 SavedLocals.try_emplace(LocalVD, it->second);
1066 else
1067 SavedLocals.try_emplace(LocalVD, Address::invalid());
1068
1069 // Generate the private entry.
1070 QualType VarTy = LocalVD->getType();
1071 if (VarTy->isReferenceType()) {
1072 Address Temp = CGF.CreateMemTemp(VarTy);
1073 CGF.Builder.CreateStore(TempAddr.emitRawPointer(CGF), Temp);
1074 TempAddr = Temp;
1075 }
1076 SavedTempAddresses.try_emplace(LocalVD, TempAddr);
1077
1078 return true;
1079 }
1080
1081 /// Applies new addresses to the list of the variables.
1082 /// \return true if at least one variable is using new address, false
1083 /// otherwise.
1085 copyInto(SavedTempAddresses, CGF.LocalDeclMap);
1086 SavedTempAddresses.clear();
1087 return !SavedLocals.empty();
1088 }
1089
1090 /// Restores original addresses of the variables.
1092 if (!SavedLocals.empty()) {
1093 copyInto(SavedLocals, CGF.LocalDeclMap);
1094 SavedLocals.clear();
1095 }
1096 }
1097
1098 private:
1099 /// Copy all the entries in the source map over the corresponding
1100 /// entries in the destination, which must exist.
1101 static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) {
1102 for (auto &Pair : Src) {
1103 if (!Pair.second.isValid()) {
1104 Dest.erase(Pair.first);
1105 continue;
1106 }
1107
1108 auto I = Dest.find(Pair.first);
1109 if (I != Dest.end())
1110 I->second = Pair.second;
1111 else
1112 Dest.insert(Pair);
1113 }
1114 }
1115 };
1116
1117 /// The scope used to remap some variables as private in the OpenMP loop body
1118 /// (or other captured region emitted without outlining), and to restore old
1119 /// vars back on exit.
1121 OMPMapVars MappedVars;
1122 OMPPrivateScope(const OMPPrivateScope &) = delete;
1123 void operator=(const OMPPrivateScope &) = delete;
1124
1125 public:
1126 /// Enter a new OpenMP private scope.
1128
1129 /// Registers \p LocalVD variable as a private with \p Addr as the address
1130 /// of the corresponding private variable. \p
1131 /// PrivateGen is the address of the generated private variable.
1132 /// \return true if the variable is registered as private, false if it has
1133 /// been privatized already.
1134 bool addPrivate(const VarDecl *LocalVD, Address Addr) {
1135 assert(PerformCleanup && "adding private to dead scope");
1136 return MappedVars.setVarAddr(CGF, LocalVD, Addr);
1137 }
1138
1139 /// Privatizes local variables previously registered as private.
1140 /// Registration is separate from the actual privatization to allow
1141 /// initializers use values of the original variables, not the private one.
1142 /// This is important, for example, if the private variable is a class
1143 /// variable initialized by a constructor that references other private
1144 /// variables. But at initialization original variables must be used, not
1145 /// private copies.
1146 /// \return true if at least one variable was privatized, false otherwise.
1147 bool Privatize() { return MappedVars.apply(CGF); }
1148
1151 restoreMap();
1152 }
1153
1154 /// Exit scope - all the mapped variables are restored.
1156 if (PerformCleanup)
1157 ForceCleanup();
1158 }
1159
1160 /// Checks if the global variable is captured in current function.
1161 bool isGlobalVarCaptured(const VarDecl *VD) const {
1162 VD = VD->getCanonicalDecl();
1163 return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0;
1164 }
1165
1166 /// Restore all mapped variables w/o clean up. This is usefully when we want
1167 /// to reference the original variables but don't want the clean up because
1168 /// that could emit lifetime end too early, causing backend issue #56913.
1169 void restoreMap() { MappedVars.restore(CGF); }
1170 };
1171
1172 /// Save/restore original map of previously emitted local vars in case when we
1173 /// need to duplicate emission of the same code several times in the same
1174 /// function for OpenMP code.
1176 CodeGenFunction &CGF;
1177 DeclMapTy SavedMap;
1178
1179 public:
1181 : CGF(CGF), SavedMap(CGF.LocalDeclMap) {}
1182 ~OMPLocalDeclMapRAII() { SavedMap.swap(CGF.LocalDeclMap); }
1183 };
1184
1185 /// Takes the old cleanup stack size and emits the cleanup blocks
1186 /// that have been added.
1187 void
1189 std::initializer_list<llvm::Value **> ValuesToReload = {});
1190
1191 /// Takes the old cleanup stack size and emits the cleanup blocks
1192 /// that have been added, then adds all lifetime-extended cleanups from
1193 /// the given position to the stack.
1194 void
1196 size_t OldLifetimeExtendedStackSize,
1197 std::initializer_list<llvm::Value **> ValuesToReload = {});
1198
1199 void ResolveBranchFixups(llvm::BasicBlock *Target);
1200
1201 /// The given basic block lies in the current EH scope, but may be a
1202 /// target of a potentially scope-crossing jump; get a stable handle
1203 /// to which we can perform this jump later.
1205 return JumpDest(Target,
1208 }
1209
1210 /// The given basic block lies in the current EH scope, but may be a
1211 /// target of a potentially scope-crossing jump; get a stable handle
1212 /// to which we can perform this jump later.
1213 JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) {
1215 }
1216
1217 /// EmitBranchThroughCleanup - Emit a branch from the current insert
1218 /// block through the normal cleanup handling code (if any) and then
1219 /// on to \arg Dest.
1221
1222 /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
1223 /// specified destination obviously has no cleanups to run. 'false' is always
1224 /// a conservatively correct answer for this method.
1226
1227 /// popCatchScope - Pops the catch scope at the top of the EHScope
1228 /// stack, emitting any required code (other than the catch handlers
1229 /// themselves).
1231
1232 llvm::BasicBlock *getEHResumeBlock(bool isCleanup);
1234 llvm::BasicBlock *
1236
1237 /// An object to manage conditionally-evaluated expressions.
1239 llvm::BasicBlock *StartBB;
1240
1241 public:
1243 : StartBB(CGF.Builder.GetInsertBlock()) {}
1244
1246 assert(CGF.OutermostConditional != this);
1247 if (!CGF.OutermostConditional)
1248 CGF.OutermostConditional = this;
1249 }
1250
1252 assert(CGF.OutermostConditional != nullptr);
1253 if (CGF.OutermostConditional == this)
1254 CGF.OutermostConditional = nullptr;
1255 }
1256
1257 /// Returns a block which will be executed prior to each
1258 /// evaluation of the conditional code.
1259 llvm::BasicBlock *getStartingBlock() const {
1260 return StartBB;
1261 }
1262 };
1263
1264 /// isInConditionalBranch - Return true if we're currently emitting
1265 /// one branch or the other of a conditional expression.
1266 bool isInConditionalBranch() const { return OutermostConditional != nullptr; }
1267
1268 void setBeforeOutermostConditional(llvm::Value *value, Address addr,
1269 CodeGenFunction &CGF) {
1270 assert(isInConditionalBranch());
1271 llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
1272 auto store =
1273 new llvm::StoreInst(value, addr.emitRawPointer(CGF), &block->back());
1274 store->setAlignment(addr.getAlignment().getAsAlign());
1275 }
1276
1277 /// An RAII object to record that we're evaluating a statement
1278 /// expression.
1280 CodeGenFunction &CGF;
1281
1282 /// We have to save the outermost conditional: cleanups in a
1283 /// statement expression aren't conditional just because the
1284 /// StmtExpr is.
1285 ConditionalEvaluation *SavedOutermostConditional;
1286
1287 public:
1289 : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) {
1290 CGF.OutermostConditional = nullptr;
1291 }
1292
1294 CGF.OutermostConditional = SavedOutermostConditional;
1295 CGF.EnsureInsertPoint();
1296 }
1297 };
1298
1299 /// An object which temporarily prevents a value from being
1300 /// destroyed by aggressive peephole optimizations that assume that
1301 /// all uses of a value have been realized in the IR.
1303 llvm::Instruction *Inst = nullptr;
1304 friend class CodeGenFunction;
1305
1306 public:
1308 };
1309
1310 /// A non-RAII class containing all the information about a bound
1311 /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
1312 /// this which makes individual mappings very simple; using this
1313 /// class directly is useful when you have a variable number of
1314 /// opaque values or don't want the RAII functionality for some
1315 /// reason.
1317 const OpaqueValueExpr *OpaqueValue;
1318 bool BoundLValue;
1320
1322 bool boundLValue)
1323 : OpaqueValue(ov), BoundLValue(boundLValue) {}
1324 public:
1325 OpaqueValueMappingData() : OpaqueValue(nullptr) {}
1326
1327 static bool shouldBindAsLValue(const Expr *expr) {
1328 // gl-values should be bound as l-values for obvious reasons.
1329 // Records should be bound as l-values because IR generation
1330 // always keeps them in memory. Expressions of function type
1331 // act exactly like l-values but are formally required to be
1332 // r-values in C.
1333 return expr->isGLValue() ||
1334 expr->getType()->isFunctionType() ||
1335 hasAggregateEvaluationKind(expr->getType());
1336 }
1337
1339 const OpaqueValueExpr *ov,
1340 const Expr *e) {
1341 if (shouldBindAsLValue(ov))
1342 return bind(CGF, ov, CGF.EmitLValue(e));
1343 return bind(CGF, ov, CGF.EmitAnyExpr(e));
1344 }
1345
1347 const OpaqueValueExpr *ov,
1348 const LValue &lv) {
1349 assert(shouldBindAsLValue(ov));
1350 CGF.OpaqueLValues.insert(std::make_pair(ov, lv));
1351 return OpaqueValueMappingData(ov, true);
1352 }
1353
1355 const OpaqueValueExpr *ov,
1356 const RValue &rv) {
1357 assert(!shouldBindAsLValue(ov));
1358 CGF.OpaqueRValues.insert(std::make_pair(ov, rv));
1359
1360 OpaqueValueMappingData data(ov, false);
1361
1362 // Work around an extremely aggressive peephole optimization in
1363 // EmitScalarConversion which assumes that all other uses of a
1364 // value are extant.
1365 data.Protection = CGF.protectFromPeepholes(rv);
1366
1367 return data;
1368 }
1369
1370 bool isValid() const { return OpaqueValue != nullptr; }
1371 void clear() { OpaqueValue = nullptr; }
1372
1374 assert(OpaqueValue && "no data to unbind!");
1375
1376 if (BoundLValue) {
1377 CGF.OpaqueLValues.erase(OpaqueValue);
1378 } else {
1379 CGF.OpaqueRValues.erase(OpaqueValue);
1380 CGF.unprotectFromPeepholes(Protection);
1381 }
1382 }
1383 };
1384
1385 /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
1387 CodeGenFunction &CGF;
1389
1390 public:
1391 static bool shouldBindAsLValue(const Expr *expr) {
1393 }
1394
1395 /// Build the opaque value mapping for the given conditional
1396 /// operator if it's the GNU ?: extension. This is a common
1397 /// enough pattern that the convenience operator is really
1398 /// helpful.
1399 ///
1401 const AbstractConditionalOperator *op) : CGF(CGF) {
1402 if (isa<ConditionalOperator>(op))
1403 // Leave Data empty.
1404 return;
1405
1406 const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op);
1408 e->getCommon());
1409 }
1410
1411 /// Build the opaque value mapping for an OpaqueValueExpr whose source
1412 /// expression is set to the expression the OVE represents.
1414 : CGF(CGF) {
1415 if (OV) {
1416 assert(OV->getSourceExpr() && "wrong form of OpaqueValueMapping used "
1417 "for OVE with no source expression");
1419 }
1420 }
1421
1423 const OpaqueValueExpr *opaqueValue,
1424 LValue lvalue)
1425 : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {
1426 }
1427
1429 const OpaqueValueExpr *opaqueValue,
1430 RValue rvalue)
1431 : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {
1432 }
1433
1434 void pop() {
1435 Data.unbind(CGF);
1436 Data.clear();
1437 }
1438
1440 if (Data.isValid()) Data.unbind(CGF);
1441 }
1442 };
1443
1444private:
1445 CGDebugInfo *DebugInfo;
1446 /// Used to create unique names for artificial VLA size debug info variables.
1447 unsigned VLAExprCounter = 0;
1448 bool DisableDebugInfo = false;
1449
1450 /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
1451 /// calling llvm.stacksave for multiple VLAs in the same scope.
1452 bool DidCallStackSave = false;
1453
1454 /// IndirectBranch - The first time an indirect goto is seen we create a block
1455 /// with an indirect branch. Every time we see the address of a label taken,
1456 /// we add the label to the indirect goto. Every subsequent indirect goto is
1457 /// codegen'd as a jump to the IndirectBranch's basic block.
1458 llvm::IndirectBrInst *IndirectBranch = nullptr;
1459
1460 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1461 /// decls.
1462 DeclMapTy LocalDeclMap;
1463
1464 // Keep track of the cleanups for callee-destructed parameters pushed to the
1465 // cleanup stack so that they can be deactivated later.
1466 llvm::DenseMap<const ParmVarDecl *, EHScopeStack::stable_iterator>
1467 CalleeDestructedParamCleanups;
1468
1469 /// SizeArguments - If a ParmVarDecl had the pass_object_size attribute, this
1470 /// will contain a mapping from said ParmVarDecl to its implicit "object_size"
1471 /// parameter.
1472 llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2>
1473 SizeArguments;
1474
1475 /// Track escaped local variables with auto storage. Used during SEH
1476 /// outlining to produce a call to llvm.localescape.
1477 llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals;
1478
1479 /// LabelMap - This keeps track of the LLVM basic block for each C label.
1480 llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap;
1481
1482 // BreakContinueStack - This keeps track of where break and continue
1483 // statements should jump to.
1484 struct BreakContinue {
1485 BreakContinue(JumpDest Break, JumpDest Continue)
1486 : BreakBlock(Break), ContinueBlock(Continue) {}
1487
1488 JumpDest BreakBlock;
1489 JumpDest ContinueBlock;
1490 };
1491 SmallVector<BreakContinue, 8> BreakContinueStack;
1492
1493 /// Handles cancellation exit points in OpenMP-related constructs.
1494 class OpenMPCancelExitStack {
1495 /// Tracks cancellation exit point and join point for cancel-related exit
1496 /// and normal exit.
1497 struct CancelExit {
1498 CancelExit() = default;
1499 CancelExit(OpenMPDirectiveKind Kind, JumpDest ExitBlock,
1500 JumpDest ContBlock)
1501 : Kind(Kind), ExitBlock(ExitBlock), ContBlock(ContBlock) {}
1502 OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown;
1503 /// true if the exit block has been emitted already by the special
1504 /// emitExit() call, false if the default codegen is used.
1505 bool HasBeenEmitted = false;
1506 JumpDest ExitBlock;
1507 JumpDest ContBlock;
1508 };
1509
1510 SmallVector<CancelExit, 8> Stack;
1511
1512 public:
1513 OpenMPCancelExitStack() : Stack(1) {}
1514 ~OpenMPCancelExitStack() = default;
1515 /// Fetches the exit block for the current OpenMP construct.
1516 JumpDest getExitBlock() const { return Stack.back().ExitBlock; }
1517 /// Emits exit block with special codegen procedure specific for the related
1518 /// OpenMP construct + emits code for normal construct cleanup.
1519 void emitExit(CodeGenFunction &CGF, OpenMPDirectiveKind Kind,
1520 const llvm::function_ref<void(CodeGenFunction &)> CodeGen) {
1521 if (Stack.back().Kind == Kind && getExitBlock().isValid()) {
1522 assert(CGF.getOMPCancelDestination(Kind).isValid());
1523 assert(CGF.HaveInsertPoint());
1524 assert(!Stack.back().HasBeenEmitted);
1525 auto IP = CGF.Builder.saveAndClearIP();
1526 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1527 CodeGen(CGF);
1528 CGF.EmitBranch(Stack.back().ContBlock.getBlock());
1529 CGF.Builder.restoreIP(IP);
1530 Stack.back().HasBeenEmitted = true;
1531 }
1532 CodeGen(CGF);
1533 }
1534 /// Enter the cancel supporting \a Kind construct.
1535 /// \param Kind OpenMP directive that supports cancel constructs.
1536 /// \param HasCancel true, if the construct has inner cancel directive,
1537 /// false otherwise.
1538 void enter(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel) {
1539 Stack.push_back({Kind,
1540 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.exit")
1541 : JumpDest(),
1542 HasCancel ? CGF.getJumpDestInCurrentScope("cancel.cont")
1543 : JumpDest()});
1544 }
1545 /// Emits default exit point for the cancel construct (if the special one
1546 /// has not be used) + join point for cancel/normal exits.
1547 void exit(CodeGenFunction &CGF) {
1548 if (getExitBlock().isValid()) {
1549 assert(CGF.getOMPCancelDestination(Stack.back().Kind).isValid());
1550 bool HaveIP = CGF.HaveInsertPoint();
1551 if (!Stack.back().HasBeenEmitted) {
1552 if (HaveIP)
1553 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1554 CGF.EmitBlock(Stack.back().ExitBlock.getBlock());
1555 CGF.EmitBranchThroughCleanup(Stack.back().ContBlock);
1556 }
1557 CGF.EmitBlock(Stack.back().ContBlock.getBlock());
1558 if (!HaveIP) {
1559 CGF.Builder.CreateUnreachable();
1560 CGF.Builder.ClearInsertionPoint();
1561 }
1562 }
1563 Stack.pop_back();
1564 }
1565 };
1566 OpenMPCancelExitStack OMPCancelStack;
1567
1568 /// Lower the Likelihood knowledge about the \p Cond via llvm.expect intrin.
1569 llvm::Value *emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond,
1570 Stmt::Likelihood LH);
1571
1572 CodeGenPGO PGO;
1573
1574 /// Bitmap used by MC/DC to track condition outcomes of a boolean expression.
1575 Address MCDCCondBitmapAddr = Address::invalid();
1576
1577 /// Calculate branch weights appropriate for PGO data
1578 llvm::MDNode *createProfileWeights(uint64_t TrueCount,
1579 uint64_t FalseCount) const;
1580 llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights) const;
1581 llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond,
1582 uint64_t LoopCount) const;
1583
1584public:
1585 /// Increment the profiler's counter for the given statement by \p StepV.
1586 /// If \p StepV is null, the default increment is 1.
1587 void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) {
1589 !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
1590 !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile))
1591 PGO.emitCounterSetOrIncrement(Builder, S, StepV);
1592 PGO.setCurrentStmt(S);
1593 }
1594
1597 CGM.getCodeGenOpts().MCDCCoverage &&
1598 !CurFn->hasFnAttribute(llvm::Attribute::NoProfile));
1599 }
1600
1601 /// Allocate a temp value on the stack that MCDC can use to track condition
1602 /// results.
1604 if (isMCDCCoverageEnabled()) {
1605 PGO.emitMCDCParameters(Builder);
1606 MCDCCondBitmapAddr =
1607 CreateIRTemp(getContext().UnsignedIntTy, "mcdc.addr");
1608 }
1609 }
1610
1611 bool isBinaryLogicalOp(const Expr *E) const {
1612 const BinaryOperator *BOp = dyn_cast<BinaryOperator>(E->IgnoreParens());
1613 return (BOp && BOp->isLogicalOp());
1614 }
1615
1616 /// Zero-init the MCDC temp value.
1619 PGO.emitMCDCCondBitmapReset(Builder, E, MCDCCondBitmapAddr);
1620 PGO.setCurrentStmt(E);
1621 }
1622 }
1623
1624 /// Increment the profiler's counter for the given expression by \p StepV.
1625 /// If \p StepV is null, the default increment is 1.
1628 PGO.emitMCDCTestVectorBitmapUpdate(Builder, E, MCDCCondBitmapAddr, *this);
1629 PGO.setCurrentStmt(E);
1630 }
1631 }
1632
1633 /// Update the MCDC temp value with the condition's evaluated result.
1634 void maybeUpdateMCDCCondBitmap(const Expr *E, llvm::Value *Val) {
1635 if (isMCDCCoverageEnabled()) {
1636 PGO.emitMCDCCondBitmapUpdate(Builder, E, MCDCCondBitmapAddr, Val, *this);
1637 PGO.setCurrentStmt(E);
1638 }
1639 }
1640
1641 /// Get the profiler's count for the given statement.
1642 uint64_t getProfileCount(const Stmt *S) {
1643 return PGO.getStmtCount(S).value_or(0);
1644 }
1645
1646 /// Set the profiler's current count.
1647 void setCurrentProfileCount(uint64_t Count) {
1648 PGO.setCurrentRegionCount(Count);
1649 }
1650
1651 /// Get the profiler's current count. This is generally the count for the most
1652 /// recently incremented counter.
1654 return PGO.getCurrentRegionCount();
1655 }
1656
1657private:
1658
1659 /// SwitchInsn - This is nearest current switch instruction. It is null if
1660 /// current context is not in a switch.
1661 llvm::SwitchInst *SwitchInsn = nullptr;
1662 /// The branch weights of SwitchInsn when doing instrumentation based PGO.
1663 SmallVector<uint64_t, 16> *SwitchWeights = nullptr;
1664
1665 /// The likelihood attributes of the SwitchCase.
1666 SmallVector<Stmt::Likelihood, 16> *SwitchLikelihood = nullptr;
1667
1668 /// CaseRangeBlock - This block holds if condition check for last case
1669 /// statement range in current switch instruction.
1670 llvm::BasicBlock *CaseRangeBlock = nullptr;
1671
1672 /// OpaqueLValues - Keeps track of the current set of opaque value
1673 /// expressions.
1674 llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
1675 llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;
1676
1677 // VLASizeMap - This keeps track of the associated size for each VLA type.
1678 // We track this by the size expression rather than the type itself because
1679 // in certain situations, like a const qualifier applied to an VLA typedef,
1680 // multiple VLA types can share the same size expression.
1681 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
1682 // enter/leave scopes.
1683 llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
1684
1685 /// A block containing a single 'unreachable' instruction. Created
1686 /// lazily by getUnreachableBlock().
1687 llvm::BasicBlock *UnreachableBlock = nullptr;
1688
1689 /// Counts of the number return expressions in the function.
1690 unsigned NumReturnExprs = 0;
1691
1692 /// Count the number of simple (constant) return expressions in the function.
1693 unsigned NumSimpleReturnExprs = 0;
1694
1695 /// The last regular (non-return) debug location (breakpoint) in the function.
1696 SourceLocation LastStopPoint;
1697
1698public:
1699 /// Source location information about the default argument or member
1700 /// initializer expression we're evaluating, if any.
1704
1705 /// A scope within which we are constructing the fields of an object which
1706 /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use
1707 /// if we need to evaluate a CXXDefaultInitExpr within the evaluation.
1709 public:
1711 : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) {
1712 CGF.CXXDefaultInitExprThis = This;
1713 }
1715 CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis;
1716 }
1717
1718 private:
1719 CodeGenFunction &CGF;
1720 Address OldCXXDefaultInitExprThis;
1721 };
1722
1723 /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
1724 /// is overridden to be the object under construction.
1726 public:
1728 : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue),
1729 OldCXXThisAlignment(CGF.CXXThisAlignment),
1731 CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getBasePointer();
1732 CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment();
1733 }
1735 CGF.CXXThisValue = OldCXXThisValue;
1736 CGF.CXXThisAlignment = OldCXXThisAlignment;
1737 }
1738
1739 public:
1741 llvm::Value *OldCXXThisValue;
1744 };
1745
1749 };
1750
1751 /// The scope of an ArrayInitLoopExpr. Within this scope, the value of the
1752 /// current loop index is overridden.
1754 public:
1755 ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index)
1756 : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) {
1757 CGF.ArrayInitIndex = Index;
1758 }
1760 CGF.ArrayInitIndex = OldArrayInitIndex;
1761 }
1762
1763 private:
1764 CodeGenFunction &CGF;
1765 llvm::Value *OldArrayInitIndex;
1766 };
1767
1769 public:
1771 : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl),
1772 OldCurCodeDecl(CGF.CurCodeDecl),
1773 OldCXXABIThisDecl(CGF.CXXABIThisDecl),
1774 OldCXXABIThisValue(CGF.CXXABIThisValue),
1775 OldCXXThisValue(CGF.CXXThisValue),
1776 OldCXXABIThisAlignment(CGF.CXXABIThisAlignment),
1777 OldCXXThisAlignment(CGF.CXXThisAlignment),
1778 OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy),
1779 OldCXXInheritedCtorInitExprArgs(
1780 std::move(CGF.CXXInheritedCtorInitExprArgs)) {
1781 CGF.CurGD = GD;
1782 CGF.CurFuncDecl = CGF.CurCodeDecl =
1783 cast<CXXConstructorDecl>(GD.getDecl());
1784 CGF.CXXABIThisDecl = nullptr;
1785 CGF.CXXABIThisValue = nullptr;
1786 CGF.CXXThisValue = nullptr;
1787 CGF.CXXABIThisAlignment = CharUnits();
1788 CGF.CXXThisAlignment = CharUnits();
1790 CGF.FnRetTy = QualType();
1791 CGF.CXXInheritedCtorInitExprArgs.clear();
1792 }
1794 CGF.CurGD = OldCurGD;
1795 CGF.CurFuncDecl = OldCurFuncDecl;
1796 CGF.CurCodeDecl = OldCurCodeDecl;
1797 CGF.CXXABIThisDecl = OldCXXABIThisDecl;
1798 CGF.CXXABIThisValue = OldCXXABIThisValue;
1799 CGF.CXXThisValue = OldCXXThisValue;
1800 CGF.CXXABIThisAlignment = OldCXXABIThisAlignment;
1801 CGF.CXXThisAlignment = OldCXXThisAlignment;
1802 CGF.ReturnValue = OldReturnValue;
1803 CGF.FnRetTy = OldFnRetTy;
1804 CGF.CXXInheritedCtorInitExprArgs =
1805 std::move(OldCXXInheritedCtorInitExprArgs);
1806 }
1807
1808 private:
1809 CodeGenFunction &CGF;
1810 GlobalDecl OldCurGD;
1811 const Decl *OldCurFuncDecl;
1812 const Decl *OldCurCodeDecl;
1813 ImplicitParamDecl *OldCXXABIThisDecl;
1814 llvm::Value *OldCXXABIThisValue;
1815 llvm::Value *OldCXXThisValue;
1816 CharUnits OldCXXABIThisAlignment;
1817 CharUnits OldCXXThisAlignment;
1818 Address OldReturnValue;
1819 QualType OldFnRetTy;
1820 CallArgList OldCXXInheritedCtorInitExprArgs;
1821 };
1822
1823 // Helper class for the OpenMP IR Builder. Allows reusability of code used for
1824 // region body, and finalization codegen callbacks. This will class will also
1825 // contain privatization functions used by the privatization call backs
1826 //
1827 // TODO: this is temporary class for things that are being moved out of
1828 // CGOpenMPRuntime, new versions of current CodeGenFunction methods, or
1829 // utility function for use with the OMPBuilder. Once that move to use the
1830 // OMPBuilder is done, everything here will either become part of CodeGenFunc.
1831 // directly, or a new helper class that will contain functions used by both
1832 // this and the OMPBuilder
1833
1835
1839
1840 using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
1841
1842 /// Cleanup action for allocate support.
1844
1845 private:
1846 llvm::CallInst *RTLFnCI;
1847
1848 public:
1849 OMPAllocateCleanupTy(llvm::CallInst *RLFnCI) : RTLFnCI(RLFnCI) {
1850 RLFnCI->removeFromParent();
1851 }
1852
1853 void Emit(CodeGenFunction &CGF, Flags /*flags*/) override {
1854 if (!CGF.HaveInsertPoint())
1855 return;
1856 CGF.Builder.Insert(RTLFnCI);
1857 }
1858 };
1859
1860 /// Returns address of the threadprivate variable for the current
1861 /// thread. This Also create any necessary OMP runtime calls.
1862 ///
1863 /// \param VD VarDecl for Threadprivate variable.
1864 /// \param VDAddr Address of the Vardecl
1865 /// \param Loc The location where the barrier directive was encountered
1867 const VarDecl *VD, Address VDAddr,
1868 SourceLocation Loc);
1869
1870 /// Gets the OpenMP-specific address of the local variable /p VD.
1872 const VarDecl *VD);
1873 /// Get the platform-specific name separator.
1874 /// \param Parts different parts of the final name that needs separation
1875 /// \param FirstSeparator First separator used between the initial two
1876 /// parts of the name.
1877 /// \param Separator separator used between all of the rest consecutinve
1878 /// parts of the name
1879 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
1880 StringRef FirstSeparator = ".",
1881 StringRef Separator = ".");
1882 /// Emit the Finalization for an OMP region
1883 /// \param CGF The Codegen function this belongs to
1884 /// \param IP Insertion point for generating the finalization code.
1886 CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
1887 assert(IP.getBlock()->end() != IP.getPoint() &&
1888 "OpenMP IR Builder should cause terminated block!");
1889
1890 llvm::BasicBlock *IPBB = IP.getBlock();
1891 llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
1892 assert(DestBB && "Finalization block should have one successor!");
1893
1894 // erase and replace with cleanup branch.
1895 IPBB->getTerminator()->eraseFromParent();
1896 CGF.Builder.SetInsertPoint(IPBB);
1898 CGF.EmitBranchThroughCleanup(Dest);
1899 }
1900
1901 /// Emit the body of an OMP region
1902 /// \param CGF The Codegen function this belongs to
1903 /// \param RegionBodyStmt The body statement for the OpenMP region being
1904 /// generated
1905 /// \param AllocaIP Where to insert alloca instructions
1906 /// \param CodeGenIP Where to insert the region code
1907 /// \param RegionName Name to be used for new blocks
1909 const Stmt *RegionBodyStmt,
1910 InsertPointTy AllocaIP,
1911 InsertPointTy CodeGenIP,
1912 Twine RegionName);
1913
1914 static void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP,
1915 llvm::BasicBlock &FiniBB, llvm::Function *Fn,
1917 llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
1918 if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminator())
1919 CodeGenIPBBTI->eraseFromParent();
1920
1921 CGF.Builder.SetInsertPoint(CodeGenIPBB);
1922
1923 if (Fn->doesNotThrow())
1924 CGF.EmitNounwindRuntimeCall(Fn, Args);
1925 else
1926 CGF.EmitRuntimeCall(Fn, Args);
1927
1928 if (CGF.Builder.saveIP().isSet())
1929 CGF.Builder.CreateBr(&FiniBB);
1930 }
1931
1932 /// Emit the body of an OMP region that will be outlined in
1933 /// OpenMPIRBuilder::finalize().
1934 /// \param CGF The Codegen function this belongs to
1935 /// \param RegionBodyStmt The body statement for the OpenMP region being
1936 /// generated
1937 /// \param AllocaIP Where to insert alloca instructions
1938 /// \param CodeGenIP Where to insert the region code
1939 /// \param RegionName Name to be used for new blocks
1941 const Stmt *RegionBodyStmt,
1942 InsertPointTy AllocaIP,
1943 InsertPointTy CodeGenIP,
1944 Twine RegionName);
1945
1946 /// RAII for preserving necessary info during Outlined region body codegen.
1948
1949 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
1950 CodeGenFunction::JumpDest OldReturnBlock;
1951 CodeGenFunction &CGF;
1952
1953 public:
1955 llvm::BasicBlock &RetBB)
1956 : CGF(cgf) {
1957 assert(AllocaIP.isSet() &&
1958 "Must specify Insertion point for allocas of outlined function");
1959 OldAllocaIP = CGF.AllocaInsertPt;
1960 CGF.AllocaInsertPt = &*AllocaIP.getPoint();
1961
1962 OldReturnBlock = CGF.ReturnBlock;
1963 CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
1964 }
1965
1967 CGF.AllocaInsertPt = OldAllocaIP;
1968 CGF.ReturnBlock = OldReturnBlock;
1969 }
1970 };
1971
1972 /// RAII for preserving necessary info during inlined region body codegen.
1974
1975 llvm::AssertingVH<llvm::Instruction> OldAllocaIP;
1976 CodeGenFunction &CGF;
1977
1978 public:
1980 llvm::BasicBlock &FiniBB)
1981 : CGF(cgf) {
1982 // Alloca insertion block should be in the entry block of the containing
1983 // function so it expects an empty AllocaIP in which case will reuse the
1984 // old alloca insertion point, or a new AllocaIP in the same block as
1985 // the old one
1986 assert((!AllocaIP.isSet() ||
1987 CGF.AllocaInsertPt->getParent() == AllocaIP.getBlock()) &&
1988 "Insertion point should be in the entry block of containing "
1989 "function!");
1990 OldAllocaIP = CGF.AllocaInsertPt;
1991 if (AllocaIP.isSet())
1992 CGF.AllocaInsertPt = &*AllocaIP.getPoint();
1993
1994 // TODO: Remove the call, after making sure the counter is not used by
1995 // the EHStack.
1996 // Since this is an inlined region, it should not modify the
1997 // ReturnBlock, and should reuse the one for the enclosing outlined
1998 // region. So, the JumpDest being return by the function is discarded
1999 (void)CGF.getJumpDestInCurrentScope(&FiniBB);
2000 }
2001
2003 };
2004 };
2005
2006private:
2007 /// CXXThisDecl - When generating code for a C++ member function,
2008 /// this will hold the implicit 'this' declaration.
2009 ImplicitParamDecl *CXXABIThisDecl = nullptr;
2010 llvm::Value *CXXABIThisValue = nullptr;
2011 llvm::Value *CXXThisValue = nullptr;
2012 CharUnits CXXABIThisAlignment;
2013 CharUnits CXXThisAlignment;
2014
2015 /// The value of 'this' to use when evaluating CXXDefaultInitExprs within
2016 /// this expression.
2017 Address CXXDefaultInitExprThis = Address::invalid();
2018
2019 /// The current array initialization index when evaluating an
2020 /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
2021 llvm::Value *ArrayInitIndex = nullptr;
2022
2023 /// The values of function arguments to use when evaluating
2024 /// CXXInheritedCtorInitExprs within this context.
2025 CallArgList CXXInheritedCtorInitExprArgs;
2026
2027 /// CXXStructorImplicitParamDecl - When generating code for a constructor or
2028 /// destructor, this will hold the implicit argument (e.g. VTT).
2029 ImplicitParamDecl *CXXStructorImplicitParamDecl = nullptr;
2030 llvm::Value *CXXStructorImplicitParamValue = nullptr;
2031
2032 /// OutermostConditional - Points to the outermost active
2033 /// conditional control. This is used so that we know if a
2034 /// temporary should be destroyed conditionally.
2035 ConditionalEvaluation *OutermostConditional = nullptr;
2036
2037 /// The current lexical scope.
2038 LexicalScope *CurLexicalScope = nullptr;
2039
2040 /// The current source location that should be used for exception
2041 /// handling code.
2042 SourceLocation CurEHLocation;
2043
2044 /// BlockByrefInfos - For each __block variable, contains
2045 /// information about the layout of the variable.
2046 llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos;
2047
2048 /// Used by -fsanitize=nullability-return to determine whether the return
2049 /// value can be checked.
2050 llvm::Value *RetValNullabilityPrecondition = nullptr;
2051
2052 /// Check if -fsanitize=nullability-return instrumentation is required for
2053 /// this function.
2054 bool requiresReturnValueNullabilityCheck() const {
2055 return RetValNullabilityPrecondition;
2056 }
2057
2058 /// Used to store precise source locations for return statements by the
2059 /// runtime return value checks.
2060 Address ReturnLocation = Address::invalid();
2061
2062 /// Check if the return value of this function requires sanitization.
2063 bool requiresReturnValueCheck() const;
2064
2065 bool isInAllocaArgument(CGCXXABI &ABI, QualType Ty);
2066 bool hasInAllocaArg(const CXXMethodDecl *MD);
2067
2068 llvm::BasicBlock *TerminateLandingPad = nullptr;
2069 llvm::BasicBlock *TerminateHandler = nullptr;
2071
2072 /// Terminate funclets keyed by parent funclet pad.
2073 llvm::MapVector<llvm::Value *, llvm::BasicBlock *> TerminateFunclets;
2074
2075 /// Largest vector width used in ths function. Will be used to create a
2076 /// function attribute.
2077 unsigned LargestVectorWidth = 0;
2078
2079 /// True if we need emit the life-time markers. This is initially set in
2080 /// the constructor, but could be overwritten to true if this is a coroutine.
2081 bool ShouldEmitLifetimeMarkers;
2082
2083 /// Add OpenCL kernel arg metadata and the kernel attribute metadata to
2084 /// the function metadata.
2085 void EmitKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn);
2086
2087public:
2088 CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false);
2090
2091 CodeGenTypes &getTypes() const { return CGM.getTypes(); }
2092 ASTContext &getContext() const { return CGM.getContext(); }
2094 if (DisableDebugInfo)
2095 return nullptr;
2096 return DebugInfo;
2097 }
2098 void disableDebugInfo() { DisableDebugInfo = true; }
2099 void enableDebugInfo() { DisableDebugInfo = false; }
2100
2102 return CGM.getCodeGenOpts().OptimizationLevel == 0;
2103 }
2104
2105 const LangOptions &getLangOpts() const { return CGM.getLangOpts(); }
2106
2107 /// Returns a pointer to the function's exception object and selector slot,
2108 /// which is assigned in every landing pad.
2111
2112 /// Returns the contents of the function's exception object and selector
2113 /// slots.
2114 llvm::Value *getExceptionFromSlot();
2115 llvm::Value *getSelectorFromSlot();
2116
2118
2119 llvm::BasicBlock *getUnreachableBlock() {
2120 if (!UnreachableBlock) {
2121 UnreachableBlock = createBasicBlock("unreachable");
2122 new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
2123 }
2124 return UnreachableBlock;
2125 }
2126
2127 llvm::BasicBlock *getInvokeDest() {
2128 if (!EHStack.requiresLandingPad()) return nullptr;
2129 return getInvokeDestImpl();
2130 }
2131
2132 bool currentFunctionUsesSEHTry() const { return !!CurSEHParent; }
2133
2134 const TargetInfo &getTarget() const { return Target; }
2135 llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); }
2137 return CGM.getTargetCodeGenInfo();
2138 }
2139
2140 //===--------------------------------------------------------------------===//
2141 // Cleanups
2142 //===--------------------------------------------------------------------===//
2143
2144 typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty);
2145
2146 void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin,
2147 Address arrayEndPointer,
2148 QualType elementType,
2149 CharUnits elementAlignment,
2150 Destroyer *destroyer);
2151 void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
2152 llvm::Value *arrayEnd,
2153 QualType elementType,
2154 CharUnits elementAlignment,
2155 Destroyer *destroyer);
2156
2158 Address addr, QualType type);
2160 Address addr, QualType type);
2162 Destroyer *destroyer, bool useEHCleanupForArray);
2164 QualType type, Destroyer *destroyer,
2165 bool useEHCleanupForArray);
2166 void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete,
2167 llvm::Value *CompletePtr,
2168 QualType ElementType);
2171 std::pair<llvm::Value *, llvm::Value *> AddrSizePair);
2173 bool useEHCleanupForArray);
2175 Destroyer *destroyer,
2176 bool useEHCleanupForArray,
2177 const VarDecl *VD);
2178 void emitArrayDestroy(llvm::Value *begin, llvm::Value *end,
2179 QualType elementType, CharUnits elementAlign,
2180 Destroyer *destroyer,
2181 bool checkZeroLength, bool useEHCleanup);
2182
2184
2185 /// Determines whether an EH cleanup is required to destroy a type
2186 /// with the given destruction kind.
2188 switch (kind) {
2189 case QualType::DK_none:
2190 return false;
2194 return getLangOpts().Exceptions;
2196 return getLangOpts().Exceptions &&
2197 CGM.getCodeGenOpts().ObjCAutoRefCountExceptions;
2198 }
2199 llvm_unreachable("bad destruction kind");
2200 }
2201
2204 }
2205
2206 //===--------------------------------------------------------------------===//
2207 // Objective-C
2208 //===--------------------------------------------------------------------===//
2209
2211
2213
2214 /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
2216 const ObjCPropertyImplDecl *PID);
2218 const ObjCPropertyImplDecl *propImpl,
2219 const ObjCMethodDecl *GetterMothodDecl,
2220 llvm::Constant *AtomicHelperFn);
2221
2223 ObjCMethodDecl *MD, bool ctor);
2224
2225 /// GenerateObjCSetter - Synthesize an Objective-C property setter function
2226 /// for the given property.
2228 const ObjCPropertyImplDecl *PID);
2230 const ObjCPropertyImplDecl *propImpl,
2231 llvm::Constant *AtomicHelperFn);
2232
2233 //===--------------------------------------------------------------------===//
2234 // Block Bits
2235 //===--------------------------------------------------------------------===//
2236
2237 /// Emit block literal.
2238 /// \return an LLVM value which is a pointer to a struct which contains
2239 /// information about the block, including the block invoke function, the
2240 /// captured variables, etc.
2241 llvm::Value *EmitBlockLiteral(const BlockExpr *);
2242
2244 const CGBlockInfo &Info,
2245 const DeclMapTy &ldm,
2246 bool IsLambdaConversionToBlock,
2247 bool BuildGlobalBlock);
2248
2249 /// Check if \p T is a C++ class that has a destructor that can throw.
2251
2252 llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo);
2253 llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo);
2255 const ObjCPropertyImplDecl *PID);
2257 const ObjCPropertyImplDecl *PID);
2258 llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
2259
2260 void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags,
2261 bool CanThrow);
2262
2263 class AutoVarEmission;
2264
2266
2267 /// Enter a cleanup to destroy a __block variable. Note that this
2268 /// cleanup should be a no-op if the variable hasn't left the stack
2269 /// yet; if a cleanup is required for the variable itself, that needs
2270 /// to be done externally.
2271 ///
2272 /// \param Kind Cleanup kind.
2273 ///
2274 /// \param Addr When \p LoadBlockVarAddr is false, the address of the __block
2275 /// structure that will be passed to _Block_object_dispose. When
2276 /// \p LoadBlockVarAddr is true, the address of the field of the block
2277 /// structure that holds the address of the __block structure.
2278 ///
2279 /// \param Flags The flag that will be passed to _Block_object_dispose.
2280 ///
2281 /// \param LoadBlockVarAddr Indicates whether we need to emit a load from
2282 /// \p Addr to get the address of the __block structure.
2284 bool LoadBlockVarAddr, bool CanThrow);
2285
2286 void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum,
2287 llvm::Value *ptr);
2288
2291
2292 /// BuildBlockByrefAddress - Computes the location of the
2293 /// data in a variable which is declared as __block.
2295 bool followForward = true);
2297 const BlockByrefInfo &info,
2298 bool followForward,
2299 const llvm::Twine &name);
2300
2302
2304
2305 void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
2306 const CGFunctionInfo &FnInfo);
2307
2308 /// Annotate the function with an attribute that disables TSan checking at
2309 /// runtime.
2310 void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn);
2311
2312 /// Emit code for the start of a function.
2313 /// \param Loc The location to be associated with the function.
2314 /// \param StartLoc The location of the function body.
2316 QualType RetTy,
2317 llvm::Function *Fn,
2318 const CGFunctionInfo &FnInfo,
2319 const FunctionArgList &Args,
2321 SourceLocation StartLoc = SourceLocation());
2322
2324
2328 void EmitFunctionBody(const Stmt *Body);
2329 void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S);
2330
2331 void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator,
2332 CallArgList &CallArgs,
2333 const CGFunctionInfo *CallOpFnInfo = nullptr,
2334 llvm::Constant *CallOpFn = nullptr);
2338 CallArgList &CallArgs);
2340 const CGFunctionInfo **ImplFnInfo,
2341 llvm::Function **ImplFn);
2344 EmitStoreThroughLValue(RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV);
2345 }
2346 void EmitAsanPrologueOrEpilogue(bool Prologue);
2347
2348 /// Emit the unified return block, trying to avoid its emission when
2349 /// possible.
2350 /// \return The debug location of the user written return statement if the
2351 /// return block is avoided.
2352 llvm::DebugLoc EmitReturnBlock();
2353
2354 /// FinishFunction - Complete IR generation of the current function. It is
2355 /// legal to call this function even if there is no current insertion point.
2357
2358 void StartThunk(llvm::Function *Fn, GlobalDecl GD,
2359 const CGFunctionInfo &FnInfo, bool IsUnprototyped);
2360
2361 void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
2362 const ThunkInfo *Thunk, bool IsUnprototyped);
2363
2365
2366 /// Emit a musttail call for a thunk with a potentially adjusted this pointer.
2367 void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr,
2368 llvm::FunctionCallee Callee);
2369
2370 /// Generate a thunk for the given method.
2371 void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
2372 GlobalDecl GD, const ThunkInfo &Thunk,
2373 bool IsUnprototyped);
2374
2375 llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn,
2376 const CGFunctionInfo &FnInfo,
2377 GlobalDecl GD, const ThunkInfo &Thunk);
2378
2380 FunctionArgList &Args);
2381
2383
2384 /// Struct with all information about dynamic [sub]class needed to set vptr.
2385 struct VPtr {
2390 };
2391
2392 /// Initialize the vtable pointer of the given subobject.
2394
2396
2399
2401 CharUnits OffsetFromNearestVBase,
2402 bool BaseIsNonVirtualPrimaryBase,
2403 const CXXRecordDecl *VTableClass,
2404 VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs);
2405
2407
2408 /// GetVTablePtr - Return the Value of the vtable pointer member pointed
2409 /// to by This.
2410 llvm::Value *GetVTablePtr(Address This, llvm::Type *VTableTy,
2411 const CXXRecordDecl *VTableClass);
2412
2421 };
2422
2423 /// Derived is the presumed address of an object of type T after a
2424 /// cast. If T is a polymorphic class type, emit a check that the virtual
2425 /// table for Derived belongs to a class derived from T.
2426 void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull,
2428
2429 /// EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
2430 /// If vptr CFI is enabled, emit a check that VTable is valid.
2431 void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable,
2433
2434 /// EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for
2435 /// RD using llvm.type.test.
2436 void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable,
2438
2439 /// If whole-program virtual table optimization is enabled, emit an assumption
2440 /// that VTable is a member of RD's type identifier. Or, if vptr CFI is
2441 /// enabled, emit a check that VTable is a member of RD's type identifier.
2443 llvm::Value *VTable, SourceLocation Loc);
2444
2445 /// Returns whether we should perform a type checked load when loading a
2446 /// virtual function for virtual calls to members of RD. This is generally
2447 /// true when both vcall CFI and whole-program-vtables are enabled.
2449
2450 /// Emit a type checked load from the given vtable.
2452 llvm::Value *VTable,
2453 llvm::Type *VTableTy,
2454 uint64_t VTableByteOffset);
2455
2456 /// EnterDtorCleanups - Enter the cleanups necessary to complete the
2457 /// given phase of destruction for a destructor. The end result
2458 /// should call destructors on members and base classes in reverse
2459 /// order of their construction.
2461
2462 /// ShouldInstrumentFunction - Return true if the current function should be
2463 /// instrumented with __cyg_profile_func_* calls
2465
2466 /// ShouldSkipSanitizerInstrumentation - Return true if the current function
2467 /// should not be instrumented with sanitizers.
2469
2470 /// ShouldXRayInstrument - Return true if the current function should be
2471 /// instrumented with XRay nop sleds.
2473
2474 /// AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit
2475 /// XRay custom event handling calls.
2477
2478 /// AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit
2479 /// XRay typed event handling calls.
2481
2482 /// Return a type hash constant for a function instrumented by
2483 /// -fsanitize=function.
2484 llvm::ConstantInt *getUBSanFunctionTypeHash(QualType T) const;
2485
2486 /// EmitFunctionProlog - Emit the target specific LLVM code to load the
2487 /// arguments for the given function. This is also responsible for naming the
2488 /// LLVM function arguments.
2490 llvm::Function *Fn,
2491 const FunctionArgList &Args);
2492
2493 /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2494 /// given temporary.
2495 void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc,
2496 SourceLocation EndLoc);
2497
2498 /// Emit a test that checks if the return value \p RV is nonnull.
2499 void EmitReturnValueCheck(llvm::Value *RV);
2500
2501 /// EmitStartEHSpec - Emit the start of the exception spec.
2502 void EmitStartEHSpec(const Decl *D);
2503
2504 /// EmitEndEHSpec - Emit the end of the exception spec.
2505 void EmitEndEHSpec(const Decl *D);
2506
2507 /// getTerminateLandingPad - Return a landing pad that just calls terminate.
2508 llvm::BasicBlock *getTerminateLandingPad();
2509
2510 /// getTerminateLandingPad - Return a cleanup funclet that just calls
2511 /// terminate.
2512 llvm::BasicBlock *getTerminateFunclet();
2513
2514 /// getTerminateHandler - Return a handler (not a landing pad, just
2515 /// a catch handler) that just calls terminate. This is used when
2516 /// a terminate scope encloses a try.
2517 llvm::BasicBlock *getTerminateHandler();
2518
2520 llvm::Type *ConvertType(QualType T);
2521 llvm::Type *ConvertType(const TypeDecl *T) {
2522 return ConvertType(getContext().getTypeDeclType(T));
2523 }
2524
2525 /// LoadObjCSelf - Load the value of self. This function is only valid while
2526 /// generating code for an Objective-C method.
2527 llvm::Value *LoadObjCSelf();
2528
2529 /// TypeOfSelfObject - Return type of object that this self represents.
2531
2532 /// getEvaluationKind - Return the TypeEvaluationKind of QualType \c T.
2534
2536 return getEvaluationKind(T) == TEK_Scalar;
2537 }
2538
2541 }
2542
2543 /// createBasicBlock - Create an LLVM basic block.
2544 llvm::BasicBlock *createBasicBlock(const Twine &name = "",
2545 llvm::Function *parent = nullptr,
2546 llvm::BasicBlock *before = nullptr) {
2547 return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before);
2548 }
2549
2550 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
2551 /// label maps to.
2553
2554 /// SimplifyForwardingBlocks - If the given basic block is only a branch to
2555 /// another basic block, simplify it. This assumes that no other code could
2556 /// potentially reference the basic block.
2557 void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
2558
2559 /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
2560 /// adding a fall-through branch from the current insert block if
2561 /// necessary. It is legal to call this function even if there is no current
2562 /// insertion point.
2563 ///
2564 /// IsFinished - If true, indicates that the caller has finished emitting
2565 /// branches to the given block and does not expect to emit code into it. This
2566 /// means the block can be ignored if it is unreachable.
2567 void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
2568
2569 /// EmitBlockAfterUses - Emit the given block somewhere hopefully
2570 /// near its uses, and leave the insertion point in it.
2571 void EmitBlockAfterUses(llvm::BasicBlock *BB);
2572
2573 /// EmitBranch - Emit a branch to the specified basic block from the current
2574 /// insert block, taking care to avoid creation of branches from dummy
2575 /// blocks. It is legal to call this function even if there is no current
2576 /// insertion point.
2577 ///
2578 /// This function clears the current insertion point. The caller should follow
2579 /// calls to this function with calls to Emit*Block prior to generation new
2580 /// code.
2581 void EmitBranch(llvm::BasicBlock *Block);
2582
2583 /// HaveInsertPoint - True if an insertion point is defined. If not, this
2584 /// indicates that the current code being emitted is unreachable.
2585 bool HaveInsertPoint() const {
2586 return Builder.GetInsertBlock() != nullptr;
2587 }
2588
2589 /// EnsureInsertPoint - Ensure that an insertion point is defined so that
2590 /// emitted IR has a place to go. Note that by definition, if this function
2591 /// creates a block then that block is unreachable; callers may do better to
2592 /// detect when no insertion point is defined and simply skip IR generation.
2594 if (!HaveInsertPoint())
2596 }
2597
2598 /// ErrorUnsupported - Print out an error that codegen doesn't support the
2599 /// specified stmt yet.
2600 void ErrorUnsupported(const Stmt *S, const char *Type);
2601
2602 //===--------------------------------------------------------------------===//
2603 // Helpers
2604 //===--------------------------------------------------------------------===//
2605
2607 llvm::BasicBlock *LHSBlock,
2608 llvm::BasicBlock *RHSBlock,
2609 llvm::BasicBlock *MergeBlock,
2610 QualType MergedType) {
2611 Builder.SetInsertPoint(MergeBlock);
2612 llvm::PHINode *PtrPhi = Builder.CreatePHI(LHS.getType(), 2, "cond");
2613 PtrPhi->addIncoming(LHS.getBasePointer(), LHSBlock);
2614 PtrPhi->addIncoming(RHS.getBasePointer(), RHSBlock);
2615 LHS.replaceBasePointer(PtrPhi);
2616 LHS.setAlignment(std::min(LHS.getAlignment(), RHS.getAlignment()));
2617 return LHS;
2618 }
2619
2620 /// Construct an address with the natural alignment of T. If a pointer to T
2621 /// is expected to be signed, the pointer passed to this function must have
2622 /// been signed, and the returned Address will have the pointer authentication
2623 /// information needed to authenticate the signed pointer.
2625 llvm::Value *Ptr, QualType T, CharUnits Alignment = CharUnits::Zero(),
2626 bool ForPointeeType = false, LValueBaseInfo *BaseInfo = nullptr,
2627 TBAAAccessInfo *TBAAInfo = nullptr,
2628 KnownNonNull_t IsKnownNonNull = NotKnownNonNull) {
2629 if (Alignment.isZero())
2630 Alignment =
2631 CGM.getNaturalTypeAlignment(T, BaseInfo, TBAAInfo, ForPointeeType);
2632 return Address(Ptr, ConvertTypeForMem(T), Alignment, nullptr,
2633 IsKnownNonNull);
2634 }
2635
2638 return MakeAddrLValue(Addr, T, LValueBaseInfo(Source),
2640 }
2641
2643 TBAAAccessInfo TBAAInfo) {
2644 return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
2645 }
2646
2647 LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2649 return MakeAddrLValue(makeNaturalAddressForPointer(V, T, Alignment), T,
2651 }
2652
2653 /// Same as MakeAddrLValue above except that the pointer is known to be
2654 /// unsigned.
2655 LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
2657 Address Addr(V, ConvertTypeForMem(T), Alignment);
2658 return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
2660 }
2661
2662 LValue
2665 return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
2666 TBAAAccessInfo());
2667 }
2668
2669 /// Given a value of type T* that may not be to a complete object, construct
2670 /// an l-value with the natural pointee alignment of T.
2672
2674
2675 /// Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known
2676 /// to be unsigned.
2678
2680
2682 LValueBaseInfo *PointeeBaseInfo = nullptr,
2683 TBAAAccessInfo *PointeeTBAAInfo = nullptr);
2686 AlignmentSource Source =
2688 LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source),
2689 CGM.getTBAAAccessInfo(RefTy));
2690 return EmitLoadOfReferenceLValue(RefLVal);
2691 }
2692
2693 /// Load a pointer with type \p PtrTy stored at address \p Ptr.
2694 /// Note that \p PtrTy is the type of the loaded pointer, not the addresses
2695 /// it is loaded from.
2697 LValueBaseInfo *BaseInfo = nullptr,
2698 TBAAAccessInfo *TBAAInfo = nullptr);
2700
2701 /// CreateTempAlloca - This creates an alloca and inserts it into the entry
2702 /// block if \p ArraySize is nullptr, otherwise inserts it at the current
2703 /// insertion point of the builder. The caller is responsible for setting an
2704 /// appropriate alignment on
2705 /// the alloca.
2706 ///
2707 /// \p ArraySize is the number of array elements to be allocated if it
2708 /// is not nullptr.
2709 ///
2710 /// LangAS::Default is the address space of pointers to local variables and
2711 /// temporaries, as exposed in the source language. In certain
2712 /// configurations, this is not the same as the alloca address space, and a
2713 /// cast is needed to lift the pointer from the alloca AS into
2714 /// LangAS::Default. This can happen when the target uses a restricted
2715 /// address space for the stack but the source language requires
2716 /// LangAS::Default to be a generic address space. The latter condition is
2717 /// common for most programming languages; OpenCL is an exception in that
2718 /// LangAS::Default is the private address space, which naturally maps
2719 /// to the stack.
2720 ///
2721 /// Because the address of a temporary is often exposed to the program in
2722 /// various ways, this function will perform the cast. The original alloca
2723 /// instruction is returned through \p Alloca if it is not nullptr.
2724 ///
2725 /// The cast is not performaed in CreateTempAllocaWithoutCast. This is
2726 /// more efficient if the caller knows that the address will not be exposed.
2727 llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp",
2728 llvm::Value *ArraySize = nullptr);
2730 const Twine &Name = "tmp",
2731 llvm::Value *ArraySize = nullptr,
2732 RawAddress *Alloca = nullptr);
2734 const Twine &Name = "tmp",
2735 llvm::Value *ArraySize = nullptr);
2736
2737 /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
2738 /// default ABI alignment of the given LLVM type.
2739 ///
2740 /// IMPORTANT NOTE: This is *not* generally the right alignment for
2741 /// any given AST type that happens to have been lowered to the
2742 /// given IR type. This should only ever be used for function-local,
2743 /// IR-driven manipulations like saving and restoring a value. Do
2744 /// not hand this address off to arbitrary IRGen routines, and especially
2745 /// do not pass it as an argument to a function that might expect a
2746 /// properly ABI-aligned value.
2748 const Twine &Name = "tmp");
2749
2750 /// CreateIRTemp - Create a temporary IR object of the given type, with
2751 /// appropriate alignment. This routine should only be used when an temporary
2752 /// value needs to be stored into an alloca (for example, to avoid explicit
2753 /// PHI construction), but the type is the IR type, not the type appropriate
2754 /// for storing in memory.
2755 ///
2756 /// That is, this is exactly equivalent to CreateMemTemp, but calling
2757 /// ConvertType instead of ConvertTypeForMem.
2758 RawAddress CreateIRTemp(QualType T, const Twine &Name = "tmp");
2759
2760 /// CreateMemTemp - Create a temporary memory object of the given type, with
2761 /// appropriate alignmen and cast it to the default address space. Returns
2762 /// the original alloca instruction by \p Alloca if it is not nullptr.
2763 RawAddress CreateMemTemp(QualType T, const Twine &Name = "tmp",
2764 RawAddress *Alloca = nullptr);
2766 const Twine &Name = "tmp",
2767 RawAddress *Alloca = nullptr);
2768
2769 /// CreateMemTemp - Create a temporary memory object of the given type, with
2770 /// appropriate alignmen without casting it to the default address space.
2771 RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp");
2773 const Twine &Name = "tmp");
2774
2775 /// CreateAggTemp - Create a temporary memory object for the given
2776 /// aggregate type.
2777 AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp",
2778 RawAddress *Alloca = nullptr) {
2779 return AggValueSlot::forAddr(
2780 CreateMemTemp(T, Name, Alloca), T.getQualifiers(),
2783 }
2784
2785 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
2786 /// expression and compare the result against zero, returning an Int1Ty value.
2787 llvm::Value *EvaluateExprAsBool(const Expr *E);
2788
2789 /// Retrieve the implicit cast expression of the rhs in a binary operator
2790 /// expression by passing pointers to Value and QualType
2791 /// This is used for implicit bitfield conversion checks, which
2792 /// must compare with the value before potential truncation.
2794 llvm::Value **Previous,
2795 QualType *SrcType);
2796
2797 /// Emit a check that an [implicit] conversion of a bitfield. It is not UB,
2798 /// so we use the value after conversion.
2799 void EmitBitfieldConversionCheck(llvm::Value *Src, QualType SrcType,
2800 llvm::Value *Dst, QualType DstType,
2801 const CGBitFieldInfo &Info,
2802 SourceLocation Loc);
2803
2804 /// EmitIgnoredExpr - Emit an expression in a context which ignores the result.
2805 void EmitIgnoredExpr(const Expr *E);
2806
2807 /// EmitAnyExpr - Emit code to compute the specified expression which can have
2808 /// any type. The result is returned as an RValue struct. If this is an
2809 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
2810 /// the result should be returned.
2811 ///
2812 /// \param ignoreResult True if the resulting value isn't used.
2815 bool ignoreResult = false);
2816
2817 // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
2818 // or the value of the expression, depending on how va_list is defined.
2820
2821 /// Emit a "reference" to a __builtin_ms_va_list; this is
2822 /// always the value of the expression, because a __builtin_ms_va_list is a
2823 /// pointer to a char.
2825
2826 /// EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will
2827 /// always be accessible even if no aggregate location is provided.
2829
2830 /// EmitAnyExprToMem - Emits the code necessary to evaluate an
2831 /// arbitrary expression into the given memory location.
2832 void EmitAnyExprToMem(const Expr *E, Address Location,
2833 Qualifiers Quals, bool IsInitializer);
2834
2835 void EmitAnyExprToExn(const Expr *E, Address Addr);
2836
2837 /// EmitExprAsInit - Emits the code necessary to initialize a
2838 /// location in memory with the given initializer.
2839 void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue,
2840 bool capturedByInit);
2841
2842 /// hasVolatileMember - returns true if aggregate type has a volatile
2843 /// member.
2845 if (const RecordType *RT = T->getAs<RecordType>()) {
2846 const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
2847 return RD->hasVolatileMember();
2848 }
2849 return false;
2850 }
2851
2852 /// Determine whether a return value slot may overlap some other object.
2854 // FIXME: Assuming no overlap here breaks guaranteed copy elision for base
2855 // class subobjects. These cases may need to be revisited depending on the
2856 // resolution of the relevant core issue.
2858 }
2859
2860 /// Determine whether a field initialization may overlap some other object.
2862
2863 /// Determine whether a base class initialization may overlap some other
2864 /// object.
2866 const CXXRecordDecl *BaseRD,
2867 bool IsVirtual);
2868
2869 /// Emit an aggregate assignment.
2871 bool IsVolatile = hasVolatileMember(EltTy);
2872 EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
2873 }
2874
2876 AggValueSlot::Overlap_t MayOverlap) {
2877 EmitAggregateCopy(Dest, Src, Src.getType(), MayOverlap);
2878 }
2879
2880 /// EmitAggregateCopy - Emit an aggregate copy.
2881 ///
2882 /// \param isVolatile \c true iff either the source or the destination is
2883 /// volatile.
2884 /// \param MayOverlap Whether the tail padding of the destination might be
2885 /// occupied by some other object. More efficient code can often be
2886 /// generated if not.
2888 AggValueSlot::Overlap_t MayOverlap,
2889 bool isVolatile = false);
2890
2891 /// GetAddrOfLocalVar - Return the address of a local variable.
2893 auto it = LocalDeclMap.find(VD);
2894 assert(it != LocalDeclMap.end() &&
2895 "Invalid argument to GetAddrOfLocalVar(), no decl!");
2896 return it->second;
2897 }
2898
2899 /// Given an opaque value expression, return its LValue mapping if it exists,
2900 /// otherwise create one.
2902
2903 /// Given an opaque value expression, return its RValue mapping if it exists,
2904 /// otherwise create one.
2906
2907 /// Get the index of the current ArrayInitLoopExpr, if any.
2908 llvm::Value *getArrayInitIndex() { return ArrayInitIndex; }
2909
2910 /// getAccessedFieldNo - Given an encoded value and a result number, return
2911 /// the input field number being accessed.
2912 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
2913
2914 llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
2915 llvm::BasicBlock *GetIndirectGotoBlock();
2916
2917 /// Check if \p E is a C++ "this" pointer wrapped in value-preserving casts.
2918 static bool IsWrappedCXXThis(const Expr *E);
2919
2920 /// EmitNullInitialization - Generate code to set a value of the given type to
2921 /// null, If the type contains data member pointers, they will be initialized
2922 /// to -1 in accordance with the Itanium C++ ABI.
2924
2925 /// Emits a call to an LLVM variable-argument intrinsic, either
2926 /// \c llvm.va_start or \c llvm.va_end.
2927 /// \param ArgValue A reference to the \c va_list as emitted by either
2928 /// \c EmitVAListRef or \c EmitMSVAListRef.
2929 /// \param IsStart If \c true, emits a call to \c llvm.va_start; otherwise,
2930 /// calls \c llvm.va_end.
2931 llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart);
2932
2933 /// Generate code to get an argument from the passed in pointer
2934 /// and update it accordingly.
2935 /// \param VE The \c VAArgExpr for which to generate code.
2936 /// \param VAListAddr Receives a reference to the \c va_list as emitted by
2937 /// either \c EmitVAListRef or \c EmitMSVAListRef.
2938 /// \returns A pointer to the argument.
2939 // FIXME: We should be able to get rid of this method and use the va_arg
2940 // instruction in LLVM instead once it works well enough.
2942
2943 /// emitArrayLength - Compute the length of an array, even if it's a
2944 /// VLA, and drill down to the base element type.
2946 QualType &baseType,
2947 Address &addr);
2948
2949 /// EmitVLASize - Capture all the sizes for the VLA expressions in
2950 /// the given variably-modified type and store them in the VLASizeMap.
2951 ///
2952 /// This function can be called with a null (unreachable) insert point.
2954
2956 llvm::Value *NumElts;
2958
2959 VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {}
2960 };
2961
2962 /// Return the number of elements for a single dimension
2963 /// for the given array type.
2966
2967 /// Returns an LLVM value that corresponds to the size,
2968 /// in non-variably-sized elements, of a variable length array type,
2969 /// plus that largest non-variably-sized element type. Assumes that
2970 /// the type has already been emitted with EmitVariablyModifiedType.
2973
2974 /// LoadCXXThis - Load the value of 'this'. This function is only valid while
2975 /// generating code for an C++ member function.
2976 llvm::Value *LoadCXXThis() {
2977 assert(CXXThisValue && "no 'this' value for this function");
2978 return CXXThisValue;
2979 }
2981
2982 /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
2983 /// virtual bases.
2984 // FIXME: Every place that calls LoadCXXVTT is something
2985 // that needs to be abstracted properly.
2986 llvm::Value *LoadCXXVTT() {
2987 assert(CXXStructorImplicitParamValue && "no VTT value for this function");
2988 return CXXStructorImplicitParamValue;
2989 }
2990
2991 /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
2992 /// complete class to the given direct base.
2993 Address
2995 const CXXRecordDecl *Derived,
2996 const CXXRecordDecl *Base,
2997 bool BaseIsVirtual);
2998
2999 static bool ShouldNullCheckClassCastValue(const CastExpr *Cast);
3000
3001 /// GetAddressOfBaseClass - This function will add the necessary delta to the
3002 /// load of 'this' and returns address of the base class.
3004 const CXXRecordDecl *Derived,
3007 bool NullCheckValue, SourceLocation Loc);
3008
3010 const CXXRecordDecl *Derived,
3013 bool NullCheckValue);
3014
3015 /// GetVTTParameter - Return the VTT parameter that should be passed to a
3016 /// base constructor/destructor with virtual bases.
3017 /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
3018 /// to ItaniumCXXABI.cpp together with all the references to VTT.
3019 llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase,
3020 bool Delegating);
3021
3023 CXXCtorType CtorType,
3024 const FunctionArgList &Args,
3025 SourceLocation Loc);
3026 // It's important not to confuse this and the previous function. Delegating
3027 // constructors are the C++0x feature. The constructor delegate optimization
3028 // is used to reduce duplication in the base and complete consturctors where
3029 // they are substantially the same.
3031 const FunctionArgList &Args);
3032
3033 /// Emit a call to an inheriting constructor (that is, one that invokes a
3034 /// constructor inherited from a base class) by inlining its definition. This
3035 /// is necessary if the ABI does not support forwarding the arguments to the
3036 /// base class constructor (because they're variadic or similar).
3038 CXXCtorType CtorType,
3039 bool ForVirtualBase,
3040 bool Delegating,
3041 CallArgList &Args);
3042
3043 /// Emit a call to a constructor inherited from a base class, passing the
3044 /// current constructor's arguments along unmodified (without even making
3045 /// a copy).
3047 bool ForVirtualBase, Address This,
3048 bool InheritedFromVBase,
3049 const CXXInheritedCtorInitExpr *E);
3050
3052 bool ForVirtualBase, bool Delegating,
3053 AggValueSlot ThisAVS, const CXXConstructExpr *E);
3054
3056 bool ForVirtualBase, bool Delegating,
3057 Address This, CallArgList &Args,
3059 SourceLocation Loc, bool NewPointerIsChecked);
3060
3061 /// Emit assumption load for all bases. Requires to be called only on
3062 /// most-derived class and not under construction of the object.
3064
3065 /// Emit assumption that vptr load == global vtable.
3066 void EmitVTableAssumptionLoad(const VPtr &vptr, Address This);
3067
3069 Address This, Address Src,
3070 const CXXConstructExpr *E);
3071
3073 const ArrayType *ArrayTy,
3074 Address ArrayPtr,
3075 const CXXConstructExpr *E,
3076 bool NewPointerIsChecked,
3077 bool ZeroInitialization = false);
3078
3080 llvm::Value *NumElements,
3081 Address ArrayPtr,
3082 const CXXConstructExpr *E,
3083 bool NewPointerIsChecked,
3084 bool ZeroInitialization = false);
3085
3087
3089 bool ForVirtualBase, bool Delegating, Address This,
3090 QualType ThisTy);
3091
3092 void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
3093 llvm::Type *ElementTy, Address NewPtr,
3094 llvm::Value *NumElements,
3095 llvm::Value *AllocSizeWithoutCookie);
3096
3097 void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
3098 Address Ptr);
3099
3104
3105 llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
3106 void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
3107
3108 llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
3110
3111 void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
3112 QualType DeleteTy, llvm::Value *NumElements = nullptr,
3113 CharUnits CookieSize = CharUnits());
3114
3116 const CallExpr *TheCallExpr, bool IsDelete);
3117
3118 llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E);
3119 llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE);
3121
3122 /// Situations in which we might emit a check for the suitability of a
3123 /// pointer or glvalue. Needs to be kept in sync with ubsan_handlers.cpp in
3124 /// compiler-rt.
3126 /// Checking the operand of a load. Must be suitably sized and aligned.
3128 /// Checking the destination of a store. Must be suitably sized and aligned.
3130 /// Checking the bound value in a reference binding. Must be suitably sized
3131 /// and aligned, but is not required to refer to an object (until the
3132 /// reference is used), per core issue 453.
3134 /// Checking the object expression in a non-static data member access. Must
3135 /// be an object within its lifetime.
3137 /// Checking the 'this' pointer for a call to a non-static member function.
3138 /// Must be an object within its lifetime.
3140 /// Checking the 'this' pointer for a constructor call.
3142 /// Checking the operand of a static_cast to a derived pointer type. Must be
3143 /// null or an object within its lifetime.
3145 /// Checking the operand of a static_cast to a derived reference type. Must
3146 /// be an object within its lifetime.
3148 /// Checking the operand of a cast to a base object. Must be suitably sized
3149 /// and aligned.
3151 /// Checking the operand of a cast to a virtual base object. Must be an
3152 /// object within its lifetime.
3154 /// Checking the value assigned to a _Nonnull pointer. Must not be null.
3156 /// Checking the operand of a dynamic_cast or a typeid expression. Must be
3157 /// null or an object within its lifetime.
3160
3161 /// Determine whether the pointer type check \p TCK permits null pointers.
3163
3164 /// Determine whether the pointer type check \p TCK requires a vptr check.
3166
3167 /// Whether any type-checking sanitizers are enabled. If \c false,
3168 /// calls to EmitTypeCheck can be skipped.
3170
3172 QualType Type, SanitizerSet SkippedChecks = SanitizerSet(),
3173 llvm::Value *ArraySize = nullptr) {
3175 return;
3176 EmitTypeCheck(TCK, Loc, LV.emitRawPointer(*this), Type, LV.getAlignment(),
3177 SkippedChecks, ArraySize);
3178 }
3179
3181 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3182 SanitizerSet SkippedChecks = SanitizerSet(),
3183 llvm::Value *ArraySize = nullptr) {
3185 return;
3186 EmitTypeCheck(TCK, Loc, Addr.emitRawPointer(*this), Type, Alignment,
3187 SkippedChecks, ArraySize);
3188 }
3189
3190 /// Emit a check that \p V is the address of storage of the
3191 /// appropriate size and alignment for an object of type \p Type
3192 /// (or if ArraySize is provided, for an array of that bound).
3193 void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V,
3194 QualType Type, CharUnits Alignment = CharUnits::Zero(),
3195 SanitizerSet SkippedChecks = SanitizerSet(),
3196 llvm::Value *ArraySize = nullptr);
3197
3198 /// Emit a check that \p Base points into an array object, which
3199 /// we can access at index \p Index. \p Accessed should be \c false if we
3200 /// this expression is used as an lvalue, for instance in "&Arr[Idx]".
3201 void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index,
3202 QualType IndexType, bool Accessed);
3203 void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound,
3204 llvm::Value *Index, QualType IndexType,
3205 QualType IndexedType, bool Accessed);
3206
3207 // Find a struct's flexible array member and get its offset. It may be
3208 // embedded inside multiple sub-structs, but must still be the last field.
3209 const FieldDecl *
3211 const FieldDecl *FAMDecl,
3212 uint64_t &Offset);
3213
3214 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3215 /// \p nullptr if either the attribute or the field doesn't exist.
3217
3218 /// Build an expression accessing the "counted_by" field.
3219 llvm::Value *EmitCountedByFieldExpr(const Expr *Base,
3220 const FieldDecl *FAMDecl,
3221 const FieldDecl *CountDecl);
3222
3224 bool isInc, bool isPre);
3226 bool isInc, bool isPre);
3227
3228 /// Converts Location to a DebugLoc, if debug information is enabled.
3229 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
3230
3231 /// Get the record field index as represented in debug info.
3232 unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex);
3233
3234
3235 //===--------------------------------------------------------------------===//
3236 // Declaration Emission
3237 //===--------------------------------------------------------------------===//
3238
3239 /// EmitDecl - Emit a declaration.
3240 ///
3241 /// This function can be called with a null (unreachable) insert point.
3242 void EmitDecl(const Decl &D);
3243
3244 /// EmitVarDecl - Emit a local variable declaration.
3245 ///
3246 /// This function can be called with a null (unreachable) insert point.
3247 void EmitVarDecl(const VarDecl &D);
3248
3249 void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,
3250 bool capturedByInit);
3251
3253 llvm::Value *Address);
3254
3255 /// Determine whether the given initializer is trivial in the sense
3256 /// that it requires no code to be generated.
3258
3259 /// EmitAutoVarDecl - Emit an auto variable declaration.
3260 ///
3261 /// This function can be called with a null (unreachable) insert point.
3262 void EmitAutoVarDecl(const VarDecl &D);
3263
3265 friend class CodeGenFunction;
3266
3267 const VarDecl *Variable;
3268
3269 /// The address of the alloca for languages with explicit address space
3270 /// (e.g. OpenCL) or alloca casted to generic pointer for address space
3271 /// agnostic languages (e.g. C++). Invalid if the variable was emitted
3272 /// as a global constant.
3273 Address Addr;
3274
3275 llvm::Value *NRVOFlag;
3276
3277 /// True if the variable is a __block variable that is captured by an
3278 /// escaping block.
3279 bool IsEscapingByRef;
3280
3281 /// True if the variable is of aggregate type and has a constant
3282 /// initializer.
3283 bool IsConstantAggregate;
3284
3285 /// Non-null if we should use lifetime annotations.
3286 llvm::Value *SizeForLifetimeMarkers;
3287
3288 /// Address with original alloca instruction. Invalid if the variable was
3289 /// emitted as a global constant.
3290 RawAddress AllocaAddr;
3291
3292 struct Invalid {};
3293 AutoVarEmission(Invalid)
3294 : Variable(nullptr), Addr(Address::invalid()),
3295 AllocaAddr(RawAddress::invalid()) {}
3296
3297 AutoVarEmission(const VarDecl &variable)
3298 : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
3299 IsEscapingByRef(false), IsConstantAggregate(false),
3300 SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
3301
3302 bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
3303
3304 public:
3305 static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
3306
3307 bool useLifetimeMarkers() const {
3308 return SizeForLifetimeMarkers != nullptr;
3309 }
3310 llvm::Value *getSizeForLifetimeMarkers() const {
3311 assert(useLifetimeMarkers());
3312 return SizeForLifetimeMarkers;
3313 }
3314
3315 /// Returns the raw, allocated address, which is not necessarily
3316 /// the address of the object itself. It is casted to default
3317 /// address space for address space agnostic languages.
3319 return Addr;
3320 }
3321
3322 /// Returns the address for the original alloca instruction.
3323 RawAddress getOriginalAllocatedAddress() const { return AllocaAddr; }
3324
3325 /// Returns the address of the object within this declaration.
3326 /// Note that this does not chase the forwarding pointer for
3327 /// __block decls.
3329 if (!IsEscapingByRef) return Addr;
3330
3331 return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false);
3332 }
3333 };
3335 void EmitAutoVarInit(const AutoVarEmission &emission);
3338 QualType::DestructionKind dtorKind);
3339
3340 /// Emits the alloca and debug information for the size expressions for each
3341 /// dimension of an array. It registers the association of its (1-dimensional)
3342 /// QualTypes and size expression's debug node, so that CGDebugInfo can
3343 /// reference this node when creating the DISubrange object to describe the
3344 /// array types.
3346 const VarDecl &D,
3347 bool EmitDebugInfo);
3348
3350 llvm::GlobalValue::LinkageTypes Linkage);
3351
3353 union {
3355 llvm::Value *Value;
3356 };
3357
3358 bool IsIndirect;
3359
3360 ParamValue(llvm::Value *V) : Value(V), IsIndirect(false) {}
3361 ParamValue(Address A) : Addr(A), IsIndirect(true) {}
3362
3363 public:
3364 static ParamValue forDirect(llvm::Value *value) {
3365 return ParamValue(value);
3366 }
3368 assert(!addr.getAlignment().isZero());
3369 return ParamValue(addr);
3370 }
3371
3372 bool isIndirect() const { return IsIndirect; }
3373 llvm::Value *getAnyValue() const {
3374 if (!isIndirect())
3375 return Value;
3376 assert(!Addr.hasOffset() && "unexpected offset");
3377 return Addr.getBasePointer();
3378 }
3379
3380 llvm::Value *getDirectValue() const {
3381 assert(!isIndirect());
3382 return Value;
3383 }
3384
3386 assert(isIndirect());
3387 return Addr;
3388 }
3389 };
3390
3391 /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
3392 void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo);
3393
3394 /// protectFromPeepholes - Protect a value that we're intending to
3395 /// store to the side, but which will probably be used later, from
3396 /// aggressive peepholing optimizations that might delete it.
3397 ///
3398 /// Pass the result to unprotectFromPeepholes to declare that
3399 /// protection is no longer required.
3400 ///
3401 /// There's no particular reason why this shouldn't apply to
3402 /// l-values, it's just that no existing peepholes work on pointers.
3405
3406 void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty,
3407 SourceLocation Loc,
3408 SourceLocation AssumptionLoc,
3409 llvm::Value *Alignment,
3410 llvm::Value *OffsetValue,
3411 llvm::Value *TheCheck,
3412 llvm::Instruction *Assumption);
3413
3414 void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty,
3415 SourceLocation Loc, SourceLocation AssumptionLoc,
3416 llvm::Value *Alignment,
3417 llvm::Value *OffsetValue = nullptr);
3418
3419 void emitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E,
3420 SourceLocation AssumptionLoc,
3421 llvm::Value *Alignment,
3422 llvm::Value *OffsetValue = nullptr);
3423
3424 //===--------------------------------------------------------------------===//
3425 // Statement Emission
3426 //===--------------------------------------------------------------------===//
3427
3428 /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
3429 void EmitStopPoint(const Stmt *S);
3430
3431 /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
3432 /// this function even if there is no current insertion point.
3433 ///
3434 /// This function may clear the current insertion point; callers should use
3435 /// EnsureInsertPoint if they wish to subsequently generate code without first
3436 /// calling EmitBlock, EmitBranch, or EmitStmt.
3437 void EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs = std::nullopt);
3438
3439 /// EmitSimpleStmt - Try to emit a "simple" statement which does not
3440 /// necessarily require an insertion point or debug information; typically
3441 /// because the statement amounts to a jump or a container of other
3442 /// statements.
3443 ///
3444 /// \return True if the statement was handled.
3446
3447 Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
3450 bool GetLast = false,
3451 AggValueSlot AVS =
3453
3454 /// EmitLabel - Emit the block for the given label. It is legal to call this
3455 /// function even if there is no current insertion point.
3456 void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt.
3457
3458 void EmitLabelStmt(const LabelStmt &S);
3460 void EmitGotoStmt(const GotoStmt &S);
3462 void EmitIfStmt(const IfStmt &S);
3463
3465 ArrayRef<const Attr *> Attrs = std::nullopt);
3466 void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = std::nullopt);
3467 void EmitForStmt(const ForStmt &S,
3468 ArrayRef<const Attr *> Attrs = std::nullopt);
3470 void EmitDeclStmt(const DeclStmt &S);
3471 void EmitBreakStmt(const BreakStmt &S);
3477 void EmitAsmStmt(const AsmStmt &S);
3478
3484
3489 bool ignoreResult = false);
3493 bool ignoreResult = false);
3495 RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID);
3496
3497 void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3498 void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
3499
3505 void VolatilizeTryBlocks(llvm::BasicBlock *BB,
3507
3509 llvm::Function *FinallyFunc);
3511 const Stmt *OutlinedStmt);
3512
3514 const SEHExceptStmt &Except);
3515
3517 const SEHFinallyStmt &Finally);
3518
3520 llvm::Value *ParentFP,
3521 llvm::Value *EntryEBP);
3522 llvm::Value *EmitSEHExceptionCode();
3523 llvm::Value *EmitSEHExceptionInfo();
3525
3526 /// Emit simple code for OpenMP directives in Simd-only mode.
3528
3529 /// Scan the outlined statement for captures from the parent function. For
3530 /// each capture, mark the capture as escaped and emit a call to
3531 /// llvm.localrecover. Insert the localrecover result into the LocalDeclMap.
3533 bool IsFilter);
3534
3535 /// Recovers the address of a local in a parent function. ParentVar is the
3536 /// address of the variable used in the immediate parent function. It can
3537 /// either be an alloca or a call to llvm.localrecover if there are nested
3538 /// outlined functions. ParentFP is the frame pointer of the outermost parent
3539 /// frame.
3541 Address ParentVar,
3542 llvm::Value *ParentFP);
3543
3545 ArrayRef<const Attr *> Attrs = std::nullopt);
3546
3547 /// Controls insertion of cancellation exit blocks in worksharing constructs.
3549 CodeGenFunction &CGF;
3550
3551 public:
3553 bool HasCancel)
3554 : CGF(CGF) {
3555 CGF.OMPCancelStack.enter(CGF, Kind, HasCancel);
3556 }
3557 ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); }
3558 };
3559
3560 /// Returns calculated size of the specified type.
3561 llvm::Value *getTypeSize(QualType Ty);
3567 SourceLocation Loc);
3569 SmallVectorImpl<llvm::Value *> &CapturedVars);
3570 void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy,
3571 SourceLocation Loc);
3572 /// Perform element by element copying of arrays with type \a
3573 /// OriginalType from \a SrcAddr to \a DestAddr using copying procedure
3574 /// generated by \a CopyGen.
3575 ///
3576 /// \param DestAddr Address of the destination array.
3577 /// \param SrcAddr Address of the source array.
3578 /// \param OriginalType Type of destination and source arrays.
3579 /// \param CopyGen Copying procedure that copies value of single array element
3580 /// to another single array element.
3582 Address DestAddr, Address SrcAddr, QualType OriginalType,
3583 const llvm::function_ref<void(Address, Address)> CopyGen);
3584 /// Emit proper copying of data from one variable to another.
3585 ///
3586 /// \param OriginalType Original type of the copied variables.
3587 /// \param DestAddr Destination address.
3588 /// \param SrcAddr Source address.
3589 /// \param DestVD Destination variable used in \a CopyExpr (for arrays, has
3590 /// type of the base array element).
3591 /// \param SrcVD Source variable used in \a CopyExpr (for arrays, has type of
3592 /// the base array element).
3593 /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a
3594 /// DestVD.
3595 void EmitOMPCopy(QualType OriginalType,
3596 Address DestAddr, Address SrcAddr,
3597 const VarDecl *DestVD, const VarDecl *SrcVD,
3598 const Expr *Copy);
3599 /// Emit atomic update code for constructs: \a X = \a X \a BO \a E or
3600 /// \a X = \a E \a BO \a E.
3601 ///
3602 /// \param X Value to be updated.
3603 /// \param E Update value.
3604 /// \param BO Binary operation for update operation.
3605 /// \param IsXLHSInRHSPart true if \a X is LHS in RHS part of the update
3606 /// expression, false otherwise.
3607 /// \param AO Atomic ordering of the generated atomic instructions.
3608 /// \param CommonGen Code generator for complex expressions that cannot be
3609 /// expressed through atomicrmw instruction.
3610 /// \returns <true, OldAtomicValue> if simple 'atomicrmw' instruction was
3611 /// generated, <false, RValue::get(nullptr)> otherwise.
3612 std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr(
3613 LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart,
3614 llvm::AtomicOrdering AO, SourceLocation Loc,
3615 const llvm::function_ref<RValue(RValue)> CommonGen);
3617 OMPPrivateScope &PrivateScope);
3619 OMPPrivateScope &PrivateScope);
3621 const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope,
3622 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3623 CaptureDeviceAddrMap);
3625 const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope,
3626 const llvm::DenseMap<const ValueDecl *, llvm::Value *>
3627 CaptureDeviceAddrMap);
3628 /// Emit code for copyin clause in \a D directive. The next code is
3629 /// generated at the start of outlined functions for directives:
3630 /// \code
3631 /// threadprivate_var1 = master_threadprivate_var1;
3632 /// operator=(threadprivate_var2, master_threadprivate_var2);
3633 /// ...
3634 /// __kmpc_barrier(&loc, global_tid);
3635 /// \endcode
3636 ///
3637 /// \param D OpenMP directive possibly with 'copyin' clause(s).
3638 /// \returns true if at least one copyin variable is found, false otherwise.
3640 /// Emit initial code for lastprivate variables. If some variable is
3641 /// not also firstprivate, then the default initialization is used. Otherwise
3642 /// initialization of this variable is performed by EmitOMPFirstprivateClause
3643 /// method.
3644 ///
3645 /// \param D Directive that may have 'lastprivate' directives.
3646 /// \param PrivateScope Private scope for capturing lastprivate variables for
3647 /// proper codegen in internal captured statement.
3648 ///
3649 /// \returns true if there is at least one lastprivate variable, false
3650 /// otherwise.
3652 OMPPrivateScope &PrivateScope);
3653 /// Emit final copying of lastprivate values to original variables at
3654 /// the end of the worksharing or simd directive.
3655 ///
3656 /// \param D Directive that has at least one 'lastprivate' directives.
3657 /// \param IsLastIterCond Boolean condition that must be set to 'i1 true' if
3658 /// it is the last iteration of the loop code in associated directive, or to
3659 /// 'i1 false' otherwise. If this item is nullptr, no final check is required.
3661 bool NoFinals,
3662 llvm::Value *IsLastIterCond = nullptr);
3663 /// Emit initial code for linear clauses.
3665 CodeGenFunction::OMPPrivateScope &PrivateScope);
3666 /// Emit final code for linear clauses.
3667 /// \param CondGen Optional conditional code for final part of codegen for
3668 /// linear clause.
3670 const OMPLoopDirective &D,
3671 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
3672 /// Emit initial code for reduction variables. Creates reduction copies
3673 /// and initializes them with the values according to OpenMP standard.
3674 ///
3675 /// \param D Directive (possibly) with the 'reduction' clause.
3676 /// \param PrivateScope Private scope for capturing reduction variables for
3677 /// proper codegen in internal captured statement.
3678 ///
3680 OMPPrivateScope &PrivateScope,
3681 bool ForInscan = false);
3682 /// Emit final update of reduction values to original variables at
3683 /// the end of the directive.
3684 ///
3685 /// \param D Directive that has at least one 'reduction' directives.
3686 /// \param ReductionKind The kind of reduction to perform.
3688 const OpenMPDirectiveKind ReductionKind);
3689 /// Emit initial code for linear variables. Creates private copies
3690 /// and initializes them with the values according to OpenMP standard.
3691 ///
3692 /// \param D Directive (possibly) with the 'linear' clause.
3693 /// \return true if at least one linear variable is found that should be
3694 /// initialized with the value of the original variable, false otherwise.
3696
3697 typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/,
3698 llvm::Function * /*OutlinedFn*/,
3699 const OMPTaskDataTy & /*Data*/)>
3702 const OpenMPDirectiveKind CapturedRegion,
3703 const RegionCodeGenTy &BodyGen,
3704 const TaskGenTy &TaskGen, OMPTaskDataTy &Data);
3711 explicit OMPTargetDataInfo() = default;
3714 unsigned NumberOfTargetItems)
3718 };
3720 const RegionCodeGenTy &BodyGen,
3721 OMPTargetDataInfo &InputInfo);
3724 CodeGenFunction &CGF,
3725 const CapturedStmt *CS,
3761 void
3764 void
3771 void
3787 void
3811
3812 /// Emit device code for the target directive.
3814 StringRef ParentName,
3815 const OMPTargetDirective &S);
3816 static void
3819 /// Emit device code for the target parallel for directive.
3821 CodeGenModule &CGM, StringRef ParentName,
3823 /// Emit device code for the target parallel for simd directive.
3825 CodeGenModule &CGM, StringRef ParentName,
3827 /// Emit device code for the target teams directive.
3828 static void
3830 const OMPTargetTeamsDirective &S);
3831 /// Emit device code for the target teams distribute directive.
3833 CodeGenModule &CGM, StringRef ParentName,
3835 /// Emit device code for the target teams distribute simd directive.
3837 CodeGenModule &CGM, StringRef ParentName,
3839 /// Emit device code for the target simd directive.
3841 StringRef ParentName,
3842 const OMPTargetSimdDirective &S);
3843 /// Emit device code for the target teams distribute parallel for simd
3844 /// directive.
3846 CodeGenModule &CGM, StringRef ParentName,
3848
3849 /// Emit device code for the target teams loop directive.
3851 CodeGenModule &CGM, StringRef ParentName,
3853
3854 /// Emit device code for the target parallel loop directive.
3856 CodeGenModule &CGM, StringRef ParentName,
3858
3860 CodeGenModule &CGM, StringRef ParentName,
3862
3863 /// Emit the Stmt \p S and return its topmost canonical loop, if any.
3864 /// TODO: The \p Depth paramter is not yet implemented and must be 1. In the
3865 /// future it is meant to be the number of loops expected in the loop nests
3866 /// (usually specified by the "collapse" clause) that are collapsed to a
3867 /// single loop by this function.
3868 llvm::CanonicalLoopInfo *EmitOMPCollapsedCanonicalLoopNest(const Stmt *S,
3869 int Depth);
3870
3871 /// Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
3873
3874 /// Emit inner loop of the worksharing/simd construct.
3875 ///
3876 /// \param S Directive, for which the inner loop must be emitted.
3877 /// \param RequiresCleanup true, if directive has some associated private
3878 /// variables.
3879 /// \param LoopCond Bollean condition for loop continuation.
3880 /// \param IncExpr Increment expression for loop control variable.
3881 /// \param BodyGen Generator for the inner body of the inner loop.
3882 /// \param PostIncGen Genrator for post-increment code (required for ordered
3883 /// loop directvies).
3885 const OMPExecutableDirective &S, bool RequiresCleanup,
3886 const Expr *LoopCond, const Expr *IncExpr,
3887 const llvm::function_ref<void(CodeGenFunction &)> BodyGen,
3888 const llvm::function_ref<void(CodeGenFunction &)> PostIncGen);
3889
3891 /// Emit initial code for loop counters of loop-based directives.
3893 OMPPrivateScope &LoopScope);
3894
3895 /// Helper for the OpenMP loop directives.
3897
3898 /// Emit code for the worksharing loop-based directive.
3899 /// \return true, if this construct has any lastprivate clause, false -
3900 /// otherwise.
3902 const CodeGenLoopBoundsTy &CodeGenLoopBounds,
3903 const CodeGenDispatchBoundsTy &CGDispatchBounds);
3904
3905 /// Emit code for the distribute loop-based directive.
3907 const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr);
3908
3909 /// Helpers for the OpenMP loop directives.
3912 const OMPLoopDirective &D,
3913 const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen);
3914
3915 /// Emits the lvalue for the expression with possibly captured variable.
3917
3918private:
3919 /// Helpers for blocks.
3920 llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info);
3921
3922 /// struct with the values to be passed to the OpenMP loop-related functions
3923 struct OMPLoopArguments {
3924 /// loop lower bound
3926 /// loop upper bound
3928 /// loop stride
3930 /// isLastIteration argument for runtime functions
3932 /// Chunk value generated by sema
3933 llvm::Value *Chunk = nullptr;
3934 /// EnsureUpperBound
3935 Expr *EUB = nullptr;
3936 /// IncrementExpression
3937 Expr *IncExpr = nullptr;
3938 /// Loop initialization
3939 Expr *Init = nullptr;
3940 /// Loop exit condition
3941 Expr *Cond = nullptr;
3942 /// Update of LB after a whole chunk has been executed
3943 Expr *NextLB = nullptr;
3944 /// Update of UB after a whole chunk has been executed
3945 Expr *NextUB = nullptr;
3946 /// Distinguish between the for distribute and sections
3947 OpenMPDirectiveKind DKind = llvm::omp::OMPD_unknown;
3948 OMPLoopArguments() = default;
3949 OMPLoopArguments(Address LB, Address UB, Address ST, Address IL,
3950 llvm::Value *Chunk = nullptr, Expr *EUB = nullptr,
3951 Expr *IncExpr = nullptr, Expr *Init = nullptr,
3952 Expr *Cond = nullptr, Expr *NextLB = nullptr,
3953 Expr *NextUB = nullptr)
3954 : LB(LB), UB(UB), ST(ST), IL(IL), Chunk(Chunk), EUB(EUB),
3955 IncExpr(IncExpr), Init(Init), Cond(Cond), NextLB(NextLB),
3956 NextUB(NextUB) {}
3957 };
3958 void EmitOMPOuterLoop(bool DynamicOrOrdered, bool IsMonotonic,
3959 const OMPLoopDirective &S, OMPPrivateScope &LoopScope,
3960 const OMPLoopArguments &LoopArgs,
3961 const CodeGenLoopTy &CodeGenLoop,
3962 const CodeGenOrderedTy &CodeGenOrdered);
3963 void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind,
3964 bool IsMonotonic, const OMPLoopDirective &S,
3965 OMPPrivateScope &LoopScope, bool Ordered,
3966 const OMPLoopArguments &LoopArgs,
3967 const CodeGenDispatchBoundsTy &CGDispatchBounds);
3968 void EmitOMPDistributeOuterLoop(OpenMPDistScheduleClauseKind ScheduleKind,
3969 const OMPLoopDirective &S,
3970 OMPPrivateScope &LoopScope,
3971 const OMPLoopArguments &LoopArgs,
3972 const CodeGenLoopTy &CodeGenLoopContent);
3973 /// Emit code for sections directive.
3974 void EmitSections(const OMPExecutableDirective &S);
3975
3976public:
3977 //===--------------------------------------------------------------------===//
3978 // OpenACC Emission
3979 //===--------------------------------------------------------------------===//
3981 // TODO OpenACC: Implement this. It is currently implemented as a 'no-op',
3982 // simply emitting its structured block, but in the future we will implement
3983 // some sort of IR.
3984 EmitStmt(S.getStructuredBlock());
3985 }
3986
3987 //===--------------------------------------------------------------------===//
3988 // LValue Expression Emission
3989 //===--------------------------------------------------------------------===//
3990
3991 /// Create a check that a scalar RValue is non-null.
3993
3994 /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
3996
3997 /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
3998 /// and issue an ErrorUnsupported style diagnostic (using the
3999 /// provided Name).
4001 const char *Name);
4002
4003 /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
4004 /// an ErrorUnsupported style diagnostic (using the provided Name).
4006 const char *Name);
4007
4008 /// EmitLValue - Emit code to compute a designator that specifies the location
4009 /// of the expression.
4010 ///
4011 /// This can return one of two things: a simple address or a bitfield
4012 /// reference. In either case, the LLVM Value* in the LValue structure is
4013 /// guaranteed to be an LLVM pointer type.
4014 ///
4015 /// If this returns a bitfield reference, nothing about the pointee type of
4016 /// the LLVM value is known: For example, it may not be a pointer to an
4017 /// integer.
4018 ///
4019 /// If this returns a normal address, and if the lvalue's C type is fixed
4020 /// size, this method guarantees that the returned pointer type will point to
4021 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
4022 /// variable length type, this is not possible.
4023 ///
4025 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
4026
4027private:
4028 LValue EmitLValueHelper(const Expr *E, KnownNonNull_t IsKnownNonNull);
4029
4030public:
4031 /// Same as EmitLValue but additionally we generate checking code to
4032 /// guard against undefined behavior. This is only suitable when we know
4033 /// that the address will be used to access the object.
4035
4037 SourceLocation Loc);
4038
4039 void EmitAtomicInit(Expr *E, LValue lvalue);
4040
4042
4045
4047 llvm::AtomicOrdering AO, bool IsVolatile = false,
4049
4050 void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit);
4051
4052 void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO,
4053 bool IsVolatile, bool isInit);
4054
4055 std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange(
4056 LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc,
4057 llvm::AtomicOrdering Success =
4058 llvm::AtomicOrdering::SequentiallyConsistent,
4059 llvm::AtomicOrdering Failure =
4060 llvm::AtomicOrdering::SequentiallyConsistent,
4061 bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored());
4062
4063 void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO,
4064 const llvm::function_ref<RValue(RValue)> &UpdateOp,
4065 bool IsVolatile);
4066
4067 /// EmitToMemory - Change a scalar value from its value
4068 /// representation to its in-memory representation.
4069 llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty);
4070
4071 /// EmitFromMemory - Change a scalar value from its memory
4072 /// representation to its value representation.
4073 llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty);
4074
4075 /// Check if the scalar \p Value is within the valid range for the given
4076 /// type \p Ty.
4077 ///
4078 /// Returns true if a check is needed (even if the range is unknown).
4079 bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
4080 SourceLocation Loc);
4081
4082 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4083 /// care to appropriately convert from the memory representation to
4084 /// the LLVM value representation.
4085 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4086 SourceLocation Loc,
4088 bool isNontemporal = false) {
4089 return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source),
4090 CGM.getTBAAAccessInfo(Ty), isNontemporal);
4091 }
4092
4093 llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
4094 SourceLocation Loc, LValueBaseInfo BaseInfo,
4095 TBAAAccessInfo TBAAInfo,
4096 bool isNontemporal = false);
4097
4098 /// EmitLoadOfScalar - Load a scalar value from an address, taking
4099 /// care to appropriately convert from the memory representation to
4100 /// the LLVM value representation. The l-value must be a simple
4101 /// l-value.
4102 llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc);
4103
4104 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4105 /// care to appropriately convert from the memory representation to
4106 /// the LLVM value representation.
4107 void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
4108 bool Volatile, QualType Ty,
4110 bool isInit = false, bool isNontemporal = false) {
4111 EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source),
4112 CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
4113 }
4114
4115 void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
4116 bool Volatile, QualType Ty,
4117 LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo,
4118 bool isInit = false, bool isNontemporal = false);
4119
4120 /// EmitStoreOfScalar - Store a scalar value to an address, taking
4121 /// care to appropriately convert from the memory representation to
4122 /// the LLVM value representation. The l-value must be a simple
4123 /// l-value. The isInit flag indicates whether this is an initialization.
4124 /// If so, atomic qualifiers are ignored and the store is always non-atomic.
4125 void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false);
4126
4127 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
4128 /// this method emits the address of the lvalue, then loads the result as an
4129 /// rvalue, returning the rvalue.
4134
4135 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
4136 /// lvalue, where both are guaranteed to the have the same type, and that type
4137 /// is 'Ty'.
4138 void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false);
4141
4142 /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints
4143 /// as EmitStoreThroughLValue.
4144 ///
4145 /// \param Result [out] - If non-null, this will be set to a Value* for the
4146 /// bit-field contents after the store, appropriate for use as the result of
4147 /// an assignment to the bit-field.
4149 llvm::Value **Result=nullptr);
4150
4151 /// Emit an l-value for an assignment (simple or compound) of complex type.
4155 llvm::Value *&Result);
4156
4157 // Note: only available for agg return types
4160 // Note: only available for agg return types
4162 // Note: only available for agg return types
4170 bool Accessed = false);
4173 bool IsLowerBound = true);
4184
4186
4188
4190 LValueBaseInfo *BaseInfo = nullptr,
4191 TBAAAccessInfo *TBAAInfo = nullptr);
4192
4194 llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference;
4195 ConstantEmission(llvm::Constant *C, bool isReference)
4196 : ValueAndIsReference(C, isReference) {}
4197 public:
4199 static ConstantEmission forReference(llvm::Constant *C) {
4200 return ConstantEmission(C, true);
4201 }
4202 static ConstantEmission forValue(llvm::Constant *C) {
4203 return ConstantEmission(C, false);
4204 }
4205
4206 explicit operator bool() const {
4207 return ValueAndIsReference.getOpaqueValue() != nullptr;
4208 }
4209
4210 bool isReference() const { return ValueAndIsReference.getInt(); }
4212 assert(isReference());
4213 return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
4214 refExpr->getType());
4215 }
4216
4217 llvm::Constant *getValue() const {
4218 assert(!isReference());
4219 return ValueAndIsReference.getPointer();
4220 }
4221 };
4222
4225 llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E);
4226
4230
4232 const ObjCIvarDecl *Ivar);
4234 const ObjCIvarDecl *Ivar);
4238 llvm::Value *ThisValue);
4239
4240 /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
4241 /// if the Field is a reference, this will return the address of the reference
4242 /// and not the address of the value stored in the reference.
4244 const FieldDecl* Field);
4245
4247 llvm::Value* Base, const ObjCIvarDecl *Ivar,
4248 unsigned CVRQualifiers);
4249
4254
4261
4262 //===--------------------------------------------------------------------===//
4263 // Scalar Expression Emission
4264 //===--------------------------------------------------------------------===//
4265
4266 /// EmitCall - Generate a call of the given function, expecting the given
4267 /// result type, and using the given argument list which specifies both the
4268 /// LLVM arguments and the types they were derived from.
4269 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4271 llvm::CallBase **callOrInvoke, bool IsMustTail,
4272 SourceLocation Loc);
4273 RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee,
4275 llvm::CallBase **callOrInvoke = nullptr,
4276 bool IsMustTail = false) {
4277 return EmitCall(CallInfo, Callee, ReturnValue, Args, callOrInvoke,
4278 IsMustTail, SourceLocation());
4279 }
4280 RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E,
4281 ReturnValueSlot ReturnValue, llvm::Value *Chain = nullptr);
4286
4287 void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl);
4289
4290 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4291 const Twine &name = "");
4292 llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
4294 const Twine &name = "");
4295 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4296 const Twine &name = "");
4297 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4298 ArrayRef<Address> args,
4299 const Twine &name = "");
4300 llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
4302 const Twine &name = "");
4303
4305 getBundlesForFunclet(llvm::Value *Callee);
4306
4307 llvm::CallBase *EmitCallOrInvoke(llvm::FunctionCallee Callee,
4309 const Twine &Name = "");
4310 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4312 const Twine &name = "");
4313 llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4314 const Twine &name = "");
4315 void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee,
4317
4319 NestedNameSpecifier *Qual,
4320 llvm::Type *Ty);
4321
4324 const CXXRecordDecl *RD);
4325
4326 llvm::Value *getAsNaturalPointerTo(Address Addr, QualType PointeeType) {
4327 return Addr.getBasePointer();
4328 }
4329
4331
4332 // Return the copy constructor name with the prefix "__copy_constructor_"
4333 // removed.
4335 CharUnits Alignment,
4336 bool IsVolatile,
4337 ASTContext &Ctx);
4338
4339 // Return the destructor name with the prefix "__destructor_" removed.
4341 CharUnits Alignment,
4342 bool IsVolatile,
4343 ASTContext &Ctx);
4344
4345 // These functions emit calls to the special functions of non-trivial C
4346 // structs.
4354
4355 RValue
4357 const CGCallee &Callee,
4358 ReturnValueSlot ReturnValue, llvm::Value *This,
4359 llvm::Value *ImplicitParam,
4360 QualType ImplicitParamTy, const CallExpr *E,
4361 CallArgList *RtlArgs);
4363 llvm::Value *This, QualType ThisTy,
4364 llvm::Value *ImplicitParam,
4365 QualType ImplicitParamTy, const CallExpr *E);
4369 const CXXMethodDecl *MD,
4371 bool HasQualifier,
4372 NestedNameSpecifier *Qualifier,
4373 bool IsArrow, const Expr *Base);
4374 // Compute the object pointer.
4376 llvm::Value *memberPtr,
4377 const MemberPointerType *memberPtrType,
4378 LValueBaseInfo *BaseInfo = nullptr,
4379 TBAAAccessInfo *TBAAInfo = nullptr);
4382
4384 const CXXMethodDecl *MD,
4387
4390
4394
4395 RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4397
4398 RValue emitRotate(const CallExpr *E, bool IsRotateRight);
4399
4400 /// Emit IR for __builtin_os_log_format.
4402
4403 /// Emit IR for __builtin_is_aligned.
4405 /// Emit IR for __builtin_align_up/__builtin_align_down.
4406 RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp);
4407
4410 CharUnits BufferAlignment);
4411
4413
4414 /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
4415 /// is unhandled by the current target.
4416 llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4418
4419 llvm::Value *EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty,
4420 const llvm::CmpInst::Predicate Fp,
4421 const llvm::CmpInst::Predicate Ip,
4422 const llvm::Twine &Name = "");
4423 llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4425 llvm::Triple::ArchType Arch);
4426 llvm::Value *EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4428 llvm::Triple::ArchType Arch);
4429 llvm::Value *EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4431 llvm::Triple::ArchType Arch);
4432 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy,
4433 QualType RTy);
4434 llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy,
4435 QualType RTy);
4436
4437 llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID,
4438 unsigned LLVMIntrinsic,
4439 unsigned AltLLVMIntrinsic,
4440 const char *NameHint,
4441 unsigned Modifier,
4442 const CallExpr *E,
4444 Address PtrOp0, Address PtrOp1,
4445 llvm::Triple::ArchType Arch);
4446
4447 llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID,
4448 unsigned Modifier, llvm::Type *ArgTy,
4449 const CallExpr *E);
4450 llvm::Value *EmitNeonCall(llvm::Function *F,
4452 const char *name,
4453 unsigned shift = 0, bool rightshift = false);
4454 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx,
4455 const llvm::ElementCount &Count);
4456 llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
4457 llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty,
4458 bool negateForRightShift);
4459 llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt,
4460 llvm::Type *Ty, bool usgn, const char *name);
4461 llvm::Value *vectorWrapScalar16(llvm::Value *Op);
4462 /// SVEBuiltinMemEltTy - Returns the memory element type for this memory
4463 /// access builtin. Only required if it can't be inferred from the base
4464 /// pointer operand.
4465 llvm::Type *SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags);
4466
4468 getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType,
4470 llvm::Type *getEltType(const SVETypeFlags &TypeFlags);
4471 llvm::ScalableVectorType *getSVEType(const SVETypeFlags &TypeFlags);
4472 llvm::ScalableVectorType *getSVEPredType(const SVETypeFlags &TypeFlags);
4473 llvm::Value *EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags,
4474 llvm::Type *ReturnType,
4476 llvm::Value *EmitSVETupleCreate(const SVETypeFlags &TypeFlags,
4477 llvm::Type *ReturnType,
4479 llvm::Value *EmitSVEAllTruePred(const SVETypeFlags &TypeFlags);
4480 llvm::Value *EmitSVEDupX(llvm::Value *Scalar);
4481 llvm::Value *EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty);
4482 llvm::Value *EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty);
4483 llvm::Value *EmitSVEPMull(const SVETypeFlags &TypeFlags,
4485 unsigned BuiltinID);
4486 llvm::Value *EmitSVEMovl(const SVETypeFlags &TypeFlags,
4488 unsigned BuiltinID);
4489 llvm::Value *EmitSVEPredicateCast(llvm::Value *Pred,
4490 llvm::ScalableVectorType *VTy);
4491 llvm::Value *EmitSVEGatherLoad(const SVETypeFlags &TypeFlags,
4493 unsigned IntID);
4494 llvm::Value *EmitSVEScatterStore(const SVETypeFlags &TypeFlags,
4496 unsigned IntID);
4497 llvm::Value *EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy,
4499 unsigned BuiltinID, bool IsZExtReturn);
4500 llvm::Value *EmitSVEMaskedStore(const CallExpr *,
4502 unsigned BuiltinID);
4503 llvm::Value *EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags,
4505 unsigned BuiltinID);
4506 llvm::Value *EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags,
4508 unsigned IntID);
4509 llvm::Value *EmitSVEStructLoad(const SVETypeFlags &TypeFlags,
4511 unsigned IntID);
4512 llvm::Value *EmitSVEStructStore(const SVETypeFlags &TypeFlags,
4514 unsigned IntID);
4515 /// FormSVEBuiltinResult - Returns the struct of scalable vectors as a wider
4516 /// vector. It extracts the scalable vector from the struct and inserts into
4517 /// the wider vector. This avoids the error when allocating space in llvm
4518 /// for struct of scalable vectors if a function returns struct.
4519 llvm::Value *FormSVEBuiltinResult(llvm::Value *Call);
4520
4521 llvm::Value *EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4522
4523 llvm::Value *EmitSMELd1St1(const SVETypeFlags &TypeFlags,
4525 unsigned IntID);
4526 llvm::Value *EmitSMEReadWrite(const SVETypeFlags &TypeFlags,
4528 unsigned IntID);
4529 llvm::Value *EmitSMEZero(const SVETypeFlags &TypeFlags,
4531 unsigned IntID);
4532 llvm::Value *EmitSMELdrStr(const SVETypeFlags &TypeFlags,
4534 unsigned IntID);
4535
4536 void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E,
4538 SVETypeFlags TypeFlags);
4539
4540 llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4541
4542 llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4543 llvm::Triple::ArchType Arch);
4544 llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4545
4547 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4548 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4549 llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4550 llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4551 llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
4552 const CallExpr *E);
4553 llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4554 llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4555 llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
4556 const CallExpr *E);
4557 llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4558 llvm::Value *EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
4560 void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope,
4561 llvm::AtomicOrdering &AO,
4562 llvm::SyncScope::ID &SSID);
4563
4564 enum class MSVCIntrin;
4565 llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E);
4566
4567 llvm::Value *EmitBuiltinAvailable(const VersionTuple &Version);
4568
4571 llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E);
4574 llvm::Value *EmitObjCCollectionLiteral(const Expr *E,
4575 const ObjCMethodDecl *MethodWithObjects);
4578 ReturnValueSlot Return = ReturnValueSlot());
4579
4580 /// Retrieves the default cleanup kind for an ARC cleanup.
4581 /// Except under -fobjc-arc-eh, ARC cleanups are normal-only.
4583 return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions
4585 }
4586
4587 // ARC primitives.
4588 void EmitARCInitWeak(Address addr, llvm::Value *value);
4590 llvm::Value *EmitARCLoadWeak(Address addr);
4592 llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored);
4593 void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
4594 void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);
4597 llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);
4598 llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value);
4599 llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value,
4600 bool resultIgnored);
4601 llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value,
4602 bool resultIgnored);
4603 llvm::Value *EmitARCRetain(QualType type, llvm::Value *value);
4604 llvm::Value *EmitARCRetainNonBlock(llvm::Value *value);
4605 llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory);
4607 void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
4608 llvm::Value *EmitARCAutorelease(llvm::Value *value);
4609 llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value);
4610 llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value);
4611 llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
4612 llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value);
4613
4614 llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType);
4615 llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value,
4616 llvm::Type *returnType);
4617 void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
4618
4619 std::pair<LValue,llvm::Value*>
4621 std::pair<LValue,llvm::Value*>
4622 EmitARCStoreStrong(const BinaryOperator *e, bool ignored);
4623 std::pair<LValue,llvm::Value*>
4625
4626 llvm::Value *EmitObjCAlloc(llvm::Value *value,
4627 llvm::Type *returnType);
4628 llvm::Value *EmitObjCAllocWithZone(llvm::Value *value,
4629 llvm::Type *returnType);
4630 llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType);
4631
4632 llvm::Value *EmitObjCThrowOperand(const Expr *expr);
4633 llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr);
4634 llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr);
4635
4636 llvm::Value *EmitARCExtendBlockObject(const Expr *expr);
4637 llvm::Value *EmitARCReclaimReturnedObject(const Expr *e,
4638 bool allowUnsafeClaim);
4639 llvm::Value *EmitARCRetainScalarExpr(const Expr *expr);
4642
4644
4646
4652
4653 void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr);
4656 void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
4657 void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr);
4658
4659 /// Emits a reference binding to the passed in expression.
4661
4662 //===--------------------------------------------------------------------===//
4663 // Expression Emission
4664 //===--------------------------------------------------------------------===//
4665
4666 // Expressions are broken into three classes: scalar, complex, aggregate.
4667
4668 /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
4669 /// scalar type, returning the result.
4670 llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
4671
4672 /// Emit a conversion from the specified type to the specified destination
4673 /// type, both of which are LLVM scalar types.
4674 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
4675 QualType DstTy, SourceLocation Loc);
4676
4677 /// Emit a conversion from the specified complex type to the specified
4678 /// destination type, where the destination type is an LLVM scalar type.
4680 QualType DstTy,
4681 SourceLocation Loc);
4682
4683 /// EmitAggExpr - Emit the computation of the specified expression
4684 /// of aggregate type. The result is computed into the given slot,
4685 /// which may be null to indicate that the value is not needed.
4686 void EmitAggExpr(const Expr *E, AggValueSlot AS);
4687
4688 /// EmitAggExprToLValue - Emit the computation of the specified expression of
4689 /// aggregate type into a temporary LValue.
4691
4692 /// Build all the stores needed to initialize an aggregate at Dest with the
4693 /// value Val.
4694 void EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile);
4695
4696 /// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
4697 /// make sure it survives garbage collection until this point.
4698 void EmitExtendGCLifetime(llvm::Value *object);
4699
4700 /// EmitComplexExpr - Emit the computation of the specified expression of
4701 /// complex type, returning the result.
4703 bool IgnoreReal = false,
4704 bool IgnoreImag = false);
4705
4706 /// EmitComplexExprIntoLValue - Emit the given expression of complex
4707 /// type and place its result into the specified l-value.
4708 void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);
4709
4710 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
4711 void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);
4712
4713 /// EmitLoadOfComplex - Load a complex number from the specified l-value.
4715
4717 llvm::Value *EmitPromotedScalarExpr(const Expr *E, QualType PromotionType);
4720
4723
4724 /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the
4725 /// global variable that has already been created for it. If the initializer
4726 /// has a different type than GV does, this may free GV and return a different
4727 /// one. Otherwise it just returns GV.
4728 llvm::GlobalVariable *
4730 llvm::GlobalVariable *GV);
4731
4732 // Emit an @llvm.invariant.start call for the given memory region.
4733 void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size);
4734
4735 /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
4736 /// variable with global storage.
4737 void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV,
4738 bool PerformInit);
4739
4740 llvm::Function *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor,
4741 llvm::Constant *Addr);
4742
4743 llvm::Function *createTLSAtExitStub(const VarDecl &VD,
4744 llvm::FunctionCallee Dtor,
4745 llvm::Constant *Addr,
4746 llvm::FunctionCallee &AtExit);
4747
4748 /// Call atexit() with a function that passes the given argument to
4749 /// the given function.
4750 void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn,
4751 llvm::Constant *addr);
4752
4753 /// Registers the dtor using 'llvm.global_dtors' for platforms that do not
4754 /// support an 'atexit()' function.
4755 void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn,
4756 llvm::Constant *addr);
4757
4758 /// Call atexit() with function dtorStub.
4759 void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub);
4760
4761 /// Call unatexit() with function dtorStub.
4762 llvm::Value *unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub);
4763
4764 /// Emit code in this function to perform a guarded variable
4765 /// initialization. Guarded initializations are used when it's not
4766 /// possible to prove that an initialization will be done exactly
4767 /// once, e.g. with a static local variable or a static data member
4768 /// of a class template.
4769 void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr,
4770 bool PerformInit);
4771
4773
4774 /// Emit a branch to select whether or not to perform guarded initialization.
4775 void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit,
4776 llvm::BasicBlock *InitBlock,
4777 llvm::BasicBlock *NoInitBlock,
4778 GuardKind Kind, const VarDecl *D);
4779
4780 /// GenerateCXXGlobalInitFunc - Generates code for initializing global
4781 /// variables.
4782 void
4783 GenerateCXXGlobalInitFunc(llvm::Function *Fn,
4784 ArrayRef<llvm::Function *> CXXThreadLocals,
4786
4787 /// GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global
4788 /// variables.
4790 llvm::Function *Fn,
4791 ArrayRef<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
4792 llvm::Constant *>>
4793 DtorsOrStermFinalizers);
4794
4795 void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
4796 const VarDecl *D,
4797 llvm::GlobalVariable *Addr,
4798 bool PerformInit);
4799
4801
4802 void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp);
4803
4804 void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true);
4805
4807
4808 //===--------------------------------------------------------------------===//
4809 // Annotations Emission
4810 //===--------------------------------------------------------------------===//
4811
4812 /// Emit an annotation call (intrinsic).
4813 llvm::Value *EmitAnnotationCall(llvm::Function *AnnotationFn,
4814 llvm::Value *AnnotatedVal,
4815 StringRef AnnotationStr,
4816 SourceLocation Location,
4817 const AnnotateAttr *Attr);
4818
4819 /// Emit local annotations for the local variable V, declared by D.
4820 void EmitVarAnnotations(const VarDecl *D, llvm::Value *V);
4821
4822 /// Emit field annotations for the given field & value. Returns the
4823 /// annotation result.
4825
4826 //===--------------------------------------------------------------------===//
4827 // Internal Helpers
4828 //===--------------------------------------------------------------------===//
4829
4830 /// ContainsLabel - Return true if the statement contains a label in it. If
4831 /// this statement is not executed normally, it not containing a label means
4832 /// that we can just remove the code.
4833 static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
4834
4835 /// containsBreak - Return true if the statement contains a break out of it.
4836 /// If the statement (recursively) contains a switch or loop with a break
4837 /// inside of it, this is fine.
4838 static bool containsBreak(const Stmt *S);
4839
4840 /// Determine if the given statement might introduce a declaration into the
4841 /// current scope, by being a (possibly-labelled) DeclStmt.
4842 static bool mightAddDeclToScope(const Stmt *S);
4843
4844 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
4845 /// to a constant, or if it does but contains a label, return false. If it
4846 /// constant folds return true and set the boolean result in Result.
4848 bool AllowLabels = false);
4849
4850 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
4851 /// to a constant, or if it does but contains a label, return false. If it
4852 /// constant folds return true and set the folded value.
4853 bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result,
4854 bool AllowLabels = false);
4855
4856 /// Ignore parentheses and logical-NOT to track conditions consistently.
4857 static const Expr *stripCond(const Expr *C);
4858
4859 /// isInstrumentedCondition - Determine whether the given condition is an
4860 /// instrumentable condition (i.e. no "&&" or "||").
4861 static bool isInstrumentedCondition(const Expr *C);
4862
4863 /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that
4864 /// increments a profile counter based on the semantics of the given logical
4865 /// operator opcode. This is used to instrument branch condition coverage
4866 /// for logical operators.
4868 llvm::BasicBlock *TrueBlock,
4869 llvm::BasicBlock *FalseBlock,
4870 uint64_t TrueCount = 0,
4872 const Expr *CntrIdx = nullptr);
4873
4874 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
4875 /// if statement) to the specified blocks. Based on the condition, this might
4876 /// try to simplify the codegen of the conditional based on the branch.
4877 /// TrueCount should be the number of times we expect the condition to
4878 /// evaluate to true based on PGO data.
4879 void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
4880 llvm::BasicBlock *FalseBlock, uint64_t TrueCount,
4882 const Expr *ConditionalOp = nullptr);
4883
4884 /// Given an assignment `*LHS = RHS`, emit a test that checks if \p RHS is
4885 /// nonnull, if \p LHS is marked _Nonnull.
4886 void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc);
4887
4888 /// An enumeration which makes it easier to specify whether or not an
4889 /// operation is a subtraction.
4890 enum { NotSubtraction = false, IsSubtraction = true };
4891
4892 /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
4893 /// detect undefined behavior when the pointer overflow sanitizer is enabled.
4894 /// \p SignedIndices indicates whether any of the GEP indices are signed.
4895 /// \p IsSubtraction indicates whether the expression used to form the GEP
4896 /// is a subtraction.
4897 llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr,
4899 bool SignedIndices,
4900 bool IsSubtraction,
4901 SourceLocation Loc,
4902 const Twine &Name = "");
4903
4905 llvm::Type *elementType, bool SignedIndices,
4906 bool IsSubtraction, SourceLocation Loc,
4907 CharUnits Align, const Twine &Name = "");
4908
4909 /// Specifies which type of sanitizer check to apply when handling a
4910 /// particular builtin.
4914 };
4915
4916 /// Emits an argument for a call to a builtin. If the builtin sanitizer is
4917 /// enabled, a runtime check specified by \p Kind is also emitted.
4918 llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind);
4919
4920 /// Emit a description of a type in a format suitable for passing to
4921 /// a runtime sanitizer handler.
4923
4924 /// Convert a value into a format suitable for passing to a runtime
4925 /// sanitizer handler.
4926 llvm::Value *EmitCheckValue(llvm::Value *V);
4927
4928 /// Emit a description of a source location in a format suitable for
4929 /// passing to a runtime sanitizer handler.
4931
4934
4935 /// Create a basic block that will either trap or call a handler function in
4936 /// the UBSan runtime with the provided arguments, and create a conditional
4937 /// branch to it.
4938 void EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
4940 ArrayRef<llvm::Value *> DynamicArgs);
4941
4942 /// Emit a slow path cross-DSO CFI check which calls __cfi_slowpath
4943 /// if Cond if false.
4944 void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond,
4945 llvm::ConstantInt *TypeId, llvm::Value *Ptr,
4946 ArrayRef<llvm::Constant *> StaticArgs);
4947
4948 /// Emit a reached-unreachable diagnostic if \p Loc is valid and runtime
4949 /// checking is enabled. Otherwise, just emit an unreachable instruction.
4951
4952 /// Create a basic block that will call the trap intrinsic, and emit a
4953 /// conditional branch to it, for the -ftrapv checks.
4954 void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID);
4955
4956 /// Emit a call to trap or debugtrap and attach function attribute
4957 /// "trap-func-name" if specified.
4958 llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID);
4959
4960 /// Emit a stub for the cross-DSO CFI check function.
4962
4963 /// Emit a cross-DSO CFI failure handling function.
4965
4966 /// Create a check for a function parameter that may potentially be
4967 /// declared as non-null.
4969 AbstractCallee AC, unsigned ParmNum);
4970
4972 SourceLocation ArgLoc, AbstractCallee AC,
4973 unsigned ParmNum);
4974
4975 /// EmitCallArg - Emit a single call argument.
4976 void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType);
4977
4978 /// EmitDelegateCallArg - We are performing a delegate call; that
4979 /// is, the current function is delegating to another one. Produce
4980 /// a r-value suitable for passing the given parameter.
4981 void EmitDelegateCallArg(CallArgList &args, const VarDecl *param,
4982 SourceLocation loc);
4983
4984 /// SetFPAccuracy - Set the minimum required accuracy of the given floating
4985 /// point operation, expressed as the maximum relative error in ulp.
4986 void SetFPAccuracy(llvm::Value *Val, float Accuracy);
4987
4988 /// Set the minimum required accuracy of the given sqrt operation
4989 /// based on CodeGenOpts.
4990 void SetSqrtFPAccuracy(llvm::Value *Val);
4991
4992 /// Set the minimum required accuracy of the given sqrt operation based on
4993 /// CodeGenOpts.
4994 void SetDivFPAccuracy(llvm::Value *Val);
4995
4996 /// Set the codegen fast-math flags.
4997 void SetFastMathFlags(FPOptions FPFeatures);
4998
4999 // Truncate or extend a boolean vector to the requested number of elements.
5000 llvm::Value *emitBoolVecConversion(llvm::Value *SrcVec,
5001 unsigned NumElementsDst,
5002 const llvm::Twine &Name = "");
5003 // Adds a convergence_ctrl token to |Input| and emits the required parent
5004 // convergence instructions.
5005 llvm::CallBase *addControlledConvergenceToken(llvm::CallBase *Input);
5006
5007private:
5008 // Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
5009 // as it's parent convergence instr.
5010 llvm::IntrinsicInst *emitConvergenceLoopToken(llvm::BasicBlock *BB,
5011 llvm::Value *ParentToken);
5012 // Adds a convergence_ctrl token with |ParentToken| as parent convergence
5013 // instr to the call |Input|.
5014 llvm::CallBase *addConvergenceControlToken(llvm::CallBase *Input,
5015 llvm::Value *ParentToken);
5016 // Find the convergence_entry instruction |F|, or emits ones if none exists.
5017 // Returns the convergence instruction.
5018 llvm::IntrinsicInst *getOrEmitConvergenceEntryToken(llvm::Function *F);
5019 // Find the convergence_loop instruction for the loop defined by |LI|, or
5020 // emits one if none exists. Returns the convergence instruction.
5021 llvm::IntrinsicInst *getOrEmitConvergenceLoopToken(const LoopInfo *LI);
5022
5023private:
5024 llvm::MDNode *getRangeForLoadFromType(QualType Ty);
5025 void EmitReturnOfRValue(RValue RV, QualType Ty);
5026
5027 void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New);
5028
5030 DeferredReplacements;
5031
5032 /// Set the address of a local variable.
5033 void setAddrOfLocalVar(const VarDecl *VD, Address Addr) {
5034 assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!");
5035 LocalDeclMap.insert({VD, Addr});
5036 }
5037
5038 /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
5039 /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
5040 ///
5041 /// \param AI - The first function argument of the expansion.
5042 void ExpandTypeFromArgs(QualType Ty, LValue Dst,
5043 llvm::Function::arg_iterator &AI);
5044
5045 /// ExpandTypeToArgs - Expand an CallArg \arg Arg, with the LLVM type for \arg
5046 /// Ty, into individual arguments on the provided vector \arg IRCallArgs,
5047 /// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand.
5048 void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,
5050 unsigned &IRCallArgPos);
5051
5052 std::pair<llvm::Value *, llvm::Type *>
5053 EmitAsmInput(const TargetInfo::ConstraintInfo &Info, const Expr *InputExpr,
5054 std::string &ConstraintStr);
5055
5056 std::pair<llvm::Value *, llvm::Type *>
5057 EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, LValue InputValue,
5058 QualType InputType, std::string &ConstraintStr,
5059 SourceLocation Loc);
5060
5061 /// Attempts to statically evaluate the object size of E. If that
5062 /// fails, emits code to figure the size of E out for us. This is
5063 /// pass_object_size aware.
5064 ///
5065 /// If EmittedExpr is non-null, this will use that instead of re-emitting E.
5066 llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
5067 llvm::IntegerType *ResType,
5068 llvm::Value *EmittedE,
5069 bool IsDynamic);
5070
5071 /// Emits the size of E, as required by __builtin_object_size. This
5072 /// function is aware of pass_object_size parameters, and will act accordingly
5073 /// if E is a parameter with the pass_object_size attribute.
5074 llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type,
5075 llvm::IntegerType *ResType,
5076 llvm::Value *EmittedE,
5077 bool IsDynamic);
5078
5079 llvm::Value *emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
5080 llvm::IntegerType *ResType);
5081
5082 void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D,
5083 Address Loc);
5084
5085public:
5086 enum class EvaluationOrder {
5087 ///! No language constraints on evaluation order.
5088 Default,
5089 ///! Language semantics require left-to-right evaluation.
5091 ///! Language semantics require right-to-left evaluation.
5093 };
5094
5095 // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
5096 // an ObjCMethodDecl.
5098 llvm::PointerUnion<const FunctionProtoType *, const ObjCMethodDecl *> P;
5099
5102 };
5103
5105 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
5107 unsigned ParamsToSkip = 0,
5109
5110 /// EmitPointerWithAlignment - Given an expression with a pointer type,
5111 /// emit the value and compute our best estimate of the alignment of the
5112 /// pointee.
5113 ///
5114 /// \param BaseInfo - If non-null, this will be initialized with
5115 /// information about the source of the alignment and the may-alias
5116 /// attribute. Note that this function will conservatively fall back on
5117 /// the type when it doesn't recognize the expression and may-alias will
5118 /// be set to false.
5119 ///
5120 /// One reasonable way to use this information is when there's a language
5121 /// guarantee that the pointer must be aligned to some stricter value, and
5122 /// we're simply trying to ensure that sufficiently obvious uses of under-
5123 /// aligned objects don't get miscompiled; for example, a placement new
5124 /// into the address of a local variable. In such a case, it's quite
5125 /// reasonable to just ignore the returned alignment when it isn't from an
5126 /// explicit source.
5127 Address
5128 EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo = nullptr,
5129 TBAAAccessInfo *TBAAInfo = nullptr,
5130 KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
5131
5132 /// If \p E references a parameter with pass_object_size info or a constant
5133 /// array size modifier, emit the object size divided by the size of \p EltTy.
5134 /// Otherwise return null.
5135 llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy);
5136
5137 void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
5138
5140 llvm::Function *Function;
5141 struct Conds {
5142 StringRef Architecture;
5144
5145 Conds(StringRef Arch, ArrayRef<StringRef> Feats)
5146 : Architecture(Arch), Features(Feats.begin(), Feats.end()) {}
5148
5149 MultiVersionResolverOption(llvm::Function *F, StringRef Arch,
5150 ArrayRef<StringRef> Feats)
5151 : Function(F), Conditions(Arch, Feats) {}
5152 };
5153
5154 // Emits the body of a multiversion function's resolver. Assumes that the
5155 // options are already sorted in the proper order, with the 'default' option
5156 // last (if it exists).
5157 void EmitMultiVersionResolver(llvm::Function *Resolver,
5159 void
5160 EmitX86MultiVersionResolver(llvm::Function *Resolver,
5162 void
5163 EmitAArch64MultiVersionResolver(llvm::Function *Resolver,
5165
5166private:
5167 QualType getVarArgType(const Expr *Arg);
5168
5169 void EmitDeclMetadata();
5170
5171 BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType,
5172 const AutoVarEmission &emission);
5173
5174 void AddObjCARCExceptionMetadata(llvm::Instruction *Inst);
5175
5176 llvm::Value *GetValueForARMHint(unsigned BuiltinID);
5177 llvm::Value *EmitX86CpuIs(const CallExpr *E);
5178 llvm::Value *EmitX86CpuIs(StringRef CPUStr);
5179 llvm::Value *EmitX86CpuSupports(const CallExpr *E);
5180 llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs);
5181 llvm::Value *EmitX86CpuSupports(std::array<uint32_t, 4> FeatureMask);
5182 llvm::Value *EmitX86CpuInit();
5183 llvm::Value *FormX86ResolverCondition(const MultiVersionResolverOption &RO);
5184 llvm::Value *EmitAArch64CpuInit();
5185 llvm::Value *
5186 FormAArch64ResolverCondition(const MultiVersionResolverOption &RO);
5187 llvm::Value *EmitAArch64CpuSupports(const CallExpr *E);
5188 llvm::Value *EmitAArch64CpuSupports(ArrayRef<StringRef> FeatureStrs);
5189};
5190
5193 if (!needsSaving(value)) return saved_type(value, false);
5194
5195 // Otherwise, we need an alloca.
5196 auto align = CharUnits::fromQuantity(
5197 CGF.CGM.getDataLayout().getPrefTypeAlign(value->getType()));
5198 Address alloca =
5199 CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save");
5200 CGF.Builder.CreateStore(value, alloca);
5201
5202 return saved_type(alloca.emitRawPointer(CGF), true);
5203}
5204
5206 saved_type value) {
5207 // If the value says it wasn't saved, trust that it's still dominating.
5208 if (!value.getInt()) return value.getPointer();
5209
5210 // Otherwise, it should be an alloca instruction, as set up in save().
5211 auto alloca = cast<llvm::AllocaInst>(value.getPointer());
5212 return CGF.Builder.CreateAlignedLoad(alloca->getAllocatedType(), alloca,
5213 alloca->getAlign());
5214}
5215
5216} // end namespace CodeGen
5217
5218// Map the LangOption for floating point exception behavior into
5219// the corresponding enum in the IR.
5220llvm::fp::ExceptionBehavior
5222} // end namespace clang
5223
5224#endif
Enums/classes describing ABI related information about constructors, destructors and thunks.
#define V(N, I)
Definition: ASTContext.h:3284
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition: CFG.cpp:2679
Defines the clang::Expr interface and subclasses for C++ expressions.
const CFGBlock * Block
Definition: HTMLLogger.cpp:153
#define X(type, name)
Definition: Value.h:143
llvm::MachO::Architecture Architecture
Definition: MachO.h:27
llvm::MachO::Target Target
Definition: MachO.h:48
Defines some OpenMP-specific enums and functions.
const char * Data
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
C Language Family Type Representation.
StateNode * Previous
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:182
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4141
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition: Expr.h:6734
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2664
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3514
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition: Stmt.h:3100
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6437
Attr - This represents one attribute.
Definition: Attr.h:42
Represents an attribute applied to a statement.
Definition: Stmt.h:2080
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4241
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:4279
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:4276
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3840
static bool isLogicalOp(Opcode Opc)
Definition: Expr.h:3972
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6173
BreakStmt - This represents a break.
Definition: Stmt.h:2980
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:231
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1485
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1540
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1264
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1371
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2491
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:478
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:1731
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2234
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2610
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a C++ temporary.
Definition: ExprCXX.h:1453
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1202
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:845
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:1062
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2820
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition: Stmt.h:3770
This captures a statement into a function.
Definition: Stmt.h:3757
CaseStmt - Represent a case statement.
Definition: Stmt.h:1801
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3483
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3550
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
Represents a 'co_await' expression.
Definition: ExprCXX.h:5151
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:111
llvm::Value * getBasePointer() const
Definition: Address.h:170
static Address invalid()
Definition: Address.h:153
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:220
CharUnits getAlignment() const
Definition: Address.h:166
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition: Address.h:184
bool hasOffset() const
Definition: Address.h:214
void setAlignment(CharUnits Value)
Definition: Address.h:168
llvm::Value * getOffset() const
Definition: Address.h:216
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:158
bool isValid() const
Definition: Address.h:154
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:176
An aggregate value slot.
Definition: CGValue.h:512
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Definition: CGValue.h:580
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:595
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:824
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:156
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:136
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition: CGBuilder.h:128
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
All available information about a concrete callee.
Definition: CGCall.h:62
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
CGFunctionInfo - Class to encapsulate the information about a function definition.
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:258
An abstract representation of regular/ObjC call/message targets.
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.
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.
RAII for correct setting/restoring of CapturedStmtInfo.
CGCapturedStmtRAII(CodeGenFunction &CGF, CGCapturedStmtInfo *NewCapturedStmtInfo)
CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E)
void Emit(CodeGenFunction &CGF, Flags flags) override
Emit the cleanup.
CallLifetimeEnd(RawAddress addr, llvm::Value *size)
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, Expr *refExpr) const
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
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.
InlinedInheritingConstructorScope(CodeGenFunction &CGF, GlobalDecl GD)
void rescopeLabels()
Change the cleanup scope of the labels in this lexical scope to match the scope of the enclosing cont...
Definition: CGStmt.cpp:680
LexicalScope(CodeGenFunction &CGF, SourceRange Range)
Enter a new cleanup scope.
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
~LexicalScope()
Exit this cleanup scope, emitting any accumulated cleanups.
RAII for preserving necessary info during inlined region body codegen.
InlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, llvm::BasicBlock &FiniBB)
void Emit(CodeGenFunction &CGF, Flags) override
Emit the cleanup.
RAII for preserving necessary info during Outlined region body codegen.
OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, llvm::BasicBlock &RetBB)
Controls insertion of cancellation exit blocks in worksharing constructs.
OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel)
Save/restore original map of previously emitted local vars in case when we need to duplicate emission...
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)
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
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...
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
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.
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
An RAII object to record that we're evaluating a statement expression.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitForStmt(const ForStmt &S, ArrayRef< const Attr * > Attrs=std::nullopt)
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor)
llvm::Value * EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E, llvm::Triple::ArchType Arch)
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
EHScopeStack::stable_iterator CurrentCleanupScopeDepth
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function * > CXXThreadLocals, ConstantAddress Guard=ConstantAddress::invalid())
GenerateCXXGlobalInitFunc - Generates code for initializing global variables.
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
RValue EmitLoadOfGlobalRegLValue(LValue LV)
void EmitGotoStmt(const GotoStmt &S)
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E)
void EmitDestructorBody(FunctionArgList &Args)
void EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, const OpenMPDirectiveKind CapturedRegion, const RegionCodeGenTy &BodyGen, const TaskGenTy &TaskGen, OMPTaskDataTy &Data)
void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD)
llvm::BasicBlock * getEHDispatchBlock(EHScopeStack::stable_iterator scope)
void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S)
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
llvm::Value * EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E)
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, Address This, CallArgList &Args, AggValueSlot::Overlap_t Overlap, SourceLocation Loc, bool NewPointerIsChecked)
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...
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
void EmitARCDestroyWeak(Address addr)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
void EmitOMPParallelGenericLoopDirective(const OMPLoopDirective &S)
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...
llvm::Value * EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
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())
void EmitAsanPrologueOrEpilogue(bool Prologue)
llvm::Value * EmitARCExtendBlockObject(const Expr *expr)
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
llvm::Value * EmitNonNullRValueCheck(RValue RV, QualType T)
Create a check that a scalar RValue is non-null.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
LValue EmitCastLValue(const CastExpr *E)
void EnterSEHTryStmt(const SEHTryStmt &S)
CurrentSourceLocExprScope CurSourceLocExprScope
Source location information about the default argument or member initializer expression we're evaluat...
void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl)
llvm::Value * EmitSVEPredicateCast(llvm::Value *Pred, llvm::ScalableVectorType *VTy)
Address getExceptionSlot()
Returns a pointer to the function's exception object and selector slot, which is assigned in every la...
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
RawAddress CreateMemTemp(QualType T, CharUnits Align, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
bool isBinaryLogicalOp(const Expr *E) const
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
void VolatilizeTryBlocks(llvm::BasicBlock *BB, llvm::SmallPtrSet< llvm::BasicBlock *, 10 > &V)
void EmitLambdaInAllocaImplFn(const CXXMethodDecl *CallOp, const CGFunctionInfo **ImplFnInfo, llvm::Function **ImplFn)
llvm::Function * GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, const SEHFinallyStmt &Finally)
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
llvm::Function * GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, const SEHExceptStmt &Except)
static Destroyer destroyNonTrivialCStruct
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...
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee, const ThunkInfo *Thunk, bool IsUnprototyped)
void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, const FunctionArgList &Args, SourceLocation Loc)
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, const FunctionArgList &Args)
llvm::CallBase * addControlledConvergenceToken(llvm::CallBase *Input)
llvm::Function * GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
SanitizerSet SanOpts
Sanitizers enabled for this function.
RValue EmitBuiltinIsAligned(const CallExpr *E)
Emit IR for __builtin_is_aligned.
LValue EmitCoawaitLValue(const CoawaitExpr *E)
llvm::BasicBlock * getInvokeDestImpl()
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
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 EmitIfStmt(const IfStmt &S)
void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, CallArgList &CallArgs, const CGFunctionInfo *CallOpFnInfo=nullptr, llvm::Constant *CallOpFn=nullptr)
void EmitOMPOrderedDirective(const OMPOrderedDirective &S)
void EmitOMPTargetDirective(const OMPTargetDirective &S)
void PushDestructorCleanup(const CXXDestructorDecl *Dtor, QualType T, Address Addr)
PushDestructorCleanup - Push a cleanup to call the complete-object variant of the given destructor on...
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...
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
bool IsOutlinedSEHHelper
True if the current function is an outlined SEH helper.
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.
bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
void EmitARCMoveWeak(Address dst, Address src)
LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, llvm::Value *&Result)
void EmitOMPReductionClauseInit(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope, bool ForInscan=false)
Emit initial code for reduction variables.
void EmitOMPAtomicDirective(const OMPAtomicDirective &S)
void EmitVTableAssumptionLoad(const VPtr &vptr, Address This)
Emit assumption that vptr load == global vtable.
void unprotectFromPeepholes(PeepholeProtection protection)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt)
void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S)
llvm::Value * EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &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...
void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, const ObjCPropertyImplDecl *propImpl, const ObjCMethodDecl *GetterMothodDecl, llvm::Constant *AtomicHelperFn)
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, SVETypeFlags TypeFlags)
llvm::Value * EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
llvm::Value * EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
bool ShouldInstrumentFunction()
ShouldInstrumentFunction - Return true if the current function should be instrumented with __cyg_prof...
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
static void EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDirective &S)
Emit device code for the target teams directive.
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
void callCStructDefaultConstructor(LValue Dst)
static bool hasScalarEvaluationKind(QualType T)
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
llvm::Value * EmitObjCAutoreleasePoolPush()
bool isCleanupPadScope() const
Returns true while emitting a cleanuppad.
llvm::Value * EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx)
void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
llvm::Value * EmitARCRetainAutoreleaseNonBlock(llvm::Value *value)
void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr)
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
AwaitSuspendWrapperInfo CurAwaitSuspendWrapper
llvm::function_ref< std::pair< llvm::Value *, llvm::Value * >(CodeGenFunction &, const OMPExecutableDirective &S, Address LB, Address UB)> CodeGenDispatchBoundsTy
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
CGCapturedStmtInfo * CapturedStmtInfo
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
BuiltinCheckKind
Specifies which type of sanitizer check to apply when handling a particular builtin.
void EmitIndirectGotoStmt(const IndirectGotoStmt &S)
void EmitDecl(const Decl &D)
EmitDecl - Emit a declaration.
LValue MakeNaturalAlignPointeeRawAddrLValue(llvm::Value *V, QualType T)
Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known to be unsigned.
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.
void EmitCXXTryStmt(const CXXTryStmt &S)
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.
std::pair< LValue, llvm::Value * > EmitARCStoreStrong(const BinaryOperator *e, bool ignored)
void EmitKCFIOperandBundle(const CGCallee &Callee, SmallVectorImpl< llvm::OperandBundleDef > &Bundles)
llvm::Value * EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind)
Emits an argument for a call to a builtin.
bool EmitSimpleStmt(const Stmt *S, ArrayRef< const Attr * > Attrs)
EmitSimpleStmt - Try to emit a "simple" statement which does not necessarily require an insertion poi...
void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk, bool IsUnprototyped)
Generate a thunk for the given method.
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
llvm::Value * EmitARCRetainAutoreleasedReturnValue(llvm::Value *value)
void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue, llvm::Value *TheCheck, llvm::Instruction *Assumption)
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
static void EmitOMPTargetTeamsDistributeDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeDirective &S)
Emit device code for the target teams distribute directive.
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Load a pointer with type PtrTy stored at address Ptr.
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
static void EmitOMPTargetParallelForSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelForSimdDirective &S)
Emit device code for the target parallel for simd directive.
llvm::Value * EmitObjCAllocWithZone(llvm::Value *value, llvm::Type *returnType)
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, llvm::Value *NumElements, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization=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...
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
llvm::Value * EmitSVEGatherLoad(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization=false)
void popCatchScope()
popCatchScope - Pops the catch scope at the top of the EHScope stack, emitting any required code (oth...
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual)
Determine whether a base class initialization may overlap some other object.
void EmitLabel(const LabelDecl *D)
EmitLabel - Emit the block for the given label.
const OMPExecutableDirective * OMPParentLoopDirectiveForScan
Parent loop-based directive for scan directive.
llvm::Value * EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &S)
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
void EmitOMPTaskDirective(const OMPTaskDirective &S)
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
void EmitOMPScanDirective(const OMPScanDirective &S)
void EmitAnyExprToExn(const Expr *E, Address Addr)
void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S)
JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind)
llvm::Value * EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
void EmitAArch64MultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
void EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S)
llvm::Value * EmitARCAutoreleaseReturnValue(llvm::Value *value)
llvm::Value * EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void GenerateObjCMethod(const ObjCMethodDecl *OMD)
void EmitOMPUseDevicePtrClause(const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope, const llvm::DenseMap< const ValueDecl *, llvm::Value * > CaptureDeviceAddrMap)
RValue emitBuiltinOSLogFormat(const CallExpr &E)
Emit IR for __builtin_os_log_format.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
bool isSEHTryScope() const
Returns true inside SEH __try blocks.
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.
llvm::Value * EmitARCAutorelease(llvm::Value *value)
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
void EmitExtendGCLifetime(llvm::Value *object)
EmitExtendGCLifetime - Given a pointer to an Objective-C object, make sure it survives garbage collec...
llvm::Value * EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart)
Emits a call to an LLVM variable-argument intrinsic, either llvm.va_start or llvm....
void EmitOMPDistributeLoop(const OMPLoopDirective &S, const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr)
Emit code for the distribute loop-based directive.
void EmitARCNoopIntrinsicUse(ArrayRef< llvm::Value * > values)
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
llvm::Value * EmitSVEMaskedStore(const CallExpr *, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
llvm::Constant * GenerateObjCAtomicGetterCopyHelperFunction(const ObjCPropertyImplDecl *PID)
void callCStructCopyAssignmentOperator(LValue Dst, LValue Src)
void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S)
void callCStructMoveConstructor(LValue Dst, LValue Src)
llvm::Value * EmitIvarOffset(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
llvm::Value * EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty)
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, llvm::Value *ParentFP, llvm::Value *EntryEBP)
llvm::Value * getAsNaturalPointerTo(Address Addr, QualType PointeeType)
llvm::BasicBlock * getEHResumeBlock(bool isCleanup)
static void EmitOMPTargetDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetDirective &S)
Emit device code for the target directive.
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits())
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
void callCStructCopyConstructor(LValue Dst, LValue Src)
void EmitCaseStmt(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, const llvm::function_ref< RValue(RValue)> &UpdateOp, bool IsVolatile)
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
llvm::Value * EmitSEHExceptionInfo()
RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp)
Emit IR for __builtin_align_up/__builtin_align_down.
llvm::Value * EmitARCLoadWeakRetained(Address addr)
void EmitDefaultStmt(const DefaultStmt &S, ArrayRef< const Attr * > Attrs)
const LangOptions & getLangOpts() const
llvm::Value * LoadPassedObjectSize(const Expr *E, QualType EltTy)
If E references a parameter with pass_object_size info or a constant array size modifier,...
static void EmitOMPTargetSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetSimdDirective &S)
Emit device code for the target simd directive.
void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S)
llvm::Value * EmitObjCProtocolExpr(const ObjCProtocolExpr *E)
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
llvm::Value * EmitObjCStringLiteral(const ObjCStringLiteral *E)
void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope, llvm::AtomicOrdering &AO, llvm::SyncScope::ID &SSID)
void EmitOMPPrivateLoopCounters(const OMPLoopDirective &S, OMPPrivateScope &LoopScope)
Emit initial code for loop counters of loop-based directives.
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
void EmitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &S)
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
LValue EmitInitListLValue(const InitListExpr *E)
llvm::Value * EmitARCRetainAutorelease(QualType type, llvm::Value *value)
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, const CGCallee &Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, CallArgList *RtlArgs)
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 EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, Address Addr, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
llvm::Function * generateAwaitSuspendWrapper(Twine const &CoroName, Twine const &SuspendPointName, CoroutineSuspendExpr const &S)
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S)
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
static bool isInstrumentedCondition(const Expr *C)
isInstrumentedCondition - Determine whether the given condition is an instrumentable condition (i....
void EmitX86MultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
SmallVector< llvm::Value *, 8 > ObjCEHValueStack
ObjCEHValueStack - Stack of Objective-C exception values, used for rethrows.
void EmitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &S)
bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
void EmitFunctionBody(const Stmt *Body)
VlaSizePair getVLAElements1D(QualType vla)
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...
llvm::Value * EmitSVETupleCreate(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
const CodeGen::CGBlockInfo * BlockInfo
void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S)
void EmitAggregateCopyCtor(LValue Dest, LValue Src, AggValueSlot::Overlap_t MayOverlap)
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset)
Emit a type checked load from the given vtable.
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.
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
llvm::Value * EmitObjCBoxedExpr(const ObjCBoxedExpr *E)
llvm::AllocaInst * EHSelectorSlot
The selector slot.
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
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...
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, const Twine &name="")
void emitByrefStructureInit(const AutoVarEmission &emission)
void SimplifyForwardingBlocks(llvm::BasicBlock *BB)
SimplifyForwardingBlocks - If the given basic block is only a branch to another basic block,...
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
void callCStructDestructor(LValue Dst)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
llvm::Value * EmitObjCRetainNonBlock(llvm::Value *value, llvm::Type *returnType)
llvm::Value * GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, bool Delegating)
GetVTTParameter - Return the VTT parameter that should be passed to a base constructor/destructor wit...
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
void EmitOMPParallelDirective(const OMPParallelDirective &S)
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...
llvm::Value * EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType)
Address EmitExtVectorElementLValue(LValue V)
void EmitOMPSimdFinal(const OMPLoopDirective &D, const llvm::function_ref< llvm::Value *(CodeGenFunction &)> CondGen)
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...
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.
void EmitBlockAfterUses(llvm::BasicBlock *BB)
EmitBlockAfterUses - Emit the given block somewhere hopefully near its uses, and leave the insertion ...
llvm::Value * EmitSMELdrStr(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
void SetDivFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
void EmitContinueStmt(const ContinueStmt &S)
void setCurrentProfileCount(uint64_t Count)
Set the profiler's current count.
llvm::BasicBlock * getTerminateFunclet()
getTerminateLandingPad - Return a cleanup funclet that just calls terminate.
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo, bool isInit=false, bool isNontemporal=false)
bool InNoMergeAttributedStmt
True if the current statement has nomerge attribute.
LValue EmitCallExprLValue(const CallExpr *E)
LValue EmitUnsupportedLValue(const Expr *E, const char *Name)
EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
llvm::Value * FormSVEBuiltinResult(llvm::Value *Call)
FormSVEBuiltinResult - Returns the struct of scalable vectors as a wider vector.
llvm::Value * EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx, const llvm::ElementCount &Count)
VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass)
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.
llvm::Type * ConvertTypeForMem(QualType T)
llvm::Function * createTLSAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr, llvm::FunctionCallee &AtExit)
Address EmitCheckedInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *elementType, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, CharUnits Align, const Twine &Name="")
void EmitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &S)
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
LValue MakeAddrLValueWithoutTBAA(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitAutoVarInit(const AutoVarEmission &emission)
llvm::BasicBlock * getUnreachableBlock()
void EmitOMPForSimdDirective(const OMPForSimdDirective &S)
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 GenerateOpenMPCapturedVars(const CapturedStmt &S, SmallVectorImpl< llvm::Value * > &CapturedVars)
void EmitNonNullArgCheck(Address Addr, QualType ArgType, SourceLocation ArgLoc, AbstractCallee AC, unsigned ParmNum)
llvm::Value * EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool isPointerKnownNonNull(const Expr *E)
RawAddress CreateMemTempWithoutCast(QualType T, CharUnits Align, const Twine &Name="tmp")
llvm::Value * EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID, bool IsZExtReturn)
bool AlwaysEmitXRayCustomEvents() const
AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit XRay custom event handling c...
llvm::SmallVector< const JumpDest *, 2 > SEHTryEpilogueStack
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
JumpDest ReturnBlock
ReturnBlock - Unified return block.
DominatingValue< T >::saved_type saveValueInCond(T value)
const llvm::function_ref< void(CodeGenFunction &, llvm::Function *, const OMPTaskDataTy &)> TaskGenTy
static void EmitOMPTargetTeamsGenericLoopDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsGenericLoopDirective &S)
Emit device code for the target teams loop directive.
bool checkIfLoopMustProgress(bool HasConstantCond)
Returns true if a loop must make progress, which means the mustprogress attribute can be added.
llvm::Value * ExceptionSlot
The exception slot.
unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex)
Get the record field index as represented in debug info.
LValue EmitLValueForField(LValue Base, const FieldDecl *Field)
llvm::Value * EmitARCRetainBlock(llvm::Value *value, bool mandatory)
QualType TypeOfSelfObject()
TypeOfSelfObject - Return type of object that this self represents.
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
llvm::Value * EmitSVEDupX(llvm::Value *Scalar)
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...
void EmitOMPFlushDirective(const OMPFlushDirective &S)
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
llvm::Value * EmitObjCArrayLiteral(const ObjCArrayLiteral *E)
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
@ Default
! No language constraints on evaluation order.
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
void EmitAttributedStmt(const AttributedStmt &S)
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
llvm::BasicBlock * OMPBeforeScanBlock
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...
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
void EmitOMPCancelDirective(const OMPCancelDirective &S)
llvm::SmallPtrSet< const CXXRecordDecl *, 4 > VisitedVirtualBasesSetTy
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective &S)
void EmitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &S)
void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
void EmitAtomicInit(Expr *E, LValue lvalue)
static const Expr * stripCond(const Expr *C)
Ignore parentheses and logical-NOT to track conditions consistently.
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
static std::string getNonTrivialDestructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
llvm::DenseMap< const Decl *, Address > DeclMapTy
void EmitCaseStmtRange(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
PeepholeProtection protectFromPeepholes(RValue rvalue)
protectFromPeepholes - Protect a value that we're intending to store to the side, but which will prob...
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr)
llvm::Value * EmitARCLoadWeak(Address addr)
const TargetInfo & getTarget() const
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
llvm::Value * EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy, QualType RTy)
void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S)
static void EmitOMPTargetTeamsDistributeParallelForDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeParallelForDirective &S)
void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy, SourceLocation Loc)
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
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.
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
llvm::Constant * GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo)
llvm::Value * vectorWrapScalar16(llvm::Value *Op)
llvm::Function * LookupNeonLLVMIntrinsic(unsigned IntrinsicID, unsigned Modifier, llvm::Type *ArgTy, const CallExpr *E)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
void EmitLabelStmt(const LabelStmt &S)
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Value *Chain=nullptr)
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.
llvm::Value * EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType)
LValue EmitVAArgExprLValue(const VAArgExpr *E)
llvm::Value * EmitSEHExceptionCode()
bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, SourceLocation Loc)
Check if the scalar Value is within the valid range for the given type Ty.
llvm::Value * EmitObjCCollectionLiteral(const Expr *E, const ObjCMethodDecl *MethodWithObjects)
void EmitOMPDepobjDirective(const OMPDepobjDirective &S)
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
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...
llvm::Value * EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
EmitTargetBuiltinExpr - Emit the given builtin call.
llvm::Value * EmitCountedByFieldExpr(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)
Build an expression accessing the "counted_by" field.
void GenerateCXXGlobalCleanUpFunc(llvm::Function *Fn, ArrayRef< std::tuple< llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant * > > DtorsOrStermFinalizers)
GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global variables.
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
const Expr * RetExpr
If a return statement is being visited, this holds the return statment's result expression.
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init)
llvm::Value * EmitObjCThrowOperand(const Expr *expr)
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
void pushCleanupAfterFullExpr(CleanupKind Kind, As... A)
Queue a cleanup to be pushed after finishing the current full-expression, potentially with an active ...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
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....
void EmitOMPSingleDirective(const OMPSingleDirective &S)
std::pair< LValue, llvm::Value * > EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored)
ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType)
void pushFullExprCleanup(CleanupKind kind, As... A)
pushFullExprCleanup - Push a cleanup to be run at the end of the current full-expression.
RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID)
void initFullExprCleanupWithFlag(RawAddress ActiveFlag)
RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
llvm::Value * EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &S)
RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E)
void EmitReturnValueCheck(llvm::Value *RV)
Emit a test that checks if the return value RV is nonnull.
llvm::BasicBlock * getInvokeDest()
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
Address mergeAddressesInConditionalExpr(Address LHS, Address RHS, llvm::BasicBlock *LHSBlock, llvm::BasicBlock *RHSBlock, llvm::BasicBlock *MergeBlock, QualType MergedType)
llvm::CanonicalLoopInfo * EmitOMPCollapsedCanonicalLoopNest(const Stmt *S, int Depth)
Emit the Stmt S and return its topmost canonical loop, if any.
LValue EmitUnaryOpLValue(const UnaryOperator *E)
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
llvm::Value * LoadObjCSelf()
LoadObjCSelf - Load the value of self.
bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
RValue EmitUnsupportedRValue(const Expr *E, const char *Name)
EmitUnsupportedRValue - Emit a dummy r-value using the type of E and issue an ErrorUnsupported style ...
void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO, bool IsVolatile, bool isInit)
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
llvm::Value * EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
void EmitARCCopyWeak(Address dst, Address src)
void maybeResetMCDCCondBitmap(const Expr *E)
Zero-init the MCDC temp value.
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)
getAccessedFieldNo - Given an encoded value and a result number, return the input field number being ...
void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D)
Emit simple code for OpenMP directives in Simd-only mode.
void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc)
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
void PushDestructorCleanup(QualType T, Address Addr)
PushDestructorCleanup - Push a cleanup to call the complete-object destructor of an object of the giv...
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
void EmitOMPDistributeDirective(const OMPDistributeDirective &S)
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
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.
void EmitOMPParallelForDirective(const OMPParallelForDirective &S)
void EmitOMPTeamsDirective(const OMPTeamsDirective &S)
bool ShouldSkipSanitizerInstrumentation()
ShouldSkipSanitizerInstrumentation - Return true if the current function should not be instrumented w...
uint64_t getCurrentProfileCount()
Get the profiler's current count.
void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::Value *Index, QualType IndexType, QualType IndexedType, bool Accessed)
llvm::Value * EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty)
llvm::Value * EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
SmallVector< const BinaryOperator *, 16 > MCDCLogOpStack
Stack to track the Logical Operator recursion nest for MC/DC.
llvm::Value * EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, const llvm::CmpInst::Predicate Fp, const llvm::CmpInst::Predicate Ip, const llvm::Twine &Name="")
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
void defaultInitNonTrivialCStructVar(LValue Dst)
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.
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
RValue EmitLoadOfExtVectorElementLValue(LValue V)
llvm::ScalableVectorType * getSVEType(const SVETypeFlags &TypeFlags)
void EmitOMPUnrollDirective(const OMPUnrollDirective &S)
void EmitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &S)
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S)
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
RValue emitRotate(const CallExpr *E, bool IsRotateRight)
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
Annotate the function with an attribute that disables TSan checking at runtime.
void EmitSwitchStmt(const SwitchStmt &S)
llvm::Function * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
LValue EmitLValueForLambdaField(const FieldDecl *Field, llvm::Value *ThisValue)
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
void EmitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &S)
Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, Address ParentVar, llvm::Value *ParentFP)
Recovers the address of a local in a parent function.
const FieldDecl * FindFlexibleArrayMemberFieldAndOffset(ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl, uint64_t &Offset)
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.
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
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...
Address EmitVAListRef(const Expr *E)
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
Address emitAddrOfImagComponent(Address complex, QualType complexType)
Address emitBlockByrefAddress(Address baseAddr, const BlockByrefInfo &info, bool followForward, const llvm::Twine &name)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
llvm::Value * EmitLoadOfScalar(LValue lvalue, SourceLocation Loc)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void EmitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &S)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
Same as MakeAddrLValue above except that the pointer is known to be unsigned.
llvm::Function * GenerateCapturedStmtFunction(const CapturedStmt &S)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
llvm::Value * EmitARCReclaimReturnedObject(const Expr *e, bool allowUnsafeClaim)
void EmitSEHTryStmt(const SEHTryStmt &S)
void maybeCreateMCDCCondBitmap()
Allocate a temp value on the stack that MCDC can use to track condition results.
void EmitOMPInteropDirective(const OMPInteropDirective &S)
llvm::Value * EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, bool negateForRightShift)
void ExitSEHTryStmt(const SEHTryStmt &S)
llvm::Constant * GenerateCopyHelperFunction(const CGBlockInfo &blockInfo)
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
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 * unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub)
Call unatexit() with function dtorStub.
llvm::BasicBlock * OMPScanDispatch
llvm::BasicBlock * getTerminateLandingPad()
getTerminateLandingPad - Return a landing pad that just calls terminate.
llvm::BasicBlock * getTerminateHandler()
getTerminateHandler - Return a handler (not a landing pad, just a catch handler) that just calls term...
void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr)
llvm::Value * EmitSVEMovl(const SVETypeFlags &TypeFlags, llvm::ArrayRef< llvm::Value * > Ops, unsigned BuiltinID)
llvm::function_ref< std::pair< LValue, LValue >(CodeGenFunction &, const OMPExecutableDirective &S)> CodeGenLoopBoundsTy
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke=nullptr, bool IsMustTail=false)
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
const TargetCodeGenInfo & getTargetHooks() const
void setBeforeOutermostConditional(llvm::Value *value, Address addr, CodeGenFunction &CGF)
llvm::Value * emitBoolVecConversion(llvm::Value *SrcVec, unsigned NumElementsDst, const llvm::Twine &Name="")
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
LValue EmitPredefinedLValue(const PredefinedExpr *E)
llvm::Value * EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
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...
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
llvm::Type * getEltType(const SVETypeFlags &TypeFlags)
CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, const RegionCodeGenTy &BodyGen, OMPTargetDataInfo &InputInfo)
void EmitDeclStmt(const DeclStmt &S)
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
bool InNoInlineAttributedStmt
True if the current statement has noinline attribute.
void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S)
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor)
llvm::Function * GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info, const DeclMapTy &ldm, bool IsLambdaConversionToBlock, bool BuildGlobalBlock)
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst)
void EmitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &S)
static void EmitOMPTargetParallelForDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelForDirective &S)
Emit device code for the target parallel for directive.
llvm::Value * EmitSVEPMull(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
void EmitCoroutineBody(const CoroutineBodyStmt &S)
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
void EmitDoStmt(const DoStmt &S, ArrayRef< const Attr * > Attrs=std::nullopt)
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
RValue EmitOpenMPDevicePrintfCallExpr(const CallExpr *E)
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
llvm::Value * EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy, QualType RTy)
void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile)
Build all the stores needed to initialize an aggregate at Dest with the value Val.
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
bool AlwaysEmitXRayTypedEvents() const
AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit XRay typed event handling ...
void pushCleanupAfterFullExprWithActiveFlag(CleanupKind Kind, RawAddress ActiveFlag, As... A)
void SetSqrtFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub)
Call atexit() with function dtorStub.
void EmitOMPSimdInit(const OMPLoopDirective &D)
Helpers for the OpenMP loop directives.
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
RValue EmitCXXDestructorCall(GlobalDecl Dtor, const CGCallee &Callee, llvm::Value *This, QualType ThisTy, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E)
llvm::Value * EmitSVEScatterStore(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::Value * EmitObjCSelectorExpr(const ObjCSelectorExpr *E)
void EmitConstructorBody(FunctionArgList &Args)
void SetFastMathFlags(FPOptions FPFeatures)
Set the codegen fast-math flags.
int ExpectedOMPLoopDepth
Number of nested loop to be consumed by the last surrounding loop-associated directive.
void EmitVarDecl(const VarDecl &D)
EmitVarDecl - Emit a local variable declaration.
llvm::Value * EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value)
void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Value * EmitBuiltinAvailable(const VersionTuple &Version)
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This)
Emit assumption load for all bases.
llvm::Function * generateBuiltinOSLogHelperFunction(const analyze_os_log::OSLogBufferLayout &Layout, CharUnits BufferAlignment)
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...
CGCallee EmitCallee(const Expr *E)
llvm::Value * EmitBlockLiteral(const BlockExpr *)
Emit block literal.
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.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
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="")
llvm::Constant * GenerateObjCAtomicSetterCopyHelperFunction(const ObjCPropertyImplDecl *PID)
ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType)
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
llvm::Value * EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx, const CallExpr *E)
void maybeUpdateMCDCCondBitmap(const Expr *E, llvm::Value *Val)
Update the MCDC temp value with the condition's evaluated result.
static void EmitOMPTargetTeamsDistributeSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeSimdDirective &S)
Emit device code for the target teams distribute simd directive.
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
void EmitLambdaInAllocaCallOpBody(const CXXMethodDecl *MD)
SmallVector< llvm::CanonicalLoopInfo *, 4 > OMPLoopNestStack
List of recently emitted OMPCanonicalLoops.
bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB, const CodeGenLoopBoundsTy &CodeGenLoopBounds, const CodeGenDispatchBoundsTy &CGDispatchBounds)
Emit code for the worksharing loop-based directive.
llvm::SmallVector< char, 256 > LifetimeExtendedCleanupStack
void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef< const Attr * > Attrs=std::nullopt)
llvm::Value * LoadCXXVTT()
LoadCXXVTT - Load the VTT parameter to base constructors/destructors have virtual bases.
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
void EmitOMPLinearClause(const OMPLoopDirective &D, CodeGenFunction::OMPPrivateScope &PrivateScope)
Emit initial code for linear clauses.
llvm::Instruction * getPostAllocaInsertPoint()
Return PostAllocaInsertPt.
void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo, bool IsUnprototyped)
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 ...
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
LValue EmitMemberExpr(const MemberExpr *E)
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
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...
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
llvm::ConstantInt * getUBSanFunctionTypeHash(QualType T) const
Return a type hash constant for a function instrumented by -fsanitize=function.
ComplexPairTy EmitPromotedValue(ComplexPairTy result, QualType PromotionType)
llvm::Value * SEHInfo
Value returned by __exception_info intrinsic.
llvm::Value * BuildVector(ArrayRef< llvm::Value * > Ops)
ConstantEmission tryEmitAsConstant(const MemberExpr *ME)
llvm::Value * EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void callCStructMoveAssignmentOperator(LValue Dst, LValue Src)
void EmitAutoVarCleanups(const AutoVarEmission &emission)
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
AddInitializerToStaticVarDecl - Add the initializer for 'D' to the global variable that has already b...
llvm::Value * EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
void EmitOMPTileDirective(const OMPTileDirective &S)
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
bool EmitOMPLinearClauseInit(const OMPLoopDirective &D)
Emit initial code for linear variables.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
llvm::Value * EmitPromotedScalarExpr(const Expr *E, QualType PromotionType)
llvm::BasicBlock * EmitLandingPad()
Emits a landing pad for the current EH stack.
void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S)
llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields
llvm::Function * EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K)
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...
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="")
void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit)
Helper for the OpenMP loop directives.
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
VlaSizePair getVLASize(QualType vla)
llvm::Value * EmitObjCMRRAutoreleasePoolPush()
void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size)
void maybeUpdateMCDCTestVectorBitmap(const Expr *E)
Increment the profiler's counter for the given expression by StepV.
void EmitOMPLinearClauseFinal(const OMPLoopDirective &D, const llvm::function_ref< llvm::Value *(CodeGenFunction &)> CondGen)
Emit final code for linear clauses.
llvm::Type * ConvertType(QualType T)
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
void EmitOMPSectionsDirective(const OMPSectionsDirective &S)
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Address GetAddrOfBlockDecl(const VarDecl *var)
CodeGenTypes & getTypes() const
void EmitARCInitWeak(Address addr, llvm::Value *value)
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
LValue EmitArraySectionExpr(const ArraySectionExpr *E, bool IsLowerBound=true)
llvm::BasicBlock * OMPScanExitBlock
llvm::Value * EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void emitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
static void EmitOMPTargetTeamsDistributeParallelForSimdDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetTeamsDistributeParallelForSimdDirective &S)
Emit device code for the target teams distribute parallel for simd directive.
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E)
llvm::CallBase * EmitCallOrInvoke(llvm::FunctionCallee Callee, ArrayRef< llvm::Value * > Args, const Twine &Name="")
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Address EmitCXXUuidofExpr(const CXXUuidofExpr *E)
bool InAlwaysInlineAttributedStmt
True if the current statement has always_inline attribute.
RawAddress CreateTempAlloca(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr, RawAddress *Alloca=nullptr)
void EmitOMPUseDeviceAddrClause(const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope, const llvm::DenseMap< const ValueDecl *, llvm::Value * > CaptureDeviceAddrMap)
void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, const ObjCPropertyImplDecl *propImpl, llvm::Constant *AtomicHelperFn)
void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S)
void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S)
void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType)
EmitCallArg - Emit a single call argument.
llvm::Value * EmitSMEReadWrite(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
void EmitOpenACCComputeConstruct(const OpenACCComputeConstruct &S)
void EmitOMPSimdDirective(const OMPSimdDirective &S)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, LValue LV, QualType Type, SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
llvm::Value * EmitSMELd1St1(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
void EmitOMPCriticalDirective(const OMPCriticalDirective &S)
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
ActivateCleanupBlock - Activates an initially-inactive cleanup.
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, size_t OldLifetimeExtendedStackSize, std::initializer_list< llvm::Value ** > ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added,...
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit)
llvm::Value * EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
LValue EmitStringLiteralLValue(const StringLiteral *E)
void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, bool IsFilter)
Scan the outlined statement for captures from the parent function.
static Destroyer destroyARCStrongPrecise
void EmitARCIntrinsicUse(ArrayRef< llvm::Value * > values)
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E)
void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S)
void EmitOMPForDirective(const OMPForDirective &S)
void EmitOMPMetaDirective(const OMPMetaDirective &S)
void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, FunctionArgList &Args)
RawAddress NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
RValue EmitAtomicLoad(LValue lvalue, SourceLocation loc, llvm::AtomicOrdering AO, bool IsVolatile=false, AggValueSlot slot=AggValueSlot::ignored())
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
llvm::Value * EmitSVEStructLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S)
LValue InitCapturedStruct(const CapturedStmt &S)
void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S)
void EmitReturnStmt(const ReturnStmt &S)
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD, CallArgList &CallArgs)
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression,...
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 ...
LValue EmitOMPSharedLValue(const Expr *E)
Emits the lvalue for the expression with possibly captured variable.
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 EmitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &S)
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
void processInReduction(const OMPExecutableDirective &S, OMPTaskDataTy &Data, CodeGenFunction &CGF, const CapturedStmt *CS, OMPPrivateScope &Scope)
void EmitOMPMasterDirective(const OMPMasterDirective &S)
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S)
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
EHScopeStack::stable_iterator PrologueCleanupDepth
PrologueCleanupDepth - The cleanup depth enclosing all the cleanups associated with the parameters.
void EmitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &S)
void pushStackRestore(CleanupKind kind, Address SPMem)
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
llvm::Value * EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, llvm::Type *Ty, bool usgn, const char *name)
void GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCSetter - Synthesize an Objective-C property setter function for the given property.
bool EmitOMPCopyinClause(const OMPExecutableDirective &D)
Emit code for copyin clause in D directive.
llvm::Value * EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty)
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope,...
SmallVector< llvm::Type *, 2 > getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
void EmitOMPMaskedDirective(const OMPMaskedDirective &S)
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E)
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
static bool hasAggregateEvaluationKind(QualType T)
void EmitOMPPrivateClause(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S)
llvm::Function * GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S, SourceLocation Loc)
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
void EmitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &S)
RawAddress CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo, bool isNontemporal=false)
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr)
const FieldDecl * FindCountedByField(const FieldDecl *FD)
Find the FieldDecl specified in a FAM's "counted_by" attribute.
void SetFPAccuracy(llvm::Value *Val, float Accuracy)
SetFPAccuracy - Set the minimum required accuracy of the given floating point operation,...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void EmitBreakStmt(const BreakStmt &S)
Address GenerateCapturedStmtArgument(const CapturedStmt &S)
void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV)
static void EmitOMPTargetParallelGenericLoopDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelGenericLoopDirective &S)
Emit device code for the target parallel loop directive.
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
llvm::function_ref< void(CodeGenFunction &, SourceLocation, const unsigned, const bool)> CodeGenOrderedTy
llvm::Value * EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
void GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCGetter - Synthesize an Objective-C property getter function.
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
const CGFunctionInfo * CurFnInfo
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const
isObviouslyBranchWithoutCleanups - Return true if a branch to the specified destination obviously has...
llvm::Value * EmitSVEStructStore(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
llvm::BasicBlock * getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope)
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
llvm::Value * getArrayInitIndex()
Get the index of the current ArrayInitLoopExpr, if any.
void pushKmpcAllocFree(CleanupKind Kind, std::pair< llvm::Value *, llvm::Value * > AddrSizePair)
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
llvm::Value * EmitSEHAbnormalTermination()
void EmitCfiSlowPathCheck(SanitizerMask Kind, 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.
void EmitCoreturnStmt(const CoreturnStmt &S)
void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type)
EnterDtorCleanups - Enter the cleanups necessary to complete the given phase of destruction for a des...
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
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...
llvm::Value * EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::BasicBlock * OMPAfterScanBlock
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S)
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
void EmitOMPErrorDirective(const OMPErrorDirective &S)
static Destroyer destroyARCStrongImprecise
void EmitOMPSectionDirective(const OMPSectionDirective &S)
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
static void EmitOMPTargetParallelDeviceFunction(CodeGenModule &CGM, StringRef ParentName, const OMPTargetParallelDirective &S)
llvm::Value * EmitSVEAllTruePred(const SVETypeFlags &TypeFlags)
void EmitOMPBarrierDirective(const OMPBarrierDirective &S)
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E)
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S)
llvm::Value * EmitObjCAlloc(llvm::Value *value, llvm::Type *returnType)
llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)
LValue EmitStmtExprLValue(const StmtExpr *E)
llvm::Instruction * CurrentFuncletPad
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=std::nullopt)
EmitStmt - Emit the code for the statement.
llvm::Type * SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags)
SVEBuiltinMemEltTy - Returns the memory element type for this memory access builtin.
void EmitWhileStmt(const WhileStmt &S, ArrayRef< const Attr * > Attrs=std::nullopt)
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S)
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 ...
llvm::LLVMContext & getLLVMContext()
void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S)
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
void ResolveBranchFixups(llvm::BasicBlock *Target)
bool checkIfFunctionMustProgress()
Returns true if a function must make progress, which means the mustprogress attribute can be added.
void EmitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &S)
bool LValueIsSuitableForInlineAtomic(LValue Src)
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
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.
llvm::SmallVector< VPtr, 4 > VPtrsVector
llvm::Value * EmitSMEZero(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::Value * getSelectorFromSlot()
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
bool EmitOMPLastprivateClauseInit(const OMPExecutableDirective &D, OMPPrivateScope &PrivateScope)
Emit initial code for lastprivate variables.
static std::string getNonTrivialCopyConstructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
void InitializeVTablePointers(const CXXRecordDecl *ClassDecl)
llvm::Value * EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S)
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)
void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase, CharUnits OffsetFromNearestVBase, bool BaseIsNonVirtualPrimaryBase, const CXXRecordDecl *VTableClass, VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs)
llvm::function_ref< void(CodeGenFunction &, const OMPLoopDirective &, JumpDest)> CodeGenLoopTy
void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, bool CanThrow)
llvm::Value * EmitNeonCall(llvm::Function *F, SmallVectorImpl< llvm::Value * > &O, const char *name, unsigned shift=0, bool rightshift=false)
void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S)
Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
void InitializeVTablePointer(const VPtr &vptr)
Initialize the vtable pointer of the given subobject.
llvm::Value * EmitAnnotationCall(llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location, const AnnotateAttr *Attr)
Emit an annotation call (intrinsic).
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
void EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S)
llvm::BasicBlock * GetIndirectGotoBlock()
void EmitAsmStmt(const AsmStmt &S)
Address emitAddrOfRealComponent(Address complex, QualType complexType)
RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, const Expr *Base)
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
llvm::ScalableVectorType * getSVEPredType(const SVETypeFlags &TypeFlags)
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
llvm::DebugLoc EmitReturnBlock()
Emit the unified return block, trying to avoid its emission when possible.
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
llvm::Value * EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, ArrayRef< Address > args, const Twine &name="")
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...
bool hasLabelBeenSeenInCurrentScope() const
Return true if a label was seen in the current scope.
RValue EmitAtomicExpr(AtomicExpr *E)
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E)
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.
void EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S)
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, AlignmentSource Source=AlignmentSource::Type)
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.
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
llvm::Value * EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
LValue EmitLValueForLambdaField(const FieldDecl *Field)
void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, llvm::FunctionCallee Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
void pushDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
llvm::Type * ConvertType(const TypeDecl *T)
This class organizes the cross-function state that is used while generating LLVM code.
const LangOptions & getLangOpts() const
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
const llvm::DataLayout & getDataLayout() const
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type.
ASTContext & getContext() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
llvm::LLVMContext & getLLVMContext()
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
A specialization of Address that requires the address to be an LLVM Constant.
Definition: Address.h:260
static ConstantAddress invalid()
Definition: Address.h:268
DominatingValue< Address >::saved_type AggregateAddr
static saved_type save(CodeGenFunction &CGF, RValue value)
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
ConditionalCleanup stores the saved form of its parameters, then restores them and performs the clean...
Definition: EHScopeStack.h:203
A saved depth on the scope stack.
Definition: EHScopeStack.h:101
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
Definition: EHScopeStack.h:94
stable_iterator getInnermostNormalCleanup() const
Returns the innermost normal cleanup on the stack, or stable_end() if there are no normal cleanups.
Definition: EHScopeStack.h:370
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
Definition: EHScopeStack.h:393
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
Definition: EHScopeStack.h:398
void pushCleanupTuple(CleanupKind Kind, std::tuple< As... > A)
Push a lazily-created cleanup on the stack. Tuple version.
Definition: EHScopeStack.h:295
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:352
LValue - This represents an lvalue references.
Definition: CGValue.h:181
CharUnits getAlignment() const
Definition: CGValue.h:346
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Definition: CGValue.h:365
static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Definition: CGValue.h:440
QualType getType() const
Definition: CGValue.h:294
A stack of loop information corresponding to loop nesting levels.
Definition: CGLoopInfo.h:204
Information used when generating a structured loop.
Definition: CGLoopInfo.h:90
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:41
static RValue get(llvm::Value *V)
Definition: CGValue.h:97
An abstract representation of an aligned address.
Definition: Address.h:41
static RawAddress invalid()
Definition: Address.h:60
bool isValid() const
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:356
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:46
The class detects jumps which bypass local variables declaration: goto L; int a; L:
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4088
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3413
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
ContinueStmt - This represents a continue.
Definition: Stmt.h:2950
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition: StmtCXX.h:473
Represents the body of a coroutine.
Definition: StmtCXX.h:320
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition: ExprCXX.h:5037
Represents a 'co_yield' expression.
Definition: ExprCXX.h:5232
Represents the current source location and context used to determine the value of the source location...
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2342
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1497
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2725
This represents one expression.
Definition: Expr.h:110
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3055
QualType getType() const
Definition: Expr.h:142
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6113
Represents a member of a struct/union/class.
Definition: Decl.h:3058
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2781
Represents a function declaration or definition.
Definition: Decl.h:1971
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4652
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
const Decl * getDecl() const
Definition: GlobalDecl.h:103
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2862
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2138
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2901
Describes an C or C++ initializer list.
Definition: Expr.h:4847
Represents the declaration of a label.
Definition: Decl.h:499
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2031
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:276
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
Represents a point when we exit a loop.
Definition: ProgramPoint.h:711
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4686
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2742
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3172
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3456
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This represents '#pragma omp atomic' directive.
Definition: StmtOpenMP.h:2963
This represents '#pragma omp barrier' directive.
Definition: StmtOpenMP.h:2641
This represents '#pragma omp cancel' directive.
Definition: StmtOpenMP.h:3671
This represents '#pragma omp cancellation point' directive.
Definition: StmtOpenMP.h:3613
Representation of an OpenMP canonical loop.
Definition: StmtOpenMP.h:142
This represents '#pragma omp critical' directive.
Definition: StmtOpenMP.h:2092
This represents '#pragma omp depobj' directive.
Definition: StmtOpenMP.h:2857
This represents '#pragma omp distribute' directive.
Definition: StmtOpenMP.h:4441
This represents '#pragma omp distribute parallel for' composite directive.
Definition: StmtOpenMP.h:4564
This represents '#pragma omp distribute parallel for simd' composite directive.
Definition: StmtOpenMP.h:4660
This represents '#pragma omp distribute simd' composite directive.
Definition: StmtOpenMP.h:4725
This represents '#pragma omp error' directive.
Definition: StmtOpenMP.h:6311
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:266
This represents '#pragma omp flush' directive.
Definition: StmtOpenMP.h:2805
This represents '#pragma omp for' directive.
Definition: StmtOpenMP.h:1649
This represents '#pragma omp for simd' directive.
Definition: StmtOpenMP.h:1740
This represents '#pragma omp loop' directive.
Definition: StmtOpenMP.h:5982
This represents '#pragma omp interop' directive.
Definition: StmtOpenMP.h:5774
This is a common base class for loop directives ('omp simd', 'omp for', 'omp for simd' etc....
Definition: StmtOpenMP.h:1018
This represents '#pragma omp masked' directive.
Definition: StmtOpenMP.h:5892
This represents '#pragma omp master' directive.
Definition: StmtOpenMP.h:2044
This represents '#pragma omp master taskloop' directive.
Definition: StmtOpenMP.h:3870
This represents '#pragma omp master taskloop simd' directive.
Definition: StmtOpenMP.h:4022
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:5943
This represents '#pragma omp ordered' directive.
Definition: StmtOpenMP.h:2909
This represents '#pragma omp parallel' directive.
Definition: StmtOpenMP.h:627
This represents '#pragma omp parallel for' directive.
Definition: StmtOpenMP.h:2163
This represents '#pragma omp parallel for simd' directive.
Definition: StmtOpenMP.h:2260
This represents '#pragma omp parallel masked' directive.
Definition: StmtOpenMP.h:2388
This represents '#pragma omp parallel master' directive.
Definition: StmtOpenMP.h:2325
This represents '#pragma omp parallel master taskloop' directive.
Definition: StmtOpenMP.h:4153
This represents '#pragma omp parallel master taskloop simd' directive.
Definition: StmtOpenMP.h:4309
This represents '#pragma omp parallel sections' directive.
Definition: StmtOpenMP.h:2452
This represents '#pragma omp scan' directive.
Definition: StmtOpenMP.h:5721
This represents '#pragma omp section' directive.
Definition: StmtOpenMP.h:1880
This represents '#pragma omp sections' directive.
Definition: StmtOpenMP.h:1803
This represents '#pragma omp simd' directive.
Definition: StmtOpenMP.h:1585
This represents '#pragma omp single' directive.
Definition: StmtOpenMP.h:1993
This represents '#pragma omp target data' directive.
Definition: StmtOpenMP.h:3222
This represents '#pragma omp target' directive.
Definition: StmtOpenMP.h:3168
This represents '#pragma omp target enter data' directive.
Definition: StmtOpenMP.h:3276
This represents '#pragma omp target exit data' directive.
Definition: StmtOpenMP.h:3331
This represents '#pragma omp target parallel' directive.
Definition: StmtOpenMP.h:3385
This represents '#pragma omp target parallel for' directive.
Definition: StmtOpenMP.h:3465
This represents '#pragma omp target parallel for simd' directive.
Definition: StmtOpenMP.h:4791
This represents '#pragma omp target parallel loop' directive.
Definition: StmtOpenMP.h:6249
This represents '#pragma omp target simd' directive.
Definition: StmtOpenMP.h:4858
This represents '#pragma omp target teams' directive.
Definition: StmtOpenMP.h:5216
This represents '#pragma omp target teams distribute' combined directive.
Definition: StmtOpenMP.h:5272
This represents '#pragma omp target teams distribute parallel for' combined directive.
Definition: StmtOpenMP.h:5339
This represents '#pragma omp target teams distribute parallel for simd' combined directive.
Definition: StmtOpenMP.h:5437
This represents '#pragma omp target teams distribute simd' combined directive.
Definition: StmtOpenMP.h:5507
This represents '#pragma omp target teams loop' directive.
Definition: StmtOpenMP.h:6109
This represents '#pragma omp target update' directive.
Definition: StmtOpenMP.h:4508
This represents '#pragma omp task' directive.
Definition: StmtOpenMP.h:2533
This represents '#pragma omp taskloop' directive.
Definition: StmtOpenMP.h:3731
This represents '#pragma omp taskloop simd' directive.
Definition: StmtOpenMP.h:3804
This represents '#pragma omp taskgroup' directive.
Definition: StmtOpenMP.h:2738
This represents '#pragma omp taskwait' directive.
Definition: StmtOpenMP.h:2687
This represents '#pragma omp taskyield' directive.
Definition: StmtOpenMP.h:2595
This represents '#pragma omp teams' directive.
Definition: StmtOpenMP.h:3560
This represents '#pragma omp teams distribute' directive.
Definition: StmtOpenMP.h:4923
This represents '#pragma omp teams distribute parallel for' composite directive.
Definition: StmtOpenMP.h:5123
This represents '#pragma omp teams distribute parallel for simd' composite directive.
Definition: StmtOpenMP.h:5057
This represents '#pragma omp teams distribute simd' combined directive.
Definition: StmtOpenMP.h:4989
This represents '#pragma omp teams loop' directive.
Definition: StmtOpenMP.h:6044
This represents the '#pragma omp tile' loop transformation directive.
Definition: StmtOpenMP.h:5565
This represents the '#pragma omp unroll' loop transformation directive.
Definition: StmtOpenMP.h:5647
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:191
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:127
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:947
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:309
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
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:2594
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition: ExprObjC.h:1491
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1950
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:549
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:945
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:2802
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition: ExprObjC.h:505
ObjCSelectorExpr used for @selector in Objective-C.
Definition: ExprObjC.h:455
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:51
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Definition: StmtOpenACC.h:120
Represents a parameter to a function.
Definition: Decl.h:1761
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3135
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6305
A (possibly-)qualified type.
Definition: Type.h:940
@ DK_cxx_destructor
Definition: Type.h:1520
@ DK_nontrivial_c_struct
Definition: Type.h:1523
@ DK_objc_weak_lifetime
Definition: Type.h:1522
@ DK_objc_strong_lifetime
Definition: Type.h:1521
The collection of all-type qualifiers we support.
Definition: Type.h:318
Represents a struct/union/class.
Definition: Decl.h:4169
bool hasVolatileMember() const
Definition: Decl.h:4232
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5545
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3019
Represents a __leave statement.
Definition: Stmt.h:3718
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:4383
Stmt - This represents one statement.
Definition: Stmt.h:84
Likelihood
The likelihood of a branch being taken.
Definition: Stmt.h:1301
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition: Stmt.h:1303
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2388
Exposes information about the current target.
Definition: TargetInfo.h:213
Represents a declaration of a type.
Definition: Decl.h:3391
The base class of the type hierarchy.
Definition: Type.h:1813
bool isReferenceType() const
Definition: Type.h:7620
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8119
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2183
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4667
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2254
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition: Decl.h:1249
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3743
Expr * getSizeExpr() const
Definition: Type.h:3762
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2584
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:140
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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...
Definition: EHScopeStack.h:84
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
Definition: CGValue.h:134
@ NotKnownNonNull
Definition: Address.h:32
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const AstTypeMatcher< ComplexType > complexType
Matches C99 complex types.
The JSON file list parser is used to communicate input to InstallAPI.
CXXCtorType
C++ constructor types.
Definition: ABI.h:24
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:24
BinaryOperatorKind
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:16
@ CR_Default
Definition: CapturedStmt.h:17
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:103
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.
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
const FunctionProtoType * T
@ Success
Template argument deduction was successful.
llvm::fp::ExceptionBehavior ToConstrainedExceptMD(LangOptions::FPExceptionModeKind Kind)
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Definition: Format.h:5394
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
#define bool
Definition: stdbool.h:20
Structure with information about how a bitfield should be accessed.
CXXDefaultArgExprScope(CodeGenFunction &CGF, const CXXDefaultArgExpr *E)
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.
MultiVersionResolverOption(llvm::Function *F, StringRef Arch, ArrayRef< StringRef > Feats)
struct clang::CodeGen::CodeGenFunction::MultiVersionResolverOption::Conds Conditions
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.
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.
llvm::PointerIntPair< llvm::Value *, 1, bool > saved_type
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.
Definition: EHScopeStack.h:65
static saved_type save(CodeGenFunction &CGF, type value)
Definition: EHScopeStack.h:59
Scheduling data for loop-based OpenMP directives.
Definition: OpenMPKinds.h:179
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition: Thunk.h:156