Path: blob/21.2-virgl/src/amd/llvm/ac_llvm_build.h
7326 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*/24#ifndef AC_LLVM_BUILD_H25#define AC_LLVM_BUILD_H2627#include "ac_llvm_util.h"28#include "ac_shader_abi.h"29#include "ac_shader_args.h"30#include "ac_shader_util.h"31#include "amd_family.h"32#include "compiler/nir/nir.h"33#include <llvm-c/Core.h>3435#include <stdbool.h>3637#ifdef __cplusplus38extern "C" {39#endif4041enum42{43AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */44AC_ADDR_SPACE_GLOBAL = 1,45AC_ADDR_SPACE_GDS = 2,46AC_ADDR_SPACE_LDS = 3,47AC_ADDR_SPACE_CONST = 4, /* Global allowing SMEM. */48AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */49};5051#define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */52#define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */53#define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */5455struct ac_llvm_flow;56struct ac_llvm_compiler;5758struct ac_llvm_flow_state {59struct ac_llvm_flow *stack;60unsigned depth_max;61unsigned depth;62};6364struct ac_llvm_context {65LLVMContextRef context;66LLVMModuleRef module;67LLVMBuilderRef builder;6869LLVMValueRef main_function;7071LLVMTypeRef voidt;72LLVMTypeRef i1;73LLVMTypeRef i8;74LLVMTypeRef i16;75LLVMTypeRef i32;76LLVMTypeRef i64;77LLVMTypeRef i128;78LLVMTypeRef intptr;79LLVMTypeRef f16;80LLVMTypeRef f32;81LLVMTypeRef f64;82LLVMTypeRef v2i16;83LLVMTypeRef v4i16;84LLVMTypeRef v2f16;85LLVMTypeRef v4f16;86LLVMTypeRef v2i32;87LLVMTypeRef v3i32;88LLVMTypeRef v4i32;89LLVMTypeRef v2f32;90LLVMTypeRef v3f32;91LLVMTypeRef v4f32;92LLVMTypeRef v8i32;93LLVMTypeRef iN_wavemask;94LLVMTypeRef iN_ballotmask;9596LLVMValueRef i8_0;97LLVMValueRef i8_1;98LLVMValueRef i16_0;99LLVMValueRef i16_1;100LLVMValueRef i32_0;101LLVMValueRef i32_1;102LLVMValueRef i64_0;103LLVMValueRef i64_1;104LLVMValueRef i128_0;105LLVMValueRef i128_1;106LLVMValueRef f16_0;107LLVMValueRef f16_1;108LLVMValueRef f32_0;109LLVMValueRef f32_1;110LLVMValueRef f64_0;111LLVMValueRef f64_1;112LLVMValueRef i1true;113LLVMValueRef i1false;114115/* Temporary helper to implement demote_to_helper:116* True = live lanes117* False = demoted lanes118*/119LLVMValueRef postponed_kill;120bool conditional_demote_seen;121122/* Since ac_nir_translate makes a local copy of ac_llvm_context, there123* are two ac_llvm_contexts. Declare a pointer here, so that the control124* flow stack is shared by both ac_llvm_contexts.125*/126struct ac_llvm_flow_state *flow;127128unsigned range_md_kind;129unsigned invariant_load_md_kind;130unsigned uniform_md_kind;131LLVMValueRef empty_md;132133enum chip_class chip_class;134enum radeon_family family;135const struct radeon_info *info;136137unsigned wave_size;138unsigned ballot_mask_bits;139140unsigned float_mode;141142LLVMValueRef lds;143};144145void ac_llvm_context_init(struct ac_llvm_context *ctx, struct ac_llvm_compiler *compiler,146enum chip_class chip_class, enum radeon_family family,147const struct radeon_info *info,148enum ac_float_mode float_mode, unsigned wave_size,149unsigned ballot_mask_bits);150151void ac_llvm_context_dispose(struct ac_llvm_context *ctx);152153int ac_get_llvm_num_components(LLVMValueRef value);154155int ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);156157LLVMValueRef ac_llvm_extract_elem(struct ac_llvm_context *ac, LLVMValueRef value, int index);158159unsigned ac_get_type_size(LLVMTypeRef type);160161LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);162LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);163LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v);164LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);165LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);166167LLVMValueRef ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,168LLVMTypeRef return_type, LLVMValueRef *params, unsigned param_count,169unsigned attrib_mask);170171void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);172173LLVMValueRef ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type, unsigned count_incoming,174LLVMValueRef *values, LLVMBasicBlockRef *blocks);175176void ac_build_s_barrier(struct ac_llvm_context *ctx);177void ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pgpr, bool sgpr);178179LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, nir_scope scope);180181LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);182LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef value);183184LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);185186LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);187188LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);189190LLVMValueRef ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,191unsigned value_count, unsigned component);192193LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values,194unsigned value_count, unsigned value_stride, bool load,195bool always_vector);196LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,197unsigned value_count);198199LLVMValueRef ac_build_concat(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);200201LLVMValueRef ac_extract_components(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned start,202unsigned channels);203204LLVMValueRef ac_build_expand(struct ac_llvm_context *ctx, LLVMValueRef value,205unsigned src_channels, unsigned dst_channels);206207LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value,208unsigned num_channels);209LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);210211LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, LLVMValueRef den);212213LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx, LLVMValueRef num,214LLVMValueRef multiplier, LLVMValueRef pre_shift,215LLVMValueRef post_shift, LLVMValueRef increment);216LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx, LLVMValueRef num,217LLVMValueRef multiplier, LLVMValueRef pre_shift,218LLVMValueRef post_shift, LLVMValueRef increment);219LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx, LLVMValueRef num,220LLVMValueRef multiplier, LLVMValueRef post_shift);221222void ac_prepare_cube_coords(struct ac_llvm_context *ctx, bool is_deriv, bool is_array, bool is_lod,223LLVMValueRef *coords_arg, LLVMValueRef *derivs_arg);224225LLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,226LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,227LLVMValueRef j);228229LLVMValueRef ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,230LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,231LLVMValueRef j, bool high_16bits);232233LLVMValueRef ac_build_fs_interp_mov(struct ac_llvm_context *ctx, LLVMValueRef parameter,234LLVMValueRef llvm_chan, LLVMValueRef attr_number,235LLVMValueRef params);236237LLVMValueRef ac_build_gep_ptr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,238LLVMValueRef index);239240LLVMValueRef ac_build_gep0(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index);241LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,242LLVMValueRef index);243244void ac_build_indexed_store(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index,245LLVMValueRef value);246247LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index);248LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,249LLVMValueRef index);250LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,251LLVMValueRef index);252LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,253LLVMValueRef base_ptr, LLVMValueRef index);254255void ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,256unsigned num_channels, LLVMValueRef voffset, LLVMValueRef soffset,257unsigned inst_offset, unsigned cache_policy);258259void ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data,260LLVMValueRef vindex, LLVMValueRef voffset, unsigned cache_policy);261262LLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels,263LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,264unsigned inst_offset, LLVMTypeRef channel_type,265unsigned cache_policy, bool can_speculate, bool allow_smem);266267LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc,268LLVMValueRef vindex, LLVMValueRef voffset,269unsigned num_channels, unsigned cache_policy,270bool can_speculate, bool d16, bool tfe);271272LLVMValueRef ac_build_tbuffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,273LLVMValueRef voffset, LLVMValueRef soffset,274LLVMValueRef immoffset, unsigned cache_policy);275276LLVMValueRef ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc,277LLVMValueRef voffset, LLVMValueRef soffset,278LLVMValueRef immoffset, unsigned cache_policy);279280LLVMValueRef ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,281LLVMValueRef vindex, LLVMValueRef voffset,282LLVMValueRef soffset, LLVMValueRef immoffset,283unsigned num_channels, unsigned dfmt, unsigned nfmt,284unsigned cache_policy, bool can_speculate);285286LLVMValueRef ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,287LLVMValueRef voffset, LLVMValueRef soffset,288LLVMValueRef immoffset, unsigned num_channels, unsigned dfmt,289unsigned nfmt, unsigned cache_policy, bool can_speculate);290291292LLVMValueRef ac_build_opencoded_load_format(struct ac_llvm_context *ctx, unsigned log_size,293unsigned num_channels, unsigned format, bool reverse,294bool known_aligned, LLVMValueRef rsrc,295LLVMValueRef vindex, LLVMValueRef voffset,296LLVMValueRef soffset, unsigned cache_policy,297bool can_speculate);298299void ac_build_tbuffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,300LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset,301unsigned cache_policy);302303void ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,304LLVMValueRef voffset, LLVMValueRef soffset, unsigned cache_policy);305306void ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc,307LLVMValueRef vdata, LLVMValueRef vindex, LLVMValueRef voffset,308LLVMValueRef soffset, LLVMValueRef immoffset,309unsigned num_channels, unsigned dfmt, unsigned nfmt,310unsigned cache_policy);311312void ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,313LLVMValueRef voffset, LLVMValueRef soffset, LLVMValueRef immoffset,314unsigned num_channels, unsigned dfmt, unsigned nfmt,315unsigned cache_policy);316317void ac_set_range_metadata(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned lo,318unsigned hi);319LLVMValueRef ac_get_thread_id(struct ac_llvm_context *ctx);320321#define AC_TID_MASK_TOP_LEFT 0xfffffffc322#define AC_TID_MASK_TOP 0xfffffffd323#define AC_TID_MASK_LEFT 0xfffffffe324325LLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val);326327#define AC_SENDMSG_GS 2328#define AC_SENDMSG_GS_DONE 3329#define AC_SENDMSG_GS_ALLOC_REQ 9330331#define AC_SENDMSG_GS_OP_NOP (0 << 4)332#define AC_SENDMSG_GS_OP_CUT (1 << 4)333#define AC_SENDMSG_GS_OP_EMIT (2 << 4)334#define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)335336void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t msg, LLVMValueRef wave_id);337338LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);339340LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);341LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);342LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);343LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);344LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);345LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);346LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);347LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);348349struct ac_export_args {350LLVMValueRef out[4];351unsigned target;352unsigned enabled_channels;353bool compr;354bool done;355bool valid_mask;356};357358void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);359360void ac_build_export_null(struct ac_llvm_context *ctx);361362enum ac_image_opcode363{364ac_image_sample,365ac_image_gather4,366ac_image_load,367ac_image_load_mip,368ac_image_store,369ac_image_store_mip,370ac_image_get_lod,371ac_image_get_resinfo,372ac_image_atomic,373ac_image_atomic_cmpswap,374};375376enum ac_atomic_op377{378ac_atomic_swap,379ac_atomic_add,380ac_atomic_sub,381ac_atomic_smin,382ac_atomic_umin,383ac_atomic_smax,384ac_atomic_umax,385ac_atomic_and,386ac_atomic_or,387ac_atomic_xor,388ac_atomic_inc_wrap,389ac_atomic_dec_wrap,390};391392/* These cache policy bits match the definitions used by the LLVM intrinsics. */393enum ac_image_cache_policy394{395ac_glc = 1 << 0, /* per-CU cache control */396ac_slc = 1 << 1, /* global L2 cache control */397ac_dlc = 1 << 2, /* per-shader-array cache control */398ac_swizzled = 1 << 3, /* the access is swizzled, disabling load/store merging */399};400401struct ac_image_args {402enum ac_image_opcode opcode;403enum ac_atomic_op atomic; /* for the ac_image_atomic opcode */404enum ac_image_dim dim;405unsigned dmask : 4;406unsigned cache_policy : 3;407bool unorm : 1;408bool level_zero : 1;409bool d16 : 1; /* GFX8+: data and return values are 16-bit */410bool a16 : 1; /* GFX9+: address components except compare, offset and bias are 16-bit */411bool g16 : 1; /* GFX10+: derivatives are 16-bit; GFX<=9: must be equal to a16 */412bool tfe : 1;413unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */414415LLVMValueRef resource;416LLVMValueRef sampler;417LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */418LLVMValueRef offset;419LLVMValueRef bias;420LLVMValueRef compare;421LLVMValueRef derivs[6];422LLVMValueRef coords[4];423LLVMValueRef lod; // also used by ac_image_get_resinfo424LLVMValueRef min_lod;425};426427LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, struct ac_image_args *a);428LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx, LLVMValueRef rsrc);429LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);430LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);431LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);432LLVMValueRef ac_build_cvt_pknorm_i16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);433LLVMValueRef ac_build_cvt_pknorm_u16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);434LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,435bool hi);436LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,437bool hi);438LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);439void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);440LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef offset,441LLVMValueRef width, bool is_signed);442LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,443LLVMValueRef s2);444LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,445LLVMValueRef s2);446447void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);448449LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);450LLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value);451LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0);452LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src);453LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);454455LLVMValueRef ac_build_fsat(struct ac_llvm_context *ctx, LLVMValueRef src,456LLVMTypeRef type);457458LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef src0);459460void ac_optimize_vs_outputs(struct ac_llvm_context *ac, LLVMValueRef main_fn,461uint8_t *vs_output_param_offset, uint32_t num_outputs,462uint32_t skip_output_mask, uint8_t *num_param_exports);463void ac_init_exec_full_mask(struct ac_llvm_context *ctx);464465void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);466LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx, LLVMValueRef dw_addr);467void ac_lds_store(struct ac_llvm_context *ctx, LLVMValueRef dw_addr, LLVMValueRef value);468469LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVMValueRef src0);470471LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);472LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);473474void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);475void ac_build_break(struct ac_llvm_context *ctx);476void ac_build_continue(struct ac_llvm_context *ctx);477void ac_build_else(struct ac_llvm_context *ctx, int lable_id);478void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);479void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);480void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);481482LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);483LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);484LLVMValueRef ac_build_alloca_init(struct ac_llvm_context *ac, LLVMValueRef val, const char *name);485486LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMTypeRef type);487488LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned count);489490LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, unsigned rshift,491unsigned bitwidth);492493void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask, LLVMValueRef *addr,494bool is_array_tex);495496LLVMValueRef ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);497498LLVMValueRef ac_build_readlane_no_opt_barrier(struct ac_llvm_context *ctx, LLVMValueRef src,499LLVMValueRef lane);500501LLVMValueRef ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);502503LLVMValueRef ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value,504LLVMValueRef lane);505506LLVMValueRef ac_build_mbcnt_add(struct ac_llvm_context *ctx, LLVMValueRef mask, LLVMValueRef add_src);507LLVMValueRef ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);508509LLVMValueRef ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);510511LLVMValueRef ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);512513LLVMValueRef ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op,514unsigned cluster_size);515516/**517* Common arguments for a scan/reduce operation that accumulates per-wave518* values across an entire workgroup, while respecting the order of waves.519*/520struct ac_wg_scan {521bool enable_reduce;522bool enable_exclusive;523bool enable_inclusive;524nir_op op;525LLVMValueRef src; /* clobbered! */526LLVMValueRef result_reduce;527LLVMValueRef result_exclusive;528LLVMValueRef result_inclusive;529LLVMValueRef extra;530LLVMValueRef waveidx;531LLVMValueRef numwaves; /* only needed for "reduce" operations */532533/* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */534LLVMValueRef scratch;535unsigned maxwaves;536};537538void ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);539void ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);540void ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);541542void ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);543void ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);544void ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);545546LLVMValueRef ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane0,547unsigned lane1, unsigned lane2, unsigned lane3);548549LLVMValueRef ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);550551LLVMValueRef ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);552553LLVMValueRef ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);554555LLVMValueRef ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,556unsigned bitsize);557558LLVMValueRef ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);559560LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx);561562LLVMValueRef ac_build_is_helper_invocation(struct ac_llvm_context *ctx);563564LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func, LLVMValueRef *args,565unsigned num_args);566567LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,568LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope);569570LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,571LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope);572573void ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil,574LLVMValueRef samplemask, struct ac_export_args *args);575576void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context *ctx, LLVMValueRef wave_id,577LLVMValueRef vtx_cnt, LLVMValueRef prim_cnt);578579struct ac_ngg_prim {580unsigned num_vertices;581LLVMValueRef isnull;582LLVMValueRef index[3];583LLVMValueRef edgeflag[3];584LLVMValueRef passthrough;585};586587LLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);588void ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);589590static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)591{592assert(arg.used);593return LLVMGetParam(ctx->main_function, arg.arg_index);594}595596enum ac_llvm_calling_convention597{598AC_LLVM_AMDGPU_VS = 87,599AC_LLVM_AMDGPU_GS = 88,600AC_LLVM_AMDGPU_PS = 89,601AC_LLVM_AMDGPU_CS = 90,602AC_LLVM_AMDGPU_HS = 93,603};604605LLVMValueRef ac_build_main(const struct ac_shader_args *args, struct ac_llvm_context *ctx,606enum ac_llvm_calling_convention convention, const char *name,607LLVMTypeRef ret_type, LLVMModuleRef module);608void ac_build_s_endpgm(struct ac_llvm_context *ctx);609610void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx, LLVMValueRef is_odd,611LLVMValueRef flatshade_first,612LLVMValueRef index[3]);613614#ifdef __cplusplus615}616#endif617618#endif619620621