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 
33 struct gallivm_state;
34 LLVMValueRef lp_build_coro_id(struct gallivm_state *gallivm);
35 
36 LLVMValueRef lp_build_coro_size(struct gallivm_state *gallivm);
37 
38 LLVMValueRef lp_build_coro_begin(struct gallivm_state *gallivm,
39                                  LLVMValueRef coro_id, LLVMValueRef mem_ptr);
40 
41 LLVMValueRef lp_build_coro_free(struct gallivm_state *gallivm,
42                                 LLVMValueRef coro_id, LLVMValueRef coro_hdl);
43 
44 void lp_build_coro_end(struct gallivm_state *gallivm,
45                        LLVMValueRef coro_hdl);
46 
47 void lp_build_coro_resume(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
48 
49 void lp_build_coro_destroy(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
50 
51 LLVMValueRef lp_build_coro_done(struct gallivm_state *gallivm, LLVMValueRef coro_hdl);
52 
53 LLVMValueRef lp_build_coro_suspend(struct gallivm_state *gallivm, bool last);
54 
55 LLVMValueRef lp_build_coro_alloc(struct gallivm_state *gallivm, LLVMValueRef id);
56 
57 LLVMValueRef lp_build_coro_begin_alloc_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id);
58 void lp_build_coro_free_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id, LLVMValueRef coro_hdl);
59 
60 struct lp_build_coro_suspend_info {
61    LLVMBasicBlockRef suspend;
62    LLVMBasicBlockRef cleanup;
63 };
64 
65 void lp_build_coro_suspend_switch(struct gallivm_state *gallivm,
66                                   const struct lp_build_coro_suspend_info *sus_info,
67                                   LLVMBasicBlockRef resume_block,
68                                   bool final_suspend);
69 
70 void lp_build_coro_add_malloc_hooks(struct gallivm_state *gallivm);
71 void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm);
72 #endif
73