llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Shilei Tian (shiltian)

<details>
<summary>Changes</summary>

AAAMDGPUMinAGPRAlloc and AAAMDGPUNoLDSDMA asked for a call site AACallEdges for
every call that is not an intrinsic, only to get its callees. For a direct call
whose callee has no callback metadata, that callee is the only one, so use it
directly, like AACallEdgesFunction does since #<!-- -->232616. Calls to 
callback brokers
still use AACallEdges, because thebroker also calls the callback target.

On a generated module with 2,001 functions and 15,986 calls,
-passes=amdgpu-attributor creates 2,001 instead of 11,987 abstract attributes,
and the median wall time goes from 95 ms to 84 ms.

This PR was assisted by AI but I reviewed all the changes.


---
Full diff: https://github.com/llvm/llvm-project/pull/237633.diff


1 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+36-27) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index c9068c7a3766cd..f149ce8d377b60 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1307,6 +1307,26 @@ static unsigned inlineAsmGetNumRequiredAGPRs(const 
InlineAsm *IA,
   return std::min(MaxVirtReg + MaxPhysReg, 256u);
 }
 
+/// Call \p Pred on each function that \p CB may call. Return false if a callee
+/// is unknown, or if \p Pred returns false for a callee.
+static bool
+checkForAllPossibleCallees(Attributor &A, const AbstractAttribute &QueryingAA,
+                           const CallBase &CB,
+                           function_ref<bool(const Function &)> Pred) {
+  // A direct call without callbacks only calls its callee, so it does not need
+  // a call site AACallEdges.
+  auto *Callee = dyn_cast<Function>(CB.getCalledOperand());
+  if (Callee && !Callee->hasMetadata(LLVMContext::MD_callback))
+    return Pred(*Callee);
+
+  const AACallEdges *CBEdges = A.getAAFor<AACallEdges>(
+      QueryingAA, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
+  if (!CBEdges || CBEdges->hasUnknownCallee())
+    return false;
+  return all_of(CBEdges->getOptimisticEdges(),
+                [&](const Function *Fn) { return Pred(*Fn); });
+}
+
 struct AAAMDGPUMinAGPRAlloc
     : public StateWrapper<DecIntegerState<>, AbstractAttribute> {
   using Base = StateWrapper<DecIntegerState<>, AbstractAttribute>;
@@ -1398,22 +1418,18 @@ struct AAAMDGPUMinAGPRAlloc
       }
 
       // TODO: Handle callsite attributes
-      auto *CBEdges = A.getAAFor<AACallEdges>(
-          *this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
-      if (!CBEdges || CBEdges->hasUnknownCallee()) {
-        Maximum.indicatePessimisticFixpoint();
-        return false;
-      }
-
-      for (const Function *PossibleCallee : CBEdges->getOptimisticEdges()) {
-        const auto *CalleeInfo = A.getAAFor<AAAMDGPUMinAGPRAlloc>(
-            *this, IRPosition::function(*PossibleCallee), 
DepClassTy::REQUIRED);
-        if (!CalleeInfo || !CalleeInfo->isValidState()) {
-          Maximum.indicatePessimisticFixpoint();
+      auto CheckCallee = [&](const Function &Callee) {
+        const AAAMDGPUMinAGPRAlloc *CalleeInfo =
+            A.getAAFor<AAAMDGPUMinAGPRAlloc>(
+                *this, IRPosition::function(Callee), DepClassTy::REQUIRED);
+        if (!CalleeInfo || !CalleeInfo->isValidState())
           return false;
-        }
-
         Maximum.takeAssumedMaximum(CalleeInfo->getAssumed());
+        return true;
+      };
+      if (!checkForAllPossibleCallees(A, *this, CB, CheckCallee)) {
+        Maximum.indicatePessimisticFixpoint();
+        return false;
       }
 
       return true;
@@ -1492,19 +1508,12 @@ struct AAAMDGPUNoLDSDMA : public 
StateWrapper<BooleanState, AbstractAttribute> {
                CB.hasFnAttr(Attribute::NoCallback);
       }
 
-      const auto *CBEdges = A.getAAFor<AACallEdges>(
-          *this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
-      if (!CBEdges || CBEdges->hasUnknownCallee())
-        return false;
-
-      for (const Function *PossibleCallee : CBEdges->getOptimisticEdges()) {
-        const auto *CalleeInfo = A.getAAFor<AAAMDGPUNoLDSDMA>(
-            *this, IRPosition::function(*PossibleCallee), 
DepClassTy::REQUIRED);
-        if (!CalleeInfo || !CalleeInfo->getAssumed())
-          return false;
-      }
-
-      return true;
+      return checkForAllPossibleCallees(
+          A, *this, CB, [&](const Function &Callee) {
+            const AAAMDGPUNoLDSDMA *CalleeInfo = A.getAAFor<AAAMDGPUNoLDSDMA>(
+                *this, IRPosition::function(Callee), DepClassTy::REQUIRED);
+            return CalleeInfo && CalleeInfo->getAssumed();
+          });
     };
 
     bool UsedAssumedInformation = false;

``````````

</details>


https://github.com/llvm/llvm-project/pull/237633
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to