Skip to content

Commit

Permalink
[Coroutine] Add statistics for the number of elided coroutine
Browse files Browse the repository at this point in the history
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.

Reviewed By: lxfind

Differential Revision: https://reviews.llvm.org/D105095
  • Loading branch information
ChuanqiXu9 committed Jun 30, 2021
1 parent 814dffa commit 1d9539c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Coroutines/CoroElide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,6 +22,8 @@ using namespace llvm;

#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 {
Expand Down Expand Up @@ -344,6 +347,7 @@ bool Lowerer::processCoroId(CoroIdInst *CoroId, AAResults &AA,
elideHeapAllocations(CoroId->getFunction(), FrameSizeAndAlign.first,
FrameSizeAndAlign.second, AA);
coro::replaceCoroFree(CoroId, /*Elide=*/true);
NumOfCoroElided++;
}

return true;
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/Coroutines/coro-elide.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; 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: | FileCheck %s
; RUN: -passes='cgscc(repeat<2>(inline,function(coro-elide,dce)))' -stats \
; RUN: 2>&1 | FileCheck %s --check-prefixes=CHECK,STATS

declare void @print(i32) nounwind

Expand Down Expand Up @@ -165,3 +165,4 @@ declare i8* @llvm.coro.begin(token, i8*)
declare i8* @llvm.coro.frame()
declare i8* @llvm.coro.subfn.addr(i8*, i8)
declare i1 @llvm.coro.alloc(token)
; STATS: 2 coro-elide - The # of coroutine get elided.

0 comments on commit 1d9539c

Please sign in to comment.