[PATCH] D105606: [Coroutine] Record the elided coroutines
Chuanqi Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 7 21:45:03 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.
This is follow up for D105095 <https://reviews.llvm.org/D105095>. In D105095 <https://reviews.llvm.org/D105095>, we recorded how many coroutine got elided.
Then in practice, it is helpful to know the accurate coroutine got elided.
I think it is helpful for others who use a large projects.
Test Plan: check-llvm
https://reviews.llvm.org/D105606
Files:
llvm/lib/Transforms/Coroutines/CoroElide.cpp
llvm/test/Transforms/Coroutines/coro-elide-count.ll
llvm/test/Transforms/Coroutines/coro-elide-stat.ll
Index: llvm/test/Transforms/Coroutines/coro-elide-stat.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-elide-stat.ll
+++ llvm/test/Transforms/Coroutines/coro-elide-stat.ll
@@ -4,8 +4,15 @@
; RUN: opt < %s -S \
; RUN: -passes='cgscc(repeat<2>(inline,function(coro-elide,dce)))' -stats 2>&1 \
; RUN: | FileCheck %s
+; RUN: opt < %s --disable-output \
+; RUN: -passes='cgscc(repeat<2>(inline,function(coro-elide,dce)))' \
+; RUN: -coro-elide-info-output-file=%t && \
+; RUN: cat %t \
+; RUN: | FileCheck %s --check-prefix=FILE
; CHECK: 2 coro-elide - The # of coroutine get elided.
+; FILE: Elide f in callResume
+; FILE: Elide f in callResumeMultiRetDommmed
declare void @print(i32) nounwind
Index: llvm/lib/Transforms/Coroutines/CoroElide.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroElide.cpp
+++ llvm/lib/Transforms/Coroutines/CoroElide.cpp
@@ -17,6 +17,7 @@
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
using namespace llvm;
@@ -24,6 +25,10 @@
STATISTIC(NumOfCoroElided, "The # of coroutine get elided.");
+static cl::opt<std::string> CoroElideInfoOutputFilename(
+ "coro-elide-info-output-file", cl::value_desc("filename"),
+ cl::desc("File to record the coroutines got elided"), cl::Hidden);
+
namespace {
// Created on demand if the coro-elide pass has work to do.
struct Lowerer : coro::LowererBase {
@@ -122,6 +127,21 @@
llvm_unreachable("no terminator in the entry block");
}
+#ifndef NDEBUG
+static std::unique_ptr<raw_fd_ostream> getOrCreateLogFile() {
+ assert(!CoroElideInfoOutputFilename.empty() &&
+ "coro-elide-info-output-file shouldn't be empty");
+ std::error_code EC;
+ auto Result = std::make_unique<raw_fd_ostream>(CoroElideInfoOutputFilename,
+ EC, sys::fs::OF_Append);
+ if (!EC)
+ return Result;
+ llvm::errs() << "Error opening coro-elide-info-output-file '"
+ << CoroElideInfoOutputFilename << " for appending!\n";
+ return std::make_unique<raw_fd_ostream>(2, false); // stderr.
+}
+#endif
+
// To elide heap allocations we need to suppress code blocks guarded by
// llvm.coro.alloc and llvm.coro.free instructions.
void Lowerer::elideHeapAllocations(Function *F, uint64_t FrameSize,
@@ -348,6 +368,13 @@
FrameSizeAndAlign.second, AA);
coro::replaceCoroFree(CoroId, /*Elide=*/true);
NumOfCoroElided++;
+#ifndef NDEBUG
+ if (!CoroElideInfoOutputFilename.empty()) {
+ auto outputFile = getOrCreateLogFile();
+ *outputFile << "Elide " << CoroId->getCoroutine()->getName() << " in "
+ << CoroId->getFunction()->getName() << "\n";
+ }
+#endif
}
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105606.357129.patch
Type: text/x-patch
Size: 2910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210708/106d8915/attachment.bin>
More information about the llvm-commits
mailing list