@@ -64,7 +64,7 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
64
64
// We need handle this case with a function signature optimization.
65
65
removeMetatypeArgumentsInCallees ( of: f, moduleContext)
66
66
67
- worklist. addCallees ( of: f)
67
+ worklist. addCallees ( of: f, moduleContext )
68
68
}
69
69
}
70
70
@@ -496,29 +496,41 @@ fileprivate struct FunctionWorklist {
496
496
return
497
497
}
498
498
499
- mutating func addCallees( of function: Function ) {
499
+ mutating func addCallees( of function: Function , _ context : ModulePassContext ) {
500
500
for inst in function. instructions {
501
501
switch inst {
502
- case let apply as ApplySite :
503
- if let callee = apply. referencedFunction {
504
- pushIfNotVisited ( callee)
502
+ case let fri as FunctionRefInst :
503
+ pushIfNotVisited ( fri. referencedFunction)
504
+ case let alloc as AllocRefInst :
505
+ if context. options. enableEmbeddedSwift {
506
+ addVTableMethods ( forClassType: alloc. type, context)
505
507
}
506
- case let bi as BuiltinInst :
507
- switch bi . id {
508
- case . Once , . OnceWithContext :
509
- if let fri = bi . operands [ 1 ] . value as? FunctionRefInst {
510
- pushIfNotVisited ( fri . referencedFunction )
508
+ case let metatype as MetatypeInst :
509
+ if context . options . enableEmbeddedSwift {
510
+ let instanceType = metatype . type . loweredInstanceTypeOfMetatype ( in : function )
511
+ if instanceType . isClass {
512
+ addVTableMethods ( forClassType : instanceType , context )
511
513
}
512
- break ;
513
- default :
514
- break
515
514
}
515
+
516
516
default :
517
517
break
518
518
}
519
519
}
520
520
}
521
521
522
+ mutating func addVTableMethods( forClassType classType: Type , _ context: ModulePassContext ) {
523
+ guard let vtable = classType. isGenericAtAnyLevel ?
524
+ context. lookupSpecializedVTable ( for: classType) :
525
+ context. lookupVTable ( for: classType. nominal!)
526
+ else {
527
+ return
528
+ }
529
+ for entry in vtable. entries where !entry. implementation. isGeneric {
530
+ pushIfNotVisited ( entry. implementation)
531
+ }
532
+ }
533
+
522
534
mutating func addWitnessMethods( of witnessTable: WitnessTable ) {
523
535
for entry in witnessTable. entries {
524
536
if case . method( _, let witness) = entry,
0 commit comments