| 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 Map<SourceString, Selector> selectorsCalledInLoop; |
| 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 Map<SourceString, Selector>(), |
| 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 bool inLoop = functionsCalledInLoop.contains(element); |
| 175 if (!inLoop) { |
| 176 Selector selector = selectorsCalledInLoop[element.name]; |
| 177 inLoop = selector !== null && selector.applies(element, compiler); |
| 178 } |
| 179 graph.calledInLoop = inLoop; |
| 169 if (compiler.tracer.enabled) { | 180 if (compiler.tracer.enabled) { |
| 170 String name; | 181 String name; |
| 171 if (element.enclosingElement !== null && | 182 if (element.enclosingElement !== null && |
| 172 element.enclosingElement.kind == ElementKind.CLASS) { | 183 element.enclosingElement.kind == ElementKind.CLASS) { |
| 173 String className = element.enclosingElement.name.slowToString(); | 184 String className = element.enclosingElement.name.slowToString(); |
| 174 String memberName = element.name.slowToString(); | 185 String memberName = element.name.slowToString(); |
| 175 name = "$className.$memberName"; | 186 name = "$className.$memberName"; |
| 176 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 187 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 177 name = "$name (body)"; | 188 name = "$name (body)"; |
| 178 } | 189 } |
| (...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3442 void visitNodeList(NodeList node) { | 3453 void visitNodeList(NodeList node) { |
| 3443 node.visitChildren(this); | 3454 node.visitChildren(this); |
| 3444 } | 3455 } |
| 3445 | 3456 |
| 3446 HInstruction concat(HInstruction left, HInstruction right) { | 3457 HInstruction concat(HInstruction left, HInstruction right) { |
| 3447 HInstruction instruction = new HStringConcat(left, right, node); | 3458 HInstruction instruction = new HStringConcat(left, right, node); |
| 3448 builder.add(instruction); | 3459 builder.add(instruction); |
| 3449 return instruction; | 3460 return instruction; |
| 3450 } | 3461 } |
| 3451 } | 3462 } |
| OLD | NEW |