llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.95k stars 11.53k forks source link

[Coroutines] The Coroutine elision optimization (or HALO) is not performed #64586

Open ChuanqiXu9 opened 1 year ago

ChuanqiXu9 commented 1 year ago

There is a middle-end optimization called coroutine elision to elide the dynamic allocation from coroutines. And several issue reports are complaining the compiler failed to optimize their program as expected.

This is not usually what we do for middle-end optimization passes. Since for an optimization pass, it is pretty common to give up optimization opportunities in complex cases. But coroutine elision (or HALO) is different than other middle-end optimizations. It is part of the coroutines semantics in many people's imagination even if it is not formally recorded. Then there is a slight conflict.

To fully address the issue, I think we need involvement from the language side, either formally from WG21 or as a clang extension.

The issue is created to collect different issues/cases/requirements that people want for coroutine elision (or HALO) so that we can handle similar things altogether. The issue reports I see now are including

Feel free to provide more reports or requirements on this page.

llvmbot commented 1 year ago

@llvm/issue-subscribers-coroutines

rnk commented 5 months ago

HALO: Heap Allocation eLision Optimization, for those wondering: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0981r0.html

DarkWingMcQuack commented 3 months ago

https://github.com/llvm/llvm-project/issues/56972#issuecomment-1216223753 does this mean, we cannot build a when_all function which takes awaitables as parameters which leverages HALO? I am currently trying to build such a function, but i cannot seem to get HALO working with clang-17 or 18. Shouldnt it be possible to perform HALO when the awaitables are moved into when all function and then called from there?

ChuanqiXu9 commented 3 months ago

#56972 (comment) does this mean, we cannot build a when_all function which takes awaitables as parameters which leverages HALO?

That is my proposal. Technically, it is not related to the compiler's optimization.

I am currently trying to build such a function, but i cannot seem to get HALO working with clang-17 or 18.

Shouldnt it be possible to perform HALO when the awaitables are moved into when all function and then called from there?

hmmm, no, it is not the case. It is a middle end optimization. We shouldn't think it from the front end.