Merge remote branch 'origin/7.8'
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_flow.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * LLVM control flow build helpers.
30 *
31 * @author Jose Fonseca <jfonseca@vmware.com>
32 */
33
34 #ifndef LP_BLD_FLOW_H
35 #define LP_BLD_FLOW_H
36
37
38 #include "gallivm/lp_bld.h"
39
40
41 struct lp_type;
42
43
44 struct lp_build_flow_context;
45
46
47 struct lp_build_flow_context *
48 lp_build_flow_create(LLVMBuilderRef builder);
49
50 void
51 lp_build_flow_destroy(struct lp_build_flow_context *flow);
52
53 void
54 lp_build_flow_scope_begin(struct lp_build_flow_context *flow);
55
56 void
57 lp_build_flow_scope_declare(struct lp_build_flow_context *flow,
58 LLVMValueRef *variable);
59
60 void
61 lp_build_flow_scope_end(struct lp_build_flow_context *flow);
62
63 void
64 lp_build_flow_skip_begin(struct lp_build_flow_context *flow);
65
66 void
67 lp_build_flow_skip_cond_break(struct lp_build_flow_context *flow,
68 LLVMValueRef cond);
69
70 void
71 lp_build_flow_skip_end(struct lp_build_flow_context *flow);
72
73
74 struct lp_build_mask_context
75 {
76 struct lp_build_flow_context *flow;
77
78 LLVMTypeRef reg_type;
79
80 LLVMValueRef value;
81 };
82
83
84 void
85 lp_build_mask_begin(struct lp_build_mask_context *mask,
86 struct lp_build_flow_context *flow,
87 struct lp_type type,
88 LLVMValueRef value);
89
90 /**
91 * Bitwise AND the mask with the given value, if a previous mask was set.
92 */
93 void
94 lp_build_mask_update(struct lp_build_mask_context *mask,
95 LLVMValueRef value);
96
97 LLVMValueRef
98 lp_build_mask_end(struct lp_build_mask_context *mask);
99
100
101 /**
102 * LLVM's IR doesn't represent for-loops directly. Furthermore it
103 * it requires creating code blocks, branches, phi variables, so it
104 * requires a fair amount of code.
105 *
106 * @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for
107 */
108 struct lp_build_loop_state
109 {
110 LLVMBasicBlockRef block;
111 LLVMValueRef counter;
112 };
113
114
115 void
116 lp_build_loop_begin(LLVMBuilderRef builder,
117 LLVMValueRef start,
118 struct lp_build_loop_state *state);
119
120
121 void
122 lp_build_loop_end(LLVMBuilderRef builder,
123 LLVMValueRef end,
124 LLVMValueRef step,
125 struct lp_build_loop_state *state);
126
127 void
128 lp_build_loop_end_cond(LLVMBuilderRef builder,
129 LLVMValueRef end,
130 LLVMValueRef step,
131 int cond, /* LLVM condition */
132 struct lp_build_loop_state *state);
133
134
135
136
137 struct lp_build_if_state
138 {
139 LLVMBuilderRef builder;
140 struct lp_build_flow_context *flow;
141 };
142
143
144 void
145 lp_build_if(struct lp_build_if_state *ctx,
146 struct lp_build_flow_context *flow,
147 LLVMBuilderRef builder,
148 LLVMValueRef condition);
149
150 void
151 lp_build_else(struct lp_build_if_state *ctx);
152
153 void
154 lp_build_endif(struct lp_build_if_state *ctx);
155
156 LLVMBasicBlockRef
157 lp_build_insert_new_block(LLVMBuilderRef builder, const char *name);
158
159
160 #endif /* !LP_BLD_FLOW_H */