[Mesa-dev] [PATCH] radeon/llvm: Run standard optimization passes on compute shader modules
Tom Stellard
tom at stellard.net
Tue May 14 16:06:24 PDT 2013
From: Tom Stellard <thomas.stellard at amd.com>
The SROA and function inliner passes are espically important, because
they optimize away unsupported features: functions and indirect
private memory access.
---
src/gallium/drivers/r600/evergreen_compute.c | 2 +-
src/gallium/drivers/radeon/radeon_llvm_util.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 5f67759..2d73ee5 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -214,7 +214,7 @@ void *evergreen_create_compute_state(
shader->private_size = cso->req_private_mem;
shader->input_size = cso->req_input_mem;
-#ifdef HAVE_OPENCL
+#ifdef HAVE_OPENCL
shader->num_kernels = radeon_llvm_get_num_kernels(code, header->num_bytes);
shader->kernels = CALLOC(sizeof(struct r600_kernel), shader->num_kernels);
diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.c b/src/gallium/drivers/radeon/radeon_llvm_util.c
index e3b0d63..5a7bcd9 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_util.c
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.c
@@ -29,6 +29,7 @@
#include <llvm-c/BitReader.h>
#include <llvm-c/Core.h>
+#include <llvm-c/Transforms/PassManagerBuilder.h>
LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode,
unsigned bitcode_len)
@@ -50,6 +51,19 @@ unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode,
return LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels");
}
+static void radeon_llvm_optimize(LLVMModuleRef mod)
+{
+ LLVMPassManagerBuilderRef builder = LLVMPassManagerBuilderCreate();
+ LLVMPassManagerRef pass_manager = LLVMCreatePassManager();
+
+ LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 1000000000);
+ LLVMPassManagerBuilderPopulateModulePassManager(builder, pass_manager);
+
+ LLVMRunPassManager(pass_manager, mod);
+ LLVMPassManagerBuilderDispose(builder);
+ LLVMDisposePassManager(pass_manager);
+}
+
LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
const unsigned char *bitcode, unsigned bitcode_len)
{
@@ -72,5 +86,7 @@ LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
LLVMDeleteFunction(kernel_function);
}
FREE(kernel_metadata);
+ radeon_llvm_optimize(mod);
return mod;
}
+
--
1.8.1.5
More information about the mesa-dev
mailing list