summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/llvm_wrapper.cpp
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2012-09-13 14:59:50 +0000
committerTom Stellard <[email protected]>2012-09-25 14:36:46 +0000
commitb57eba365496307c35373f5c303996731b994f25 (patch)
tree949e648c7e6b5eeeb8815689de1ca9910a513189 /src/gallium/drivers/r600/llvm_wrapper.cpp
parente59505e34bdea772bb439cb42f2ef20ec495de03 (diff)
r600g: Handle multiple kernels in the same program v2
v2: - Use pc parameter of launch_grid
Diffstat (limited to 'src/gallium/drivers/r600/llvm_wrapper.cpp')
-rw-r--r--src/gallium/drivers/r600/llvm_wrapper.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gallium/drivers/r600/llvm_wrapper.cpp b/src/gallium/drivers/r600/llvm_wrapper.cpp
index 174fb013c83..81f53974d11 100644
--- a/src/gallium/drivers/r600/llvm_wrapper.cpp
+++ b/src/gallium/drivers/r600/llvm_wrapper.cpp
@@ -1,9 +1,11 @@
#include <llvm/ADT/OwningPtr.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/LLVMContext.h>
+#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"
@@ -17,3 +19,39 @@ extern "C" LLVMModuleRef llvm_parse_bitcode(const unsigned char * bitcode, unsig
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;
+}