aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2021-08-12 20:07:55 -0500
committerMichael Kruse <llvm-project@meinersbur.de>2021-08-12 21:02:19 -0500
commitb1de32d6ddd90046171ecee0047fbf448a97e16f (patch)
treed86820e122a17e753fe4adec07834af09350ac9c /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
parent3980cfcbaaa432477c966956ee75e062902e02b8 (diff)
downloadllvm-b1de32d6ddd90046171ecee0047fbf448a97e16f.zip
llvm-b1de32d6ddd90046171ecee0047fbf448a97e16f.tar.gz
llvm-b1de32d6ddd90046171ecee0047fbf448a97e16f.tar.bz2
[OMPIRBuilder] Clarify CanonicalLoopInfo. NFC.
Add in-source documentation on how CanonicalLoopInfo is intended to be used. In particular, clarify what parts of a CanonicalLoopInfo is considered part of the loop, that those parts must be side-effect free, and that InsertPoints to instructions outside those parts can be expected to be preserved after method calls implementing loop-associated directives. CanonicalLoopInfo are now invalidated after it does not describe canonical loop anymore and asserts when trying to use it afterwards. In addition, rename `createXYZWorkshareLoop` to `applyXYZWorkshareLoop` and remove the update location to avoid that the impression that they insert something from scratch at that location where in reality its InsertPoint is ignored. createStaticWorkshareLoop does not return a CanonicalLoopInfo anymore. First, it was not a canonical loop in the clarified sense (containing side-effects in form of calls to the OpenMP runtime). Second, it is ambiguous which of the two possible canonical loops it should actually return. It will not be needed before a feature expected to be introduced in OpenMP 6.0 Also see discussion in D105706. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D107540
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r--llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index dbb5e8e..9c9893c 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1586,6 +1586,7 @@ TEST_F(OpenMPIRBuilderTest, TileSingleLoopCounts) {
CanonicalLoopInfo *Loop =
OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, StartVal, StopVal,
StepVal, IsSigned, InclusiveStop);
+ InsertPointTy AfterIP = Loop->getAfterIP();
// Tile the loop.
Value *TileSizeVal = ConstantInt::get(LCTy, TileSize);
@@ -1594,7 +1595,7 @@ TEST_F(OpenMPIRBuilderTest, TileSingleLoopCounts) {
// Set the insertion pointer to after loop, where the next loop will be
// emitted.
- Builder.restoreIP(Loop->getAfterIP());
+ Builder.restoreIP(AfterIP);
// Extract the trip count.
CanonicalLoopInfo *FloorLoop = GenLoops[0];
@@ -1663,12 +1664,20 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
CanonicalLoopInfo *CLI = OMPBuilder.createCanonicalLoop(
Loc, LoopBodyGen, StartVal, StopVal, StepVal,
/*IsSigned=*/false, /*InclusiveStop=*/false);
+ BasicBlock *Preheader = CLI->getPreheader();
+ BasicBlock *Body = CLI->getBody();
+ Value *IV = CLI->getIndVar();
+ BasicBlock *ExitBlock = CLI->getExit();
Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
InsertPointTy AllocaIP = Builder.saveIP();
- CLI = OMPBuilder.createStaticWorkshareLoop(Loc, CLI, AllocaIP,
- /*NeedsBarrier=*/true);
+ OMPBuilder.applyStaticWorkshareLoop(DL, CLI, AllocaIP, /*NeedsBarrier=*/true);
+
+ BasicBlock *Cond = Body->getSinglePredecessor();
+ Instruction *Cmp = &*Cond->begin();
+ Value *TripCount = Cmp->getOperand(1);
+
auto AllocaIter = BB->begin();
ASSERT_GE(std::distance(BB->begin(), BB->end()), 4);
AllocaInst *PLastIter = dyn_cast<AllocaInst>(&*(AllocaIter++));
@@ -1680,10 +1689,8 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
EXPECT_NE(PUpperBound, nullptr);
EXPECT_NE(PStride, nullptr);
- auto PreheaderIter = CLI->getPreheader()->begin();
- ASSERT_GE(
- std::distance(CLI->getPreheader()->begin(), CLI->getPreheader()->end()),
- 7);
+ auto PreheaderIter = Preheader->begin();
+ ASSERT_GE(std::distance(Preheader->begin(), Preheader->end()), 7);
StoreInst *LowerBoundStore = dyn_cast<StoreInst>(&*(PreheaderIter++));
StoreInst *UpperBoundStore = dyn_cast<StoreInst>(&*(PreheaderIter++));
StoreInst *StrideStore = dyn_cast<StoreInst>(&*(PreheaderIter++));
@@ -1705,15 +1712,15 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
// Check that the loop IV is updated to account for the lower bound returned
// by the OpenMP runtime call.
- BinaryOperator *Add = dyn_cast<BinaryOperator>(&CLI->getBody()->front());
- EXPECT_EQ(Add->getOperand(0), CLI->getIndVar());
+ BinaryOperator *Add = dyn_cast<BinaryOperator>(&Body->front());
+ EXPECT_EQ(Add->getOperand(0), IV);
auto *LoadedLowerBound = dyn_cast<LoadInst>(Add->getOperand(1));
ASSERT_NE(LoadedLowerBound, nullptr);
EXPECT_EQ(LoadedLowerBound->getPointerOperand(), PLowerBound);
// Check that the trip count is updated to account for the lower and upper
// bounds return by the OpenMP runtime call.
- auto *AddOne = dyn_cast<Instruction>(CLI->getTripCount());
+ auto *AddOne = dyn_cast<Instruction>(TripCount);
ASSERT_NE(AddOne, nullptr);
ASSERT_TRUE(AddOne->isBinaryOp());
auto *One = dyn_cast<ConstantInt>(AddOne->getOperand(1));
@@ -1729,12 +1736,10 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
// 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.
- Value *IV = CLI->getIndVar();
EXPECT_EQ(std::distance(IV->use_begin(), IV->use_end()), 3);
// The exit block should contain the "fini" call and the barrier call,
// plus the call to obtain the thread ID.
- BasicBlock *ExitBlock = CLI->getExit();
size_t NumCallsInExitBlock =
count_if(*ExitBlock, [](Instruction &I) { return isa<CallInst>(I); });
EXPECT_EQ(NumCallsInExitBlock, 3u);
@@ -1785,8 +1790,8 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
Value *IV = CLI->getIndVar();
InsertPointTy EndIP =
- OMPBuilder.createDynamicWorkshareLoop(Loc, CLI, AllocaIP, SchedType,
- /*NeedsBarrier=*/true, ChunkVal);
+ OMPBuilder.applyDynamicWorkshareLoop(DL, CLI, AllocaIP, SchedType,
+ /*NeedsBarrier=*/true, ChunkVal);
// The returned value should be the "after" point.
ASSERT_EQ(EndIP.getBlock(), AfterIP.getBlock());
ASSERT_EQ(EndIP.getPoint(), AfterIP.getPoint());