[Mesa-dev] [PATCH 1/7] r600g/llvm: Move llvm wrapper functions into the radeon directory

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


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

---
 src/gallium/drivers/r600/Makefile.am            |    6 +--
 src/gallium/drivers/r600/Makefile.sources       |    1 -
 src/gallium/drivers/r600/evergreen_compute.c    |    6 +-
 src/gallium/drivers/r600/llvm_wrapper.cpp       |   61 ----------------------
 src/gallium/drivers/r600/llvm_wrapper.h         |   20 -------
 src/gallium/drivers/radeon/Makefile.sources     |    3 +-
 src/gallium/drivers/radeon/radeon_llvm_util.cpp |   62 +++++++++++++++++++++++
 src/gallium/drivers/radeon/radeon_llvm_util.h   |   20 +++++++
 8 files changed, 88 insertions(+), 91 deletions(-)
 delete mode 100644 src/gallium/drivers/r600/llvm_wrapper.cpp
 delete mode 100644 src/gallium/drivers/r600/llvm_wrapper.h
 create mode 100644 src/gallium/drivers/radeon/radeon_llvm_util.cpp
 create mode 100644 src/gallium/drivers/radeon/radeon_llvm_util.h

diff --git a/src/gallium/drivers/r600/Makefile.am b/src/gallium/drivers/r600/Makefile.am
index e1c8574..a067f2c 100644
--- a/src/gallium/drivers/r600/Makefile.am
+++ b/src/gallium/drivers/r600/Makefile.am
@@ -16,8 +16,7 @@ libr600_la_SOURCES = \
 if R600_NEED_RADEON_GALLIUM
 
 libr600_la_SOURCES += \
-	$(LLVM_C_SOURCES) \
-	$(LLVM_CXX_SOURCES)
+	$(LLVM_C_SOURCES)
 
 libr600_la_LIBADD = ../radeon/libllvmradeon at VERSION@.la
 
@@ -25,9 +24,6 @@ AM_CFLAGS += \
 	$(LLVM_CFLAGS) \
 	-I$(top_srcdir)/src/gallium/drivers/radeon/
 
-AM_CXXFLAGS= \
-	$(LLVM_CXXFLAGS) \
-	$(DEFINES)
 endif
 
 if USE_R600_LLVM_COMPILER
diff --git a/src/gallium/drivers/r600/Makefile.sources b/src/gallium/drivers/r600/Makefile.sources
index a99ef11..b51f274 100644
--- a/src/gallium/drivers/r600/Makefile.sources
+++ b/src/gallium/drivers/r600/Makefile.sources
@@ -20,4 +20,3 @@ C_SOURCES = \
 	compute_memory_pool.c
 
 LLVM_C_SOURCES = r600_llvm.c
-LLVM_CXX_SOURCES = llvm_wrapper.cpp
diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 8b3104e..4c9d3a6 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -49,7 +49,7 @@
 #include "evergreen_compute_internal.h"
 #include "compute_memory_pool.h"
 #ifdef HAVE_OPENCL
