@@ -431,6 +431,33 @@ static void getArgAsLocalSelfTypeMetadata(IRGenFunction &IGF,
431
431
getArgAsLocalSelfTypeMetadata (IGF, arg, abstractType);
432
432
}
433
433
434
+ static const TypeLayoutEntry *
435
+ conditionallyGetTypeLayoutEntry (IRGenModule &IGM, SILType concreteType) {
436
+ if (!IGM.getOptions ().UseTypeLayoutValueHandling )
437
+ return nullptr ;
438
+
439
+ auto &typeLayoutEntry = IGM.getTypeLayoutEntry (concreteType);
440
+
441
+ // Don't use type layout based generation for layouts that contain a resilient
442
+ // field but no archetype. We don't expect a speadup by using type layout
443
+ // based ir generation.
444
+ if ((typeLayoutEntry.containsResilientField () &&
445
+ !typeLayoutEntry.containsArchetypeField ()) ||
446
+ typeLayoutEntry.containsDependentResilientField ())
447
+ return nullptr ;
448
+
449
+ return &typeLayoutEntry;
450
+ }
451
+
452
+ static const EnumTypeLayoutEntry *
453
+ conditionallyGetEnumTypeLayoutEntry (IRGenModule &IGM, SILType concreteType) {
454
+ auto *entry = conditionallyGetTypeLayoutEntry (IGM, concreteType);
455
+ if (!entry)
456
+ return nullptr ;
457
+
458
+ return entry->getAsEnum ();
459
+ }
460
+
434
461
// / Build a specific value-witness function.
435
462
static void buildValueWitnessFunction (IRGenModule &IGM,
436
463
llvm::Function *fn,
@@ -452,9 +479,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
452
479
Address src = getArgAs (IGF, argv, type, " src" );
453
480
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
454
481
455
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
456
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
457
- typeLayoutEntry. assignWithCopy (IGF, dest, src);
482
+ if (auto *typeLayoutEntry =
483
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
484
+ typeLayoutEntry-> assignWithCopy (IGF, dest, src);
458
485
} else {
459
486
type.assignWithCopy (IGF, dest, src, concreteType, true );
460
487
}
@@ -467,9 +494,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
467
494
Address dest = getArgAs (IGF, argv, type, " dest" );
468
495
Address src = getArgAs (IGF, argv, type, " src" );
469
496
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
470
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
471
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
472
- typeLayoutEntry. assignWithTake (IGF, dest, src);
497
+ if (auto *typeLayoutEntry =
498
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
499
+ typeLayoutEntry-> assignWithTake (IGF, dest, src);
473
500
} else {
474
501
type.assignWithTake (IGF, dest, src, concreteType, true );
475
502
}
@@ -481,9 +508,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
481
508
case ValueWitness::Destroy: {
482
509
Address object = getArgAs (IGF, argv, type, " object" );
483
510
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
484
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
485
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
486
- typeLayoutEntry. destroy (IGF, object);
511
+ if (auto *typeLayoutEntry =
512
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
513
+ typeLayoutEntry-> destroy (IGF, object);
487
514
} else {
488
515
type.destroy (IGF, object, concreteType, true );
489
516
}
@@ -497,9 +524,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
497
524
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
498
525
499
526
llvm::Value *objectPtr = nullptr ;
500
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
501
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
502
- objectPtr = typeLayoutEntry. initBufferWithCopyOfBuffer (IGF, dest, src);
527
+ if (auto *typeLayoutEntry =
528
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
529
+ objectPtr = typeLayoutEntry-> initBufferWithCopyOfBuffer (IGF, dest, src);
503
530
} else {
504
531
Address result = emitInitializeBufferWithCopyOfBuffer (
505
532
IGF, dest, src, concreteType, type, packing);
@@ -514,9 +541,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
514
541
Address dest = getArgAs (IGF, argv, type, " dest" );
515
542
Address src = getArgAs (IGF, argv, type, " src" );
516
543
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
517
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
518
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
519
- typeLayoutEntry. initWithCopy (IGF, dest, src);
544
+ if (auto *typeLayoutEntry =
545
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
546
+ typeLayoutEntry-> initWithCopy (IGF, dest, src);
520
547
} else {
521
548
type.initializeWithCopy (IGF, dest, src, concreteType, true );
522
549
}
@@ -530,9 +557,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
530
557
Address src = getArgAs (IGF, argv, type, " src" );
531
558
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
532
559
533
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
534
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
535
- typeLayoutEntry. initWithTake (IGF, dest, src);
560
+ if (auto *typeLayoutEntry =
561
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
562
+ typeLayoutEntry-> initWithTake (IGF, dest, src);
536
563
} else {
537
564
type.initializeWithTake (IGF, dest, src, concreteType, true );
538
565
}
@@ -552,9 +579,8 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
552
579
auto enumAddr = type.getAddressForPointer (value);
553
580
554
581
llvm::Value *result;
555
- auto &typeLayoutEntry = IGM.getTypeLayoutEntry (concreteType);
556
- const auto *enumTypeLayoutEntry = typeLayoutEntry.getAsEnum ();
557
- if (enumTypeLayoutEntry && IGM.getOptions ().UseTypeLayoutValueHandling ) {
582
+ if (auto *enumTypeLayoutEntry =
583
+ conditionallyGetEnumTypeLayoutEntry (IGM, concreteType)) {
558
584
result = enumTypeLayoutEntry->getEnumTag (IGF, enumAddr);
559
585
} else {
560
586
result = strategy.emitGetEnumTag (IGF, concreteType, enumAddr);
@@ -570,9 +596,8 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
570
596
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
571
597
572
598
if (!strategy.getElementsWithPayload ().empty ()) {
573
- auto &typeLayoutEntry = IGM.getTypeLayoutEntry (concreteType);
574
- const auto *enumTypeLayoutEntry = typeLayoutEntry.getAsEnum ();
575
- if (enumTypeLayoutEntry && IGM.getOptions ().UseTypeLayoutValueHandling ) {
599
+ if (auto *enumTypeLayoutEntry =
600
+ conditionallyGetEnumTypeLayoutEntry (IGM, concreteType)) {
576
601
enumTypeLayoutEntry->destructiveProjectEnumData (
577
602
IGF, Address (value, type.getBestKnownAlignment ()));
578
603
} else {
@@ -596,9 +621,8 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
596
621
llvm::Value *tag = getArg (argv, " tag" );
597
622
598
623
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
599
- auto &typeLayoutEntry = IGM.getTypeLayoutEntry (concreteType);
600
- const auto *enumTypeLayoutEntry = typeLayoutEntry.getAsEnum ();
601
- if (enumTypeLayoutEntry && IGM.getOptions ().UseTypeLayoutValueHandling ) {
624
+ if (auto *enumTypeLayoutEntry =
625
+ conditionallyGetEnumTypeLayoutEntry (IGM, concreteType)) {
602
626
enumTypeLayoutEntry->destructiveInjectEnumTag (
603
627
IGF, tag, Address (value, type.getBestKnownAlignment ()));
604
628
} else {
@@ -618,9 +642,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
618
642
llvm::Value *numEmptyCases = getArg (argv, " numEmptyCases" );
619
643
620
644
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
621
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
622
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
623
- auto *idx = typeLayoutEntry. getEnumTagSinglePayload (
645
+ if (auto *typeLayoutEntry =
646
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
647
+ auto *idx = typeLayoutEntry-> getEnumTagSinglePayload (
624
648
IGF, numEmptyCases, Address (value, type.getBestKnownAlignment ()));
625
649
IGF.Builder .CreateRet (idx);
626
650
} else {
@@ -642,9 +666,9 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
642
666
llvm::Value *numEmptyCases = getArg (argv, " numEmptyCases" );
643
667
644
668
getArgAsLocalSelfTypeMetadata (IGF, argv, abstractType);
645
- if (IGM. getOptions (). UseTypeLayoutValueHandling ) {
646
- auto &typeLayoutEntry = IGM. getTypeLayoutEntry ( concreteType);
647
- typeLayoutEntry. storeEnumTagSinglePayload (
669
+ if (auto *typeLayoutEntry =
670
+ conditionallyGetTypeLayoutEntry (IGM, concreteType)) {
671
+ typeLayoutEntry-> storeEnumTagSinglePayload (
648
672
IGF, whichCase, numEmptyCases,
649
673
Address (value, type.getBestKnownAlignment ()));
650
674
} else {
0 commit comments