1 /**************************************************************************
2 *
3 * Copyright 2019 Red Hat.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **************************************************************************/
25
26 #ifndef LP_BLD_CORO_H
27 #define LP_BLD_CORO_H
28
29 #include <stdbool.h>
30 #include "util/compiler.h"
31 #include "gallivm/lp_bld.h"
32 #include "gallivm/lp_bld_intr.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct gallivm_state;
39 LLVMValueRef lp_build_coro_id(struct gallivm_state *gallivm);
40
41 LLVMValueRef lp_build_coro_size(struct gallivm_state *gallivm);
42
43 LLVMValueRef lp_build_coro_begin(struct gallivm_state *gallivm,
44 LLVMValueRef coro_id, LLVMValueRef mem_ptr);
45
46 LLVMValueRef lp_build_coro_free(struct gallivm_state *gallivm,
47 LLVMValueRef coro_id, LLVMValueRef coro_hdl);
48
49 void lp_build_coro_end(struct gallivm_state *gallivm,
50 LLVMValueRef coro_hdl);
51
52 void lp_build_coro_resume(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
53
54 void lp_build_coro_destroy(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
55
56 LLVMValueRef lp_build_coro_done(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
57
58 LLVMValueRef lp_build_coro_suspend(struct gallivm_state *gallivm, bool last);
59
60 LLVMValueRef lp_build_coro_alloc(struct gallivm_state *gallivm, LLVMValueRef id);
61
62 LLVMValueRef lp_build_coro_begin_alloc_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id);
63
64 LLVMValueRef lp_build_coro_alloc_mem_array(struct gallivm_state *gallivm,
65 LLVMValueRef coro_hdl_ptr, LLVMValueRef coro_idx,
66 LLVMValueRef coro_num_hdls);
67 void lp_build_coro_free_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id, LLVMValueRef coro_hdl);
68
69 struct lp_build_coro_suspend_info {
70 LLVMBasicBlockRef suspend;
71 LLVMBasicBlockRef cleanup;
72 };
73
74 void lp_build_coro_suspend_switch(struct gallivm_state *gallivm,
75 const struct lp_build_coro_suspend_info *sus_info,
76 LLVMBasicBlockRef resume_block,
77 bool final_suspend);
78
79 void lp_build_coro_add_malloc_hooks(struct gallivm_state *gallivm);
80 void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm);
81
lp_build_coro_add_presplit(LLVMValueRef coro)82 static inline void lp_build_coro_add_presplit(LLVMValueRef coro)
83 {
84 #if LLVM_VERSION_MAJOR >= 15
85 lp_add_function_attr(coro, -1, LP_FUNC_ATTR_PRESPLITCORO);
86 #else
87 LLVMAddTargetDependentFunctionAttr(coro, "coroutine.presplit", "0");
88 #endif
89 }
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif
96