llvm-project-source: allow to use with zeus release

In order to use latest opencl versions with zeus, carrying llvm9 specific
patches, and conditinally applying based on LLVMVERSION.

In zeus release, LLVMVERSION points to 9.x.

Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
This commit is contained in:
Naveen Saini 2020-04-24 13:38:34 +08:00 committed by Anuj Mittal
parent 9f65fd57fe
commit 0cd0dafe0f
6 changed files with 396 additions and 6 deletions

View File

@ -0,0 +1,68 @@
From 559fb8f82295ec4dc64a132b6566939b85c1b6fe Mon Sep 17 00:00:00 2001
From: Anuj Mittal <anuj.mittal@intel.com>
Date: Thu, 15 Aug 2019 22:34:31 +0800
Subject: [PATCH] dont export targets for binaries
The projects using LLVM cmake modules look for target binaries in
sysroot as a result which isn't desirable in this case and isn't needed
either.
Upstream-Status: Inappropriate [cross-compile specific]
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
llvm/cmake/modules/AddLLVM.cmake | 9 ---------
llvm/cmake/modules/TableGen.cmake | 6 ------
2 files changed, 15 deletions(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 619e986b8aa..d2bc1a25dd9 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -898,12 +898,6 @@ macro(add_llvm_tool name)
if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
if( LLVM_BUILD_TOOLS )
- set(export_to_llvmexports)
- if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
- NOT LLVM_DISTRIBUTION_COMPONENTS)
- set(export_to_llvmexports EXPORT LLVMExports)
- set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
- endif()
install(TARGETS ${name}
${export_to_llvmexports}
@@ -917,9 +911,6 @@ macro(add_llvm_tool name)
endif()
endif()
endif()
- if( LLVM_BUILD_TOOLS )
- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
- endif()
set_target_properties(${name} PROPERTIES FOLDER "Tools")
endmacro(add_llvm_tool name)
diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 36c026b5c0f..537acd696d8 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -148,15 +148,9 @@ macro(add_tablegen target project)
endif()
if (${project} STREQUAL LLVM AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
- set(export_to_llvmexports)
- if(${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
- NOT LLVM_DISTRIBUTION_COMPONENTS)
- set(export_to_llvmexports EXPORT LLVMExports)
- endif()
install(TARGETS ${target}
${export_to_llvmexports}
RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR})
endif()
- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${target})
endmacro()
--
2.17.1

View File

@ -0,0 +1,111 @@
From eeb816d95f0910bd246e37bb2bb3923acf0edf6b Mon Sep 17 00:00:00 2001
From: Aleksander Us <aleksander.us@intel.com>
Date: Mon, 26 Aug 2019 15:47:41 +0300
Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in
SplitBlockPredecessors.
In case when BB is header of some loop and predecessor is latch of
this loop, metadata was not attached to newly created basic block.
This led to loss of loop metadata for other passes.
Upstream-Status: Submitted [https://reviews.llvm.org/D66892]
https://github.com/intel/llvm-patches/commit/8af4449e2d201707f7f2f832b473a0439e255f32
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
lib/Transforms/Utils/BasicBlockUtils.cpp | 23 ++++++++----
test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++
2 files changed, 52 insertions(+), 7 deletions(-)
create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 5fa371377c8..3a90ae061fb 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -579,24 +579,33 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
// The new block unconditionally branches to the old block.
BranchInst *BI = BranchInst::Create(BB, NewBB);
+ bool IsBBHeader = LI && LI->isLoopHeader(BB);
+ Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr;
// Splitting the predecessors of a loop header creates a preheader block.
- if (LI && LI->isLoopHeader(BB))
+ if (IsBBHeader)
// Using the loop start line number prevents debuggers stepping into the
// loop body for this instruction.
- BI->setDebugLoc(LI->getLoopFor(BB)->getStartLoc());
+ BI->setDebugLoc(BBLoop->getStartLoc());
else
BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc());
// Move the edges from Preds to point to NewBB instead of BB.
- for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+ for (BasicBlock *Pred : Preds) {
+ Instruction *PI = Pred->getTerminator();
// This is slightly more strict than necessary; the minimum requirement
// is that there be no more than one indirectbr branching to BB. And
// all BlockAddress uses would need to be updated.
- assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
+ assert(!isa<IndirectBrInst>(PI) &&
"Cannot split an edge from an IndirectBrInst");
- assert(!isa<CallBrInst>(Preds[i]->getTerminator()) &&
- "Cannot split an edge from a CallBrInst");
- Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
+ assert(!isa<CallBrInst>(PI) && "Cannot split an edge from a CallBrInst");
+ if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) {
+ // Update loop metadata if it exists.
+ if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) {
+ BI->setMetadata(LLVMContext::MD_loop, LoopMD);
+ PI->setMetadata(LLVMContext::MD_loop, nullptr);
+ }
+ }
+ PI->replaceUsesOfWith(BB, NewBB);
}
// Insert a new PHI node into NewBB for every PHI node in BB and that new PHI
diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll
new file mode 100644
index 00000000000..c15c92fe3ae
--- /dev/null
+++ b/test/Transforms/LoopSimplify/loop_metadata.ll
@@ -0,0 +1,36 @@
+; RUN: opt -S -loop-simplify < %s | FileCheck %s
+
+; CHECK: for.cond.loopexit:
+; CHECK: br label %for.cond, !llvm.loop !0
+; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit
+
+define void @foo() {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.cond1, %entry
+ %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ]
+ %cmp = icmp ult i32 %j, 8
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %dummy1 = add i32 1, 1
+ %add = add nuw nsw i32 %j, 1
+ br label %for.cond1
+
+for.cond1: ; preds = %for.body1, %for.body
+ %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ]
+ %cmp1 = icmp ult i32 %i.0, 8
+ br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0
+
+for.body1: ; preds = %for.cond1
+ %dummy2 = add i32 1, 1
+ %inc = add nuw nsw i32 %i.0, 1
+ br label %for.cond1
+
+for.end: ; preds = %for.cond
+ ret void
+}
+
+!0 = distinct !{!0, !1}
+!1 = !{!"llvm.loop.unroll.full"}
--
2.18.0

