From 1c4f283151b191c51cbd76d7f304cc1fe7be3019 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 7 Mar 2013 16:51:13 -0500 Subject: radeon/llvm: Make radeon_llvm_util.cpp a C file All the functions in this file are now implemented in C. --- src/gallium/drivers/radeon/Makefile.sources | 6 +-- src/gallium/drivers/radeon/radeon_llvm_util.c | 49 +++++++++++++++++++ src/gallium/drivers/radeon/radeon_llvm_util.cpp | 62 ------------------------- src/gallium/drivers/radeon/radeon_llvm_util.h | 8 ---- 4 files changed, 52 insertions(+), 73 deletions(-) create mode 100644 src/gallium/drivers/radeon/radeon_llvm_util.c delete mode 100644 src/gallium/drivers/radeon/radeon_llvm_util.cpp (limited to 'src/gallium/drivers/radeon') diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources index aa327490f44..efe0e6bb4da 100644 --- a/src/gallium/drivers/radeon/Makefile.sources +++ b/src/gallium/drivers/radeon/Makefile.sources @@ -1,6 +1,6 @@ CPP_FILES := \ - radeon_llvm_emit.cpp \ - radeon_llvm_util.cpp + radeon_llvm_emit.cpp C_FILES := \ - radeon_setup_tgsi_llvm.c + radeon_setup_tgsi_llvm.c \ + radeon_llvm_util.c diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.c b/src/gallium/drivers/radeon/radeon_llvm_util.c new file mode 100644 index 00000000000..3d30612ffd9 --- /dev/null +++ b/src/gallium/drivers/radeon/radeon_llvm_util.c @@ -0,0 +1,49 @@ +#include "radeon_llvm_util.h" +#include "util/u_memory.h" + +#include +#include + +static LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode, + unsigned bitcode_len) +{ + LLVMMemoryBufferRef buf; + LLVMModuleRef module = LLVMModuleCreateWithName("radeon"); + + buf = LLVMCreateMemoryBufferWithMemoryRangeCopy((const char*)bitcode, + bitcode_len, "radeon"); + LLVMParseBitcode(buf, &module, NULL); + return module; +} + +unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode, + unsigned bitcode_len) +{ + LLVMModuleRef mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len); + return LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels"); +} + +LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index, + const unsigned char *bitcode, unsigned bitcode_len) +{ + LLVMModuleRef mod; + unsigned num_kernels; + LLVMValueRef *kernel_metadata; + unsigned i; + + mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len); + num_kernels = LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels"); + kernel_metadata = MALLOC(num_kernels * sizeof(LLVMValueRef)); + LLVMGetNamedMetadataOperands(mod, "opencl.kernels", kernel_metadata); + 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.cpp b/src/gallium/drivers/radeon/radeon_llvm_util.cpp deleted file mode 100644 index aa9f3b3c74c..00000000000 --- a/src/gallium/drivers/radeon/radeon_llvm_util.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#if HAVE_LLVM < 0x0303 -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -#include "radeon_llvm_util.h" -#include "util/u_memory.h" - - -static LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode, - unsigned bitcode_len) -{ - LLVMMemoryBufferRef buf; - LLVMModuleRef module = LLVMModuleCreateWithName("radeon"); - - buf = LLVMCreateMemoryBufferWithMemoryRangeCopy((const char*)bitcode, - bitcode_len, "radeon"); - LLVMParseBitcode(buf, &module, NULL); - return module; -} - -extern "C" unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode, - unsigned bitcode_len) -{ - LLVMModuleRef mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len); - return LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels"); -} - -extern "C" LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index, - const unsigned char *bitcode, unsigned bitcode_len) -{ - LLVMModuleRef mod; - unsigned num_kernels; - LLVMValueRef *kernel_metadata; - 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); - 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 1e827ba0d7c..a5870306195 100644 --- a/src/gallium/drivers/radeon/radeon_llvm_util.h +++ b/src/gallium/drivers/radeon/radeon_llvm_util.h @@ -3,16 +3,8 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - 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); -#ifdef __cplusplus -} -#endif - #endif -- cgit v1.2.3