@@ -95,41 +95,31 @@ func chooseArgumentLists(_ b: ProgramBuilder, forCalling f: Variable) -> ([Varia
9595 return ( args [ 0 ] , args [ 1 ] , args [ 2 ] , args [ 3 ] )
9696}
9797
98- public let ForceTurboFanCompilationGenerator = CodeGenerator ( " ForceTurboFanCompilationGenerator " , inputs: . required( . function( ) ) ) { b, f in
99- assert ( b. type ( of: f) . Is ( . function( ) ) )
100- let ( args1, args2, args3, args4) = chooseArgumentLists ( b, forCalling: f)
98+ private func forceCompilationGenerator( _ generatorName: String , optimizeName: String ) -> CodeGenerator {
99+ return CodeGenerator ( generatorName, inputs: . required( . function( ) ) ) { b, f in
100+ assert ( b. type ( of: f) . Is ( . function( ) ) )
101+ let ( args1, args2, args3, args4) = chooseArgumentLists ( b, forCalling: f)
101102
102- let guardCalls = probability ( 0.5 )
103+ let guardCalls = probability ( 0.5 )
103104
104- b. callFunction ( f, withArgs: args1, guard: guardCalls)
105+ b. callFunction ( f, withArgs: args1, guard: guardCalls)
105106
106- b. eval ( " %PrepareFunctionForOptimization(%@) " , with: [ f] ) ;
107+ b. eval ( " %PrepareFunctionForOptimization(%@) " , with: [ f] ) ;
107108
108- b. callFunction ( f, withArgs: args2, guard: guardCalls)
109- b. callFunction ( f, withArgs: args3, guard: guardCalls)
109+ b. callFunction ( f, withArgs: args2, guard: guardCalls)
110+ b. callFunction ( f, withArgs: args3, guard: guardCalls)
110111
111- b. eval ( " %OptimizeFunctionOnNextCall (%@) " , with: [ f] ) ;
112+ b. eval ( " % \( optimizeName ) (%@) " , with: [ f] ) ;
112113
113- b. callFunction ( f, withArgs: args4, guard: guardCalls)
114+ b. callFunction ( f, withArgs: args4, guard: guardCalls)
115+ }
114116}
115117
116- public let ForceMaglevCompilationGenerator = CodeGenerator ( " ForceMaglevCompilationGenerator " , inputs: . required( . function( ) ) ) { b, f in
117- assert ( b. type ( of: f) . Is ( . function( ) ) )
118- let ( args1, args2, args3, args4) = chooseArgumentLists ( b, forCalling: f)
118+ public let ForceTurboFanCompilationGenerator = forceCompilationGenerator (
119+ " ForceTurboFanCompilationGenerator " , optimizeName: " OptimizeFunctionOnNextCall " )
119120
120- let guardCalls = probability ( 0.5 )
121-
122- b. callFunction ( f, withArgs: args1, guard: guardCalls)
123-
124- b. eval ( " %PrepareFunctionForOptimization(%@) " , with: [ f] ) ;
125-
126- b. callFunction ( f, withArgs: args2, guard: guardCalls)
127- b. callFunction ( f, withArgs: args3, guard: guardCalls)
128-
129- b. eval ( " %OptimizeMaglevOnNextCall(%@) " , with: [ f] ) ;
130-
131- b. callFunction ( f, withArgs: args4, guard: guardCalls)
132- }
121+ public let ForceMaglevCompilationGenerator = forceCompilationGenerator (
122+ " ForceMaglevCompilationGenerator " , optimizeName: " OptimizeMaglevOnNextCall " )
133123
134124public let TurbofanVerifyTypeGenerator = CodeGenerator ( " TurbofanVerifyTypeGenerator " , inputs: . one) { b, v in
135125 b. eval ( " %VerifyType(%@) " , with: [ v] )
0 commit comments