GBE: pass compile against LLVM 3.5
authorRuiling Song <ruiling.song@intel.com>
Wed, 18 Jun 2014 07:09:44 +0000 (15:09 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 19 Jun 2014 08:40:30 +0000 (16:40 +0800)
backward compatible with LLVM 3.3

merged a bug fix patch into this one.
  1. use_iterator point to 'Use' now instead of 'User'.
  2. all c-string are in constant address space now, which follows OCL Spec.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/backend/gen_program.cpp
backend/src/backend/program.cpp
backend/src/llvm/llvm_barrier_nodup.cpp
backend/src/llvm/llvm_gen_backend.cpp
backend/src/llvm/llvm_intrinsic_lowering.cpp
backend/src/llvm/llvm_loadstore_optimization.cpp
backend/src/llvm/llvm_passes.cpp
backend/src/llvm/llvm_printf_parser.cpp
backend/src/llvm/llvm_scalarize.cpp
backend/src/llvm/llvm_to_gen.cpp
backend/src/ocl_stdlib.tmpl.h

index 8897dbb..84e8c2a 100644 (file)
@@ -22,7 +22,7 @@
  * \author Benjamin Segovia <benjamin.segovia@intel.com>
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
 #include "llvm/LLVMContext.h"
 #include "llvm/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/Transforms/Utils/Cloning.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/raw_ostream.h"
index 98e7ab7..934aeb2 100644 (file)
@@ -32,7 +32,7 @@
 #include "ir/unit.hpp"
 #include "ir/printf.hpp"
 #include "llvm/llvm_to_gen.hpp"
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Transforms/Utils/Cloning.h"
index cc1e22c..791df00 100644 (file)
@@ -28,7 +28,7 @@
  *  
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
 #include "llvm/Function.h"
 #include "llvm/InstrTypes.h"
@@ -50,8 +50,6 @@
 #else
 #include "llvm/IR/IRBuilder.h"
 #endif /* LLVM_VERSION_MINOR <= 1 */
-#include "llvm/Support/CallSite.h"
-#include "llvm/Support/CFG.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/IR/Attributes.h"
 
index 8662415..a5aa038 100644 (file)
@@ -71,7 +71,7 @@
  *   is intercepted, we just abort
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #else
 #include "llvm/IR/DataLayout.h"
 #endif
+
+#if LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/CallSite.h"
+#include "llvm/IR/CFG.h"
+#else
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
+#endif
+
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/GetElementPtrTypeIterator.h"
 #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 2)
 #include "llvm/Support/InstVisitor.h"
+#elif LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/InstVisitor.h"
 #else
 #include "llvm/InstVisitor.h"
 #endif
 #include "llvm/Support/Host.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/SourceMgr.h"
-#include "llvm/Config/config.h"
 
 #include "llvm/llvm_gen_backend.hpp"
 #include "ir/context.hpp"
@@ -1032,7 +1039,7 @@ namespace gbe
       // If the "taken" successor is the next block, we try to invert the
       // branch.
       BasicBlock *succ = I->getSuccessor(0);
-      if (llvm::next(Function::iterator(bb)) != Function::iterator(succ))
+      if (std::next(Function::iterator(bb)) != Function::iterator(succ))
         return;
 
       // More than one use is too complicated: we skip it
@@ -1517,8 +1524,14 @@ namespace gbe
     // one instruction that use the local variable, simply return.
     const Instruction *insn = NULL;
     for(Value::const_use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) {
-      if(isa<Instruction>(*iter)) return cast<const Instruction>(*iter);
-      insn = getInstructionUseLocal(*iter);
+    // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', which is more straightforward.
+#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
+      const User *theUser = *iter;
+#else
+      const User *theUser = iter->getUser();
+#endif
+      if(isa<Instruction>(theUser)) return cast<const Instruction>(theUser);
+      insn = getInstructionUseLocal(theUser);
       if(insn != NULL) break;
     }
     return insn;
@@ -2157,7 +2170,7 @@ namespace gbe
     // successor
     if (I.isConditional() == false) {
       BasicBlock *target = I.getSuccessor(0);
-      if (llvm::next(Function::iterator(bb)) != Function::iterator(target)) {
+      if (std::next(Function::iterator(bb)) != Function::iterator(target)) {
         GBE_ASSERT(labelMap.find(target) != labelMap.end());
         const ir::LabelIndex labelIndex = labelMap[target];
         ctx.BRA(labelIndex);
@@ -2181,7 +2194,7 @@ namespace gbe
 
       // If non-taken target is the next block, there is nothing to do
       BasicBlock *bb = I.getParent();
-      if (llvm::next(Function::iterator(bb)) == Function::iterator(nonTaken))
+      if (std::next(Function::iterator(bb)) == Function::iterator(nonTaken))
         return;
 
       // This is slightly more complicated here. We need to issue one more
index 1942860..7d04318 100644 (file)
@@ -20,7 +20,7 @@
  * \author Yang Rong <rong.r.yang@intel.com>
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
 #include "llvm/Function.h"
 #include "llvm/InstrTypes.h"
@@ -42,8 +42,6 @@
 #else
 #include "llvm/IR/IRBuilder.h"
 #endif /* LLVM_VERSION_MINOR <= 1 */
-#include "llvm/Support/CallSite.h"
-#include "llvm/Support/CFG.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include "llvm/llvm_gen_backend.hpp"
index a597927..4bfc7f6 100644 (file)
@@ -26,7 +26,7 @@
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
@@ -50,8 +50,6 @@
 #else
 #include "llvm/IR/IRBuilder.h"
 #endif /* LLVM_VERSION_MINOR <= 1 */
-#include "llvm/Support/CallSite.h"
-#include "llvm/Support/CFG.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
@@ -63,7 +61,7 @@ namespace gbe {
   public:
     static char ID;
     ScalarEvolution *SE;
-    DataLayout *TD;
+    const DataLayout *TD;
     GenLoadStoreOptimization() : BasicBlockPass(ID) {}
 
     void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -74,7 +72,12 @@ namespace gbe {
 
     virtual bool runOnBasicBlock(BasicBlock &BB) {
       SE = &getAnalysis<ScalarEvolution>();
-      TD = getAnalysisIfAvailable<DataLayout>();
+      #if LLVM_VERSION_MINOR >= 5
+        DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
+        TD = DLP ? &DLP->getDataLayout() : nullptr;
+      #else
+        TD = getAnalysisIfAvailable<DataLayout>();
+      #endif
       return optimizeLoadStore(BB);
     }
     Type    *getValueType(Value *insn);
index 16d461d..3078470 100644 (file)
@@ -30,7 +30,7 @@
  * Segovia) the right to use another license for it (MIT here)
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #else
 #include "llvm/IR/DataLayout.h"
 #endif
-#include "llvm/Support/CallSite.h"
-#include "llvm/Support/CFG.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/GetElementPtrTypeIterator.h"
 #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 2)
 #include "llvm/Support/InstVisitor.h"
+#elif LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/InstVisitor.h"
 #else
 #include "llvm/InstVisitor.h"
 #endif
 #include "llvm/Support/Host.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/SourceMgr.h"
-#include "llvm/Config/config.h"
 
 #include "llvm/llvm_gen_backend.hpp"
 #include "ir/unit.hpp"
index ec8e76d..6d85a64 100644 (file)
@@ -33,7 +33,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
 #include "llvm/Function.h"
 #include "llvm/InstrTypes.h"
 #else
 #include "llvm/IR/IRBuilder.h"
 #endif /* LLVM_VERSION_MINOR <= 1 */
+
+#if LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/CallSite.h"
+#include "llvm/IR/CFG.h"
+#else
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
+#endif
+
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/IR/Attributes.h"
 
index f1513f8..5c14012 100644 (file)
@@ -63,7 +63,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
 #else
 #include "llvm/IR/IRBuilder.h"
 #endif /* LLVM_VERSION_MINOR <= 1 */
+
+#if LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/CallSite.h"
+#include "llvm/IR/CFG.h"
+#else
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
+#endif
 #include "llvm/Support/raw_ostream.h"
 
 #include "llvm/llvm_gen_backend.hpp"
index ee5eb88..50b3a19 100644 (file)
@@ -22,7 +22,7 @@
  * \author Benjamin Segovia <benjamin.segovia@intel.com>
  */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
@@ -79,7 +79,13 @@ namespace gbe
   void runFuntionPass(Module &mod, TargetLibraryInfo *libraryInfo)
   {
     FunctionPassManager FPM(&mod);
+
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+    FPM.add(new DataLayoutPass(&mod));
+#else
     FPM.add(new DataLayout(&mod));
+#endif
+
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
     FPM.add(createVerifierPass(true));
 #else
@@ -105,7 +111,11 @@ namespace gbe
   {
     llvm::PassManager MPM;
 
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+    MPM.add(new DataLayoutPass(&mod));
+#else
     MPM.add(new DataLayout(&mod));
+#endif
     MPM.add(new TargetLibraryInfo(*libraryInfo));
     MPM.add(createTypeBasedAliasAnalysisPass());
     MPM.add(createBasicAliasAnalysisPass());
@@ -191,7 +201,11 @@ namespace gbe
     runModulePass(mod, libraryInfo, optLevel);
 
     llvm::PassManager passes;
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+    passes.add(new DataLayoutPass(&mod));
+#else
     passes.add(new DataLayout(&mod));
+#endif
     // Print the code before further optimizations
     if (OCL_OUTPUT_LLVM_BEFORE_EXTRA_PASS)
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
index a4bdfbd..c2eca7c 100755 (executable)
@@ -5018,7 +5018,12 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_fastpath_tanh (float x)
 #undef INLINE
 
 /* The printf function. */
+/* From LLVM 3.5, c string are all in constant address space */
+#if 100*__clang_major__ + __clang_minor__ < 305
 int __gen_ocl_printf_stub(const char * format, ...);
+#else
+int __gen_ocl_printf_stub(constant char * format, ...);
+#endif
 #define printf __gen_ocl_printf_stub
 
 #endif /* __GEN_OCL_STDLIB_H__ */