Skip to content

[Polly] Switch DT/LI in RegionGenerator for parallel subfn #120413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polly/include/polly/CodeGen/BlockGenerators.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class BlockGenerator {
};

/// Generator for new versions of polyhedral region statements.
class RegionGenerator final : BlockGenerator {
class RegionGenerator final : public BlockGenerator {
public:
/// Create a generator for regions.
///
Expand Down
10 changes: 5 additions & 5 deletions polly/lib/CodeGen/BlockGenerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ BasicBlock *RegionGenerator::repairDominance(BasicBlock *BB,
BasicBlock *BBCopyIDom = EndBlockMap.lookup(BBIDom);

if (BBCopyIDom)
DT.changeImmediateDominator(BBCopy, BBCopyIDom);
GenDT->changeImmediateDominator(BBCopy, BBCopyIDom);

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

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

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

// As the block generator doesn't handle control flow we need to add the
// region control flow by hand after all blocks have been copied.
Expand Down
2 changes: 2 additions & 0 deletions polly/lib/CodeGen/IslNodeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
GenLI = SubLI;
GenSE = SubSE.get();
BlockGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
RegionGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
ExprBuilder.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
Builder.SetInsertPoint(&*LoopBody);

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

Expand Down
41 changes: 41 additions & 0 deletions polly/test/CodeGen/reggen_domtree_crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; RUN: opt %loadNPMPolly -passes=polly-codegen -polly-parallel -S < %s | FileCheck %s

; CHECK: define ptr @ham(ptr %arg, i64 %arg1, i1 %arg2)

; This test is added to verify if the following IR does not crash on using different Dominator Tree when using polly parallel flag.

; ModuleID = '<stdin>'
source_filename = "<stdin>"

define ptr @ham(ptr %arg, i64 %arg1, i1 %arg2) {
bb:
br label %bb3

bb3: ; preds = %bb8, %bb
%phi = phi i64 [ 0, %bb ], [ %add9, %bb8 ]
%getelementptr = getelementptr [64 x i16], ptr %arg, i64 %phi
br label %bb4

bb4: ; preds = %bb7, %bb3
%phi5 = phi i64 [ %add, %bb7 ], [ 0, %bb3 ]
%load = load i16, ptr null, align 2
br i1 %arg2, label %bb7, label %bb6

bb6: ; preds = %bb4
store i16 0, ptr %getelementptr, align 2
br label %bb7

bb7: ; preds = %bb6, %bb4
%add = add i64 %phi5, 1
%icmp = icmp ne i64 %phi5, 64
br i1 %icmp, label %bb4, label %bb8

bb8: ; preds = %bb7
%add9 = add i64 %phi, 1
%icmp10 = icmp ult i64 %phi, %arg1
br i1 %icmp10, label %bb3, label %bb11

bb11: ; preds = %bb8
ret ptr null
}

Loading