[Beignet] [PATCH 1/3] Use llvm-c's LLVMLinkModules instead of llvm::Linker::LinkModules.

Yang Rong rong.r.yang at intel.com
Thu Feb 12 00:29:39 PST 2015


llvm::Linker::LinkModules's define will be changed in llvm3.6, and LLVMLinkModules'
define is more stable, so use LLVMLinkModules to link.

Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 backend/src/backend/gen_program.cpp    | 22 +++++++---------------
 backend/src/llvm/llvm_bitcode_link.cpp | 18 +++++++-----------
 2 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 4cfb703..a4019fe 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -33,12 +33,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/DataLayout.h"
 #endif  /* LLVM_VERSION_MINOR <= 2 */
-
-#if LLVM_VERSION_MINOR >= 5
-#include "llvm/Linker/Linker.h"
-#else
-#include "llvm/Linker.h"
-#endif
+#include "llvm-c/Linker.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/raw_ostream.h"
@@ -379,22 +374,19 @@ namespace gbe {
   {
 #ifdef GBE_COMPILER_AVAILABLE
     using namespace gbe;
-    std::string errMsg;
+    char* errMsg;
     if(((GenProgram*)dst_program)->module == NULL){
       ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module);
       errSize = 0;
     }else{
       llvm::Module* src = (llvm::Module*)((GenProgram*)src_program)->module;
       llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module;
-      llvm::Linker::LinkModules( dst,
-                                 src,
-                                 llvm::Linker::PreserveSource,
-                                 &errMsg);
-      if (errMsg.c_str() != NULL) {
+
+      if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) {
         if (err != NULL && errSize != NULL && stringSize > 0u) {
-          if(errMsg.length() < stringSize )
-            stringSize = errMsg.length();
-          strcpy(err, errMsg.c_str());
+          if(strlen(errMsg) < stringSize )
+            stringSize = strlen(errMsg);
+          strcpy(err, errMsg);
           err[stringSize+1] = '\0';
         }
       }
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
index d3058d6..8eb6dd5 100644
--- a/backend/src/llvm/llvm_bitcode_link.cpp
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
@@ -38,11 +38,7 @@
 #include "sys/cvar.hpp"
 #include "src/GBEConfig.h"
 #include "llvm/llvm_gen_backend.hpp"
-#if LLVM_VERSION_MINOR >= 5
-#include "llvm/Linker/Linker.h"
-#else
-#include "llvm/Linker.h"
-#endif
+#include "llvm-c/Linker.h"
 
 using namespace llvm;
 
@@ -110,10 +106,10 @@ namespace gbe
         if (!newMF) {
           newMF = src.getFunction(fnName);
           if (!newMF) {
-	    printf("Can not find the lib: %s\n", fnName.c_str());
-	    return false;
+            printf("Can not find the lib: %s\n", fnName.c_str());
+            return false;
           }
-	  fromSrc = true;
+          fromSrc = true;
         }
 
         std::string ErrInfo;// = "Not Materializable";
@@ -226,10 +222,10 @@ namespace gbe
 
     /* We use beignet's bitcode as dst because it will have a lot of
        lazy functions which will not be loaded. */
-    std::string errorMsg;
-    if(Linker::LinkModules(clonedLib, mod, Linker::DestroySource, &errorMsg)) {
+    char* errorMsg;
+    if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) {
       delete clonedLib;
-      printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg.c_str());
+      printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
       return NULL;
     }
 
-- 
1.8.3.2



More information about the Beignet mailing list