@@ -1986,176 +1986,6 @@ IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
1986
1986
return MetadataResponse::handle (*this , request, call);
1987
1987
}
1988
1988
1989
- static void emitCanonicalSpecializationsForGenericTypeMetadataAccessFunction (
1990
- IRGenFunction &IGF, llvm::Value *request, NominalTypeDecl *nominal,
1991
- GenericArguments &genericArgs,
1992
- std::function<llvm::Value *(int )> valueAtIndex) {
1993
- auto &IGM = IGF.IGM ;
1994
- auto specializations = IGM.IRGen .metadataPrespecializationsForType (nominal);
1995
- auto canonicalCount = llvm::count_if (specializations, [](auto pair) {
1996
- return pair.second == TypeMetadataCanonicality::Canonical;
1997
- });
1998
-
1999
- if (canonicalCount > 0 ) {
2000
- SmallVector<llvm::BasicBlock *, 4 > conditionBlocks;
2001
- for (size_t index = 0 ; index < specializations.size (); ++index) {
2002
- conditionBlocks.push_back (llvm::BasicBlock::Create (IGM.getLLVMContext ()));
2003
- }
2004
-
2005
- IGF.Builder .CreateBr (conditionBlocks[0 ]);
2006
-
2007
- SmallVector<std::tuple<llvm::BasicBlock *, CanType,
2008
- std::function<llvm::Value *(llvm::Value *, CanType,
2009
- IRGenFunction &,
2010
- IRGenModule &)>>,
2011
- 4 >
2012
- specializationBlocks;
2013
- auto switchDestination = llvm::BasicBlock::Create (IGM.getLLVMContext ());
2014
- unsigned long blockIndex = 0 ;
2015
- for (auto pair : specializations) {
2016
- if (pair.second != TypeMetadataCanonicality::Canonical) {
2017
- continue ;
2018
- }
2019
- auto specialization = pair.first ;
2020
- auto conditionBlock = conditionBlocks[blockIndex];
2021
- IGF.Builder .emitBlock (conditionBlock);
2022
- auto successorBlock = blockIndex < conditionBlocks.size () - 1
2023
- ? conditionBlocks[blockIndex + 1 ]
2024
- : switchDestination;
2025
- auto specializationBlock = llvm::BasicBlock::Create (IGM.getLLVMContext ());
2026
- auto substitutions = specialization->getContextSubstitutionMap (
2027
- IGM.getSwiftModule (), nominal);
2028
-
2029
- llvm::Value *condition = llvm::ConstantInt::get (IGM.Int1Ty , 1 );
2030
- auto nominal = specialization->getAnyNominal ();
2031
- auto requirements = GenericTypeRequirements (IGM, nominal);
2032
- int requirementIndex = 0 ;
2033
- for (auto requirement : requirements.getRequirements ()) {
2034
- auto parameter = requirement.TypeParameter ;
2035
- auto argument = parameter.subst (substitutions);
2036
- if (requirement.Protocol ) {
2037
- auto conformance = substitutions.lookupConformance (
2038
- requirement.TypeParameter ->getCanonicalType (),
2039
- requirement.Protocol );
2040
- ProtocolConformance *concreteConformance = conformance.getConcrete ();
2041
- auto argumentNominal = argument->getAnyNominal ();
2042
- if (argumentNominal && argumentNominal->isGenericContext ()) {
2043
- // TODO: Statically specialize the witness table pattern for t's
2044
- // conformance.
2045
- llvm_unreachable (
2046
- " Statically specializing metadata at generic types is "
2047
- " not supported." );
2048
- } else {
2049
- RootProtocolConformance *rootConformance =
2050
- concreteConformance->getRootConformance ();
2051
- llvm::Value *expectedDescriptor =
2052
- IGM.getAddrOfProtocolConformanceDescriptor (rootConformance);
2053
- auto *witnessTable = valueAtIndex (requirementIndex);
2054
- auto *witnessBuffer =
2055
- IGF.Builder .CreateBitCast (witnessTable, IGM.Int8PtrPtrTy );
2056
- auto *uncastProvidedDescriptor =
2057
- IGF.Builder .CreateLoad (witnessBuffer, Alignment ());
2058
- auto *providedDescriptor = IGF.Builder .CreateBitCast (
2059
- uncastProvidedDescriptor,
2060
- IGM.ProtocolConformanceDescriptorPtrTy );
2061
-
2062
- // Auth the stored descriptor.
2063
- auto storedScheme =
2064
- IGM.getOptions ().PointerAuth .ProtocolConformanceDescriptors ;
2065
- if (storedScheme) {
2066
- auto authInfo = PointerAuthInfo::emit (
2067
- IGF, storedScheme, witnessTable,
2068
- PointerAuthEntity::Special::ProtocolConformanceDescriptor);
2069
- providedDescriptor =
2070
- emitPointerAuthAuth (IGF, providedDescriptor, authInfo);
2071
- }
2072
-
2073
- // Sign the descriptors.
2074
- auto argScheme =
2075
- IGM.getOptions ()
2076
- .PointerAuth .ProtocolConformanceDescriptorsAsArguments ;
2077
- if (argScheme) {
2078
- auto authInfo = PointerAuthInfo::emit (
2079
- IGF, argScheme, nullptr ,
2080
- PointerAuthEntity::Special::
2081
- ProtocolConformanceDescriptorAsArgument);
2082
- expectedDescriptor =
2083
- emitPointerAuthSign (IGF, expectedDescriptor, authInfo);
2084
- providedDescriptor =
2085
- emitPointerAuthSign (IGF, providedDescriptor, authInfo);
2086
- }
2087
-
2088
- auto *call = IGF.Builder .CreateCall (
2089
- IGM.getCompareProtocolConformanceDescriptorsFn (),
2090
- {providedDescriptor, expectedDescriptor});
2091
- call->setDoesNotThrow ();
2092
- call->setCallingConv (IGM.SwiftCC );
2093
- call->addAttribute (llvm::AttributeList::FunctionIndex,
2094
- llvm::Attribute::ReadNone);
2095
- condition = IGF.Builder .CreateAnd (condition, call);
2096
- }
2097
- } else {
2098
- llvm::Constant *addr =
2099
- IGM.getAddrOfTypeMetadata (argument->getCanonicalType ());
2100
- auto addrInt = IGF.Builder .CreateBitCast (addr, IGM.Int8PtrTy );
2101
- condition = IGF.Builder .CreateAnd (
2102
- condition, IGF.Builder .CreateICmpEQ (
2103
- addrInt, valueAtIndex (requirementIndex)));
2104
- }
2105
- ++requirementIndex;
2106
- }
2107
- IGF.Builder .CreateCondBr (condition, specializationBlock, successorBlock);
2108
-
2109
- auto responseBuilder = [](llvm::Value *request, CanType specialization,
2110
- IRGenFunction &IGF, IRGenModule &IGM) {
2111
- auto nominal = specialization->getAnyNominal ();
2112
- llvm::Value *specializedMetadata;
2113
- if (isa<ClassDecl>(nominal)) {
2114
- llvm::Function *accessor =
2115
- IGM
2116
- .getAddrOfCanonicalSpecializedGenericTypeMetadataAccessFunction (
2117
- specialization, NotForDefinition);
2118
-
2119
- specializedMetadata =
2120
- IGF.emitGenericTypeMetadataAccessFunctionCall (
2121
- accessor, {}, DynamicMetadataRequest (request))
2122
- .getMetadata ();
2123
- } else {
2124
- specializedMetadata = IGM.getAddrOfTypeMetadata (specialization);
2125
- }
2126
- // Construct a MetadataResponse. It has three fields in the following
2127
- // order:
2128
- // - const Metadata *Metadata;
2129
- // - MetadataState (i32) StaticState;
2130
- llvm::Value *response =
2131
- llvm::UndefValue::get (IGM.TypeMetadataResponseTy );
2132
- response = IGF.Builder .CreateInsertValue (
2133
- response, specializedMetadata, 0 ,
2134
- " insert metadata address into response" );
2135
- auto state = MetadataResponse::getCompletedState (IGM);
2136
- response = IGF.Builder .CreateInsertValue (
2137
- response, state, 1 , " insert metadata state into response" );
2138
- return response;
2139
- };
2140
- specializationBlocks.push_back (std::make_tuple (
2141
- specializationBlock, specialization, responseBuilder));
2142
- ++blockIndex;
2143
- }
2144
-
2145
- for (auto tuple : specializationBlocks) {
2146
- llvm::BasicBlock *block;
2147
- CanType type;
2148
- std::function<llvm::Value *(llvm::Value *, CanType, IRGenFunction &,
2149
- IRGenModule &)>
2150
- builder;
2151
- std::tie (block, type, builder) = tuple;
2152
- IGF.Builder .emitBlock (block);
2153
- IGF.Builder .CreateRet (builder (request, type, IGF, IGM));
2154
- }
2155
- IGF.Builder .emitBlock (switchDestination);
2156
- }
2157
- }
2158
-
2159
1989
MetadataResponse irgen::emitGenericTypeMetadataAccessFunction (
2160
1990
IRGenFunction &IGF, Explosion ¶ms, NominalTypeDecl *nominal,
2161
1991
GenericArguments &genericArgs) {
@@ -2186,20 +2016,6 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
2186
2016
llvm::Value *arguments =
2187
2017
IGF.Builder .CreateBitCast (argsBuffer.getAddress (), IGM.Int8PtrTy );
2188
2018
2189
- llvm::Value *argumentsBuffer =
2190
- IGF.Builder .CreateBitCast (argsBuffer.getAddress (), IGM.Int8PtrPtrTy );
2191
-
2192
- emitCanonicalSpecializationsForGenericTypeMetadataAccessFunction (
2193
- IGF, request, nominal, genericArgs, [&](int index) {
2194
- llvm::Value *indexValue = llvm::ConstantInt::get (IGM.Int64Ty , index);
2195
- llvm::Value *elementPointer =
2196
- IGF.Builder .CreateGEP (argumentsBuffer, indexValue);
2197
- llvm::LoadInst *retval = IGF.Builder .CreateLoad (
2198
- elementPointer, Alignment (),
2199
- llvm::formatv (" load argument at index {0} from buffer" , index));
2200
- return retval;
2201
- });
2202
-
2203
2019
// Make the call.
2204
2020
auto call = IGF.Builder .CreateCall (IGM.getGetGenericMetadataFn (),
2205
2021
{request, arguments, descriptor});
@@ -2278,12 +2094,6 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
2278
2094
? IGF.Builder .CreateBitCast (params.claimNext (), IGM.Int8PtrTy )
2279
2095
: llvm::UndefValue::get (IGM.Int8PtrTy );
2280
2096
2281
- std::array<llvm::Value *, 3 > argValues = {arg0, arg1, arg2};
2282
-
2283
- emitCanonicalSpecializationsForGenericTypeMetadataAccessFunction (
2284
- IGF, request, nominal, genericArgs,
2285
- [&](int index) { return argValues[index]; });
2286
-
2287
2097
auto call = IGF.Builder .CreateCall (thunkFn,
2288
2098
{request, arg0, arg1, arg2, descriptor});
2289
2099
call->setDoesNotAccessMemory ();
0 commit comments