@@ -95,7 +95,17 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
9595 worklist. pushIfNotVisited ( f)
9696 }
9797 }
98-
98+
99+ func specializeVTable( for type: Type , instruction: Instruction ) {
100+ if context. options. enableEmbeddedSwift,
101+ type. isClass
102+ {
103+ Optimizer . specializeVTable ( forClassType: type, errorLocation: instruction. location, moduleContext) {
104+ worklist. pushIfNotVisited ( $0)
105+ }
106+ }
107+ }
108+
99109 var changed = true
100110 while changed {
101111 changed = runSimplification ( on: function, context, preserveDebugInfo: true ) { instruction, simplifyCtxt in
@@ -111,21 +121,15 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
111121
112122 // Embedded Swift specific transformations
113123 case let alloc as AllocRefInst :
114- if context. options. enableEmbeddedSwift {
115- specializeVTable ( forClassType: alloc. type, errorLocation: alloc. location, moduleContext) {
116- worklist. pushIfNotVisited ( $0)
117- }
118- }
124+ specializeVTable ( for: alloc. type, instruction: alloc)
119125 case let metatype as MetatypeInst :
120- if context. options. enableEmbeddedSwift,
121- metatype. type. representationOfMetatype == . thick {
122- let instanceType = metatype. type. loweredInstanceTypeOfMetatype ( in: function)
123- if instanceType. isClass {
124- specializeVTable ( forClassType: instanceType, errorLocation: metatype. location, moduleContext) {
125- worklist. pushIfNotVisited ( $0)
126- }
127- }
126+ if metatype. type. representationOfMetatype == . thick {
127+ specializeVTable ( for: metatype. type. loweredInstanceTypeOfMetatype ( in: function) , instruction: metatype)
128128 }
129+ case let cast as UnconditionalCheckedCastInst :
130+ specializeVTable ( for: cast. type, instruction: cast)
131+ case let cast as UncheckedRefCastInst :
132+ specializeVTable ( for: cast. type, instruction: cast)
129133 case let classMethod as ClassMethodInst :
130134 if context. options. enableEmbeddedSwift {
131135 _ = context. specializeClassMethodInst ( classMethod)
0 commit comments