[Beignet] [PATCH] GBE: pass compile against LLVM 3.5

Zhigang Gong zhigang.gong at linux.intel.com
Thu Jun 19 01:37:58 PDT 2014


LGTM, pushed, thanks.

On Wed, Jun 18, 2014 at 03:09:44PM +0800, Ruiling Song wrote:
> backward compatible with LLVM 3.3
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  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            |   19 +++++++++++++------
>  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 +++++++++++++++-
>  10 files changed, 62 insertions(+), 27 deletions(-)
> 
> diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
> index 300741e..e98e66c 100644
> --- a/backend/src/backend/gen_program.cpp
> +++ b/backend/src/backend/gen_program.cpp
> @@ -22,7 +22,7 @@
>   * \author Benjamin Segovia <benjamin.segovia at 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"
> @@ -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 "backend/program.h"
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index 45983fd..029faf1 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 08fe8b6..f3291f8 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
> @@ -2159,7 +2166,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);
> @@ -2183,7 +2190,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 <rong.r.yang at 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"
> 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<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);
> 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 <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"
> @@ -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 <benjamin.segovia at 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
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list