aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
diff options
context:
space:
mode:
authorPeixin-Qiao <qiaopeixin@huawei.com>2022-04-01 16:17:29 +0800
committerPeixin-Qiao <qiaopeixin@huawei.com>2022-04-01 16:17:29 +0800
commit3e7415a0ff30f7d310af4f8ee24269aa450889ba (patch)
treef2bd3cfff0a47f203d45b3d008697273027521af /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
parentc7ed65b4bcbd8c26704efc4193243831e3c13d3c (diff)
downloadllvm-3e7415a0ff30f7d310af4f8ee24269aa450889ba.zip
llvm-3e7415a0ff30f7d310af4f8ee24269aa450889ba.tar.gz
llvm-3e7415a0ff30f7d310af4f8ee24269aa450889ba.tar.bz2
[OMPIRBuilder] Support ordered clause specified without parameter
This patch supports ordered clause specified without parameter in worksharing-loop directive in the OpenMPIRBuilder and lowering MLIR to LLVM IR. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D114940
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r--llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp85
1 files changed, 84 insertions, 1 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 3cffabe..6a58702 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -2089,11 +2089,13 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
InsertPointTy AfterIP = CLI->getAfterIP();
BasicBlock *Preheader = CLI->getPreheader();
BasicBlock *ExitBlock = CLI->getExit();
+ BasicBlock *LatchBlock = CLI->getLatch();
Value *IV = CLI->getIndVar();
InsertPointTy EndIP =
OMPBuilder.applyDynamicWorkshareLoop(DL, CLI, AllocaIP, SchedType,
- /*NeedsBarrier=*/true, ChunkVal);
+ /*NeedsBarrier=*/true, ChunkVal,
+ /*Ordered=*/false);
// The returned value should be the "after" point.
ASSERT_EQ(EndIP.getBlock(), AfterIP.getBlock());
ASSERT_EQ(EndIP.getPoint(), AfterIP.getPoint());
@@ -2146,6 +2148,10 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
EXPECT_EQ(OrigUpperBound->getValue(), 21);
EXPECT_EQ(OrigStride->getValue(), 1);
+ CallInst *FiniCall = dyn_cast<CallInst>(
+ &*(LatchBlock->getTerminator()->getPrevNonDebugInstruction(true)));
+ EXPECT_EQ(FiniCall, nullptr);
+
// The original loop iterator should only be used in the condition, in the
// increment and in the statement that adds the lower bound to it.
EXPECT_EQ(std::distance(IV->use_begin(), IV->use_end()), 3);
@@ -2181,6 +2187,83 @@ INSTANTIATE_TEST_SUITE_P(
omp::OMPScheduleType::Runtime |
omp::OMPScheduleType::ModifierMonotonic));
+TEST_F(OpenMPIRBuilderTest, DynamicWorkShareLoopOrdered) {
+ using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
+ OpenMPIRBuilder OMPBuilder(*M);
+ OMPBuilder.initialize();
+ IRBuilder<> Builder(BB);
+ OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+ omp::OMPScheduleType SchedType = omp::OMPScheduleType::OrderedStaticChunked;
+ uint32_t ChunkSize = 1;
+ Type *LCTy = Type::getInt32Ty(Ctx);
+ Value *StartVal = ConstantInt::get(LCTy, 10);
+ Value *StopVal = ConstantInt::get(LCTy, 52);
+ Value *StepVal = ConstantInt::get(LCTy, 2);
+ Value *ChunkVal = ConstantInt::get(LCTy, ChunkSize);
+ auto LoopBodyGen = [&](InsertPointTy, llvm::Value *) {};
+
+ CanonicalLoopInfo *CLI = OMPBuilder.createCanonicalLoop(
+ Loc, LoopBodyGen, StartVal, StopVal, StepVal,
+ /*IsSigned=*/false, /*InclusiveStop=*/false);
+
+ Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
+ InsertPointTy AllocaIP = Builder.saveIP();
+
+ // Collect all the info from CLI, as it isn't usable after the call to
+ // createDynamicWorkshareLoop.
+ InsertPointTy AfterIP = CLI->getAfterIP();
+ BasicBlock *Preheader = CLI->getPreheader();
+ BasicBlock *ExitBlock = CLI->getExit();
+ BasicBlock *LatchBlock = CLI->getLatch();
+ Value *IV = CLI->getIndVar();
+
+ InsertPointTy EndIP =
+ OMPBuilder.applyDynamicWorkshareLoop(DL, CLI, AllocaIP, SchedType,
+ /*NeedsBarrier=*/true, ChunkVal,
+ /*Ordered=*/true);
+
+ // Add a termination to our block and check that it is internally consistent.
+ Builder.restoreIP(EndIP);
+ Builder.CreateRetVoid();
+ OMPBuilder.finalize();
+ EXPECT_FALSE(verifyModule(*M, &errs()));
+
+ CallInst *InitCall = nullptr;
+ for (Instruction &EI : *Preheader) {
+ Instruction *Cur = &EI;
+ if (isa<CallInst>(Cur)) {
+ InitCall = cast<CallInst>(Cur);
+ if (InitCall->getCalledFunction()->getName() == "__kmpc_dispatch_init_4u")
+ break;
+ InitCall = nullptr;
+ }
+ }
+ EXPECT_NE(InitCall, nullptr);
+ EXPECT_EQ(InitCall->arg_size(), 7U);
+ ConstantInt *SchedVal = cast<ConstantInt>(InitCall->getArgOperand(2));
+ EXPECT_EQ(SchedVal->getValue(), static_cast<uint64_t>(SchedType));
+
+ CallInst *FiniCall = dyn_cast<CallInst>(
+ &*(LatchBlock->getTerminator()->getPrevNonDebugInstruction(true)));
+ ASSERT_NE(FiniCall, nullptr);
+ EXPECT_EQ(FiniCall->getCalledFunction()->getName(),
+ "__kmpc_dispatch_fini_4u");
+ EXPECT_EQ(FiniCall->arg_size(), 2U);
+ EXPECT_EQ(InitCall->getArgOperand(0), FiniCall->getArgOperand(0));
+ EXPECT_EQ(InitCall->getArgOperand(1), FiniCall->getArgOperand(1));
+
+ // The original loop iterator should only be used in the condition, in the
+ // increment and in the statement that adds the lower bound to it.
+ EXPECT_EQ(std::distance(IV->use_begin(), IV->use_end()), 3);
+
+ // The exit block should contain the barrier call, plus the call to obtain
+ // the thread ID.
+ size_t NumCallsInExitBlock =
+ count_if(*ExitBlock, [](Instruction &I) { return isa<CallInst>(I); });
+ EXPECT_EQ(NumCallsInExitBlock, 2u);
+}
+
TEST_F(OpenMPIRBuilderTest, MasterDirective) {
using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
OpenMPIRBuilder OMPBuilder(*M);