ac/radeonsi: port compiler init/destroy out of radeonsi.
authorDave Airlie <airlied@redhat.com>
Mon, 2 Jul 2018 23:51:42 +0000 (09:51 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 4 Jul 2018 00:29:03 +0000 (10:29 +1000)
We want to share this code with radv in the future, so port
it out of radeonsi.

Add a return value as radv will want that to know if this
succeeds

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_llvm_util.c
src/amd/common/ac_llvm_util.h
src/gallium/drivers/radeonsi/si_pipe.c

index 01852dbff4664f36e238b7efc56cd502ee4af39a..fa85c625b336907caa7475c455562588f817aed5 100644 (file)
@@ -282,3 +282,46 @@ ac_count_scratch_private_memory(LLVMValueRef function)
 
        return private_mem_vgprs;
 }
+
+bool
+ac_init_llvm_compiler(struct ac_llvm_compiler *compiler,
+                     enum radeon_family family,
+                     enum ac_target_machine_options tm_options)
+{
+       const char *triple;
+       memset(compiler, 0, sizeof(*compiler));
+
+       compiler->tm = ac_create_target_machine(family,
+                                           tm_options, &triple);
+       if (!compiler->tm)
+               return false;
+
+       compiler->target_library_info =
+               ac_create_target_library_info(triple);
+       if (!compiler->target_library_info)
+               goto fail;
+
+       compiler->passmgr = ac_create_passmgr(compiler->target_library_info,
+                                             tm_options & AC_TM_CHECK_IR);
+       if (!compiler->passmgr)
+               goto fail;
+
+       return true;
+fail:
+       ac_destroy_llvm_compiler(compiler);
+       return false;
+}
+
+void
+ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler)
+{
+       if (compiler->passmgr)
+               LLVMDisposePassManager(compiler->passmgr);
+#if HAVE_LLVM >= 0x0700
+       /* This crashes on LLVM 5.0 and 6.0 and Ubuntu 18.04, so leak it there. */
+       if (compiler->target_library_info)
+               ac_dispose_target_library_info(compiler->target_library_info);
+#endif
+       if (compiler->tm)
+               LLVMDisposeTargetMachine(compiler->tm);
+}
index 2a8f691136590c77e9eab6836edfce4b9cb1508d..cd56ff5f41cf31199c977a86b4324142f13706bb 100644 (file)
@@ -125,6 +125,12 @@ LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple);
 void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info);
 void ac_init_llvm_once(void);
 
+
+bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler,
+                          enum radeon_family family,
+                          enum ac_target_machine_options tm_options);
+void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler);
+
 #ifdef __cplusplus
 }
 #endif
index 5ac1a12a0585b56d734e15fc1f9195fc5bbb126d..ad0ca7c6169f2db3be9a1e2cb7f762bc88575c90 100644 (file)
@@ -114,35 +114,12 @@ static void si_init_compiler(struct si_screen *sscreen,
                (!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0) |
                (sscreen->debug_flags & DBG(CHECK_IR) ? AC_TM_CHECK_IR : 0);
 
-       const char *triple;
-       ac_init_llvm_once();
-       compiler->tm = ac_create_target_machine(sscreen->info.family,
-                                               tm_options, &triple);
-       if (!compiler->tm)
-               return;
-
-       compiler->target_library_info =
-               gallivm_create_target_library_info(triple);
-       if (!compiler->target_library_info)
-               return;
-
-       compiler->passmgr = ac_create_passmgr(compiler->target_library_info,
-                                             tm_options & AC_TM_CHECK_IR);
-       if (!compiler->passmgr)
-               return;
+       ac_init_llvm_compiler(compiler, sscreen->info.family, tm_options);
 }
 
 static void si_destroy_compiler(struct ac_llvm_compiler *compiler)
 {
-       if (compiler->passmgr)
-               LLVMDisposePassManager(compiler->passmgr);
-#if HAVE_LLVM >= 0x0700
-       /* This crashes on LLVM 5.0 and 6.0 and Ubuntu 18.04, so leak it there. */
-       if (compiler->target_library_info)
-               gallivm_dispose_target_library_info(compiler->target_library_info);
-#endif
-       if (compiler->tm)
-               LLVMDisposeTargetMachine(compiler->tm);
+       ac_destroy_llvm_compiler(compiler);
 }
 
 /*