forked from OSchip/llvm-project
Refactor replaceDominatedUsesWith to have a flag to control whether to replace uses in BB itself.
Summary: This is in preparation for LoopSink pass which calls replaceDominatedUsesWith to update after sinking. Reviewers: chandlerc, davidxl, danielcdh Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D24170 llvm-svn: 280427
This commit is contained in:
parent
3087b2cf2b
commit
ddd0c125e3
|
@ -326,10 +326,12 @@ void combineMetadataForCSE(Instruction *K, const Instruction *J);
|
||||||
/// the given edge. Returns the number of replacements made.
|
/// the given edge. Returns the number of replacements made.
|
||||||
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
||||||
const BasicBlockEdge &Edge);
|
const BasicBlockEdge &Edge);
|
||||||
|
|
||||||
/// Replace each use of 'From' with 'To' if that use is dominated by
|
/// Replace each use of 'From' with 'To' if that use is dominated by
|
||||||
/// the end of the given BasicBlock. Returns the number of replacements made.
|
/// the end of 'BB'. Returns the number of replacements made.
|
||||||
|
/// Replace use of 'From' with 'To' in 'BB' if 'IncludeSelf' is true.
|
||||||
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
||||||
const BasicBlock *BB);
|
const BasicBlock *BB, bool IncludeSelf);
|
||||||
|
|
||||||
|
|
||||||
/// Return true if the CallSite CS calls a gc leaf function.
|
/// Return true if the CallSite CS calls a gc leaf function.
|
||||||
|
|
|
@ -1962,7 +1962,7 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, const BasicBlockEdge &Root,
|
||||||
unsigned NumReplacements =
|
unsigned NumReplacements =
|
||||||
DominatesByEdge
|
DominatesByEdge
|
||||||
? replaceDominatedUsesWith(LHS, RHS, *DT, Root)
|
? replaceDominatedUsesWith(LHS, RHS, *DT, Root)
|
||||||
: replaceDominatedUsesWith(LHS, RHS, *DT, Root.getStart());
|
: replaceDominatedUsesWith(LHS, RHS, *DT, Root.getStart(), false);
|
||||||
|
|
||||||
Changed |= NumReplacements > 0;
|
Changed |= NumReplacements > 0;
|
||||||
NumGVNEqProp += NumReplacements;
|
NumGVNEqProp += NumReplacements;
|
||||||
|
@ -2038,7 +2038,7 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, const BasicBlockEdge &Root,
|
||||||
DominatesByEdge
|
DominatesByEdge
|
||||||
? replaceDominatedUsesWith(NotCmp, NotVal, *DT, Root)
|
? replaceDominatedUsesWith(NotCmp, NotVal, *DT, Root)
|
||||||
: replaceDominatedUsesWith(NotCmp, NotVal, *DT,
|
: replaceDominatedUsesWith(NotCmp, NotVal, *DT,
|
||||||
Root.getStart());
|
Root.getStart(), false);
|
||||||
Changed |= NumReplacements > 0;
|
Changed |= NumReplacements > 0;
|
||||||
NumGVNEqProp += NumReplacements;
|
NumGVNEqProp += NumReplacements;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1679,7 +1679,8 @@ unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||||
|
|
||||||
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||||
DominatorTree &DT,
|
DominatorTree &DT,
|
||||||
const BasicBlock *BB) {
|
const BasicBlock *BB,
|
||||||
|
bool IncludeSelf) {
|
||||||
assert(From->getType() == To->getType());
|
assert(From->getType() == To->getType());
|
||||||
|
|
||||||
unsigned Count = 0;
|
unsigned Count = 0;
|
||||||
|
@ -1687,7 +1688,8 @@ unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||||
UI != UE;) {
|
UI != UE;) {
|
||||||
Use &U = *UI++;
|
Use &U = *UI++;
|
||||||
auto *I = cast<Instruction>(U.getUser());
|
auto *I = cast<Instruction>(U.getUser());
|
||||||
if (DT.properlyDominates(BB, I->getParent())) {
|
if ((IncludeSelf && BB == I->getParent()) ||
|
||||||
|
DT.properlyDominates(BB, I->getParent())) {
|
||||||
U.set(To);
|
U.set(To);
|
||||||
DEBUG(dbgs() << "Replace dominated use of '" << From->getName() << "' as "
|
DEBUG(dbgs() << "Replace dominated use of '" << From->getName() << "' as "
|
||||||
<< *To << " in " << *U << "\n");
|
<< *To << " in " << *U << "\n");
|
||||||
|
|
Loading…
Reference in New Issue