amd/common: use ac_build_buffer_load() for emitting UBO loads
[mesa.git] / src / amd / common / ac_llvm_util.c
index 2598875ab70a4ae4d021bc09c7c2184c38beb848..429904c04036399366f2029398e269a3aa24d883 100644 (file)
@@ -26,7 +26,7 @@
 #include "ac_llvm_util.h"
 #include "util/bitscan.h"
 #include <llvm-c/Core.h>
-
+#include <llvm-c/Support.h>
 #include "c11/threads.h"
 
 #include <assert.h>
 
 static void ac_init_llvm_target()
 {
-#if HAVE_LLVM < 0x0307
-       LLVMInitializeR600TargetInfo();
-       LLVMInitializeR600Target();
-       LLVMInitializeR600TargetMC();
-       LLVMInitializeR600AsmPrinter();
-#else
        LLVMInitializeAMDGPUTargetInfo();
        LLVMInitializeAMDGPUTarget();
        LLVMInitializeAMDGPUTargetMC();
        LLVMInitializeAMDGPUAsmPrinter();
-#endif
+
+       /* For inline assembly. */
+       LLVMInitializeAMDGPUAsmParser();
+
+       /* Workaround for bug in llvm 4.0 that causes image intrinsics
+        * to disappear.
+        * https://reviews.llvm.org/D26348
+        */
+       if (HAVE_LLVM >= 0x0400) {
+               /* "mesa" is the prefix for error messages */
+               const char *argv[2] = { "mesa", "-simplifycfg-sink-common=false" };
+               LLVMParseCommandLineOptions(2, argv, NULL);
+       }
 }
 
 static once_flag ac_init_llvm_target_once_flag = ONCE_FLAG_INIT;
 
-static LLVMTargetRef ac_get_llvm_target(const char *triple)
+LLVMTargetRef ac_get_llvm_target(const char *triple)
 {
        LLVMTargetRef target = NULL;
        char *err_message = NULL;
@@ -68,7 +74,7 @@ static LLVMTargetRef ac_get_llvm_target(const char *triple)
        return target;
 }
 
-static const char *ac_get_llvm_processor_name(enum radeon_family family)
+const char *ac_get_llvm_processor_name(enum radeon_family family)
 {
        switch (family) {
        case CHIP_TAHITI:
@@ -97,44 +103,42 @@ static const char *ac_get_llvm_processor_name(enum radeon_family family)
                return "iceland";
        case CHIP_CARRIZO:
                return "carrizo";
-#if HAVE_LLVM <= 0x0307
-       case CHIP_FIJI:
-               return "tonga";
-       case CHIP_STONEY:
-               return "carrizo";
-#else
        case CHIP_FIJI:
                return "fiji";
        case CHIP_STONEY:
                return "stoney";
-#endif
-#if HAVE_LLVM <= 0x0308
-       case CHIP_POLARIS10:
-               return "tonga";
-       case CHIP_POLARIS11:
-               return "tonga";
-#else
        case CHIP_POLARIS10:
                return "polaris10";
        case CHIP_POLARIS11:
+       case CHIP_POLARIS12:
                return "polaris11";
-#endif
+       case CHIP_VEGA10:
+       case CHIP_RAVEN:
+               return "gfx900";
        default:
                return "";
        }
 }
 
-LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family, bool supports_spill)
+LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family, enum ac_target_machine_options tm_options)
 {
        assert(family >= CHIP_TAHITI);
-
-       const char *triple = supports_spill ? "amdgcn-mesa-mesa3d" : "amdgcn--";
+       char features[256];
+       const char *triple = (tm_options & AC_TM_SUPPORTS_SPILL) ? "amdgcn-mesa-mesa3d" : "amdgcn--";
        LLVMTargetRef target = ac_get_llvm_target(triple);
+
+       snprintf(features, sizeof(features),
+                "+DumpCode,+vgpr-spilling,-fp32-denormals,+fp64-denormals%s%s%s%s",
+                tm_options & AC_TM_SISCHED ? ",+si-scheduler" : "",
+                tm_options & AC_TM_FORCE_ENABLE_XNACK ? ",+xnack" : "",
+                tm_options & AC_TM_FORCE_DISABLE_XNACK ? ",-xnack" : "",
+                tm_options & AC_TM_PROMOTE_ALLOCA_TO_SCRATCH ? ",-promote-alloca" : "");
+       
        LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
                                     target,
                                     triple,
                                     ac_get_llvm_processor_name(family),
-                                    "+DumpCode,+vgpr-spilling",
+                                    features,
                                     LLVMCodeGenLevelDefault,
                                     LLVMRelocDefault,
                                     LLVMCodeModelDefault);
@@ -174,6 +178,7 @@ static const char *attr_to_str(enum ac_func_attr attr)
    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:
           fprintf(stderr, "Unhandled function attribute: %x\n", attr);
           return 0;
@@ -225,3 +230,13 @@ ac_dump_module(LLVMModuleRef module)
        fprintf(stderr, "%s", str);
        LLVMDisposeMessage(str);
 }
+
+void
+ac_llvm_add_target_dep_function_attr(LLVMValueRef F,
+                                    const char *name, int value)
+{
+       char str[16];
+
+       snprintf(str, sizeof(str), "%i", value);
+       LLVMAddTargetDependentFunctionAttr(F, name, str);
+}