From 8912668bd3bbba302c66e7d3ddc02d50ac7e78a8 Mon Sep 17 00:00:00 2001 From: Ruiling Song Date: Wed, 18 Jun 2014 15:09:44 +0800 Subject: [PATCH] GBE: pass compile against LLVM 3.5 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 Reviewed-by: Zhigang Gong --- backend/src/backend/gen_program.cpp | 6 ++++- backend/src/backend/program.cpp | 2 +- backend/src/llvm/llvm_barrier_nodup.cpp | 4 +--- backend/src/llvm/llvm_gen_backend.cpp | 29 +++++++++++++++++------- backend/src/llvm/llvm_intrinsic_lowering.cpp | 4 +--- backend/src/llvm/llvm_loadstore_optimization.cpp | 13 +++++++---- backend/src/llvm/llvm_passes.cpp | 8 +++---- backend/src/llvm/llvm_printf_parser.cpp | 9 +++++++- backend/src/llvm/llvm_scalarize.cpp | 8 ++++++- backend/src/llvm/llvm_to_gen.cpp | 16 ++++++++++++- backend/src/ocl_stdlib.tmpl.h | 5 ++++ 11 files changed, 75 insertions(+), 29 deletions(-) diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp index 8897dbb..84e8c2a 100644 --- a/backend/src/backend/gen_program.cpp +++ b/backend/src/backend/gen_program.cpp @@ -22,7 +22,7 @@ * \author Benjamin Segovia */ -#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" @@ -33,7 +33,11 @@ #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" diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index 98e7ab7..934aeb2 100644 --- a/backend/src/backend/program.cpp +++ b/backend/src/backend/program.cpp @@ -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" diff --git a/backend/src/llvm/llvm_barrier_nodup.cpp b/backend/src/llvm/llvm_barrier_nodup.cpp index cc1e22c..791df00 100644 --- a/backend/src/llvm/llvm_barrier_nodup.cpp +++ b/backend/src/llvm/llvm_barrier_nodup.cpp @@ -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" diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 8662415..a5aa038 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -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" @@ -127,13 +127,21 @@ #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 @@ -142,7 +150,6 @@ #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(*iter)) return cast(*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(theUser)) return cast(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 diff --git a/backend/src/llvm/llvm_intrinsic_lowering.cpp b/backend/src/llvm/llvm_intrinsic_lowering.cpp index 1942860..7d04318 100644 --- a/backend/src/llvm/llvm_intrinsic_lowering.cpp +++ b/backend/src/llvm/llvm_intrinsic_lowering.cpp @@ -20,7 +20,7 @@ * \author Yang Rong */ -#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" diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp index a597927..4bfc7f6 100644 --- a/backend/src/llvm/llvm_loadstore_optimization.cpp +++ b/backend/src/llvm/llvm_loadstore_optimization.cpp @@ -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(); - TD = getAnalysisIfAvailable(); + #if LLVM_VERSION_MINOR >= 5 + DataLayoutPass *DLP = getAnalysisIfAvailable(); + TD = DLP ? &DLP->getDataLayout() : nullptr; + #else + TD = getAnalysisIfAvailable(); + #endif return optimizeLoadStore(BB); } Type *getValueType(Value *insn); diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp index 16d461d..3078470 100644 --- a/backend/src/llvm/llvm_passes.cpp +++ b/backend/src/llvm/llvm_passes.cpp @@ -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" @@ -86,13 +86,12 @@ #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 @@ -101,7 +100,6 @@ #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" diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp index ec8e76d..6d85a64 100644 --- a/backend/src/llvm/llvm_printf_parser.cpp +++ b/backend/src/llvm/llvm_printf_parser.cpp @@ -33,7 +33,7 @@ #include #include -#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" #if LLVM_VERSION_MINOR <= 2 #include "llvm/Function.h" #include "llvm/InstrTypes.h" @@ -55,8 +55,15 @@ #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" diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp index f1513f8..5c14012 100644 --- a/backend/src/llvm/llvm_scalarize.cpp +++ b/backend/src/llvm/llvm_scalarize.cpp @@ -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 @@ -87,8 +87,14 @@ #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" diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp index ee5eb88..50b3a19 100644 --- a/backend/src/llvm/llvm_to_gen.cpp +++ b/backend/src/llvm/llvm_to_gen.cpp @@ -22,7 +22,7 @@ * \author Benjamin Segovia */ -#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 diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index a4bdfbd..c2eca7c 100755 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -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__ */ -- 2.7.4