nir: Add lower_rotate flag and set to true in all drivers
[mesa.git] / src / gallium / drivers / radeonsi / si_shader_tgsi_setup.c
index 20164939cb762d5ea39468d503d4774920c3ffe8..33b40685f04a8c96ad6cd36051c53029867b88f0 100644 (file)
@@ -80,7 +80,7 @@ static void si_diagnostic_handler(LLVMDiagnosticInfoRef di, void *context)
  *
  * @returns 0 for success, 1 for failure
  */
-unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
+unsigned si_llvm_compile(LLVMModuleRef M, struct si_shader_binary *binary,
                         struct ac_llvm_compiler *compiler,
                         struct pipe_debug_callback *debug,
                         bool less_optimized)
@@ -100,7 +100,8 @@ unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
        LLVMContextSetDiagnosticHandler(llvm_ctx, si_diagnostic_handler, &diag);
 
        /* Compile IR. */
-       if (!ac_compile_module_to_binary(passes, M, binary))
+       if (!ac_compile_module_to_elf(passes, M, (char **)&binary->elf_buffer,
+                                     &binary->elf_size))
                diag.retval = 1;
 
        if (diag.retval != 0)
@@ -108,6 +109,15 @@ unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
        return diag.retval;
 }
 
+void si_shader_binary_clean(struct si_shader_binary *binary)
+{
+       free((void *)binary->elf_buffer);
+       binary->elf_buffer = NULL;
+
+       free(binary->llvm_ir_string);
+       binary->llvm_ir_string = NULL;
+}
+
 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
                          enum tgsi_opcode_type type)
 {
@@ -317,18 +327,21 @@ static LLVMValueRef
 emit_array_fetch(struct lp_build_tgsi_context *bld_base,
                 unsigned File, enum tgsi_opcode_type type,
                 struct tgsi_declaration_range range,
-                unsigned swizzle)
+                unsigned swizzle_in)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        unsigned i, size = range.Last - range.First + 1;
        LLVMTypeRef vec = LLVMVectorType(tgsi2llvmtype(bld_base, type), size);
        LLVMValueRef result = LLVMGetUndef(vec);
-
+       unsigned swizzle = swizzle_in;
        struct tgsi_full_src_register tmp_reg = {};
        tmp_reg.Register.File = File;
+       if (tgsi_type_is_64bit(type))
+               swizzle |= (swizzle_in + 1) << 16;
 
        for (i = 0; i < size; ++i) {
                tmp_reg.Register.Index = i + range.First;
+
                LLVMValueRef temp = si_llvm_emit_fetch(bld_base, &tmp_reg, type, swizzle);
                result = LLVMBuildInsertElement(ctx->ac.builder, result, temp,
                        LLVMConstInt(ctx->i32, i, 0), "array_vector");
@@ -445,13 +458,14 @@ get_output_ptr(struct lp_build_tgsi_context *bld_base, unsigned index,
 LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
                                const struct tgsi_full_src_register *reg,
                                enum tgsi_opcode_type type,
-                               unsigned swizzle)
+                               unsigned swizzle_in)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMBuilderRef builder = ctx->ac.builder;
        LLVMValueRef result = NULL, ptr, ptr2;
+       unsigned swizzle = swizzle_in & 0xffff;
 
