[Mesa-dev] [PATCH 5/7] radeon/llvm: Optimize radeon_llvm_strip_unused_kernels()
Tom Stellard
tom at stellard.net
Thu Mar 7 13:51:12 PST 2013
From: Tom Stellard <thomas.stellard at amd.com>
Just delete unused kernels rather than marking them as internal and
running the GlobalDCE pass.
Also implement this function in C and inline it into
radeon_llvm_get_kernel_module()
---
src/gallium/drivers/radeon/radeon_llvm_util.cpp | 26 ++++++++--------------
src/gallium/drivers/radeon/radeon_llvm_util.h | 1 -
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.cpp b/src/gallium/drivers/radeon/radeon_llvm_util.cpp
index 17a3122..aa9f3b3 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_util.cpp
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.cpp
@@ -29,17 +29,6 @@ static LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode,
return module;
}
-extern "C" void radeon_llvm_strip_unused_kernels(LLVMModuleRef mod, const char *kernel_name)
-{
- llvm::Module *M = llvm::unwrap(mod);
- std::vector<const char *> export_list;
- export_list.push_back(kernel_name);
- llvm::PassManager PM;
- PM.add(llvm::createInternalizePass(export_list));
- PM.add(llvm::createGlobalDCEPass());
- PM.run(*M);
-}
-
extern "C" unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode,
unsigned bitcode_len)
{
@@ -53,16 +42,21 @@ extern "C" LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
LLVMModuleRef mod;
unsigned num_kernels;
LLVMValueRef *kernel_metadata;
- LLVMValueRef kernel_signature, kernel_function;
+ unsigned i;
mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len);
num_kernels = LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels");
kernel_metadata = (LLVMValueRef*)MALLOC(num_kernels * sizeof(LLVMValueRef));
LLVMGetNamedMetadataOperands(mod, "opencl.kernels", kernel_metadata);
- kernel_signature = kernel_metadata[index];
- LLVMGetMDNodeOperands(kernel_signature, &kernel_function);
- const char* kernel_name = LLVMGetValueName(kernel_function);
- radeon_llvm_strip_unused_kernels(mod, kernel_name);
+ for (i = 0; i < num_kernels; i++) {
+ LLVMValueRef kernel_signature, kernel_function;
+ if (i == index) {
+ continue;
+ }
+ kernel_signature = kernel_metadata[i];
+ LLVMGetMDNodeOperands(kernel_signature, &kernel_function);
+ LLVMDeleteFunction(kernel_function);
+ }
FREE(kernel_metadata);
return mod;
}
diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.h b/src/gallium/drivers/radeon/radeon_llvm_util.h
index e144164..1e827ba 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_util.h
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.h
@@ -7,7 +7,6 @@
extern "C" {
#endif
-void radeon_llvm_strip_unused_kernels(LLVMModuleRef mod, const char *kernel_name);
unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode, unsigned bitcode_len);
LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
const unsigned char *bitcode, unsigned bitcode_len);
--
1.7.8.6
More information about the mesa-dev
mailing list