[llvm] b5cdb03 - [Coroutines] Better optimization remarks for CoroAnnotationElide pass (#109352)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 19 19:16:13 PDT 2024


Author: Yuxuan Chen
Date: 2024-09-19T19:16:10-07:00
New Revision: b5cdb039712d0c24b0d10c96b6b6d52456088f84

URL: https://github.com/llvm/llvm-project/commit/b5cdb039712d0c24b0d10c96b6b6d52456088f84
DIFF: https://github.com/llvm/llvm-project/commit/b5cdb039712d0c24b0d10c96b6b6d52456088f84.diff

LOG: [Coroutines] Better optimization remarks for CoroAnnotationElide pass (#109352)

Added: 
    

Modified: 
    llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
index ed036f254a1cfb..5f19d600a983aa 100644
--- a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
@@ -101,42 +101,54 @@ PreservedAnalyses CoroAnnotationElidePass::run(Function &F,
 
   Function *NewCallee =
       F.getParent()->getFunction((F.getName() + ".noalloc").str());
-  if (!NewCallee) {
-    return PreservedAnalyses::all();
-  }
-
-    auto FramePtrArgPosition = NewCallee->arg_size() - 1;
-    auto FrameSize =
-        NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
-    auto FrameAlign =
-        NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
-
-    SmallVector<CallBase *, 4> Users;
-    for (auto *U : F.users()) {
-      if (auto *CB = dyn_cast<CallBase>(U)) {
-        if (CB->getCalledFunction() == &F)
-          Users.push_back(CB);
-      }
-    }
 
-    auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+  if (!NewCallee)
+    return PreservedAnalyses::all();
 
-    for (auto *CB : Users) {
-      auto *Caller = CB->getFunction();
-      if (Caller && Caller->isPresplitCoroutine() &&
-          CB->hasFnAttr(llvm::Attribute::CoroElideSafe)) {
+  auto FramePtrArgPosition = NewCallee->arg_size() - 1;
+  auto FrameSize = NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
+  auto FrameAlign = NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
 
-        processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+  SmallVector<CallBase *, 4> Users;
+  for (auto *U : F.users()) {
+    if (auto *CB = dyn_cast<CallBase>(U)) {
+      if (CB->getCalledFunction() == &F)
+        Users.push_back(CB);
+    }
+  }
 
-        ORE.emit([&]() {
-          return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
-                 << "'" << ore::NV("callee", F.getName()) << "' elided in '"
-                 << ore::NV("caller", Caller->getName());
-        });
-        FAM.invalidate(*Caller, PreservedAnalyses::none());
-        Changed = true;
-      }
+  auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+
+  for (auto *CB : Users) {
+    auto *Caller = CB->getFunction();
+    if (!Caller)
+      continue;
+
+    bool IsCallerPresplitCoroutine = Caller->isPresplitCoroutine();
+    bool HasAttr = CB->hasFnAttr(llvm::Attribute::CoroElideSafe);
+    if (IsCallerPresplitCoroutine && HasAttr) {
+      processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+
+      ORE.emit([&]() {
+        return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
+               << "'" << ore::NV("callee", F.getName()) << "' elided in '"
+               << ore::NV("caller", Caller->getName()) << "'";
+      });
+
+      FAM.invalidate(*Caller, PreservedAnalyses::none());
+      Changed = true;
+    } else {
+      ORE.emit([&]() {
+        return OptimizationRemarkMissed(DEBUG_TYPE, "CoroAnnotationElide",
+                                        Caller)
+               << "'" << ore::NV("callee", F.getName()) << "' not elided in '"
+               << ore::NV("caller", Caller->getName()) << "' (caller_presplit="
+               << ore::NV("caller_presplit", IsCallerPresplitCoroutine)
+               << ", elide_safe_attr=" << ore::NV("elide_safe_attr", HasAttr)
+               << ")";
+      });
     }
+  }
 
   return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
 }


        


More information about the llvm-commits mailing list