[NFC] PHITransAddr refactoring - return translated value directly or nullptr on
authorSergey Kachkov <sergey.kachkov@syntacore.com>
Thu, 2 Feb 2023 12:52:34 +0000 (15:52 +0300)
committerSergey Kachkov <sergey.kachkov@syntacore.com>
Fri, 3 Feb 2023 09:08:45 +0000 (12:08 +0300)
failure (instead of bool flag)

Differential Revision: https://reviews.llvm.org/D143171

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

index 68e2dc8..7038b66 100644 (file)
@@ -1272,11 +1272,11 @@ private:
           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
index ec6dbb2..2cca2e1 100644 (file)
@@ -76,10 +76,9 @@ public:
 
   /// 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
index aeed5a0..071ecdb 100644 (file)
@@ -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
index 1c3e55b..70a5aa6 100644 (file)
@@ -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);
index bff4bcc..ceebfd7 100644 (file)
@@ -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();