Path: blob/21.2-virgl/src/amd/llvm/ac_llvm_util.h
7237 views
/*1* Copyright 2016 Bas Nieuwenhuizen2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sub license, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR12* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,13* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL14* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,15* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR16* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE17* USE OR OTHER DEALINGS IN THE SOFTWARE.18*19* The above copyright notice and this permission notice (including the20* next paragraph) shall be included in all copies or substantial portions21* of the Software.22*23*/2425#ifndef AC_LLVM_UTIL_H26#define AC_LLVM_UTIL_H2728#include "amd_family.h"29#include "util/macros.h"30#include <llvm-c/TargetMachine.h>31#include <llvm/Config/llvm-config.h>3233#include <stdbool.h>3435#ifdef __cplusplus36extern "C" {37#endif3839struct ac_compiler_passes;40struct ac_llvm_context;4142enum ac_func_attr43{44AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0),45AC_FUNC_ATTR_INREG = (1 << 2),46AC_FUNC_ATTR_NOALIAS = (1 << 3),47AC_FUNC_ATTR_NOUNWIND = (1 << 4),48AC_FUNC_ATTR_READNONE = (1 << 5),49AC_FUNC_ATTR_READONLY = (1 << 6),50AC_FUNC_ATTR_WRITEONLY = (1 << 7),51AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY = (1 << 8),52AC_FUNC_ATTR_CONVERGENT = (1 << 9),5354/* Legacy intrinsic that needs attributes on function declarations55* and they must match the internal LLVM definition exactly, otherwise56* intrinsic selection fails.57*/58AC_FUNC_ATTR_LEGACY = (1u << 31),59};6061enum ac_target_machine_options62{63AC_TM_SUPPORTS_SPILL = 1 << 0,64AC_TM_CHECK_IR = 1 << 1,65AC_TM_ENABLE_GLOBAL_ISEL = 1 << 2,66AC_TM_CREATE_LOW_OPT = 1 << 3,67};6869enum ac_float_mode70{71AC_FLOAT_MODE_DEFAULT,72AC_FLOAT_MODE_DEFAULT_OPENGL,73AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO,74};7576/* Per-thread persistent LLVM objects. */77struct ac_llvm_compiler {78LLVMTargetLibraryInfoRef target_library_info;79LLVMPassManagerRef passmgr;8081/* Default compiler. */82LLVMTargetMachineRef tm;83struct ac_compiler_passes *passes;8485/* Optional compiler for faster compilation with fewer optimizations.86* LLVM modules can be created with "tm" too. There is no difference.87*/88LLVMTargetMachineRef low_opt_tm; /* uses -O1 instead of -O2 */89struct ac_compiler_passes *low_opt_passes;90};9192const char *ac_get_llvm_processor_name(enum radeon_family family);93void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);94void ac_add_attr_alignment(LLVMValueRef val, uint64_t bytes);95bool ac_is_sgpr_param(LLVMValueRef param);96void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, int attr_idx,97enum ac_func_attr attr);98void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function, unsigned attrib_mask);99void ac_dump_module(LLVMModuleRef module);100101LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call);102bool ac_llvm_is_function(LLVMValueRef v);103LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx);104105LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, enum ac_float_mode float_mode);106void ac_enable_signed_zeros(struct ac_llvm_context *ctx);107void ac_disable_signed_zeros(struct ac_llvm_context *ctx);108109void ac_llvm_add_target_dep_function_attr(LLVMValueRef F, const char *name, unsigned value);110void ac_llvm_set_workgroup_size(LLVMValueRef F, unsigned size);111void ac_llvm_set_target_features(LLVMValueRef F, struct ac_llvm_context *ctx);112113static inline unsigned ac_get_load_intr_attribs(bool can_speculate)114{115/* READNONE means writes can't affect it, while READONLY means that116* writes can affect it. */117return can_speculate ? AC_FUNC_ATTR_READNONE : AC_FUNC_ATTR_READONLY;118}119120unsigned ac_count_scratch_private_memory(LLVMValueRef function);121122LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple);123void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info);124PUBLIC void ac_init_shared_llvm_once(void); /* Do not use directly, use ac_init_llvm_once */125void ac_init_llvm_once(void);126127bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler, enum radeon_family family,128enum ac_target_machine_options tm_options);129void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler);130131struct ac_compiler_passes *ac_create_llvm_passes(LLVMTargetMachineRef tm);132void ac_destroy_llvm_passes(struct ac_compiler_passes *p);133bool ac_compile_module_to_elf(struct ac_compiler_passes *p, LLVMModuleRef module,134char **pelf_buffer, size_t *pelf_size);135void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr);136void ac_enable_global_isel(LLVMTargetMachineRef tm);137138static inline bool ac_has_vec3_support(enum chip_class chip, bool use_format)139{140/* GFX6 only supports vec3 with load/store format. */141return chip != GFX6 || use_format;142}143144#ifdef __cplusplus145}146#endif147148#endif /* AC_LLVM_UTIL_H */149150151