[PATCH] D71663: [Coroutines] CoroElide enhancement
JunMa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 07:11:50 PST 2019
junparser created this revision.
junparser added reviewers: GorNishanov, modocache.
Herald added subscribers: llvm-commits, hiraditya, EricWF.
Herald added a project: LLVM.
junparser edited the summary of this revision.
According to https://reviews.llvm.org/D43242, coroelide pass only considers llvm.coro.destroy that dominate non-exceptional return. However, this cannot be met if current function is coroutine function because of suspend point.
Consider case from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0978r0.html :
task<> big_task() { // lifetime of `subtask` is fully enclosed in its caller
co_await subtask(); // coroutine frame allocation elided
}
such cases should be optimized.
this patch does two changes in shouldElide function:
1. Consider final coro.suspend as real non-exceptional terminator when function is coroutine, since final suspend is executed with or without exception at last.
2. When function body is wrapped by try-catch, block of coro.suspend may has multiple predecessors : one normal path and the others are exceptional path, and they do not dominate each other. If all the predecessors dominate coro.destroys that reference same coro.begin, we consider condition is met.
3. Keep normal function as usual
Test Plan:
Compile https://godbolt.org/g/mCKfnr and confirm it is still optimized to a single instruction, 'return 1190'.
Compile and run https://godbolt.org/z/AbdRw4, there is no "new" and "delete" output
Compile and run https://godbolt.org/z/gjYSi5 , there is no "new" and "delete" output
check-llvm
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71663
Files:
llvm/lib/Transforms/Coroutines/CoroElide.cpp
llvm/test/Transforms/Coroutines/coro-heap-elide.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71663.234526.patch
Type: text/x-patch
Size: 9645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191218/dece16f5/attachment.bin>
More information about the llvm-commits
mailing list