| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class InvocationInfo { | 5 class InvocationInfo { |
| 6 int parameterCount; | 6 int parameterCount; |
| 7 List<HType> providedTypes; | 7 List<HType> providedTypes; |
| 8 List<Element> compiledFunctions; | 8 List<Element> compiledFunctions; |
| 9 | 9 |
| 10 InvocationInfo(List<HType> types) | 10 InvocationInfo(List<HType> types) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 SsaBuilderTask builder; | 24 SsaBuilderTask builder; |
| 25 SsaOptimizerTask optimizer; | 25 SsaOptimizerTask optimizer; |
| 26 SsaCodeGeneratorTask generator; | 26 SsaCodeGeneratorTask generator; |
| 27 CodeEmitterTask emitter; | 27 CodeEmitterTask emitter; |
| 28 final Map<Element, Map<Element, HType>> fieldInitializers; | 28 final Map<Element, Map<Element, HType>> fieldInitializers; |
| 29 final Map<Element, Map<Element, HType>> fieldConstructorSetters; | 29 final Map<Element, Map<Element, HType>> fieldConstructorSetters; |
| 30 final Map<Element, Map<Element, HType>> fieldSettersType; | 30 final Map<Element, Map<Element, HType>> fieldSettersType; |
| 31 | 31 |
| 32 final Map<SourceString, Map<Selector, InvocationInfo>> invocationInfo; | 32 final Map<SourceString, Map<Selector, InvocationInfo>> invocationInfo; |
| 33 | 33 |
| 34 final List<Element> invalidateAfterCodegen; |
| 35 |
| 34 List<CompilerTask> get tasks() { | 36 List<CompilerTask> get tasks() { |
| 35 return <CompilerTask>[builder, optimizer, generator, emitter]; | 37 return <CompilerTask>[builder, optimizer, generator, emitter]; |
| 36 } | 38 } |
| 37 | 39 |
| 38 JavaScriptBackend(Compiler compiler, bool generateSourceMap) | 40 JavaScriptBackend(Compiler compiler, bool generateSourceMap) |
| 39 : emitter = new CodeEmitterTask(compiler, generateSourceMap), | 41 : emitter = new CodeEmitterTask(compiler, generateSourceMap), |
| 40 fieldInitializers = new Map<Element, Map<Element, HType>>(), | 42 fieldInitializers = new Map<Element, Map<Element, HType>>(), |
| 41 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(), | 43 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(), |
| 42 fieldSettersType = new Map<Element, Map<Element, HType>>(), | 44 fieldSettersType = new Map<Element, Map<Element, HType>>(), |
| 43 invocationInfo = new Map<SourceString, Map<Selector, InvocationInfo>>(), | 45 invocationInfo = new Map<SourceString, Map<Selector, InvocationInfo>>(), |
| 46 invalidateAfterCodegen = new List<Element>(), |
| 44 super(compiler) { | 47 super(compiler) { |
| 45 builder = new SsaBuilderTask(this); | 48 builder = new SsaBuilderTask(this); |
| 46 optimizer = new SsaOptimizerTask(this); | 49 optimizer = new SsaOptimizerTask(this); |
| 47 generator = new SsaCodeGeneratorTask(this); | 50 generator = new SsaCodeGeneratorTask(this); |
| 48 } | 51 } |
| 49 | 52 |
| 50 void enqueueHelpers(Enqueuer world) { | 53 void enqueueHelpers(Enqueuer world) { |
| 51 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world); | 54 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world); |
| 52 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world); | 55 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world); |
| 53 for (var helper in [const SourceString('Closure'), | 56 for (var helper in [const SourceString('Closure'), |
| 54 const SourceString('ConstantMap'), | 57 const SourceString('ConstantMap'), |
| 55 const SourceString('ConstantProtoMap')]) { | 58 const SourceString('ConstantProtoMap')]) { |
| 56 var e = compiler.findHelper(helper); | 59 var e = compiler.findHelper(helper); |
| 57 if (e !== null) world.registerInstantiatedClass(e); | 60 if (e !== null) world.registerInstantiatedClass(e); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 | 63 |
| 61 CodeBuffer codegen(WorkItem work) { | 64 void codegen(WorkItem work) { |
| 62 HGraph graph = builder.build(work); | 65 HGraph graph = builder.build(work); |
| 63 optimizer.optimize(work, graph); | 66 optimizer.optimize(work, graph); |
| 64 if (work.allowSpeculativeOptimization | 67 if (work.allowSpeculativeOptimization |
| 65 && optimizer.trySpeculativeOptimizations(work, graph)) { | 68 && optimizer.trySpeculativeOptimizations(work, graph)) { |
| 66 CodeBuffer codeBuffer = generator.generateBailoutMethod(work, graph); | 69 CodeBuffer codeBuffer = generator.generateBailoutMethod(work, graph); |
| 67 compiler.codegenWorld.addBailoutCode(work, codeBuffer); | 70 compiler.codegenWorld.addBailoutCode(work, codeBuffer); |
| 68 optimizer.prepareForSpeculativeOptimizations(work, graph); | 71 optimizer.prepareForSpeculativeOptimizations(work, graph); |
| 69 optimizer.optimize(work, graph); | 72 optimizer.optimize(work, graph); |
| 70 } | 73 } |
| 71 return generator.generateMethod(work, graph); | 74 CodeBuffer codeBuffer = generator.generateMethod(work, graph); |
| 75 compiler.codegenWorld.addGeneratedCode(work, codeBuffer); |
| 76 invalidateAfterCodegen.forEach((Element element) { |
| 77 compiler.codegenWorld.invalidateCode(element); |
| 78 compiler.enqueuer.codegen.eagerRecompile(element); |
| 79 }); |
| 80 invalidateAfterCodegen.clear(); |
| 72 } | 81 } |
| 73 | 82 |
| 74 void processNativeClasses(Enqueuer world, | 83 void processNativeClasses(Enqueuer world, |
| 75 Collection<LibraryElement> libraries) { | 84 Collection<LibraryElement> libraries) { |
| 76 native.processNativeClasses(world, emitter, libraries); | 85 native.processNativeClasses(world, emitter, libraries); |
| 77 } | 86 } |
| 78 | 87 |
| 79 void assembleProgram() { | 88 void assembleProgram() { |
| 80 emitter.assembleProgram(); | 89 emitter.assembleProgram(); |
| 81 } | 90 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (newType != types[i]) { | 211 if (newType != types[i]) { |
| 203 typesChanged = true; | 212 typesChanged = true; |
| 204 types[i] = newType; | 213 types[i] = newType; |
| 205 } | 214 } |
| 206 if (types[i] != HType.UNKNOWN) allUnknown = false; | 215 if (types[i] != HType.UNKNOWN) allUnknown = false; |
| 207 } | 216 } |
| 208 // If the provided types change we need to recompile all functions which | 217 // If the provided types change we need to recompile all functions which |
| 209 // have been compiled under the now invalidated assumptions. | 218 // have been compiled under the now invalidated assumptions. |
| 210 if (typesChanged && info.compiledFunctions.length != 0) { | 219 if (typesChanged && info.compiledFunctions.length != 0) { |
| 211 if (compiler.phase == Compiler.PHASE_COMPILING) { | 220 if (compiler.phase == Compiler.PHASE_COMPILING) { |
| 212 info.compiledFunctions.forEach( | 221 info.compiledFunctions.forEach(invalidateAfterCodegen.add); |
| 213 compiler.enqueuer.codegen.eagerRecompile); | |
| 214 info.compiledFunctions.clear(); | 222 info.compiledFunctions.clear(); |
| 215 } | 223 } |
| 216 } | 224 } |
| 217 // If all information is lost no need to keep it around. | 225 // If all information is lost no need to keep it around. |
| 218 if (allUnknown) info.clearTypeInformation(); | 226 if (allUnknown) info.clearTypeInformation(); |
| 219 } else { | 227 } else { |
| 220 // Gather the type information provided. If the types contains no useful | 228 // Gather the type information provided. If the types contains no useful |
| 221 // information there is no need to actually store them. | 229 // information there is no need to actually store them. |
| 222 bool allUnknown = true; | 230 bool allUnknown = true; |
| 223 for (int i = 1; i < node.inputs.length; i++) { | 231 for (int i = 1; i < node.inputs.length; i++) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (foundCount == 1 && found.hasTypeInformation) { | 272 if (foundCount == 1 && found.hasTypeInformation) { |
| 265 FunctionSignature signature = element.computeSignature(compiler); | 273 FunctionSignature signature = element.computeSignature(compiler); |
| 266 if (signature.parameterCount == found.parameterCount) { | 274 if (signature.parameterCount == found.parameterCount) { |
| 267 found.addCompiledFunction(element); | 275 found.addCompiledFunction(element); |
| 268 return found.providedTypes; | 276 return found.providedTypes; |
| 269 } | 277 } |
| 270 } | 278 } |
| 271 return null; | 279 return null; |
| 272 } | 280 } |
| 273 } | 281 } |
| OLD | NEW |