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 calling intrinsics. 31bf215546Sopenharmony_ci * 32bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com> 33bf215546Sopenharmony_ci */ 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#ifndef LP_BLD_INTR_H 37bf215546Sopenharmony_ci#define LP_BLD_INTR_H 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include <llvm/Config/llvm-config.h> 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "gallivm/lp_bld.h" 42bf215546Sopenharmony_ci#include "gallivm/lp_bld_init.h" 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_cistruct lp_type; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci/** 47bf215546Sopenharmony_ci * Max number of arguments in an intrinsic. 48bf215546Sopenharmony_ci */ 49bf215546Sopenharmony_ci#define LP_MAX_FUNC_ARGS 32 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_cienum lp_func_attr { 52bf215546Sopenharmony_ci LP_FUNC_ATTR_ALWAYSINLINE = (1 << 0), 53bf215546Sopenharmony_ci LP_FUNC_ATTR_INREG = (1 << 2), 54bf215546Sopenharmony_ci LP_FUNC_ATTR_NOALIAS = (1 << 3), 55bf215546Sopenharmony_ci LP_FUNC_ATTR_NOUNWIND = (1 << 4), 56bf215546Sopenharmony_ci LP_FUNC_ATTR_READNONE = (1 << 5), 57bf215546Sopenharmony_ci LP_FUNC_ATTR_READONLY = (1 << 6), 58bf215546Sopenharmony_ci LP_FUNC_ATTR_WRITEONLY = LLVM_VERSION_MAJOR >= 4 ? (1 << 7) : 0, 59bf215546Sopenharmony_ci LP_FUNC_ATTR_INACCESSIBLE_MEM_ONLY = LLVM_VERSION_MAJOR >= 4 ? (1 << 8) : 0, 60bf215546Sopenharmony_ci LP_FUNC_ATTR_CONVERGENT = LLVM_VERSION_MAJOR >= 4 ? (1 << 9) : 0, 61bf215546Sopenharmony_ci LP_FUNC_ATTR_PRESPLITCORO = (1 << 10), 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /* Legacy intrinsic that needs attributes on function declarations 64bf215546Sopenharmony_ci * and they must match the internal LLVM definition exactly, otherwise 65bf215546Sopenharmony_ci * intrinsic selection fails. 66bf215546Sopenharmony_ci */ 67bf215546Sopenharmony_ci LP_FUNC_ATTR_LEGACY = (1u << 31), 68bf215546Sopenharmony_ci}; 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_civoid 71bf215546Sopenharmony_cilp_format_intrinsic(char *name, 72bf215546Sopenharmony_ci size_t size, 73bf215546Sopenharmony_ci const char *name_root, 74bf215546Sopenharmony_ci LLVMTypeRef type); 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ciLLVMValueRef 77bf215546Sopenharmony_cilp_declare_intrinsic(LLVMModuleRef module, 78bf215546Sopenharmony_ci const char *name, 79bf215546Sopenharmony_ci LLVMTypeRef ret_type, 80bf215546Sopenharmony_ci LLVMTypeRef *arg_types, 81bf215546Sopenharmony_ci unsigned num_args); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ciLLVMValueRef 84bf215546Sopenharmony_cilp_declare_intrinsic_with_type(LLVMModuleRef module, 85bf215546Sopenharmony_ci const char *name, 86bf215546Sopenharmony_ci LLVMTypeRef function_type); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_civoid 89bf215546Sopenharmony_cilp_add_function_attr(LLVMValueRef function_or_call, 90bf215546Sopenharmony_ci int attr_idx, enum lp_func_attr attr); 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ciLLVMValueRef 93bf215546Sopenharmony_cilp_build_intrinsic(LLVMBuilderRef builder, 94bf215546Sopenharmony_ci const char *name, 95bf215546Sopenharmony_ci LLVMTypeRef ret_type, 96bf215546Sopenharmony_ci LLVMValueRef *args, 97bf215546Sopenharmony_ci unsigned num_args, 98bf215546Sopenharmony_ci unsigned attr_mask); 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ciLLVMValueRef 102bf215546Sopenharmony_cilp_build_intrinsic_unary(LLVMBuilderRef builder, 103bf215546Sopenharmony_ci const char *name, 104bf215546Sopenharmony_ci LLVMTypeRef ret_type, 105bf215546Sopenharmony_ci LLVMValueRef a); 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ciLLVMValueRef 109bf215546Sopenharmony_cilp_build_intrinsic_binary(LLVMBuilderRef builder, 110bf215546Sopenharmony_ci const char *name, 111bf215546Sopenharmony_ci LLVMTypeRef ret_type, 112bf215546Sopenharmony_ci LLVMValueRef a, 113bf215546Sopenharmony_ci LLVMValueRef b); 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ciLLVMValueRef 117bf215546Sopenharmony_cilp_build_intrinsic_binary_anylength(struct gallivm_state *gallivm, 118bf215546Sopenharmony_ci const char *name, 119bf215546Sopenharmony_ci struct lp_type src_type, 120bf215546Sopenharmony_ci unsigned intr_size, 121bf215546Sopenharmony_ci LLVMValueRef a, 122bf215546Sopenharmony_ci LLVMValueRef b); 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ciLLVMValueRef 126bf215546Sopenharmony_cilp_build_intrinsic_map(struct gallivm_state *gallivm, 127bf215546Sopenharmony_ci const char *name, 128bf215546Sopenharmony_ci LLVMTypeRef ret_type, 129bf215546Sopenharmony_ci LLVMValueRef *args, 130bf215546Sopenharmony_ci unsigned num_args); 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ciLLVMValueRef 134bf215546Sopenharmony_cilp_build_intrinsic_map_unary(struct gallivm_state *gallivm, 135bf215546Sopenharmony_ci const char *name, 136bf215546Sopenharmony_ci LLVMTypeRef ret_type, 137bf215546Sopenharmony_ci LLVMValueRef a); 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ciLLVMValueRef 141bf215546Sopenharmony_cilp_build_intrinsic_map_binary(struct gallivm_state *gallivm, 142bf215546Sopenharmony_ci const char *name, 143bf215546Sopenharmony_ci LLVMTypeRef ret_type, 144bf215546Sopenharmony_ci LLVMValueRef a, 145bf215546Sopenharmony_ci LLVMValueRef b); 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci#endif /* !LP_BLD_INTR_H */ 149