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

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 21:56:17 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();
----------------
ssahasra wrote:

> This is backwards. checkForAllCallees's callback takes only the candidate callee function, not the callsite.

Ummm, no it does not? Unless we are looking at different things, it takes a `CallBase`:

```
   1737 bool Attributor::checkForAllCallees(
   1738     function_ref<bool(ArrayRef<const Function *>)> Pred,
   1739     const AbstractAttribute &QueryingAA, const CallBase &CB) {
```

> The point is it passes possible indirect callees you cannot trivially infer from just the callsite. This does mean you can miss manually specified callsite attributes, but that rarely matters.

Yes, that's the advantage.
 
> Just use checkForAllCallees.

But how exactly? When computing a function attribute, we have to do `getAAFor()` on every callsite in that function, right?

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


More information about the llvm-commits mailing list