55 #define DEBUG_TYPE "atomic-expand" 75 bool tryExpandAtomicLoad(
LoadInst *LI);
76 bool expandAtomicLoadToLL(
LoadInst *LI);
77 bool expandAtomicLoadToCmpXchg(
LoadInst *LI);
85 void expandAtomicOpToLLSC(
88 void expandPartwordAtomicRMW(
94 static Value *insertRMWCmpXchgLoop(
109 void expandAtomicLoadToLibcall(
LoadInst *LI);
110 void expandAtomicStoreToLibcall(
StoreInst *LI);
157 assert(Align != 0 &&
"An atomic LoadInst always has an explicit alignment");
166 assert(Align != 0 &&
"An atomic StoreInst always has an explicit alignment");
187 template <
typename Inst>
195 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
200 if (!
TM.getSubtargetImpl(F)->enableAtomicExpand())
202 TLI =
TM.getSubtargetImpl(F)->getTargetLowering();
214 bool MadeChange =
false;
215 for (
auto I : AtomicInsts) {
220 assert((LI || SI || RMWI || CASI) &&
"Unknown atomic instruction");
225 expandAtomicLoadToLibcall(LI);
231 expandAtomicStoreToLibcall(SI);
237 expandAtomicRMWToLibcall(RMWI);
243 expandAtomicCASToLibcall(CASI);
249 if (TLI->shouldInsertFencesForAtomic(
I)) {
252 FenceOrdering = LI->getOrdering();
255 FenceOrdering = SI->getOrdering();
259 FenceOrdering = RMWI->getOrdering();
261 }
else if (CASI && !TLI->shouldExpandAtomicCmpXchgInIR(CASI) &&
268 FenceOrdering = CASI->getSuccessOrdering();
274 MadeChange |= bracketInstWithFences(
I, FenceOrdering);
279 if (LI->getType()->isFloatingPointTy()) {
282 LI = convertAtomicLoadToIntegerType(LI);
283 assert(LI->getType()->isIntegerTy() &&
"invariant broken");
287 MadeChange |= tryExpandAtomicLoad(LI);
289 if (SI->getValueOperand()->getType()->isFloatingPointTy()) {
292 SI = convertAtomicStoreToIntegerType(SI);
293 assert(SI->getValueOperand()->getType()->isIntegerTy() &&
298 if (TLI->shouldExpandAtomicStoreInIR(SI))
299 MadeChange |= expandAtomicStore(SI);
306 if (isIdempotentRMW(RMWI) && simplifyIdempotentRMW(RMWI)) {
309 MadeChange |= tryExpandAtomicRMW(RMWI);
314 assert(!CASI->getCompareOperand()->getType()->isFloatingPointTy() &&
315 "unimplemented - floating point not legal at IR level");
316 if (CASI->getCompareOperand()->getType()->isPointerTy() ) {
319 CASI = convertCmpXchgToIntegerType(CASI);
320 assert(CASI->getCompareOperand()->getType()->isIntegerTy() &&
325 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
327 if (ValueSize < MinCASSize) {
328 assert(!TLI->shouldExpandAtomicCmpXchgInIR(CASI) &&
329 "MinCmpXchgSizeInBits not yet supported for LL/SC expansions.");
330 expandPartwordCmpXchg(CASI);
332 if (TLI->shouldExpandAtomicCmpXchgInIR(CASI))
333 MadeChange |= expandAtomicCmpXchg(CASI);
343 auto LeadingFence = TLI->emitLeadingFence(Builder, I, Order);
345 auto TrailingFence = TLI->emitTrailingFence(Builder, I, Order);
349 TrailingFence->moveAfter(I);
351 return (LeadingFence || TrailingFence);
357 EVT VT = TLI->getValueType(DL, T);
368 Type *NewTy = getCorrespondingIntegerType(LI->
getType(),
376 Value *NewAddr = Builder.CreateBitCast(Addr, PT);
378 auto *NewLI = Builder.CreateLoad(NewAddr);
382 LLVM_DEBUG(
dbgs() <<
"Replaced " << *LI <<
" with " << *NewLI <<
"\n");
384 Value *NewVal = Builder.CreateBitCast(NewLI, LI->
getType());
390 bool AtomicExpand::tryExpandAtomicLoad(
LoadInst *LI) {
391 switch (TLI->shouldExpandAtomicLoadInIR(LI)) {
395 expandAtomicOpToLLSC(
400 return expandAtomicLoadToLL(LI);
402 return expandAtomicLoadToCmpXchg(LI);
407 bool AtomicExpand::expandAtomicLoadToLL(
LoadInst *LI) {
415 TLI->emitAtomicCmpXchgNoStoreLLBalance(Builder);
423 bool AtomicExpand::expandAtomicLoadToCmpXchg(
LoadInst *LI) {
427 Type *Ty = cast<PointerType>(Addr->
getType())->getElementType();
431 Addr, DummyVal, DummyVal, Order,
465 LLVM_DEBUG(
dbgs() <<
"Replaced " << *SI <<
" with " << *NewSI <<
"\n");
470 bool AtomicExpand::expandAtomicStore(
StoreInst *SI) {
484 return tryExpandAtomicRMW(AI);
492 Addr, Loaded, NewVal, MemOpOrder,
507 return Builder.
CreateAdd(Loaded, Inc,
"new");
509 return Builder.
CreateSub(Loaded, Inc,
"new");
511 return Builder.
CreateAnd(Loaded, Inc,
"new");
515 return Builder.
CreateOr(Loaded, Inc,
"new");
517 return Builder.
CreateXor(Loaded, Inc,
"new");
520 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
523 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
526 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
529 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
536 switch (TLI->shouldExpandAtomicRMWInIR(AI)) {
540 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
542 if (ValueSize < MinCASSize) {
544 "MinCmpXchgSizeInBits not yet supported for LL/SC architectures.");
556 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
558 if (ValueSize < MinCASSize) {
559 expandPartwordAtomicRMW(AI,
574 struct PartwordMaskValues {
604 PartwordMaskValues
Ret;
615 assert(ValueSize < WordSize);
625 Builder.
CreateAnd(AddrInt, ~(uint64_t)(WordSize - 1)), WordPtrType,
628 Value *PtrLSB = Builder.
CreateAnd(AddrInt, WordSize - 1,
"PtrLSB");
631 Ret.ShiftAmt = Builder.
CreateShl(PtrLSB, 3);
638 Ret.ShiftAmt = Builder.
CreateTrunc(Ret.ShiftAmt, Ret.WordType,
"ShiftAmt");
642 Ret.Inv_Mask = Builder.
CreateNot(Ret.Mask,
"Inv_Mask");
653 const PartwordMaskValues &PMV) {
657 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, Shifted_Inc);
673 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Masked);
684 Builder.
CreateLShr(Loaded, PMV.ShiftAmt), PMV.ValueType);
687 Builder.
CreateZExt(NewVal, PMV.WordType), PMV.ShiftAmt);
689 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Shiftup);
704 void AtomicExpand::expandPartwordAtomicRMW(
712 PartwordMaskValues PMV =
714 TLI->getMinCmpXchgSizeInBits() / 8);
716 Value *ValOperand_Shifted =
718 PMV.ShiftAmt,
"ValOperand_Shifted");
728 insertRMWCmpXchgLoop(Builder, PMV.WordType, PMV.AlignedAddr, MemOpOrder,
731 Builder.
CreateLShr(OldResult, PMV.ShiftAmt), PMV.ValueType);
781 const int WordSize = TLI->getMinCmpXchgSizeInBits() / 8;
791 std::prev(BB->
end())->eraseFromParent();
798 Value *NewVal_Shifted =
807 Value *InitLoaded_MaskOut = Builder.
CreateAnd(InitLoaded, PMV.Inv_Mask);
813 Loaded_MaskOut->
addIncoming(InitLoaded_MaskOut, BB);
816 Value *FullWord_NewVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Shifted);
817 Value *FullWord_Cmp = Builder.
CreateOr(Loaded_MaskOut, Cmp_Shifted);
847 Loaded_MaskOut->
addIncoming(OldVal_MaskOut, FailureBB);
853 Builder.
CreateLShr(OldVal, PMV.ShiftAmt), PMV.ValueType);
862 void AtomicExpand::expandAtomicOpToLLSC(
867 insertRMWLLSCLoop(Builder, ResultType, Addr, MemOpOrder, PerformOp);
873 Value *AtomicExpand::insertRMWLLSCLoop(
899 std::prev(BB->
end())->eraseFromParent();
905 Value *Loaded = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
907 Value *NewVal = PerformOp(Builder, Loaded);
909 Value *StoreSuccess =
910 TLI->emitStoreConditional(Builder, NewVal, Addr, MemOpOrder);
934 Value *NewAddr = Builder.CreateBitCast(Addr, PT);
940 auto *NewCI = Builder.CreateAtomicCmpXchg(NewAddr, NewCmp, NewNewVal,
945 NewCI->setWeak(CI->
isWeak());
946 LLVM_DEBUG(
dbgs() <<
"Replaced " << *CI <<
" with " << *NewCI <<
"\n");
948 Value *OldVal = Builder.CreateExtractValue(NewCI, 0);
949 Value *Succ = Builder.CreateExtractValue(NewCI, 1);
954 Res = Builder.CreateInsertValue(Res, OldVal, 0);
955 Res = Builder.CreateInsertValue(Res, Succ, 1);
973 bool ShouldInsertFencesForAtomic = TLI->shouldInsertFencesForAtomic(CI);
986 bool HasReleasedLoadBB = !CI->
isWeak() && ShouldInsertFencesForAtomic &&
1042 auto ReleasedLoadBB =
1046 auto ReleasingStoreBB =
1056 std::prev(BB->
end())->eraseFromParent();
1058 if (ShouldInsertFencesForAtomic && UseUnconditionalReleaseBarrier)
1059 TLI->emitLeadingFence(Builder, CI, SuccessOrder);
1064 Value *UnreleasedLoad = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
1070 Builder.
CreateCondBr(ShouldStore, ReleasingStoreBB, NoStoreBB);
1073 if (ShouldInsertFencesForAtomic && !UseUnconditionalReleaseBarrier)
1074 TLI->emitLeadingFence(Builder, CI, SuccessOrder);
1078 Value *StoreSuccess = TLI->emitStoreConditional(
1082 BasicBlock *RetryBB = HasReleasedLoadBB ? ReleasedLoadBB : StartBB;
1084 CI->
isWeak() ? FailureBB : RetryBB);
1088 if (HasReleasedLoadBB) {
1089 SecondLoad = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
1095 Builder.
CreateCondBr(ShouldStore, TryStoreBB, NoStoreBB);
1102 if (ShouldInsertFencesForAtomic)
1103 TLI->emitTrailingFence(Builder, CI, SuccessOrder);
1110 TLI->emitAtomicCmpXchgNoStoreLLBalance(Builder);
1114 if (ShouldInsertFencesForAtomic)
1115 TLI->emitTrailingFence(Builder, CI, FailureOrder);
1129 if (!HasReleasedLoadBB)
1130 Loaded = UnreleasedLoad;
1134 TryStoreLoaded->
addIncoming(UnreleasedLoad, ReleasingStoreBB);
1135 TryStoreLoaded->
addIncoming(SecondLoad, ReleasedLoadBB);
1139 NoStoreLoaded->
addIncoming(UnreleasedLoad, StartBB);
1140 NoStoreLoaded->
addIncoming(SecondLoad, ReleasedLoadBB);
1144 ExitLoaded->
addIncoming(TryStoreLoaded, SuccessBB);
1145 ExitLoaded->
addIncoming(NoStoreLoaded, FailureBB);
1147 Loaded = ExitLoaded;
1159 "weird extraction from { iN, i1 }");
1170 for (
auto EV : PrunedInsts)
1171 EV->eraseFromParent();
1200 return C->isMinusOne();
1207 bool AtomicExpand::simplifyIdempotentRMW(
AtomicRMWInst* RMWI) {
1208 if (
auto ResultingLoad = TLI->lowerIdempotentRMWIntoFencedLoad(RMWI)) {
1209 tryExpandAtomicLoad(ResultingLoad);
1215 Value *AtomicExpand::insertRMWCmpXchgLoop(
1246 std::prev(BB->
end())->eraseFromParent();
1258 Value *NewVal = PerformOp(Builder, Loaded);
1260 Value *NewLoaded =
nullptr;
1263 CreateCmpXchg(Builder, Addr, Loaded, NewVal,
1267 Success, NewLoaded);
1268 assert(Success && NewLoaded);
1282 Value *Loaded = AtomicExpand::insertRMWCmpXchgLoop(
1310 return Align >= Size &&
1311 (Size == 1 || Size == 2 || Size == 4 || Size == 8 || Size == 16) &&
1312 Size <= LargestSize;
1315 void AtomicExpand::expandAtomicLoadToLibcall(
LoadInst *I) {
1318 RTLIB::ATOMIC_LOAD_4, RTLIB::ATOMIC_LOAD_8, RTLIB::ATOMIC_LOAD_16};
1322 bool expanded = expandAtomicOpToLibcall(
1326 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor Load");
1329 void AtomicExpand::expandAtomicStoreToLibcall(
StoreInst *I) {
1332 RTLIB::ATOMIC_STORE_4, RTLIB::ATOMIC_STORE_8, RTLIB::ATOMIC_STORE_16};
1336 bool expanded = expandAtomicOpToLibcall(
1340 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor Store");
1345 RTLIB::ATOMIC_COMPARE_EXCHANGE, RTLIB::ATOMIC_COMPARE_EXCHANGE_1,
1346 RTLIB::ATOMIC_COMPARE_EXCHANGE_2, RTLIB::ATOMIC_COMPARE_EXCHANGE_4,
1347 RTLIB::ATOMIC_COMPARE_EXCHANGE_8, RTLIB::ATOMIC_COMPARE_EXCHANGE_16};
1351 bool expanded = expandAtomicOpToLibcall(
1356 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor CAS");
1361 RTLIB::ATOMIC_EXCHANGE, RTLIB::ATOMIC_EXCHANGE_1,
1362 RTLIB::ATOMIC_EXCHANGE_2, RTLIB::ATOMIC_EXCHANGE_4,
1363 RTLIB::ATOMIC_EXCHANGE_8, RTLIB::ATOMIC_EXCHANGE_16};
1365 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_ADD_1,
1366 RTLIB::ATOMIC_FETCH_ADD_2, RTLIB::ATOMIC_FETCH_ADD_4,
1367 RTLIB::ATOMIC_FETCH_ADD_8, RTLIB::ATOMIC_FETCH_ADD_16};
1369 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_SUB_1,
1370 RTLIB::ATOMIC_FETCH_SUB_2, RTLIB::ATOMIC_FETCH_SUB_4,
1371 RTLIB::ATOMIC_FETCH_SUB_8, RTLIB::ATOMIC_FETCH_SUB_16};
1373 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_AND_1,
1374 RTLIB::ATOMIC_FETCH_AND_2, RTLIB::ATOMIC_FETCH_AND_4,
1375 RTLIB::ATOMIC_FETCH_AND_8, RTLIB::ATOMIC_FETCH_AND_16};
1377 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_OR_1,
1378 RTLIB::ATOMIC_FETCH_OR_2, RTLIB::ATOMIC_FETCH_OR_4,
1379 RTLIB::ATOMIC_FETCH_OR_8, RTLIB::ATOMIC_FETCH_OR_16};
1381 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_XOR_1,
1382 RTLIB::ATOMIC_FETCH_XOR_2, RTLIB::ATOMIC_FETCH_XOR_4,
1383 RTLIB::ATOMIC_FETCH_XOR_8, RTLIB::ATOMIC_FETCH_XOR_16};
1385 RTLIB::UNKNOWN_LIBCALL, RTLIB::ATOMIC_FETCH_NAND_1,
1386 RTLIB::ATOMIC_FETCH_NAND_2, RTLIB::ATOMIC_FETCH_NAND_4,
1387 RTLIB::ATOMIC_FETCH_NAND_8, RTLIB::ATOMIC_FETCH_NAND_16};
1416 void AtomicExpand::expandAtomicRMWToLibcall(
AtomicRMWInst *I) {
1423 if (!Libcalls.
empty())
1424 Success = expandAtomicOpToLibcall(
1439 Addr, Loaded, NewVal, MemOpOrder,
1445 expandAtomicCASToLibcall(Pair);
1456 bool AtomicExpand::expandAtomicOpToLibcall(
1488 if (UseSizedLibcall) {
1490 case 1: RTLibType = Libcalls[1];
break;
1491 case 2: RTLibType = Libcalls[2];
break;
1492 case 4: RTLibType = Libcalls[3];
break;
1493 case 8: RTLibType = Libcalls[4];
break;
1494 case 16: RTLibType = Libcalls[5];
break;
1496 }
else if (Libcalls[0] != RTLIB::UNKNOWN_LIBCALL) {
1497 RTLibType = Libcalls[0];
1531 Value *AllocaCASExpected_i8 =
nullptr;
1533 Value *AllocaValue_i8 =
nullptr;
1535 Value *AllocaResult_i8 =
nullptr;
1542 if (!UseSizedLibcall) {
1554 AllocaCASExpected = AllocaBuilder.CreateAlloca(CASExpected->
getType());
1556 AllocaCASExpected_i8 =
1565 if (UseSizedLibcall) {
1570 AllocaValue = AllocaBuilder.CreateAlloca(ValueOperand->
getType());
1581 if (!CASExpected && HasResult && !UseSizedLibcall) {
1582 AllocaResult = AllocaBuilder.CreateAlloca(I->
getType());
1601 }
else if (HasResult && UseSizedLibcall)
1602 ResultTy = SizedIntTy;
1618 if (ValueOperand && !UseSizedLibcall)
1626 Value *ExpectedOut =
1632 }
else if (HasResult) {
1634 if (UseSizedLibcall)
Value * getValueOperand()
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
*p = old <signed v ? old : v
LLVMContext & getContext() const
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Atomic ordering constants.
Compute iterated dominance frontiers using a linear time algorithm.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
static bool atomicSizeSupported(const TargetLowering *TLI, Inst *I)
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
A Module instance is used to store all the information related to an LLVM module. ...
void setAlignment(unsigned Align)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
This class represents a function call, abstracting a target machine's calling convention.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
static PartwordMaskValues createMaskInstrs(IRBuilder<> &Builder, Instruction *I, Type *ValueType, Value *Addr, unsigned WordSize)
This is a helper function which builds instructions to provide values necessary for partword atomic o...
*p = old <unsigned v ? old : v
An efficient, type-erasing, non-owning reference to a callable.
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
*p = old >unsigned v ? old : v
LLVMContext & getContext() const
All values hold a context through their type.
Value * getNewValOperand()
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
char & AtomicExpandID
AtomicExpandID – Lowers atomic operations in terms of either cmpxchg load-linked/store-conditional l...
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
*p = old >signed v ? old : v
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
iterator begin()
Instruction iterator methods.
Value * CreateNot(Value *V, const Twine &Name="")
bool isVolatile() const
Return true if this is a load from a volatile memory location.
inst_iterator inst_begin(Function *F)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
BinOp getOperation() const
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This file contains the simple types necessary to represent the attributes associated with functions a...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
AtomicOrdering
Atomic ordering for LLVM's memory model.
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun CreateCmpXchg)
Expand an atomic RMW instruction into a loop utilizing cmpxchg.
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Value * getPointerOperand()
Class to represent function types.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getType() const
All values are typed, get the type of this value.
static bool canUseSizedAtomicCall(unsigned Size, unsigned Align, const DataLayout &DL)
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
BinOp
This enumeration lists the possible modifications atomicrmw can make.
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
static void createCmpXchgInstFun(IRBuilder<> &Builder, Value *Addr, Value *Loaded, Value *NewVal, AtomicOrdering MemOpOrder, Value *&Success, Value *&NewLoaded)
BasicBlock * GetInsertBlock() const
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isLittleEndian() const
Layout endianness...
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
const BasicBlock & getEntryBlock() const
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of converting the string to 'bool' fo...
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
static bool runOnFunction(Function &F, bool PostInlining)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
UnreachableInst * CreateUnreachable()
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Value * getCompareOperand()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
const Instruction & front() const
bool isAcquireOrStronger(AtomicOrdering ao)
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
static Type * getVoidTy(LLVMContext &C)
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
static unsigned getAtomicOpSize(LoadInst *LI)
void initializeAtomicExpandPass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Value * getPointerOperand()
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
self_iterator getIterator()
Class to represent integer types.
const Function * getFunction() const
Return the function this instruction belongs to.
void setAlignment(unsigned Align)
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
INITIALIZE_PASS(AtomicExpand, DEBUG_TYPE, "Expand Atomic instructions", false, false) FunctionPass *llvm
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this cmpxchg instruction.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
unsigned getMaxAtomicSizeInBitsSupported() const
Returns the maximum atomic operation size (in bits) supported by the backend.
static Value * performAtomicOp(AtomicRMWInst::BinOp Op, IRBuilder<> &Builder, Value *Loaded, Value *Inc)
Emit IR to implement the given atomicrmw operation on values in registers, returning the new value...
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success...
bool isReleaseOrStronger(AtomicOrdering ao)
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
This is the shared class of boolean and integer constants.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getTrue(LLVMContext &Context)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setVolatile(bool V)
Specify whether this is a volatile store or not.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void setWeak(bool IsWeak)
iterator_range< user_iterator > users()
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
amdgpu Simplify well known AMD library false Value Value * Arg
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
bool isVolatile() const
Return true if this is a store to a volatile memory location.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
static IntegerType * getInt32Ty(LLVMContext &C)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
Value * getPointerOperand()
const Function * getParent() const
Return the enclosing method, or null if none.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
static unsigned getAtomicOpAlign(LoadInst *LI)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
AtomicOrderingCABI toCABI(AtomicOrdering ao)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' correctly, instead of converting the strin...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
void setAlignment(unsigned Align)
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
static ArrayRef< RTLIB::Libcall > GetRMWLibcall(AtomicRMWInst::BinOp Op)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
BasicBlock::iterator GetInsertPoint() const
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Primary interface to the complete machine description for the target machine.
static Value * performMaskedAtomicOp(AtomicRMWInst::BinOp Op, IRBuilder<> &Builder, Value *Loaded, Value *Shifted_Inc, Value *Inc, const PartwordMaskValues &PMV)
Emit IR to implement a masked version of a given atomicrmw operation.
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
inst_iterator inst_end(Function *F)
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
FunctionPass * createAtomicExpandPass()
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Value * getPointerOperand()
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool empty() const
empty - Check if the array is empty.
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)