35 #define DEBUG_TYPE "atomic-expand"
52 bool tryExpandAtomicLoad(
LoadInst *LI);
53 bool expandAtomicLoadToLL(
LoadInst *LI);
54 bool expandAtomicLoadToCmpXchg(
LoadInst *LI);
62 void expandAtomicOpToLLSC(
65 void expandPartwordAtomicRMW(
71 static Value *insertRMWCmpXchgLoop(
86 void expandAtomicLoadToLibcall(
LoadInst *LI);
87 void expandAtomicStoreToLibcall(
StoreInst *LI);
106 unsigned getAtomicOpSize(
LoadInst *LI) {
111 unsigned getAtomicOpSize(
StoreInst *SI) {
127 unsigned getAtomicOpAlign(
LoadInst *LI) {
132 assert(Align != 0 &&
"An atomic LoadInst always has an explicit alignment");
136 unsigned getAtomicOpAlign(
StoreInst *SI) {
141 assert(Align != 0 &&
"An atomic StoreInst always has an explicit alignment");
162 template <
typename Inst>
164 unsigned Size = getAtomicOpSize(I);
165 unsigned Align = getAtomicOpAlign(I);
171 bool AtomicExpand::runOnFunction(
Function &
F) {
172 auto *
TPC = getAnalysisIfAvailable<TargetPassConfig>();
177 if (!
TM.getSubtargetImpl(F)->enableAtomicExpand())
179 TLI =
TM.getSubtargetImpl(F)->getTargetLowering();
191 bool MadeChange =
false;
192 for (
auto I : AtomicInsts) {
197 assert((LI || SI || RMWI || CASI) &&
"Unknown atomic instruction");
201 if (!atomicSizeSupported(TLI, LI)) {
202 expandAtomicLoadToLibcall(LI);
207 if (!atomicSizeSupported(TLI, SI)) {
208 expandAtomicStoreToLibcall(SI);
213 if (!atomicSizeSupported(TLI, RMWI)) {
214 expandAtomicRMWToLibcall(RMWI);
219 if (!atomicSizeSupported(TLI, CASI)) {
220 expandAtomicCASToLibcall(CASI);
226 if (TLI->shouldInsertFencesForAtomic(I)) {
232 FenceOrdering = SI->getOrdering();
236 FenceOrdering = RMWI->getOrdering();
238 }
else if (CASI && !TLI->shouldExpandAtomicCmpXchgInIR(CASI) &&
245 FenceOrdering = CASI->getSuccessOrdering();
251 MadeChange |= bracketInstWithFences(I, FenceOrdering);
259 LI = convertAtomicLoadToIntegerType(LI);
264 MadeChange |= tryExpandAtomicLoad(LI);
266 if (SI->getValueOperand()->getType()->isFloatingPointTy()) {
269 SI = convertAtomicStoreToIntegerType(SI);
270 assert(SI->getValueOperand()->getType()->isIntegerTy() &&
275 if (TLI->shouldExpandAtomicStoreInIR(SI))
276 MadeChange |= expandAtomicStore(SI);
283 if (isIdempotentRMW(RMWI) && simplifyIdempotentRMW(RMWI)) {
286 MadeChange |= tryExpandAtomicRMW(RMWI);
291 assert(!CASI->getCompareOperand()->getType()->isFloatingPointTy() &&
292 "unimplemented - floating point not legal at IR level");
293 if (CASI->getCompareOperand()->getType()->isPointerTy() ) {
296 CASI = convertCmpXchgToIntegerType(CASI);
297 assert(CASI->getCompareOperand()->getType()->isIntegerTy() &&
302 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
303 unsigned ValueSize = getAtomicOpSize(CASI);
304 if (ValueSize < MinCASSize) {
305 assert(!TLI->shouldExpandAtomicCmpXchgInIR(CASI) &&
306 "MinCmpXchgSizeInBits not yet supported for LL/SC expansions.");
307 expandPartwordCmpXchg(CASI);
309 if (TLI->shouldExpandAtomicCmpXchgInIR(CASI))
310 MadeChange |= expandAtomicCmpXchg(CASI);
320 auto LeadingFence = TLI->emitLeadingFence(Builder, I, Order);
322 auto TrailingFence = TLI->emitTrailingFence(Builder, I, Order);
330 TrailingFence->removeFromParent();
331 TrailingFence->insertAfter(I);
334 return (LeadingFence || TrailingFence);
340 EVT VT = TLI->getValueType(DL, T);
351 Type *NewTy = getCorrespondingIntegerType(LI->
getType(),
359 Value *NewAddr = Builder.CreateBitCast(Addr, PT);
361 auto *NewLI = Builder.CreateLoad(NewAddr);
365 DEBUG(
dbgs() <<
"Replaced " << *LI <<
" with " << *NewLI <<
"\n");
367 Value *NewVal = Builder.CreateBitCast(NewLI, LI->
getType());
373 bool AtomicExpand::tryExpandAtomicLoad(
LoadInst *LI) {
374 switch (TLI->shouldExpandAtomicLoadInIR(LI)) {
378 expandAtomicOpToLLSC(
383 return expandAtomicLoadToLL(LI);
385 return expandAtomicLoadToCmpXchg(LI);
390 bool AtomicExpand::expandAtomicLoadToLL(
LoadInst *LI) {
398 TLI->emitAtomicCmpXchgNoStoreLLBalance(Builder);
406 bool AtomicExpand::expandAtomicLoadToCmpXchg(
LoadInst *LI) {
410 Type *Ty = cast<PointerType>(Addr->
getType())->getElementType();
413 Value *Pair = Builder.CreateAtomicCmpXchg(
414 Addr, DummyVal, DummyVal, Order,
416 Value *Loaded = Builder.CreateExtractValue(Pair, 0,
"loaded");
442 Value *NewAddr = Builder.CreateBitCast(Addr, PT);
444 StoreInst *NewSI = Builder.CreateStore(NewVal, NewAddr);
448 DEBUG(
dbgs() <<
"Replaced " << *SI <<
" with " << *NewSI <<
"\n");
453 bool AtomicExpand::expandAtomicStore(
StoreInst *SI) {
467 return tryExpandAtomicRMW(AI);
475 Addr, Loaded, NewVal, MemOpOrder,
490 return Builder.
CreateAdd(Loaded, Inc,
"new");
492 return Builder.
CreateSub(Loaded, Inc,
"new");
494 return Builder.
CreateAnd(Loaded, Inc,
"new");
498 return Builder.
CreateOr(Loaded, Inc,
"new");
500 return Builder.
CreateXor(Loaded, Inc,
"new");
503 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
506 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
509 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
512 return Builder.
CreateSelect(NewVal, Loaded, Inc,
"new");
519 switch (TLI->shouldExpandAtomicRMWInIR(AI)) {
523 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
524 unsigned ValueSize = getAtomicOpSize(AI);
525 if (ValueSize < MinCASSize) {
527 "MinCmpXchgSizeInBits not yet supported for LL/SC architectures.");
539 unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
540 unsigned ValueSize = getAtomicOpSize(AI);
541 if (ValueSize < MinCASSize) {
542 expandPartwordAtomicRMW(AI,
557 struct PartwordMaskValues {
587 PartwordMaskValues
Ret;
598 assert(ValueSize < WordSize);
608 Builder.
CreateAnd(AddrInt, ~(uint64_t)(WordSize - 1)), WordPtrType,
611 Value *PtrLSB = Builder.
CreateAnd(AddrInt, WordSize - 1,
"PtrLSB");
614 Ret.ShiftAmt = Builder.
CreateShl(PtrLSB, 3);
621 Ret.ShiftAmt = Builder.
CreateTrunc(Ret.ShiftAmt, Ret.WordType,
"ShiftAmt");
625 Ret.Inv_Mask = Builder.
CreateNot(Ret.Mask,
"Inv_Mask");
636 const PartwordMaskValues &PMV) {
640 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, Shifted_Inc);
656 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Masked);
667 Builder.
CreateLShr(Loaded, PMV.ShiftAmt), PMV.ValueType);
670 Builder.
CreateZExt(NewVal, PMV.WordType), PMV.ShiftAmt);
672 Value *FinalVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Shiftup);
687 void AtomicExpand::expandPartwordAtomicRMW(
696 PartwordMaskValues PMV =
698 TLI->getMinCmpXchgSizeInBits() / 8);
700 Value *ValOperand_Shifted =
702 PMV.ShiftAmt,
"ValOperand_Shifted");
712 insertRMWCmpXchgLoop(Builder, PMV.WordType, PMV.AlignedAddr, MemOpOrder,
715 Builder.
CreateLShr(OldResult, PMV.ShiftAmt), PMV.ValueType);
765 const int WordSize = TLI->getMinCmpXchgSizeInBits() / 8;
775 std::prev(BB->
end())->eraseFromParent();
782 Value *NewVal_Shifted =
791 Value *InitLoaded_MaskOut = Builder.
CreateAnd(InitLoaded, PMV.Inv_Mask);
797 Loaded_MaskOut->
addIncoming(InitLoaded_MaskOut, BB);
800 Value *FullWord_NewVal = Builder.
CreateOr(Loaded_MaskOut, NewVal_Shifted);
801 Value *FullWord_Cmp = Builder.
CreateOr(Loaded_MaskOut, Cmp_Shifted);
831 Loaded_MaskOut->
addIncoming(OldVal_MaskOut, FailureBB);
837 Builder.
CreateLShr(OldVal, PMV.ShiftAmt), PMV.ValueType);
846 void AtomicExpand::expandAtomicOpToLLSC(
851 insertRMWLLSCLoop(Builder, ResultType, Addr, MemOpOrder, PerformOp);
857 Value *AtomicExpand::insertRMWLLSCLoop(
883 std::prev(BB->
end())->eraseFromParent();
889 Value *Loaded = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
891 Value *NewVal = PerformOp(Builder, Loaded);
893 Value *StoreSuccess =
894 TLI->emitStoreConditional(Builder, NewVal, Addr, MemOpOrder);
930 DEBUG(
dbgs() <<
"Replaced " << *CI <<
" with " << *NewCI <<
"\n");
958 bool ShouldInsertFencesForAtomic = TLI->shouldInsertFencesForAtomic(CI);
971 bool HasReleasedLoadBB = !CI->
isWeak() && ShouldInsertFencesForAtomic &&
1027 auto ReleasedLoadBB =
1031 auto ReleasingStoreBB =
1041 std::prev(BB->
end())->eraseFromParent();
1043 if (ShouldInsertFencesForAtomic && UseUnconditionalReleaseBarrier)
1044 TLI->emitLeadingFence(Builder, CI, SuccessOrder);
1049 Value *UnreleasedLoad = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
1055 Builder.
CreateCondBr(ShouldStore, ReleasingStoreBB, NoStoreBB);
1058 if (ShouldInsertFencesForAtomic && !UseUnconditionalReleaseBarrier)
1059 TLI->emitLeadingFence(Builder, CI, SuccessOrder);
1063 Value *StoreSuccess = TLI->emitStoreConditional(
1067 BasicBlock *RetryBB = HasReleasedLoadBB ? ReleasedLoadBB : StartBB;
1069 CI->
isWeak() ? FailureBB : RetryBB);
1073 if (HasReleasedLoadBB) {
1074 SecondLoad = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
1080 Builder.
CreateCondBr(ShouldStore, TryStoreBB, NoStoreBB);
1087 if (ShouldInsertFencesForAtomic)
1088 TLI->emitTrailingFence(Builder, CI, SuccessOrder);
1095 TLI->emitAtomicCmpXchgNoStoreLLBalance(Builder);
1099 if (ShouldInsertFencesForAtomic)
1100 TLI->emitTrailingFence(Builder, CI, FailureOrder);
1114 if (!HasReleasedLoadBB)
1115 Loaded = UnreleasedLoad;
1119 TryStoreLoaded->
addIncoming(UnreleasedLoad, ReleasingStoreBB);
1120 TryStoreLoaded->
addIncoming(SecondLoad, ReleasedLoadBB);
1124 NoStoreLoaded->
addIncoming(UnreleasedLoad, StartBB);
1125 NoStoreLoaded->
addIncoming(SecondLoad, ReleasedLoadBB);
1129 ExitLoaded->
addIncoming(TryStoreLoaded, SuccessBB);
1130 ExitLoaded->
addIncoming(NoStoreLoaded, FailureBB);
1132 Loaded = ExitLoaded;
1144 "weird extraction from { iN, i1 }");
1155 for (
auto EV : PrunedInsts)
1185 return C->isMinusOne();
1192 bool AtomicExpand::simplifyIdempotentRMW(
AtomicRMWInst* RMWI) {
1193 if (
auto ResultingLoad = TLI->lowerIdempotentRMWIntoFencedLoad(RMWI)) {
1194 tryExpandAtomicLoad(ResultingLoad);
1200 Value *AtomicExpand::insertRMWCmpXchgLoop(
1231 std::prev(BB->
end())->eraseFromParent();
1243 Value *NewVal = PerformOp(Builder, Loaded);
1245 Value *NewLoaded =
nullptr;
1246 Value *Success =
nullptr;
1248 CreateCmpXchg(Builder, Addr, Loaded, NewVal,
1252 Success, NewLoaded);
1253 assert(Success && NewLoaded);
1267 Value *Loaded = AtomicExpand::insertRMWCmpXchgLoop(
1295 return Align >= Size &&
1296 (Size == 1 || Size == 2 || Size == 4 || Size == 8 || Size == 16) &&
1297 Size <= LargestSize;
1300 void AtomicExpand::expandAtomicLoadToLibcall(
LoadInst *I) {
1304 unsigned Size = getAtomicOpSize(I);
1305 unsigned Align = getAtomicOpAlign(I);
1307 bool expanded = expandAtomicOpToLibcall(
1311 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor Load");
1314 void AtomicExpand::expandAtomicStoreToLibcall(
StoreInst *I) {
1318 unsigned Size = getAtomicOpSize(I);
1319 unsigned Align = getAtomicOpAlign(I);
1321 bool expanded = expandAtomicOpToLibcall(
1325 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor Store");
1333 unsigned Size = getAtomicOpSize(I);
1334 unsigned Align = getAtomicOpAlign(I);
1336 bool expanded = expandAtomicOpToLibcall(
1341 assert(expanded &&
"expandAtomicOpToLibcall shouldn't fail tor CAS");
1401 void AtomicExpand::expandAtomicRMWToLibcall(
AtomicRMWInst *I) {
1404 unsigned Size = getAtomicOpSize(I);
1405 unsigned Align = getAtomicOpAlign(I);
1407 bool Success =
false;
1408 if (!Libcalls.
empty())
1409 Success = expandAtomicOpToLibcall(
1424 Addr, Loaded, NewVal, MemOpOrder,
1430 expandAtomicCASToLibcall(Pair);
1441 bool AtomicExpand::expandAtomicOpToLibcall(
1473 if (UseSizedLibcall) {
1475 case 1: RTLibType = Libcalls[1];
break;
1476 case 2: RTLibType = Libcalls[2];
break;
1477 case 4: RTLibType = Libcalls[3];
break;
1478 case 8: RTLibType = Libcalls[4];
break;
1479 case 16: RTLibType = Libcalls[5];
break;
1482 RTLibType = Libcalls[0];
1516 Value *AllocaCASExpected_i8 =
nullptr;
1518 Value *AllocaValue_i8 =
nullptr;
1520 Value *AllocaResult_i8 =
nullptr;
1527 if (!UseSizedLibcall) {
1539 AllocaCASExpected = AllocaBuilder.CreateAlloca(CASExpected->
getType());
1541 AllocaCASExpected_i8 =
1550 if (UseSizedLibcall) {
1555 AllocaValue = AllocaBuilder.CreateAlloca(ValueOperand->
getType());
1566 if (!CASExpected && HasResult && !UseSizedLibcall) {
1567 AllocaResult = AllocaBuilder.CreateAlloca(I->
getType());
1586 }
else if (HasResult && UseSizedLibcall)
1587 ResultTy = SizedIntTy;
1593 for (
Value *Arg : Args)
1600 Value *Result = Call;
1603 if (ValueOperand && !UseSizedLibcall)
1611 Value *ExpectedOut =
1617 }
else if (HasResult) {
1619 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. ...
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
static ConstantInt * getFalse(LLVMContext &Context)
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)
BasicBlock::iterator GetInsertPoint() const
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
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
*p = old <signed v ? old : v
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
bool isVolatile() const
Return true if this is a store to a volatile memory location.
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)
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
static AtomicOrderingCABI toCABI(AtomicOrdering ao)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this cmpxchg instruction.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
This class represents a function call, abstracting a target machine's calling convention.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
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...
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.
*p = old >unsigned v ? old : v
const Function * getParent() const
Return the enclosing method, or null if none.
Value * getNewValOperand()
const Instruction & front() const
char & AtomicExpandID
AtomicExpandID – Lowers atomic operations in terms of either cmpxchg load-linked/store-conditional lo...
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
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
iterator begin()
Instruction iterator methods.
Value * CreateNot(Value *V, const Twine &Name="")
inst_iterator inst_begin(Function *F)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
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.
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Value * getPointerOperand()
Class to represent function types.
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
static bool canUseSizedAtomicCall(unsigned Size, unsigned Align, const DataLayout &DL)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
BinOp
This enumeration lists the possible modifications atomicrmw can make.
static void createCmpXchgInstFun(IRBuilder<> &Builder, Value *Addr, Value *Loaded, Value *NewVal, AtomicOrdering MemOpOrder, Value *&Success, Value *&NewLoaded)
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
bool isLittleEndian() const
Layout endianness...
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
const Function * getFunction() const
Return the function this instruction belongs to.
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="")
AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
size_t size() const
size - Get the array size.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
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="")
LoadInst * CreateLoad(Value *Ptr, const char *Name)
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
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()
This is an important base class in LLVM.
Value * getCompareOperand()
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
static Type * getVoidTy(LLVMContext &C)
void initializeAtomicExpandPass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
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="")
unsigned getMaxAtomicSizeInBitsSupported() const
Returns the maximum atomic operation size (in bits) supported by the backend.
self_iterator getIterator()
Class to represent integer types.
bool empty() const
empty - Check if the array is empty.
void setAlignment(unsigned Align)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
LLVMContext & getContext() const
All values hold a context through their type.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
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 bool isReleaseOrStronger(AtomicOrdering ao)
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success...
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
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...
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.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
This is the shared class of boolean and integer constants.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
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.
Type * getType() const
All values are typed, get the type of this value.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
INITIALIZE_PASS(AtomicExpand, DEBUG_TYPE,"Expand Atomic instructions", false, false) FunctionPass *llvm
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
BasicBlock * GetInsertBlock() const
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.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
const BasicBlock & getEntryBlock() const
static ConstantInt * getTrue(LLVMContext &Context)
BinOp getOperation() const
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.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setWeak(bool IsWeak)
iterator_range< user_iterator > users()
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static bool isAcquireOrStronger(AtomicOrdering ao)
llvm_unreachable("Unknown RegBank!")
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Value * getPointerOperand()
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
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.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
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)
static ArrayRef< RTLIB::Libcall > GetRMWLibcall(AtomicRMWInst::BinOp Op)
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.
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)
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun Factory)
Expand an atomic RMW instruction into a loop utilizing cmpxchg.
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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Value * getPointerOperand()
const BasicBlock * getParent() const
This file describes how to lower LLVM code to machine code.
an instruction to allocate memory on the stack