Skip to content

Commit 8556bee

Browse files
committed
[MLIR][OpenMP] Update OpenMPIRBuilderTest to use opaque pointers
This patch updates all tests to use to use the opaque pointers. Differential Revision: https://reviews.llvm.org/D147599
1 parent 1edfb4b commit 8556bee

File tree

1 file changed

+51
-87
lines changed

1 file changed

+51
-87
lines changed

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 51 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static omp::ScheduleKind getSchedKind(omp::OMPScheduleType SchedType) {
161161
class OpenMPIRBuilderTest : public testing::Test {
162162
protected:
163163
void SetUp() override {
164-
Ctx.setOpaquePointers(false); // TODO: Update tests for opaque pointers.
164+
Ctx.setOpaquePointers(true);
165165
M.reset(new Module("MyModule", Ctx));
166166
FunctionType *FTy =
167167
FunctionType::get(Type::getVoidTy(Ctx), {Type::getInt32Ty(Ctx)},
@@ -680,16 +680,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
680680
EXPECT_EQ(&OutlinedFn->getEntryBlock(), PrivAI->getParent());
681681
EXPECT_EQ(OutlinedFn->getNumUses(), 1U);
682682
User *Usr = OutlinedFn->user_back();
683-
ASSERT_TRUE(isa<ConstantExpr>(Usr));
684-
CallInst *ForkCI = dyn_cast<CallInst>(Usr->user_back());
683+
ASSERT_TRUE(isa<CallInst>(Usr));
684+
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
685685
ASSERT_NE(ForkCI, nullptr);
686686

687687
EXPECT_EQ(ForkCI->getCalledFunction()->getName(), "__kmpc_fork_call");
688688
EXPECT_EQ(ForkCI->arg_size(), 4U);
689689
EXPECT_TRUE(isa<GlobalVariable>(ForkCI->getArgOperand(0)));
690690
EXPECT_EQ(ForkCI->getArgOperand(1),
691691
ConstantInt::get(Type::getInt32Ty(Ctx), 1U));
692-
EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
692+
EXPECT_EQ(ForkCI, Usr);
693693
Value *StoredValue =
694694
findStoredValueInAggregateAt(Ctx, ForkCI->getArgOperand(3), 0);
695695
EXPECT_EQ(StoredValue, F->arg_begin());
@@ -776,16 +776,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
776776

777777
EXPECT_EQ(OutlinedFn.getNumUses(), 1U);
778778
User *Usr = OutlinedFn.user_back();
779-
ASSERT_TRUE(isa<ConstantExpr>(Usr));
780-
CallInst *ForkCI = dyn_cast<CallInst>(Usr->user_back());
779+
ASSERT_TRUE(isa<CallInst>(Usr));
780+
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
781781
ASSERT_NE(ForkCI, nullptr);
782782

783783
EXPECT_EQ(ForkCI->getCalledFunction()->getName(), "__kmpc_fork_call");
784784
EXPECT_EQ(ForkCI->arg_size(), 3U);
785785
EXPECT_TRUE(isa<GlobalVariable>(ForkCI->getArgOperand(0)));
786786
EXPECT_EQ(ForkCI->getArgOperand(1),
787787
ConstantInt::get(Type::getInt32Ty(Ctx), 0U));
788-
EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
788+
EXPECT_EQ(ForkCI, Usr);
789789
}
790790
}
791791

@@ -885,16 +885,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
885885

886886
EXPECT_EQ(OutlinedFn.getNumUses(), 1U);
887887
User *Usr = OutlinedFn.user_back();
888-
ASSERT_TRUE(isa<ConstantExpr>(Usr));
889-
CallInst *ForkCI = dyn_cast<CallInst>(Usr->user_back());
888+
ASSERT_TRUE(isa<CallInst>(Usr));
889+
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
890890
ASSERT_NE(ForkCI, nullptr);
891891

892892
EXPECT_EQ(ForkCI->getCalledFunction()->getName(), "__kmpc_fork_call");
893893
EXPECT_EQ(ForkCI->arg_size(), 3U);
894894
EXPECT_TRUE(isa<GlobalVariable>(ForkCI->getArgOperand(0)));
895895
EXPECT_EQ(ForkCI->getArgOperand(1),
896896
ConstantInt::get(Type::getInt32Ty(Ctx), 0U));
897-
EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
897+
EXPECT_EQ(ForkCI, Usr);
898898
}
899899
}
900900

