Blame SOURCES/beignet-llvm7.patch

4c80fc
From e1b2419a0008e38ef2d9d255d9e9c74e9fba084b Mon Sep 17 00:00:00 2001
4c80fc
From: "Rebecca N. Palmer" <rebecca_palmer@zoho.com>
4c80fc
Date: Sat, 21 Jul 2018 20:05:54 +0100
4c80fc
Subject: Add preliminary LLVM 7 support
4c80fc
4c80fc
This is preliminary because LLVM 7 has not been released yet:
4c80fc
it was tested with the snapshot from Debian experimental (svn336894).
4c80fc
4c80fc
1.Change linking order, as clangCodeGen now links to clangFrontend
4c80fc
2.Pass references not pointers to WriteBitcodeToFile and CloneModule
4c80fc
3.Add the headers that LoopSimplifyID, LCSSAID and
4c80fc
some create*Pass have moved to
4c80fc
4.Define our DEBUG whether or not we just undefined LLVM's
4c80fc
(theirs is now LLVM_DEBUG, but we never actually use it)
4c80fc
4c80fc
Signed-off-by: Rebecca N. Palmer <rebecca_palmer@zoho.com>
4c80fc
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
4c80fc
---
4c80fc
 CMake/FindLLVM.cmake                     | 2 +-
4c80fc
 backend/src/backend/gen_program.cpp      | 8 ++++++++
4c80fc
 backend/src/backend/program.cpp          | 4 ++++
4c80fc
 backend/src/llvm/ExpandLargeIntegers.cpp | 2 +-
4c80fc
 backend/src/llvm/llvm_bitcode_link.cpp   | 4 ++++
4c80fc
 backend/src/llvm/llvm_includes.hpp       | 4 ++++
4c80fc
 6 files changed, 22 insertions(+), 2 deletions(-)
4c80fc
4c80fc
diff --git a/CMake/FindLLVM.cmake b/CMake/FindLLVM.cmake
4c80fc
index 5457f24..f882589 100644
4c80fc
--- a/CMake/FindLLVM.cmake
4c80fc
+++ b/CMake/FindLLVM.cmake
4c80fc
@@ -113,10 +113,10 @@ macro(add_one_lib name)
4c80fc
 endmacro()
4c80fc
 
4c80fc
 #Assume clang lib path same as llvm lib path
4c80fc
+add_one_lib("clangCodeGen")
4c80fc
 add_one_lib("clangFrontend")
4c80fc
 add_one_lib("clangSerialization")
4c80fc
 add_one_lib("clangDriver")
4c80fc
-add_one_lib("clangCodeGen")
4c80fc
 add_one_lib("clangSema")
4c80fc
 add_one_lib("clangStaticAnalyzerFrontend")
4c80fc
 add_one_lib("clangStaticAnalyzerCheckers")
4c80fc
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
4c80fc
index 274c99c..4159234 100644
4c80fc
--- a/backend/src/backend/gen_program.cpp
4c80fc
+++ b/backend/src/backend/gen_program.cpp
4c80fc
@@ -454,7 +454,11 @@ namespace gbe {
4c80fc
 #ifdef GBE_COMPILER_AVAILABLE
4c80fc
       std::string str;
4c80fc
       llvm::raw_string_ostream OS(str);
4c80fc
+#if LLVM_VERSION_MAJOR >= 7
4c80fc
+      llvm::WriteBitcodeToFile(*((llvm::Module*)prog->module), OS);
4c80fc
+#else
4c80fc
       llvm::WriteBitcodeToFile((llvm::Module*)prog->module, OS);
4c80fc
+#endif
4c80fc
       std::string& bin_str = OS.str();
4c80fc
       int llsz = bin_str.size();
4c80fc
       *binary = (char *)malloc(sizeof(char) * (llsz+1) );
4c80fc
@@ -545,7 +549,11 @@ namespace gbe {
4c80fc
                                     &modRef);
4c80fc
         src = llvm::unwrap(modRef);
4c80fc
       }
