Path: blob/21.2-virgl/src/gallium/auxiliary/gallivm/lp_bld_flow.h
4565 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* LLVM control flow build helpers.29*30* @author Jose Fonseca <[email protected]>31*/3233#ifndef LP_BLD_FLOW_H34#define LP_BLD_FLOW_H353637#include "gallivm/lp_bld.h"3839#ifdef __cplusplus40extern "C" {41#endif4243struct lp_type;444546/**47* Early exit. Useful to skip to the end of a function or block when48* the execution mask becomes zero or when there is an error condition.49*/50struct lp_build_skip_context51{52struct gallivm_state *gallivm;5354/** Block to skip to */55LLVMBasicBlockRef block;56};5758void59lp_build_flow_skip_begin(struct lp_build_skip_context *ctx,60struct gallivm_state *gallivm);6162void63lp_build_flow_skip_cond_break(struct lp_build_skip_context *ctx,64LLVMValueRef cond);6566void67lp_build_flow_skip_end(struct lp_build_skip_context *ctx);686970struct lp_build_mask_context71{72struct lp_build_skip_context skip;7374LLVMTypeRef reg_type;7576LLVMValueRef var;77};787980void81lp_build_mask_begin(struct lp_build_mask_context *mask,82struct gallivm_state *gallivm,83struct lp_type type,84LLVMValueRef value);8586LLVMValueRef87lp_build_mask_value(struct lp_build_mask_context *mask);8889/**90* Bitwise AND the mask with the given value, if a previous mask was set.91*/92void93lp_build_mask_update(struct lp_build_mask_context *mask,94LLVMValueRef value);9596void97lp_build_mask_force(struct lp_build_mask_context *mask,98LLVMValueRef value);99100void101lp_build_mask_check(struct lp_build_mask_context *mask);102103LLVMValueRef104lp_build_mask_end(struct lp_build_mask_context *mask);105106107/**108* LLVM's IR doesn't represent for-loops directly. Furthermore it109* it requires creating code blocks, branches, phi variables, so it110* requires a fair amount of code.111*112* @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for113*/114struct lp_build_loop_state115{116LLVMBasicBlockRef block;117LLVMValueRef counter_var;118LLVMValueRef counter;119struct gallivm_state *gallivm;120};121122123void124lp_build_loop_begin(struct lp_build_loop_state *state,125struct gallivm_state *gallivm,126LLVMValueRef start);127128void129lp_build_loop_end(struct lp_build_loop_state *state,130LLVMValueRef end,131LLVMValueRef step);132133void134lp_build_loop_force_set_counter(struct lp_build_loop_state *state,135LLVMValueRef end);136137void138lp_build_loop_force_reload_counter(struct lp_build_loop_state *state);139void140lp_build_loop_end_cond(struct lp_build_loop_state *state,141LLVMValueRef end,142LLVMValueRef step,143LLVMIntPredicate cond);144145146/**147* Implementation of simple C-style for loops148*/149struct lp_build_for_loop_state150{151LLVMBasicBlockRef begin;152LLVMBasicBlockRef body;153LLVMBasicBlockRef exit;154LLVMValueRef counter_var;155LLVMValueRef counter;156LLVMValueRef step;157LLVMIntPredicate cond;158LLVMValueRef end;159struct gallivm_state *gallivm;160};161162void163lp_build_for_loop_begin(struct lp_build_for_loop_state *state,164struct gallivm_state *gallivm,165LLVMValueRef start,166LLVMIntPredicate llvm_cond,167LLVMValueRef end,168LLVMValueRef step);169170void171lp_build_for_loop_end(struct lp_build_for_loop_state *state);172173174/**175* if/else/endif.176*/177struct lp_build_if_state178{179struct gallivm_state *gallivm;180LLVMValueRef condition;181LLVMBasicBlockRef entry_block;182LLVMBasicBlockRef true_block;183LLVMBasicBlockRef false_block;184LLVMBasicBlockRef merge_block;185};186187188void189lp_build_if(struct lp_build_if_state *ctx,190struct gallivm_state *gallivm,191LLVMValueRef condition);192193void194lp_build_else(struct lp_build_if_state *ctx);195196void197lp_build_endif(struct lp_build_if_state *ctx);198199LLVMBasicBlockRef200lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name);201202LLVMValueRef203lp_build_alloca(struct gallivm_state *gallivm,204LLVMTypeRef type,205const char *name);206207LLVMValueRef208lp_build_alloca_undef(struct gallivm_state *gallivm,209LLVMTypeRef type,210const char *name);211212LLVMValueRef213lp_build_array_alloca(struct gallivm_state *gallivm,214LLVMTypeRef type,215LLVMValueRef count,216const char *name);217218#ifdef __cplusplus219}220#endif221222#endif /* !LP_BLD_FLOW_H */223224225