@@ -933,6 +933,21 @@ static bool isRuntimeInstatiatedLayoutString(IRGenModule &IGM,
933933 return false ;
934934}
935935
936+ static bool
937+ useMultiPayloadEnumFNSpecialization (IRGenModule &IGM,
938+ const TypeLayoutEntry *typeLayoutEntry,
939+ GenericSignature genericSig) {
940+ // if (!typeLayoutEntry->layoutString(IGM, genericSig)) {
941+ // return false;
942+ // }
943+ // auto *enumTLE = typeLayoutEntry->getAsEnum();
944+ // return enumTLE && enumTLE->isFixedSize(IGM) &&
945+ // enumTLE->isMultiPayloadEnum();
946+
947+ // Disabled for now
948+ return false ;
949+ }
950+
936951static llvm::Constant *getEnumTagFunction (IRGenModule &IGM,
937952 const EnumTypeLayoutEntry *typeLayoutEntry,
938953 GenericSignature genericSig) {
@@ -953,19 +968,7 @@ static llvm::Constant *getEnumTagFunction(IRGenModule &IGM,
953968 } else if (typeLayoutEntry->isMultiPayloadEnum ()) {
954969 return IGM.getEnumFnGetEnumTagFn ();
955970 } else {
956- auto &payloadTI = **(typeLayoutEntry->cases [0 ]->getFixedTypeInfo ());
957- auto mask = payloadTI.getFixedExtraInhabitantMask (IGM);
958- auto tzCount = mask.countTrailingZeros ();
959- auto shiftedMask = mask.lshr (tzCount);
960- // auto toCount = shiftedMask.countTrailingOnes();
961- // if (payloadTI.mayHaveExtraInhabitants(IGM) &&
962- // (mask.popcount() > 64 ||
963- // toCount != mask.popcount() ||
964- // (tzCount % toCount != 0))) {
965- return IGM.getEnumFnGetEnumTagFn ();
966- // } else {
967- // return IGM.getEnumSimpleGetEnumTagFn();
968- // }
971+ return IGM.getEnumFnGetEnumTagFn ();
969972 }
970973}
971974
@@ -990,18 +993,7 @@ getDestructiveInjectEnumTagFunction(IRGenModule &IGM,
990993 } else if (typeLayoutEntry->isMultiPayloadEnum ()) {
991994 return nullptr ;
992995 } else {
993- auto &payloadTI = **(typeLayoutEntry->cases [0 ]->getFixedTypeInfo ());
994- auto mask = payloadTI.getFixedExtraInhabitantMask (IGM);
995- auto tzCount = mask.countTrailingZeros ();
996- auto shiftedMask = mask.lshr (tzCount);
997- // auto toCount = shiftedMask.countTrailingOnes();
998- // if (payloadTI.mayHaveExtraInhabitants(IGM) &&
999- // (mask.popcount() > 64 || toCount != mask.popcount() ||
1000- // (tzCount % toCount != 0))) {
1001- return nullptr ;
1002- // } else {
1003- // return IGM.getEnumSimpleDestructiveInjectEnumTagFn();
1004- // }
996+ return nullptr ;
1005997 }
1006998}
1007999
@@ -1072,7 +1064,12 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10721064 ->getGenericSignature ();
10731065 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
10741066 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1075- return addFunction (IGM.getGenericDestroyFn ());
1067+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1068+ genericSig)) {
1069+ return addFunction (IGM.getGenericDestroyMultiPayloadEnumFNFn ());
1070+ } else {
1071+ return addFunction (IGM.getGenericDestroyFn ());
1072+ }
10761073 }
10771074 }
10781075 }
@@ -1101,8 +1098,14 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
11011098 ->getGenericSignature ();
11021099 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
11031100 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1104- return addFunction (
1105- IGM.getGenericInitializeBufferWithCopyOfBufferFn ());
1101+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1102+ genericSig)) {
1103+ return addFunction (
1104+ IGM.getGenericInitializeBufferWithCopyOfBufferMultiPayloadEnumFNFn ());
1105+ } else {
1106+ return addFunction (
1107+ IGM.getGenericInitializeBufferWithCopyOfBufferFn ());
1108+ }
11061109 }
11071110 }
11081111 }
@@ -1121,7 +1124,13 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
11211124 ->getGenericSignature ();
11221125 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
11231126 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1124- return addFunction (IGM.getGenericInitWithTakeFn ());
1127+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1128+ genericSig)) {
1129+ return addFunction (
1130+ IGM.getGenericInitWithTakeMultiPayloadEnumFNFn ());
1131+ } else {
1132+ return addFunction (IGM.getGenericInitWithTakeFn ());
1133+ }
11251134 }
11261135 }
11271136 }
@@ -1142,7 +1151,13 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
11421151 ->getGenericSignature ();
11431152 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
11441153 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1145- return addFunction (IGM.getGenericAssignWithCopyFn ());
1154+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1155+ genericSig)) {
1156+ return addFunction (
1157+ IGM.getGenericAssignWithCopyMultiPayloadEnumFNFn ());
1158+ } else {
1159+ return addFunction (IGM.getGenericAssignWithCopyFn ());
1160+ }
11461161 }
11471162 }
11481163 }
@@ -1163,7 +1178,13 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
11631178 ->getGenericSignature ();
11641179 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
11651180 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1166- return addFunction (IGM.getGenericAssignWithTakeFn ());
1181+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1182+ genericSig)) {
1183+ return addFunction (
1184+ IGM.getGenericAssignWithTakeMultiPayloadEnumFNFn ());
1185+ } else {
1186+ return addFunction (IGM.getGenericAssignWithTakeFn ());
1187+ }
11671188 }
11681189 }
11691190 }
@@ -1184,7 +1205,13 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
11841205 ->getGenericSignature ();
11851206 if (typeLayoutEntry->layoutString (IGM, genericSig) ||
11861207 isRuntimeInstatiatedLayoutString (IGM, typeLayoutEntry)) {
1187- return addFunction (IGM.getGenericInitWithCopyFn ());
1208+ if (useMultiPayloadEnumFNSpecialization (IGM, typeLayoutEntry,
1209+ genericSig)) {
1210+ return addFunction (
1211+ IGM.getGenericInitWithCopyMultiPayloadEnumFNFn ());
1212+ } else {
1213+ return addFunction (IGM.getGenericInitWithCopyFn ());
1214+ }
11881215 }
11891216 }
11901217 }
0 commit comments