OSDN Git Service

radeon/llvm: Implement radeon_llvm_parse_bitcode() using C API
authorTom Stellard <thomas.stellard@amd.com>
Thu, 7 Mar 2013 21:51:09 +0000 (16:51 -0500)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 13 Mar 2013 16:01:30 +0000 (16:01 +0000)
Also make the function static since it is not used anywhere else.

src/gallium/drivers/radeon/radeon_llvm_util.cpp
src/gallium/drivers/radeon/radeon_llvm_util.h

index 22c6dc6..5f63ed7 100644 (file)
 #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"
 
 
-extern "C" LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode, unsigned bitcode_len)
+static 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());
+       LLVMMemoryBufferRef buf;
+       LLVMModuleRef module = LLVMModuleCreateWithName("radeon");
+
+       buf = LLVMCreateMemoryBufferWithMemoryRangeCopy((const char*)bitcode,
+                                                       bitcode_len, "radeon");
+       LLVMParseBitcode(buf, &module, NULL);
+       return module;
 }
 
 extern "C" void radeon_llvm_strip_unused_kernels(LLVMModuleRef mod, const char *kernel_name)
index a7dfa9b..e144164 100644 (file)
@@ -7,7 +7,6 @@
 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,