radeonsi: move kill intrinsic building into amd/common
authorMarek Olšák <marek.olsak@amd.com>
Fri, 24 Feb 2017 21:44:18 +0000 (22:44 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 3 Mar 2017 14:29:30 +0000 (15:29 +0100)
just a cleanup

Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c

index f0ab9cb1367a4b57ab7e272ba26a94239f8a6aa8..a569a7c30f1a482f8948a819907f51e12200d950 100644 (file)
@@ -1105,3 +1105,19 @@ LLVMValueRef ac_emit_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
                                      AC_FUNC_ATTR_READNONE |
                                      AC_FUNC_ATTR_LEGACY);
 }
+
+/**
+ * KILL, AKA discard in GLSL.
+ *
+ * \param value  kill if value < 0.0 or value == NULL.
+ */
+void ac_emit_kill(struct ac_llvm_context *ctx, LLVMValueRef value)
+{
+       if (value) {
+               ac_emit_llvm_intrinsic(ctx, "llvm.AMDGPU.kill", ctx->voidt,
+                                      &value, 1, AC_FUNC_ATTR_LEGACY);
+       } else {
+               ac_emit_llvm_intrinsic(ctx, "llvm.AMDGPU.kilp", ctx->voidt,
+                                      NULL, 0, AC_FUNC_ATTR_LEGACY);
+       }
+}
index e6e4e434e2ec9fe7b8fea40f6c40307bd4b21e00..af16a2bca73fa510ca002ea6c4f487356dd41931 100644 (file)
@@ -236,6 +236,7 @@ LLVMValueRef ac_emit_image_opcode(struct ac_llvm_context *ctx,
                                  struct ac_image_args *a);
 LLVMValueRef ac_emit_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
                                   LLVMValueRef args[2]);
+void ac_emit_kill(struct ac_llvm_context *ctx, LLVMValueRef value);
 
 #ifdef __cplusplus
 }
index 48b4a94b3c98e63cf9ed668e211268b6292380e9..4fa46d4ff17a420d988453cd476cc41d386f1dfb 100644 (file)
@@ -1940,11 +1940,9 @@ static void si_alpha_test(struct lp_build_tgsi_context *bld_base,
                                        lp_build_const_float(gallivm, 1.0f),
                                        lp_build_const_float(gallivm, -1.0f));
 
-               lp_build_intrinsic(gallivm->builder, "llvm.AMDGPU.kill",
-                                  ctx->voidt, &arg, 1, LP_FUNC_ATTR_LEGACY);
+               ac_emit_kill(&ctx->ac, arg);
        } else {
-               lp_build_intrinsic(gallivm->builder, "llvm.AMDGPU.kilp",
-                                  ctx->voidt, NULL, 0, LP_FUNC_ATTR_LEGACY);
+               ac_emit_kill(&ctx->ac, NULL);
        }
 }
 
@@ -5033,8 +5031,7 @@ static void si_llvm_emit_vertex(
                                       lp_build_const_float(gallivm, 1.0f),
                                       lp_build_const_float(gallivm, -1.0f));
 
-               lp_build_intrinsic(gallivm->builder, "llvm.AMDGPU.kill",
-                                  ctx->voidt, &kill, 1, LP_FUNC_ATTR_LEGACY);
+               ac_emit_kill(&ctx->ac, kill);
        } else {
                lp_build_if(&if_state, gallivm, can_emit);
        }
@@ -5656,8 +5653,7 @@ static void si_llvm_emit_polygon_stipple(struct si_shader_context *ctx,
        /* The intrinsic kills the thread if arg < 0. */
        bit = LLVMBuildSelect(builder, bit, LLVMConstReal(ctx->f32, 0),
                              LLVMConstReal(ctx->f32, -1), "");
-       lp_build_intrinsic(builder, "llvm.AMDGPU.kill", ctx->voidt, &bit, 1,
-                          LP_FUNC_ATTR_LEGACY);
+       ac_emit_kill(&ctx->ac, bit);
 }
 
 void si_shader_binary_read_config(struct ac_shader_binary *binary,
index ee59fed607e8b1e2bcdc1fa1521c5e89512fd9eb..d80848ef84324c006fd8748411632fe679833503 100644 (file)
@@ -26,6 +26,7 @@
 #include "gallivm/lp_bld_intr.h"
 #include "gallivm/lp_bld_gather.h"
 #include "tgsi/tgsi_parse.h"
+#include "amd/common/ac_llvm_build.h"
 
 static void kill_if_fetch_args(struct lp_build_tgsi_context *bld_base,
                               struct lp_build_emit_data *emit_data)
@@ -58,9 +59,12 @@ static void kil_emit(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
-       lp_build_intrinsic(bld_base->base.gallivm->builder,
-                          action->intr_name, emit_data->dst_type,
-                          &emit_data->args[0], 1, LP_FUNC_ATTR_LEGACY);
+       struct si_shader_context *ctx = si_shader_context(bld_base);
+
+       if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_KILL_IF)
+               ac_emit_kill(&ctx->ac, emit_data->args[0]);
+       else
+               ac_emit_kill(&ctx->ac, NULL);
 }
 
 static void emit_icmp(const struct lp_build_tgsi_action *action,
@@ -779,9 +783,7 @@ void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base)
        bld_base->op_actions[TGSI_OPCODE_I2F].emit = emit_i2f;
        bld_base->op_actions[TGSI_OPCODE_KILL_IF].fetch_args = kill_if_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_KILL_IF].emit = kil_emit;
-       bld_base->op_actions[TGSI_OPCODE_KILL_IF].intr_name = "llvm.AMDGPU.kill";
-       bld_base->op_actions[TGSI_OPCODE_KILL].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_KILL].intr_name = "llvm.AMDGPU.kilp";
+       bld_base->op_actions[TGSI_OPCODE_KILL].emit = kil_emit;
        bld_base->op_actions[TGSI_OPCODE_LSB].emit = emit_lsb;
        bld_base->op_actions[TGSI_OPCODE_LG2].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_LG2].intr_name = "llvm.log2.f32";