[SCCP] Move logic for removing ssa.copy into Solver (NFC)
So it can be reused between IPSCCP and SCCP. Make the implementation a bit more efficient by only lookup the PredicateInfo once.
This commit is contained in:
@@ -77,6 +77,8 @@ public:
|
||||
LLVM_ABI void addPredicateInfo(Function &F, DominatorTree &DT,
|
||||
AssumptionCache &AC);
|
||||
|
||||
LLVM_ABI void removeSSACopies(Function &F);
|
||||
|
||||
/// markBlockExecutable - This method can be used by clients to mark all of
|
||||
/// the blocks that are known to be intrinsically live in the processed unit.
|
||||
/// This returns true if the block was not considered live before.
|
||||
|
||||
@@ -250,19 +250,7 @@ static bool runIPSCCP(
|
||||
if (!DeadBB->hasAddressTaken())
|
||||
DTU.deleteBB(DeadBB);
|
||||
|
||||
for (BasicBlock &BB : F) {
|
||||
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
|
||||
if (Solver.getPredicateInfoFor(&Inst)) {
|
||||
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
|
||||
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
|
||||
Value *Op = II->getOperand(0);
|
||||
Inst.replaceAllUsesWith(Op);
|
||||
Inst.eraseFromParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Solver.removeSSACopies(F);
|
||||
}
|
||||
|
||||
// If we inferred constant or undef return values for a function, we replaced
|
||||
|
||||
@@ -764,6 +764,26 @@ public:
|
||||
FnPredicateInfo.insert({&F, std::make_unique<PredicateInfo>(F, DT, AC)});
|
||||
}
|
||||
|
||||
void removeSSACopies(Function &F) {
|
||||
auto It = FnPredicateInfo.find(&F);
|
||||
if (It == FnPredicateInfo.end())
|
||||
return;
|
||||
|
||||
for (BasicBlock &BB : F) {
|
||||
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
|
||||
if (It->second->getPredicateInfoFor(&Inst)) {
|
||||
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
|
||||
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
|
||||
Value *Op = II->getOperand(0);
|
||||
Inst.replaceAllUsesWith(Op);
|
||||
Inst.eraseFromParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void visitCallInst(CallInst &I) { visitCallBase(I); }
|
||||
|
||||
bool markBlockExecutable(BasicBlock *BB);
|
||||
@@ -2168,6 +2188,10 @@ void SCCPSolver::addPredicateInfo(Function &F, DominatorTree &DT,
|
||||
Visitor->addPredicateInfo(F, DT, AC);
|
||||
}
|
||||
|
||||
void SCCPSolver::removeSSACopies(Function &F) {
|
||||
Visitor->removeSSACopies(F);
|
||||
}
|
||||
|
||||
bool SCCPSolver::markBlockExecutable(BasicBlock *BB) {
|
||||
return Visitor->markBlockExecutable(BB);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user