21#include "llvm/ADT/DenseMap.h"
22#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/Intrinsics.h"
35 CharUnits AtomicAlign;
42 AtomicInfo(CodeGenFunction &CGF, LValue &lvalue)
43 : CGF(CGF), AtomicSizeInBits(0), ValueSizeInBits(0),
45 assert(!lvalue.isGlobalReg());
47 if (lvalue.isSimple()) {
48 AtomicTy = lvalue.getType();
49 if (
auto *ATy = AtomicTy->
getAs<AtomicType>())
50 ValueTy = ATy->getValueType();
57 TypeInfo ValueTI =
C.getTypeInfo(ValueTy);
58 ValueSizeInBits = ValueTI.
Width;
59 ValueAlignInBits = ValueTI.
Align;
61 TypeInfo AtomicTI =
C.getTypeInfo(AtomicTy);
62 AtomicSizeInBits = AtomicTI.
Width;
63 AtomicAlignInBits = AtomicTI.
Align;
65 assert(ValueSizeInBits <= AtomicSizeInBits);
66 assert(ValueAlignInBits <= AtomicAlignInBits);
68 AtomicAlign =
C.toCharUnitsFromBits(AtomicAlignInBits);
69 ValueAlign =
C.toCharUnitsFromBits(ValueAlignInBits);
70 if (lvalue.getAlignment().isZero())
71 lvalue.setAlignment(AtomicAlign);
74 }
else if (lvalue.isBitField()) {
75 ValueTy = lvalue.getType();
76 ValueSizeInBits =
C.getTypeSize(ValueTy);
77 auto &OrigBFI = lvalue.getBitFieldInfo();
78 auto Offset = OrigBFI.Offset %
C.toBits(lvalue.getAlignment());
79 AtomicSizeInBits =
C.toBits(
80 C.toCharUnitsFromBits(Offset + OrigBFI.Size +
C.getCharWidth() - 1)
81 .alignTo(lvalue.getAlignment()));
82 llvm::Value *BitFieldPtr = lvalue.getRawBitFieldPointer(CGF);
84 (
C.toCharUnitsFromBits(OrigBFI.Offset) / lvalue.getAlignment()) *
85 lvalue.getAlignment();
86 llvm::Value *StoragePtr = CGF.
Builder.CreateConstGEP1_64(
87 CGF.
Int8Ty, BitFieldPtr, OffsetInChars.getQuantity());
94 llvm::Type *StorageTy = CGF.
Builder.getIntNTy(AtomicSizeInBits);
95 LVal = LValue::MakeBitfield(
96 Address(StoragePtr, StorageTy, lvalue.getAlignment()), BFI,
97 lvalue.getType(), lvalue.getBaseInfo(), lvalue.getTBAAInfo());
98 AtomicTy =
C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
102 C.toCharUnitsFromBits(AtomicSizeInBits).getQuantity());
103 AtomicTy =
C.getConstantArrayType(
C.CharTy, Size,
nullptr,
104 ArraySizeModifier::Normal,
107 AtomicAlign = ValueAlign = lvalue.getAlignment();
108 }
else if (lvalue.isVectorElt()) {
109 ValueTy = lvalue.getType()->
castAs<VectorType>()->getElementType();
110 ValueSizeInBits =
C.getTypeSize(ValueTy);
111 AtomicTy = lvalue.getType();
112 AtomicSizeInBits =
C.getTypeSize(AtomicTy);
113 AtomicAlign = ValueAlign = lvalue.getAlignment();
116 assert(lvalue.isExtVectorElt());
117 ValueTy = lvalue.getType();
118 ValueSizeInBits =
C.getTypeSize(ValueTy);
121 lvalue.getExtVectorAddress().getElementType())
123 AtomicSizeInBits =
C.getTypeSize(AtomicTy);
124 AtomicAlign = ValueAlign = lvalue.getAlignment();
127 UseLibcall = !
C.getTargetInfo().hasBuiltinAtomic(
128 AtomicSizeInBits,
C.toBits(lvalue.getAlignment()));
131 QualType getAtomicType()
const {
return AtomicTy; }
132 QualType getValueType()
const {
return ValueTy; }
133 CharUnits getAtomicAlignment()
const {
return AtomicAlign; }
134 uint64_t getAtomicSizeInBits()
const {
return AtomicSizeInBits; }
135 uint64_t getValueSizeInBits()
const {
return ValueSizeInBits; }
137 bool shouldUseLibcall()
const {
return UseLibcall; }
138 const LValue &getAtomicLValue()
const {
return LVal; }
139 llvm::Value *getAtomicPointer()
const {
141 return LVal.emitRawPointer(CGF);
142 else if (LVal.isBitField())
143 return LVal.getRawBitFieldPointer(CGF);
144 else if (LVal.isVectorElt())
145 return LVal.getRawVectorPointer(CGF);
146 assert(LVal.isExtVectorElt());
147 return LVal.getRawExtVectorPointer(CGF);
149 Address getAtomicAddress()
const {
152 ElTy = LVal.getAddress().getElementType();
153 else if (LVal.isBitField())
154 ElTy = LVal.getBitFieldAddress().getElementType();
155 else if (LVal.isVectorElt())
156 ElTy = LVal.getVectorAddress().getElementType();
158 ElTy = LVal.getExtVectorAddress().getElementType();
159 return Address(getAtomicPointer(), ElTy, getAtomicAlignment());
162 Address getAtomicAddressAsAtomicIntPointer()
const {
163 return castToAtomicIntPointer(getAtomicAddress());
172 bool hasPadding()
const {
173 return (ValueSizeInBits != AtomicSizeInBits);
176 bool emitMemSetZeroIfNecessary()
const;
178 llvm::Value *getAtomicSizeValue()
const {
185 Address castToAtomicIntPointer(Address
Addr)
const;
190 Address convertToAtomicIntPointer(Address
Addr)
const;
193 RValue convertAtomicTempToRValue(Address addr, AggValueSlot resultSlot,
194 SourceLocation loc,
bool AsValue)
const;
196 llvm::Value *getScalarRValValueOrNull(RValue RVal)
const;
199 llvm::Value *convertRValueToInt(RValue RVal,
bool CmpXchg =
false)
const;
201 RValue ConvertToValueOrAtomic(llvm::Value *IntVal, AggValueSlot ResultSlot,
202 SourceLocation Loc,
bool AsValue,
203 bool CmpXchg =
false)
const;
206 void emitCopyIntoMemory(RValue rvalue)
const;
209 LValue projectValue()
const {
210 assert(LVal.isSimple());
211 Address addr = getAtomicAddress();
215 return LValue::MakeAddr(addr, getValueType(), CGF.
getContext(),
216 LVal.getBaseInfo(), LVal.getTBAAInfo());
221 RValue EmitAtomicLoad(AggValueSlot ResultSlot, SourceLocation Loc,
222 bool AsValue, llvm::AtomicOrdering AO,
233 std::pair<RValue, llvm::Value *>
234 EmitAtomicCompareExchange(RValue Expected, RValue Desired,
236 llvm::AtomicOrdering::SequentiallyConsistent,
238 llvm::AtomicOrdering::SequentiallyConsistent,
239 bool IsWeak =
false);
244 void EmitAtomicUpdate(llvm::AtomicOrdering AO,
245 const llvm::function_ref<RValue(RValue)> &UpdateOp,
249 void EmitAtomicUpdate(llvm::AtomicOrdering AO, RValue UpdateRVal,
253 Address materializeRValue(RValue rvalue)
const;
256 Address CreateTempAlloca()
const;
258 bool requiresMemSetZero(llvm::Type *
type)
const;
262 void EmitAtomicLoadLibcall(llvm::Value *AddForLoaded,
263 llvm::AtomicOrdering AO,
bool IsVolatile);
265 llvm::Value *EmitAtomicLoadOp(llvm::AtomicOrdering AO,
bool IsVolatile,
266 bool CmpXchg =
false);
268 llvm::Value *EmitAtomicCompareExchangeLibcall(
269 llvm::Value *ExpectedAddr, llvm::Value *DesiredAddr,
271 llvm::AtomicOrdering::SequentiallyConsistent,
273 llvm::AtomicOrdering::SequentiallyConsistent);
275 std::pair<llvm::Value *, llvm::Value *> EmitAtomicCompareExchangeOp(
276 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
278 llvm::AtomicOrdering::SequentiallyConsistent,
280 llvm::AtomicOrdering::SequentiallyConsistent,
281 bool IsWeak =
false);
284 EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO,
285 const llvm::function_ref<RValue(RValue)> &UpdateOp,
288 void EmitAtomicUpdateOp(llvm::AtomicOrdering AO,
289 const llvm::function_ref<RValue(RValue)> &UpdateOp,
292 void EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO, RValue UpdateRVal,
295 void EmitAtomicUpdateOp(llvm::AtomicOrdering AO, RValue UpdateRal,
300Address AtomicInfo::CreateTempAlloca()
const {
303 QualType TmpTy = (LVal.isBitField() && ValueSizeInBits > AtomicSizeInBits)
309 if (LVal.isBitField())
311 TempAlloca, getAtomicAddress().
getType(),
312 getAtomicAddress().getElementType());
324 fnAttrB.addAttribute(llvm::Attribute::NoUnwind);
325 fnAttrB.addAttribute(llvm::Attribute::WillReturn);
326 llvm::AttributeList fnAttrs = llvm::AttributeList::get(
327 CGF.
getLLVMContext(), llvm::AttributeList::FunctionIndex, fnAttrB);
329 llvm::FunctionCallee fn =
337 uint64_t expectedSize) {
344bool AtomicInfo::requiresMemSetZero(llvm::Type *
type)
const {
346 if (hasPadding())
return true;
349 switch (getEvaluationKind()) {
356 AtomicSizeInBits / 2);
362 llvm_unreachable(
"bad evaluation kind");
365bool AtomicInfo::emitMemSetZeroIfNecessary()
const {
366 assert(LVal.isSimple());
367 Address addr = LVal.getAddress();
374 LVal.getAlignment().getAsAlign());
381 uint64_t Size, llvm::AtomicOrdering SuccessOrder,
382 llvm::AtomicOrdering FailureOrder,
383 llvm::SyncScope::ID
Scope) {
391 Pair->setWeak(IsWeak);
396 llvm::Value *Old = CGF.
Builder.CreateExtractValue(Pair, 0);
397 llvm::Value *
Cmp = CGF.
Builder.CreateExtractValue(Pair, 1);
401 llvm::BasicBlock *StoreExpectedBB =
406 llvm::BasicBlock *ContinueBB =
411 CGF.
Builder.CreateCondBr(
Cmp, ContinueBB, StoreExpectedBB);
413 CGF.
Builder.SetInsertPoint(StoreExpectedBB);
417 uint64_t ExpectedSizeInBytes = DL.getTypeStoreSize(
ExpectedType);
419 if (ExpectedSizeInBytes == Size) {
425 llvm::Type *OldType = Old->getType();
441 CGF.
Builder.CreateBr(ContinueBB);
443 CGF.
Builder.SetInsertPoint(ContinueBB);
454 llvm::Value *FailureOrderVal, uint64_t Size,
455 llvm::AtomicOrdering SuccessOrder, llvm::SyncScope::ID
Scope) {
456 llvm::AtomicOrdering FailureOrder;
457 if (llvm::ConstantInt *FO = dyn_cast<llvm::ConstantInt>(FailureOrderVal)) {
458 auto FOS = FO->getSExtValue();
459 if (!llvm::isValidAtomicOrderingCABI(FOS))
460 FailureOrder = llvm::AtomicOrdering::Monotonic;
462 switch ((llvm::AtomicOrderingCABI)FOS) {
463 case llvm::AtomicOrderingCABI::relaxed:
466 case llvm::AtomicOrderingCABI::release:
467 case llvm::AtomicOrderingCABI::acq_rel:
468 FailureOrder = llvm::AtomicOrdering::Monotonic;
470 case llvm::AtomicOrderingCABI::consume:
471 case llvm::AtomicOrderingCABI::acquire:
472 FailureOrder = llvm::AtomicOrdering::Acquire;
474 case llvm::AtomicOrderingCABI::seq_cst:
475 FailureOrder = llvm::AtomicOrdering::SequentiallyConsistent;
483 Size, SuccessOrder, FailureOrder,
Scope);
496 llvm::SwitchInst *SI = CGF.
Builder.CreateSwitch(FailureOrderVal, MonotonicBB);
498 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::consume),
500 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acquire),
502 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::seq_cst),
506 CGF.
Builder.SetInsertPoint(MonotonicBB);
508 SuccessOrder, llvm::AtomicOrdering::Monotonic,
Scope);
511 CGF.
Builder.SetInsertPoint(AcquireBB);
513 SuccessOrder, llvm::AtomicOrdering::Acquire,
Scope);
516 CGF.
Builder.SetInsertPoint(SeqCstBB);
518 SuccessOrder, llvm::AtomicOrdering::SequentiallyConsistent,
522 CGF.
Builder.SetInsertPoint(ContBB);
532 const bool IsFP = OldVal->getType()->isFloatingPointTy();
535 llvm::Intrinsic::ID IID = (Op == AtomicExpr::AO__atomic_max_fetch ||
536 Op == AtomicExpr::AO__scoped_atomic_max_fetch)
537 ? llvm::Intrinsic::maxnum
538 : llvm::Intrinsic::minnum;
539 return Builder.CreateBinaryIntrinsic(IID, OldVal, RHS, llvm::FMFSource(),
543 llvm::CmpInst::Predicate Pred;
546 llvm_unreachable(
"Unexpected min/max operation");
547 case AtomicExpr::AO__atomic_max_fetch:
548 case AtomicExpr::AO__scoped_atomic_max_fetch:
549 Pred = IsSigned ? llvm::CmpInst::ICMP_SGT : llvm::CmpInst::ICMP_UGT;
551 case AtomicExpr::AO__atomic_min_fetch:
552 case AtomicExpr::AO__scoped_atomic_min_fetch:
553 Pred = IsSigned ? llvm::CmpInst::ICMP_SLT : llvm::CmpInst::ICMP_ULT;
556 llvm::Value *
Cmp = Builder.CreateICmp(Pred, OldVal, RHS,
"tst");
557 return Builder.CreateSelect(
Cmp, OldVal, RHS,
"newval");
562 Address ExpectedResult, llvm::Value *IsWeak,
563 llvm::Value *FailureOrder, uint64_t Size,
564 llvm::AtomicOrdering Order,
565 llvm::SyncScope::ID
Scope) {
566 llvm::AtomicRMWInst::BinOp Op = llvm::AtomicRMWInst::Add;
567 bool PostOpMinMax =
false;
570 switch (E->
getOp()) {
571 case AtomicExpr::AO__c11_atomic_init:
572 case AtomicExpr::AO__opencl_atomic_init:
573 llvm_unreachable(
"Already handled!");
575 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
576 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
577 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
579 ExpectedResult, FailureOrder, Size, Order,
582 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
583 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
584 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
586 ExpectedResult, FailureOrder, Size, Order,
589 case AtomicExpr::AO__atomic_compare_exchange:
590 case AtomicExpr::AO__atomic_compare_exchange_n:
591 case AtomicExpr::AO__scoped_atomic_compare_exchange:
592 case AtomicExpr::AO__scoped_atomic_compare_exchange_n: {
593 if (llvm::ConstantInt *IsWeakC = dyn_cast<llvm::ConstantInt>(IsWeak)) {
595 Val1, Val2, ExpectedResult, FailureOrder,
599 llvm::BasicBlock *StrongBB =
602 llvm::BasicBlock *ContBB =
605 llvm::SwitchInst *SI = CGF.
Builder.CreateSwitch(IsWeak, WeakBB);
606 SI->addCase(CGF.
Builder.getInt1(
false), StrongBB);
608 CGF.
Builder.SetInsertPoint(StrongBB);
610 ExpectedResult, FailureOrder, Size, Order,
614 CGF.
Builder.SetInsertPoint(WeakBB);
616 ExpectedResult, FailureOrder, Size, Order,
620 CGF.
Builder.SetInsertPoint(ContBB);
624 case AtomicExpr::AO__c11_atomic_load:
625 case AtomicExpr::AO__opencl_atomic_load:
626 case AtomicExpr::AO__hip_atomic_load:
627 case AtomicExpr::AO__atomic_load_n:
628 case AtomicExpr::AO__atomic_load:
629 case AtomicExpr::AO__scoped_atomic_load_n:
630 case AtomicExpr::AO__scoped_atomic_load: {
632 Load->setAtomic(Order,
Scope);
640 case AtomicExpr::AO__c11_atomic_store:
641 case AtomicExpr::AO__opencl_atomic_store:
642 case AtomicExpr::AO__hip_atomic_store:
643 case AtomicExpr::AO__atomic_store:
644 case AtomicExpr::AO__atomic_store_n:
645 case AtomicExpr::AO__scoped_atomic_store:
646 case AtomicExpr::AO__scoped_atomic_store_n: {
649 Store->setAtomic(Order,
Scope);
655 case AtomicExpr::AO__c11_atomic_exchange:
656 case AtomicExpr::AO__hip_atomic_exchange:
657 case AtomicExpr::AO__opencl_atomic_exchange:
658 case AtomicExpr::AO__atomic_exchange_n:
659 case AtomicExpr::AO__atomic_exchange:
660 case AtomicExpr::AO__scoped_atomic_exchange_n:
661 case AtomicExpr::AO__scoped_atomic_exchange:
662 Op = llvm::AtomicRMWInst::Xchg;
665 case AtomicExpr::AO__atomic_add_fetch:
666 case AtomicExpr::AO__scoped_atomic_add_fetch:
668 : llvm::Instruction::Add;
670 case AtomicExpr::AO__c11_atomic_fetch_add:
671 case AtomicExpr::AO__hip_atomic_fetch_add:
672 case AtomicExpr::AO__opencl_atomic_fetch_add:
673 case AtomicExpr::AO__atomic_fetch_add:
674 case AtomicExpr::AO__scoped_atomic_fetch_add:
676 : llvm::AtomicRMWInst::Add;
679 case AtomicExpr::AO__atomic_sub_fetch:
680 case AtomicExpr::AO__scoped_atomic_sub_fetch:
682 : llvm::Instruction::Sub;
684 case AtomicExpr::AO__c11_atomic_fetch_sub:
685 case AtomicExpr::AO__hip_atomic_fetch_sub:
686 case AtomicExpr::AO__opencl_atomic_fetch_sub:
687 case AtomicExpr::AO__atomic_fetch_sub:
688 case AtomicExpr::AO__scoped_atomic_fetch_sub:
690 : llvm::AtomicRMWInst::Sub;
693 case AtomicExpr::AO__atomic_min_fetch:
694 case AtomicExpr::AO__scoped_atomic_min_fetch:
697 case AtomicExpr::AO__c11_atomic_fetch_min:
698 case AtomicExpr::AO__hip_atomic_fetch_min:
699 case AtomicExpr::AO__opencl_atomic_fetch_min:
700 case AtomicExpr::AO__atomic_fetch_min:
701 case AtomicExpr::AO__scoped_atomic_fetch_min:
703 ? llvm::AtomicRMWInst::FMin
705 ? llvm::AtomicRMWInst::Min
706 : llvm::AtomicRMWInst::UMin);
709 case AtomicExpr::AO__atomic_fetch_fminimum:
710 case AtomicExpr::AO__scoped_atomic_fetch_fminimum:
712 "fminimum operations only support floating-point types");
713 Op = llvm::AtomicRMWInst::FMinimum;
716 case AtomicExpr::AO__atomic_fetch_fminimum_num:
717 case AtomicExpr::AO__scoped_atomic_fetch_fminimum_num:
719 "fminimum_num operations only support floating-point types");
720 Op = llvm::AtomicRMWInst::FMinimumNum;
723 case AtomicExpr::AO__atomic_max_fetch:
724 case AtomicExpr::AO__scoped_atomic_max_fetch:
727 case AtomicExpr::AO__c11_atomic_fetch_max:
728 case AtomicExpr::AO__hip_atomic_fetch_max:
729 case AtomicExpr::AO__opencl_atomic_fetch_max:
730 case AtomicExpr::AO__atomic_fetch_max:
731 case AtomicExpr::AO__scoped_atomic_fetch_max:
733 ? llvm::AtomicRMWInst::FMax
735 ? llvm::AtomicRMWInst::Max
736 : llvm::AtomicRMWInst::UMax);
739 case AtomicExpr::AO__atomic_fetch_fmaximum:
740 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum:
742 "fmaximum operations only support floating-point types");
743 Op = llvm::AtomicRMWInst::FMaximum;
746 case AtomicExpr::AO__atomic_fetch_fmaximum_num:
747 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum_num:
749 "fmaximum_num operations only support floating-point types");
750 Op = llvm::AtomicRMWInst::FMaximumNum;
753 case AtomicExpr::AO__atomic_and_fetch:
754 case AtomicExpr::AO__scoped_atomic_and_fetch:
755 PostOp = llvm::Instruction::And;
757 case AtomicExpr::AO__c11_atomic_fetch_and:
758 case AtomicExpr::AO__hip_atomic_fetch_and:
759 case AtomicExpr::AO__opencl_atomic_fetch_and:
760 case AtomicExpr::AO__atomic_fetch_and:
761 case AtomicExpr::AO__scoped_atomic_fetch_and:
762 Op = llvm::AtomicRMWInst::And;
765 case AtomicExpr::AO__atomic_or_fetch:
766 case AtomicExpr::AO__scoped_atomic_or_fetch:
767 PostOp = llvm::Instruction::Or;
769 case AtomicExpr::AO__c11_atomic_fetch_or:
770 case AtomicExpr::AO__hip_atomic_fetch_or:
771 case AtomicExpr::AO__opencl_atomic_fetch_or:
772 case AtomicExpr::AO__atomic_fetch_or:
773 case AtomicExpr::AO__scoped_atomic_fetch_or:
774 Op = llvm::AtomicRMWInst::Or;
777 case AtomicExpr::AO__atomic_xor_fetch:
778 case AtomicExpr::AO__scoped_atomic_xor_fetch:
779 PostOp = llvm::Instruction::Xor;
781 case AtomicExpr::AO__c11_atomic_fetch_xor:
782 case AtomicExpr::AO__hip_atomic_fetch_xor:
783 case AtomicExpr::AO__opencl_atomic_fetch_xor:
784 case AtomicExpr::AO__atomic_fetch_xor:
785 case AtomicExpr::AO__scoped_atomic_fetch_xor:
786 Op = llvm::AtomicRMWInst::Xor;
789 case AtomicExpr::AO__atomic_nand_fetch:
790 case AtomicExpr::AO__scoped_atomic_nand_fetch:
791 PostOp = llvm::Instruction::And;
793 case AtomicExpr::AO__c11_atomic_fetch_nand:
794 case AtomicExpr::AO__atomic_fetch_nand:
795 case AtomicExpr::AO__scoped_atomic_fetch_nand:
796 Op = llvm::AtomicRMWInst::Nand;
799 case AtomicExpr::AO__atomic_fetch_uinc:
800 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
801 Op = llvm::AtomicRMWInst::UIncWrap;
803 case AtomicExpr::AO__atomic_fetch_udec:
804 case AtomicExpr::AO__scoped_atomic_fetch_udec:
805 Op = llvm::AtomicRMWInst::UDecWrap;
808 case AtomicExpr::AO__atomic_test_and_set: {
809 llvm::AtomicRMWInst *RMWI =
820 case AtomicExpr::AO__atomic_clear: {
821 llvm::StoreInst *Store =
823 Store->setAtomic(Order,
Scope);
831 llvm::AtomicRMWInst *RMWI =
837 llvm::Value *
Result = RMWI;
843 Result = CGF.
Builder.CreateBinOp((llvm::Instruction::BinaryOps)PostOp, RMWI,
845 if (E->
getOp() == AtomicExpr::AO__atomic_nand_fetch ||
846 E->
getOp() == AtomicExpr::AO__scoped_atomic_nand_fetch)
868 if (ValTy->isFloatingPointTy())
869 return ValTy->isX86_FP80Ty() || CmpXchg;
870 return !ValTy->isIntegerTy() && !ValTy->isPointerTy();
875 Address OriginalVal1, llvm::Value *IsWeak,
876 llvm::Value *FailureOrder, uint64_t Size,
877 llvm::AtomicOrdering Order, llvm::Value *
Scope) {
878 auto ScopeModel =
Expr->getScopeModel();
883 llvm::SyncScope::ID SS;
893 SS = llvm::SyncScope::System;
895 FailureOrder, Size, Order, SS);
900 if (
auto SC = dyn_cast<llvm::ConstantInt>(
Scope)) {
905 FailureOrder, Size, Order, SCID);
911 auto Scopes = ScopeModel->getRuntimeValues();
912 llvm::DenseMap<unsigned, llvm::BasicBlock *> BB;
913 for (
auto S : Scopes)
916 llvm::BasicBlock *ContBB =
919 auto *SC = Builder.CreateIntCast(
Scope, Builder.getInt32Ty(),
false);
922 auto FallBack = ScopeModel->getFallBackValue();
923 llvm::SwitchInst *SI = Builder.CreateSwitch(SC, BB[FallBack]);
924 for (
auto S : Scopes) {
927 SI->addCase(Builder.getInt32(S), B);
929 Builder.SetInsertPoint(B);
931 FailureOrder, Size, Order,
935 Builder.CreateBr(ContBB);
938 Builder.SetInsertPoint(ContBB);
947 MemTy = AT->getValueType();
948 llvm::Value *IsWeak =
nullptr, *OrderFail =
nullptr;
955 if (E->
getOp() == AtomicExpr::AO__c11_atomic_init ||
956 E->
getOp() == AtomicExpr::AO__opencl_atomic_init) {
962 auto TInfo =
getContext().getTypeInfoInChars(AtomicTy);
963 uint64_t Size = TInfo.Width.getQuantity();
964 unsigned MaxInlineWidthInBits =
getTarget().getMaxAtomicInlineWidth();
967 getContext().toCharUnitsFromBits(MaxInlineWidthInBits);
970 bool Oversized =
getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
973 << (int)TInfo.Width.getQuantity()
978 << (int)TInfo.Width.getQuantity() << (int)MaxInlineWidth.
getQuantity();
985 switch (E->
getOp()) {
986 case AtomicExpr::AO__c11_atomic_init:
987 case AtomicExpr::AO__opencl_atomic_init:
988 llvm_unreachable(
"Already handled above with EmitAtomicInit!");
990 case AtomicExpr::AO__atomic_load_n:
991 case AtomicExpr::AO__scoped_atomic_load_n:
992 case AtomicExpr::AO__c11_atomic_load:
993 case AtomicExpr::AO__opencl_atomic_load:
994 case AtomicExpr::AO__hip_atomic_load:
995 case AtomicExpr::AO__atomic_test_and_set:
996 case AtomicExpr::AO__atomic_clear:
999 case AtomicExpr::AO__atomic_load:
1000 case AtomicExpr::AO__scoped_atomic_load:
1004 case AtomicExpr::AO__atomic_store:
1005 case AtomicExpr::AO__scoped_atomic_store:
1009 case AtomicExpr::AO__atomic_exchange:
1010 case AtomicExpr::AO__scoped_atomic_exchange:
1015 case AtomicExpr::AO__atomic_compare_exchange:
1016 case AtomicExpr::AO__atomic_compare_exchange_n:
1017 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
1018 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
1019 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
1020 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
1021 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
1022 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
1023 case AtomicExpr::AO__scoped_atomic_compare_exchange:
1024 case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
1026 if (E->
getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1027 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange)
1032 if (E->
getOp() == AtomicExpr::AO__atomic_compare_exchange_n ||
1033 E->
getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1034 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange_n ||
1035 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange)
1039 case AtomicExpr::AO__c11_atomic_fetch_add:
1040 case AtomicExpr::AO__c11_atomic_fetch_sub:
1041 case AtomicExpr::AO__hip_atomic_fetch_add:
1042 case AtomicExpr::AO__hip_atomic_fetch_sub:
1043 case AtomicExpr::AO__opencl_atomic_fetch_add:
1044 case AtomicExpr::AO__opencl_atomic_fetch_sub:
1054 Val1Scalar =
Builder.CreateMul(Val1Scalar,
CGM.getSize(PointeeIncAmt));
1061 case AtomicExpr::AO__atomic_fetch_add:
1062 case AtomicExpr::AO__atomic_fetch_max:
1063 case AtomicExpr::AO__atomic_fetch_min:
1064 case AtomicExpr::AO__atomic_fetch_sub:
1065 case AtomicExpr::AO__atomic_add_fetch:
1066 case AtomicExpr::AO__atomic_max_fetch:
1067 case AtomicExpr::AO__atomic_min_fetch:
1068 case AtomicExpr::AO__atomic_sub_fetch:
1069 case AtomicExpr::AO__c11_atomic_fetch_max:
1070 case AtomicExpr::AO__c11_atomic_fetch_min:
1071 case AtomicExpr::AO__opencl_atomic_fetch_max:
1072 case AtomicExpr::AO__opencl_atomic_fetch_min:
1073 case AtomicExpr::AO__hip_atomic_fetch_max:
1074 case AtomicExpr::AO__hip_atomic_fetch_min:
1075 case AtomicExpr::AO__scoped_atomic_fetch_add:
1076 case AtomicExpr::AO__scoped_atomic_fetch_max:
1077 case AtomicExpr::AO__scoped_atomic_fetch_min:
1078 case AtomicExpr::AO__scoped_atomic_fetch_sub:
1079 case AtomicExpr::AO__scoped_atomic_fetch_fminimum:
1080 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum:
1081 case AtomicExpr::AO__scoped_atomic_fetch_fminimum_num:
1082 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum_num:
1083 case AtomicExpr::AO__scoped_atomic_add_fetch:
1084 case AtomicExpr::AO__scoped_atomic_max_fetch:
1085 case AtomicExpr::AO__scoped_atomic_min_fetch:
1086 case AtomicExpr::AO__scoped_atomic_sub_fetch:
1089 case AtomicExpr::AO__atomic_fetch_and:
1090 case AtomicExpr::AO__atomic_fetch_nand:
1091 case AtomicExpr::AO__atomic_fetch_or:
1092 case AtomicExpr::AO__atomic_fetch_xor:
1093 case AtomicExpr::AO__atomic_fetch_uinc:
1094 case AtomicExpr::AO__atomic_fetch_udec:
1095 case AtomicExpr::AO__atomic_and_fetch:
1096 case AtomicExpr::AO__atomic_nand_fetch:
1097 case AtomicExpr::AO__atomic_or_fetch:
1098 case AtomicExpr::AO__atomic_xor_fetch:
1099 case AtomicExpr::AO__atomic_store_n:
1100 case AtomicExpr::AO__atomic_exchange_n:
1101 case AtomicExpr::AO__c11_atomic_fetch_and:
1102 case AtomicExpr::AO__c11_atomic_fetch_nand:
1103 case AtomicExpr::AO__c11_atomic_fetch_or:
1104 case AtomicExpr::AO__c11_atomic_fetch_xor:
1105 case AtomicExpr::AO__c11_atomic_store:
1106 case AtomicExpr::AO__c11_atomic_exchange:
1107 case AtomicExpr::AO__hip_atomic_fetch_and:
1108 case AtomicExpr::AO__hip_atomic_fetch_or:
1109 case AtomicExpr::AO__hip_atomic_fetch_xor:
1110 case AtomicExpr::AO__hip_atomic_store:
1111 case AtomicExpr::AO__hip_atomic_exchange:
1112 case AtomicExpr::AO__opencl_atomic_fetch_and:
1113 case AtomicExpr::AO__opencl_atomic_fetch_or:
1114 case AtomicExpr::AO__opencl_atomic_fetch_xor:
1115 case AtomicExpr::AO__opencl_atomic_store:
1116 case AtomicExpr::AO__opencl_atomic_exchange:
1117 case AtomicExpr::AO__scoped_atomic_fetch_and:
1118 case AtomicExpr::AO__scoped_atomic_fetch_nand:
1119 case AtomicExpr::AO__scoped_atomic_fetch_or:
1120 case AtomicExpr::AO__scoped_atomic_fetch_xor:
1121 case AtomicExpr::AO__scoped_atomic_and_fetch:
1122 case AtomicExpr::AO__scoped_atomic_nand_fetch:
1123 case AtomicExpr::AO__scoped_atomic_or_fetch:
1124 case AtomicExpr::AO__scoped_atomic_xor_fetch:
1125 case AtomicExpr::AO__scoped_atomic_store_n:
1126 case AtomicExpr::AO__scoped_atomic_exchange_n:
1127 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
1128 case AtomicExpr::AO__scoped_atomic_fetch_udec:
1129 case AtomicExpr::AO__atomic_fetch_fminimum:
1130 case AtomicExpr::AO__atomic_fetch_fmaximum:
1131 case AtomicExpr::AO__atomic_fetch_fminimum_num:
1132 case AtomicExpr::AO__atomic_fetch_fmaximum_num:
1138 bool ShouldCastToIntPtrTy =
1145 AtomicInfo Atomics(*
this, AtomicVal);
1148 if (ShouldCastToIntPtrTy) {
1149 Ptr = Atomics.castToAtomicIntPointer(Ptr);
1151 Val1 = Atomics.convertToAtomicIntPointer(Val1);
1153 Val2 = Atomics.convertToAtomicIntPointer(Val2);
1156 if (ShouldCastToIntPtrTy)
1157 Dest = Atomics.castToAtomicIntPointer(Dest);
1161 Dest = Atomics.CreateTempAlloca();
1162 if (ShouldCastToIntPtrTy)
1163 Dest = Atomics.castToAtomicIntPointer(Dest);
1166 bool PowerOf2Size = (Size & (Size - 1)) == 0;
1167 bool UseLibcall = !PowerOf2Size || (Size > 16);
1187 auto CastToGenericAddrSpace = [&](llvm::Value *
V,
QualType PT) {
1194 auto *DestType = llvm::PointerType::get(
getLLVMContext(), DestAS);
1204 std::string LibCallName;
1206 bool HaveRetTy =
false;
1207 switch (E->
getOp()) {
1208 case AtomicExpr::AO__c11_atomic_init:
1209 case AtomicExpr::AO__opencl_atomic_init:
1210 llvm_unreachable(
"Already handled!");
1217 case AtomicExpr::AO__atomic_compare_exchange:
1218 case AtomicExpr::AO__atomic_compare_exchange_n:
1219 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
1220 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
1221 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
1222 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
1223 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
1224 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
1225 case AtomicExpr::AO__scoped_atomic_compare_exchange:
1226 case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
1227 LibCallName =
"__atomic_compare_exchange";
1241 case AtomicExpr::AO__atomic_exchange:
1242 case AtomicExpr::AO__atomic_exchange_n:
1243 case AtomicExpr::AO__c11_atomic_exchange:
1244 case AtomicExpr::AO__hip_atomic_exchange:
1245 case AtomicExpr::AO__opencl_atomic_exchange:
1246 case AtomicExpr::AO__scoped_atomic_exchange:
1247 case AtomicExpr::AO__scoped_atomic_exchange_n:
1248 LibCallName =
"__atomic_exchange";
1254 case AtomicExpr::AO__atomic_store:
1255 case AtomicExpr::AO__atomic_store_n:
1256 case AtomicExpr::AO__c11_atomic_store:
1257 case AtomicExpr::AO__hip_atomic_store:
1258 case AtomicExpr::AO__opencl_atomic_store:
1259 case AtomicExpr::AO__scoped_atomic_store:
1260 case AtomicExpr::AO__scoped_atomic_store_n:
1261 LibCallName =
"__atomic_store";
1269 case AtomicExpr::AO__atomic_load:
1270 case AtomicExpr::AO__atomic_load_n:
1271 case AtomicExpr::AO__c11_atomic_load:
1272 case AtomicExpr::AO__hip_atomic_load:
1273 case AtomicExpr::AO__opencl_atomic_load:
1274 case AtomicExpr::AO__scoped_atomic_load:
1275 case AtomicExpr::AO__scoped_atomic_load_n:
1276 LibCallName =
"__atomic_load";
1278 case AtomicExpr::AO__atomic_add_fetch:
1279 case AtomicExpr::AO__scoped_atomic_add_fetch:
1280 case AtomicExpr::AO__atomic_fetch_add:
1281 case AtomicExpr::AO__c11_atomic_fetch_add:
1282 case AtomicExpr::AO__hip_atomic_fetch_add:
1283 case AtomicExpr::AO__opencl_atomic_fetch_add:
1284 case AtomicExpr::AO__scoped_atomic_fetch_add:
1285 case AtomicExpr::AO__atomic_and_fetch:
1286 case AtomicExpr::AO__scoped_atomic_and_fetch:
1287 case AtomicExpr::AO__atomic_fetch_and:
1288 case AtomicExpr::AO__c11_atomic_fetch_and:
1289 case AtomicExpr::AO__hip_atomic_fetch_and:
1290 case AtomicExpr::AO__opencl_atomic_fetch_and:
1291 case AtomicExpr::AO__scoped_atomic_fetch_and:
1292 case AtomicExpr::AO__atomic_or_fetch:
1293 case AtomicExpr::AO__scoped_atomic_or_fetch:
1294 case AtomicExpr::AO__atomic_fetch_or:
1295 case AtomicExpr::AO__c11_atomic_fetch_or:
1296 case AtomicExpr::AO__hip_atomic_fetch_or:
1297 case AtomicExpr::AO__opencl_atomic_fetch_or:
1298 case AtomicExpr::AO__scoped_atomic_fetch_or:
1299 case AtomicExpr::AO__atomic_sub_fetch:
1300 case AtomicExpr::AO__scoped_atomic_sub_fetch:
1301 case AtomicExpr::AO__atomic_fetch_sub:
1302 case AtomicExpr::AO__c11_atomic_fetch_sub:
1303 case AtomicExpr::AO__hip_atomic_fetch_sub:
1304 case AtomicExpr::AO__opencl_atomic_fetch_sub:
1305 case AtomicExpr::AO__scoped_atomic_fetch_sub:
1306 case AtomicExpr::AO__atomic_xor_fetch:
1307 case AtomicExpr::AO__scoped_atomic_xor_fetch:
1308 case AtomicExpr::AO__atomic_fetch_xor:
1309 case AtomicExpr::AO__c11_atomic_fetch_xor:
1310 case AtomicExpr::AO__hip_atomic_fetch_xor:
1311 case AtomicExpr::AO__opencl_atomic_fetch_xor:
1312 case AtomicExpr::AO__scoped_atomic_fetch_xor:
1313 case AtomicExpr::AO__atomic_nand_fetch:
1314 case AtomicExpr::AO__atomic_fetch_nand:
1315 case AtomicExpr::AO__c11_atomic_fetch_nand:
1316 case AtomicExpr::AO__scoped_atomic_fetch_nand:
1317 case AtomicExpr::AO__scoped_atomic_nand_fetch:
1318 case AtomicExpr::AO__atomic_min_fetch:
1319 case AtomicExpr::AO__atomic_fetch_min:
1320 case AtomicExpr::AO__c11_atomic_fetch_min:
1321 case AtomicExpr::AO__hip_atomic_fetch_min:
1322 case AtomicExpr::AO__opencl_atomic_fetch_min:
1323 case AtomicExpr::AO__scoped_atomic_fetch_min:
1324 case AtomicExpr::AO__scoped_atomic_min_fetch:
1325 case AtomicExpr::AO__atomic_max_fetch:
1326 case AtomicExpr::AO__atomic_fetch_max:
1327 case AtomicExpr::AO__c11_atomic_fetch_max:
1328 case AtomicExpr::AO__hip_atomic_fetch_max:
1329 case AtomicExpr::AO__opencl_atomic_fetch_max:
1330 case AtomicExpr::AO__scoped_atomic_fetch_max:
1331 case AtomicExpr::AO__scoped_atomic_max_fetch:
1332 case AtomicExpr::AO__atomic_fetch_fminimum:
1333 case AtomicExpr::AO__atomic_fetch_fmaximum:
1334 case AtomicExpr::AO__atomic_fetch_fminimum_num:
1335 case AtomicExpr::AO__atomic_fetch_fmaximum_num:
1336 case AtomicExpr::AO__scoped_atomic_fetch_fminimum:
1337 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum:
1338 case AtomicExpr::AO__scoped_atomic_fetch_fminimum_num:
1339 case AtomicExpr::AO__scoped_atomic_fetch_fmaximum_num:
1340 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
1341 case AtomicExpr::AO__scoped_atomic_fetch_udec:
1342 case AtomicExpr::AO__atomic_test_and_set:
1343 case AtomicExpr::AO__atomic_clear:
1344 case AtomicExpr::AO__atomic_fetch_uinc:
1345 case AtomicExpr::AO__atomic_fetch_udec:
1346 llvm_unreachable(
"Integral atomic operations always become atomicrmw!");
1351 std::string(
"__opencl") + StringRef(LibCallName).drop_front(1).str();
1379 bool IsStore = E->
getOp() == AtomicExpr::AO__c11_atomic_store ||
1380 E->
getOp() == AtomicExpr::AO__opencl_atomic_store ||
1381 E->
getOp() == AtomicExpr::AO__hip_atomic_store ||
1382 E->
getOp() == AtomicExpr::AO__atomic_store ||
1383 E->
getOp() == AtomicExpr::AO__atomic_store_n ||
1384 E->
getOp() == AtomicExpr::AO__scoped_atomic_store ||
1385 E->
getOp() == AtomicExpr::AO__scoped_atomic_store_n ||
1386 E->
getOp() == AtomicExpr::AO__atomic_clear;
1387 bool IsLoad = E->
getOp() == AtomicExpr::AO__c11_atomic_load ||
1388 E->
getOp() == AtomicExpr::AO__opencl_atomic_load ||
1389 E->
getOp() == AtomicExpr::AO__hip_atomic_load ||
1390 E->
getOp() == AtomicExpr::AO__atomic_load ||
1391 E->
getOp() == AtomicExpr::AO__atomic_load_n ||
1392 E->
getOp() == AtomicExpr::AO__scoped_atomic_load ||
1393 E->
getOp() == AtomicExpr::AO__scoped_atomic_load_n;
1399 if (llvm::isValidAtomicOrderingCABI(ord))
1400 switch ((llvm::AtomicOrderingCABI)ord) {
1401 case llvm::AtomicOrderingCABI::relaxed:
1402 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1403 OrderFail, Size, llvm::AtomicOrdering::Monotonic,
Scope);
1405 case llvm::AtomicOrderingCABI::consume:
1406 case llvm::AtomicOrderingCABI::acquire:
1409 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1410 OrderFail, Size, llvm::AtomicOrdering::Acquire,
Scope);
1412 case llvm::AtomicOrderingCABI::release:
1415 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1416 OrderFail, Size, llvm::AtomicOrdering::Release,
Scope);
1418 case llvm::AtomicOrderingCABI::acq_rel:
1419 if (IsLoad || IsStore)
1421 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1422 OrderFail, Size, llvm::AtomicOrdering::AcquireRelease,
1425 case llvm::AtomicOrderingCABI::seq_cst:
1426 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1428 llvm::AtomicOrdering::SequentiallyConsistent,
Scope);
1441 llvm::BasicBlock *MonotonicBB =
nullptr, *AcquireBB =
nullptr,
1442 *ReleaseBB =
nullptr, *AcqRelBB =
nullptr,
1443 *SeqCstBB =
nullptr;
1449 if (!IsLoad && !IsStore)
1458 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
1459 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, MonotonicBB);
1462 Builder.SetInsertPoint(MonotonicBB);
1463 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak, OrderFail,
1464 Size, llvm::AtomicOrdering::Monotonic,
Scope);
1467 Builder.SetInsertPoint(AcquireBB);
1468 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1469 OrderFail, Size, llvm::AtomicOrdering::Acquire,
Scope);
1471 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::consume),
1473 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acquire),
1477 Builder.SetInsertPoint(ReleaseBB);
1478 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1479 OrderFail, Size, llvm::AtomicOrdering::Release,
Scope);
1481 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::release),
1484 if (!IsLoad && !IsStore) {
1485 Builder.SetInsertPoint(AcqRelBB);
1486 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1487 OrderFail, Size, llvm::AtomicOrdering::AcquireRelease,
Scope);
1489 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acq_rel),
1492 Builder.SetInsertPoint(SeqCstBB);
1493 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak, OrderFail,
1494 Size, llvm::AtomicOrdering::SequentiallyConsistent,
Scope);
1496 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::seq_cst),
1500 Builder.SetInsertPoint(ContBB);
1504 assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
1510 llvm::IntegerType *ty =
1516 llvm::Type *Ty =
Addr.getElementType();
1518 if (SourceSizeInBits != AtomicSizeInBits) {
1519 Address Tmp = CreateTempAlloca();
1526 std::min(AtomicSizeInBits, SourceSizeInBits) / 8);
1530 return castToAtomicIntPointer(
Addr);
1533RValue AtomicInfo::convertAtomicTempToRValue(Address addr,
1534 AggValueSlot resultSlot,
1536 bool asValue)
const {
1537 if (LVal.isSimple()) {
1552 if (LVal.isBitField())
1554 LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(),
1555 LVal.getBaseInfo(), TBAAAccessInfo()), loc);
1556 if (LVal.isVectorElt())
1558 LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(),
1559 LVal.getBaseInfo(), TBAAAccessInfo()), loc);
1560 assert(LVal.isExtVectorElt());
1562 addr, LVal.getExtVectorElts(), LVal.getType(),
1563 LVal.getBaseInfo(), TBAAAccessInfo()));
1566RValue AtomicInfo::ConvertToValueOrAtomic(llvm::Value *Val,
1567 AggValueSlot ResultSlot,
1568 SourceLocation Loc,
bool AsValue,
1569 bool CmpXchg)
const {
1571 assert((Val->getType()->isIntegerTy() || Val->getType()->isPointerTy() ||
1572 Val->getType()->isIEEELikeFPTy()) &&
1573 "Expected integer, pointer or floating point value when converting "
1576 (((!LVal.isBitField() ||
1577 LVal.getBitFieldInfo().Size == ValueSizeInBits) &&
1580 auto *ValTy = AsValue
1582 : getAtomicAddress().getElementType();
1584 assert((!ValTy->isIntegerTy() || Val->getType() == ValTy) &&
1585 "Different integer types.");
1588 if (llvm::CastInst::isBitCastable(Val->getType(), ValTy))
1595 bool TempIsVolatile =
false;
1601 Temp = CreateTempAlloca();
1605 Address CastTemp = castToAtomicIntPointer(Temp);
1608 return convertAtomicTempToRValue(Temp, ResultSlot, Loc, AsValue);
1611void AtomicInfo::EmitAtomicLoadLibcall(llvm::Value *AddForLoaded,
1612 llvm::AtomicOrdering AO,
bool) {
1624llvm::Value *AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO,
1625 bool IsVolatile,
bool CmpXchg) {
1629 Addr = castToAtomicIntPointer(
Addr);
1631 Load->setAtomic(AO);
1635 Load->setVolatile(
true);
1644 if (!
CGM.getLangOpts().MSVolatile)
return false;
1645 AtomicInfo AI(*
this, LV);
1648 bool AtomicIsInline = !AI.shouldUseLibcall();
1653 return IsVolatile && AtomicIsInline;
1658 llvm::AtomicOrdering AO;
1661 AO = llvm::AtomicOrdering::SequentiallyConsistent;
1663 AO = llvm::AtomicOrdering::Acquire;
1670 bool AsValue, llvm::AtomicOrdering AO,
1673 if (shouldUseLibcall()) {
1675 if (LVal.isSimple() && !ResultSlot.
isIgnored()) {
1679 TempAddr = CreateTempAlloca();
1681 EmitAtomicLoadLibcall(TempAddr.
emitRawPointer(CGF), AO, IsVolatile);
1685 return convertAtomicTempToRValue(TempAddr, ResultSlot, Loc, AsValue);
1689 auto *Load = EmitAtomicLoadOp(AO, IsVolatile);
1697 return ConvertToValueOrAtomic(Load, ResultSlot, Loc, AsValue);
1703 llvm::AtomicOrdering AO,
bool IsVolatile,
1705 AtomicInfo Atomics(*
this, src);
1706 return Atomics.EmitAtomicLoad(resultSlot, loc,
true, AO,
1712void AtomicInfo::emitCopyIntoMemory(
RValue rvalue)
const {
1713 assert(LVal.isSimple());
1722 LVal.isVolatileQualified();
1731 emitMemSetZeroIfNecessary();
1734 LValue TempLVal = projectValue();
1747Address AtomicInfo::materializeRValue(RValue rvalue)
const {
1754 LValue TempLV = CGF.
MakeAddrLValue(CreateTempAlloca(), getAtomicType());
1755 AtomicInfo Atomics(CGF, TempLV);
1756 Atomics.emitCopyIntoMemory(rvalue);
1757 return TempLV.getAddress();
1760llvm::Value *AtomicInfo::getScalarRValValueOrNull(RValue RVal)
const {
1761 if (RVal.
isScalar() && (!hasPadding() || !LVal.isSimple()))
1766llvm::Value *AtomicInfo::convertRValueToInt(RValue RVal,
bool CmpXchg)
const {
1769 if (llvm::Value *
Value = getScalarRValValueOrNull(RVal)) {
1773 llvm::IntegerType *InputIntTy = llvm::IntegerType::get(
1775 LVal.isSimple() ? getValueSizeInBits() : getAtomicSizeInBits());
1776 if (llvm::BitCastInst::isBitCastable(
Value->getType(), InputIntTy))
1785 Addr = castToAtomicIntPointer(
Addr);
1789std::pair<llvm::Value *, llvm::Value *> AtomicInfo::EmitAtomicCompareExchangeOp(
1790 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
1791 llvm::AtomicOrdering
Success, llvm::AtomicOrdering
Failure,
bool IsWeak) {
1793 Address Addr = getAtomicAddressAsAtomicIntPointer();
1797 Inst->setVolatile(LVal.isVolatileQualified());
1798 Inst->setWeak(IsWeak);
1801 auto *PreviousVal = CGF.
Builder.CreateExtractValue(Inst, 0);
1802 auto *SuccessFailureVal = CGF.
Builder.CreateExtractValue(Inst, 1);
1803 return std::make_pair(PreviousVal, SuccessFailureVal);
1807AtomicInfo::EmitAtomicCompareExchangeLibcall(llvm::Value *ExpectedAddr,
1808 llvm::Value *DesiredAddr,
1810 llvm::AtomicOrdering
Failure) {
1819 llvm::ConstantInt::get(CGF.
IntTy, (
int)llvm::toCABI(
Success))),
1822 llvm::ConstantInt::get(CGF.
IntTy, (
int)llvm::toCABI(
Failure))),
1827 return SuccessFailureRVal.getScalarVal();
1830std::pair<RValue, llvm::Value *> AtomicInfo::EmitAtomicCompareExchange(
1831 RValue Expected, RValue Desired, llvm::AtomicOrdering
Success,
1832 llvm::AtomicOrdering
Failure,
bool IsWeak) {
1834 if (shouldUseLibcall()) {
1836 Address ExpectedAddr = materializeRValue(Expected);
1838 llvm::Value *DesiredPtr = materializeRValue(Desired).emitRawPointer(CGF);
1839 auto *Res = EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr,
1841 return std::make_pair(
1843 SourceLocation(),
false),
1849 auto *ExpectedVal = convertRValueToInt(Expected,
true);
1850 auto *DesiredVal = convertRValueToInt(Desired,
true);
1851 auto Res = EmitAtomicCompareExchangeOp(ExpectedVal, DesiredVal,
Success,
1853 return std::make_pair(
1855 SourceLocation(),
false,
1865 LValue AtomicLVal = Atomics.getAtomicLValue();
1867 if (AtomicLVal.isSimple()) {
1869 DesiredLVal = CGF.
MakeAddrLValue(DesiredAddr, AtomicLVal.getType());
1872 Address Ptr = Atomics.materializeRValue(OldRVal);
1874 if (AtomicLVal.isBitField()) {
1876 LValue::MakeBitfield(Ptr, AtomicLVal.getBitFieldInfo(),
1877 AtomicLVal.getType(),
1878 AtomicLVal.getBaseInfo(),
1879 AtomicLVal.getTBAAInfo());
1881 LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
1882 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1883 AtomicLVal.getTBAAInfo());
1884 }
else if (AtomicLVal.isVectorElt()) {
1885 UpdateLVal = LValue::MakeVectorElt(Ptr, AtomicLVal.getVectorIdx(),
1886 AtomicLVal.getType(),
1887 AtomicLVal.getBaseInfo(),
1888 AtomicLVal.getTBAAInfo());
1889 DesiredLVal = LValue::MakeVectorElt(
1890 DesiredAddr, AtomicLVal.getVectorIdx(), AtomicLVal.getType(),
1891 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
1893 assert(AtomicLVal.isExtVectorElt());
1894 UpdateLVal = LValue::MakeExtVectorElt(Ptr, AtomicLVal.getExtVectorElts(),
1895 AtomicLVal.getType(),
1896 AtomicLVal.getBaseInfo(),
1897 AtomicLVal.getTBAAInfo());
1898 DesiredLVal = LValue::MakeExtVectorElt(
1899 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
1900 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
1905 RValue NewRVal = UpdateOp(UpRVal);
1915void AtomicInfo::EmitAtomicUpdateLibcall(
1916 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
1918 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1920 Address ExpectedAddr = CreateTempAlloca();
1922 EmitAtomicLoadLibcall(ExpectedAddr.
emitRawPointer(CGF), AO, IsVolatile);
1926 Address DesiredAddr = CreateTempAlloca();
1927 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
1928 requiresMemSetZero(getAtomicAddress().getElementType())) {
1932 auto OldRVal = convertAtomicTempToRValue(ExpectedAddr,
1934 SourceLocation(),
false);
1939 EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO,
Failure);
1940 CGF.
Builder.CreateCondBr(Res, ExitBB, ContBB);
1944void AtomicInfo::EmitAtomicUpdateOp(
1945 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
1947 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1950 auto *OldVal = EmitAtomicLoadOp(
Failure, IsVolatile,
true);
1954 auto *CurBB = CGF.
Builder.GetInsertBlock();
1956 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(OldVal->getType(),
1958 PHI->addIncoming(OldVal, CurBB);
1959 Address NewAtomicAddr = CreateTempAlloca();
1962 ? castToAtomicIntPointer(NewAtomicAddr)
1965 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
1966 requiresMemSetZero(getAtomicAddress().getElementType())) {
1970 SourceLocation(),
false,
1975 auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO,
Failure);
1976 PHI->addIncoming(Res.first, CGF.
Builder.GetInsertBlock());
1977 CGF.
Builder.CreateCondBr(Res.second, ExitBB, ContBB);
1983 LValue AtomicLVal = Atomics.getAtomicLValue();
1986 if (AtomicLVal.isBitField()) {
1988 LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
1989 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1990 AtomicLVal.getTBAAInfo());
1991 }
else if (AtomicLVal.isVectorElt()) {
1993 LValue::MakeVectorElt(DesiredAddr, AtomicLVal.getVectorIdx(),
1994 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1995 AtomicLVal.getTBAAInfo());
1997 assert(AtomicLVal.isExtVectorElt());
1998 DesiredLVal = LValue::MakeExtVectorElt(
1999 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
2000 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
2007void AtomicInfo::EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO,
2008 RValue UpdateRVal,
bool IsVolatile) {
2009 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
2011 Address ExpectedAddr = CreateTempAlloca();
2013 EmitAtomicLoadLibcall(ExpectedAddr.
emitRawPointer(CGF), AO, IsVolatile);
2017 Address DesiredAddr = CreateTempAlloca();
2018 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
2019 requiresMemSetZero(getAtomicAddress().getElementType())) {
2027 EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO,
Failure);
2028 CGF.
Builder.CreateCondBr(Res, ExitBB, ContBB);
2032void AtomicInfo::EmitAtomicUpdateOp(llvm::AtomicOrdering AO, RValue UpdateRVal,
2034 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
2037 auto *OldVal = EmitAtomicLoadOp(
Failure, IsVolatile,
true);
2041 auto *CurBB = CGF.
Builder.GetInsertBlock();
2043 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(OldVal->getType(),
2045 PHI->addIncoming(OldVal, CurBB);
2046 Address NewAtomicAddr = CreateTempAlloca();
2047 Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
2048 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
2049 requiresMemSetZero(getAtomicAddress().getElementType())) {
2055 auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO,
Failure);
2056 PHI->addIncoming(Res.first, CGF.
Builder.GetInsertBlock());
2057 CGF.
Builder.CreateCondBr(Res.second, ExitBB, ContBB);
2061void AtomicInfo::EmitAtomicUpdate(
2062 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
2064 if (shouldUseLibcall()) {
2065 EmitAtomicUpdateLibcall(AO, UpdateOp, IsVolatile);
2067 EmitAtomicUpdateOp(AO, UpdateOp, IsVolatile);
2071void AtomicInfo::EmitAtomicUpdate(llvm::AtomicOrdering AO, RValue UpdateRVal,
2073 if (shouldUseLibcall()) {
2074 EmitAtomicUpdateLibcall(AO, UpdateRVal, IsVolatile);
2076 EmitAtomicUpdateOp(AO, UpdateRVal, IsVolatile);
2083 llvm::AtomicOrdering AO;
2085 AO = llvm::AtomicOrdering::SequentiallyConsistent;
2087 AO = llvm::AtomicOrdering::Release;
2099 llvm::AtomicOrdering AO,
bool IsVolatile,
2107 AtomicInfo atomics(*
this, dest);
2108 LValue LVal = atomics.getAtomicLValue();
2113 atomics.emitCopyIntoMemory(rvalue);
2118 if (atomics.shouldUseLibcall()) {
2120 Address srcAddr = atomics.materializeRValue(rvalue);
2137 llvm::Value *ValToStore = atomics.convertRValueToInt(rvalue);
2141 if (llvm::Value *
Value = atomics.getScalarRValValueOrNull(rvalue))
2143 Addr = atomics.castToAtomicIntPointer(
Addr);
2144 ValToStore =
Builder.CreateIntCast(ValToStore,
Addr.getElementType(),
2147 llvm::StoreInst *store =
Builder.CreateStore(ValToStore,
Addr);
2149 if (AO == llvm::AtomicOrdering::Acquire)
2150 AO = llvm::AtomicOrdering::Monotonic;
2151 else if (AO == llvm::AtomicOrdering::AcquireRelease)
2152 AO = llvm::AtomicOrdering::Release;
2155 store->setAtomic(AO);
2159 store->setVolatile(
true);
2165 atomics.EmitAtomicUpdate(AO, rvalue, IsVolatile);
2172 llvm::AtomicOrdering
Success, llvm::AtomicOrdering
Failure,
bool IsWeak,
2177 Expected.getAggregateAddress().getElementType() ==
2182 AtomicInfo Atomics(*
this, Obj);
2188llvm::AtomicRMWInst *
2190 llvm::Value *Val, llvm::AtomicOrdering Order,
2191 llvm::SyncScope::ID SSID,
2193 llvm::AtomicRMWInst *RMW =
2194 Builder.CreateAtomicRMW(Op,
Addr, Val, Order, SSID);
2200 LValue LVal, llvm::AtomicOrdering AO,
2201 const llvm::function_ref<
RValue(
RValue)> &UpdateOp,
bool IsVolatile) {
2202 AtomicInfo Atomics(*
this, LVal);
2203 Atomics.EmitAtomicUpdate(AO, UpdateOp, IsVolatile);
2207 AtomicInfo atomics(*
this, dest);
2209 switch (atomics.getEvaluationKind()) {
2225 bool Zeroed =
false;
2227 Zeroed = atomics.emitMemSetZeroIfNecessary();
2228 dest = atomics.projectValue();
2242 llvm_unreachable(
"bad evaluation kind");
Defines the clang::ASTContext interface.
static llvm::Value * EmitPostAtomicMinMax(CGBuilderTy &Builder, AtomicExpr::AtomicOp Op, bool IsSigned, llvm::Value *OldVal, llvm::Value *RHS)
Duplicate the atomic min/max operation in conventional IR for the builtin variants that return the ne...
static void EmitAtomicUpdateValue(CodeGenFunction &CGF, AtomicInfo &Atomics, RValue OldRVal, const llvm::function_ref< RValue(RValue)> &UpdateOp, Address DesiredAddr)
static Address EmitValToTemp(CodeGenFunction &CGF, Expr *E)
static RValue emitAtomicLibcall(CodeGenFunction &CGF, StringRef fnName, QualType resultType, CallArgList &args)
static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest, Address Ptr, Address Val1, Address Val2, Address ExpectedResult, llvm::Value *IsWeak, llvm::Value *FailureOrder, uint64_t Size, llvm::AtomicOrdering Order, llvm::SyncScope::ID Scope)
static Address EmitPointerWithAlignment(const Expr *E, LValueBaseInfo *BaseInfo, TBAAAccessInfo *TBAAInfo, KnownNonNull_t IsKnownNonNull, CodeGenFunction &CGF)
static bool shouldCastToInt(mlir::Type valueTy, bool cmpxchg)
Return true if.
static void emitAtomicCmpXchg(CIRGenFunction &cgf, AtomicExpr *e, bool isWeak, Address dest, Address ptr, Address val1, Address val2, uint64_t size, cir::MemOrder successOrder, cir::MemOrder failureOrder, cir::SyncScopeKind scope)
static bool isFullSizeType(CIRGenModule &cgm, mlir::Type ty, uint64_t expectedSize)
Does a store of the given IR type modify the full expected width?
static void emitAtomicCmpXchgFailureSet(CIRGenFunction &cgf, AtomicExpr *e, bool isWeak, Address dest, Address ptr, Address val1, Address val2, Expr *failureOrderExpr, uint64_t size, cir::MemOrder successOrder, cir::SyncScopeKind scope)
Result
Implement __builtin_bit_cast and related operations.
static QualType getPointeeType(const MemRegion *R)
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
static std::unique_ptr< AtomicScopeModel > getScopeModel(AtomicOp Op)
Get atomic scope model for the atomic op code.
QualType getValueType() const
SourceLocation getBeginLoc() const LLVM_READONLY
Expr * getOrderFail() const
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isMultipleOf(CharUnits N) const
Test whether this is a multiple of the other value.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Address getAddress() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
A scoped helper to set the current source atom group for CGDebugInfo::addInstToCurrentSourceAtom.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
llvm::AtomicCmpXchgInst * CreateAtomicCmpXchg(Address Addr, llvm::Value *Cmp, llvm::Value *New, llvm::AtomicOrdering SuccessOrdering, llvm::AtomicOrdering FailureOrdering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
CGFunctionInfo - Class to encapsulate the information about a function definition.
CallArgList - Type for representing both the value and type of arguments in a call.
void add(RValue rvalue, QualType type)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * performAddrSpaceCast(llvm::Value *Src, llvm::Type *DestTy)
void EmitAtomicInit(Expr *E, LValue lvalue)
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Given the address of a temporary variable, produce an r-value of its type.
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
const LangOptions & getLangOpts() const
void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, const llvm::function_ref< RValue(RValue)> &UpdateOp, bool IsVolatile)
std::pair< RValue, llvm::Value * > EmitAtomicCompareExchange(LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, llvm::AtomicOrdering Success=llvm::AtomicOrdering::SequentiallyConsistent, llvm::AtomicOrdering Failure=llvm::AtomicOrdering::SequentiallyConsistent, bool IsWeak=false, AggValueSlot Slot=AggValueSlot::ignored())
Emit a compare-and-exchange op for atomic type.
void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty, SourceLocation Loc)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
const TargetInfo & getTarget() const
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
CGDebugInfo * getDebugInfo()
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
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...
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
const TargetCodeGenInfo & getTargetHooks() const
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
ASTContext & getContext() const
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
llvm::AtomicRMWInst * emitAtomicRMWInst(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val, llvm::AtomicOrdering Order=llvm::AtomicOrdering::SequentiallyConsistent, llvm::SyncScope::ID SSID=llvm::SyncScope::System, const AtomicExpr *AE=nullptr)
Emit an atomicrmw instruction, and applying relevant metadata when applicable.
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...
llvm::Type * ConvertTypeForMem(QualType T)
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
RValue EmitAtomicExpr(AtomicExpr *E)
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
RValue EmitLoadOfExtVectorElementLValue(LValue V)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
llvm::LLVMContext & getLLVMContext()
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
This class organizes the cross-function state that is used while generating LLVM code.
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
const llvm::DataLayout & getDataLayout() const
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
llvm::LLVMContext & getLLVMContext()
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
LValue - This represents an lvalue references.
bool isVolatileQualified() const
Address getAddress() const
TBAAAccessInfo getTBAAInfo() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
bool isVolatileQualified() const
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, SyncScope Scope, llvm::AtomicOrdering Ordering, llvm::LLVMContext &Ctx) const
Get the syncscope used in LLVM IR as a SyncScope ID.
virtual void setTargetAtomicMetadata(CodeGenFunction &CGF, llvm::Instruction &AtomicInst, const AtomicExpr *Expr=nullptr) const
Allow the target to apply other metadata to an atomic instruction.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isAtomicType() const
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
@ Address
A pointer to a ValueDecl.
bool Load(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Success
Annotation was successful.
llvm::Expected< QualType > ExpectedType
llvm::StringRef getAsString(SyncScope S)
U cast(CodeGen::Address addr)
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned Size
The total size of the bit-field, in bits.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * SizeTy
llvm::IntegerType * IntTy
int
llvm::PointerType * DefaultPtrTy