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 "pipe/p_compiler.h"
31 #include "gallivm/lp_bld.h"
32 #include "gallivm/lp_bld_intr.h"
33
34 struct gallivm_state;
35 LLVMValueRef lp_build_coro_id(struct gallivm_state *gallivm);
36
37 LLVMValueRef lp_build_coro_size(struct gallivm_state *gallivm);
38
39 LLVMValueRef lp_build_coro_begin(struct gallivm_state *gallivm,
40 LLVMValueRef coro_id, LLVMValueRef mem_ptr);
41
42 LLVMValueRef lp_build_coro_free(struct gallivm_state *gallivm,
43 LLVMValueRef coro_id, LLVMValueRef coro_hdl);
44
45 void lp_build_coro_end(struct gallivm_state *gallivm,
46 LLVMValueRef coro_hdl);
47
48 void lp_build_coro_resume(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
49
50 void lp_build_coro_destroy(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
51
52 LLVMValueRef lp_build_coro_done(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
53
54 LLVMValueRef lp_build_coro_suspend(struct gallivm_state *gallivm, bool last);
55
56 LLVMValueRef lp_build_coro_alloc(struct gallivm_state *gallivm, LLVMValueRef id);
57
58 LLVMValueRef lp_build_coro_begin_alloc_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id);
59
60 LLVMValueRef lp_build_coro_alloc_mem_array(struct gallivm_state *gallivm,
61 LLVMValueRef coro_hdl_ptr, LLVMValueRef coro_idx,
62 LLVMValueRef coro_num_hdls);
63 void lp_build_coro_free_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id, LLVMValueRef coro_hdl);
64
65 struct lp_build_coro_suspend_info {
66 LLVMBasicBlockRef suspend;
67 LLVMBasicBlockRef cleanup;
68 };
69
70 void lp_build_coro_suspend_switch(struct gallivm_state *gallivm,
71 const struct lp_build_coro_suspend_info *sus_info,
72 LLVMBasicBlockRef resume_block,
73 bool final_suspend);
74
75 void lp_build_coro_add_malloc_hooks(struct gallivm_state *gallivm);
76 void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm);
77
lp_build_coro_add_presplit(LLVMValueRef coro)78 static inline void lp_build_coro_add_presplit(LLVMValueRef coro)
79 {
80 #if LLVM_VERSION_MAJOR >= 15
81 lp_add_function_attr(coro, -1, LP_FUNC_ATTR_PRESPLITCORO);
82 #else
83 LLVMAddTargetDependentFunctionAttr(coro, "coroutine.presplit", "0");
84 #endif
85 }
86
87 #endif
88