diff options
author | Michael Kruse <llvm-project@meinersbur.de> | 2022-01-20 08:18:08 -0600 |
---|---|---|
committer | Michael Kruse <llvm-project@meinersbur.de> | 2022-01-20 10:13:44 -0600 |
commit | 616f77172f0a48ef02c1700882ca0ba2215066d1 (patch) | |
tree | 63bffb2228e66199e6ffa72cd039ce489330be72 /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | |
parent | 91eca967b9eb115afda52e3a7d158a97a24bfe7f (diff) | |
download | llvm-616f77172f0a48ef02c1700882ca0ba2215066d1.zip llvm-616f77172f0a48ef02c1700882ca0ba2215066d1.tar.gz llvm-616f77172f0a48ef02c1700882ca0ba2215066d1.tar.bz2 |
[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.
When a Builder methods accepts multiple InsertPoints, when both point to
the same position, inserting instructions at one position will "move" the
other after the inserted position since the InsertPoint is pegged to the
instruction following the intended InsertPoint. For instance, when
creating a parallel region at Loc and passing the same position as AllocaIP,
creating instructions at Loc will "move" the AllocIP behind the Loc
position.
To avoid this ambiguity, add an assertion checking this condition and
fix the unittests.
In case of AllocaIP, an alternative solution could be to implicitly
split BasicBlock at InsertPoint, using the first as AllocaIP, the second
for inserting the instructions themselves. However, this solution is
specific to AllocaIP since AllocaIP will always have to be first. Hence,
this is an argument to generally handling ambiguous InsertPoints as API
sage error.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D117226
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r-- | llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index d00f799..bc2d3ec 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -483,6 +483,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) { F->setName("func"); IRBuilder<> Builder(BB); + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); AllocaInst *PrivAI = nullptr; @@ -589,6 +592,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) { F->setName("func"); IRBuilder<> Builder(BB); + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); unsigned NumInnerBodiesGenerated = 0; @@ -682,6 +688,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) { F->setName("func"); IRBuilder<> Builder(BB); + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); unsigned NumInnerBodiesGenerated = 0; @@ -790,6 +799,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) { F->setName("func"); IRBuilder<> Builder(BB); + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); AllocaInst *PrivAI = nullptr; @@ -913,6 +925,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) { F->setName("func"); IRBuilder<> Builder(BB); + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); unsigned NumBodiesGenerated = 0; @@ -3108,6 +3123,10 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) { OMPBuilder.initialize(); F->setName("func"); IRBuilder<> Builder(BB); + + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); // Create variables to be reduced. @@ -3345,6 +3364,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) { OMPBuilder.initialize(); F->setName("func"); IRBuilder<> Builder(BB); + + BasicBlock *EnterBB = BasicBlock::Create(Ctx, "parallel.enter", F); + Builder.CreateBr(EnterBB); + Builder.SetInsertPoint(EnterBB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); // Create variables to be reduced. |