1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci/** 29bf215546Sopenharmony_ci * @file 30bf215546Sopenharmony_ci * Helper functions for type conversions. 31bf215546Sopenharmony_ci * 32bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com> 33bf215546Sopenharmony_ci */ 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#ifndef LP_BLD_STRUCT_H 37bf215546Sopenharmony_ci#define LP_BLD_STRUCT_H 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci#include "gallivm/lp_bld.h" 41bf215546Sopenharmony_ci#include "gallivm/lp_bld_init.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci#include "util/u_debug.h" 44bf215546Sopenharmony_ci#include "util/u_memory.h" 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci#define LP_CHECK_STRUCT_SIZE(_ctype, _ltarget, _ltype) \ 48bf215546Sopenharmony_ci assert(LLVMABISizeOfType(_ltarget, _ltype) == \ 49bf215546Sopenharmony_ci sizeof(_ctype)) 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci#define LP_CHECK_MEMBER_OFFSET(_ctype, _cmember, _ltarget, _ltype, _lindex) \ 52bf215546Sopenharmony_ci assert(LLVMOffsetOfElement(_ltarget, _ltype, _lindex) == \ 53bf215546Sopenharmony_ci offsetof(_ctype, _cmember)) 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci/** 57bf215546Sopenharmony_ci * Get value pointer to a structure member. 58bf215546Sopenharmony_ci */ 59bf215546Sopenharmony_ciLLVMValueRef 60bf215546Sopenharmony_cilp_build_struct_get_ptr(struct gallivm_state *gallivm, 61bf215546Sopenharmony_ci LLVMValueRef ptr, 62bf215546Sopenharmony_ci unsigned member, 63bf215546Sopenharmony_ci const char *name); 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci/** 66bf215546Sopenharmony_ci * Get the value of a structure member. 67bf215546Sopenharmony_ci */ 68bf215546Sopenharmony_ciLLVMValueRef 69bf215546Sopenharmony_cilp_build_struct_get(struct gallivm_state *gallivm, 70bf215546Sopenharmony_ci LLVMValueRef ptr, 71bf215546Sopenharmony_ci unsigned member, 72bf215546Sopenharmony_ci const char *name); 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci/** 75bf215546Sopenharmony_ci * Get value pointer to a structure member. 76bf215546Sopenharmony_ci * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. 77bf215546Sopenharmony_ci */ 78bf215546Sopenharmony_ciLLVMValueRef 79bf215546Sopenharmony_cilp_build_struct_get_ptr2(struct gallivm_state *gallivm, 80bf215546Sopenharmony_ci LLVMTypeRef ptr_type, 81bf215546Sopenharmony_ci LLVMValueRef ptr, 82bf215546Sopenharmony_ci unsigned member, 83bf215546Sopenharmony_ci const char *name); 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci/** 86bf215546Sopenharmony_ci * Get the value of a structure member. 87bf215546Sopenharmony_ci * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. 88bf215546Sopenharmony_ci */ 89bf215546Sopenharmony_ciLLVMValueRef 90bf215546Sopenharmony_cilp_build_struct_get2(struct gallivm_state *gallivm, 91bf215546Sopenharmony_ci LLVMTypeRef ptr_type, 92bf215546Sopenharmony_ci LLVMValueRef ptr, 93bf215546Sopenharmony_ci unsigned member, 94bf215546Sopenharmony_ci const char *name); 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci/** 97bf215546Sopenharmony_ci * Get value pointer to an array element. 98bf215546Sopenharmony_ci */ 99bf215546Sopenharmony_ciLLVMValueRef 100bf215546Sopenharmony_cilp_build_array_get_ptr(struct gallivm_state *gallivm, 101bf215546Sopenharmony_ci LLVMValueRef ptr, 102bf215546Sopenharmony_ci LLVMValueRef index); 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci/** 105bf215546Sopenharmony_ci * Get the value of an array element. 106bf215546Sopenharmony_ci */ 107bf215546Sopenharmony_ciLLVMValueRef 108bf215546Sopenharmony_cilp_build_array_get(struct gallivm_state *gallivm, 109bf215546Sopenharmony_ci LLVMValueRef ptr, 110bf215546Sopenharmony_ci LLVMValueRef index); 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci/** 113bf215546Sopenharmony_ci * Set the value of an array element. 114bf215546Sopenharmony_ci */ 115bf215546Sopenharmony_civoid 116bf215546Sopenharmony_cilp_build_array_set(struct gallivm_state *gallivm, 117bf215546Sopenharmony_ci LLVMValueRef ptr, 118bf215546Sopenharmony_ci LLVMValueRef index, 119bf215546Sopenharmony_ci LLVMValueRef value); 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci/** 122bf215546Sopenharmony_ci * Get the value of an array element. 123bf215546Sopenharmony_ci */ 124bf215546Sopenharmony_ciLLVMValueRef 125bf215546Sopenharmony_cilp_build_pointer_get(LLVMBuilderRef builder, 126bf215546Sopenharmony_ci LLVMValueRef ptr, 127bf215546Sopenharmony_ci LLVMValueRef index); 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci/** 130bf215546Sopenharmony_ci * Get the value of an array element, with explicit alignment. 131bf215546Sopenharmony_ci * 132bf215546Sopenharmony_ci * If the element size is different from the alignment this will 133bf215546Sopenharmony_ci * cause llvm to emit an unaligned load 134bf215546Sopenharmony_ci */ 135bf215546Sopenharmony_ciLLVMValueRef 136bf215546Sopenharmony_cilp_build_pointer_get_unaligned(LLVMBuilderRef builder, 137bf215546Sopenharmony_ci LLVMValueRef ptr, 138bf215546Sopenharmony_ci LLVMValueRef index, 139bf215546Sopenharmony_ci unsigned alignment); 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci/** 142bf215546Sopenharmony_ci * Set the value of an array element. 143bf215546Sopenharmony_ci */ 144bf215546Sopenharmony_civoid 145bf215546Sopenharmony_cilp_build_pointer_set(LLVMBuilderRef builder, 146bf215546Sopenharmony_ci LLVMValueRef ptr, 147bf215546Sopenharmony_ci LLVMValueRef index, 148bf215546Sopenharmony_ci LLVMValueRef value); 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci/** 151bf215546Sopenharmony_ci * Set the value of an array element, with explicit alignment. 152bf215546Sopenharmony_ci * 153bf215546Sopenharmony_ci * If the element size is different from the alignment this will 154bf215546Sopenharmony_ci * cause llvm to emit an unaligned store 155bf215546Sopenharmony_ci */ 156bf215546Sopenharmony_civoid 157bf215546Sopenharmony_cilp_build_pointer_set_unaligned(LLVMBuilderRef builder, 158bf215546Sopenharmony_ci LLVMValueRef ptr, 159bf215546Sopenharmony_ci LLVMValueRef index, 160bf215546Sopenharmony_ci LLVMValueRef value, 161bf215546Sopenharmony_ci unsigned alignment); 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci#endif /* !LP_BLD_STRUCT_H */ 164