@@ -690,9 +690,6 @@ namespace {
690
690
case LoweringStyle::Shallow:
691
691
Fn = &TypeLowering::emitReleaseValue;
692
692
break ;
693
- case LoweringStyle::Deep:
694
- Fn = &TypeLowering::emitLoweredReleaseValueDeep;
695
- break ;
696
693
case LoweringStyle::DeepNoEnum:
697
694
Fn = &TypeLowering::emitLoweredReleaseValueDeepNoEnum;
698
695
break ;
@@ -772,98 +769,10 @@ namespace {
772
769
773
770
// / A lowering for loadable but non-trivial enum types.
774
771
class LoadableEnumTypeLowering final : public NonTrivialLoadableTypeLowering {
775
- public:
776
- // / A non-trivial case of the enum.
777
- class NonTrivialElement {
778
- // / The non-trivial element.
779
- EnumElementDecl *element;
780
-
781
- // / Its type lowering.
782
- const TypeLowering *lowering;
783
-
784
- public:
785
- NonTrivialElement (EnumElementDecl *element, const TypeLowering &lowering)
786
- : element(element), lowering(&lowering) {}
787
-
788
- const TypeLowering &getLowering () const { return *lowering; }
789
- EnumElementDecl *getElement () const { return element; }
790
- };
791
-
792
- private:
793
-
794
- using SimpleOperationTy = void (*)(SILBuilder &B, SILLocation loc, SILValue value,
795
- const TypeLowering &valueLowering,
796
- SILBasicBlock *dest);
797
-
798
- // / Emit a value semantics operation for each nontrivial case of the enum.
799
- template <typename T>
800
- void ifNonTrivialElement (SILBuilder &B, SILLocation loc, SILValue value,
801
- const T &operation) const {
802
- SmallVector<std::pair<EnumElementDecl*,SILBasicBlock*>, 4 > nonTrivialBBs;
803
-
804
- auto &M = B.getFunction ().getModule ();
805
-
806
- // Create all the blocks up front, so we can set up our switch_enum.
807
- auto nonTrivialElts = getNonTrivialElements (M);
808
- for (auto &elt : nonTrivialElts) {
809
- auto bb = new (M) SILBasicBlock (&B.getFunction ());
810
- auto argTy = elt.getLowering ().getLoweredType ();
811
- new (M) SILArgument (bb, argTy);
812
- nonTrivialBBs.push_back ({elt.getElement (), bb});
813
- }
814
-
815
- // If we are appending to the end of a block being constructed, then we
816
- // create a new basic block to continue cons'ing up code. If we're
817
- // emitting this operation into the middle of existing code, we split the
818
- // block.
819
- SILBasicBlock *doneBB = B.splitBlockForFallthrough ();
820
- B.createSwitchEnum (loc, value, doneBB, nonTrivialBBs);
821
-
822
- for (size_t i = 0 ; i < nonTrivialBBs.size (); ++i) {
823
- SILBasicBlock *bb = nonTrivialBBs[i].second ;
824
- const TypeLowering &lowering = nonTrivialElts[i].getLowering ();
825
- B.emitBlock (bb);
826
- operation (B, loc, bb->getBBArgs ()[0 ], lowering, doneBB);
827
- }
828
-
829
- B.emitBlock (doneBB);
830
- }
831
-
832
- // / A reference to the lazily-allocated array of non-trivial enum cases.
833
- mutable ArrayRef<NonTrivialElement> NonTrivialElements = {};
834
-
835
772
public:
836
773
LoadableEnumTypeLowering (CanType type)
837
774
: NonTrivialLoadableTypeLowering(SILType::getPrimitiveObjectType(type),
838
- IsNotReferenceCounted)
839
- {
840
- }
841
-
842
- ArrayRef<NonTrivialElement> getNonTrivialElements (SILModule &M) const {
843
- SILType silTy = getLoweredType ();
844
- EnumDecl *enumDecl = silTy.getEnumOrBoundGenericEnum ();
845
- assert (enumDecl);
846
-
847
- if (NonTrivialElements.data () == nullptr ) {
848
- SmallVector<NonTrivialElement, 4 > elts;
849
-
850
- for (auto elt : enumDecl->getAllElements ()) {
851
- if (!elt->hasArgumentType ()) continue ;
852
- SILType substTy = silTy.getEnumElementType (elt, M);
853
- elts.push_back (NonTrivialElement{elt,
854
- M.Types .getTypeLowering (substTy)});
855
- }
856
-
857
- auto isDependent = IsDependent_t (silTy.hasTypeParameter ());
858
-
859
- auto buf = operator new (sizeof (NonTrivialElement) * elts.size (),
860
- M.Types , isDependent);
861
- memcpy (buf, elts.data (), sizeof (NonTrivialElement) * elts.size ());
862
- NonTrivialElements = {reinterpret_cast <NonTrivialElement*>(buf),
863
- elts.size ()};
864
- }
865
- return NonTrivialElements;
866
- }
775
+ IsNotReferenceCounted) {}
867
776
868
777
void emitRetainValue (SILBuilder &B, SILLocation loc,
869
778
SILValue value) const override {
@@ -873,17 +782,7 @@ namespace {
873
782
void emitLoweredRetainValue (SILBuilder &B, SILLocation loc,
874
783
SILValue value,
875
784
LoweringStyle style) const override {
876
- if (style == LoweringStyle::Shallow ||
877
- style == LoweringStyle::DeepNoEnum) {
878
- B.createRetainValue (loc, value, Atomicity::Atomic);
879
- } else {
880
- ifNonTrivialElement (B, loc, value,
881
- [&](SILBuilder &B, SILLocation loc, SILValue child,
882
- const TypeLowering &childLowering, SILBasicBlock *dest) {
883
- childLowering.emitLoweredCopyChildValue (B, loc, child, style);
884
- B.createBranch (loc, dest);
885
- });
886
- }
785
+ B.createRetainValue (loc, value, Atomicity::Atomic);
887
786
}
888
787
889
788
void emitReleaseValue (SILBuilder &B, SILLocation loc,
@@ -897,15 +796,7 @@ namespace {
897
796
assert (style != LoweringStyle::Shallow &&
898
797
" This method should never be called when performing a shallow "
899
798
" destroy value." );
900
- if (style == LoweringStyle::DeepNoEnum)
901
- B.emitReleaseValueAndFold (loc, value);
902
- else
903
- ifNonTrivialElement (B, loc, value,
904
- [&](SILBuilder &B, SILLocation loc, SILValue child,
905
- const TypeLowering &childLowering, SILBasicBlock *dest) {
906
- childLowering.emitLoweredDestroyChildValue (B, loc, child, style);
907
- B.createBranch (loc, dest);
908
- });
799
+ B.emitReleaseValueAndFold (loc, value);
909
800
}
910
801
};
911
802
0 commit comments