[PATCH] D83246: [Attributor] use liveness information from AAIsDead in AAReachability and cache query results

Shinji Okumura via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 11:50:11 PDT 2020


okura created this revision.
okura added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, bbn, kuter, uenoku, hiraditya.
Herald added a reviewer: sstefan1.
Herald added a reviewer: uenoku.
Herald added a reviewer: homerdin.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.

This is the next patch of D76210 <https://reviews.llvm.org/D76210>.
This patch contains two changes.

1. Use assumed liveness from AAIsDead  ... If From instruction is assumed to be dead, return false immediately



2. Cache results ... Made a map in `InformationCache` for caching results.




https://reviews.llvm.org/D83246

Files:
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp


Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -2469,7 +2469,7 @@
         const auto &ReachabilityAA =
             A.getAAFor<AAReachability>(*this, IRPosition::function(*ScopeFn));
 
-        if (!ReachabilityAA.isAssumedReachable(UserI, getCtxI()))
+        if (!ReachabilityAA.isAssumedReachable(UserI, getCtxI(), A))
           return true;
 
         if (auto *CB = dyn_cast<CallBase>(UserI)) {
Index: llvm/include/llvm/Transforms/IPO/Attributor.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Attributor.h
+++ llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -715,6 +715,19 @@
   /// Return the map conaining all the knowledge we have from `llvm.assume`s.
   const RetainedKnowledgeMap &getKnowledgeMap() const { return KnowledgeMap; }
 
+  bool getPotentiallyReachable(const Instruction *From, const Instruction *To) {
+    auto KeyPair = std::make_pair(From, To);
+    auto Iter = PotentiallyReachableMap.find(KeyPair);
+    const Function &F = *From->getFunction();
+    if (Iter != PotentiallyReachableMap.end())
+      return Iter->second;
+    bool Result = isPotentiallyReachable(
+        From, To, nullptr, AG.getAnalysis<DominatorTreeAnalysis>(F),
+        AG.getAnalysis<LoopAnalysis>(F));
+    PotentiallyReachableMap.insert(std::make_pair(KeyPair, Result));
+    return Result;
+  }
+
 private:
   struct FunctionInfo {
     ~FunctionInfo();
@@ -774,6 +787,9 @@
   /// Set of inlineable functions
   SmallPtrSet<const Function *, 8> InlineableFunctions;
 
+  DenseMap<std::pair<const Instruction *, const Instruction *>, bool>
+      PotentiallyReachableMap;
+
   /// Give the Attributor access to the members so
   /// Attributor::identifyDefaultAbstractAttributes(...) can initialize them.
   friend struct Attributor;
@@ -2291,16 +2307,21 @@
   /// Returns true if 'From' instruction is assumed to reach, 'To' instruction.
   /// Users should provide two positions they are interested in, and the class
   /// determines (and caches) reachability.
-  bool isAssumedReachable(const Instruction *From,
-                          const Instruction *To) const {
-    return isPotentiallyReachable(From, To);
+  bool isAssumedReachable(const Instruction *From, const Instruction *To,
+                          Attributor &A) const {
+    const auto &LivenessAA =
+        A.getAAFor<AAIsDead>(*this, IRPosition::value(*From));
+    if (A.isAssumedDead(*From, this, &LivenessAA))
+      return false;
+    return A.getInfoCache().getPotentiallyReachable(From, To);
   }
 
   /// Returns true if 'From' instruction is known to reach, 'To' instruction.
   /// Users should provide two positions they are interested in, and the class
   /// determines (and caches) reachability.
-  bool isKnownReachable(const Instruction *From, const Instruction *To) const {
-    return isPotentiallyReachable(From, To);
+  bool isKnownReachable(const Instruction *From, const Instruction *To,
+                        Attributor &A) const {
+    return A.getInfoCache().getPotentiallyReachable(From, To);
   }
 
   /// Create an abstract attribute view for the position \p IRP.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83246.275776.patch
Type: text/x-patch
Size: 3325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200706/8aa854d0/attachment.bin>


More information about the llvm-commits mailing list