[PATCH] D140166: [IR] return nullptr in Instruction::getInsertionPointAfterDef for CallBrInst
Chuanqi Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 27 19:31:46 PST 2022
ChuanqiXu added a comment.
> How long's the frontend-generated IR (after as much IR optimization as is acceptable while still preserving the interesting thing to test?)?
For most tests under llvm/test/Transform/Coroutines, there is not a corresponding frontend source due to the design of coroutine will generate too many codes.
For example, for the following simple coroutine which returns 43 simply:
#include <cstdio>
#include <coroutine>
#include <exception>
#include <cassert>
template <typename T> struct task {
struct promise_type {
T value{123};
std::coroutine_handle<> caller{std::noop_coroutine()};
struct final_awaiter: std::suspend_always {
auto await_suspend(std::coroutine_handle<promise_type> me) const noexcept {
return me.promise().caller;
}
};
constexpr auto initial_suspend() const noexcept {
return std::suspend_always();
}
constexpr auto final_suspend() const noexcept {
return final_awaiter{};
}
auto unhandled_exception() noexcept {
// ignore
}
constexpr void return_value(T v) noexcept {
value = v;
}
constexpr auto & get_return_object() noexcept {
return *this;
}
};
using coroutine_handle = std::coroutine_handle<promise_type>;
promise_type & promise{nullptr};
task(promise_type & p) noexcept: promise{p} { }
~task() noexcept {
coroutine_handle::from_promise(promise).destroy();
}
auto await_ready() noexcept {
return false;
}
auto await_suspend(std::coroutine_handle<> caller) noexcept {
promise.caller = caller;
return coroutine_handle::from_promise(promise);
}
constexpr auto await_resume() const noexcept {
return promise.value;
}
// non-coroutine access to result
auto get() noexcept {
const auto handle = coroutine_handle::from_promise(promise);
if (!handle.done()) {
handle.resume();
}
return promise.value;
}
};
auto a() noexcept -> task<int> {
co_return 42;
}
Note that there is only a coroutine `a()` in the above example. The frontend generated code (with -g) will consist of 1144 lines of IR codes. I get it by:
clang++ -std=c++20 src.cpp -O3 -S -emit-llvm -g -Xclang -disable-llvm-passes -o frontend-generated.ll
And for the optimized (but before coroutine splitting) IR, it'll still consist of 645 lines of IR code. (I get it by inserting codes in CoroSplit.cpp). So I feel it is too lengthy for a lit test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140166/new/
https://reviews.llvm.org/D140166
More information about the llvm-commits
mailing list