@@ -1233,3 +1233,155 @@ AbstractionPattern AbstractionPattern::getAutoDiffDerivativeFunctionType(
12331233 llvm_unreachable (" called on unsupported abstraction pattern kind" );
12341234 }
12351235}
1236+
1237+ AbstractionPattern::CallingConventionKind
1238+ AbstractionPattern::getResultConvention (TypeConverter &TC) const {
1239+ // Tuples should be destructured.
1240+ if (isTuple ()) {
1241+ return Destructured;
1242+ }
1243+ switch (getKind ()) {
1244+ case Kind::Opaque:
1245+ // Maximally abstracted values are always passed indirectly.
1246+ return Indirect;
1247+
1248+ case Kind::OpaqueFunction:
1249+ case Kind::OpaqueDerivativeFunction:
1250+ case Kind::PartialCurriedObjCMethodType:
1251+ case Kind::CurriedObjCMethodType:
1252+ case Kind::PartialCurriedCFunctionAsMethodType:
1253+ case Kind::CurriedCFunctionAsMethodType:
1254+ case Kind::CFunctionAsMethodType:
1255+ case Kind::ObjCMethodType:
1256+ case Kind::CXXMethodType:
1257+ case Kind::CurriedCXXMethodType:
1258+ case Kind::PartialCurriedCXXMethodType:
1259+ case Kind::CXXOperatorMethodType:
1260+ case Kind::CurriedCXXOperatorMethodType:
1261+ case Kind::PartialCurriedCXXOperatorMethodType:
1262+ // Function types are always passed directly
1263+ return Direct;
1264+
1265+ case Kind::ClangType:
1266+ case Kind::Type:
1267+ case Kind::Discard:
1268+ // Pass according to the formal type.
1269+ return SILType::isFormallyReturnedIndirectly (getType (),
1270+ TC,
1271+ getGenericSignatureOrNull ())
1272+ ? Indirect : Direct;
1273+
1274+ case Kind::Invalid:
1275+ case Kind::Tuple:
1276+ case Kind::ObjCCompletionHandlerArgumentsType:
1277+ llvm_unreachable (" should not get here" );
1278+ }
1279+ }
1280+
1281+ AbstractionPattern::CallingConventionKind
1282+ AbstractionPattern::getParameterConvention (TypeConverter &TC) const {
1283+ // Tuples should be destructured.
1284+ if (isTuple ()) {
1285+ return Destructured;
1286+ }
1287+ switch (getKind ()) {
1288+ case Kind::Opaque:
1289+ // Maximally abstracted values are always passed indirectly.
1290+ return Indirect;
1291+
1292+ case Kind::OpaqueFunction:
1293+ case Kind::OpaqueDerivativeFunction:
1294+ case Kind::PartialCurriedObjCMethodType:
1295+ case Kind::CurriedObjCMethodType:
1296+ case Kind::PartialCurriedCFunctionAsMethodType:
1297+ case Kind::CurriedCFunctionAsMethodType:
1298+ case Kind::CFunctionAsMethodType:
1299+ case Kind::ObjCMethodType:
1300+ case Kind::CXXMethodType:
1301+ case Kind::CurriedCXXMethodType:
1302+ case Kind::PartialCurriedCXXMethodType:
1303+ case Kind::CXXOperatorMethodType:
1304+ case Kind::CurriedCXXOperatorMethodType:
1305+ case Kind::PartialCurriedCXXOperatorMethodType:
1306+ // Function types are always passed directly
1307+ return Direct;
1308+
1309+ case Kind::ClangType:
1310+ case Kind::Type:
1311+ case Kind::Discard:
1312+ // Pass according to the formal type.
1313+ return SILType::isFormallyPassedIndirectly (getType (),
1314+ TC,
1315+ getGenericSignatureOrNull ())
1316+ ? Indirect : Direct;
1317+
1318+ case Kind::Invalid:
1319+ case Kind::Tuple:
1320+ case Kind::ObjCCompletionHandlerArgumentsType:
1321+ llvm_unreachable (" should not get here" );
1322+ }
1323+ }
1324+
1325+ bool
1326+ AbstractionPattern::operator ==(const AbstractionPattern &other) const {
1327+ if (TheKind != other.TheKind )
1328+ return false ;
1329+
1330+ switch (getKind ()) {
1331+ case Kind::Opaque:
1332+ case Kind::Invalid:
1333+ case Kind::OpaqueFunction:
1334+ case Kind::OpaqueDerivativeFunction:
1335+ // No additional info to compare.
1336+ return true ;
1337+
1338+ case Kind::Tuple:
1339+ if (getNumTupleElements () != other.getNumTupleElements ()) {
1340+ return false ;
1341+ }
1342+ for (unsigned i = 0 ; i < getNumTupleElements (); ++i) {
1343+ if (getTupleElementType (i) != other.getTupleElementType (i)) {
1344+ return false ;
1345+ }
1346+ }
1347+ return true ;
1348+
1349+ case Kind::Type:
1350+ case Kind::Discard:
1351+ return OrigType == other.OrigType
1352+ && GenericSig == other.GenericSig ;
1353+
1354+ case Kind::ClangType:
1355+ return OrigType == other.OrigType
1356+ && GenericSig == other.GenericSig
1357+ && ClangType == other.ClangType ;
1358+
1359+ case Kind::ObjCCompletionHandlerArgumentsType:
1360+ case Kind::CFunctionAsMethodType:
1361+ case Kind::CurriedCFunctionAsMethodType:
1362+ case Kind::PartialCurriedCFunctionAsMethodType:
1363+ return OrigType == other.OrigType
1364+ && GenericSig == other.GenericSig
1365+ && ClangType == other.ClangType
1366+ && OtherData == other.OtherData ;
1367+
1368+ case Kind::ObjCMethodType:
1369+ case Kind::CurriedObjCMethodType:
1370+ case Kind::PartialCurriedObjCMethodType:
1371+ return OrigType == other.OrigType
1372+ && GenericSig == other.GenericSig
1373+ && ObjCMethod == other.ObjCMethod
1374+ && OtherData == other.OtherData ;
1375+
1376+ case Kind::CXXMethodType:
1377+ case Kind::CXXOperatorMethodType:
1378+ case Kind::CurriedCXXMethodType:
1379+ case Kind::CurriedCXXOperatorMethodType:
1380+ case Kind::PartialCurriedCXXMethodType:
1381+ case Kind::PartialCurriedCXXOperatorMethodType:
1382+ return OrigType == other.OrigType
1383+ && GenericSig == other.GenericSig
1384+ && CXXMethod == other.CXXMethod
1385+ && OtherData == other.OtherData ;
1386+ }
1387+ }
0 commit comments