View File

@ -0,0 +1,146 @@
From 35e218a886f4c066eabd18685240d55270bd5a6d Mon Sep 17 00:00:00 2001
From: Aleksander Us <aleksander.us@intel.com>
Date: Mon, 26 Aug 2019 15:45:47 +0300
Subject: [PATCH] [IndVarSimplify] Do not use SCEV expander for IVCount in
LFTR when possible.
SCEV analysis cannot properly cache instruction with poison flags
(for example, add nsw outside of loop will not be reused by expander).
This can lead to generating of additional instructions by SCEV expander.
Example IR:
...
%maxval = add nuw nsw i32 %a1, %a2
...
for.body:
...
%cmp22 = icmp ult i32 %ivadd, %maxval
br i1 %cmp22, label %for.body, label %for.end
...
SCEV expander will generate copy of %maxval in preheader but without
nuw/nsw flags. This can be avoided by explicit check that iv count
value gives the same SCEV expressions as calculated by LFTR.
Upstream-Status: Submitted [https://reviews.llvm.org/D66890]
https://github.com/intel/llvm-patches/commit/fd6a6c97341a56fd21bc32bc940afea751312e8f
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
lib/Transforms/Scalar/IndVarSimplify.cpp | 12 +++++++++-
test/Transforms/IndVarSimplify/add_nsw.ll | 23 ++++++++++++++++++++
test/Transforms/IndVarSimplify/lftr-reuse.ll | 9 +++-----
test/Transforms/IndVarSimplify/udiv.ll | 1 +
4 files changed, 38 insertions(+), 7 deletions(-)
create mode 100644 test/Transforms/IndVarSimplify/add_nsw.ll
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index f9fc698a4a9..5e04dac8aa6 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2375,6 +2375,17 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
if (UsePostInc)
IVLimit = SE->getAddExpr(IVLimit, SE->getOne(IVLimit->getType()));
+ // If computed limit is equal to old limit then do not use SCEV expander
+ // because it can lost NUW/NSW flags and create extra instructions.
+ BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
+ if (ICmpInst *Cmp = dyn_cast<ICmpInst>(BI->getOperand(0))) {
+ Value *Limit = Cmp->getOperand(0);
+ if (!L->isLoopInvariant(Limit))
+ Limit = Cmp->getOperand(1);
+ if (SE->getSCEV(Limit) == IVLimit)
+ return Limit;
+ }
+
// Expand the code for the iteration count.
assert(SE->isLoopInvariant(IVLimit, L) &&
"Computed iteration count is not loop invariant!");
@@ -2383,7 +2394,6 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
// SCEV expression (IVInit) for a pointer type IV value (IndVar).
Type *LimitTy = ExitCount->getType()->isPointerTy() ?
IndVar->getType() : ExitCount->getType();
- BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
return Rewriter.expandCodeFor(IVLimit, LimitTy, BI);
}
}
diff --git a/test/Transforms/IndVarSimplify/add_nsw.ll b/test/Transforms/IndVarSimplify/add_nsw.ll
new file mode 100644
index 00000000000..abd1cbb6c51
--- /dev/null
+++ b/test/Transforms/IndVarSimplify/add_nsw.ll
@@ -0,0 +1,23 @@
+; RUN: opt -indvars -S %s | FileCheck %s
+
+target datalayout = "e-p:32:32-i64:64-n8:16:32"
+
+; CHECK: for.body.preheader:
+; CHECK-NOT: add
+; CHECK: for.body:
+
+define void @foo(i32 %a1, i32 %a2) {
+entry:
+ %maxval = add nuw nsw i32 %a1, %a2
+ %cmp = icmp slt i32 %maxval, 1
+ br i1 %cmp, label %for.end, label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %j.02 = phi i32 [ 0, %entry ], [ %add31, %for.body ]
+ %add31 = add nuw nsw i32 %j.02, 1
+ %cmp22 = icmp slt i32 %add31, %maxval
+ br i1 %cmp22, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
diff --git a/test/Transforms/IndVarSimplify/lftr-reuse.ll b/test/Transforms/IndVarSimplify/lftr-reuse.ll
index 14ae9738696..509d662b767 100644
--- a/test/Transforms/IndVarSimplify/lftr-reuse.ll
+++ b/test/Transforms/IndVarSimplify/lftr-reuse.ll
@@ -67,11 +67,9 @@ define void @expandOuterRecurrence(i32 %arg) nounwind {
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]]
; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]]
; CHECK: outer.preheader:
-; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG]], -1
; CHECK-NEXT: br label [[OUTER:%.*]]
; CHECK: outer:
-; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[TMP0]], [[OUTER_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[OUTER_INC:%.*]] ]
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC]] ], [ 0, [[OUTER_PREHEADER]] ]
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ], [ 0, [[OUTER_PREHEADER]] ]
; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]]
; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 0, [[SUB3]]
@@ -81,14 +79,13 @@ define void @expandOuterRecurrence(i32 %arg) nounwind {
; CHECK: inner:
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[INNER_PH]] ], [ [[J_INC:%.*]], [[INNER]] ]
; CHECK-NEXT: [[J_INC]] = add nuw nsw i32 [[J]], 1
-; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[INDVARS_IV]]
+; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[SUB3]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]]
; CHECK: outer.inc.loopexit:
; CHECK-NEXT: br label [[OUTER_INC]]
; CHECK: outer.inc:
; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1
-; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i32 [[INDVARS_IV]], -1
-; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[TMP0]]
+; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[SUB1]]
; CHECK-NEXT: br i1 [[EXITCOND1]], label [[OUTER]], label [[EXIT_LOOPEXIT:%.*]]
; CHECK: exit.loopexit:
; CHECK-NEXT: br label [[EXIT]]
diff --git a/test/Transforms/IndVarSimplify/udiv.ll b/test/Transforms/IndVarSimplify/udiv.ll
index b3f2c2a6a66..3530343ef4a 100644
--- a/test/Transforms/IndVarSimplify/udiv.ll
+++ b/test/Transforms/IndVarSimplify/udiv.ll
@@ -133,6 +133,7 @@ declare i32 @printf(i8* nocapture, ...) nounwind
; CHECK-LABEL: @foo(
; CHECK: for.body.preheader:
; CHECK-NOT: udiv
+; CHECK: for.body:
define void @foo(double* %p, i64 %n) nounwind {
entry:
--
2.18.0

View File

@ -0,0 +1,51 @@
From 48e50f06b1bbed94cdf5207587161d4bfce7366e Mon Sep 17 00:00:00 2001
From: Naveen Saini <naveen.kumar.saini@intel.com>
Date: Wed, 21 Aug 2019 14:35:31 +0800
Subject: [PATCH] llvm-spirv: skip building tests
Some of these need clang to be built and since we're building this in-tree,
that leads to problems when compiling libcxx, compiler-rt which aren't built
in-tree.
Instead of using SPIRV_SKIP_CLANG_BUILD to skip clang build and adding this to
all components, disable the building of tests altogether.
Upstream-Status: Inappropriate
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
CMakeLists.txt | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1208741..20ca3e6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,13 +15,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
- if(LLVM_INCLUDE_TESTS)
- set(LLVM_TEST_COMPONENTS
- llvm-as
- llvm-dis
- )
- endif(LLVM_INCLUDE_TESTS)
-
find_package(LLVM 9.0.0 REQUIRED
COMPONENTS
Analysis
@@ -56,9 +49,6 @@ set(LLVM_SPIRV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(lib/SPIRV)
add_subdirectory(tools/llvm-spirv)
-if(LLVM_INCLUDE_TESTS)
- add_subdirectory(test)
-endif(LLVM_INCLUDE_TESTS)
install(
FILES
--
2.17.1

View File

@ -1,9 +1,23 @@
FILESEXTRAPATHS_prepend_intel-x86-common := "${THISDIR}/files:" FILESEXTRAPATHS_prepend_intel-x86-common := "${THISDIR}/files:"
SRC_URI_append_intel-x86-common = " \ SPIRV_BRANCH = "${@bb.utils.contains('LLVMVERSION', '9.0.1', 'llvm_release_90', 'llvm_release_100', d)}"
git://github.com/KhronosGroup/SPIRV-LLVM-Translator.git;protocol=https;branch=llvm_release_100;destsuffix=git/llvm/projects/llvm-spirv;name=spirv \
file://0001-skip-building-tests.patch;patchdir=llvm/projects/llvm-spirv \ SPIRV9_SRCREV = "70420631144a6a25613ae37178f2cc1d3607b65b"
SPIRV10_SRCREV = "7743482f2053582be990e93ca46d15239c509c9d"
SPIRV_SRCREV = "${@bb.utils.contains('LLVMVERSION', '9.0.1', '${SPIRV9_SRCREV}', '${SPIRV10_SRCREV}', d)}"
LLVM9_PATCH_LIST = " file://0001-dont-export-targets-for-binaries.patch \
file://BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch;patchdir=llvm \
file://IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch;patchdir=llvm \
file://llvm9-skip-building-tests.patch;patchdir=llvm/projects/llvm-spirv \
"
LLVM10_PATCH_LIST = " file://llvm10-skip-building-tests.patch;patchdir=llvm/projects/llvm-spirv \
file://fix-shared-libs.patch;patchdir=llvm/projects/llvm-spirv \ file://fix-shared-libs.patch;patchdir=llvm/projects/llvm-spirv \
" "
SRCREV_spirv = "7743482f2053582be990e93ca46d15239c509c9d" SRC_URI_append_intel-x86-common = " \
git://github.com/KhronosGroup/SPIRV-LLVM-Translator.git;protocol=https;branch=${SPIRV_BRANCH};destsuffix=git/llvm/projects/llvm-spirv;name=spirv \
"
SRC_URI_append_intel-x86-common = "${@bb.utils.contains('LLVMVERSION', '9.0.1', '${LLVM9_PATCH_LIST}', '${LLVM10_PATCH_LIST}', d)}"
SRCREV_spirv = "${SPIRV_SRCREV}"