forked from OSchip/llvm-project
IVUsers no longer needs to record the phis.
llvm-svn: 133518
This commit is contained in:
parent
f6474fd5f3
commit
fc4ccb20c6
|
@ -37,8 +37,8 @@ class TargetData;
|
||||||
class IVStrideUse : public CallbackVH, public ilist_node<IVStrideUse> {
|
class IVStrideUse : public CallbackVH, public ilist_node<IVStrideUse> {
|
||||||
friend class IVUsers;
|
friend class IVUsers;
|
||||||
public:
|
public:
|
||||||
IVStrideUse(IVUsers *P, Instruction* U, Value *O, Value *PN)
|
IVStrideUse(IVUsers *P, Instruction* U, Value *O)
|
||||||
: CallbackVH(U), Parent(P), OperandValToReplace(O), Phi(PN) {
|
: CallbackVH(U), Parent(P), OperandValToReplace(O) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getUser - Return the user instruction for this use.
|
/// getUser - Return the user instruction for this use.
|
||||||
|
@ -51,11 +51,6 @@ public:
|
||||||
setValPtr(NewUser);
|
setValPtr(NewUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getPhi - Return the phi node that represents this IV.
|
|
||||||
PHINode *getPhi() const {
|
|
||||||
return cast<PHINode>(Phi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getOperandValToReplace - Return the Value of the operand in the user
|
/// getOperandValToReplace - Return the Value of the operand in the user
|
||||||
/// instruction that this IVStrideUse is representing.
|
/// instruction that this IVStrideUse is representing.
|
||||||
Value *getOperandValToReplace() const {
|
Value *getOperandValToReplace() const {
|
||||||
|
@ -86,9 +81,6 @@ private:
|
||||||
/// that this IVStrideUse is representing.
|
/// that this IVStrideUse is representing.
|
||||||
WeakVH OperandValToReplace;
|
WeakVH OperandValToReplace;
|
||||||
|
|
||||||
/// Phi - The loop header phi that represents this IV.
|
|
||||||
WeakVH Phi;
|
|
||||||
|
|
||||||
/// PostIncLoops - The set of loops for which Expr has been adjusted to
|
/// PostIncLoops - The set of loops for which Expr has been adjusted to
|
||||||
/// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
|
/// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
|
||||||
PostIncLoopSet PostIncLoops;
|
PostIncLoopSet PostIncLoops;
|
||||||
|
@ -151,9 +143,9 @@ public:
|
||||||
/// AddUsersIfInteresting - Inspect the specified Instruction. If it is a
|
/// AddUsersIfInteresting - Inspect the specified Instruction. If it is a
|
||||||
/// reducible SCEV, recursively add its users to the IVUsesByStride set and
|
/// reducible SCEV, recursively add its users to the IVUsesByStride set and
|
||||||
/// return true. Otherwise, return false.
|
/// return true. Otherwise, return false.
|
||||||
bool AddUsersIfInteresting(Instruction *I, PHINode *Phi);
|
bool AddUsersIfInteresting(Instruction *I);
|
||||||
|
|
||||||
IVStrideUse &AddUser(Instruction *User, Value *Operand, PHINode *Phi);
|
IVStrideUse &AddUser(Instruction *User, Value *Operand);
|
||||||
|
|
||||||
/// getReplacementExpr - Return a SCEV expression which computes the
|
/// getReplacementExpr - Return a SCEV expression which computes the
|
||||||
/// value of the OperandValToReplace of the given IVStrideUse.
|
/// value of the OperandValToReplace of the given IVStrideUse.
|
||||||
|
|
|
@ -89,7 +89,7 @@ static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L,
|
||||||
/// AddUsersIfInteresting - Inspect the specified instruction. If it is a
|
/// AddUsersIfInteresting - Inspect the specified instruction. If it is a
|
||||||
/// reducible SCEV, recursively add its users to the IVUsesByStride set and
|
/// reducible SCEV, recursively add its users to the IVUsesByStride set and
|
||||||
/// return true. Otherwise, return false.
|
/// return true. Otherwise, return false.
|
||||||
bool IVUsers::AddUsersIfInteresting(Instruction *I, PHINode *Phi) {
|
bool IVUsers::AddUsersIfInteresting(Instruction *I) {
|
||||||
if (!SE->isSCEVable(I->getType()))
|
if (!SE->isSCEVable(I->getType()))
|
||||||
return false; // Void and FP expressions cannot be reduced.
|
return false; // Void and FP expressions cannot be reduced.
|
||||||
|
|
||||||
|
@ -136,13 +136,12 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I, PHINode *Phi) {
|
||||||
bool AddUserToIVUsers = false;
|
bool AddUserToIVUsers = false;
|
||||||
if (LI->getLoopFor(User->getParent()) != L) {
|
if (LI->getLoopFor(User->getParent()) != L) {
|
||||||
if (isa<PHINode>(User) || Processed.count(User) ||
|
if (isa<PHINode>(User) || Processed.count(User) ||
|
||||||
!AddUsersIfInteresting(User, Phi)) {
|
!AddUsersIfInteresting(User)) {
|
||||||
DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
|
DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
|
||||||
<< " OF SCEV: " << *ISE << '\n');
|
<< " OF SCEV: " << *ISE << '\n');
|
||||||
AddUserToIVUsers = true;
|
AddUserToIVUsers = true;
|
||||||
}
|
}
|
||||||
} else if (Processed.count(User) ||
|
} else if (Processed.count(User) || !AddUsersIfInteresting(User)) {
|
||||||
!AddUsersIfInteresting(User, Phi)) {
|
|
||||||
DEBUG(dbgs() << "FOUND USER: " << *User << '\n'
|
DEBUG(dbgs() << "FOUND USER: " << *User << '\n'
|
||||||
<< " OF SCEV: " << *ISE << '\n');
|
<< " OF SCEV: " << *ISE << '\n');
|
||||||
AddUserToIVUsers = true;
|
AddUserToIVUsers = true;
|
||||||
|
@ -150,7 +149,7 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I, PHINode *Phi) {
|
||||||
|
|
||||||
if (AddUserToIVUsers) {
|
if (AddUserToIVUsers) {
|
||||||
// Okay, we found a user that we cannot reduce.
|
// Okay, we found a user that we cannot reduce.
|
||||||
IVUses.push_back(new IVStrideUse(this, User, I, Phi));
|
IVUses.push_back(new IVStrideUse(this, User, I));
|
||||||
IVStrideUse &NewUse = IVUses.back();
|
IVStrideUse &NewUse = IVUses.back();
|
||||||
// Autodetect the post-inc loop set, populating NewUse.PostIncLoops.
|
// Autodetect the post-inc loop set, populating NewUse.PostIncLoops.
|
||||||
// The regular return value here is discarded; instead of recording
|
// The regular return value here is discarded; instead of recording
|
||||||
|
@ -165,8 +164,8 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I, PHINode *Phi) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IVStrideUse &IVUsers::AddUser(Instruction *User, Value *Operand, PHINode *Phi) {
|
IVStrideUse &IVUsers::AddUser(Instruction *User, Value *Operand) {
|
||||||
IVUses.push_back(new IVStrideUse(this, User, Operand, Phi));
|
IVUses.push_back(new IVStrideUse(this, User, Operand));
|
||||||
return IVUses.back();
|
return IVUses.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +193,7 @@ bool IVUsers::runOnLoop(Loop *l, LPPassManager &LPM) {
|
||||||
// them by stride. Start by finding all of the PHI nodes in the header for
|
// them by stride. Start by finding all of the PHI nodes in the header for
|
||||||
// this loop. If they are induction variables, inspect their uses.
|
// this loop. If they are induction variables, inspect their uses.
|
||||||
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I)
|
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I)
|
||||||
(void)AddUsersIfInteresting(I, cast<PHINode>(I));
|
(void)AddUsersIfInteresting(I);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,7 @@ namespace {
|
||||||
void EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand);
|
void EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand);
|
||||||
void EliminateIVRemainder(BinaryOperator *Rem,
|
void EliminateIVRemainder(BinaryOperator *Rem,
|
||||||
Value *IVOperand,
|
Value *IVOperand,
|
||||||
bool IsSigned,
|
bool IsSigned);
|
||||||
PHINode *IVPhi);
|
|
||||||
void pushIVUsers(Instruction *Def);
|
void pushIVUsers(Instruction *Def);
|
||||||
bool isSimpleIVUser(Instruction *I, const Loop *L);
|
bool isSimpleIVUser(Instruction *I, const Loop *L);
|
||||||
void RewriteNonIntegerIVs(Loop *L);
|
void RewriteNonIntegerIVs(Loop *L);
|
||||||
|
@ -523,7 +522,7 @@ void IndVarSimplify::SimplifyIVUsers(SCEVExpander &Rewriter) {
|
||||||
if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
|
if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
|
||||||
bool IsSigned = Rem->getOpcode() == Instruction::SRem;
|
bool IsSigned = Rem->getOpcode() == Instruction::SRem;
|
||||||
if (IsSigned || Rem->getOpcode() == Instruction::URem) {
|
if (IsSigned || Rem->getOpcode() == Instruction::URem) {
|
||||||
EliminateIVRemainder(Rem, IVOperand, IsSigned, I->getPhi());
|
EliminateIVRemainder(Rem, IVOperand, IsSigned);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -946,8 +945,7 @@ void IndVarSimplify::EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) {
|
||||||
|
|
||||||
void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
|
void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
|
||||||
Value *IVOperand,
|
Value *IVOperand,
|
||||||
bool IsSigned,
|
bool IsSigned) {
|
||||||
PHINode *IVPhi) {
|
|
||||||
// We're only interested in the case where we know something about
|
// We're only interested in the case where we know something about
|
||||||
// the numerator.
|
// the numerator.
|
||||||
if (IVOperand != Rem->getOperand(0))
|
if (IVOperand != Rem->getOperand(0))
|
||||||
|
@ -992,7 +990,7 @@ void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
|
||||||
// Inform IVUsers about the new users.
|
// Inform IVUsers about the new users.
|
||||||
if (IU) {
|
if (IU) {
|
||||||
if (Instruction *I = dyn_cast<Instruction>(Rem->getOperand(0)))
|
if (Instruction *I = dyn_cast<Instruction>(Rem->getOperand(0)))
|
||||||
IU->AddUsersIfInteresting(I, IVPhi);
|
IU->AddUsersIfInteresting(I);
|
||||||
}
|
}
|
||||||
DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n');
|
DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n');
|
||||||
++NumElimRem;
|
++NumElimRem;
|
||||||
|
@ -1011,7 +1009,7 @@ bool IndVarSimplify::EliminateIVUser(Instruction *UseInst,
|
||||||
if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
|
if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
|
||||||
bool IsSigned = Rem->getOpcode() == Instruction::SRem;
|
bool IsSigned = Rem->getOpcode() == Instruction::SRem;
|
||||||
if (IsSigned || Rem->getOpcode() == Instruction::URem) {
|
if (IsSigned || Rem->getOpcode() == Instruction::URem) {
|
||||||
EliminateIVRemainder(Rem, IVOperand, IsSigned, CurrIV);
|
EliminateIVRemainder(Rem, IVOperand, IsSigned);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1283,8 +1281,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
// For completeness, inform IVUsers of the IV use in the newly-created
|
// For completeness, inform IVUsers of the IV use in the newly-created
|
||||||
// loop exit test instruction.
|
// loop exit test instruction.
|
||||||
if (NewICmp && IU)
|
if (NewICmp && IU)
|
||||||
IU->AddUsersIfInteresting(cast<Instruction>(NewICmp->getOperand(0)),
|
IU->AddUsersIfInteresting(cast<Instruction>(NewICmp->getOperand(0)));
|
||||||
IndVar);
|
|
||||||
|
|
||||||
// Clean up dead instructions.
|
// Clean up dead instructions.
|
||||||
Changed |= DeleteDeadPHIs(L->getHeader());
|
Changed |= DeleteDeadPHIs(L->getHeader());
|
||||||
|
@ -1716,5 +1713,5 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PN) {
|
||||||
|
|
||||||
// Add a new IVUsers entry for the newly-created integer PHI.
|
// Add a new IVUsers entry for the newly-created integer PHI.
|
||||||
if (IU)
|
if (IU)
|
||||||
IU->AddUsersIfInteresting(NewPHI, NewPHI);
|
IU->AddUsersIfInteresting(NewPHI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1804,8 +1804,7 @@ LSRInstance::OptimizeLoopTermCond() {
|
||||||
ExitingBlock->getInstList().insert(TermBr, Cond);
|
ExitingBlock->getInstList().insert(TermBr, Cond);
|
||||||
|
|
||||||
// Clone the IVUse, as the old use still exists!
|
// Clone the IVUse, as the old use still exists!
|
||||||
CondUse = &IU.AddUser(Cond, CondUse->getOperandValToReplace(),
|
CondUse = &IU.AddUser(Cond, CondUse->getOperandValToReplace());
|
||||||
CondUse->getPhi());
|
|
||||||
TermBr->replaceUsesOfWith(OldCond, Cond);
|
TermBr->replaceUsesOfWith(OldCond, Cond);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue