|
15 | 15 | #include "RValue.h"
|
16 | 16 | #include "SILGenFunction.h"
|
17 | 17 | #include "Scope.h"
|
18 |
| -#include "SwitchCaseFullExpr.h" |
| 18 | +#include "SwitchEnumBuilder.h" |
19 | 19 | #include "swift/AST/GenericSignature.h"
|
20 | 20 | #include "swift/AST/SubstitutionMap.h"
|
21 | 21 |
|
@@ -833,120 +833,3 @@ ManagedValue SILGenBuilder::createTuple(SILLocation loc, SILType type,
|
833 | 833 | });
|
834 | 834 | return cloner.clone(createTuple(loc, type, forwardedValues));
|
835 | 835 | }
|
836 |
| - |
837 |
| -//===----------------------------------------------------------------------===// |
838 |
| -// Switch Enum Builder |
839 |
| -//===----------------------------------------------------------------------===// |
840 |
| - |
841 |
| -void SwitchEnumBuilder::emit() && { |
842 |
| - bool isAddressOnly = optional.getType().isAddressOnly(builder.getModule()) && |
843 |
| - getSGF().silConv.useLoweredAddresses(); |
844 |
| - using DeclBlockPair = std::pair<EnumElementDecl *, SILBasicBlock *>; |
845 |
| - { |
846 |
| - // TODO: We could store the data in CaseBB form and not have to do this. |
847 |
| - llvm::SmallVector<DeclBlockPair, 8> caseBlocks; |
848 |
| - llvm::SmallVector<ProfileCounter, 8> caseBlockCounts; |
849 |
| - std::transform(caseDataArray.begin(), caseDataArray.end(), |
850 |
| - std::back_inserter(caseBlocks), |
851 |
| - [](NormalCaseData &caseData) -> DeclBlockPair { |
852 |
| - return {caseData.decl, caseData.block}; |
853 |
| - }); |
854 |
| - std::transform(caseDataArray.begin(), caseDataArray.end(), |
855 |
| - std::back_inserter(caseBlockCounts), |
856 |
| - [](NormalCaseData &caseData) -> ProfileCounter { |
857 |
| - return caseData.count; |
858 |
| - }); |
859 |
| - SILBasicBlock *defaultBlock = |
860 |
| - defaultBlockData ? defaultBlockData->block : nullptr; |
861 |
| - ProfileCounter defaultBlockCount = |
862 |
| - defaultBlockData ? defaultBlockData->count : ProfileCounter(); |
863 |
| - ArrayRef<ProfileCounter> caseBlockCountsRef = caseBlockCounts; |
864 |
| - if (isAddressOnly) { |
865 |
| - builder.createSwitchEnumAddr(loc, optional.getValue(), defaultBlock, |
866 |
| - caseBlocks, caseBlockCountsRef, |
867 |
| - defaultBlockCount); |
868 |
| - } else { |
869 |
| - if (optional.getType().isAddress()) { |
870 |
| - // TODO: Refactor this into a maybe load. |
871 |
| - if (optional.hasCleanup()) { |
872 |
| - optional = builder.createLoadTake(loc, optional); |
873 |
| - } else { |
874 |
| - optional = builder.createLoadCopy(loc, optional); |
875 |
| - } |
876 |
| - } |
877 |
| - builder.createSwitchEnum(loc, optional.forward(getSGF()), defaultBlock, |
878 |
| - caseBlocks, caseBlockCountsRef, |
879 |
| - defaultBlockCount); |
880 |
| - } |
881 |
| - } |
882 |
| - |
883 |
| - // If we are asked to create a default block and it is specified that the |
884 |
| - // default block should be emitted before normal cases, emit it now. |
885 |
| - if (defaultBlockData && |
886 |
| - defaultBlockData->dispatchTime == |
887 |
| - DefaultDispatchTime::BeforeNormalCases) { |
888 |
| - SILBasicBlock *defaultBlock = defaultBlockData->block; |
889 |
| - NullablePtr<SILBasicBlock> contBB = defaultBlockData->contBlock; |
890 |
| - DefaultCaseHandler handler = defaultBlockData->handler; |
891 |
| - |
892 |
| - // Don't allow cleanups to escape the conditional block. |
893 |
| - SwitchCaseFullExpr presentScope(builder.getSILGenFunction(), |
894 |
| - CleanupLocation::get(loc), |
895 |
| - contBB.getPtrOrNull()); |
896 |
| - builder.emitBlock(defaultBlock); |
897 |
| - ManagedValue input = optional; |
898 |
| - if (!isAddressOnly) { |
899 |
| - input = builder.createOwnedPHIArgument(optional.getType()); |
900 |
| - } |
901 |
| - handler(input, presentScope); |
902 |
| - assert(!builder.hasValidInsertionPoint()); |
903 |
| - } |
904 |
| - |
905 |
| - for (NormalCaseData &caseData : caseDataArray) { |
906 |
| - EnumElementDecl *decl = caseData.decl; |
907 |
| - SILBasicBlock *caseBlock = caseData.block; |
908 |
| - NullablePtr<SILBasicBlock> contBlock = caseData.contBlock; |
909 |
| - NormalCaseHandler handler = caseData.handler; |
910 |
| - |
911 |
| - // Don't allow cleanups to escape the conditional block. |
912 |
| - SwitchCaseFullExpr presentScope(builder.getSILGenFunction(), |
913 |
| - CleanupLocation::get(loc), |
914 |
| - contBlock.getPtrOrNull()); |
915 |
| - |
916 |
| - builder.emitBlock(caseBlock); |
917 |
| - |
918 |
| - ManagedValue input; |
919 |
| - if (decl->hasAssociatedValues()) { |
920 |
| - // Pull the payload out if we have one. |
921 |
| - SILType inputType = |
922 |
| - optional.getType().getEnumElementType(decl, builder.getModule()); |
923 |
| - input = optional; |
924 |
| - if (!isAddressOnly) { |
925 |
| - input = builder.createOwnedPHIArgument(inputType); |
926 |
| - } |
927 |
| - } |
928 |
| - handler(input, presentScope); |
929 |
| - assert(!builder.hasValidInsertionPoint()); |
930 |
| - } |
931 |
| - |
932 |
| - // If we are asked to create a default block and it is specified that the |
933 |
| - // default block should be emitted after normal cases, emit it now. |
934 |
| - if (defaultBlockData && |
935 |
| - defaultBlockData->dispatchTime == DefaultDispatchTime::AfterNormalCases) { |
936 |
| - SILBasicBlock *defaultBlock = defaultBlockData->block; |
937 |
| - NullablePtr<SILBasicBlock> contBB = defaultBlockData->contBlock; |
938 |
| - DefaultCaseHandler handler = defaultBlockData->handler; |
939 |
| - |
940 |
| - // Don't allow cleanups to escape the conditional block. |
941 |
| - SwitchCaseFullExpr presentScope(builder.getSILGenFunction(), |
942 |
| - CleanupLocation::get(loc), |
943 |
| - contBB.getPtrOrNull()); |
944 |
| - builder.emitBlock(defaultBlock); |
945 |
| - ManagedValue input = optional; |
946 |
| - if (!isAddressOnly) { |
947 |
| - input = builder.createOwnedPHIArgument(optional.getType()); |
948 |
| - } |
949 |
| - handler(input, presentScope); |
950 |
| - assert(!builder.hasValidInsertionPoint()); |
951 |
| - } |
952 |
| -} |
0 commit comments