22 #define DEBUG_TYPE "loweratomic"
30 LoadInst *Orig = Builder.CreateLoad(Ptr);
31 Value *Equal = Builder.CreateICmpEQ(Orig, Cmp);
32 Value *Res = Builder.CreateSelect(Equal, Val, Orig);
33 Builder.CreateStore(Res, Ptr);
36 Res = Builder.CreateInsertValue(Res, Equal, 1);
48 LoadInst *Orig = Builder.CreateLoad(Ptr);
57 Res = Builder.CreateAdd(Orig, Val);
60 Res = Builder.CreateSub(Orig, Val);
63 Res = Builder.CreateAnd(Orig, Val);
66 Res = Builder.CreateNot(Builder.CreateAnd(Orig, Val));
69 Res = Builder.CreateOr(Orig, Val);
72 Res = Builder.CreateXor(Orig, Val);
75 Res = Builder.CreateSelect(Builder.CreateICmpSLT(Orig, Val),
79 Res = Builder.CreateSelect(Builder.CreateICmpSLT(Orig, Val),
83 Res = Builder.CreateSelect(Builder.CreateICmpULT(Orig, Val),
87 Res = Builder.CreateSelect(Builder.CreateICmpULT(Orig, Val),
91 Builder.CreateStore(Res, Ptr);
118 bool runOnBasicBlock(
BasicBlock &BB)
override {
119 if (skipOptnoneFunction(BB))
121 bool Changed =
false;
124 if (
FenceInst *FI = dyn_cast<FenceInst>(Inst))
128 else if (
AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(Inst))
130 else if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
133 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
145 "Lower atomic intrinsics to non-atomic form",
Pass interface - Implemented by all 'passes'.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
*p = old <signed v ? old : v
FenceInst - an instruction for ordering other memory operations.
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
*p = old <unsigned v ? old : v
static bool LowerLoadInst(LoadInst *LI)
*p = old >unsigned v ? old : v
Value * getNewValOperand()
LoadInst - an instruction for reading from memory.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
static bool LowerFenceInst(FenceInst *FI)
*p = old >signed v ? old : v
iterator begin()
Instruction iterator methods.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Value * getPointerOperand()
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
static bool LowerStoreInst(StoreInst *SI)
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM Basic Block Representation.
Value * getCompareOperand()
static bool LowerAtomicRMWInst(AtomicRMWInst *RMWI)
void initializeLowerAtomicPass(PassRegistry &)
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
BasicBlockPass class - This class is used to implement most local optimizations.
Type * getType() const
All values are typed, get the type of this value.
Pass * createLowerAtomicPass()
BinOp getOperation() const
Value * getPointerOperand()
INITIALIZE_PASS(LowerAtomic,"loweratomic","Lower atomic intrinsics to non-atomic form", false, false) Pass *llvm
LLVM Value Representation.
static bool LowerAtomicCmpXchgInst(AtomicCmpXchgInst *CXI)
const BasicBlock * getParent() const