mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-22 23:24:59 +00:00
Refactor rewriting for PHI nodes into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96382 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1188,6 +1188,13 @@ public:
|
|||||||
SCEVExpander &Rewriter,
|
SCEVExpander &Rewriter,
|
||||||
SmallVectorImpl<WeakVH> &DeadInsts,
|
SmallVectorImpl<WeakVH> &DeadInsts,
|
||||||
ScalarEvolution &SE, DominatorTree &DT) const;
|
ScalarEvolution &SE, DominatorTree &DT) const;
|
||||||
|
void RewriteForPHI(PHINode *PN, const LSRFixup &LF,
|
||||||
|
const Formula &F,
|
||||||
|
Loop *L, Instruction *IVIncInsertPos,
|
||||||
|
SCEVExpander &Rewriter,
|
||||||
|
SmallVectorImpl<WeakVH> &DeadInsts,
|
||||||
|
ScalarEvolution &SE, DominatorTree &DT,
|
||||||
|
Pass *P) const;
|
||||||
void Rewrite(const LSRFixup &LF,
|
void Rewrite(const LSRFixup &LF,
|
||||||
const Formula &F,
|
const Formula &F,
|
||||||
Loop *L, Instruction *IVIncInsertPos,
|
Loop *L, Instruction *IVIncInsertPos,
|
||||||
@@ -2921,21 +2928,17 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
|
|||||||
return FullV;
|
return FullV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rewrite - Emit instructions for the leading candidate expression for this
|
/// RewriteForPHI - Helper for Rewrite. PHI nodes are special because the use
|
||||||
/// LSRUse (this is called "expanding"), and update the UserInst to reference
|
/// of their operands effectively happens in their predecessor blocks, so the
|
||||||
/// the newly expanded value.
|
/// expression may need to be expanded in multiple places.
|
||||||
void LSRInstance::Rewrite(const LSRFixup &LF,
|
void LSRInstance::RewriteForPHI(PHINode *PN,
|
||||||
|
const LSRFixup &LF,
|
||||||
const Formula &F,
|
const Formula &F,
|
||||||
Loop *L, Instruction *IVIncInsertPos,
|
Loop *L, Instruction *IVIncInsertPos,
|
||||||
SCEVExpander &Rewriter,
|
SCEVExpander &Rewriter,
|
||||||
SmallVectorImpl<WeakVH> &DeadInsts,
|
SmallVectorImpl<WeakVH> &DeadInsts,
|
||||||
ScalarEvolution &SE, DominatorTree &DT,
|
ScalarEvolution &SE, DominatorTree &DT,
|
||||||
Pass *P) const {
|
Pass *P) const {
|
||||||
const Type *OpTy = LF.OperandValToReplace->getType();
|
|
||||||
|
|
||||||
// First, find an insertion point that dominates UserInst. For PHI nodes,
|
|
||||||
// find the nearest block which dominates all the relevant uses.
|
|
||||||
if (PHINode *PN = dyn_cast<PHINode>(LF.UserInst)) {
|
|
||||||
DenseMap<BasicBlock *, Value *> Inserted;
|
DenseMap<BasicBlock *, Value *> Inserted;
|
||||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
||||||
if (PN->getIncomingValue(i) == LF.OperandValToReplace) {
|
if (PN->getIncomingValue(i) == LF.OperandValToReplace) {
|
||||||
@@ -2972,6 +2975,7 @@ void LSRInstance::Rewrite(const LSRFixup &LF,
|
|||||||
Rewriter, DeadInsts, SE, DT);
|
Rewriter, DeadInsts, SE, DT);
|
||||||
|
|
||||||
// If this is reuse-by-noop-cast, insert the noop cast.
|
// If this is reuse-by-noop-cast, insert the noop cast.
|
||||||
|
const Type *OpTy = LF.OperandValToReplace->getType();
|
||||||
if (FullV->getType() != OpTy)
|
if (FullV->getType() != OpTy)
|
||||||
FullV =
|
FullV =
|
||||||
CastInst::Create(CastInst::getCastOpcode(FullV, false,
|
CastInst::Create(CastInst::getCastOpcode(FullV, false,
|
||||||
@@ -2983,11 +2987,28 @@ void LSRInstance::Rewrite(const LSRFixup &LF,
|
|||||||
Pair.first->second = FullV;
|
Pair.first->second = FullV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rewrite - Emit instructions for the leading candidate expression for this
|
||||||
|
/// LSRUse (this is called "expanding"), and update the UserInst to reference
|
||||||
|
/// the newly expanded value.
|
||||||
|
void LSRInstance::Rewrite(const LSRFixup &LF,
|
||||||
|
const Formula &F,
|
||||||
|
Loop *L, Instruction *IVIncInsertPos,
|
||||||
|
SCEVExpander &Rewriter,
|
||||||
|
SmallVectorImpl<WeakVH> &DeadInsts,
|
||||||
|
ScalarEvolution &SE, DominatorTree &DT,
|
||||||
|
Pass *P) const {
|
||||||
|
// First, find an insertion point that dominates UserInst. For PHI nodes,
|
||||||
|
// find the nearest block which dominates all the relevant uses.
|
||||||
|
if (PHINode *PN = dyn_cast<PHINode>(LF.UserInst)) {
|
||||||
|
RewriteForPHI(PN, LF, F, L, IVIncInsertPos, Rewriter, DeadInsts, SE, DT, P);
|
||||||
} else {
|
} else {
|
||||||
Value *FullV = Expand(LF, F, LF.UserInst, L, IVIncInsertPos,
|
Value *FullV = Expand(LF, F, LF.UserInst, L, IVIncInsertPos,
|
||||||
Rewriter, DeadInsts, SE, DT);
|
Rewriter, DeadInsts, SE, DT);
|
||||||
|
|
||||||
// If this is reuse-by-noop-cast, insert the noop cast.
|
// If this is reuse-by-noop-cast, insert the noop cast.
|
||||||
|
const Type *OpTy = LF.OperandValToReplace->getType();
|
||||||
if (FullV->getType() != OpTy) {
|
if (FullV->getType() != OpTy) {
|
||||||
Instruction *Cast =
|
Instruction *Cast =
|
||||||
CastInst::Create(CastInst::getCastOpcode(FullV, false, OpTy, false),
|
CastInst::Create(CastInst::getCastOpcode(FullV, false, OpTy, false),
|
||||||
|
Reference in New Issue
Block a user