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

Jun Wang via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 17 17:40:20 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();
----------------
jwanggit86 wrote:

Code has been updated after fixing a bug regarding indirect calls of known callees. I'm not sure using `checkForAllCallees()` is necessary for 2 reasons: (1) code is now very simple, boiling down to just checking for intrinsics (2) the first part of `AAAMDAttributesFunction::updateImpl()` already does similar work as `checkForAllCallees()`:
```cpp
  ChangeStatus updateImpl(Attributor &A) override {
    ...
    // Check for Intrinsics and propagate attributes.
    const AACallEdges *AAEdges = A.getAAFor<AACallEdges>(
        *this, this->getIRPosition(), DepClassTy::REQUIRED);
    if (!AAEdges || AAEdges->hasNonAsmUnknownCallee())
      return indicatePessimisticFixpoint();
...
    for (Function *Callee : AAEdges->getOptimisticEdges()) { // Jun - what checkForAllCallees() does is essentially calling getOptimisticEdges() and then running the pred on the edges
      Intrinsic::ID IID = Callee->getIntrinsicID();
      if (IID == Intrinsic::not_intrinsic) {
        const AAAMDAttributes *AAAMD = A.getAAFor<AAAMDAttributes>(
            *this, IRPosition::function(*Callee), DepClassTy::REQUIRED);
        if (!AAAMD)
          return indicatePessimisticFixpoint();
        *this &= *AAAMD;
        continue;
      }
...
```

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


More information about the llvm-commits mailing list