[llvm] 1fc1827 - [NFC] PHITransAddr refactoring - return translated value directly or nullptr on
Sergey Kachkov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 3 01:09:29 PST 2023
Author: Sergey Kachkov
Date: 2023-02-03T12:08:45+03:00
New Revision: 1fc18272e6091ef9fb47661744b35ddc06782d0d
URL: https://github.com/llvm/llvm-project/commit/1fc18272e6091ef9fb47661744b35ddc06782d0d
DIFF: https://github.com/llvm/llvm-project/commit/1fc18272e6091ef9fb47661744b35ddc06782d0d.diff
LOG: [NFC] PHITransAddr refactoring - return translated value directly or nullptr on
failure (instead of bool flag)
Differential Revision: https://reviews.llvm.org/D143171
Added:
Modified:
llvm/include/llvm/Analysis/MemorySSA.h
llvm/include/llvm/Analysis/PHITransAddr.h
llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/lib/Analysis/PHITransAddr.cpp
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h
index 68e2dc80a12f4..7038b663c3ab0 100644
--- a/llvm/include/llvm/Analysis/MemorySSA.h
+++ b/llvm/include/llvm/Analysis/MemorySSA.h
@@ -1272,11 +1272,11 @@ class upward_defs_iterator
const_cast<Value *>(Location.Ptr),
OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr);
- if (!Translator.translateValue(OriginalAccess->getBlock(),
- DefIterator.getPhiArgBlock(), DT, true))
- if (Translator.getAddr() != CurrentPair.second.Ptr)
- CurrentPair.second =
- CurrentPair.second.getWithNewPtr(Translator.getAddr());
+ if (Value *Addr =
+ Translator.translateValue(OriginalAccess->getBlock(),
+ DefIterator.getPhiArgBlock(), DT, true))
+ if (Addr != CurrentPair.second.Ptr)
+ CurrentPair.second = CurrentPair.second.getWithNewPtr(Addr);
// Mark size as unknown, if the location is not guaranteed to be
// loop-invariant for any possible loop in the function. Setting the size
diff --git a/llvm/include/llvm/Analysis/PHITransAddr.h b/llvm/include/llvm/Analysis/PHITransAddr.h
index ec6dbb227af77..2cca2e1b93d46 100644
--- a/llvm/include/llvm/Analysis/PHITransAddr.h
+++ b/llvm/include/llvm/Analysis/PHITransAddr.h
@@ -76,10 +76,9 @@ class PHITransAddr {
/// translateValue - PHI translate the current address up the CFG from
/// CurBB to Pred, updating our state to reflect any needed changes. If
- /// 'MustDominate' is true, the translated value must dominate
- /// PredBB. This returns true on failure and sets Addr to null.
- bool translateValue(BasicBlock *CurBB, BasicBlock *PredBB,
- const DominatorTree *DT, bool MustDominate);
+ /// 'MustDominate' is true, the translated value must dominate PredBB.
+ Value *translateValue(BasicBlock *CurBB, BasicBlock *PredBB,
+ const DominatorTree *DT, bool MustDominate);
/// translateWithInsertion - PHI translate this value into the specified
/// predecessor block, inserting a computation of the value if it is
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index aeed5a0e66e97..071ecdba8a54a 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -1298,8 +1298,8 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
// Get the PHI translated pointer in this predecessor. This can fail if
// not translatable, in which case the getAddr() returns null.
PHITransAddr &PredPointer = PredList.back().second;
- PredPointer.translateValue(BB, Pred, &DT, /*MustDominate=*/false);
- Value *PredPtrVal = PredPointer.getAddr();
+ Value *PredPtrVal =
+ PredPointer.translateValue(BB, Pred, &DT, /*MustDominate=*/false);
// Check to see if we have already visited this pred block with another
// pointer. If so, we can't do this lookup. This failure can occur
diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp
index 1c3e55b47f045..70a5aa6ba298d 100644
--- a/llvm/lib/Analysis/PHITransAddr.cpp
+++ b/llvm/lib/Analysis/PHITransAddr.cpp
@@ -305,10 +305,10 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB,
/// PHITranslateValue - PHI translate the current address up the CFG from
/// CurBB to Pred, updating our state to reflect any needed changes. If
-/// 'MustDominate' is true, the translated value must dominate
-/// PredBB. This returns true on failure and sets Addr to null.
-bool PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB,
- const DominatorTree *DT, bool MustDominate) {
+/// 'MustDominate' is true, the translated value must dominate PredBB.
+Value *PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB,
+ const DominatorTree *DT,
+ bool MustDominate) {
assert(DT || !MustDominate);
assert(verify() && "Invalid PHITransAddr!");
if (DT && DT->isReachableFromEntry(PredBB))
@@ -323,7 +323,7 @@ bool PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB,
if (!DT->dominates(Inst->getParent(), PredBB))
Addr = nullptr;
- return Addr == nullptr;
+ return Addr;
}
/// PHITranslateWithInsertion - PHI translate this value into the specified
@@ -362,8 +362,9 @@ Value *PHITransAddr::insertTranslatedSubExpr(
// See if we have a version of this value already available and dominating
// PredBB. If so, there is no need to insert a new instance of it.
PHITransAddr Tmp(InVal, DL, AC);
- if (!Tmp.translateValue(CurBB, PredBB, &DT, /*MustDominate=*/true))
- return Tmp.getAddr();
+ if (Value *Addr =
+ Tmp.translateValue(CurBB, PredBB, &DT, /*MustDominate=*/true))
+ return Addr;
// We don't need to PHI translate values which aren't instructions.
auto *Inst = dyn_cast<Instruction>(InVal);
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index bff4bcc543039..ceebfd7465efc 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -465,7 +465,7 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI,
if (PredAddr.needsPHITranslationFromBlock(B)) {
if (!PredAddr.isPotentiallyPHITranslatable())
return false;
- if (PredAddr.translateValue(B, Pred, DT, false))
+ if (!PredAddr.translateValue(B, Pred, DT, false))
return false;
}
Value *TranslatedPtr = PredAddr.getAddr();
More information about the llvm-commits
mailing list