[PATCH] D105095: [Coroutine] Add statistics for the number of elided coroutine

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 29 03:00:59 PDT 2021


ChuanqiXu created this revision.
ChuanqiXu added reviewers: lxfind, rjmccall.
Herald added a subscriber: hiraditya.
ChuanqiXu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Now we lack a benchmark to measure the performance change for each commit.
Since coro elide is the main optimization in coroutine module, I wonder it may be an estimation to count the number of elided coroutine in private code bases.
e.g., for a certain commit, if we found that the number of elided goes down, we could find it before the commit check-in.

Hopes this helps.


https://reviews.llvm.org/D105095

Files:
  llvm/lib/Transforms/Coroutines/CoroElide.cpp
  llvm/test/Transforms/Coroutines/coro-elide.ll


Index: llvm/test/Transforms/Coroutines/coro-elide.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-elide.ll
+++ llvm/test/Transforms/Coroutines/coro-elide.ll
@@ -1,7 +1,7 @@
 ; Tests that the coro.destroy and coro.resume are devirtualized where possible,
 ; SCC pipeline restarts and inlines the direct calls.
 ; RUN: opt < %s -S \
-; RUN:   -passes='cgscc(repeat<2>(inline,function(coro-elide,dce)))' \
+; RUN:   -passes='cgscc(repeat<2>(inline,function(coro-elide,dce)))' -stats \
 ; RUN:   | FileCheck %s
 
 declare void @print(i32) nounwind
@@ -165,3 +165,5 @@
 declare i8* @llvm.coro.frame()
 declare i8* @llvm.coro.subfn.addr(i8*, i8)
 declare i1 @llvm.coro.alloc(token)
+
+; CHECK: 2 coro-elide  - The # of coroutine get elided.
Index: llvm/lib/Transforms/Coroutines/CoroElide.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroElide.cpp
+++ llvm/lib/Transforms/Coroutines/CoroElide.cpp
@@ -9,6 +9,7 @@
 #include "llvm/Transforms/Coroutines/CoroElide.h"
 #include "CoroInternal.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/IR/Dominators.h"
@@ -21,6 +22,8 @@
 
 #define DEBUG_TYPE "coro-elide"
 
+STATISTIC(NumOfCoroElided, "The # of coroutine get elided.");
+
 namespace {
 // Created on demand if the coro-elide pass has work to do.
 struct Lowerer : coro::LowererBase {
@@ -344,6 +347,7 @@
     elideHeapAllocations(CoroId->getFunction(), FrameSizeAndAlign.first,
                          FrameSizeAndAlign.second, AA);
     coro::replaceCoroFree(CoroId, /*Elide=*/true);
+    NumOfCoroElided++;
   }
 
   return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105095.355160.patch
Type: text/x-patch
Size: 1781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210629/aa6486bb/attachment.bin>


More information about the llvm-commits mailing list