summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhigang Gong <zhigang.gong@intel.com>2014-02-08 11:16:43 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-02-11 17:23:06 +0800
commit6f096ed860916b5a13649e22bfe6104e25dea2af (patch)
treee1c48e3393095826b4bda918fb2efa3ceebe3909
parent38d82357747a50715f998e0cda3852ca83871f79 (diff)
Add clang/LLVM 3.5svn support.
The clang/llvm 3.3 has some minor bugs such as the vector ++/-- which was fixed in 3.4. But the 3.4 version introduces severer OCL bugs as below: http://llvm.org/bugs/show_bug.cgi?id=18119 http://llvm.org/bugs/show_bug.cgi?id=18120 It seems that the community will only fix these bugs in the ToT version rather than the llvm 3.4 branch. I think we'd better to enable clang/llvm 3.5 in beignet. Currently, the 18120 was fixed in ToT, but 18119 still breaks us. When 18119 get fixed, I will switch the preferred version to 3.5. Please be noted, when you build clang/llvm 3.5, you need to enable the cxx11 to make it compatible with beignet. --enable-cxx11 v2: fix the llvm3.4 issue. Signed-off-by: Zhigang Gong <zhigang.gong@intel.com> Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
-rw-r--r--CMake/FindLLVM.cmake9
-rw-r--r--backend/src/CMakeLists.txt1
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp4
-rw-r--r--backend/src/llvm/llvm_scalarize.cpp11
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp21
5 files changed, 38 insertions, 8 deletions
diff --git a/CMake/FindLLVM.cmake b/CMake/FindLLVM.cmake
index 6256cb00..1a37167c 100644
--- a/CMake/FindLLVM.cmake
+++ b/CMake/FindLLVM.cmake
@@ -72,6 +72,15 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)
+if (LLVM_VERSION_NODOT VERSION_GREATER 34)
+execute_process(
+ COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs
+ OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_ORIG
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+string(REGEX REPLACE " *\n" "" LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS_ORIG})
+endif (LLVM_VERSION_NODOT VERSION_GREATER 33)
+
macro(add_one_lib name)
FIND_LIBRARY(CLANG_LIB
NAMES ${name}
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index 3f24a91e..33494a07 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -184,6 +184,7 @@ target_link_libraries(
${OPENGL_LIBRARIES}
${CLANG_LIBRARIES}
${LLVM_MODULE_LIBS}
+ ${LLVM_SYSTEM_LIBS}
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS})
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index c6948da6..a9c08bf2 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -154,8 +154,8 @@
#define LLVM_VERSION_MINOR 0
#endif /* !defined(LLVM_VERSION_MINOR) */
-#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4)
-#error "Only LLVM 3.0 - 3.4 is supported"
+#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR < 3)
+#error "Only LLVM 3.3 and newer are supported"
#endif /* (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4) */
using namespace llvm;
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index 35504f37..c1790f73 100644
--- a/backend/src/llvm/llvm_scalarize.cpp
+++ b/backend/src/llvm/llvm_scalarize.cpp
@@ -66,7 +66,7 @@
#include "llvm/Config/config.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PostOrderIterator.h"
-#if LLVM_VERSION_MINOR <= 2
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
#include "llvm/Function.h"
#include "llvm/InstrTypes.h"
#include "llvm/Instructions.h"
@@ -80,7 +80,7 @@
#include "llvm/IR/Module.h"
#endif /* LLVM_VERSION_MINOR <= 2 */
#include "llvm/Pass.h"
-#if LLVM_VERSION_MINOR <= 1
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 1
#include "llvm/Support/IRBuilder.h"
#elif LLVM_VERSION_MINOR == 2
#include "llvm/IRBuilder.h"
@@ -94,7 +94,6 @@
#include "llvm/llvm_gen_backend.hpp"
#include "sys/map.hpp"
-
using namespace llvm;
namespace gbe {
@@ -128,7 +127,11 @@ namespace gbe {
Scalarize() : FunctionPass(ID)
{
initializeLoopInfoPass(*PassRegistry::getPassRegistry());
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+ initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
+#else
initializeDominatorTreePass(*PassRegistry::getPassRegistry());
+#endif
}
virtual bool runOnFunction(Function&);
@@ -767,7 +770,7 @@ namespace gbe {
bool Scalarize::runOnFunction(Function& F)
{
switch (F.getCallingConv()) {
-#if LLVM_VERSION_MINOR <= 2
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
case CallingConv::PTX_Device:
return false;
case CallingConv::PTX_Kernel:
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index b2279129..62d6f131 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -23,7 +23,7 @@
*/
#include "llvm/Config/config.h"
-#if LLVM_VERSION_MINOR <= 2
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DataLayout.h"
@@ -39,7 +39,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/ADT/Triple.h"
-#if LLVM_VERSION_MINOR <= 2
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
#include "llvm/Support/IRReader.h"
#else
#include "llvm/IRReader/IRReader.h"
@@ -49,6 +49,11 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Assembly/PrintModulePass.h"
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
+#include "llvm/IR/IRPrintingPasses.h"
+#include "llvm/IR/Verifier.h"
+#endif
+
#include "llvm/llvm_gen_backend.hpp"
#include "llvm/llvm_to_gen.hpp"
#include "sys/cvar.hpp"
@@ -69,7 +74,11 @@ namespace gbe
{
FunctionPassManager FPM(&mod);
FPM.add(new DataLayout(&mod));
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
+ FPM.add(createVerifierPass(true));
+#else
FPM.add(createVerifierPass());
+#endif
FPM.add(new TargetLibraryInfo(*libraryInfo));
FPM.add(createTypeBasedAliasAnalysisPass());
FPM.add(createBasicAliasAnalysisPass());
@@ -174,7 +183,11 @@ namespace gbe
// Print the code before further optimizations
if (OCL_OUTPUT_LLVM_BEFORE_EXTRA_PASS)
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+ passes.add(createPrintModulePass(*o));
+#else
passes.add(createPrintModulePass(&*o));
+#endif
passes.add(createIntrinsicLoweringPass());
passes.add(createFunctionInliningPass(200000));
passes.add(createScalarReplAggregatesPass()); // Break up allocas
@@ -189,7 +202,11 @@ namespace gbe
// Print the code extra optimization passes
if (OCL_OUTPUT_LLVM)
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+ passes.add(createPrintModulePass(*o));
+#else
passes.add(createPrintModulePass(&*o));
+#endif
passes.run(mod);
return true;