mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-15 04:08:07 +00:00
Change lower atomic pass to use IntrinsicInst to simplify it a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113114 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
906a675db8
commit
bdabacdcca
@ -726,10 +726,9 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
|
||||
if (Baseline != LazyValueInfo::Unknown) {
|
||||
// Check that all remaining incoming values match the first one.
|
||||
while (++PI != PE) {
|
||||
LazyValueInfo::Tristate Ret = LVI->getPredicateOnEdge(
|
||||
CondCmp->getPredicate(),
|
||||
CondCmp->getOperand(0),
|
||||
CondConst, *PI, BB);
|
||||
LazyValueInfo::Tristate Ret =
|
||||
LVI->getPredicateOnEdge(CondCmp->getPredicate(),
|
||||
CondCmp->getOperand(0), CondConst, *PI, BB);
|
||||
if (Ret != Baseline) break;
|
||||
}
|
||||
|
||||
|
@ -18,22 +18,15 @@
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
bool LowerAtomicIntrinsic(CallInst *CI) {
|
||||
IRBuilder<> Builder(CI->getParent(), CI);
|
||||
|
||||
Function *Callee = CI->getCalledFunction();
|
||||
if (!Callee)
|
||||
return false;
|
||||
|
||||
unsigned IID = Callee->getIntrinsicID();
|
||||
static bool LowerAtomicIntrinsic(IntrinsicInst *II) {
|
||||
IRBuilder<> Builder(II->getParent(), II);
|
||||
unsigned IID = II->getIntrinsicID();
|
||||
switch (IID) {
|
||||
case Intrinsic::memory_barrier:
|
||||
break;
|
||||
@ -48,8 +41,8 @@ bool LowerAtomicIntrinsic(CallInst *CI) {
|
||||
case Intrinsic::atomic_load_min:
|
||||
case Intrinsic::atomic_load_umax:
|
||||
case Intrinsic::atomic_load_umin: {
|
||||
Value *Ptr = CI->getArgOperand(0);
|
||||
Value *Delta = CI->getArgOperand(1);
|
||||
Value *Ptr = II->getArgOperand(0);
|
||||
Value *Delta = II->getArgOperand(1);
|
||||
|
||||
LoadInst *Orig = Builder.CreateLoad(Ptr);
|
||||
Value *Res = NULL;
|
||||
@ -96,32 +89,32 @@ bool LowerAtomicIntrinsic(CallInst *CI) {
|
||||
}
|
||||
Builder.CreateStore(Res, Ptr);
|
||||
|
||||
CI->replaceAllUsesWith(Orig);
|
||||
II->replaceAllUsesWith(Orig);
|
||||
break;
|
||||
}
|
||||
|
||||
case Intrinsic::atomic_swap: {
|
||||
Value *Ptr = CI->getArgOperand(0);
|
||||
Value *Val = CI->getArgOperand(1);
|
||||
Value *Ptr = II->getArgOperand(0);
|
||||
Value *Val = II->getArgOperand(1);
|
||||
|
||||
LoadInst *Orig = Builder.CreateLoad(Ptr);
|
||||
Builder.CreateStore(Val, Ptr);
|
||||
|
||||
CI->replaceAllUsesWith(Orig);
|
||||
II->replaceAllUsesWith(Orig);
|
||||
break;
|
||||
}
|
||||
|
||||
case Intrinsic::atomic_cmp_swap: {
|
||||
Value *Ptr = CI->getArgOperand(0);
|
||||
Value *Cmp = CI->getArgOperand(1);
|
||||
Value *Val = CI->getArgOperand(2);
|
||||
Value *Ptr = II->getArgOperand(0);
|
||||
Value *Cmp = II->getArgOperand(1);
|
||||
Value *Val = II->getArgOperand(2);
|
||||
|
||||
LoadInst *Orig = Builder.CreateLoad(Ptr);
|
||||
Value *Equal = Builder.CreateICmpEQ(Orig, Cmp);
|
||||
Value *Res = Builder.CreateSelect(Equal, Val, Orig);
|
||||
Builder.CreateStore(Res, Ptr);
|
||||
|
||||
CI->replaceAllUsesWith(Orig);
|
||||
II->replaceAllUsesWith(Orig);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -129,28 +122,25 @@ bool LowerAtomicIntrinsic(CallInst *CI) {
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(CI->use_empty() &&
|
||||
assert(II->use_empty() &&
|
||||
"Lowering should have eliminated any uses of the intrinsic call!");
|
||||
CI->eraseFromParent();
|
||||
II->eraseFromParent();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct LowerAtomic : public BasicBlockPass {
|
||||
static char ID;
|
||||
LowerAtomic() : BasicBlockPass(ID) {}
|
||||
bool runOnBasicBlock(BasicBlock &BB) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE; ) {
|
||||
Instruction *Inst = DI++;
|
||||
if (CallInst *CI = dyn_cast<CallInst>(Inst))
|
||||
Changed |= LowerAtomicIntrinsic(CI);
|
||||
namespace {
|
||||
struct LowerAtomic : public BasicBlockPass {
|
||||
static char ID;
|
||||
LowerAtomic() : BasicBlockPass(ID) {}
|
||||
bool runOnBasicBlock(BasicBlock &BB) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE; )
|
||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(DI++))
|
||||
Changed |= LowerAtomicIntrinsic(II);
|
||||
return Changed;
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
char LowerAtomic::ID = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user