[Mesa-dev] [PATCH 6/7] radeon/llvm: Make radeon_llvm_util.cpp a C file

Tom Stellard tom at stellard.net
Thu Mar 7 13:51:13 PST 2013


From: Tom Stellard <thomas.stellard at amd.com>

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

diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources
index aa32749..efe0e6b 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 0000000..3d30612
--- /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 <llvm-c/BitReader.h>
+#include <llvm-c/Core.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;
+}
+
+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 aa9f3b3..0000000
--- a/src/gallium/drivers/radeon/radeon_llvm_util.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <llvm/ADT/OwningPtr.h>
-#include <llvm/ADT/StringRef.h>
-#if HAVE_LLVM < 0x0303
-#include <llvm/LLVMContext.h>
-#else
-#include <llvm/IR/LLVMContext.h>
-#endif
-#include <llvm/PassManager.h>
-#include <llvm/Support/IRReader.h>
-#include <llvm/Support/MemoryBuffer.h>
-#include <llvm/Support/SourceMgr.h>
-#include <llvm/Transforms/IPO.h>
-#include <llvm-c/BitReader.h>
-#include <llvm-c/Core.h>
-
-#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 1e827ba..a587030 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_util.h
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.h
@@ -3,16 +3,8 @@
 
 #include <llvm-c/Core.h>
 
-#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
-- 
1.7.8.6



More information about the mesa-dev mailing list