forked from OSchip/llvm-project
NFC: refactor replaceDominatedUsesWith
Summary: Since I will post patch with some changes to replaceDominatedUsesWith, it would be good to avoid duplicating code again. Reviewers: davide, dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32798 llvm-svn: 302575
This commit is contained in:
parent
15fa44698c
commit
d979c1f806
|
@ -1781,46 +1781,45 @@ void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J) {
|
|||
combineMetadata(K, J, KnownIDs);
|
||||
}
|
||||
|
||||
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||
DominatorTree &DT,
|
||||
const BasicBlockEdge &Root) {
|
||||
assert(From->getType() == To->getType());
|
||||
|
||||
unsigned Count = 0;
|
||||
for (Value::use_iterator UI = From->use_begin(), UE = From->use_end();
|
||||
UI != UE; ) {
|
||||
Use &U = *UI++;
|
||||
if (DT.dominates(Root, U)) {
|
||||
U.set(To);
|
||||
DEBUG(dbgs() << "Replace dominated use of '"
|
||||
<< From->getName() << "' as "
|
||||
<< *To << " in " << *U << "\n");
|
||||
++Count;
|
||||
}
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
|
||||
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||
DominatorTree &DT,
|
||||
const BasicBlock *BB) {
|
||||
template <typename RootType, typename DominatesFn>
|
||||
static unsigned replaceDominatedUsesWith(Value *From, Value *To,
|
||||
const RootType &Root,
|
||||
const DominatesFn &Dominates) {
|
||||
assert(From->getType() == To->getType());
|
||||
|
||||
unsigned Count = 0;
|
||||
for (Value::use_iterator UI = From->use_begin(), UE = From->use_end();
|
||||
UI != UE;) {
|
||||
Use &U = *UI++;
|
||||
auto *I = cast<Instruction>(U.getUser());
|
||||
if (DT.properlyDominates(BB, I->getParent())) {
|
||||
U.set(To);
|
||||
DEBUG(dbgs() << "Replace dominated use of '" << From->getName() << "' as "
|
||||
<< *To << " in " << *U << "\n");
|
||||
++Count;
|
||||
}
|
||||
if (!Dominates(Root, U))
|
||||
continue;
|
||||
U.set(To);
|
||||
DEBUG(dbgs() << "Replace dominated use of '" << From->getName() << "' as "
|
||||
<< *To << " in " << *U << "\n");
|
||||
++Count;
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
|
||||
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||
DominatorTree &DT,
|
||||
const BasicBlockEdge &Root) {
|
||||
auto Dominates = [&DT](const BasicBlockEdge &Root, const Use &U) {
|
||||
return DT.dominates(Root, U);
|
||||
};
|
||||
return ::replaceDominatedUsesWith(From, To, Root, Dominates);
|
||||
}
|
||||
|
||||
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
|
||||
DominatorTree &DT,
|
||||
const BasicBlock *BB) {
|
||||
auto ProperlyDominates = [&DT](const BasicBlock *BB, const Use &U) {
|
||||
auto *I = cast<Instruction>(U.getUser())->getParent();
|
||||
return DT.properlyDominates(BB, I);
|
||||
};
|
||||
return ::replaceDominatedUsesWith(From, To, BB, ProperlyDominates);
|
||||
}
|
||||
|
||||
bool llvm::callsGCLeafFunction(ImmutableCallSite CS) {
|
||||
// Check if the function is specifically marked as a gc leaf function.
|
||||
if (CS.hasFnAttr("gc-leaf-function"))
|
||||
|
|
Loading…
Reference in New Issue