1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * LLVM control flow build helpers.
31 * @author Jose Fonseca <jfonseca@vmware.com>
38 #include "gallivm/lp_bld.h"
45 * Early exit. Useful to skip to the end of a function or block when
46 * the execution mask becomes zero or when there is an error condition.
48 struct lp_build_skip_context
50 struct gallivm_state
*gallivm
;
52 /** Block to skip to */
53 LLVMBasicBlockRef block
;
57 lp_build_flow_skip_begin(struct lp_build_skip_context
*ctx
,
58 struct gallivm_state
*gallivm
);
61 lp_build_flow_skip_cond_break(struct lp_build_skip_context
*ctx
,
65 lp_build_flow_skip_end(struct lp_build_skip_context
*ctx
);
68 struct lp_build_mask_context
70 struct lp_build_skip_context skip
;
79 lp_build_mask_begin(struct lp_build_mask_context
*mask
,
80 struct gallivm_state
*gallivm
,
85 lp_build_mask_value(struct lp_build_mask_context
*mask
);
88 * Bitwise AND the mask with the given value, if a previous mask was set.
91 lp_build_mask_update(struct lp_build_mask_context
*mask
,
95 lp_build_mask_check(struct lp_build_mask_context
*mask
);
98 lp_build_mask_end(struct lp_build_mask_context
*mask
);
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.
106 * @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for
108 struct lp_build_loop_state
110 LLVMBasicBlockRef block
;
111 LLVMValueRef counter_var
;
112 LLVMValueRef counter
;
113 struct gallivm_state
*gallivm
;
118 lp_build_loop_begin(struct lp_build_loop_state
*state
,
119 struct gallivm_state
*gallivm
,
123 lp_build_loop_end(struct lp_build_loop_state
*state
,
128 lp_build_loop_end_cond(struct lp_build_loop_state
*state
,
131 LLVMIntPredicate cond
);
138 struct lp_build_if_state
140 struct gallivm_state
*gallivm
;
141 LLVMValueRef condition
;
142 LLVMBasicBlockRef entry_block
;
143 LLVMBasicBlockRef true_block
;
144 LLVMBasicBlockRef false_block
;
145 LLVMBasicBlockRef merge_block
;
150 lp_build_if(struct lp_build_if_state
*ctx
,
151 struct gallivm_state
*gallivm
,
152 LLVMValueRef condition
);
155 lp_build_else(struct lp_build_if_state
*ctx
);
158 lp_build_endif(struct lp_build_if_state
*ctx
);
161 lp_build_insert_new_block(struct gallivm_state
*gallivm
, const char *name
);
164 lp_build_alloca(struct gallivm_state
*gallivm
,
169 lp_build_array_alloca(struct gallivm_state
*gallivm
,
174 #endif /* !LP_BLD_FLOW_H */