Chromium Code Reviews| 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 Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 132 |
| 133 Element getGetRuntimeTypeInfo() { | 133 Element getGetRuntimeTypeInfo() { |
| 134 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); | 134 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 class SsaBuilderTask extends CompilerTask { | 138 class SsaBuilderTask extends CompilerTask { |
| 139 final Interceptors interceptors; | 139 final Interceptors interceptors; |
| 140 final Map<Node, ClosureData> closureDataCache; | 140 final Map<Node, ClosureData> closureDataCache; |
| 141 final CodeEmitterTask emitter; | 141 final CodeEmitterTask emitter; |
| 142 // Loop tracking information. | |
| 143 final Set<FunctionElement> functionsCalledInLoop; | |
| 144 final Set<SourceString> selectorsCalledInLoop; | |
|
ngeoffray
2012/06/12 11:11:09
I think this should be a Map<SourceString, Selecto
Mads Ager (google)
2012/06/12 11:24:21
Another good point. Done!
| |
| 142 | 145 |
| 143 String get name() => 'SSA builder'; | 146 String get name() => 'SSA builder'; |
| 144 | 147 |
| 145 SsaBuilderTask(JavaScriptBackend backend) | 148 SsaBuilderTask(JavaScriptBackend backend) |
| 146 : interceptors = new Interceptors(backend.compiler), | 149 : interceptors = new Interceptors(backend.compiler), |
| 147 closureDataCache = new HashMap<Node, ClosureData>(), | 150 closureDataCache = new HashMap<Node, ClosureData>(), |
| 148 emitter = backend.emitter, | 151 emitter = backend.emitter, |
| 152 functionsCalledInLoop = new Set<FunctionElement>(), | |
| 153 selectorsCalledInLoop = new Set<SourceString>(), | |
| 149 super(backend.compiler); | 154 super(backend.compiler); |
| 150 | 155 |
| 151 HGraph build(WorkItem work) { | 156 HGraph build(WorkItem work) { |
| 152 return measure(() { | 157 return measure(() { |
| 153 FunctionElement element = work.element; | 158 FunctionElement element = work.element; |
| 154 HInstruction.idCounter = 0; | 159 HInstruction.idCounter = 0; |
| 155 SsaBuilder builder = new SsaBuilder(this, work); | 160 SsaBuilder builder = new SsaBuilder(this, work); |
| 156 HGraph graph; | 161 HGraph graph; |
| 157 switch (element.kind) { | 162 switch (element.kind) { |
| 158 case ElementKind.GENERATIVE_CONSTRUCTOR: | 163 case ElementKind.GENERATIVE_CONSTRUCTOR: |
| 159 graph = compileConstructor(builder, work); | 164 graph = compileConstructor(builder, work); |
| 160 break; | 165 break; |
| 161 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY: | 166 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY: |
| 162 case ElementKind.FUNCTION: | 167 case ElementKind.FUNCTION: |
| 163 case ElementKind.GETTER: | 168 case ElementKind.GETTER: |
| 164 case ElementKind.SETTER: | 169 case ElementKind.SETTER: |
| 165 graph = builder.buildMethod(work.element); | 170 graph = builder.buildMethod(work.element); |
| 166 break; | 171 break; |
| 167 } | 172 } |
| 168 assert(graph.isValid()); | 173 assert(graph.isValid()); |
| 174 if (functionsCalledInLoop.contains(element) || | |
| 175 selectorsCalledInLoop.contains(element.name)) { | |
| 176 graph.calledInLoop = true; | |
| 177 } | |
| 169 if (compiler.tracer.enabled) { | 178 if (compiler.tracer.enabled) { |
| 170 String name; | 179 String name; |
| 171 if (element.enclosingElement !== null && | 180 if (element.enclosingElement !== null && |
| 172 element.enclosingElement.kind == ElementKind.CLASS) { | 181 element.enclosingElement.kind == ElementKind.CLASS) { |
| 173 String className = element.enclosingElement.name.slowToString(); | 182 String className = element.enclosingElement.name.slowToString(); |
| 174 String memberName = element.name.slowToString(); | 183 String memberName = element.name.slowToString(); |
| 175 name = "$className.$memberName"; | 184 name = "$className.$memberName"; |
| 176 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 185 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 177 name = "$name (body)"; | 186 name = "$name (body)"; |
| 178 } | 187 } |
| (...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3442 void visitNodeList(NodeList node) { | 3451 void visitNodeList(NodeList node) { |
| 3443 node.visitChildren(this); | 3452 node.visitChildren(this); |
| 3444 } | 3453 } |
| 3445 | 3454 |
| 3446 HInstruction concat(HInstruction left, HInstruction right) { | 3455 HInstruction concat(HInstruction left, HInstruction right) { |
| 3447 HInstruction instruction = new HStringConcat(left, right, node); | 3456 HInstruction instruction = new HStringConcat(left, right, node); |
| 3448 builder.add(instruction); | 3457 builder.add(instruction); |
| 3449 return instruction; | 3458 return instruction; |
| 3450 } | 3459 } |
| 3451 } | 3460 } |
| OLD | NEW |