4c80fc
+#if LLVM_VERSION_MAJOR >= 7
4c80fc
+      llvm::Module* clone = llvm::CloneModule(*src).release();
4c80fc
+#else
4c80fc
       llvm::Module* clone = llvm::CloneModule(src).release();
4c80fc
+#endif
4c80fc
       if (LLVMLinkModules2(wrap(dst), wrap(clone))) {
4c80fc
 #elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
4c80fc
       if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource_Removed, &errMsg)) {
4c80fc
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
4c80fc
index c37c595..b36f7b4 100644
4c80fc
--- a/backend/src/backend/program.cpp
4c80fc
+++ b/backend/src/backend/program.cpp
4c80fc
@@ -794,7 +794,11 @@ namespace gbe {
4c80fc
       llvm::raw_fd_ostream ostream (dumpSPIRBinaryName.c_str(),
4c80fc
                                     err, llvm::sys::fs::F_None);
4c80fc
       if (!err)
4c80fc
+#if LLVM_VERSION_MAJOR<7
4c80fc
         llvm::WriteBitcodeToFile(*out_module, ostream);
4c80fc
+#else
4c80fc
+        llvm::WriteBitcodeToFile(**out_module, ostream);
4c80fc
+#endif
4c80fc
     }
4c80fc
 #endif
4c80fc
     return true;
4c80fc
diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp
4c80fc
index 8515dc1..4aec44e 100644
4c80fc
--- a/backend/src/llvm/ExpandLargeIntegers.cpp
4c80fc
+++ b/backend/src/llvm/ExpandLargeIntegers.cpp
4c80fc
@@ -99,8 +99,8 @@ using namespace llvm;
4c80fc
 
4c80fc
 #ifdef DEBUG
4c80fc
   #undef DEBUG
4c80fc
-  #define DEBUG(...)
4c80fc
 #endif
4c80fc
+#define DEBUG(...)
4c80fc
 // Break instructions up into no larger than 64-bit chunks.
4c80fc
 static const unsigned kChunkBits = 64;
4c80fc
 static const unsigned kChunkBytes = kChunkBits / CHAR_BIT;
4c80fc
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
4c80fc
index ef56e4c..4c3e20e 100644
4c80fc
--- a/backend/src/llvm/llvm_bitcode_link.cpp
4c80fc
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
4c80fc
@@ -340,7 +340,11 @@ namespace gbe
4c80fc
     /* We use beignet's bitcode as dst because it will have a lot of
4c80fc
        lazy functions which will not be loaded. */
4c80fc
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
4c80fc
+#if LLVM_VERSION_MAJOR >= 7
4c80fc
+    llvm::Module * linked_module = llvm::CloneModule(*(llvm::Module*)mod).release();
4c80fc
+#else
4c80fc
     llvm::Module * linked_module = llvm::CloneModule((llvm::Module*)mod).release();
4c80fc
+#endif
4c80fc
     if(LLVMLinkModules2(wrap(clonedLib), wrap(linked_module))) {
4c80fc
 #else
4c80fc
     char* errorMsg;
4c80fc
diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp
4c80fc
index 184553a..ffccf02 100644
4c80fc
--- a/backend/src/llvm/llvm_includes.hpp
4c80fc
+++ b/backend/src/llvm/llvm_includes.hpp
4c80fc
@@ -89,6 +89,10 @@
4c80fc
 #include "llvm/CodeGen/IntrinsicLowering.h"
4c80fc
 
4c80fc
 #include "llvm/Transforms/Scalar.h"
4c80fc
+#if LLVM_VERSION_MAJOR >= 7
4c80fc
+#include "llvm/Transforms/Utils.h"
4c80fc
+#include "llvm/Transforms/InstCombine/InstCombine.h"
4c80fc
+#endif
4c80fc
 #include "llvm/MC/MCAsmInfo.h"
4c80fc
 #include "llvm/MC/MCContext.h"
4c80fc
 #include "llvm/MC/MCInstrInfo.h"
4c80fc
-- 
4c80fc
cgit v1.1
4c80fc
4c80fc