summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/radeon
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2013-03-07 16:51:08 -0500
committerTom Stellard <[email protected]>2013-03-13 16:01:30 +0000
commit97bfcddde0a0e827cb868b38c7da8d8692da6cce (patch)
tree31b9cba3e9baacdf8d61cedeaa2f17addc28d637 /src/gallium/drivers/radeon
parent28e169363033aff7752382d790886eaadd4787f9 (diff)
r600g/llvm: Move llvm wrapper functions into the radeon directory
Diffstat (limited to 'src/gallium/drivers/radeon')
-rw-r--r--src/gallium/drivers/radeon/Makefile.sources3
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm_util.cpp62
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm_util.h20
3 files changed, 84 insertions, 1 deletions
diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources
index 39f9532fe40..aa327490f44 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 00000000000..22c6dc6f65c
--- /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 00000000000..a7dfa9baf56
--- /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