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,
237 llvm::AtomicOrdering Failure =
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,
272 llvm::AtomicOrdering Failure =
273 llvm::AtomicOrdering::SequentiallyConsistent);
275 std::pair<llvm::Value *, llvm::Value *> EmitAtomicCompareExchangeOp(
276 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
278 llvm::AtomicOrdering::SequentiallyConsistent,
279 llvm::AtomicOrdering Failure =
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 {
302 (LVal.isBitField() && ValueSizeInBits > AtomicSizeInBits) ? ValueTy
304 getAtomicAlignment(),
307 if (LVal.isBitField())
309 TempAlloca, getAtomicAddress().
getType(),
310 getAtomicAddress().getElementType());
322 fnAttrB.addAttribute(llvm::Attribute::NoUnwind);
323 fnAttrB.addAttribute(llvm::Attribute::WillReturn);
324 llvm::AttributeList fnAttrs = llvm::AttributeList::get(
325 CGF.
getLLVMContext(), llvm::AttributeList::FunctionIndex, fnAttrB);
327 llvm::FunctionCallee fn =
335 uint64_t expectedSize) {
342bool AtomicInfo::requiresMemSetZero(llvm::Type *
type)
const {
344 if (hasPadding())
return true;
347 switch (getEvaluationKind()) {
354 AtomicSizeInBits / 2);
360 llvm_unreachable(
"bad evaluation kind");
363bool AtomicInfo::emitMemSetZeroIfNecessary()
const {
364 assert(LVal.isSimple());
365 Address addr = LVal.getAddress();
372 LVal.getAlignment().getAsAlign());
379 uint64_t Size, llvm::AtomicOrdering SuccessOrder,
380 llvm::AtomicOrdering FailureOrder,
381 llvm::SyncScope::ID
Scope) {
389 Pair->setWeak(IsWeak);
394 llvm::Value *Old = CGF.
Builder.CreateExtractValue(Pair, 0);
395 llvm::Value *Cmp = CGF.
Builder.CreateExtractValue(Pair, 1);
399 llvm::BasicBlock *StoreExpectedBB =
404 llvm::BasicBlock *ContinueBB =
409 CGF.
Builder.CreateCondBr(Cmp, ContinueBB, StoreExpectedBB);
411 CGF.
Builder.SetInsertPoint(StoreExpectedBB);
415 uint64_t ExpectedSizeInBytes = DL.getTypeStoreSize(
ExpectedType);
417 if (ExpectedSizeInBytes == Size) {
423 llvm::Type *OldType = Old->getType();
439 CGF.
Builder.CreateBr(ContinueBB);
441 CGF.
Builder.SetInsertPoint(ContinueBB);
452 llvm::Value *FailureOrderVal, uint64_t Size,
453 llvm::AtomicOrdering SuccessOrder, llvm::SyncScope::ID
Scope) {
454 llvm::AtomicOrdering FailureOrder;
455 if (llvm::ConstantInt *FO = dyn_cast<llvm::ConstantInt>(FailureOrderVal)) {
456 auto FOS = FO->getSExtValue();
457 if (!llvm::isValidAtomicOrderingCABI(FOS))
458 FailureOrder = llvm::AtomicOrdering::Monotonic;
460 switch ((llvm::AtomicOrderingCABI)FOS) {
461 case llvm::AtomicOrderingCABI::relaxed:
464 case llvm::AtomicOrderingCABI::release:
465 case llvm::AtomicOrderingCABI::acq_rel:
466 FailureOrder = llvm::AtomicOrdering::Monotonic;
468 case llvm::AtomicOrderingCABI::consume:
469 case llvm::AtomicOrderingCABI::acquire:
470 FailureOrder = llvm::AtomicOrdering::Acquire;
472 case llvm::AtomicOrderingCABI::seq_cst:
473 FailureOrder = llvm::AtomicOrdering::SequentiallyConsistent;
481 Size, SuccessOrder, FailureOrder,
Scope);
494 llvm::SwitchInst *SI = CGF.
Builder.CreateSwitch(FailureOrderVal, MonotonicBB);
496 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::consume),
498 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acquire),
500 SI->addCase(CGF.
Builder.getInt32((
int)llvm::AtomicOrderingCABI::seq_cst),
504 CGF.
Builder.SetInsertPoint(MonotonicBB);
506 SuccessOrder, llvm::AtomicOrdering::Monotonic,
Scope);
509 CGF.
Builder.SetInsertPoint(AcquireBB);
511 SuccessOrder, llvm::AtomicOrdering::Acquire,
Scope);
514 CGF.
Builder.SetInsertPoint(SeqCstBB);
516 SuccessOrder, llvm::AtomicOrdering::SequentiallyConsistent,
520 CGF.
Builder.SetInsertPoint(ContBB);
530 const bool IsFP = OldVal->getType()->isFloatingPointTy();
533 llvm::Intrinsic::ID IID = (Op == AtomicExpr::AO__atomic_max_fetch ||
534 Op == AtomicExpr::AO__scoped_atomic_max_fetch)
535 ? llvm::Intrinsic::maxnum
536 : llvm::Intrinsic::minnum;
538 return Builder.CreateBinaryIntrinsic(IID, OldVal, RHS, llvm::FMFSource(),
542 llvm::CmpInst::Predicate Pred;
545 llvm_unreachable(
"Unexpected min/max operation");
546 case AtomicExpr::AO__atomic_max_fetch:
547 case AtomicExpr::AO__scoped_atomic_max_fetch:
548 Pred = IsSigned ? llvm::CmpInst::ICMP_SGT : llvm::CmpInst::ICMP_UGT;
550 case AtomicExpr::AO__atomic_min_fetch:
551 case AtomicExpr::AO__scoped_atomic_min_fetch:
552 Pred = IsSigned ? llvm::CmpInst::ICMP_SLT : llvm::CmpInst::ICMP_ULT;
555 llvm::Value *Cmp = Builder.CreateICmp(Pred, OldVal, RHS,
"tst");
556 return Builder.CreateSelect(Cmp, OldVal, RHS,
"newval");
561 Address ExpectedResult, llvm::Value *IsWeak,
562 llvm::Value *FailureOrder, uint64_t Size,
563 llvm::AtomicOrdering Order,
564 llvm::SyncScope::ID
Scope) {
565 llvm::AtomicRMWInst::BinOp Op = llvm::AtomicRMWInst::Add;
566 bool PostOpMinMax =
false;
569 switch (E->
getOp()) {
570 case AtomicExpr::AO__c11_atomic_init:
571 case AtomicExpr::AO__opencl_atomic_init:
572 llvm_unreachable(
"Already handled!");
574 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
575 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
576 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
578 ExpectedResult, FailureOrder, Size, Order,
581 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
582 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
583 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
585 ExpectedResult, FailureOrder, Size, Order,
588 case AtomicExpr::AO__atomic_compare_exchange:
589 case AtomicExpr::AO__atomic_compare_exchange_n:
590 case AtomicExpr::AO__scoped_atomic_compare_exchange:
591 case AtomicExpr::AO__scoped_atomic_compare_exchange_n: {
592 if (llvm::ConstantInt *IsWeakC = dyn_cast<llvm::ConstantInt>(IsWeak)) {
594 Val1, Val2, ExpectedResult, FailureOrder,
598 llvm::BasicBlock *StrongBB =
601 llvm::BasicBlock *ContBB =
604 llvm::SwitchInst *SI = CGF.
Builder.CreateSwitch(IsWeak, WeakBB);
605 SI->addCase(CGF.
Builder.getInt1(
false), StrongBB);
607 CGF.
Builder.SetInsertPoint(StrongBB);
609 ExpectedResult, FailureOrder, Size, Order,
613 CGF.
Builder.SetInsertPoint(WeakBB);
615 ExpectedResult, FailureOrder, Size, Order,
619 CGF.
Builder.SetInsertPoint(ContBB);
623 case AtomicExpr::AO__c11_atomic_load:
624 case AtomicExpr::AO__opencl_atomic_load:
625 case AtomicExpr::AO__hip_atomic_load:
626 case AtomicExpr::AO__atomic_load_n:
627 case AtomicExpr::AO__atomic_load:
628 case AtomicExpr::AO__scoped_atomic_load_n:
629 case AtomicExpr::AO__scoped_atomic_load: {
631 Load->setAtomic(Order,
Scope);
639 case AtomicExpr::AO__c11_atomic_store:
640 case AtomicExpr::AO__opencl_atomic_store:
641 case AtomicExpr::AO__hip_atomic_store:
642 case AtomicExpr::AO__atomic_store:
643 case AtomicExpr::AO__atomic_store_n:
644 case AtomicExpr::AO__scoped_atomic_store:
645 case AtomicExpr::AO__scoped_atomic_store_n: {
648 Store->setAtomic(Order,
Scope);
654 case AtomicExpr::AO__c11_atomic_exchange:
655 case AtomicExpr::AO__hip_atomic_exchange:
656 case AtomicExpr::AO__opencl_atomic_exchange:
657 case AtomicExpr::AO__atomic_exchange_n:
658 case AtomicExpr::AO__atomic_exchange:
659 case AtomicExpr::AO__scoped_atomic_exchange_n:
660 case AtomicExpr::AO__scoped_atomic_exchange:
661 Op = llvm::AtomicRMWInst::Xchg;
664 case AtomicExpr::AO__atomic_add_fetch:
665 case AtomicExpr::AO__scoped_atomic_add_fetch:
667 : llvm::Instruction::Add;
669 case AtomicExpr::AO__c11_atomic_fetch_add:
670 case AtomicExpr::AO__hip_atomic_fetch_add:
671 case AtomicExpr::AO__opencl_atomic_fetch_add:
672 case AtomicExpr::AO__atomic_fetch_add:
673 case AtomicExpr::AO__scoped_atomic_fetch_add:
675 : llvm::AtomicRMWInst::Add;
678 case AtomicExpr::AO__atomic_sub_fetch:
679 case AtomicExpr::AO__scoped_atomic_sub_fetch:
681 : llvm::Instruction::Sub;
683 case AtomicExpr::AO__c11_atomic_fetch_sub:
684 case AtomicExpr::AO__hip_atomic_fetch_sub:
685 case AtomicExpr::AO__opencl_atomic_fetch_sub:
686 case AtomicExpr::AO__atomic_fetch_sub:
687 case AtomicExpr::AO__scoped_atomic_fetch_sub:
689 : llvm::AtomicRMWInst::Sub;
692 case AtomicExpr::AO__atomic_min_fetch:
693 case AtomicExpr::AO__scoped_atomic_min_fetch:
696 case AtomicExpr::AO__c11_atomic_fetch_min:
697 case AtomicExpr::AO__hip_atomic_fetch_min:
698 case AtomicExpr::AO__opencl_atomic_fetch_min:
699 case AtomicExpr::AO__atomic_fetch_min:
700 case AtomicExpr::AO__scoped_atomic_fetch_min:
702 ? llvm::AtomicRMWInst::FMin
704 ? llvm::AtomicRMWInst::Min
705 : llvm::AtomicRMWInst::UMin);
708 case AtomicExpr::AO__atomic_max_fetch:
709 case AtomicExpr::AO__scoped_atomic_max_fetch:
712 case AtomicExpr::AO__c11_atomic_fetch_max:
713 case AtomicExpr::AO__hip_atomic_fetch_max:
714 case AtomicExpr::AO__opencl_atomic_fetch_max:
715 case AtomicExpr::AO__atomic_fetch_max:
716 case AtomicExpr::AO__scoped_atomic_fetch_max:
718 ? llvm::AtomicRMWInst::FMax
720 ? llvm::AtomicRMWInst::Max
721 : llvm::AtomicRMWInst::UMax);
724 case AtomicExpr::AO__atomic_and_fetch:
725 case AtomicExpr::AO__scoped_atomic_and_fetch:
726 PostOp = llvm::Instruction::And;
728 case AtomicExpr::AO__c11_atomic_fetch_and:
729 case AtomicExpr::AO__hip_atomic_fetch_and:
730 case AtomicExpr::AO__opencl_atomic_fetch_and:
731 case AtomicExpr::AO__atomic_fetch_and:
732 case AtomicExpr::AO__scoped_atomic_fetch_and:
733 Op = llvm::AtomicRMWInst::And;
736 case AtomicExpr::AO__atomic_or_fetch:
737 case AtomicExpr::AO__scoped_atomic_or_fetch:
738 PostOp = llvm::Instruction::Or;
740 case AtomicExpr::AO__c11_atomic_fetch_or:
741 case AtomicExpr::AO__hip_atomic_fetch_or:
742 case AtomicExpr::AO__opencl_atomic_fetch_or:
743 case AtomicExpr::AO__atomic_fetch_or:
744 case AtomicExpr::AO__scoped_atomic_fetch_or:
745 Op = llvm::AtomicRMWInst::Or;
748 case AtomicExpr::AO__atomic_xor_fetch:
749 case AtomicExpr::AO__scoped_atomic_xor_fetch:
750 PostOp = llvm::Instruction::Xor;
752 case AtomicExpr::AO__c11_atomic_fetch_xor:
753 case AtomicExpr::AO__hip_atomic_fetch_xor:
754 case AtomicExpr::AO__opencl_atomic_fetch_xor:
755 case AtomicExpr::AO__atomic_fetch_xor:
756 case AtomicExpr::AO__scoped_atomic_fetch_xor:
757 Op = llvm::AtomicRMWInst::Xor;
760 case AtomicExpr::AO__atomic_nand_fetch:
761 case AtomicExpr::AO__scoped_atomic_nand_fetch:
762 PostOp = llvm::Instruction::And;
764 case AtomicExpr::AO__c11_atomic_fetch_nand:
765 case AtomicExpr::AO__atomic_fetch_nand:
766 case AtomicExpr::AO__scoped_atomic_fetch_nand:
767 Op = llvm::AtomicRMWInst::Nand;
770 case AtomicExpr::AO__atomic_fetch_uinc:
771 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
772 Op = llvm::AtomicRMWInst::UIncWrap;
774 case AtomicExpr::AO__atomic_fetch_udec:
775 case AtomicExpr::AO__scoped_atomic_fetch_udec:
776 Op = llvm::AtomicRMWInst::UDecWrap;
779 case AtomicExpr::AO__atomic_test_and_set: {
780 llvm::AtomicRMWInst *RMWI =
791 case AtomicExpr::AO__atomic_clear: {
792 llvm::StoreInst *Store =
794 Store->setAtomic(Order,
Scope);
802 llvm::AtomicRMWInst *RMWI =
808 llvm::Value *Result = RMWI;
814 Result = CGF.
Builder.CreateBinOp((llvm::Instruction::BinaryOps)PostOp, RMWI,
816 if (E->
getOp() == AtomicExpr::AO__atomic_nand_fetch ||
817 E->
getOp() == AtomicExpr::AO__scoped_atomic_nand_fetch)
818 Result = CGF.
Builder.CreateNot(Result);
835 Address OriginalVal1, llvm::Value *IsWeak,
836 llvm::Value *FailureOrder, uint64_t Size,
837 llvm::AtomicOrdering Order, llvm::Value *
Scope) {
838 auto ScopeModel =
Expr->getScopeModel();
843 llvm::SyncScope::ID SS;
853 SS = llvm::SyncScope::System;
855 FailureOrder, Size, Order, SS);
860 if (
auto SC = dyn_cast<llvm::ConstantInt>(
Scope)) {
865 FailureOrder, Size, Order, SCID);
871 auto Scopes = ScopeModel->getRuntimeValues();
872 llvm::DenseMap<unsigned, llvm::BasicBlock *> BB;
873 for (
auto S : Scopes)
876 llvm::BasicBlock *ContBB =
879 auto *SC = Builder.CreateIntCast(
Scope, Builder.getInt32Ty(),
false);
882 auto FallBack = ScopeModel->getFallBackValue();
883 llvm::SwitchInst *SI = Builder.CreateSwitch(SC, BB[FallBack]);
884 for (
auto S : Scopes) {
887 SI->addCase(Builder.getInt32(S), B);
889 Builder.SetInsertPoint(B);
891 FailureOrder, Size, Order,
895 Builder.CreateBr(ContBB);
898 Builder.SetInsertPoint(ContBB);
907 MemTy = AT->getValueType();
908 llvm::Value *IsWeak =
nullptr, *OrderFail =
nullptr;
915 if (E->
getOp() == AtomicExpr::AO__c11_atomic_init ||
916 E->
getOp() == AtomicExpr::AO__opencl_atomic_init) {
922 auto TInfo =
getContext().getTypeInfoInChars(AtomicTy);
923 uint64_t Size = TInfo.Width.getQuantity();
924 unsigned MaxInlineWidthInBits =
getTarget().getMaxAtomicInlineWidth();
927 getContext().toCharUnitsFromBits(MaxInlineWidthInBits);
930 bool Oversized =
getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
933 << (int)TInfo.Width.getQuantity()
938 << (int)TInfo.Width.getQuantity() << (int)MaxInlineWidth.
getQuantity();
944 bool ShouldCastToIntPtrTy =
true;
946 switch (E->
getOp()) {
947 case AtomicExpr::AO__c11_atomic_init:
948 case AtomicExpr::AO__opencl_atomic_init:
949 llvm_unreachable(
"Already handled above with EmitAtomicInit!");
951 case AtomicExpr::AO__atomic_load_n:
952 case AtomicExpr::AO__scoped_atomic_load_n:
953 case AtomicExpr::AO__c11_atomic_load:
954 case AtomicExpr::AO__opencl_atomic_load:
955 case AtomicExpr::AO__hip_atomic_load:
956 case AtomicExpr::AO__atomic_test_and_set:
957 case AtomicExpr::AO__atomic_clear:
960 case AtomicExpr::AO__atomic_load:
961 case AtomicExpr::AO__scoped_atomic_load:
965 case AtomicExpr::AO__atomic_store:
966 case AtomicExpr::AO__scoped_atomic_store:
970 case AtomicExpr::AO__atomic_exchange:
971 case AtomicExpr::AO__scoped_atomic_exchange:
976 case AtomicExpr::AO__atomic_compare_exchange:
977 case AtomicExpr::AO__atomic_compare_exchange_n:
978 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
979 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
980 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
981 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
982 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
983 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
984 case AtomicExpr::AO__scoped_atomic_compare_exchange:
985 case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
987 if (E->
getOp() == AtomicExpr::AO__atomic_compare_exchange ||
988 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange)
993 if (E->
getOp() == AtomicExpr::AO__atomic_compare_exchange_n ||
994 E->
getOp() == AtomicExpr::AO__atomic_compare_exchange ||
995 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange_n ||
996 E->
getOp() == AtomicExpr::AO__scoped_atomic_compare_exchange)
1000 case AtomicExpr::AO__c11_atomic_fetch_add:
1001 case AtomicExpr::AO__c11_atomic_fetch_sub:
1002 case AtomicExpr::AO__hip_atomic_fetch_add:
1003 case AtomicExpr::AO__hip_atomic_fetch_sub:
1004 case AtomicExpr::AO__opencl_atomic_fetch_add:
1005 case AtomicExpr::AO__opencl_atomic_fetch_sub:
1015 Val1Scalar =
Builder.CreateMul(Val1Scalar,
CGM.getSize(PointeeIncAmt));
1022 case AtomicExpr::AO__atomic_fetch_add:
1023 case AtomicExpr::AO__atomic_fetch_max:
1024 case AtomicExpr::AO__atomic_fetch_min:
1025 case AtomicExpr::AO__atomic_fetch_sub:
1026 case AtomicExpr::AO__atomic_add_fetch:
1027 case AtomicExpr::AO__atomic_max_fetch:
1028 case AtomicExpr::AO__atomic_min_fetch:
1029 case AtomicExpr::AO__atomic_sub_fetch:
1030 case AtomicExpr::AO__c11_atomic_fetch_max:
1031 case AtomicExpr::AO__c11_atomic_fetch_min:
1032 case AtomicExpr::AO__opencl_atomic_fetch_max:
1033 case AtomicExpr::AO__opencl_atomic_fetch_min:
1034 case AtomicExpr::AO__hip_atomic_fetch_max:
1035 case AtomicExpr::AO__hip_atomic_fetch_min:
1036 case AtomicExpr::AO__scoped_atomic_fetch_add:
1037 case AtomicExpr::AO__scoped_atomic_fetch_max:
1038 case AtomicExpr::AO__scoped_atomic_fetch_min:
1039 case AtomicExpr::AO__scoped_atomic_fetch_sub:
1040 case AtomicExpr::AO__scoped_atomic_add_fetch:
1041 case AtomicExpr::AO__scoped_atomic_max_fetch:
1042 case AtomicExpr::AO__scoped_atomic_min_fetch:
1043 case AtomicExpr::AO__scoped_atomic_sub_fetch:
1047 case AtomicExpr::AO__atomic_fetch_and:
1048 case AtomicExpr::AO__atomic_fetch_nand:
1049 case AtomicExpr::AO__atomic_fetch_or:
1050 case AtomicExpr::AO__atomic_fetch_xor:
1051 case AtomicExpr::AO__atomic_fetch_uinc:
1052 case AtomicExpr::AO__atomic_fetch_udec:
1053 case AtomicExpr::AO__atomic_and_fetch:
1054 case AtomicExpr::AO__atomic_nand_fetch:
1055 case AtomicExpr::AO__atomic_or_fetch:
1056 case AtomicExpr::AO__atomic_xor_fetch:
1057 case AtomicExpr::AO__atomic_store_n:
1058 case AtomicExpr::AO__atomic_exchange_n:
1059 case AtomicExpr::AO__c11_atomic_fetch_and:
1060 case AtomicExpr::AO__c11_atomic_fetch_nand:
1061 case AtomicExpr::AO__c11_atomic_fetch_or:
1062 case AtomicExpr::AO__c11_atomic_fetch_xor:
1063 case AtomicExpr::AO__c11_atomic_store:
1064 case AtomicExpr::AO__c11_atomic_exchange:
1065 case AtomicExpr::AO__hip_atomic_fetch_and:
1066 case AtomicExpr::AO__hip_atomic_fetch_or:
1067 case AtomicExpr::AO__hip_atomic_fetch_xor:
1068 case AtomicExpr::AO__hip_atomic_store:
1069 case AtomicExpr::AO__hip_atomic_exchange:
1070 case AtomicExpr::AO__opencl_atomic_fetch_and:
1071 case AtomicExpr::AO__opencl_atomic_fetch_or:
1072 case AtomicExpr::AO__opencl_atomic_fetch_xor:
1073 case AtomicExpr::AO__opencl_atomic_store:
1074 case AtomicExpr::AO__opencl_atomic_exchange:
1075 case AtomicExpr::AO__scoped_atomic_fetch_and:
1076 case AtomicExpr::AO__scoped_atomic_fetch_nand:
1077 case AtomicExpr::AO__scoped_atomic_fetch_or:
1078 case AtomicExpr::AO__scoped_atomic_fetch_xor:
1079 case AtomicExpr::AO__scoped_atomic_and_fetch:
1080 case AtomicExpr::AO__scoped_atomic_nand_fetch:
1081 case AtomicExpr::AO__scoped_atomic_or_fetch:
1082 case AtomicExpr::AO__scoped_atomic_xor_fetch:
1083 case AtomicExpr::AO__scoped_atomic_store_n:
1084 case AtomicExpr::AO__scoped_atomic_exchange_n:
1085 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
1086 case AtomicExpr::AO__scoped_atomic_fetch_udec:
1097 AtomicInfo Atomics(*
this, AtomicVal);
1100 if (ShouldCastToIntPtrTy) {
1101 Ptr = Atomics.castToAtomicIntPointer(Ptr);
1103 Val1 = Atomics.convertToAtomicIntPointer(Val1);
1105 Val2 = Atomics.convertToAtomicIntPointer(Val2);
1108 if (ShouldCastToIntPtrTy)
1109 Dest = Atomics.castToAtomicIntPointer(Dest);
1113 Dest = Atomics.CreateTempAlloca();
1114 if (ShouldCastToIntPtrTy)
1115 Dest = Atomics.castToAtomicIntPointer(Dest);
1118 bool PowerOf2Size = (Size & (Size - 1)) == 0;
1119 bool UseLibcall = !PowerOf2Size || (Size > 16);
1139 auto CastToGenericAddrSpace = [&](llvm::Value *
V,
QualType PT) {
1146 auto *DestType = llvm::PointerType::get(
getLLVMContext(), DestAS);
1157 std::string LibCallName;
1159 bool HaveRetTy =
false;
1160 switch (E->
getOp()) {
1161 case AtomicExpr::AO__c11_atomic_init:
1162 case AtomicExpr::AO__opencl_atomic_init:
1163 llvm_unreachable(
"Already handled!");
1170 case AtomicExpr::AO__atomic_compare_exchange:
1171 case AtomicExpr::AO__atomic_compare_exchange_n:
1172 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
1173 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
1174 case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
1175 case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
1176 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
1177 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
1178 case AtomicExpr::AO__scoped_atomic_compare_exchange:
1179 case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
1180 LibCallName =
"__atomic_compare_exchange";
1194 case AtomicExpr::AO__atomic_exchange:
1195 case AtomicExpr::AO__atomic_exchange_n:
1196 case AtomicExpr::AO__c11_atomic_exchange:
1197 case AtomicExpr::AO__hip_atomic_exchange:
1198 case AtomicExpr::AO__opencl_atomic_exchange:
1199 case AtomicExpr::AO__scoped_atomic_exchange:
1200 case AtomicExpr::AO__scoped_atomic_exchange_n:
1201 LibCallName =
"__atomic_exchange";
1207 case AtomicExpr::AO__atomic_store:
1208 case AtomicExpr::AO__atomic_store_n:
1209 case AtomicExpr::AO__c11_atomic_store:
1210 case AtomicExpr::AO__hip_atomic_store:
1211 case AtomicExpr::AO__opencl_atomic_store:
1212 case AtomicExpr::AO__scoped_atomic_store:
1213 case AtomicExpr::AO__scoped_atomic_store_n:
1214 LibCallName =
"__atomic_store";
1222 case AtomicExpr::AO__atomic_load:
1223 case AtomicExpr::AO__atomic_load_n:
1224 case AtomicExpr::AO__c11_atomic_load:
1225 case AtomicExpr::AO__hip_atomic_load:
1226 case AtomicExpr::AO__opencl_atomic_load:
1227 case AtomicExpr::AO__scoped_atomic_load:
1228 case AtomicExpr::AO__scoped_atomic_load_n:
1229 LibCallName =
"__atomic_load";
1231 case AtomicExpr::AO__atomic_add_fetch:
1232 case AtomicExpr::AO__scoped_atomic_add_fetch:
1233 case AtomicExpr::AO__atomic_fetch_add:
1234 case AtomicExpr::AO__c11_atomic_fetch_add:
1235 case AtomicExpr::AO__hip_atomic_fetch_add:
1236 case AtomicExpr::AO__opencl_atomic_fetch_add:
1237 case AtomicExpr::AO__scoped_atomic_fetch_add:
1238 case AtomicExpr::AO__atomic_and_fetch:
1239 case AtomicExpr::AO__scoped_atomic_and_fetch:
1240 case AtomicExpr::AO__atomic_fetch_and:
1241 case AtomicExpr::AO__c11_atomic_fetch_and:
1242 case AtomicExpr::AO__hip_atomic_fetch_and:
1243 case AtomicExpr::AO__opencl_atomic_fetch_and:
1244 case AtomicExpr::AO__scoped_atomic_fetch_and:
1245 case AtomicExpr::AO__atomic_or_fetch:
1246 case AtomicExpr::AO__scoped_atomic_or_fetch:
1247 case AtomicExpr::AO__atomic_fetch_or:
1248 case AtomicExpr::AO__c11_atomic_fetch_or:
1249 case AtomicExpr::AO__hip_atomic_fetch_or:
1250 case AtomicExpr::AO__opencl_atomic_fetch_or:
1251 case AtomicExpr::AO__scoped_atomic_fetch_or:
1252 case AtomicExpr::AO__atomic_sub_fetch:
1253 case AtomicExpr::AO__scoped_atomic_sub_fetch:
1254 case AtomicExpr::AO__atomic_fetch_sub:
1255 case AtomicExpr::AO__c11_atomic_fetch_sub:
1256 case AtomicExpr::AO__hip_atomic_fetch_sub:
1257 case AtomicExpr::AO__opencl_atomic_fetch_sub:
1258 case AtomicExpr::AO__scoped_atomic_fetch_sub:
1259 case AtomicExpr::AO__atomic_xor_fetch:
1260 case AtomicExpr::AO__scoped_atomic_xor_fetch:
1261 case AtomicExpr::AO__atomic_fetch_xor:
1262 case AtomicExpr::AO__c11_atomic_fetch_xor:
1263 case AtomicExpr::AO__hip_atomic_fetch_xor:
1264 case AtomicExpr::AO__opencl_atomic_fetch_xor:
1265 case AtomicExpr::AO__scoped_atomic_fetch_xor:
1266 case AtomicExpr::AO__atomic_nand_fetch:
1267 case AtomicExpr::AO__atomic_fetch_nand:
1268 case AtomicExpr::AO__c11_atomic_fetch_nand:
1269 case AtomicExpr::AO__scoped_atomic_fetch_nand:
1270 case AtomicExpr::AO__scoped_atomic_nand_fetch:
1271 case AtomicExpr::AO__atomic_min_fetch:
1272 case AtomicExpr::AO__atomic_fetch_min:
1273 case AtomicExpr::AO__c11_atomic_fetch_min:
1274 case AtomicExpr::AO__hip_atomic_fetch_min:
1275 case AtomicExpr::AO__opencl_atomic_fetch_min:
1276 case AtomicExpr::AO__scoped_atomic_fetch_min:
1277 case AtomicExpr::AO__scoped_atomic_min_fetch:
1278 case AtomicExpr::AO__atomic_max_fetch:
1279 case AtomicExpr::AO__atomic_fetch_max:
1280 case AtomicExpr::AO__c11_atomic_fetch_max:
1281 case AtomicExpr::AO__hip_atomic_fetch_max:
1282 case AtomicExpr::AO__opencl_atomic_fetch_max:
1283 case AtomicExpr::AO__scoped_atomic_fetch_max:
1284 case AtomicExpr::AO__scoped_atomic_max_fetch:
1285 case AtomicExpr::AO__scoped_atomic_fetch_uinc:
1286 case AtomicExpr::AO__scoped_atomic_fetch_udec:
1287 case AtomicExpr::AO__atomic_test_and_set:
1288 case AtomicExpr::AO__atomic_clear:
1289 case AtomicExpr::AO__atomic_fetch_uinc:
1290 case AtomicExpr::AO__atomic_fetch_udec:
1291 llvm_unreachable(
"Integral atomic operations always become atomicrmw!");
1296 std::string(
"__opencl") + StringRef(LibCallName).drop_front(1).str();
1324 bool IsStore = E->
getOp() == AtomicExpr::AO__c11_atomic_store ||
1325 E->
getOp() == AtomicExpr::AO__opencl_atomic_store ||
1326 E->
getOp() == AtomicExpr::AO__hip_atomic_store ||
1327 E->
getOp() == AtomicExpr::AO__atomic_store ||
1328 E->
getOp() == AtomicExpr::AO__atomic_store_n ||
1329 E->
getOp() == AtomicExpr::AO__scoped_atomic_store ||
1330 E->
getOp() == AtomicExpr::AO__scoped_atomic_store_n ||
1331 E->
getOp() == AtomicExpr::AO__atomic_clear;
1332 bool IsLoad = E->
getOp() == AtomicExpr::AO__c11_atomic_load ||
1333 E->
getOp() == AtomicExpr::AO__opencl_atomic_load ||
1334 E->
getOp() == AtomicExpr::AO__hip_atomic_load ||
1335 E->
getOp() == AtomicExpr::AO__atomic_load ||
1336 E->
getOp() == AtomicExpr::AO__atomic_load_n ||
1337 E->
getOp() == AtomicExpr::AO__scoped_atomic_load ||
1338 E->
getOp() == AtomicExpr::AO__scoped_atomic_load_n;
1344 if (llvm::isValidAtomicOrderingCABI(ord))
1345 switch ((llvm::AtomicOrderingCABI)ord) {
1346 case llvm::AtomicOrderingCABI::relaxed:
1347 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1348 OrderFail, Size, llvm::AtomicOrdering::Monotonic,
Scope);
1350 case llvm::AtomicOrderingCABI::consume:
1351 case llvm::AtomicOrderingCABI::acquire:
1354 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1355 OrderFail, Size, llvm::AtomicOrdering::Acquire,
Scope);
1357 case llvm::AtomicOrderingCABI::release:
1360 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1361 OrderFail, Size, llvm::AtomicOrdering::Release,
Scope);
1363 case llvm::AtomicOrderingCABI::acq_rel:
1364 if (IsLoad || IsStore)
1366 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1367 OrderFail, Size, llvm::AtomicOrdering::AcquireRelease,
1370 case llvm::AtomicOrderingCABI::seq_cst:
1371 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1373 llvm::AtomicOrdering::SequentiallyConsistent,
Scope);
1386 llvm::BasicBlock *MonotonicBB =
nullptr, *AcquireBB =
nullptr,
1387 *ReleaseBB =
nullptr, *AcqRelBB =
nullptr,
1388 *SeqCstBB =
nullptr;
1394 if (!IsLoad && !IsStore)
1403 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
1404 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, MonotonicBB);
1407 Builder.SetInsertPoint(MonotonicBB);
1408 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak, OrderFail,
1409 Size, llvm::AtomicOrdering::Monotonic,
Scope);
1412 Builder.SetInsertPoint(AcquireBB);
1413 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1414 OrderFail, Size, llvm::AtomicOrdering::Acquire,
Scope);
1416 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::consume),
1418 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acquire),
1422 Builder.SetInsertPoint(ReleaseBB);
1423 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1424 OrderFail, Size, llvm::AtomicOrdering::Release,
Scope);
1426 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::release),
1429 if (!IsLoad && !IsStore) {
1430 Builder.SetInsertPoint(AcqRelBB);
1431 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak,
1432 OrderFail, Size, llvm::AtomicOrdering::AcquireRelease,
Scope);
1434 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::acq_rel),
1437 Builder.SetInsertPoint(SeqCstBB);
1438 EmitAtomicOp(*
this, E, Dest, Ptr, Val1, Val2, OriginalVal1, IsWeak, OrderFail,
1439 Size, llvm::AtomicOrdering::SequentiallyConsistent,
Scope);
1441 SI->addCase(
Builder.getInt32((
int)llvm::AtomicOrderingCABI::seq_cst),
1445 Builder.SetInsertPoint(ContBB);
1449 assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
1455 llvm::IntegerType *ty =
1461 llvm::Type *Ty =
Addr.getElementType();
1463 if (SourceSizeInBits != AtomicSizeInBits) {
1464 Address Tmp = CreateTempAlloca();
1471 std::min(AtomicSizeInBits, SourceSizeInBits) / 8);
1475 return castToAtomicIntPointer(
Addr);
1478RValue AtomicInfo::convertAtomicTempToRValue(Address addr,
1479 AggValueSlot resultSlot,
1481 bool asValue)
const {
1482 if (LVal.isSimple()) {
1497 if (LVal.isBitField())
1499 LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(),
1500 LVal.getBaseInfo(), TBAAAccessInfo()), loc);
1501 if (LVal.isVectorElt())
1503 LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(),
1504 LVal.getBaseInfo(), TBAAAccessInfo()), loc);
1505 assert(LVal.isExtVectorElt());
1507 addr, LVal.getExtVectorElts(), LVal.getType(),
1508 LVal.getBaseInfo(), TBAAAccessInfo()));
1517 if (ValTy->isFloatingPointTy())
1518 return ValTy->isX86_FP80Ty() || CmpXchg;
1519 return !ValTy->isIntegerTy() && !ValTy->isPointerTy();
1522RValue AtomicInfo::ConvertToValueOrAtomic(llvm::Value *Val,
1523 AggValueSlot ResultSlot,
1524 SourceLocation Loc,
bool AsValue,
1525 bool CmpXchg)
const {
1527 assert((Val->getType()->isIntegerTy() || Val->getType()->isPointerTy() ||
1528 Val->getType()->isIEEELikeFPTy()) &&
1529 "Expected integer, pointer or floating point value when converting "
1532 (((!LVal.isBitField() ||
1533 LVal.getBitFieldInfo().Size == ValueSizeInBits) &&
1536 auto *ValTy = AsValue
1538 : getAtomicAddress().getElementType();
1540 assert((!ValTy->isIntegerTy() || Val->getType() == ValTy) &&
1541 "Different integer types.");
1544 if (llvm::CastInst::isBitCastable(Val->getType(), ValTy))
1551 bool TempIsVolatile =
false;
1557 Temp = CreateTempAlloca();
1561 Address CastTemp = castToAtomicIntPointer(Temp);
1564 return convertAtomicTempToRValue(Temp, ResultSlot, Loc, AsValue);
1567void AtomicInfo::EmitAtomicLoadLibcall(llvm::Value *AddForLoaded,
1568 llvm::AtomicOrdering AO,
bool) {
1580llvm::Value *AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO,
1581 bool IsVolatile,
bool CmpXchg) {
1583 Address
Addr = getAtomicAddress();
1585 Addr = castToAtomicIntPointer(
Addr);
1587 Load->setAtomic(AO);
1591 Load->setVolatile(
true);
1600 if (!
CGM.getLangOpts().MSVolatile)
return false;
1601 AtomicInfo AI(*
this, LV);
1604 bool AtomicIsInline = !AI.shouldUseLibcall();
1609 return IsVolatile && AtomicIsInline;
1614 llvm::AtomicOrdering AO;
1617 AO = llvm::AtomicOrdering::SequentiallyConsistent;
1619 AO = llvm::AtomicOrdering::Acquire;
1626 bool AsValue, llvm::AtomicOrdering AO,
1629 if (shouldUseLibcall()) {
1631 if (LVal.isSimple() && !ResultSlot.
isIgnored()) {
1635 TempAddr = CreateTempAlloca();
1637 EmitAtomicLoadLibcall(TempAddr.
emitRawPointer(CGF), AO, IsVolatile);
1641 return convertAtomicTempToRValue(TempAddr, ResultSlot, Loc, AsValue);
1645 auto *Load = EmitAtomicLoadOp(AO, IsVolatile);
1653 return ConvertToValueOrAtomic(Load, ResultSlot, Loc, AsValue);
1659 llvm::AtomicOrdering AO,
bool IsVolatile,
1661 AtomicInfo Atomics(*
this, src);
1662 return Atomics.EmitAtomicLoad(resultSlot, loc,
true, AO,
1668void AtomicInfo::emitCopyIntoMemory(
RValue rvalue)
const {
1669 assert(LVal.isSimple());
1678 LVal.isVolatileQualified();
1687 emitMemSetZeroIfNecessary();
1690 LValue TempLVal = projectValue();
1703Address AtomicInfo::materializeRValue(RValue rvalue)
const {
1710 LValue TempLV = CGF.
MakeAddrLValue(CreateTempAlloca(), getAtomicType());
1711 AtomicInfo Atomics(CGF, TempLV);
1712 Atomics.emitCopyIntoMemory(rvalue);
1713 return TempLV.getAddress();
1716llvm::Value *AtomicInfo::getScalarRValValueOrNull(RValue RVal)
const {
1717 if (RVal.
isScalar() && (!hasPadding() || !LVal.isSimple()))
1722llvm::Value *AtomicInfo::convertRValueToInt(RValue RVal,
bool CmpXchg)
const {
1725 if (llvm::Value *
Value = getScalarRValValueOrNull(RVal)) {
1729 llvm::IntegerType *InputIntTy = llvm::IntegerType::get(
1731 LVal.isSimple() ? getValueSizeInBits() : getAtomicSizeInBits());
1732 if (llvm::BitCastInst::isBitCastable(
Value->getType(), InputIntTy))
1738 Address
Addr = materializeRValue(RVal);
1741 Addr = castToAtomicIntPointer(
Addr);
1745std::pair<llvm::Value *, llvm::Value *> AtomicInfo::EmitAtomicCompareExchangeOp(
1746 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
1747 llvm::AtomicOrdering
Success, llvm::AtomicOrdering Failure,
bool IsWeak) {
1749 Address
Addr = getAtomicAddressAsAtomicIntPointer();
1753 Inst->setVolatile(LVal.isVolatileQualified());
1754 Inst->setWeak(IsWeak);
1757 auto *PreviousVal = CGF.
Builder.CreateExtractValue(Inst, 0);
1758 auto *SuccessFailureVal = CGF.
Builder.CreateExtractValue(Inst, 1);
1759 return std::make_pair(PreviousVal, SuccessFailureVal);
1763AtomicInfo::EmitAtomicCompareExchangeLibcall(llvm::Value *ExpectedAddr,
1764 llvm::Value *DesiredAddr,
1766 llvm::AtomicOrdering Failure) {
1775 llvm::ConstantInt::get(CGF.
IntTy, (
int)llvm::toCABI(
Success))),
1778 llvm::ConstantInt::get(CGF.
IntTy, (
int)llvm::toCABI(Failure))),
1783 return SuccessFailureRVal.getScalarVal();
1786std::pair<RValue, llvm::Value *> AtomicInfo::EmitAtomicCompareExchange(
1787 RValue Expected, RValue Desired, llvm::AtomicOrdering
Success,
1788 llvm::AtomicOrdering Failure,
bool IsWeak) {
1790 if (shouldUseLibcall()) {
1792 Address ExpectedAddr = materializeRValue(Expected);
1794 llvm::Value *DesiredPtr = materializeRValue(Desired).emitRawPointer(CGF);
1795 auto *Res = EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr,
1797 return std::make_pair(
1799 SourceLocation(),
false),
1805 auto *ExpectedVal = convertRValueToInt(Expected,
true);
1806 auto *DesiredVal = convertRValueToInt(Desired,
true);
1807 auto Res = EmitAtomicCompareExchangeOp(ExpectedVal, DesiredVal,
Success,
1809 return std::make_pair(
1811 SourceLocation(),
false,
1821 LValue AtomicLVal = Atomics.getAtomicLValue();
1823 if (AtomicLVal.isSimple()) {
1825 DesiredLVal = CGF.
MakeAddrLValue(DesiredAddr, AtomicLVal.getType());
1828 Address Ptr = Atomics.materializeRValue(OldRVal);
1830 if (AtomicLVal.isBitField()) {
1832 LValue::MakeBitfield(Ptr, AtomicLVal.getBitFieldInfo(),
1833 AtomicLVal.getType(),
1834 AtomicLVal.getBaseInfo(),
1835 AtomicLVal.getTBAAInfo());
1837 LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
1838 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1839 AtomicLVal.getTBAAInfo());
1840 }
else if (AtomicLVal.isVectorElt()) {
1841 UpdateLVal = LValue::MakeVectorElt(Ptr, AtomicLVal.getVectorIdx(),
1842 AtomicLVal.getType(),
1843 AtomicLVal.getBaseInfo(),
1844 AtomicLVal.getTBAAInfo());
1845 DesiredLVal = LValue::MakeVectorElt(
1846 DesiredAddr, AtomicLVal.getVectorIdx(), AtomicLVal.getType(),
1847 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
1849 assert(AtomicLVal.isExtVectorElt());
1850 UpdateLVal = LValue::MakeExtVectorElt(Ptr, AtomicLVal.getExtVectorElts(),
1851 AtomicLVal.getType(),
1852 AtomicLVal.getBaseInfo(),
1853 AtomicLVal.getTBAAInfo());
1854 DesiredLVal = LValue::MakeExtVectorElt(
1855 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
1856 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
1861 RValue NewRVal = UpdateOp(UpRVal);
1871void AtomicInfo::EmitAtomicUpdateLibcall(
1872 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
1874 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1876 Address ExpectedAddr = CreateTempAlloca();
1878 EmitAtomicLoadLibcall(ExpectedAddr.
emitRawPointer(CGF), AO, IsVolatile);
1882 Address DesiredAddr = CreateTempAlloca();
1883 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
1884 requiresMemSetZero(getAtomicAddress().getElementType())) {
1888 auto OldRVal = convertAtomicTempToRValue(ExpectedAddr,
1890 SourceLocation(),
false);
1895 EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO, Failure);
1896 CGF.
Builder.CreateCondBr(Res, ExitBB, ContBB);
1900void AtomicInfo::EmitAtomicUpdateOp(
1901 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
1903 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1906 auto *OldVal = EmitAtomicLoadOp(Failure, IsVolatile,
true);
1910 auto *CurBB = CGF.
Builder.GetInsertBlock();
1912 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(OldVal->getType(),
1914 PHI->addIncoming(OldVal, CurBB);
1915 Address NewAtomicAddr = CreateTempAlloca();
1916 Address NewAtomicIntAddr =
1918 ? castToAtomicIntPointer(NewAtomicAddr)
1921 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
1922 requiresMemSetZero(getAtomicAddress().getElementType())) {
1926 SourceLocation(),
false,
1931 auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO, Failure);
1932 PHI->addIncoming(Res.first, CGF.
Builder.GetInsertBlock());
1933 CGF.
Builder.CreateCondBr(Res.second, ExitBB, ContBB);
1939 LValue AtomicLVal = Atomics.getAtomicLValue();
1942 if (AtomicLVal.isBitField()) {
1944 LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
1945 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1946 AtomicLVal.getTBAAInfo());
1947 }
else if (AtomicLVal.isVectorElt()) {
1949 LValue::MakeVectorElt(DesiredAddr, AtomicLVal.getVectorIdx(),
1950 AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
1951 AtomicLVal.getTBAAInfo());
1953 assert(AtomicLVal.isExtVectorElt());
1954 DesiredLVal = LValue::MakeExtVectorElt(
1955 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
1956 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
1963void AtomicInfo::EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO,
1964 RValue UpdateRVal,
bool IsVolatile) {
1965 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1967 Address ExpectedAddr = CreateTempAlloca();
1969 EmitAtomicLoadLibcall(ExpectedAddr.
emitRawPointer(CGF), AO, IsVolatile);
1973 Address DesiredAddr = CreateTempAlloca();
1974 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
1975 requiresMemSetZero(getAtomicAddress().getElementType())) {
1983 EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO, Failure);
1984 CGF.
Builder.CreateCondBr(Res, ExitBB, ContBB);
1988void AtomicInfo::EmitAtomicUpdateOp(llvm::AtomicOrdering AO, RValue UpdateRVal,
1990 auto Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
1993 auto *OldVal = EmitAtomicLoadOp(Failure, IsVolatile,
true);
1997 auto *CurBB = CGF.
Builder.GetInsertBlock();
1999 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(OldVal->getType(),
2001 PHI->addIncoming(OldVal, CurBB);
2002 Address NewAtomicAddr = CreateTempAlloca();
2003 Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
2004 if ((LVal.isBitField() && BFI.
Size != ValueSizeInBits) ||
2005 requiresMemSetZero(getAtomicAddress().getElementType())) {
2011 auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO, Failure);
2012 PHI->addIncoming(Res.first, CGF.
Builder.GetInsertBlock());
2013 CGF.
Builder.CreateCondBr(Res.second, ExitBB, ContBB);
2017void AtomicInfo::EmitAtomicUpdate(
2018 llvm::AtomicOrdering AO,
const llvm::function_ref<RValue(RValue)> &UpdateOp,
2020 if (shouldUseLibcall()) {
2021 EmitAtomicUpdateLibcall(AO, UpdateOp, IsVolatile);
2023 EmitAtomicUpdateOp(AO, UpdateOp, IsVolatile);
2027void AtomicInfo::EmitAtomicUpdate(llvm::AtomicOrdering AO, RValue UpdateRVal,
2029 if (shouldUseLibcall()) {
2030 EmitAtomicUpdateLibcall(AO, UpdateRVal, IsVolatile);
2032 EmitAtomicUpdateOp(AO, UpdateRVal, IsVolatile);
2039 llvm::AtomicOrdering AO;
2041 AO = llvm::AtomicOrdering::SequentiallyConsistent;
2043 AO = llvm::AtomicOrdering::Release;
2055 llvm::AtomicOrdering AO,
bool IsVolatile,
2063 AtomicInfo atomics(*
this, dest);
2064 LValue LVal = atomics.getAtomicLValue();
2069 atomics.emitCopyIntoMemory(rvalue);
2074 if (atomics.shouldUseLibcall()) {
2076 Address srcAddr = atomics.materializeRValue(rvalue);
2093 llvm::Value *ValToStore = atomics.convertRValueToInt(rvalue);
2097 if (llvm::Value *
Value = atomics.getScalarRValValueOrNull(rvalue))
2099 Addr = atomics.castToAtomicIntPointer(
Addr);
2100 ValToStore =
Builder.CreateIntCast(ValToStore,
Addr.getElementType(),
2103 llvm::StoreInst *store =
Builder.CreateStore(ValToStore,
Addr);
2105 if (AO == llvm::AtomicOrdering::Acquire)
2106 AO = llvm::AtomicOrdering::Monotonic;
2107 else if (AO == llvm::AtomicOrdering::AcquireRelease)
2108 AO = llvm::AtomicOrdering::Release;
2111 store->setAtomic(AO);
2115 store->setVolatile(
true);
2121 atomics.EmitAtomicUpdate(AO, rvalue, IsVolatile);
2128 llvm::AtomicOrdering
Success, llvm::AtomicOrdering Failure,
bool IsWeak,
2133 Expected.getAggregateAddress().getElementType() ==
2138 AtomicInfo Atomics(*
this, Obj);
2140 return Atomics.EmitAtomicCompareExchange(
Expected, Desired,
Success, Failure,
2144llvm::AtomicRMWInst *
2146 llvm::Value *Val, llvm::AtomicOrdering Order,
2147 llvm::SyncScope::ID SSID,
2149 llvm::AtomicRMWInst *RMW =
2150 Builder.CreateAtomicRMW(Op,
Addr, Val, Order, SSID);
2156 LValue LVal, llvm::AtomicOrdering AO,
2157 const llvm::function_ref<
RValue(
RValue)> &UpdateOp,
bool IsVolatile) {
2158 AtomicInfo Atomics(*
this, LVal);
2159 Atomics.EmitAtomicUpdate(AO, UpdateOp, IsVolatile);
2163 AtomicInfo atomics(*
this, dest);
2165 switch (atomics.getEvaluationKind()) {
2181 bool Zeroed =
false;
2183 Zeroed = atomics.emitMemSetZeroIfNecessary();
2184 dest = atomics.projectValue();
2198 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)
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)
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 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...
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
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...
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 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,...
virtual llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, SyncScope Scope, llvm::AtomicOrdering Ordering, llvm::LLVMContext &Ctx) const
Get the syncscope used in LLVM IR.
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.
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