-#include "llvm_wrapper.h"
+#include "radeon_llvm_util.h"
 #endif
 
 /**
@@ -142,12 +142,12 @@ void *evergreen_create_compute_state(
 	shader->input_size = cso->req_input_mem;
 
 #ifdef HAVE_OPENCL 
-	shader->num_kernels = llvm_get_num_kernels(code, header->num_bytes);
+	shader->num_kernels = radeon_llvm_get_num_kernels(code, header->num_bytes);
 	shader->kernels = CALLOC(sizeof(struct r600_kernel), shader->num_kernels);
 
 	for (i = 0; i < shader->num_kernels; i++) {
 		struct r600_kernel *kernel = &shader->kernels[i];
-		kernel->llvm_module = llvm_get_kernel_module(i, code,
+		kernel->llvm_module = radeon_llvm_get_kernel_module(i, code,
 							header->num_bytes);
 	}
 #endif
diff --git a/src/gallium/drivers/r600/llvm_wrapper.cpp b/src/gallium/drivers/r600/llvm_wrapper.cpp
deleted file mode 100644
index ae2f4d2..0000000
--- a/src/gallium/drivers/r600/llvm_wrapper.cpp
+++ /dev/null
@@ -1,61 +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_wrapper.h"
-
-
-extern "C" LLVMModuleRef llvm_parse_bitcode(const unsigned char * bitcode, unsigned bitcode_len)
-{
-	llvm::OwningPtr<llvm::Module> M;
-	llvm::StringRef str((const char*)bitcode, bitcode_len);
-	llvm::MemoryBuffer*  buffer = llvm::MemoryBuffer::getMemBufferCopy(str);
-	llvm::SMDiagnostic Err;
-	M.reset(llvm::ParseIR(buffer, Err, llvm::getGlobalContext()));
-	return wrap(M.take());
-}
-
-extern "C" void 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 llvm_get_num_kernels(const unsigned char *bitcode,
-				unsigned bitcode_len)
-{
-	LLVMModuleRef mod = llvm_parse_bitcode(bitcode, bitcode_len);
-	llvm::Module *M = llvm::unwrap(mod);
-	const llvm::NamedMDNode *kernel_node
-				= M->getNamedMetadata("opencl.kernels");
-	unsigned kernel_count = kernel_node->getNumOperands();
-	delete M;
-	return kernel_count;
-}
-
-extern "C" LLVMModuleRef llvm_get_kernel_module(unsigned index,
-		const unsigned char *bitcode, unsigned bitcode_len)
-{
-	LLVMModuleRef mod = llvm_parse_bitcode(bitcode, bitcode_len);
-	llvm::Module *M = llvm::unwrap(mod);
-	const llvm::NamedMDNode *kernel_node =
-				M->getNamedMetadata("opencl.kernels");
-	const char* kernel_name = kernel_node->getOperand(index)->
-					getOperand(0)->getName().data();
-	llvm_strip_unused_kernels(mod, kernel_name);
-	return mod;
-}
diff --git a/src/gallium/drivers/r600/llvm_wrapper.h b/src/gallium/drivers/r600/llvm_wrapper.h
deleted file mode 100644
index 4b9b93f..0000000
--- a/src/gallium/drivers/r600/llvm_wrapper.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef LLVM_WRAPPER_H
-#define LLVM_WRAPPER_H
-
-#include <llvm-c/Core.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-LLVMModuleRef llvm_parse_bitcode(const unsigned char * bitcode, unsigned bitcode_len);
-void llvm_strip_unused_kernels(LLVMModuleRef mod, const char *kernel_name);
-unsigned llvm_get_num_kernels(const unsigned char *bitcode, unsigned bitcode_len);
-LLVMModuleRef llvm_get_kernel_module(unsigned index,
-			const unsigned char *bitcode, unsigned bitcode_len);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources
index 39f9532..aa32749 100644
--- a/src/gallium/drivers/radeon/Makefile.sources
+++ b/src/gallium/drivers/radeon/Makefile.sources
@@ -1,5 +1,6 @@
 CPP_FILES := \
-	radeon_llvm_emit.cpp
+	radeon_llvm_emit.cpp \
+	radeon_llvm_util.cpp
 
 C_FILES := \
 	radeon_setup_tgsi_llvm.c
diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.cpp b/src/gallium/drivers/radeon/radeon_llvm_util.cpp
new file mode 100644
index 0000000..22c6dc6
--- /dev/null
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.cpp
@@ -0,0 +1,62 @@
+#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 "radeon_llvm_util.h"
+
+
+extern "C" LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode, unsigned bitcode_len)
+{
+	llvm::OwningPtr<llvm::Module> M;
+	llvm::StringRef str((const char*)bitcode, bitcode_len);
+	llvm::MemoryBuffer*  buffer = llvm::MemoryBuffer::getMemBufferCopy(str);
+	llvm::SMDiagnostic Err;
+	M.reset(llvm::ParseIR(buffer, Err, llvm::getGlobalContext()));
+	return wrap(M.take());
+}
+
+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)
+{
+	LLVMModuleRef mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len);
+	llvm::Module *M = llvm::unwrap(mod);
+	const llvm::NamedMDNode *kernel_node
+				= M->getNamedMetadata("opencl.kernels");
+	unsigned kernel_count = kernel_node->getNumOperands();
+	delete M;
+	return kernel_count;
+}
+
+extern "C" LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
+		const unsigned char *bitcode, unsigned bitcode_len)
+{
+	LLVMModuleRef mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len);
+	llvm::Module *M = llvm::unwrap(mod);
+	const llvm::NamedMDNode *kernel_node =
+				M->getNamedMetadata("opencl.kernels");
+	const char* kernel_name = kernel_node->getOperand(index)->
+					getOperand(0)->getName().data();
+	radeon_llvm_strip_unused_kernels(mod, kernel_name);
+	return mod;
+
+}
diff --git a/src/gallium/drivers/radeon/radeon_llvm_util.h b/src/gallium/drivers/radeon/radeon_llvm_util.h
new file mode 100644
index 0000000..a7dfa9b
--- /dev/null
+++ b/src/gallium/drivers/radeon/radeon_llvm_util.h
@@ -0,0 +1,20 @@
+#ifndef RADEON_LLVM_UTIL_H
+#define RADEON_LLVM_UTIL_H
+
+#include <llvm-c/Core.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode, unsigned bitcode_len);
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
-- 
1.7.8.6



More information about the mesa-dev mailing list