radeon/llvm: Optimize radeon_llvm_strip_unused_kernels()
authorTom Stellard <thomas.stellard@amd.com>
Thu, 7 Mar 2013 21:51:12 +0000 (16:51 -0500)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 13 Mar 2013 16:01:31 +0000 (16:01 +0000)
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
src/gallium/drivers/radeon/radeon_llvm_util.h

index 17a312280874159eff17bc5e38b26d3265dbbc03..aa9f3b3c74cfb904e8ab2a72702932b6cc883e4c 100644 (file)
@@ -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;
 }
index e144164b759d102af417f7f78ff80db52a5591e5..1e827ba0d7ced7cdc4ffdcabedf337e71827655c 100644 (file)
@@ -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);