amd/llvm: switch to 3-spaces style

Follow-up of !4319 using the same clang-format config.

Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5310>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-09-07 09:56:01 +02:00
parent afa1fba198
commit 82d2d73e03
10 changed files with 8876 additions and 10026 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,19 +25,21 @@
#ifndef AC_LLVM_BUILD_H #ifndef AC_LLVM_BUILD_H
#define AC_LLVM_BUILD_H #define AC_LLVM_BUILD_H
#include <stdbool.h>
#include <llvm-c/Core.h>
#include "compiler/nir/nir.h"
#include "amd_family.h"
#include "ac_shader_util.h"
#include "ac_shader_args.h"
#include "ac_shader_abi.h" #include "ac_shader_abi.h"
#include "ac_shader_args.h"
#include "ac_shader_util.h"
#include "amd_family.h"
#include "compiler/nir/nir.h"
#include <llvm-c/Core.h>
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
enum { enum
{
AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */ AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */
AC_ADDR_SPACE_GLOBAL = 1, AC_ADDR_SPACE_GLOBAL = 1,
AC_ADDR_SPACE_GDS = 2, AC_ADDR_SPACE_GDS = 2,
@ -139,26 +141,18 @@ struct ac_llvm_context {
LLVMValueRef lds; LLVMValueRef lds;
}; };
void void ac_llvm_context_init(struct ac_llvm_context *ctx, struct ac_llvm_compiler *compiler,
ac_llvm_context_init(struct ac_llvm_context *ctx,
struct ac_llvm_compiler *compiler,
enum chip_class chip_class, enum radeon_family family, enum chip_class chip_class, enum radeon_family family,
enum ac_float_mode float_mode, unsigned wave_size, enum ac_float_mode float_mode, unsigned wave_size,
unsigned ballot_mask_bits); unsigned ballot_mask_bits);
void void ac_llvm_context_dispose(struct ac_llvm_context *ctx);
ac_llvm_context_dispose(struct ac_llvm_context *ctx);
int int ac_get_llvm_num_components(LLVMValueRef value);
ac_get_llvm_num_components(LLVMValueRef value);
int int ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
LLVMValueRef LLVMValueRef ac_llvm_extract_elem(struct ac_llvm_context *ac, LLVMValueRef value, int index);
ac_llvm_extract_elem(struct ac_llvm_context *ac,
LLVMValueRef value,
int index);
unsigned ac_get_type_size(LLVMTypeRef type); unsigned ac_get_type_size(LLVMTypeRef type);
@ -168,28 +162,22 @@ LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef
LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t); LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v); LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
LLVMValueRef LLVMValueRef ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name, LLVMTypeRef return_type, LLVMValueRef *params, unsigned param_count,
LLVMTypeRef return_type, LLVMValueRef *params, unsigned attrib_mask);
unsigned param_count, unsigned attrib_mask);
void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize); void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
LLVMValueRef LLVMValueRef ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type, unsigned count_incoming,
ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type, LLVMValueRef *values, LLVMBasicBlockRef *blocks);
unsigned count_incoming, LLVMValueRef *values,
LLVMBasicBlockRef *blocks);
void ac_build_s_barrier(struct ac_llvm_context *ctx); void ac_build_s_barrier(struct ac_llvm_context *ctx);
void ac_build_optimization_barrier(struct ac_llvm_context *ctx, void ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pvgpr);
LLVMValueRef *pvgpr);
LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, nir_scope scope);
nir_scope scope);
LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef value);
LLVMValueRef value);
LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
@ -197,196 +185,108 @@ LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
LLVMValueRef LLVMValueRef ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
unsigned value_count, unsigned component); unsigned value_count, unsigned component);
LLVMValueRef LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values,
ac_build_gather_values_extended(struct ac_llvm_context *ctx, unsigned value_count, unsigned value_stride, bool load,
LLVMValueRef *values,
unsigned value_count,
unsigned value_stride,
bool load,
bool always_vector); bool always_vector);
LLVMValueRef LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
ac_build_gather_values(struct ac_llvm_context *ctx,
LLVMValueRef *values,
unsigned value_count); unsigned value_count);
LLVMValueRef LLVMValueRef ac_extract_components(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned start,
ac_extract_components(struct ac_llvm_context *ctx,
LLVMValueRef value,
unsigned start,
unsigned channels); unsigned channels);
LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value,
LLVMValueRef value,
unsigned num_channels); unsigned num_channels);
LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
LLVMValueRef LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, LLVMValueRef den);
ac_build_fdiv(struct ac_llvm_context *ctx,
LLVMValueRef num,
LLVMValueRef den);
LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx, LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx, LLVMValueRef num,
LLVMValueRef num, LLVMValueRef multiplier, LLVMValueRef pre_shift,
LLVMValueRef multiplier, LLVMValueRef post_shift, LLVMValueRef increment);
LLVMValueRef pre_shift, LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx, LLVMValueRef num,
LLVMValueRef post_shift, LLVMValueRef multiplier, LLVMValueRef pre_shift,
LLVMValueRef increment); LLVMValueRef post_shift, LLVMValueRef increment);
LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx, LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx, LLVMValueRef num,
LLVMValueRef num, LLVMValueRef multiplier, LLVMValueRef post_shift);
LLVMValueRef multiplier,
LLVMValueRef pre_shift,
LLVMValueRef post_shift,
LLVMValueRef increment);
LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx,
LLVMValueRef num,
LLVMValueRef multiplier,
LLVMValueRef post_shift);
void void ac_prepare_cube_coords(struct ac_llvm_context *ctx, bool is_deriv, bool is_array, bool is_lod,
ac_prepare_cube_coords(struct ac_llvm_context *ctx, LLVMValueRef *coords_arg, LLVMValueRef *derivs_arg);
bool is_deriv, bool is_array, bool is_lod,
LLVMValueRef *coords_arg,
LLVMValueRef *derivs_arg);
LLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
LLVMValueRef LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
ac_build_fs_interp(struct ac_llvm_context *ctx,
LLVMValueRef llvm_chan,
LLVMValueRef attr_number,
LLVMValueRef params,
LLVMValueRef i,
LLVMValueRef j); LLVMValueRef j);
LLVMValueRef LLVMValueRef ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
LLVMValueRef llvm_chan,
LLVMValueRef attr_number,
LLVMValueRef params,
LLVMValueRef i,
LLVMValueRef j); LLVMValueRef j);
LLVMValueRef LLVMValueRef ac_build_fs_interp_mov(struct ac_llvm_context *ctx, LLVMValueRef parameter,
ac_build_fs_interp_mov(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan, LLVMValueRef attr_number,
LLVMValueRef parameter,
LLVMValueRef llvm_chan,
LLVMValueRef attr_number,
LLVMValueRef params); LLVMValueRef params);
LLVMValueRef LLVMValueRef ac_build_gep_ptr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
ac_build_gep_ptr(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr,
LLVMValueRef index); LLVMValueRef index);
LLVMValueRef LLVMValueRef ac_build_gep0(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index);
ac_build_gep0(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr,
LLVMValueRef index);
LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,
LLVMValueRef index); LLVMValueRef index);
void void ac_build_indexed_store(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index,
ac_build_indexed_store(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr, LLVMValueRef index,
LLVMValueRef value); LLVMValueRef value);
LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index);
LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
LLVMValueRef index);
LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
LLVMValueRef index); LLVMValueRef index);
LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr, LLVMValueRef index);
LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr, LLVMValueRef index);
LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx, LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
LLVMValueRef base_ptr, LLVMValueRef index); LLVMValueRef base_ptr, LLVMValueRef index);
void void ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
ac_build_buffer_store_dword(struct ac_llvm_context *ctx, unsigned num_channels, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc, unsigned inst_offset, unsigned cache_policy);
LLVMValueRef vdata,
unsigned num_channels,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned inst_offset,
unsigned cache_policy);
void void ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data,
ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef vindex, LLVMValueRef voffset, unsigned cache_policy);
LLVMValueRef rsrc,
LLVMValueRef data,
LLVMValueRef vindex,
LLVMValueRef voffset,
unsigned cache_policy);
LLVMValueRef LLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels,
ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc, unsigned inst_offset, unsigned cache_policy, bool can_speculate,
int num_channels,
LLVMValueRef vindex,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned inst_offset,
unsigned cache_policy,
bool can_speculate,
bool allow_smem); bool allow_smem);
LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
LLVMValueRef rsrc, LLVMValueRef vindex, LLVMValueRef voffset,
LLVMValueRef vindex, unsigned num_channels, unsigned cache_policy,
LLVMValueRef voffset, bool can_speculate, bool d16);
unsigned num_channels,
unsigned cache_policy,
bool can_speculate,
bool d16);
LLVMValueRef LLVMValueRef ac_build_tbuffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
ac_build_tbuffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc, LLVMValueRef immoffset, unsigned cache_policy);
LLVMValueRef voffset,
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned cache_policy);
LLVMValueRef LLVMValueRef ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc, LLVMValueRef immoffset, unsigned cache_policy);
LLVMValueRef voffset,
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned cache_policy);
LLVMValueRef LLVMValueRef ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef vindex, LLVMValueRef voffset,
LLVMValueRef rsrc, LLVMValueRef soffset, LLVMValueRef immoffset,
LLVMValueRef vindex, unsigned num_channels, unsigned dfmt, unsigned nfmt,
LLVMValueRef voffset, unsigned cache_policy, bool can_speculate);
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned num_channels,
unsigned dfmt,
unsigned nfmt,
unsigned cache_policy,
bool can_speculate);
LLVMValueRef LLVMValueRef ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc, LLVMValueRef immoffset, unsigned num_channels, unsigned dfmt,
LLVMValueRef voffset, unsigned nfmt, unsigned cache_policy, bool can_speculate);
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned num_channels,
unsigned dfmt,
unsigned nfmt,
unsigned cache_policy,
bool can_speculate);
/* For ac_build_fetch_format. /* For ac_build_fetch_format.
* *
* Note: FLOAT must be 0 (used for convenience of encoding in radeonsi). * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
*/ */
enum { enum
{
AC_FETCH_FORMAT_FLOAT = 0, AC_FETCH_FORMAT_FLOAT = 0,
AC_FETCH_FORMAT_FIXED, AC_FETCH_FORMAT_FIXED,
AC_FETCH_FORMAT_UNORM, AC_FETCH_FORMAT_UNORM,
@ -397,73 +297,38 @@ enum {
AC_FETCH_FORMAT_SINT, AC_FETCH_FORMAT_SINT,
}; };
LLVMValueRef LLVMValueRef ac_build_opencoded_load_format(struct ac_llvm_context *ctx, unsigned log_size,
ac_build_opencoded_load_format(struct ac_llvm_context *ctx, unsigned num_channels, unsigned format, bool reverse,
unsigned log_size, bool known_aligned, LLVMValueRef rsrc,
unsigned num_channels, LLVMValueRef vindex, LLVMValueRef voffset,
unsigned format, LLVMValueRef soffset, unsigned cache_policy,
bool reverse,
bool known_aligned,
LLVMValueRef rsrc,
LLVMValueRef vindex,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned cache_policy,
bool can_speculate); bool can_speculate);
void void ac_build_tbuffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
ac_build_tbuffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset,
LLVMValueRef rsrc,
LLVMValueRef vdata,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned cache_policy); unsigned cache_policy);
void void ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef voffset, LLVMValueRef soffset, unsigned cache_policy);
LLVMValueRef rsrc,
LLVMValueRef vdata, void ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
LLVMValueRef voffset, LLVMValueRef vdata, LLVMValueRef vindex, LLVMValueRef voffset,
LLVMValueRef soffset, LLVMValueRef soffset, LLVMValueRef immoffset,
unsigned num_channels, unsigned dfmt, unsigned nfmt,
unsigned cache_policy); unsigned cache_policy);
void void ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef voffset, LLVMValueRef soffset, LLVMValueRef immoffset,
LLVMValueRef rsrc, unsigned num_channels, unsigned dfmt, unsigned nfmt,
LLVMValueRef vdata,
LLVMValueRef vindex,
LLVMValueRef voffset,
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned num_channels,
unsigned dfmt,
unsigned nfmt,
unsigned cache_policy); unsigned cache_policy);
void LLVMValueRef ac_get_thread_id(struct ac_llvm_context *ctx);
ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx,
LLVMValueRef rsrc,
LLVMValueRef vdata,
LLVMValueRef voffset,
LLVMValueRef soffset,
LLVMValueRef immoffset,
unsigned num_channels,
unsigned dfmt,
unsigned nfmt,
unsigned cache_policy);
LLVMValueRef
ac_get_thread_id(struct ac_llvm_context *ctx);
#define AC_TID_MASK_TOP_LEFT 0xfffffffc #define AC_TID_MASK_TOP_LEFT 0xfffffffc
#define AC_TID_MASK_TOP 0xfffffffd #define AC_TID_MASK_TOP 0xfffffffd
#define AC_TID_MASK_LEFT 0xfffffffe #define AC_TID_MASK_LEFT 0xfffffffe
LLVMValueRef LLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val);
ac_build_ddxy(struct ac_llvm_context *ctx,
uint32_t mask,
int idx,
LLVMValueRef val);
#define AC_SENDMSG_GS 2 #define AC_SENDMSG_GS 2
#define AC_SENDMSG_GS_DONE 3 #define AC_SENDMSG_GS_DONE 3
@ -474,25 +339,15 @@ ac_build_ddxy(struct ac_llvm_context *ctx,
#define AC_SENDMSG_GS_OP_EMIT (2 << 4) #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
#define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4) #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
void ac_build_sendmsg(struct ac_llvm_context *ctx, void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t msg, LLVMValueRef wave_id);
uint32_t msg,
LLVMValueRef wave_id);
LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);
LLVMValueRef arg,
LLVMTypeRef dst_type);
LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);
LLVMValueRef arg, LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMTypeRef dst_type); LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef b); LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
LLVMValueRef b);
LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
LLVMValueRef b);
LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
LLVMValueRef b);
LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
@ -510,7 +365,8 @@ void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
void ac_build_export_null(struct ac_llvm_context *ctx); void ac_build_export_null(struct ac_llvm_context *ctx);
enum ac_image_opcode { enum ac_image_opcode
{
ac_image_sample, ac_image_sample,
ac_image_gather4, ac_image_gather4,
ac_image_load, ac_image_load,
@ -523,7 +379,8 @@ enum ac_image_opcode {
ac_image_atomic_cmpswap, ac_image_atomic_cmpswap,
}; };
enum ac_atomic_op { enum ac_atomic_op
{
ac_atomic_swap, ac_atomic_swap,
ac_atomic_add, ac_atomic_add,
ac_atomic_sub, ac_atomic_sub,
@ -539,7 +396,8 @@ enum ac_atomic_op {
}; };
/* These cache policy bits match the definitions used by the LLVM intrinsics. */ /* These cache policy bits match the definitions used by the LLVM intrinsics. */
enum ac_image_cache_policy { enum ac_image_cache_policy
{
ac_glc = 1 << 0, /* per-CU cache control */ ac_glc = 1 << 0, /* per-CU cache control */
ac_slc = 1 << 1, /* global L2 cache control */ ac_slc = 1 << 1, /* global L2 cache control */
ac_dlc = 1 << 2, /* per-shader-array cache control */ ac_dlc = 1 << 2, /* per-shader-array cache control */
@ -569,59 +427,44 @@ struct ac_image_args {
LLVMValueRef min_lod; LLVMValueRef min_lod;
}; };
LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, struct ac_image_args *a);
struct ac_image_args *a); LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx, LLVMValueRef rsrc);
LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx, LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
LLVMValueRef rsrc); LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
LLVMValueRef args[2]); LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, bool hi);
LLVMValueRef args[2]); LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, bool hi);
LLVMValueRef args[2]);
LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx,
LLVMValueRef args[2], unsigned bits, bool hi);
LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx,
LLVMValueRef args[2], unsigned bits, bool hi);
LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1); LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1); void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef offset,
LLVMValueRef offset, LLVMValueRef width, LLVMValueRef width, bool is_signed);
bool is_signed); LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s2);
LLVMValueRef s1, LLVMValueRef s2); LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s2);
LLVMValueRef s1, LLVMValueRef s2);
void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags); void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);
LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
unsigned bitsize);
LLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value); LLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value);
LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0); LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0);
LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src); LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src);
LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0); LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef src0);
LLVMValueRef src0);
void ac_optimize_vs_outputs(struct ac_llvm_context *ac, void ac_optimize_vs_outputs(struct ac_llvm_context *ac, LLVMValueRef main_fn,
LLVMValueRef main_fn, uint8_t *vs_output_param_offset, uint32_t num_outputs,
uint8_t *vs_output_param_offset, uint32_t skip_output_mask, uint8_t *num_param_exports);
uint32_t num_outputs,
uint32_t skip_output_mask,
uint8_t *num_param_exports);
void ac_init_exec_full_mask(struct ac_llvm_context *ctx); void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
void ac_declare_lds_as_pointer(struct ac_llvm_context *ac); void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx, LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx, LLVMValueRef dw_addr);
LLVMValueRef dw_addr); void ac_lds_store(struct ac_llvm_context *ctx, LLVMValueRef dw_addr, LLVMValueRef value);
void ac_lds_store(struct ac_llvm_context *ctx,
LLVMValueRef dw_addr, LLVMValueRef value);
LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVMValueRef src0);
LLVMTypeRef dst_type,
LLVMValueRef src0);
LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type); LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type); LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
@ -633,51 +476,40 @@ void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
void ac_build_endif(struct ac_llvm_context *ctx, int lable_id); void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id); void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id); void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value, void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value, int lable_id);
int lable_id); void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value, int lable_id);
void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value,
int lable_id);
LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);
const char *name); LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);
LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type,
const char *name);
LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMTypeRef type);
LLVMTypeRef type);
LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned count);
unsigned count);
LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, unsigned rshift,
unsigned rshift, unsigned bitwidth); unsigned bitwidth);
void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask, void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask, LLVMValueRef *addr,
LLVMValueRef *addr, bool is_array_tex); bool is_array_tex);
LLVMValueRef LLVMValueRef ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
LLVMValueRef ac_build_readlane_no_opt_barrier(struct ac_llvm_context *ctx, LLVMValueRef ac_build_readlane_no_opt_barrier(struct ac_llvm_context *ctx, LLVMValueRef src,
LLVMValueRef src, LLVMValueRef lane); LLVMValueRef lane);
LLVMValueRef LLVMValueRef ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
LLVMValueRef LLVMValueRef ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value,
ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, LLVMValueRef lane); LLVMValueRef lane);
LLVMValueRef LLVMValueRef ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
LLVMValueRef LLVMValueRef ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
LLVMValueRef LLVMValueRef ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
LLVMValueRef LLVMValueRef ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op,
ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, unsigned cluster_size); unsigned cluster_size);
/** /**
* Common arguments for a scan/reduce operation that accumulates per-wave * Common arguments for a scan/reduce operation that accumulates per-wave
@ -701,63 +533,43 @@ struct ac_wg_scan {
unsigned maxwaves; unsigned maxwaves;
}; };
void void ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); void ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
void void ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
void
ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
void void ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); void ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
void void ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
void
ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
LLVMValueRef LLVMValueRef ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane0,
ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane1, unsigned lane2, unsigned lane3);
unsigned lane0, unsigned lane1, unsigned lane2, unsigned lane3);
LLVMValueRef LLVMValueRef ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
LLVMValueRef LLVMValueRef ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
LLVMValueRef ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
LLVMValueRef ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
unsigned bitsize); unsigned bitsize);
LLVMValueRef LLVMValueRef ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
unsigned bitsize);
LLVMValueRef LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
unsigned bitsize);
LLVMValueRef LLVMValueRef ac_build_is_helper_invocation(struct ac_llvm_context *ctx);
ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
LLVMValueRef LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func, LLVMValueRef *args,
ac_build_load_helper_invocation(struct ac_llvm_context *ctx); unsigned num_args);
LLVMValueRef
ac_build_is_helper_invocation(struct ac_llvm_context *ctx);
LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
LLVMValueRef *args, unsigned num_args);
LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op, LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
LLVMValueRef ptr, LLVMValueRef val, LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope);
const char *sync_scope);
LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
LLVMValueRef cmp, LLVMValueRef val, LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope);
const char *sync_scope);
void void ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil,
ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef samplemask, struct ac_export_args *args);
LLVMValueRef stencil, LLVMValueRef samplemask,
struct ac_export_args *args);
void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context *ctx, LLVMValueRef wave_id, void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context *ctx, LLVMValueRef wave_id,
LLVMValueRef vtx_cnt, LLVMValueRef prim_cnt); LLVMValueRef vtx_cnt, LLVMValueRef prim_cnt);
@ -770,19 +582,17 @@ struct ac_ngg_prim {
LLVMValueRef passthrough; LLVMValueRef passthrough;
}; };
LLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, LLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);
const struct ac_ngg_prim *prim); void ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);
void ac_build_export_prim(struct ac_llvm_context *ctx,
const struct ac_ngg_prim *prim);
static inline LLVMValueRef static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)
ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)
{ {
assert(arg.used); assert(arg.used);
return LLVMGetParam(ctx->main_function, arg.arg_index); return LLVMGetParam(ctx->main_function, arg.arg_index);
} }
enum ac_llvm_calling_convention { enum ac_llvm_calling_convention
{
AC_LLVM_AMDGPU_VS = 87, AC_LLVM_AMDGPU_VS = 87,
AC_LLVM_AMDGPU_GS = 88, AC_LLVM_AMDGPU_GS = 88,
AC_LLVM_AMDGPU_PS = 89, AC_LLVM_AMDGPU_PS = 89,
@ -790,19 +600,15 @@ enum ac_llvm_calling_convention {
AC_LLVM_AMDGPU_HS = 93, AC_LLVM_AMDGPU_HS = 93,
}; };
LLVMValueRef ac_build_main(const struct ac_shader_args *args, LLVMValueRef ac_build_main(const struct ac_shader_args *args, struct ac_llvm_context *ctx,
struct ac_llvm_context *ctx, enum ac_llvm_calling_convention convention, const char *name,
enum ac_llvm_calling_convention convention, LLVMTypeRef ret_type, LLVMModuleRef module);
const char *name, LLVMTypeRef ret_type,
LLVMModuleRef module);
void ac_build_s_endpgm(struct ac_llvm_context *ctx); void ac_build_s_endpgm(struct ac_llvm_context *ctx);
LLVMValueRef ac_prefix_bitcount(struct ac_llvm_context *ctx, LLVMValueRef ac_prefix_bitcount(struct ac_llvm_context *ctx, LLVMValueRef mask, LLVMValueRef index);
LLVMValueRef mask, LLVMValueRef index); LLVMValueRef ac_prefix_bitcount_2x64(struct ac_llvm_context *ctx, LLVMValueRef mask[2],
LLVMValueRef ac_prefix_bitcount_2x64(struct ac_llvm_context *ctx, LLVMValueRef index);
LLVMValueRef mask[2], LLVMValueRef index); void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx, LLVMValueRef is_odd,
void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx,
LLVMValueRef is_odd,
LLVMValueRef flatshade_first, LLVMValueRef flatshade_first,
LLVMValueRef index[3]); LLVMValueRef index[3]);

View file

@ -24,6 +24,7 @@
*/ */
#include "ac_llvm_cull.h" #include "ac_llvm_cull.h"
#include <llvm-c/Core.h> #include <llvm-c/Core.h>
struct ac_position_w_info { struct ac_position_w_info {
@ -50,8 +51,7 @@ struct ac_position_w_info {
LLVMValueRef any_w_negative; LLVMValueRef any_w_negative;
}; };
static void ac_analyze_position_w(struct ac_llvm_context *ctx, static void ac_analyze_position_w(struct ac_llvm_context *ctx, LLVMValueRef pos[3][4],
LLVMValueRef pos[3][4],
struct ac_position_w_info *w) struct ac_position_w_info *w)
{ {
LLVMBuilderRef builder = ctx->builder; LLVMBuilderRef builder = ctx->builder;
@ -74,11 +74,8 @@ static void ac_analyze_position_w(struct ac_llvm_context *ctx,
} }
/* Perform front/back face culling and return true if the primitive is accepted. */ /* Perform front/back face culling and return true if the primitive is accepted. */
static LLVMValueRef ac_cull_face(struct ac_llvm_context *ctx, static LLVMValueRef ac_cull_face(struct ac_llvm_context *ctx, LLVMValueRef pos[3][4],
LLVMValueRef pos[3][4], struct ac_position_w_info *w, bool cull_front, bool cull_back,
struct ac_position_w_info *w,
bool cull_front,
bool cull_back,
bool cull_zero_area) bool cull_zero_area)
{ {
LLVMBuilderRef builder = ctx->builder; LLVMBuilderRef builder = ctx->builder;
@ -101,9 +98,7 @@ static LLVMValueRef ac_cull_face(struct ac_llvm_context *ctx,
LLVMValueRef det = LLVMBuildFSub(builder, det_p0, det_p1, ""); LLVMValueRef det = LLVMBuildFSub(builder, det_p0, det_p1, "");
/* Negative W negates the determinant. */ /* Negative W negates the determinant. */
det = LLVMBuildSelect(builder, w->w_reflection, det = LLVMBuildSelect(builder, w->w_reflection, LLVMBuildFNeg(builder, det, ""), det, "");
LLVMBuildFNeg(builder, det, ""),
det, "");
LLVMValueRef accepted = NULL; LLVMValueRef accepted = NULL;
if (cull_front) { if (cull_front) {
@ -120,17 +115,11 @@ static LLVMValueRef ac_cull_face(struct ac_llvm_context *ctx,
/* Perform view culling and small primitive elimination and return true /* Perform view culling and small primitive elimination and return true
* if the primitive is accepted and initially_accepted == true. */ * if the primitive is accepted and initially_accepted == true. */
static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx, static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx, LLVMValueRef pos[3][4],
LLVMValueRef pos[3][4], LLVMValueRef initially_accepted, struct ac_position_w_info *w,
LLVMValueRef initially_accepted, LLVMValueRef vp_scale[2], LLVMValueRef vp_translate[2],
struct ac_position_w_info *w, LLVMValueRef small_prim_precision, bool cull_view_xy,
LLVMValueRef vp_scale[2], bool cull_view_near_z, bool cull_view_far_z, bool cull_small_prims,
LLVMValueRef vp_translate[2],
LLVMValueRef small_prim_precision,
bool cull_view_xy,
bool cull_view_near_z,
bool cull_view_far_z,
bool cull_small_prims,
bool use_halfz_clip_space) bool use_halfz_clip_space)
{ {
LLVMBuilderRef builder = ctx->builder; LLVMBuilderRef builder = ctx->builder;
@ -142,8 +131,7 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
* if any W is negative. The bounding box culling doesn't work when * if any W is negative. The bounding box culling doesn't work when
* W is negative. * W is negative.
*/ */
LLVMValueRef cond = LLVMBuildAnd(builder, initially_accepted, LLVMValueRef cond = LLVMBuildAnd(builder, initially_accepted, w->all_w_positive, "");
w->all_w_positive, "");
LLVMValueRef accepted_var = ac_build_alloca_undef(ctx, ctx->i1, ""); LLVMValueRef accepted_var = ac_build_alloca_undef(ctx, ctx->i1, "");
LLVMBuildStore(builder, initially_accepted, accepted_var); LLVMBuildStore(builder, initially_accepted, accepted_var);
@ -166,18 +154,15 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
for (unsigned chan = 0; chan < 3; chan++) { for (unsigned chan = 0; chan < 3; chan++) {
LLVMValueRef visible; LLVMValueRef visible;
if ((cull_view_xy && chan <= 1) || if ((cull_view_xy && chan <= 1) || (cull_view_near_z && chan == 2)) {
(cull_view_near_z && chan == 2)) {
float t = chan == 2 && use_halfz_clip_space ? 0 : -1; float t = chan == 2 && use_halfz_clip_space ? 0 : -1;
visible = LLVMBuildFCmp(builder, LLVMRealOGE, bbox_max[chan], visible = LLVMBuildFCmp(builder, LLVMRealOGE, bbox_max[chan],
LLVMConstReal(ctx->f32, t), ""); LLVMConstReal(ctx->f32, t), "");
accepted = LLVMBuildAnd(builder, accepted, visible, ""); accepted = LLVMBuildAnd(builder, accepted, visible, "");
} }
if ((cull_view_xy && chan <= 1) || if ((cull_view_xy && chan <= 1) || (cull_view_far_z && chan == 2)) {
(cull_view_far_z && chan == 2)) { visible = LLVMBuildFCmp(builder, LLVMRealOLE, bbox_min[chan], ctx->f32_1, "");
visible = LLVMBuildFCmp(builder, LLVMRealOLE, bbox_min[chan],
ctx->f32_1, "");
accepted = LLVMBuildAnd(builder, accepted, visible, ""); accepted = LLVMBuildAnd(builder, accepted, visible, "");
} }
} }
@ -197,10 +182,8 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
for (unsigned chan = 0; chan < 2; chan++) { for (unsigned chan = 0; chan < 2; chan++) {
/* Convert the position to screen-space coordinates. */ /* Convert the position to screen-space coordinates. */
min = ac_build_fmad(ctx, bbox_min[chan], min = ac_build_fmad(ctx, bbox_min[chan], vp_scale[chan], vp_translate[chan]);
vp_scale[chan], vp_translate[chan]); max = ac_build_fmad(ctx, bbox_max[chan], vp_scale[chan], vp_translate[chan]);
max = ac_build_fmad(ctx, bbox_max[chan],
vp_scale[chan], vp_translate[chan]);
/* Scale the bounding box according to the precision of /* Scale the bounding box according to the precision of
* the rasterizer and the number of MSAA samples. */ * the rasterizer and the number of MSAA samples. */
min = LLVMBuildFSub(builder, min, small_prim_precision, ""); min = LLVMBuildFSub(builder, min, small_prim_precision, "");
@ -241,12 +224,9 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
* subpixel_bits are defined by the quantization mode. * subpixel_bits are defined by the quantization mode.
* \param options See ac_cull_options. * \param options See ac_cull_options.
*/ */
LLVMValueRef ac_cull_triangle(struct ac_llvm_context *ctx, LLVMValueRef ac_cull_triangle(struct ac_llvm_context *ctx, LLVMValueRef pos[3][4],
LLVMValueRef pos[3][4], LLVMValueRef initially_accepted, LLVMValueRef vp_scale[2],
LLVMValueRef initially_accepted, LLVMValueRef vp_translate[2], LLVMValueRef small_prim_precision,
LLVMValueRef vp_scale[2],
LLVMValueRef vp_translate[2],
LLVMValueRef small_prim_precision,
struct ac_cull_options *options) struct ac_cull_options *options)
{ {
struct ac_position_w_info w; struct ac_position_w_info w;
@ -257,19 +237,14 @@ LLVMValueRef ac_cull_triangle(struct ac_llvm_context *ctx,
accepted = LLVMBuildAnd(ctx->builder, accepted, initially_accepted, ""); accepted = LLVMBuildAnd(ctx->builder, accepted, initially_accepted, "");
/* Face culling. */ /* Face culling. */
accepted = LLVMBuildAnd(ctx->builder, accepted, accepted = LLVMBuildAnd(
ac_cull_face(ctx, pos, &w, ctx->builder, accepted,
options->cull_front, ac_cull_face(ctx, pos, &w, options->cull_front, options->cull_back, options->cull_zero_area),
options->cull_back, "");
options->cull_zero_area), "");
/* View culling and small primitive elimination. */ /* View culling and small primitive elimination. */
accepted = cull_bbox(ctx, pos, accepted, &w, vp_scale, vp_translate, accepted = cull_bbox(ctx, pos, accepted, &w, vp_scale, vp_translate, small_prim_precision,
small_prim_precision, options->cull_view_xy, options->cull_view_near_z, options->cull_view_far_z,
options->cull_view_xy, options->cull_small_prims, options->use_halfz_clip_space);
options->cull_view_near_z,
options->cull_view_far_z,
options->cull_small_prims,
options->use_halfz_clip_space);
return accepted; return accepted;
} }

View file

@ -48,12 +48,9 @@ struct ac_cull_options {
bool use_halfz_clip_space; bool use_halfz_clip_space;
}; };
LLVMValueRef ac_cull_triangle(struct ac_llvm_context *ctx, LLVMValueRef ac_cull_triangle(struct ac_llvm_context *ctx, LLVMValueRef pos[3][4],
LLVMValueRef pos[3][4], LLVMValueRef initially_accepted, LLVMValueRef vp_scale[2],
LLVMValueRef initially_accepted, LLVMValueRef vp_translate[2], LLVMValueRef small_prim_precision,
LLVMValueRef vp_scale[2],
LLVMValueRef vp_translate[2],
LLVMValueRef small_prim_precision,
struct ac_cull_options *options); struct ac_cull_options *options);
#endif #endif

View file

@ -23,15 +23,14 @@
* *
*/ */
#include <cstring>
#include <llvm-c/Core.h> #include <llvm-c/Core.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Analysis/TargetLibraryInfo.h> #include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Transforms/IPO.h> #include <llvm/Transforms/IPO.h>
#include <llvm/IR/LegacyPassManager.h> #include <cstring>
/* DO NOT REORDER THE HEADERS /* DO NOT REORDER THE HEADERS
* The LLVM headers need to all be included before any Mesa header, * The LLVM headers need to all be included before any Mesa header,
@ -42,7 +41,6 @@
#include "ac_binary.h" #include "ac_binary.h"
#include "ac_llvm_util.h" #include "ac_llvm_util.h"
#include "ac_llvm_build.h" #include "ac_llvm_build.h"
#include "util/macros.h" #include "util/macros.h"
void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes) void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes)
@ -83,7 +81,7 @@ bool ac_llvm_is_function(LLVMValueRef v)
LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx) LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx)
{ {
llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine*>(tm); llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine *>(tm);
LLVMModuleRef module = LLVMModuleCreateWithNameInContext("mesa-shader", ctx); LLVMModuleRef module = LLVMModuleCreateWithNameInContext("mesa-shader", ctx);
llvm::unwrap(module)->setTargetTriple(TM->getTargetTriple().getTriple()); llvm::unwrap(module)->setTargetTriple(TM->getTargetTriple().getTriple());
@ -91,8 +89,7 @@ LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx)
return module; return module;
} }
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, enum ac_float_mode float_mode)
enum ac_float_mode float_mode)
{ {
LLVMBuilderRef builder = LLVMCreateBuilderInContext(ctx); LLVMBuilderRef builder = LLVMCreateBuilderInContext(ctx);
@ -146,14 +143,13 @@ void ac_disable_signed_zeros(struct ac_llvm_context *ctx)
} }
} }
LLVMTargetLibraryInfoRef LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple)
ac_create_target_library_info(const char *triple)
{ {
return reinterpret_cast<LLVMTargetLibraryInfoRef>(new llvm::TargetLibraryInfoImpl(llvm::Triple(triple))); return reinterpret_cast<LLVMTargetLibraryInfoRef>(
new llvm::TargetLibraryInfoImpl(llvm::Triple(triple)));
} }
void void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info)
ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info)
{ {
delete reinterpret_cast<llvm::TargetLibraryInfoImpl *>(library_info); delete reinterpret_cast<llvm::TargetLibraryInfoImpl *>(library_info);
} }
@ -212,8 +208,7 @@ struct raw_memory_ostream : public llvm::raw_pwrite_stream {
void pwrite_impl(const char *ptr, size_t size, uint64_t offset) override void pwrite_impl(const char *ptr, size_t size, uint64_t offset) override
{ {
assert(offset == (size_t)offset && assert(offset == (size_t)offset && offset + size >= offset && offset + size <= written);
offset + size >= offset && offset + size <= written);
memcpy(buffer + offset, ptr, size); memcpy(buffer + offset, ptr, size);
} }
@ -237,10 +232,9 @@ struct ac_compiler_passes *ac_create_llvm_passes(LLVMTargetMachineRef tm)
if (!p) if (!p)
return NULL; return NULL;
llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine*>(tm); llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine *>(tm);
if (TM->addPassesToEmitFile(p->passmgr, p->ostream, if (TM->addPassesToEmitFile(p->passmgr, p->ostream, nullptr,
nullptr,
#if LLVM_VERSION_MAJOR >= 10 #if LLVM_VERSION_MAJOR >= 10
llvm::CGFT_ObjectFile)) { llvm::CGFT_ObjectFile)) {
#else #else
@ -274,12 +268,12 @@ void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr)
void ac_enable_global_isel(LLVMTargetMachineRef tm) void ac_enable_global_isel(LLVMTargetMachineRef tm)
{ {
reinterpret_cast<llvm::TargetMachine*>(tm)->setGlobalISel(true); reinterpret_cast<llvm::TargetMachine *>(tm)->setGlobalISel(true);
} }
LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op, LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
LLVMValueRef ptr, LLVMValueRef val, LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope)
const char *sync_scope) { {
llvm::AtomicRMWInst::BinOp binop; llvm::AtomicRMWInst::BinOp binop;
switch (op) { switch (op) {
case LLVMAtomicRMWBinOpXchg: case LLVMAtomicRMWBinOpXchg:
@ -320,17 +314,18 @@ LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp
break; break;
} }
unsigned SSID = llvm::unwrap(ctx->context)->getOrInsertSyncScopeID(sync_scope); unsigned SSID = llvm::unwrap(ctx->context)->getOrInsertSyncScopeID(sync_scope);
return llvm::wrap(llvm::unwrap(ctx->builder)->CreateAtomicRMW( return llvm::wrap(llvm::unwrap(ctx->builder)
binop, llvm::unwrap(ptr), llvm::unwrap(val), ->CreateAtomicRMW(binop, llvm::unwrap(ptr), llvm::unwrap(val),
llvm::AtomicOrdering::SequentiallyConsistent, SSID)); llvm::AtomicOrdering::SequentiallyConsistent, SSID));
} }
LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
LLVMValueRef cmp, LLVMValueRef val, LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope)
const char *sync_scope) { {
unsigned SSID = llvm::unwrap(ctx->context)->getOrInsertSyncScopeID(sync_scope); unsigned SSID = llvm::unwrap(ctx->context)->getOrInsertSyncScopeID(sync_scope);
return llvm::wrap(llvm::unwrap(ctx->builder)->CreateAtomicCmpXchg( return llvm::wrap(llvm::unwrap(ctx->builder)
llvm::unwrap(ptr), llvm::unwrap(cmp), llvm::unwrap(val), ->CreateAtomicCmpXchg(llvm::unwrap(ptr), llvm::unwrap(cmp),
llvm::unwrap(val),
llvm::AtomicOrdering::SequentiallyConsistent, llvm::AtomicOrdering::SequentiallyConsistent,
llvm::AtomicOrdering::SequentiallyConsistent, SSID)); llvm::AtomicOrdering::SequentiallyConsistent, SSID));
} }

View file

@ -24,16 +24,17 @@
*/ */
/* based on pieces from si_pipe.c and radeon_llvm_emit.c */ /* based on pieces from si_pipe.c and radeon_llvm_emit.c */
#include "ac_llvm_util.h" #include "ac_llvm_util.h"
#include "ac_llvm_build.h" #include "ac_llvm_build.h"
#include "c11/threads.h"
#include "gallivm/lp_bld_misc.h"
#include "util/bitscan.h" #include "util/bitscan.h"
#include "util/u_math.h"
#include <llvm-c/Core.h> #include <llvm-c/Core.h>
#include <llvm-c/Support.h> #include <llvm-c/Support.h>
#include <llvm-c/Transforms/IPO.h> #include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/Scalar.h> #include <llvm-c/Transforms/Scalar.h>
#include <llvm-c/Transforms/Utils.h> #include <llvm-c/Transforms/Utils.h>
#include "c11/threads.h"
#include "gallivm/lp_bld_misc.h"
#include "util/u_math.h"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
@ -191,23 +192,18 @@ static LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family,
const char *triple = (tm_options & AC_TM_SUPPORTS_SPILL) ? "amdgcn-mesa-mesa3d" : "amdgcn--"; const char *triple = (tm_options & AC_TM_SUPPORTS_SPILL) ? "amdgcn-mesa-mesa3d" : "amdgcn--";
LLVMTargetRef target = ac_get_llvm_target(triple); LLVMTargetRef target = ac_get_llvm_target(triple);
snprintf(features, sizeof(features), snprintf(features, sizeof(features), "+DumpCode%s%s%s%s%s",
"+DumpCode%s%s%s%s%s",
LLVM_VERSION_MAJOR >= 11 ? "" : ",-fp32-denormals,+fp64-denormals", LLVM_VERSION_MAJOR >= 11 ? "" : ",-fp32-denormals,+fp64-denormals",
family >= CHIP_NAVI10 && !(tm_options & AC_TM_WAVE32) ? family >= CHIP_NAVI10 && !(tm_options & AC_TM_WAVE32)
",+wavefrontsize64,-wavefrontsize32" : "", ? ",+wavefrontsize64,-wavefrontsize32"
: "",
family <= CHIP_NAVI14 && tm_options & AC_TM_FORCE_ENABLE_XNACK ? ",+xnack" : "", family <= CHIP_NAVI14 && tm_options & AC_TM_FORCE_ENABLE_XNACK ? ",+xnack" : "",
family <= CHIP_NAVI14 && tm_options & AC_TM_FORCE_DISABLE_XNACK ? ",-xnack" : "", family <= CHIP_NAVI14 && tm_options & AC_TM_FORCE_DISABLE_XNACK ? ",-xnack" : "",
tm_options & AC_TM_PROMOTE_ALLOCA_TO_SCRATCH ? ",-promote-alloca" : ""); tm_options & AC_TM_PROMOTE_ALLOCA_TO_SCRATCH ? ",-promote-alloca" : "");
LLVMTargetMachineRef tm = LLVMCreateTargetMachine( LLVMTargetMachineRef tm =
target, LLVMCreateTargetMachine(target, triple, ac_get_llvm_processor_name(family), features, level,
triple, LLVMRelocDefault, LLVMCodeModelDefault);
ac_get_llvm_processor_name(family),
features,
level,
LLVMRelocDefault,
LLVMCodeModelDefault);
if (out_triple) if (out_triple)
*out_triple = triple; *out_triple = triple;
@ -224,8 +220,7 @@ static LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_libr
return NULL; return NULL;
if (target_library_info) if (target_library_info)
LLVMAddTargetLibraryInfo(target_library_info, LLVMAddTargetLibraryInfo(target_library_info, passmgr);
passmgr);
if (check_ir) if (check_ir)
LLVMAddVerifierPass(passmgr); LLVMAddVerifierPass(passmgr);
@ -252,28 +247,35 @@ static LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_libr
static const char *attr_to_str(enum ac_func_attr attr) static const char *attr_to_str(enum ac_func_attr attr)
{ {
switch (attr) { switch (attr) {
case AC_FUNC_ATTR_ALWAYSINLINE: return "alwaysinline"; case AC_FUNC_ATTR_ALWAYSINLINE:
case AC_FUNC_ATTR_INREG: return "inreg"; return "alwaysinline";
case AC_FUNC_ATTR_NOALIAS: return "noalias"; case AC_FUNC_ATTR_INREG:
case AC_FUNC_ATTR_NOUNWIND: return "nounwind"; return "inreg";
case AC_FUNC_ATTR_READNONE: return "readnone"; case AC_FUNC_ATTR_NOALIAS:
case AC_FUNC_ATTR_READONLY: return "readonly"; return "noalias";
case AC_FUNC_ATTR_WRITEONLY: return "writeonly"; case AC_FUNC_ATTR_NOUNWIND:
case AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY: return "inaccessiblememonly"; return "nounwind";
case AC_FUNC_ATTR_CONVERGENT: return "convergent"; case AC_FUNC_ATTR_READNONE:
return "readnone";
case AC_FUNC_ATTR_READONLY:
return "readonly";
case AC_FUNC_ATTR_WRITEONLY:
return "writeonly";
case AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY:
return "inaccessiblememonly";
case AC_FUNC_ATTR_CONVERGENT:
return "convergent";
default: default:
fprintf(stderr, "Unhandled function attribute: %x\n", attr); fprintf(stderr, "Unhandled function attribute: %x\n", attr);
return 0; return 0;
} }
} }
void void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, int attr_idx,
ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, enum ac_func_attr attr)
int attr_idx, enum ac_func_attr attr)
{ {
const char *attr_name = attr_to_str(attr); const char *attr_name = attr_to_str(attr);
unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, strlen(attr_name));
strlen(attr_name));
LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(ctx, kind_id, 0); LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(ctx, kind_id, 0);
if (LLVMIsAFunction(function)) if (LLVMIsAFunction(function))
@ -282,8 +284,7 @@ ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function,
LLVMAddCallSiteAttribute(function, attr_idx, llvm_attr); LLVMAddCallSiteAttribute(function, attr_idx, llvm_attr);
} }
void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function, void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function, unsigned attrib_mask)
unsigned attrib_mask)
{ {
attrib_mask |= AC_FUNC_ATTR_NOUNWIND; attrib_mask |= AC_FUNC_ATTR_NOUNWIND;
attrib_mask &= ~AC_FUNC_ATTR_LEGACY; attrib_mask &= ~AC_FUNC_ATTR_LEGACY;
@ -294,17 +295,14 @@ void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function,
} }
} }
void void ac_dump_module(LLVMModuleRef module)
ac_dump_module(LLVMModuleRef module)
{ {
char *str = LLVMPrintModuleToString(module); char *str = LLVMPrintModuleToString(module);
fprintf(stderr, "%s", str); fprintf(stderr, "%s", str);
LLVMDisposeMessage(str); LLVMDisposeMessage(str);
} }
void void ac_llvm_add_target_dep_function_attr(LLVMValueRef F, const char *name, unsigned value)
ac_llvm_add_target_dep_function_attr(LLVMValueRef F,
const char *name, unsigned value)
{ {
char str[16]; char str[16];
@ -322,8 +320,7 @@ void ac_llvm_set_workgroup_size(LLVMValueRef F, unsigned size)
LLVMAddTargetDependentFunctionAttr(F, "amdgpu-flat-work-group-size", str); LLVMAddTargetDependentFunctionAttr(F, "amdgpu-flat-work-group-size", str);
} }
unsigned unsigned ac_count_scratch_private_memory(LLVMValueRef function)
ac_count_scratch_private_memory(LLVMValueRef function)
{ {
unsigned private_mem_vgprs = 0; unsigned private_mem_vgprs = 0;
@ -351,45 +348,37 @@ ac_count_scratch_private_memory(LLVMValueRef function)
return private_mem_vgprs; return private_mem_vgprs;
} }
bool bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler, enum radeon_family family,
ac_init_llvm_compiler(struct ac_llvm_compiler *compiler,
enum radeon_family family,
enum ac_target_machine_options tm_options) enum ac_target_machine_options tm_options)
{ {
const char *triple; const char *triple;
memset(compiler, 0, sizeof(*compiler)); memset(compiler, 0, sizeof(*compiler));
compiler->tm = ac_create_target_machine(family, tm_options, compiler->tm = ac_create_target_machine(family, tm_options, LLVMCodeGenLevelDefault, &triple);
LLVMCodeGenLevelDefault,
&triple);
if (!compiler->tm) if (!compiler->tm)
return false; return false;
if (tm_options & AC_TM_CREATE_LOW_OPT) { if (tm_options & AC_TM_CREATE_LOW_OPT) {
compiler->low_opt_tm = compiler->low_opt_tm =
ac_create_target_machine(family, tm_options, ac_create_target_machine(family, tm_options, LLVMCodeGenLevelLess, NULL);
LLVMCodeGenLevelLess, NULL);
if (!compiler->low_opt_tm) if (!compiler->low_opt_tm)
goto fail; goto fail;
} }
if (family >= CHIP_NAVI10) { if (family >= CHIP_NAVI10) {
assert(!(tm_options & AC_TM_CREATE_LOW_OPT)); assert(!(tm_options & AC_TM_CREATE_LOW_OPT));
compiler->tm_wave32 = ac_create_target_machine(family, compiler->tm_wave32 =
tm_options | AC_TM_WAVE32, ac_create_target_machine(family, tm_options | AC_TM_WAVE32, LLVMCodeGenLevelDefault, NULL);
LLVMCodeGenLevelDefault,
NULL);
if (!compiler->tm_wave32) if (!compiler->tm_wave32)
goto fail; goto fail;
} }
compiler->target_library_info = compiler->target_library_info = ac_create_target_library_info(triple);
ac_create_target_library_info(triple);
if (!compiler->target_library_info) if (!compiler->target_library_info)
goto fail; goto fail;
compiler->passmgr = ac_create_passmgr(compiler->target_library_info, compiler->passmgr =
tm_options & AC_TM_CHECK_IR); ac_create_passmgr(compiler->target_library_info, tm_options & AC_TM_CHECK_IR);
if (!compiler->passmgr) if (!compiler->passmgr)
goto fail; goto fail;
@ -399,8 +388,7 @@ fail:
return false; return false;
} }
void void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler)
ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler)
{ {
ac_destroy_llvm_passes(compiler->passes); ac_destroy_llvm_passes(compiler->passes);
ac_destroy_llvm_passes(compiler->passes_wave32); ac_destroy_llvm_passes(compiler->passes_wave32);

View file

@ -26,11 +26,11 @@
#ifndef AC_LLVM_UTIL_H #ifndef AC_LLVM_UTIL_H
#define AC_LLVM_UTIL_H #define AC_LLVM_UTIL_H
#include <stdbool.h> #include "amd_family.h"
#include <llvm-c/TargetMachine.h> #include <llvm-c/TargetMachine.h>
#include <llvm/Config/llvm-config.h> #include <llvm/Config/llvm-config.h>
#include "amd_family.h" #include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -39,7 +39,8 @@ extern "C" {
struct ac_compiler_passes; struct ac_compiler_passes;
struct ac_llvm_context; struct ac_llvm_context;
enum ac_func_attr { enum ac_func_attr
{
AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0), AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0),
AC_FUNC_ATTR_INREG = (1 << 2), AC_FUNC_ATTR_INREG = (1 << 2),
AC_FUNC_ATTR_NOALIAS = (1 << 3), AC_FUNC_ATTR_NOALIAS = (1 << 3),
@ -57,7 +58,8 @@ enum ac_func_attr {
AC_FUNC_ATTR_LEGACY = (1u << 31), AC_FUNC_ATTR_LEGACY = (1u << 31),
}; };
enum ac_target_machine_options { enum ac_target_machine_options
{
AC_TM_SUPPORTS_SPILL = (1 << 0), AC_TM_SUPPORTS_SPILL = (1 << 0),
AC_TM_FORCE_ENABLE_XNACK = (1 << 1), AC_TM_FORCE_ENABLE_XNACK = (1 << 1),
AC_TM_FORCE_DISABLE_XNACK = (1 << 2), AC_TM_FORCE_DISABLE_XNACK = (1 << 2),
@ -68,7 +70,8 @@ enum ac_target_machine_options {
AC_TM_WAVE32 = (1 << 7), AC_TM_WAVE32 = (1 << 7),
}; };
enum ac_float_mode { enum ac_float_mode
{
AC_FLOAT_MODE_DEFAULT, AC_FLOAT_MODE_DEFAULT,
AC_FLOAT_MODE_DEFAULT_OPENGL, AC_FLOAT_MODE_DEFAULT_OPENGL,
AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO, AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO,
@ -98,46 +101,37 @@ const char *ac_get_llvm_processor_name(enum radeon_family family);
void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes); void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
void ac_add_attr_alignment(LLVMValueRef val, uint64_t bytes); void ac_add_attr_alignment(LLVMValueRef val, uint64_t bytes);
bool ac_is_sgpr_param(LLVMValueRef param); bool ac_is_sgpr_param(LLVMValueRef param);
void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, int attr_idx,
int attr_idx, enum ac_func_attr attr); enum ac_func_attr attr);
void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function, void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function, unsigned attrib_mask);
unsigned attrib_mask);
void ac_dump_module(LLVMModuleRef module); void ac_dump_module(LLVMModuleRef module);
LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call); LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call);
bool ac_llvm_is_function(LLVMValueRef v); bool ac_llvm_is_function(LLVMValueRef v);
LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx); LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx);
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, enum ac_float_mode float_mode);
enum ac_float_mode float_mode);
void ac_enable_signed_zeros(struct ac_llvm_context *ctx); void ac_enable_signed_zeros(struct ac_llvm_context *ctx);
void ac_disable_signed_zeros(struct ac_llvm_context *ctx); void ac_disable_signed_zeros(struct ac_llvm_context *ctx);
void void ac_llvm_add_target_dep_function_attr(LLVMValueRef F, const char *name, unsigned value);
ac_llvm_add_target_dep_function_attr(LLVMValueRef F,
const char *name, unsigned value);
void ac_llvm_set_workgroup_size(LLVMValueRef F, unsigned size); void ac_llvm_set_workgroup_size(LLVMValueRef F, unsigned size);
static inline unsigned static inline unsigned ac_get_load_intr_attribs(bool can_speculate)
ac_get_load_intr_attribs(bool can_speculate)
{ {
/* READNONE means writes can't affect it, while READONLY means that /* READNONE means writes can't affect it, while READONLY means that
* writes can affect it. */ * writes can affect it. */
return can_speculate ? AC_FUNC_ATTR_READNONE : return can_speculate ? AC_FUNC_ATTR_READNONE : AC_FUNC_ATTR_READONLY;
AC_FUNC_ATTR_READONLY;
} }
unsigned unsigned ac_count_scratch_private_memory(LLVMValueRef function);
ac_count_scratch_private_memory(LLVMValueRef function);
LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple); LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple);
void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info); void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info);
void ac_init_shared_llvm_once(void); /* Do not use directly, use ac_init_llvm_once */ void ac_init_shared_llvm_once(void); /* Do not use directly, use ac_init_llvm_once */
void ac_init_llvm_once(void); void ac_init_llvm_once(void);
bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler, enum radeon_family family,
bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler,
enum radeon_family family,
enum ac_target_machine_options tm_options); enum ac_target_machine_options tm_options);
void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler); void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler);
@ -148,8 +142,7 @@ bool ac_compile_module_to_elf(struct ac_compiler_passes *p, LLVMModuleRef module
void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr); void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr);
void ac_enable_global_isel(LLVMTargetMachineRef tm); void ac_enable_global_isel(LLVMTargetMachineRef tm);
static inline bool static inline bool ac_has_vec3_support(enum chip_class chip, bool use_format)
ac_has_vec3_support(enum chip_class chip, bool use_format)
{ {
if (chip == GFX6 && !use_format) { if (chip == GFX6 && !use_format) {
/* GFX6 only supports vec3 with load/store format. */ /* GFX6 only supports vec3 with load/store format. */

File diff suppressed because it is too large Load diff

View file

@ -24,11 +24,12 @@
#ifndef AC_NIR_TO_LLVM_H #ifndef AC_NIR_TO_LLVM_H
#define AC_NIR_TO_LLVM_H #define AC_NIR_TO_LLVM_H
#include <stdbool.h>
#include "llvm-c/Core.h"
#include "llvm-c/TargetMachine.h"
#include "amd_family.h" #include "amd_family.h"
#include "compiler/shader_enums.h" #include "compiler/shader_enums.h"
#include "llvm-c/Core.h"
#include "llvm-c/TargetMachine.h"
#include <stdbool.h>
struct nir_shader; struct nir_shader;
struct nir_variable; struct nir_variable;
@ -53,11 +54,8 @@ bool ac_are_tessfactors_def_in_all_invocs(const struct nir_shader *nir);
void ac_nir_translate(struct ac_llvm_context *ac, struct ac_shader_abi *abi, void ac_nir_translate(struct ac_llvm_context *ac, struct ac_shader_abi *abi,
const struct ac_shader_args *args, struct nir_shader *nir); const struct ac_shader_args *args, struct nir_shader *nir);
void void ac_handle_shader_output_decl(struct ac_llvm_context *ctx, struct ac_shader_abi *abi,
ac_handle_shader_output_decl(struct ac_llvm_context *ctx, struct nir_shader *nir, struct nir_variable *variable,
struct ac_shader_abi *abi,
struct nir_shader *nir,
struct nir_variable *variable,
gl_shader_stage stage); gl_shader_stage stage);
void ac_emit_barrier(struct ac_llvm_context *ac, gl_shader_stage stage); void ac_emit_barrier(struct ac_llvm_context *ac, gl_shader_stage stage);

View file

@ -24,11 +24,11 @@
#ifndef AC_SHADER_ABI_H #ifndef AC_SHADER_ABI_H
#define AC_SHADER_ABI_H #define AC_SHADER_ABI_H
#include <llvm-c/Core.h>
#include <assert.h>
#include "ac_shader_args.h" #include "ac_shader_args.h"
#include "compiler/shader_enums.h" #include "compiler/shader_enums.h"
#include <llvm-c/Core.h>
#include <assert.h>
struct nir_variable; struct nir_variable;
@ -36,7 +36,8 @@ struct nir_variable;
#define AC_MAX_INLINE_PUSH_CONSTS 8 #define AC_MAX_INLINE_PUSH_CONSTS 8
enum ac_descriptor_type { enum ac_descriptor_type
{
AC_DESC_IMAGE, AC_DESC_IMAGE,
AC_DESC_FMASK, AC_DESC_FMASK,
AC_DESC_SAMPLER, AC_DESC_SAMPLER,
@ -69,63 +70,39 @@ struct ac_shader_abi {
/* Varying -> attribute number mapping. Also NIR-only */ /* Varying -> attribute number mapping. Also NIR-only */
unsigned fs_input_attr_indices[MAX_VARYING]; unsigned fs_input_attr_indices[MAX_VARYING];
void (*emit_outputs)(struct ac_shader_abi *abi, void (*emit_outputs)(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);
unsigned max_outputs,
LLVMValueRef *addrs);
void (*emit_vertex)(struct ac_shader_abi *abi, void (*emit_vertex)(struct ac_shader_abi *abi, unsigned stream, LLVMValueRef *addrs);
unsigned stream,
LLVMValueRef *addrs);
void (*emit_primitive)(struct ac_shader_abi *abi, void (*emit_primitive)(struct ac_shader_abi *abi, unsigned stream);
unsigned stream);
void (*emit_vertex_with_counter)(struct ac_shader_abi *abi, void (*emit_vertex_with_counter)(struct ac_shader_abi *abi, unsigned stream,
unsigned stream, LLVMValueRef vertexidx, LLVMValueRef *addrs);
LLVMValueRef vertexidx,
LLVMValueRef *addrs);
LLVMValueRef (*load_inputs)(struct ac_shader_abi *abi, LLVMValueRef (*load_inputs)(struct ac_shader_abi *abi, unsigned location,
unsigned location, unsigned driver_location, unsigned component,
unsigned driver_location, unsigned num_components, unsigned vertex_index, unsigned const_index,
unsigned component,
unsigned num_components,
unsigned vertex_index,
unsigned const_index,
LLVMTypeRef type); LLVMTypeRef type);
LLVMValueRef (*load_tess_varyings)(struct ac_shader_abi *abi, LLVMValueRef (*load_tess_varyings)(struct ac_shader_abi *abi, LLVMTypeRef type,
LLVMTypeRef type, LLVMValueRef vertex_index, LLVMValueRef param_index,
LLVMValueRef vertex_index, unsigned const_index, unsigned location,
LLVMValueRef param_index, unsigned driver_location, unsigned component,
unsigned const_index, unsigned num_components, bool is_patch, bool is_compact,
unsigned location,
unsigned driver_location,
unsigned component,
unsigned num_components,
bool is_patch,
bool is_compact,
bool load_inputs); bool load_inputs);
void (*store_tcs_outputs)(struct ac_shader_abi *abi, void (*store_tcs_outputs)(struct ac_shader_abi *abi, const struct nir_variable *var,
const struct nir_variable *var, LLVMValueRef vertex_index, LLVMValueRef param_index,
LLVMValueRef vertex_index, unsigned const_index, LLVMValueRef src, unsigned writemask,
LLVMValueRef param_index, unsigned component, unsigned driver_location);
unsigned const_index,
LLVMValueRef src,
unsigned writemask,
unsigned component,
unsigned driver_location);
LLVMValueRef (*load_tess_coord)(struct ac_shader_abi *abi); LLVMValueRef (*load_tess_coord)(struct ac_shader_abi *abi);
LLVMValueRef (*load_patch_vertices_in)(struct ac_shader_abi *abi); LLVMValueRef (*load_patch_vertices_in)(struct ac_shader_abi *abi);
LLVMValueRef (*load_tess_level)(struct ac_shader_abi *abi, LLVMValueRef (*load_tess_level)(struct ac_shader_abi *abi, unsigned varying_id,
unsigned varying_id,
bool load_default_state); bool load_default_state);
LLVMValueRef (*load_ubo)(struct ac_shader_abi *abi, LLVMValueRef index); LLVMValueRef (*load_ubo)(struct ac_shader_abi *abi, LLVMValueRef index);
/** /**
@ -135,8 +112,7 @@ struct ac_shader_abi {
* in Vulkan, and the buffer index in OpenGL/Gallium * in Vulkan, and the buffer index in OpenGL/Gallium
* \param write whether buffer contents will be written * \param write whether buffer contents will be written
*/ */
LLVMValueRef (*load_ssbo)(struct ac_shader_abi *abi, LLVMValueRef (*load_ssbo)(struct ac_shader_abi *abi, LLVMValueRef buffer, bool write);
LLVMValueRef buffer, bool write);
/** /**
* Load a descriptor associated to a sampler. * Load a descriptor associated to a sampler.
@ -149,14 +125,10 @@ struct ac_shader_abi {
* \param desc_type the type of descriptor to load * \param desc_type the type of descriptor to load
* \param image whether the descriptor is loaded for an image operation * \param image whether the descriptor is loaded for an image operation
*/ */
LLVMValueRef (*load_sampler_desc)(struct ac_shader_abi *abi, LLVMValueRef (*load_sampler_desc)(struct ac_shader_abi *abi, unsigned descriptor_set,
unsigned descriptor_set, unsigned base_index, unsigned constant_index,
unsigned base_index, LLVMValueRef index, enum ac_descriptor_type desc_type,
unsigned constant_index, bool image, bool write, bool bindless);
LLVMValueRef index,
enum ac_descriptor_type desc_type,
bool image, bool write,
bool bindless);
/** /**
* Load a Vulkan-specific resource. * Load a Vulkan-specific resource.
@ -165,13 +137,10 @@ struct ac_shader_abi {
* \param desc_set descriptor set * \param desc_set descriptor set
* \param binding descriptor set binding * \param binding descriptor set binding
*/ */
LLVMValueRef (*load_resource)(struct ac_shader_abi *abi, LLVMValueRef (*load_resource)(struct ac_shader_abi *abi, LLVMValueRef index, unsigned desc_set,
LLVMValueRef index,
unsigned desc_set,
unsigned binding); unsigned binding);
LLVMValueRef (*load_sample_position)(struct ac_shader_abi *abi, LLVMValueRef (*load_sample_position)(struct ac_shader_abi *abi, LLVMValueRef sample_id);
LLVMValueRef sample_id);
LLVMValueRef (*load_local_group_size)(struct ac_shader_abi *abi); LLVMValueRef (*load_local_group_size)(struct ac_shader_abi *abi);