[llvm] [AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (PR #94647)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 19:47:50 PDT 2024


================
@@ -677,6 +693,33 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
     return !A.checkForAllCallLikeInstructions(DoesNotRetrieve, *this,
                                               UsedAssumedInformation);
   }
+
+  // Returns true if FlatScratchInit is needed, i.e., no-flat-scratch-init is
+  // not to be set.
+  bool needFlatScratchInit(Attributor &A) {
+    // This is called on each callee; false means callee shouldn't have
+    // no-flat-scratch-init.
+    auto CheckForNoFlatScratchInit = [&](Instruction &I) {
+      const auto &CB = cast<CallBase>(I);
+      const Value *CalleeOp = CB.getCalledOperand();
+      const Function *Callee = dyn_cast<Function>(CalleeOp);
+      if (!Callee) // indirect call
+        return CB.isInlineAsm();
----------------
jdoerfert wrote:

You should replace all this handling, starting from here till the end of this lambda, with a call to 
```
 /// Check \p Pred on all potential Callees of \p CB.
  ///
  /// This method will evaluate \p Pred with all potential callees of \p CB as
  /// input and return true if \p Pred does. If some callees might be unknown
  /// this function will return false.
  bool checkForAllCallees(
      function_ref<bool(ArrayRef<const Function *> Callees)> Pred,
      const AbstractAttribute &QueryingAA, const CallBase &CB);
```
This will work for indirect calls as well.

https://github.com/llvm/llvm-project/pull/94647


More information about the llvm-commits mailing list