diff options
author | Shraiysh Vaishay <Shraiysh.Vaishay@amd.com> | 2021-12-01 13:22:56 +0530 |
---|---|---|
committer | Shraiysh Vaishay <Shraiysh.Vaishay@amd.com> | 2021-12-01 15:11:54 +0530 |
commit | ec97e1206abd6f30a1b549db62e87bea8dee0082 (patch) | |
tree | 523a8ea0506645b3143fbe5f8fcba17c1786dbc3 /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | |
parent | 84b978da3b80b986327a830c01e32f12cefe86b3 (diff) | |
download | llvm-ec97e1206abd6f30a1b549db62e87bea8dee0082.zip llvm-ec97e1206abd6f30a1b549db62e87bea8dee0082.tar.gz llvm-ec97e1206abd6f30a1b549db62e87bea8dee0082.tar.bz2 |
[OpenMP][IRBuilder] Fix createSections
Fix for the case when there are no instructions in the entry basic block before the call
to `createSections`
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D114143
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r-- | llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 43b95a4..8373d69 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -3487,6 +3487,37 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) { EXPECT_TRUE(isSimpleBinaryReduction(Bitcast, FnReductionBB, &Opcode)); } +TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) { + using InsertPointTy = OpenMPIRBuilder::InsertPointTy; + using BodyGenCallbackTy = llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy; + OpenMPIRBuilder OMPBuilder(*M); + OMPBuilder.initialize(); + F->setName("func"); + IRBuilder<> Builder(BB); + OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); + llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector; + llvm::SmallVector<BasicBlock *, 4> CaseBBs; + + auto FiniCB = [&](InsertPointTy IP) {}; + auto SectionCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP, + BasicBlock &FiniBB) { + Builder.restoreIP(CodeGenIP); + Builder.CreateBr(&FiniBB); + }; + SectionCBVector.push_back(SectionCB); + + auto PrivCB = [](InsertPointTy AllocaIP, InsertPointTy CodeGenIP, + llvm::Value &, llvm::Value &Val, + llvm::Value *&ReplVal) { return CodeGenIP; }; + IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(), + F->getEntryBlock().getFirstInsertionPt()); + Builder.restoreIP(OMPBuilder.createSections(Loc, AllocaIP, SectionCBVector, + PrivCB, FiniCB, false, false)); + Builder.CreateRetVoid(); // Required at the end of the function + EXPECT_NE(F->getEntryBlock().getTerminator(), nullptr); + EXPECT_FALSE(verifyModule(*M, &errs())); +} + TEST_F(OpenMPIRBuilderTest, CreateSections) { using InsertPointTy = OpenMPIRBuilder::InsertPointTy; using BodyGenCallbackTy = llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy; @@ -3607,6 +3638,7 @@ TEST_F(OpenMPIRBuilderTest, CreateSections) { ASSERT_EQ(NumBodiesGenerated, 2U); ASSERT_EQ(NumFiniCBCalls, 1U); + EXPECT_FALSE(verifyModule(*M, &errs())); } TEST_F(OpenMPIRBuilderTest, CreateOffloadMaptypes) { |