@@ -161,7 +161,7 @@ static omp::ScheduleKind getSchedKind(omp::OMPScheduleType SchedType) {
161
161
class OpenMPIRBuilderTest : public testing ::Test {
162
162
protected:
163
163
void SetUp () override {
164
- Ctx.setOpaquePointers (false ); // TODO: Update tests for opaque pointers.
164
+ Ctx.setOpaquePointers (true );
165
165
M.reset (new Module (" MyModule" , Ctx));
166
166
FunctionType *FTy =
167
167
FunctionType::get (Type::getVoidTy (Ctx), {Type::getInt32Ty (Ctx)},
@@ -680,16 +680,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
680
680
EXPECT_EQ (&OutlinedFn->getEntryBlock (), PrivAI->getParent ());
681
681
EXPECT_EQ (OutlinedFn->getNumUses (), 1U );
682
682
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);
685
685
ASSERT_NE (ForkCI, nullptr );
686
686
687
687
EXPECT_EQ (ForkCI->getCalledFunction ()->getName (), " __kmpc_fork_call" );
688
688
EXPECT_EQ (ForkCI->arg_size (), 4U );
689
689
EXPECT_TRUE (isa<GlobalVariable>(ForkCI->getArgOperand (0 )));
690
690
EXPECT_EQ (ForkCI->getArgOperand (1 ),
691
691
ConstantInt::get (Type::getInt32Ty (Ctx), 1U ));
692
- EXPECT_EQ (ForkCI-> getArgOperand ( 2 ) , Usr);
692
+ EXPECT_EQ (ForkCI, Usr);
693
693
Value *StoredValue =
694
694
findStoredValueInAggregateAt (Ctx, ForkCI->getArgOperand (3 ), 0 );
695
695
EXPECT_EQ (StoredValue, F->arg_begin ());
@@ -776,16 +776,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
776
776
777
777
EXPECT_EQ (OutlinedFn.getNumUses (), 1U );
778
778
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);
781
781
ASSERT_NE (ForkCI, nullptr );
782
782
783
783
EXPECT_EQ (ForkCI->getCalledFunction ()->getName (), " __kmpc_fork_call" );
784
784
EXPECT_EQ (ForkCI->arg_size (), 3U );
785
785
EXPECT_TRUE (isa<GlobalVariable>(ForkCI->getArgOperand (0 )));
786
786
EXPECT_EQ (ForkCI->getArgOperand (1 ),
787
787
ConstantInt::get (Type::getInt32Ty (Ctx), 0U ));
788
- EXPECT_EQ (ForkCI-> getArgOperand ( 2 ) , Usr);
788
+ EXPECT_EQ (ForkCI, Usr);
789
789
}
790
790
}
791
791
@@ -885,16 +885,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
885
885
886
886
EXPECT_EQ (OutlinedFn.getNumUses (), 1U );
887
887
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);
890
890
ASSERT_NE (ForkCI, nullptr );
891
891
892
892
EXPECT_EQ (ForkCI->getCalledFunction ()->getName (), " __kmpc_fork_call" );
893
893
EXPECT_EQ (ForkCI->arg_size (), 3U );
894
894
EXPECT_TRUE (isa<GlobalVariable>(ForkCI->getArgOperand (0 )));
895
895
EXPECT_EQ (ForkCI->getArgOperand (1 ),
896
896
ConstantInt::get (Type::getInt32Ty (Ctx), 0U ));
897
- EXPECT_EQ (ForkCI-> getArgOperand ( 2 ) , Usr);
897
+ EXPECT_EQ (ForkCI, Usr);
898
898
}
899
899
}
900
900
@@ -990,10 +990,8 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
990
990
991
991
CallInst *ForkCI = nullptr ;
992
992
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);
997
995
}
998
996
999
997
EXPECT_EQ (ForkCI->getCalledFunction ()->getName (), " __kmpc_fork_call_if" );
@@ -3298,14 +3296,9 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicReadFlt) {
3298
3296
IntegerType *IntCastTy =
3299
3297
IntegerType::get (M->getContext (), Float32->getScalarSizeInBits ());
3300
3298
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 ());
3307
3300
EXPECT_TRUE (AtomicLoad->isAtomic ());
3308
- EXPECT_EQ (AtomicLoad->getPointerOperand (), CastFrmFlt );
3301
+ EXPECT_EQ (AtomicLoad->getPointerOperand (), XVal );
3309
3302
3310
3303
BitCastInst *CastToFlt = cast<BitCastInst>(AtomicLoad->getNextNode ());
3311
3304
EXPECT_EQ (CastToFlt->getSrcTy (), IntCastTy);
@@ -3391,16 +3384,11 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteFlt) {
3391
3384
IntegerType *IntCastTy =
3392
3385
IntegerType::get (M->getContext (), Float32->getScalarSizeInBits ());
3393
3386
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
-
3399
3387
Value *ExprCast = Builder.CreateBitCast (ValToWrite, IntCastTy);
3400
3388
3401
- StoreInst *StoreofAtomic = cast<StoreInst>(CastFrmFlt ->getNextNode ());
3389
+ StoreInst *StoreofAtomic = cast<StoreInst>(XVal ->getNextNode ());
3402
3390
EXPECT_EQ (StoreofAtomic->getValueOperand (), ExprCast);
3403
- EXPECT_EQ (StoreofAtomic->getPointerOperand (), CastFrmFlt );
3391
+ EXPECT_EQ (StoreofAtomic->getPointerOperand (), XVal );
3404
3392
EXPECT_TRUE (StoreofAtomic->isAtomic ());
3405
3393
3406
3394
Builder.CreateRetVoid ();
@@ -3569,19 +3557,13 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {
3569
3557
AtomicCmpXchgInst *CmpExchg =
3570
3558
dyn_cast<AtomicCmpXchgInst>(ExVI1->getAggregateOperand ());
3571
3559
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);
3576
3561
EXPECT_EQ (CmpExchg->getCompareOperand (), Phi);
3577
3562
EXPECT_EQ (CmpExchg->getSuccessOrdering (), AtomicOrdering::Monotonic);
3578
3563
3579
3564
LoadInst *Ld = dyn_cast<LoadInst>(CmpExchg->getNewValOperand ());
3580
3565
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 ());
3585
3567
Builder.CreateRetVoid ();
3586
3568
OMPBuilder.finalize ();
3587
3569
EXPECT_FALSE (verifyModule (*M, &errs ()));
@@ -4024,8 +4006,14 @@ static InstTy *findSingleUserInBlock(Value *V, BasicBlock *BB) {
4024
4006
auto *Inst = dyn_cast<InstTy>(U);
4025
4007
if (!Inst || Inst->getParent () != BB)
4026
4008
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
+ }
4029
4017
Result = Inst;
4030
4018
}
4031
4019
return Result;
@@ -4250,7 +4238,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
4250
4238
findCalls (F, omp::RuntimeFunction::OMPRTL___kmpc_fork_call, OMPBuilder,
4251
4239
ForkCalls);
4252
4240
ASSERT_EQ (ForkCalls.size (), 1u );
4253
- Value *CalleeVal = cast<Constant>( ForkCalls[0 ]->getOperand (2 ))-> getOperand ( 0 );
4241
+ Value *CalleeVal = ForkCalls[0 ]->getOperand (2 );
4254
4242
Function *Outlined = dyn_cast<Function>(CalleeVal);
4255
4243
EXPECT_NE (Outlined, nullptr );
4256
4244
@@ -4294,9 +4282,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
4294
4282
4295
4283
// Check that the local array is passed to the function.
4296
4284
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);
4300
4286
4301
4287
// Find the GEP instructions preceding stores to the local array.
4302
4288
Value *FirstArrayElemPtr = nullptr ;
@@ -4307,18 +4293,17 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
4307
4293
4308
4294
// Check that the values stored into the local array are privatized reduction
4309
4295
// variables.
4310
- auto *FirstStored = dyn_cast_or_null<BitCastInst >(
4296
+ auto *FirstPrivatized = dyn_cast_or_null<AllocaInst >(
4311
4297
findStoredValue<GetElementPtrInst>(FirstArrayElemPtr));
4312
- auto *SecondStored = dyn_cast_or_null<BitCastInst >(
4298
+ auto *SecondPrivatized = dyn_cast_or_null<AllocaInst >(
4313
4299
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 ()));
4322
4307
4323
4308
// Check that the result of the runtime reduction call is used for further
4324
4309
// dispatch.
@@ -4355,27 +4340,20 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
4355
4340
// reductions after extracting reduction variables from its arguments.
4356
4341
Function *ReductionFn = cast<Function>(ReductionFnVal);
4357
4342
BasicBlock *FnReductionBB = &ReductionFn->getEntryBlock ();
4358
- auto *Bitcast =
4359
- findSingleUserInBlock<BitCastInst>(ReductionFn->getArg (0 ), FnReductionBB);
4360
4343
Value *FirstLHSPtr;
4361
4344
Value *SecondLHSPtr;
4362
- ASSERT_TRUE (findGEPZeroOne (Bitcast, FirstLHSPtr, SecondLHSPtr));
4345
+ ASSERT_TRUE (
4346
+ findGEPZeroOne (ReductionFn->getArg (0 ), FirstLHSPtr, SecondLHSPtr));
4363
4347
Value *Opaque = findSingleUserInBlock<LoadInst>(FirstLHSPtr, FnReductionBB);
4364
4348
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));
4368
4350
Opaque = findSingleUserInBlock<LoadInst>(SecondLHSPtr, FnReductionBB);
4369
4351
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));
4373
4353
4374
- Bitcast =
4375
- findSingleUserInBlock<BitCastInst>(ReductionFn->getArg (1 ), FnReductionBB);
4376
4354
Value *FirstRHS;
4377
4355
Value *SecondRHS;
4378
- EXPECT_TRUE (findGEPZeroOne (Bitcast , FirstRHS, SecondRHS));
4356
+ EXPECT_TRUE (findGEPZeroOne (ReductionFn-> getArg ( 1 ) , FirstRHS, SecondRHS));
4379
4357
}
4380
4358
4381
4359
TEST_F (OpenMPIRBuilderTest, CreateTwoReductions) {
@@ -4511,9 +4489,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
4511
4489
findCalls (F, omp::RuntimeFunction::OMPRTL___kmpc_fork_call, OMPBuilder,
4512
4490
ForkCalls);
4513
4491
ASSERT_EQ (ForkCalls.size (), 2u );
4514
- Value *CalleeVal = cast<Constant>( ForkCalls[0 ]->getOperand (2 ))-> getOperand ( 0 );
4492
+ Value *CalleeVal = ForkCalls[0 ]->getOperand (2 );
4515
4493
Function *FirstCallee = cast<Function>(CalleeVal);
4516
- CalleeVal = cast<Constant>( ForkCalls[1 ]->getOperand (2 ))-> getOperand ( 0 );
4494
+ CalleeVal = ForkCalls[1 ]->getOperand (2 );
4517
4495
Function *SecondCallee = cast<Function>(CalleeVal);
4518
4496
EXPECT_NE (FirstCallee, SecondCallee);
4519
4497
@@ -4531,32 +4509,22 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
4531
4509
4532
4510
// Each reduction function does its own kind of reduction.
4533
4511
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);
4539
4514
ASSERT_NE (FirstLHSPtr, nullptr );
4540
4515
Value *Opaque = findSingleUserInBlock<LoadInst>(FirstLHSPtr, FnReductionBB);
4541
4516
ASSERT_NE (Opaque, nullptr );
4542
- Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4543
- ASSERT_NE (Bitcast, nullptr );
4544
4517
Instruction::BinaryOps Opcode = Instruction::FAdd;
4545
- EXPECT_TRUE (isSimpleBinaryReduction (Bitcast , FnReductionBB, &Opcode));
4518
+ EXPECT_TRUE (isSimpleBinaryReduction (Opaque , FnReductionBB, &Opcode));
4546
4519
4547
4520
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);
4553
4523
ASSERT_NE (FirstLHSPtr, nullptr );
4554
4524
Opaque = findSingleUserInBlock<LoadInst>(SecondLHSPtr, FnReductionBB);
4555
4525
ASSERT_NE (Opaque, nullptr );
4556
- Bitcast = findSingleUserInBlock<BitCastInst>(Opaque, FnReductionBB);
4557
- ASSERT_NE (Bitcast, nullptr );
4558
4526
Opcode = Instruction::Xor;
4559
- EXPECT_TRUE (isSimpleBinaryReduction (Bitcast , FnReductionBB, &Opcode));
4527
+ EXPECT_TRUE (isSimpleBinaryReduction (Opaque , FnReductionBB, &Opcode));
4560
4528
}
4561
4529
4562
4530
TEST_F (OpenMPIRBuilderTest, CreateSectionsSimple) {
@@ -5352,13 +5320,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {
5352
5320
EXPECT_EQ (NumDeps->getZExtValue (), 1U );
5353
5321
5354
5322
// 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 ));
5359
5324
ASSERT_NE (DepArray, nullptr );
5360
5325
Value::user_iterator DepArrayI = DepArray->user_begin ();
5361
- EXPECT_EQ (*DepArrayI, DepArrayPtr);
5362
5326
++DepArrayI;
5363
5327
Value::user_iterator DepInfoI = DepArrayI->user_begin ();
5364
5328
// Check for the `DependKind` flag in the `DepInfo` array
0 commit comments