@@ -302,13 +302,13 @@ static void buildMethodDescriptorFields(IRGenModule &IGM,
302302 assert (entry->getKind () == SILVTable::Entry::Kind::Normal);
303303
304304 auto *impl = entry->getImplementation ();
305- llvm::Constant *implFn;
306- if (impl-> isAsync ())
307- implFn = IGM. getAddrOfAsyncFunctionPointer (impl );
308- else
309- implFn = IGM.getAddrOfSILFunction (impl, NotForDefinition);
310-
311- descriptor. addRelativeAddress (implFn);
305+ if (impl-> isAsync ()) {
306+ llvm::Constant *implFn = IGM. getAddrOfAsyncFunctionPointer (impl);
307+ descriptor. addRelativeAddress (implFn );
308+ } else {
309+ llvm::Function * implFn = IGM.getAddrOfSILFunction (impl, NotForDefinition);
310+ descriptor. addCompactFunctionReference (implFn);
311+ }
312312 } else {
313313 // The method is removed by dead method elimination.
314314 // It should be never called. We add a pointer to an error function.
@@ -962,7 +962,15 @@ namespace {
962962 reqt.addInt32 (info.Flags .getIntValue ());
963963
964964 // Default implementation.
965- reqt.addRelativeAddressOrNull (info.DefaultImpl );
965+ if (info.DefaultImpl ) {
966+ if (auto *fn = llvm::dyn_cast<llvm::Function>(info.DefaultImpl )) {
967+ reqt.addCompactFunctionReference (fn);
968+ } else {
969+ reqt.addRelativeAddress (info.DefaultImpl );
970+ }
971+ } else {
972+ reqt.addRelativeAddressOrNull (nullptr );
973+ }
966974
967975 reqt.finishAndAddTo (B);
968976 }
@@ -1226,7 +1234,7 @@ namespace {
12261234 }
12271235
12281236 void addAccessFunction () {
1229- llvm::Constant *accessor;
1237+ llvm::Function *accessor;
12301238
12311239 // Don't include an access function if we're emitting the context
12321240 // descriptor without metadata.
@@ -1247,7 +1255,7 @@ namespace {
12471255 accessor = getOtherwiseDefinedTypeMetadataAccessFunction (IGM, type);
12481256 }
12491257
1250- B.addRelativeAddressOrNull (accessor);
1258+ B.addCompactFunctionReferenceOrNull (accessor);
12511259 }
12521260
12531261 ConstantReference getParent () {
@@ -1376,12 +1384,12 @@ namespace {
13761384
13771385 // / Add a ForeignMetadataInitialization structure to the descriptor.
13781386 void addForeignMetadataInitialization () {
1379- llvm::Constant *completionFunction = nullptr ;
1387+ llvm::Function *completionFunction = nullptr ;
13801388 if (asImpl ().needsForeignMetadataCompletionFunction ()) {
13811389 completionFunction =
13821390 IGM.getAddrOfTypeMetadataCompletionFunction (Type, NotForDefinition);
13831391 }
1384- B.addRelativeAddressOrNull (completionFunction);
1392+ B.addCompactFunctionReferenceOrNull (completionFunction);
13851393 }
13861394
13871395 bool needsForeignMetadataCompletionFunction () {
@@ -1402,7 +1410,7 @@ namespace {
14021410 // Completion function.
14031411 auto completionFunction =
14041412 IGM.getAddrOfTypeMetadataCompletionFunction (Type, NotForDefinition);
1405- B.addRelativeAddress (completionFunction);
1413+ B.addCompactFunctionReference (completionFunction);
14061414 }
14071415
14081416 void addIncompleteMetadata () {
@@ -1905,13 +1913,13 @@ namespace {
19051913 assert (entry->getKind () == SILVTable::Entry::Kind::Override);
19061914
19071915 auto *impl = entry->getImplementation ();
1908- llvm::Constant *implFn;
1909- if (impl-> isAsync ())
1910- implFn = IGM. getAddrOfAsyncFunctionPointer (impl );
1911- else
1912- implFn = IGM.getAddrOfSILFunction (impl, NotForDefinition);
1913-
1914- descriptor. addRelativeAddress (implFn);
1916+ if (impl-> isAsync ()) {
1917+ llvm::Constant *implFn = IGM. getAddrOfAsyncFunctionPointer (impl);
1918+ descriptor. addRelativeAddress (implFn );
1919+ } else {
1920+ llvm::Function * implFn = IGM.getAddrOfSILFunction (impl, NotForDefinition);
1921+ descriptor. addCompactFunctionReference (implFn);
1922+ }
19151923 } else {
19161924 // The method is removed by dead method elimination.
19171925 // It should be never called. We add a pointer to an error function.
@@ -2005,7 +2013,7 @@ namespace {
20052013 }
20062014 auto specialization = pair.first ;
20072015 auto *function = IGM.getAddrOfCanonicalSpecializedGenericTypeMetadataAccessFunction (specialization, NotForDefinition);
2008- B.addRelativeAddress (function);
2016+ B.addCompactFunctionReference (function);
20092017 }
20102018 }
20112019 };
@@ -2723,7 +2731,7 @@ namespace {
27232731 void addInstantiationFunction () {
27242732 auto function = IGM.getAddrOfTypeMetadataInstantiationFunction (Target,
27252733 NotForDefinition);
2726- B.addRelativeAddress (function);
2734+ B.addCompactFunctionReference (function);
27272735 }
27282736
27292737 void addCompletionFunction () {
@@ -2734,7 +2742,7 @@ namespace {
27342742
27352743 auto function = IGM.getAddrOfTypeMetadataCompletionFunction (Target,
27362744 NotForDefinition);
2737- B.addRelativeAddress (function);
2745+ B.addCompactFunctionReference (function);
27382746 }
27392747
27402748 void addPatternFlags () {
@@ -2935,7 +2943,7 @@ static void emitClassMetadataBaseOffset(IRGenModule &IGM,
29352943 offsetVar->setConstant (true );
29362944}
29372945
2938- static Optional<llvm::Constant *>
2946+ static Optional<llvm::Function *>
29392947getAddrOfDestructorFunction (IRGenModule &IGM, ClassDecl *classDecl) {
29402948 auto dtorRef = SILDeclRef (classDecl->getDestructor (),
29412949 SILDeclRef::Kind::Deallocator);
@@ -3539,15 +3547,15 @@ namespace {
35393547
35403548 void addDestructorFunction () {
35413549 auto function = getAddrOfDestructorFunction (IGM, Target);
3542- B.addRelativeAddressOrNull (function ? *function : nullptr );
3550+ B.addCompactFunctionReferenceOrNull (function ? *function : nullptr );
35433551 }
35443552
35453553 void addIVarDestroyer () {
35463554 auto function = IGM.getAddrOfIVarInitDestroy (Target,
35473555 /* isDestroyer=*/ true ,
35483556 /* isForeign=*/ false ,
35493557 NotForDefinition);
3550- B.addRelativeAddressOrNull (function ? *function : nullptr );
3558+ B.addCompactFunctionReferenceOrNull (function ? *function : nullptr );
35513559 }
35523560
35533561 void addClassFlags () {
@@ -3663,15 +3671,15 @@ namespace {
36633671
36643672 void addDestructorFunction () {
36653673 auto function = getAddrOfDestructorFunction (IGM, Target);
3666- B.addRelativeAddressOrNull (function ? *function : nullptr );
3674+ B.addCompactFunctionReferenceOrNull (function ? *function : nullptr );
36673675 }
36683676
36693677 void addIVarDestroyer () {
36703678 auto function = IGM.getAddrOfIVarInitDestroy (Target,
36713679 /* isDestroyer=*/ true ,
36723680 /* isForeign=*/ false ,
36733681 NotForDefinition);
3674- B.addRelativeAddressOrNull (function ? *function : nullptr );
3682+ B.addCompactFunctionReferenceOrNull (function ? *function : nullptr );
36753683 }
36763684
36773685 bool hasExtraDataPattern () {
@@ -5614,7 +5622,7 @@ llvm::GlobalValue *irgen::emitAsyncFunctionPointer(IRGenModule &IGM,
56145622 ConstantInitBuilder initBuilder (IGM);
56155623 ConstantStructBuilder builder (
56165624 initBuilder.beginStruct (IGM.AsyncFunctionPointerTy ));
5617- builder.addRelativeAddress (function);
5625+ builder.addCompactFunctionReference (function);
56185626 builder.addInt32 (size.getValue ());
56195627 return cast<llvm::GlobalValue>(IGM.defineAsyncFunctionPointer (
56205628 entity, builder.finishAndCreateFuture ()));
0 commit comments