diff options
author | Naveen Saini <naveen.kumar.saini@intel.com> | 2020-04-24 13:38:34 +0800 |
---|---|---|
committer | Anuj Mittal <anuj.mittal@intel.com> | 2020-04-27 16:23:50 +0800 |
commit | d45a72dc4b912b8f754d3a4e17593b49ac5a2f6b (patch) | |
tree | fc3c36859eab817c264cee6ed6ea4d968558e33f /dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch | |
parent | d8d1cc3023aa63049fe18052120d74a1e9cae16e (diff) | |
download | meta-intel-d45a72dc4b912b8f754d3a4e17593b49ac5a2f6b.tar.gz |
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>
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch')
-rw-r--r-- | dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch b/dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch new file mode 100644 index 00000000..cd519971 --- /dev/null +++ b/dynamic-layers/clang-layer/recipes-devtools/clang/files/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch | |||
@@ -0,0 +1,111 @@ | |||
1 | From eeb816d95f0910bd246e37bb2bb3923acf0edf6b Mon Sep 17 00:00:00 2001 | ||
2 | From: Aleksander Us <aleksander.us@intel.com> | ||
3 | Date: Mon, 26 Aug 2019 15:47:41 +0300 | ||
4 | Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in | ||
5 | SplitBlockPredecessors. | ||
6 | |||
7 | In case when BB is header of some loop and predecessor is latch of | ||
8 | this loop, metadata was not attached to newly created basic block. | ||
9 | This led to loss of loop metadata for other passes. | ||
10 | |||
11 | Upstream-Status: Submitted [https://reviews.llvm.org/D66892] | ||
12 | |||
13 | https://github.com/intel/llvm-patches/commit/8af4449e2d201707f7f2f832b473a0439e255f32 | ||
14 | |||
15 | Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com> | ||
16 | --- | ||
17 | lib/Transforms/Utils/BasicBlockUtils.cpp | 23 ++++++++---- | ||
18 | test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++ | ||
19 | 2 files changed, 52 insertions(+), 7 deletions(-) | ||
20 | create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll | ||
21 | |||
22 | diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp | ||
23 | index 5fa371377c8..3a90ae061fb 100644 | ||
24 | --- a/lib/Transforms/Utils/BasicBlockUtils.cpp | ||
25 | +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp | ||
26 | @@ -579,24 +579,33 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, | ||
27 | |||
28 | // The new block unconditionally branches to the old block. | ||
29 | BranchInst *BI = BranchInst::Create(BB, NewBB); | ||
30 | + bool IsBBHeader = LI && LI->isLoopHeader(BB); | ||
31 | + Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr; | ||
32 | // Splitting the predecessors of a loop header creates a preheader block. | ||
33 | - if (LI && LI->isLoopHeader(BB)) | ||
34 | + if (IsBBHeader) | ||
35 | // Using the loop start line number prevents debuggers stepping into the | ||
36 | // loop body for this instruction. | ||
37 | - BI->setDebugLoc(LI->getLoopFor(BB)->getStartLoc()); | ||
38 | + BI->setDebugLoc(BBLoop->getStartLoc()); | ||
39 | else | ||
40 | BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); | ||
41 | |||
42 | // Move the edges from Preds to point to NewBB instead of BB. | ||
43 | - for (unsigned i = 0, e = Preds.size(); i != e; ++i) { | ||
44 | + for (BasicBlock *Pred : Preds) { | ||
45 | + Instruction *PI = Pred->getTerminator(); | ||
46 | // This is slightly more strict than necessary; the minimum requirement | ||
47 | // is that there be no more than one indirectbr branching to BB. And | ||
48 | // all BlockAddress uses would need to be updated. | ||
49 | - assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) && | ||
50 | + assert(!isa<IndirectBrInst>(PI) && | ||
51 | "Cannot split an edge from an IndirectBrInst"); | ||
52 | - assert(!isa<CallBrInst>(Preds[i]->getTerminator()) && | ||
53 | - "Cannot split an edge from a CallBrInst"); | ||
54 | - Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); | ||
55 | + assert(!isa<CallBrInst>(PI) && "Cannot split an edge from a CallBrInst"); | ||
56 | + if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) { | ||
57 | + // Update loop metadata if it exists. | ||
58 | + if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) { | ||
59 | + BI->setMetadata(LLVMContext::MD_loop, LoopMD); | ||
60 | + PI->setMetadata(LLVMContext::MD_loop, nullptr); | ||
61 | + } | ||
62 | + } | ||
63 | + PI->replaceUsesOfWith(BB, NewBB); | ||
64 | } | ||
65 | |||
66 | // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI | ||
67 | diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll | ||
68 | new file mode 100644 | ||
69 | index 00000000000..c15c92fe3ae | ||
70 | --- /dev/null | ||
71 | +++ b/test/Transforms/LoopSimplify/loop_metadata.ll | ||
72 | @@ -0,0 +1,36 @@ | ||
73 | +; RUN: opt -S -loop-simplify < %s | FileCheck %s | ||
74 | + | ||
75 | +; CHECK: for.cond.loopexit: | ||
76 | +; CHECK: br label %for.cond, !llvm.loop !0 | ||
77 | +; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit | ||
78 | + | ||
79 | +define void @foo() { | ||
80 | +entry: | ||
81 | + br label %for.cond | ||
82 | + | ||
83 | +for.cond: ; preds = %for.cond1, %entry | ||
84 | + %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ] | ||
85 | + %cmp = icmp ult i32 %j, 8 | ||
86 | + br i1 %cmp, label %for.body, label %for.end | ||
87 | + | ||
88 | +for.body: ; preds = %for.cond | ||
89 | + %dummy1 = add i32 1, 1 | ||
90 | + %add = add nuw nsw i32 %j, 1 | ||
91 | + br label %for.cond1 | ||
92 | + | ||
93 | +for.cond1: ; preds = %for.body1, %for.body | ||
94 | + %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ] | ||
95 | + %cmp1 = icmp ult i32 %i.0, 8 | ||
96 | + br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0 | ||
97 | + | ||
98 | +for.body1: ; preds = %for.cond1 | ||
99 | + %dummy2 = add i32 1, 1 | ||
100 | + %inc = add nuw nsw i32 %i.0, 1 | ||
101 | + br label %for.cond1 | ||
102 | + | ||
103 | +for.end: ; preds = %for.cond | ||
104 | + ret void | ||
105 | +} | ||
106 | + | ||
107 | +!0 = distinct !{!0, !1} | ||
108 | +!1 = !{!"llvm.loop.unroll.full"} | ||
109 | -- | ||
110 | 2.18.0 | ||
111 | |||