@@ -538,14 +538,17 @@ namespace {
538
538
// Trivial
539
539
}
540
540
541
- void emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue value,
542
- LoweringStyle style) const override {
541
+ SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc,
542
+ SILValue value,
543
+ LoweringStyle style) const override {
543
544
// Trivial
545
+ return value;
544
546
}
545
547
546
- void emitCopyValue (SILBuilder &B, SILLocation loc,
547
- SILValue value) const override {
548
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
549
+ SILValue value) const override {
548
550
// Trivial
551
+ return value;
549
552
}
550
553
551
554
void emitDestroyValue (SILBuilder &B, SILLocation loc,
@@ -615,6 +618,9 @@ namespace {
615
618
IsNotReferenceCounted) {
616
619
}
617
620
621
+ virtual SILValue rebuildAggregate (SILBuilder &B, SILLocation loc,
622
+ ArrayRef<SILValue> values) const = 0;
623
+
618
624
ArrayRef<Child> getChildren (SILModule &M) const {
619
625
if (Children.data () == nullptr ) {
620
626
SmallVector<Child, 4 > children;
@@ -657,22 +663,31 @@ namespace {
657
663
});
658
664
}
659
665
660
- void emitCopyValue (SILBuilder &B, SILLocation loc,
661
- SILValue aggValue) const override {
666
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
667
+ SILValue aggValue) const override {
662
668
B.createRetainValue (loc, aggValue, Atomicity::Atomic);
669
+ return aggValue;
663
670
}
664
671
665
- void emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue aggValue,
666
- LoweringStyle style) const override {
672
+ SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc,
673
+ SILValue aggValue,
674
+ LoweringStyle style) const override {
675
+ llvm::SmallVector<SILValue, 8 > loweredChildValues;
667
676
for (auto &child : getChildren (B.getModule ())) {
668
677
auto &childLowering = child.getLowering ();
669
678
SILValue childValue = asImpl ().emitRValueProject (B, loc, aggValue,
670
679
child.getIndex (),
671
680
childLowering);
672
681
if (!childLowering.isTrivial ()) {
673
- childLowering.emitLoweredCopyChildValue (B, loc, childValue, style);
682
+ SILValue loweredChildValue = childLowering.emitLoweredCopyChildValue (
683
+ B, loc, childValue, style);
684
+ loweredChildValues.push_back (loweredChildValue);
685
+ } else {
686
+ loweredChildValues.push_back (childValue);
674
687
}
675
688
}
689
+
690
+ return rebuildAggregate (B, loc, loweredChildValues);
676
691
}
677
692
678
693
void emitDestroyValue (SILBuilder &B, SILLocation loc,
@@ -713,7 +728,7 @@ namespace {
713
728
}
714
729
715
730
SILValue rebuildAggregate (SILBuilder &B, SILLocation loc,
716
- ArrayRef<SILValue> values) const {
731
+ ArrayRef<SILValue> values) const override {
717
732
return B.createTuple (loc, getLoweredType (), values);
718
733
}
719
734
@@ -748,7 +763,7 @@ namespace {
748
763
}
749
764
750
765
SILValue rebuildAggregate (SILBuilder &B, SILLocation loc,
751
- ArrayRef<SILValue> values) const {
766
+ ArrayRef<SILValue> values) const override {
752
767
return B.createStruct (loc, getLoweredType (), values);
753
768
}
754
769
@@ -773,14 +788,16 @@ namespace {
773
788
: NonTrivialLoadableTypeLowering(SILType::getPrimitiveObjectType(type),
774
789
IsNotReferenceCounted) {}
775
790
776
- void emitCopyValue (SILBuilder &B, SILLocation loc,
777
- SILValue value) const override {
791
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
792
+ SILValue value) const override {
778
793
B.createRetainValue (loc, value, Atomicity::Atomic);
794
+ return value;
779
795
}
780
796
781
- void emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue value,
797
+ SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue value,
782
798
LoweringStyle style) const override {
783
799
B.createRetainValue (loc, value, Atomicity::Atomic);
800
+ return value;
784
801
}
785
802
786
803
void emitDestroyValue (SILBuilder &B, SILLocation loc,
@@ -802,9 +819,10 @@ namespace {
802
819
LeafLoadableTypeLowering (SILType type, IsReferenceCounted_t isRefCounted)
803
820
: NonTrivialLoadableTypeLowering(type, isRefCounted) {}
804
821
805
- void emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue value,
806
- LoweringStyle style) const override {
807
- emitCopyValue (B, loc, value);
822
+ SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc,
823
+ SILValue value,
824
+ LoweringStyle style) const override {
825
+ return emitCopyValue (B, loc, value);
808
826
}
809
827
810
828
void emitLoweredDestroyValue (SILBuilder &B, SILLocation loc, SILValue value,
@@ -820,10 +838,11 @@ namespace {
820
838
ReferenceTypeLowering (SILType type)
821
839
: LeafLoadableTypeLowering(type, IsReferenceCounted) {}
822
840
823
- void emitCopyValue (SILBuilder &B, SILLocation loc,
824
- SILValue value) const override {
841
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
842
+ SILValue value) const override {
825
843
if (!isa<FunctionRefInst>(value))
826
844
B.createStrongRetain (loc, value, Atomicity::Atomic);
845
+ return value;
827
846
}
828
847
829
848
void emitDestroyValue (SILBuilder &B, SILLocation loc,
@@ -838,9 +857,10 @@ namespace {
838
857
LoadableUnownedTypeLowering (SILType type)
839
858
: LeafLoadableTypeLowering(type, IsReferenceCounted) {}
840
859
841
- void emitCopyValue (SILBuilder &B, SILLocation loc,
842
- SILValue value) const override {
860
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
861
+ SILValue value) const override {
843
862
B.createUnownedRetain (loc, value, Atomicity::Atomic);
863
+ return value;
844
864
}
845
865
846
866
void emitDestroyValue (SILBuilder &B, SILLocation loc,
@@ -883,13 +903,14 @@ namespace {
883
903
B.emitDestroyAddrAndFold (loc, value);
884
904
}
885
905
886
- void emitCopyValue (SILBuilder &B, SILLocation loc,
887
- SILValue value) const override {
906
+ SILValue emitCopyValue (SILBuilder &B, SILLocation loc,
907
+ SILValue value) const override {
888
908
llvm_unreachable (" type is not loadable!" );
889
909
}
890
910
891
- void emitLoweredCopyValue (SILBuilder &B, SILLocation loc, SILValue value,
892
- LoweringStyle style) const override {
911
+ SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc,
912
+ SILValue value,
913
+ LoweringStyle style) const override {
893
914
llvm_unreachable (" type is not loadable!" );
894
915
}
895
916
0 commit comments