-       if (swizzle == ~0) {
+       if (swizzle_in == ~0) {
                LLVMValueRef values[TGSI_NUM_CHANNELS];
                unsigned chan;
                for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
@@ -476,7 +490,7 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
                                                        ctx->imms[reg->Register.Index * TGSI_NUM_CHANNELS + swizzle],
                                                        ctx->i32_0);
                        result = LLVMConstInsertElement(result,
-                                                       ctx->imms[reg->Register.Index * TGSI_NUM_CHANNELS + swizzle + 1],
+                                                       ctx->imms[reg->Register.Index * TGSI_NUM_CHANNELS + (swizzle_in >> 16)],
                                                        ctx->i32_1);
                        return LLVMConstBitCast(result, ctype);
                } else {
@@ -503,7 +517,7 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
 
                if (tgsi_type_is_64bit(type)) {
                        ptr = result;
-                       ptr2 = input[swizzle + 1];
+                       ptr2 = input[swizzle_in >> 16];
                        return si_llvm_emit_fetch_64bit(bld_base, tgsi2llvmtype(bld_base, type),
                                                        ptr, ptr2);
                }
@@ -515,7 +529,7 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
                        return LLVMGetUndef(tgsi2llvmtype(bld_base, type));
                ptr = ctx->temps[reg->Register.Index * TGSI_NUM_CHANNELS + swizzle];
                if (tgsi_type_is_64bit(type)) {
-                       ptr2 = ctx->temps[reg->Register.Index * TGSI_NUM_CHANNELS + swizzle + 1];
+                       ptr2 = ctx->temps[reg->Register.Index * TGSI_NUM_CHANNELS + (swizzle_in >> 16)];
                        return si_llvm_emit_fetch_64bit(bld_base, tgsi2llvmtype(bld_base, type),
                                                        LLVMBuildLoad(builder, ptr, ""),
                                                        LLVMBuildLoad(builder, ptr2, ""));
@@ -526,7 +540,7 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
        case TGSI_FILE_OUTPUT:
                ptr = get_output_ptr(bld_base, reg->Register.Index, swizzle);
                if (tgsi_type_is_64bit(type)) {
-                       ptr2 = get_output_ptr(bld_base, reg->Register.Index, swizzle + 1);
+                       ptr2 = get_output_ptr(bld_base, reg->Register.Index, (swizzle_in >> 16));
                        return si_llvm_emit_fetch_64bit(bld_base, tgsi2llvmtype(bld_base, type),
                                                        LLVMBuildLoad(builder, ptr, ""),
                                                        LLVMBuildLoad(builder, ptr2, ""));
@@ -544,11 +558,12 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
 static LLVMValueRef fetch_system_value(struct lp_build_tgsi_context *bld_base,
                                       const struct tgsi_full_src_register *reg,
                                       enum tgsi_opcode_type type,
-                                      unsigned swizzle)
+                                      unsigned swizzle_in)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMBuilderRef builder = ctx->ac.builder;
        LLVMValueRef cval = ctx->system_values[reg->Register.Index];
+       unsigned swizzle = swizzle_in & 0xffff;
 
        if (tgsi_type_is_64bit(type)) {
                LLVMValueRef lo, hi;
@@ -558,7 +573,7 @@ static LLVMValueRef fetch_system_value(struct lp_build_tgsi_context *bld_base,
                lo = LLVMBuildExtractElement(
                        builder, cval, LLVMConstInt(ctx->i32, swizzle, 0), "");
                hi = LLVMBuildExtractElement(
-                       builder, cval, LLVMConstInt(ctx->i32, swizzle + 1, 0), "");
+                       builder, cval, LLVMConstInt(ctx->i32, (swizzle_in >> 16), 0), "");
 
                return si_llvm_emit_fetch_64bit(bld_base, tgsi2llvmtype(bld_base, type),
                                                lo, hi);
@@ -646,7 +661,7 @@ static void emit_declaration(struct lp_build_tgsi_context *bld_base,
                }
                if (!array_alloca) {
                        for (i = 0; i < decl_size; ++i) {
-#ifdef DEBUG
+#ifndef NDEBUG
                                snprintf(name, sizeof(name), "TEMP%d.%c",
                                         first + i / 4, "xyzw"[i % 4]);
 #endif
@@ -676,7 +691,7 @@ static void emit_declaration(struct lp_build_tgsi_context *bld_base,
                        for (i = 0; i < decl_size; ++i) {
                                LLVMValueRef ptr;
                                if (writemask & (1 << (i % 4))) {
-#ifdef DEBUG
+#ifndef NDEBUG
                                        snprintf(name, sizeof(name), "TEMP%d.%c",
                                                 first + i / 4, "xyzw"[i % 4]);
 #endif
@@ -730,7 +745,7 @@ static void emit_declaration(struct lp_build_tgsi_context *bld_base,
                        if (ctx->outputs[idx][0])
                                continue;
                        for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
-#ifdef DEBUG
+#ifndef NDEBUG
                                snprintf(name, sizeof(name), "OUT%d.%c",
                                         idx, "xyzw"[chan % 4]);
 #endif