Skip to content

Commit 49668d5

Browse files
authored
[Polly] Switch DT/LI in RegionGenerator for parallel subfn (#120413)
The patch #102460 already implements separate DT/LI/SE for parallel sub function. Crashes have been reported while region generator tries using oringinal function's DT while creating new parallel sub function due to checks in #101198. This patch aims at fixing those cases by switching the DT/LI while generating parallel function using Region Generator. Fixes #117877
1 parent a8dab1a commit 49668d5

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

polly/include/polly/CodeGen/BlockGenerators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class BlockGenerator {
632632
};
633633

634634
/// Generator for new versions of polyhedral region statements.
635-
class RegionGenerator final : BlockGenerator {
635+
class RegionGenerator final : public BlockGenerator {
636636
public:
637637
/// Create a generator for regions.
638638
///

polly/lib/CodeGen/BlockGenerators.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ BasicBlock *RegionGenerator::repairDominance(BasicBlock *BB,
10001000
BasicBlock *BBCopyIDom = EndBlockMap.lookup(BBIDom);
10011001

10021002
if (BBCopyIDom)
1003-
DT.changeImmediateDominator(BBCopy, BBCopyIDom);
1003+
GenDT->changeImmediateDominator(BBCopy, BBCopyIDom);
10041004

10051005
return StartBlockMap.lookup(BBIDom);
10061006
}
@@ -1069,8 +1069,8 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
10691069
// Create a dedicated entry for the region where we can reload all demoted
10701070
// inputs.
10711071
BasicBlock *EntryBB = R->getEntry();
1072-
BasicBlock *EntryBBCopy = SplitBlock(Builder.GetInsertBlock(),
1073-
&*Builder.GetInsertPoint(), &DT, &LI);
1072+
BasicBlock *EntryBBCopy = SplitBlock(
1073+
Builder.GetInsertBlock(), &*Builder.GetInsertPoint(), GenDT, GenLI);
10741074
EntryBBCopy->setName("polly.stmt." + EntryBB->getName() + ".entry");
10751075
Builder.SetInsertPoint(&EntryBBCopy->front());
10761076

@@ -1136,7 +1136,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
11361136

11371137
// Now create a new dedicated region exit block and add it to the region map.
11381138
BasicBlock *ExitBBCopy = SplitBlock(Builder.GetInsertBlock(),
1139-
&*Builder.GetInsertPoint(), &DT, &LI);
1139+
&*Builder.GetInsertPoint(), GenDT, GenLI);
11401140
ExitBBCopy->setName("polly.stmt." + R->getExit()->getName() + ".exit");
11411141
StartBlockMap[R->getExit()] = ExitBBCopy;
11421142
EndBlockMap[R->getExit()] = ExitBBCopy;
@@ -1145,7 +1145,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
11451145
assert(ExitDomBBCopy &&
11461146
"Common exit dominator must be within region; at least the entry node "
11471147
"must match");
1148-
DT.changeImmediateDominator(ExitBBCopy, ExitDomBBCopy);
1148+
GenDT->changeImmediateDominator(ExitBBCopy, ExitDomBBCopy);
11491149

11501150
// As the block generator doesn't handle control flow we need to add the
11511151
// region control flow by hand after all blocks have been copied.

polly/lib/CodeGen/IslNodeBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
612612
GenLI = SubLI;
613613
GenSE = SubSE.get();
614614
BlockGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
615+
RegionGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
615616
ExprBuilder.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
616617
Builder.SetInsertPoint(&*LoopBody);
617618

@@ -681,6 +682,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
681682
IDToValue = std::move(IDToValueCopy);
682683
ValueMap = std::move(CallerGlobals);
683684
ExprBuilder.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
685+
RegionGen.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
684686
BlockGen.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
685687
Builder.SetInsertPoint(&*AfterLoop);
686688

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; RUN: opt %loadNPMPolly -passes=polly-codegen -polly-parallel -S < %s | FileCheck %s
2+
3+
; CHECK: define ptr @ham(ptr %arg, i64 %arg1, i1 %arg2)
4+
5+
; This test is added to verify if the following IR does not crash on using different Dominator Tree when using polly parallel flag.
6+
7+
; ModuleID = '<stdin>'
8+
source_filename = "<stdin>"
9+
10+
define ptr @ham(ptr %arg, i64 %arg1, i1 %arg2) {
11+
bb:
12+
br label %bb3
13+
14+
bb3: ; preds = %bb8, %bb
15+
%phi = phi i64 [ 0, %bb ], [ %add9, %bb8 ]
16+
%getelementptr = getelementptr [64 x i16], ptr %arg, i64 %phi
17+
br label %bb4
18+
19+
bb4: ; preds = %bb7, %bb3
20+
%phi5 = phi i64 [ %add, %bb7 ], [ 0, %bb3 ]
21+
%load = load i16, ptr null, align 2
22+
br i1 %arg2, label %bb7, label %bb6
23+
24+
bb6: ; preds = %bb4
25+
store i16 0, ptr %getelementptr, align 2
26+
br label %bb7
27+
28+
bb7: ; preds = %bb6, %bb4
29+
%add = add i64 %phi5, 1
30+
%icmp = icmp ne i64 %phi5, 64
31+
br i1 %icmp, label %bb4, label %bb8
32+
33+
bb8: ; preds = %bb7
34+
%add9 = add i64 %phi, 1
35+
%icmp10 = icmp ult i64 %phi, %arg1
36+
br i1 %icmp10, label %bb3, label %bb11
37+
38+
bb11: ; preds = %bb8
39+
ret ptr null
40+
}
41+

0 commit comments

Comments
 (0)