@@ -4408,13 +4408,10 @@ IRGenSILFunction::visitSwitchEnumAddrInst(SwitchEnumAddrInst *inst) {
4408
4408
4409
4409
// FIXME: We could lower select_enum directly to LLVM select in a lot of cases.
4410
4410
// For now, just emit a switch and phi nodes, like a chump.
4411
- template <class C , class T , class B >
4412
- static llvm::BasicBlock *
4413
- emitBBMapForSelect (IRGenSILFunction &IGF, Explosion &resultPHI,
4414
- SmallVectorImpl<std::pair<T, llvm::BasicBlock *>> &BBs,
4415
- llvm::BasicBlock *&defaultBB,
4416
- SelectInstBase<C, T, B> *inst) {
4417
-
4411
+ static llvm::BasicBlock *emitBBMapForSelect (
4412
+ IRGenSILFunction &IGF, Explosion &resultPHI,
4413
+ SmallVectorImpl<std::pair<EnumElementDecl *, llvm::BasicBlock *>> &BBs,
4414
+ llvm::BasicBlock *&defaultBB, SelectEnumOperation inst) {
4418
4415
auto origBB = IGF.Builder .GetInsertBlock ();
4419
4416
4420
4417
// Set up a continuation BB and phi nodes to receive the result value.
@@ -4425,8 +4422,7 @@ emitBBMapForSelect(IRGenSILFunction &IGF, Explosion &resultPHI,
4425
4422
SmallVector<llvm::Value*, 4 > phis;
4426
4423
auto &ti = IGF.getTypeInfo (inst->getType ());
4427
4424
emitPHINodesForType (IGF, inst->getType (), ti,
4428
- inst->getNumCases () + inst->hasDefault (),
4429
- phis);
4425
+ inst.getNumCases () + inst.hasDefault (), phis);
4430
4426
resultPHI.add (phis);
4431
4427
4432
4428
IGF.Builder .SetInsertPoint (origBB);
@@ -4440,10 +4436,10 @@ emitBBMapForSelect(IRGenSILFunction &IGF, Explosion &resultPHI,
4440
4436
addIncomingExplosionToPHINodes (IGF, resultPHI.getAll (), ex);
4441
4437
}
4442
4438
};
4443
-
4444
- for (unsigned i = 0 , e = inst-> getNumCases (); i < e; ++i) {
4445
- auto casePair = inst-> getCase (i);
4446
-
4439
+
4440
+ for (unsigned i = 0 , e = inst. getNumCases (); i < e; ++i) {
4441
+ auto casePair = inst. getCase (i);
4442
+
4447
4443
// Create a basic block destination for this case.
4448
4444
llvm::BasicBlock *destBB = IGF.createBasicBlock (" " );
4449
4445
IGF.Builder .emitBlock (destBB);
@@ -4455,18 +4451,18 @@ emitBBMapForSelect(IRGenSILFunction &IGF, Explosion &resultPHI,
4455
4451
IGF.Builder .CreateBr (contBB);
4456
4452
BBs.push_back (std::make_pair (casePair.first , destBB));
4457
4453
}
4458
-
4459
- if (inst-> hasDefault ()) {
4454
+
4455
+ if (inst. hasDefault ()) {
4460
4456
defaultBB = IGF.createBasicBlock (" " );
4461
4457
IGF.Builder .emitBlock (defaultBB);
4462
-
4463
- addIncoming (inst-> getDefaultResult ());
4464
-
4458
+
4459
+ addIncoming (inst. getDefaultResult ());
4460
+
4465
4461
IGF.Builder .CreateBr (contBB);
4466
4462
} else {
4467
4463
defaultBB = nullptr ;
4468
4464
}
4469
-
4465
+
4470
4466
IGF.Builder .emitBlock (contBB);
4471
4467
4472
4468
IGF.Builder .SetInsertPoint (origBB);
@@ -4545,10 +4541,9 @@ mapTriviallyToInt(IRGenSILFunction &IGF, const EnumImplStrategy &EIS, SelectEnum
4545
4541
return result;
4546
4542
}
4547
4543
4548
- template <class C , class T , class B >
4549
4544
static LoweredValue getLoweredValueForSelect (IRGenSILFunction &IGF,
4550
4545
Explosion &result,
4551
- SelectInstBase<C, T, B> * inst) {
4546
+ SelectEnumOperation inst) {
4552
4547
if (inst->getType ().isAddress ())
4553
4548
// FIXME: Loses potentially better alignment info we might have.
4554
4549
return LoweredValue (Address (
@@ -4558,14 +4553,14 @@ static LoweredValue getLoweredValueForSelect(IRGenSILFunction &IGF,
4558
4553
}
4559
4554
4560
4555
static void emitSingleEnumMemberSelectResult (IRGenSILFunction &IGF,
4561
- SelectEnumInstBase *inst ,
4556
+ SelectEnumOperation seo ,
4562
4557
llvm::Value *isTrue,
4563
4558
Explosion &result) {
4564
- assert ((inst-> getNumCases () == 1 && inst-> hasDefault ()) ||
4565
- (inst-> getNumCases () == 2 && !inst-> hasDefault ()));
4566
-
4559
+ assert ((seo. getNumCases () == 1 && seo. hasDefault ()) ||
4560
+ (seo. getNumCases () == 2 && !seo. hasDefault ()));
4561
+
4567
4562
// Extract the true values.
4568
- auto trueValue = inst-> getCase (0 ).second ;
4563
+ auto trueValue = seo. getCase (0 ).second ;
4569
4564
SmallVector<llvm::Value*, 4 > TrueValues;
4570
4565
if (trueValue->getType ().isAddress ()) {
4571
4566
TrueValues.push_back (IGF.getLoweredAddress (trueValue).getAddress ());
@@ -4577,7 +4572,7 @@ static void emitSingleEnumMemberSelectResult(IRGenSILFunction &IGF,
4577
4572
4578
4573
// Extract the false values.
4579
4574
auto falseValue =
4580
- inst-> hasDefault () ? inst-> getDefaultResult () : inst-> getCase (1 ).second ;
4575
+ seo. hasDefault () ? seo. getDefaultResult () : seo. getCase (1 ).second ;
4581
4576
SmallVector<llvm::Value*, 4 > FalseValues;
4582
4577
if (falseValue->getType ().isAddress ()) {
4583
4578
FalseValues.push_back (IGF.getLoweredAddress (falseValue).getAddress ());
@@ -4605,11 +4600,10 @@ static void emitSingleEnumMemberSelectResult(IRGenSILFunction &IGF,
4605
4600
}
4606
4601
}
4607
4602
4608
-
4609
4603
void IRGenSILFunction::visitSelectEnumInst (SelectEnumInst *inst) {
4610
4604
auto &EIS = getEnumImplStrategy (IGM, inst->getEnumOperand ()->getType ());
4605
+ auto seo = SelectEnumOperation (inst);
4611
4606
Explosion result;
4612
-
4613
4607
if (llvm::Value *R = mapTriviallyToInt (*this , EIS, inst)) {
4614
4608
result.add (R);
4615
4609
} else if ((inst->getNumCases () == 1 && inst->hasDefault ()) ||
@@ -4618,29 +4612,30 @@ void IRGenSILFunction::visitSelectEnumInst(SelectEnumInst *inst) {
4618
4612
// particularly common when testing optionals.
4619
4613
Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4620
4614
auto isTrue = EIS.emitValueCaseTest (*this , value, inst->getCase (0 ).first );
4621
- emitSingleEnumMemberSelectResult (*this , inst, isTrue, result);
4615
+ emitSingleEnumMemberSelectResult (*this , SelectEnumOperation (inst), isTrue,
4616
+ result);
4622
4617
} else {
4623
4618
Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4624
4619
4625
4620
// Map the SIL dest bbs to their LLVM bbs.
4626
4621
SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
4627
4622
llvm::BasicBlock *defaultDest;
4628
- llvm::BasicBlock *contBB
4629
- = emitBBMapForSelect (*this , result, dests, defaultDest, inst );
4630
-
4623
+ llvm::BasicBlock *contBB =
4624
+ emitBBMapForSelect (*this , result, dests, defaultDest, seo );
4625
+
4631
4626
// Emit the dispatch.
4632
4627
EIS.emitValueSwitch (*this , value, dests, defaultDest);
4633
4628
4634
4629
// emitBBMapForSelectEnum set up a continuation block and phi nodes to
4635
4630
// receive the result.
4636
4631
Builder.SetInsertPoint (contBB);
4637
4632
}
4638
- setLoweredValue (inst,
4639
- getLoweredValueForSelect (*this , result, inst));
4633
+ setLoweredValue (inst, getLoweredValueForSelect (*this , result, seo));
4640
4634
}
4641
4635
4642
4636
void IRGenSILFunction::visitSelectEnumAddrInst (SelectEnumAddrInst *inst) {
4643
4637
Address value = getLoweredAddress (inst->getEnumOperand ());
4638
+ auto seo = SelectEnumOperation (inst);
4644
4639
Explosion result;
4645
4640
4646
4641
if ((inst->getNumCases () == 1 && inst->hasDefault ()) ||
@@ -4651,14 +4646,15 @@ void IRGenSILFunction::visitSelectEnumAddrInst(SelectEnumAddrInst *inst) {
4651
4646
auto isTrue = EIS.emitIndirectCaseTest (*this ,
4652
4647
inst->getEnumOperand ()->getType (),
4653
4648
value, inst->getCase (0 ).first );
4654
- emitSingleEnumMemberSelectResult (*this , inst, isTrue, result);
4649
+ emitSingleEnumMemberSelectResult (*this , SelectEnumOperation (inst), isTrue,
4650
+ result);
4655
4651
} else {
4656
4652
// Map the SIL dest bbs to their LLVM bbs.
4657
4653
SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
4658
4654
llvm::BasicBlock *defaultDest;
4659
- llvm::BasicBlock *contBB
4660
- = emitBBMapForSelect (*this , result, dests, defaultDest, inst );
4661
-
4655
+ llvm::BasicBlock *contBB =
4656
+ emitBBMapForSelect (*this , result, dests, defaultDest, seo );
4657
+
4662
4658
// Emit the dispatch.
4663
4659
emitSwitchAddressOnlyEnumDispatch (*this , inst->getEnumOperand ()->getType (),
4664
4660
value, dests, defaultDest);
@@ -4667,8 +4663,7 @@ void IRGenSILFunction::visitSelectEnumAddrInst(SelectEnumAddrInst *inst) {
4667
4663
Builder.SetInsertPoint (contBB);
4668
4664
}
4669
4665
4670
- setLoweredValue (inst,
4671
- getLoweredValueForSelect (*this , result, inst));
4666
+ setLoweredValue (inst, getLoweredValueForSelect (*this , result, seo));
4672
4667
}
4673
4668
4674
4669
void IRGenSILFunction::visitDynamicMethodBranchInst (DynamicMethodBranchInst *i){
0 commit comments