@@ -990,10 +990,8 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
990990

991991
CallInst *ForkCI = nullptr;
992992
for (User *Usr : OutlinedFn->users()) {
993-
ASSERT_TRUE(isa<ConstantExpr>(Usr));
994-
ASSERT_EQ(Usr->getNumUses(), 1U);
995-
ASSERT_TRUE(isa<CallInst>(Usr->user_back()));
996-
ForkCI = cast<CallInst>(Usr->user_back());
993+
ASSERT_TRUE(isa<CallInst>(Usr));
994+
ForkCI = cast<CallInst>(Usr);
997995
}
998996

999997
EXPECT_EQ(ForkCI->getCalledFunction()->getName(), "__kmpc_fork_call_if");
@@ -3298,14 +3296,9 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicReadFlt) {
32983296
IntegerType *IntCastTy =
32993297
IntegerType::get(M->getContext(), Float32->getScalarSizeInBits());
33003298

3301-
BitCastInst *CastFrmFlt = cast<BitCastInst>(VVal->getNextNode());
3302-
EXPECT_EQ(CastFrmFlt->getSrcTy(), Float32->getPointerTo());
3303-
EXPECT_EQ(CastFrmFlt->getDestTy(), IntCastTy->getPointerTo());
3304-
EXPECT_EQ(CastFrmFlt->getOperand(0), XVal);
3305-
3306-
LoadInst *AtomicLoad = cast<LoadInst>(CastFrmFlt->getNextNode());
3299+
LoadInst *AtomicLoad = cast<LoadInst>(VVal->getNextNode());
33073300
EXPECT_TRUE(AtomicLoad->isAtomic());
3308-
EXPECT_EQ(AtomicLoad->getPointerOperand(), CastFrmFlt);
3301+
EXPECT_EQ(AtomicLoad->getPointerOperand(), XVal);
33093302

33103303
BitCastInst *CastToFlt = cast<BitCastInst>(AtomicLoad->getNextNode());
33113304
EXPECT_EQ(CastToFlt->getSrcTy(), IntCastTy);
@@ -3391,16 +3384,11 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteFlt) {
33913384
IntegerType *IntCastTy =
33923385
IntegerType::get(M->getContext(), Float32->getScalarSizeInBits());
33933386

3394-
BitCastInst *CastFrmFlt = cast<BitCastInst>(XVal->getNextNode());
3395-
EXPECT_EQ(CastFrmFlt->getSrcTy(), Float32->getPointerTo());
3396-
EXPECT_EQ(CastFrmFlt->getDestTy(), IntCastTy->getPointerTo());
3397-
EXPECT_EQ(CastFrmFlt->getOperand(0), XVal);
3398-
33993387
Value *ExprCast = Builder.CreateBitCast(ValToWrite, IntCastTy);
34003388

3401-
StoreInst *StoreofAtomic = cast<StoreInst>(CastFrmFlt->getNextNode());
3389+
StoreInst *StoreofAtomic = cast<StoreInst>(XVal->getNextNode());
34023390
EXPECT_EQ(StoreofAtomic->getValueOperand(), ExprCast);
3403-
EXPECT_EQ(StoreofAtomic->getPointerOperand(), CastFrmFlt);
3391+
EXPECT_EQ(StoreofAtomic->getPointerOperand(), XVal);
34043392
EXPECT_TRUE(StoreofAtomic->isAtomic());
34053393

34063394
Builder.CreateRetVoid();
@@ -3569,19 +3557,13 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {
35693557
AtomicCmpXchgInst *CmpExchg =
35703558
dyn_cast<AtomicCmpXchgInst>(ExVI1->getAggregateOperand());
35713559
EXPECT_NE(CmpExchg, nullptr);
3572-
BitCastInst *BitCastNew =
3573-
dyn_cast<BitCastInst>(CmpExchg->getPointerOperand());
3574-
EXPECT_NE(BitCastNew, nullptr);
3575-
EXPECT_EQ(BitCastNew->getOperand(0), XVal);
3560+
EXPECT_EQ(CmpExchg->getPointerOperand(), XVal);
35763561
EXPECT_EQ(CmpExchg->getCompareOperand(), Phi);
35773562
EXPECT_EQ(CmpExchg->getSuccessOrdering(), AtomicOrdering::Monotonic);
35783563

35793564
LoadInst *Ld = dyn_cast<LoadInst>(CmpExchg->getNewValOperand());
35803565
EXPECT_NE(Ld, nullptr);
3581-
BitCastInst *BitCastOld = dyn_cast<BitCastInst>(Ld->getPointerOperand());
3582-
EXPECT_NE(BitCastOld, nullptr);
3583-
EXPECT_EQ(UpdateTemp, BitCastOld->getOperand(0));
3584-
3566+
EXPECT_EQ(UpdateTemp, Ld->getPointerOperand());
35853567
Builder.CreateRetVoid();
35863568
OMPBuilder.finalize();
35873569
EXPECT_FALSE(verifyModule(*M, &errs()));
@@ -4024,8 +4006,14 @@ static InstTy *findSingleUserInBlock(Value *V, BasicBlock *BB) {
40244006
auto *Inst = dyn_cast<InstTy>(U);
40254007
if (!Inst || Inst->getParent() != BB)
40264008
continue;
4027-
if (Result)
4028-
return nullptr;
4009+
if (Result) {
4010+
if (auto *SI = dyn_cast<StoreInst>(Inst)) {
4011+
if (V == SI->getValueOperand())
4012+
continue;
4013+
} else {
4014+
return nullptr;
4015+
}
4016+
}
40294017
Result = Inst;
40304018
}
40314019
return Result;
@@ -4250,7 +4238,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
42504238
findCalls(F, omp::RuntimeFunction::OMPRTL___kmpc_fork_call, OMPBuilder,
42514239
ForkCalls);
42524240
ASSERT_EQ(ForkCalls.size(), 1u);
4253-
Value *CalleeVal = cast<Constant>(ForkCalls[0]->getOperand(2))->getOperand(0);
4241+
Value *CalleeVal = ForkCalls[0]->getOperand(2);
42544242
Function *Outlined = dyn_cast<Function>(CalleeVal);
42554243
EXPECT_NE(Outlined, nullptr);
42564244

@@ -4294,9 +4282,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
42944282

42954283
// Check that the local array is passed to the function.
42964284
ASSERT_NE(LocalArrayPtr, nullptr);
4297-
BitCastInst *BitCast = dyn_cast<BitCastInst>(LocalArrayPtr);
4298-
ASSERT_NE(BitCast, nullptr);
4299-
EXPECT_EQ(BitCast->getOperand(0), LocalArray);
4285+
EXPECT_EQ(LocalArrayPtr, LocalArray);
43004286

43014287
// Find the GEP instructions preceding stores to the local array.
43024288
Value *FirstArrayElemPtr = nullptr;
@@ -4307,18 +4293,17 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
43074293

43084294
// Check that the values stored into the local array are privatized reduction
43094295
// variables.
4310-
auto *FirstStored = dyn_cast_or_null<BitCastInst>(
4296+
auto *FirstPrivatized = dyn_cast_or_null<AllocaInst>(
43114297
findStoredValue<GetElementPtrInst>(FirstArrayElemPtr));
4312-
auto *SecondStored = dyn_cast_or_null<BitCastInst>(
4298+
auto *SecondPrivatized = dyn_cast_or_null<AllocaInst>(
43134299
findStoredValue<GetElementPtrInst>(SecondArrayElemPtr));
4314-
ASSERT_NE(FirstStored, nullptr);
4315-
ASSERT_NE(SecondStored, nullptr);
4316-
Value *FirstPrivatized = FirstStored->getOperand(0);
4317-
Value *SecondPrivatized = SecondStored->getOperand(0);
4318-
EXPECT_TRUE(
4319-
isSimpleBinaryReduction(FirstPrivatized, FirstStored->getParent()));
4320-
EXPECT_TRUE(
4321-
isSimpleBinaryReduction(SecondPrivatized, SecondStored->getParent()));
4300+
ASSERT_NE(FirstPrivatized, nullptr);
4301+
ASSERT_NE(SecondPrivatized, nullptr);
4302+
ASSERT_TRUE(isa<Instruction>(FirstArrayElemPtr));
4303+
EXPECT_TRUE(isSimpleBinaryReduction(
4304+
FirstPrivatized, cast<Instruction>(FirstArrayElemPtr)->getParent()));
4305+
EXPECT_TRUE(isSimpleBinaryReduction(
4306+
SecondPrivatized, cast<Instruction>(FirstArrayElemPtr)->getParent()));
43224307

43234308
// Check that the result of the runtime reduction call is used for further
43244309
// dispatch.
@@ -4355,27 +4340,20 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
43554340
// reductions after extracting reduction variables from its arguments.
43564341
Function *ReductionFn = cast<Function>(ReductionFnVal);
43574342
BasicBlock *FnReductionBB = &ReductionFn->getEntryBlock();
4358-
auto *Bitcast =
4359-
findSingleUserInBlock<BitCastInst>(ReductionFn->getArg(0), FnReductionBB);
43604343
Value *FirstLHSPtr;
43614344
Value *SecondLHSPtr;
4362-
ASSERT_TRUE(findGEPZeroOne(Bitcast, FirstLHSPtr, SecondLHSPtr));
4345+
ASSERT_TRUE(
4346+
findGEPZeroOne(ReductionFn->getArg(0), FirstLHSPtr, SecondLHSPtr));
43634347
Value *Opaque = findSingleUserInBlock<LoadInst>(FirstLHSPtr, FnReductionBB);
43644348
ASSERT_NE(Opaque, nullptr);
4365-
Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4366-
ASSERT_NE(Bitcast, nullptr);
4367-
EXPECT_TRUE(isSimpleBinaryReduction(Bitcast, FnReductionBB));
4349+
EXPECT_TRUE(isSimpleBinaryReduction(Opaque, FnReductionBB));
43684350
Opaque = findSingleUserInBlock<LoadInst>(SecondLHSPtr, FnReductionBB);
43694351
ASSERT_NE(Opaque, nullptr);
4370-
Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4371-
ASSERT_NE(Bitcast, nullptr);
4372-
EXPECT_TRUE(isSimpleBinaryReduction(Bitcast, FnReductionBB));
4352+
EXPECT_TRUE(isSimpleBinaryReduction(Opaque, FnReductionBB));
43734353

4374-
Bitcast =
4375-
findSingleUserInBlock<BitCastInst>(ReductionFn->getArg(1), FnReductionBB);
43764354
Value *FirstRHS;
43774355
Value *SecondRHS;
4378-
EXPECT_TRUE(findGEPZeroOne(Bitcast, FirstRHS, SecondRHS));
4356+
EXPECT_TRUE(findGEPZeroOne(ReductionFn->getArg(1), FirstRHS, SecondRHS));
43794357
}
43804358

43814359
TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
@@ -4511,9 +4489,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
45114489
findCalls(F, omp::RuntimeFunction::OMPRTL___kmpc_fork_call, OMPBuilder,
45124490
ForkCalls);
45134491
ASSERT_EQ(ForkCalls.size(), 2u);
4514-
Value *CalleeVal = cast<Constant>(ForkCalls[0]->getOperand(2))->getOperand(0);
4492+
Value *CalleeVal = ForkCalls[0]->getOperand(2);
45154493
Function *FirstCallee = cast<Function>(CalleeVal);
4516-
CalleeVal = cast<Constant>(ForkCalls[1]->getOperand(2))->getOperand(0);
4494+
CalleeVal = ForkCalls[1]->getOperand(2);
45174495
Function *SecondCallee = cast<Function>(CalleeVal);
45184496
EXPECT_NE(FirstCallee, SecondCallee);
45194497

@@ -4531,32 +4509,22 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
45314509

45324510
// Each reduction function does its own kind of reduction.
45334511
BasicBlock *FnReductionBB = &AddReduction->getEntryBlock();
4534-
auto *Bitcast = findSingleUserInBlock<BitCastInst>(AddReduction->getArg(0),
4535-
FnReductionBB);
4536-
ASSERT_NE(Bitcast, nullptr);
4537-
Value *FirstLHSPtr =
4538-
findSingleUserInBlock<GetElementPtrInst>(Bitcast, FnReductionBB);
4512+
Value *FirstLHSPtr = findSingleUserInBlock<GetElementPtrInst>(
4513+
AddReduction->getArg(0), FnReductionBB);
45394514
ASSERT_NE(FirstLHSPtr, nullptr);
45404515
Value *Opaque = findSingleUserInBlock<LoadInst>(FirstLHSPtr, FnReductionBB);
45414516
ASSERT_NE(Opaque, nullptr);
4542-
Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4543-
ASSERT_NE(Bitcast, nullptr);
45444517
Instruction::BinaryOps Opcode = Instruction::FAdd;
4545-
EXPECT_TRUE(isSimpleBinaryReduction(Bitcast, FnReductionBB, &Opcode));
4518+
EXPECT_TRUE(isSimpleBinaryReduction(Opaque, FnReductionBB, &Opcode));
45464519

45474520
FnReductionBB = &XorReduction->getEntryBlock();
4548-
Bitcast = findSingleUserInBlock<BitCastInst>(XorReduction->getArg(0),
4549-
FnReductionBB);
4550-
ASSERT_NE(Bitcast, nullptr);
4551-
Value *SecondLHSPtr =
4552-
findSingleUserInBlock<GetElementPtrInst>(Bitcast, FnReductionBB);
4521+
Value *SecondLHSPtr = findSingleUserInBlock<GetElementPtrInst>(
4522+
XorReduction->getArg(0), FnReductionBB);
45534523
ASSERT_NE(FirstLHSPtr, nullptr);
45544524
Opaque = findSingleUserInBlock<LoadInst>(SecondLHSPtr, FnReductionBB);
45554525
ASSERT_NE(Opaque, nullptr);
4556-
Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4557-
ASSERT_NE(Bitcast, nullptr);
45584526
Opcode = Instruction::Xor;
4559-
EXPECT_TRUE(isSimpleBinaryReduction(Bitcast, FnReductionBB, &Opcode));
4527+
EXPECT_TRUE(isSimpleBinaryReduction(Opaque, FnReductionBB, &Opcode));
45604528
}
45614529

45624530
TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) {
@@ -5352,13 +5320,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {
53525320
EXPECT_EQ(NumDeps->getZExtValue(), 1U);
53535321

53545322
// Check for the `DepInfo` array argument
5355-
BitCastInst *DepArrayPtr =
5356-
dyn_cast<BitCastInst>(TaskAllocCall->getOperand(4));
5357-
ASSERT_NE(DepArrayPtr, nullptr);
5358-
AllocaInst *DepArray = dyn_cast<AllocaInst>(DepArrayPtr->getOperand(0));
5323+
AllocaInst *DepArray = dyn_cast<AllocaInst>(TaskAllocCall->getOperand(4));
53595324
ASSERT_NE(DepArray, nullptr);
53605325
Value::user_iterator DepArrayI = DepArray->user_begin();
5361-
EXPECT_EQ(*DepArrayI, DepArrayPtr);
53625326
++DepArrayI;
53635327
Value::user_iterator DepInfoI = DepArrayI->user_begin();
53645328
// Check for the `DependKind` flag in the `DepInfo` array

0 commit comments

Comments
 (0)