10#ifndef LLVM_FRONTEND_ATOMIC_ATOMIC_H
11#define LLVM_FRONTEND_ATOMIC_ATOMIC_H
72 bool CmpXchg =
false) {
81 Load->setVolatile(
true);
90 for (
Value *Arg : Args)
101 FunctionCallee LibcallFn = M->getOrInsertFunction(fnName, FnType, fnAttrs);
147 return std::make_pair(ExpectedVal, Result);
158 std::pair<llvm::Value *, llvm::Value *>
162 bool IsVolatile =
false,
bool IsWeak =
false) {
165 auto *Inst =
Builder->CreateAtomicCmpXchg(
Addr, ExpectedVal, DesiredVal,
169 Inst->setVolatile(IsVolatile);
170 Inst->setWeak(IsWeak);
172 auto *PreviousVal =
Builder->CreateExtractValue(Inst, 0);
173 auto *SuccessFailureVal =
Builder->CreateExtractValue(Inst, 1);
174 return std::make_pair(PreviousVal, SuccessFailureVal);
177 std::pair<llvm::Value *, llvm::Value *>
187 Failure, IsVolatile, IsWeak);
192 std::pair<llvm::LoadInst *, llvm::AllocaInst *>
201 Args.push_back(ConstantInt::get(
DL.getIntPtrType(Ctx),
202 this->getAtomicSizeInBits() / 8));
206 Args.push_back(PtrVal);
209 const Align AllocaAlignment =
DL.getPrefTypeAlign(SizedIntTy);
211 Args.push_back(AllocaResult);
214 Args.push_back(OrderingVal);
218 for (
Value *Arg : Args)
222 M->getOrInsertFunction(
"__atomic_load", FnType, Attr);
224 Call->setAttributes(Attr);
225 return std::make_pair(
226 Builder->CreateAlignedLoad(
Ty, AllocaResult, AllocaAlignment),
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
static StringRef getName(Value *V)
Class for arbitrary precision integers.
an instruction to allocate memory on the stack
void setAlignment(Align Align)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
A parsed version of the target data layout string in and methods for querying it.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Type * getVoidTy(LLVMContext &C)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM Value Representation.
@ System
Synchronized with respect to all concurrently executing threads.
This is an optimization pass for GlobalISel generic memory operations.
AtomicOrderingCABI toCABI(AtomicOrdering AO)
AtomicOrdering
Atomic ordering for LLVM's memory model.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t AtomicSizeInBits
uint64_t getValueSizeInBits() const
AtomicInfo(IRBuilderTy *Builder, Type *Ty, uint64_t AtomicSizeInBits, uint64_t ValueSizeInBits, llvm::Align AtomicAlign, llvm::Align ValueAlign, bool UseLibcall)
uint64_t getAtomicSizeInBits() const
std::pair< llvm::Value *, llvm::Value * > EmitAtomicCompareExchangeLibcall(llvm::Value *ExpectedVal, llvm::Value *DesiredVal, llvm::AtomicOrdering Success, llvm::AtomicOrdering Failure)
std::pair< llvm::Value *, llvm::Value * > EmitAtomicCompareExchange(llvm::Value *ExpectedVal, llvm::Value *DesiredVal, llvm::AtomicOrdering Success, llvm::AtomicOrdering Failure, bool IsVolatile, bool IsWeak)
std::pair< llvm::Value *, llvm::Value * > EmitAtomicCompareExchangeOp(llvm::Value *ExpectedVal, llvm::Value *DesiredVal, llvm::AtomicOrdering Success, llvm::AtomicOrdering Failure, bool IsVolatile=false, bool IsWeak=false)
llvm::Type * getAtomicTy() const
Value * castToAtomicIntPointer(Value *addr) const
virtual llvm::AllocaInst * CreateAlloca(llvm::Type *Ty, const llvm::Twine &Name) const =0
static CallInst * EmitAtomicLibcall(IRBuilderTy *Builder, StringRef fnName, Type *ResultType, ArrayRef< Value * > Args)
static bool shouldCastToInt(llvm::Type *ValTy, bool CmpXchg)
llvm::Value * EmitAtomicLoadOp(llvm::AtomicOrdering AO, bool IsVolatile, bool CmpXchg=false)
llvm::Align getAtomicAlignment() const
virtual llvm::Value * getAtomicPointer() const =0
virtual void decorateWithTBAA(Instruction *I)=0
LLVMContext & getLLVMContext() const
bool shouldUseLibcall() const
std::pair< llvm::LoadInst *, llvm::AllocaInst * > EmitAtomicLoadLibcall(llvm::AtomicOrdering AO)
Value * getAtomicAddressAsAtomicIntPointer() const
virtual ~AtomicInfo()=default
llvm::Value * getAtomicSizeValue() const