[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / libcxx / include / __coroutine / noop_coroutine_handle.h
blob9b7802d1e2827a8858ab7d1cc6ccc97d13fbe52e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
10 #define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
12 #include <__config>
13 #include <__coroutine/coroutine_handle.h>
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 # pragma GCC system_header
17 #endif
19 #if _LIBCPP_STD_VER >= 20
21 _LIBCPP_BEGIN_NAMESPACE_STD
23 #if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
25 // [coroutine.noop]
26 // [coroutine.promise.noop]
27 struct noop_coroutine_promise {};
29 // [coroutine.handle.noop]
30 template <>
31 struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
32 public:
33 // [coroutine.handle.noop.conv], conversion
34 _LIBCPP_HIDE_FROM_ABI
35 constexpr operator coroutine_handle<>() const noexcept {
36 return coroutine_handle<>::from_address(address());
39 // [coroutine.handle.noop.observers], observers
40 _LIBCPP_HIDE_FROM_ABI
41 constexpr explicit operator bool() const noexcept { return true; }
42 _LIBCPP_HIDE_FROM_ABI
43 constexpr bool done() const noexcept { return false; }
45 // [coroutine.handle.noop.resumption], resumption
46 _LIBCPP_HIDE_FROM_ABI
47 constexpr void operator()() const noexcept {}
48 _LIBCPP_HIDE_FROM_ABI
49 constexpr void resume() const noexcept {}
50 _LIBCPP_HIDE_FROM_ABI
51 constexpr void destroy() const noexcept {}
53 // [coroutine.handle.noop.promise], promise access
54 _LIBCPP_HIDE_FROM_ABI
55 noop_coroutine_promise& promise() const noexcept {
56 return *static_cast<noop_coroutine_promise*>(
57 __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false));
60 // [coroutine.handle.noop.address], address
61 _LIBCPP_HIDE_FROM_ABI
62 constexpr void* address() const noexcept { return __handle_; }
64 private:
65 _LIBCPP_HIDE_FROM_ABI
66 friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
68 #if __has_builtin(__builtin_coro_noop)
69 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept {
70 this->__handle_ = __builtin_coro_noop();
73 void* __handle_ = nullptr;
75 #elif defined(_LIBCPP_COMPILER_GCC)
76 // GCC doesn't implement __builtin_coro_noop().
77 // Construct the coroutine frame manually instead.
78 struct __noop_coroutine_frame_ty_ {
79 static void __dummy_resume_destroy_func() { }
81 void (*__resume_)() = __dummy_resume_destroy_func;
82 void (*__destroy_)() = __dummy_resume_destroy_func;
83 struct noop_coroutine_promise __promise_;
86 static __noop_coroutine_frame_ty_ __noop_coroutine_frame_;
88 void* __handle_ = &__noop_coroutine_frame_;
90 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default;
92 #endif // __has_builtin(__builtin_coro_noop)
95 using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
97 #if defined(_LIBCPP_COMPILER_GCC)
98 inline noop_coroutine_handle::__noop_coroutine_frame_ty_
99 noop_coroutine_handle::__noop_coroutine_frame_{};
100 #endif
102 // [coroutine.noop.coroutine]
103 inline _LIBCPP_HIDE_FROM_ABI
104 noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
106 #endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
108 _LIBCPP_END_NAMESPACE_STD
110 #endif // __LIBCPP_STD_VER >= 20
112 #endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H