mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[NFCI][SCEVExpander] Extract GetOptimalInsertionPointForCastOf() helper
This commit is contained in:
parent
c8b00b65d5
commit
a5687129f2
@ -382,7 +382,7 @@ public:
|
||||
/// Returns a suitable insert point after \p I, that dominates \p
|
||||
/// MustDominate. Skips instructions inserted by the expander.
|
||||
BasicBlock::iterator findInsertPointAfter(Instruction *I,
|
||||
Instruction *MustDominate);
|
||||
Instruction *MustDominate) const;
|
||||
|
||||
private:
|
||||
LLVMContext &getContext() const { return SE.getContext(); }
|
||||
@ -415,6 +415,9 @@ private:
|
||||
Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS,
|
||||
SCEV::NoWrapFlags Flags, bool IsSafeToHoist);
|
||||
|
||||
/// We want to cast \p V. What would be the best place for such a cast?
|
||||
BasicBlock::iterator GetOptimalInsertionPointForCastOf(Value *V) const;
|
||||
|
||||
/// Arrange for there to be a cast of V to Ty at IP, reusing an existing
|
||||
/// cast if a suitable one exists, moving an existing cast if a suitable one
|
||||
/// exists but isn't in the right place, or creating a new one.
|
||||
|
@ -89,7 +89,8 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
|
||||
}
|
||||
|
||||
BasicBlock::iterator
|
||||
SCEVExpander::findInsertPointAfter(Instruction *I, Instruction *MustDominate) {
|
||||
SCEVExpander::findInsertPointAfter(Instruction *I,
|
||||
Instruction *MustDominate) const {
|
||||
BasicBlock::iterator IP = ++I->getIterator();
|
||||
if (auto *II = dyn_cast<InvokeInst>(I))
|
||||
IP = II->getNormalDest()->begin();
|
||||
@ -114,6 +115,25 @@ SCEVExpander::findInsertPointAfter(Instruction *I, Instruction *MustDominate) {
|
||||
return IP;
|
||||
}
|
||||
|
||||
BasicBlock::iterator
|
||||
SCEVExpander::GetOptimalInsertionPointForCastOf(Value *V) const {
|
||||
// Cast the argument at the beginning of the entry block, after
|
||||
// any bitcasts of other arguments.
|
||||
if (Argument *A = dyn_cast<Argument>(V)) {
|
||||
BasicBlock::iterator IP = A->getParent()->getEntryBlock().begin();
|
||||
while ((isa<BitCastInst>(IP) &&
|
||||
isa<Argument>(cast<BitCastInst>(IP)->getOperand(0)) &&
|
||||
cast<BitCastInst>(IP)->getOperand(0) != A) ||
|
||||
isa<DbgInfoIntrinsic>(IP))
|
||||
++IP;
|
||||
return IP;
|
||||
}
|
||||
|
||||
// Cast the instruction immediately after the instruction.
|
||||
Instruction *I = cast<Instruction>(V);
|
||||
return findInsertPointAfter(I, &*Builder.GetInsertPoint());
|
||||
}
|
||||
|
||||
/// InsertNoopCastOfTo - Insert a cast of V to the specified type,
|
||||
/// which must be possible with a noop cast, doing what we can to share
|
||||
/// the casts.
|
||||
@ -172,22 +192,8 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
|
||||
if (Constant *C = dyn_cast<Constant>(V))
|
||||
return ConstantExpr::getCast(Op, C, Ty);
|
||||
|
||||
// Cast the argument at the beginning of the entry block, after
|
||||
// any bitcasts of other arguments.
|
||||
if (Argument *A = dyn_cast<Argument>(V)) {
|
||||
BasicBlock::iterator IP = A->getParent()->getEntryBlock().begin();
|
||||
while ((isa<BitCastInst>(IP) &&
|
||||
isa<Argument>(cast<BitCastInst>(IP)->getOperand(0)) &&
|
||||
cast<BitCastInst>(IP)->getOperand(0) != A) ||
|
||||
isa<DbgInfoIntrinsic>(IP))
|
||||
++IP;
|
||||
return ReuseOrCreateCast(A, Ty, Op, IP);
|
||||
}
|
||||
|
||||
// Cast the instruction immediately after the instruction.
|
||||
Instruction *I = cast<Instruction>(V);
|
||||
BasicBlock::iterator IP = findInsertPointAfter(I, &*Builder.GetInsertPoint());
|
||||
return ReuseOrCreateCast(I, Ty, Op, IP);
|
||||
// Try to reuse existing cast, or insert one.
|
||||
return ReuseOrCreateCast(V, Ty, Op, GetOptimalInsertionPointForCastOf(V));
|
||||
}
|
||||
|
||||
/// InsertBinop - Insert the specified binary operator, doing a small amount
|
||||
|
Loading…
Reference in New Issue
Block a user