| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 class SsaBuilderTask extends CompilerTask { | 134 class SsaBuilderTask extends CompilerTask { |
| 135 final Interceptors interceptors; | 135 final Interceptors interceptors; |
| 136 final Map<Node, ClosureData> closureDataCache; | 136 final Map<Node, ClosureData> closureDataCache; |
| 137 final CodeEmitterTask emitter; | 137 final CodeEmitterTask emitter; |
| 138 // Loop tracking information. | 138 // Loop tracking information. |
| 139 final Set<FunctionElement> functionsCalledInLoop; | 139 final Set<FunctionElement> functionsCalledInLoop; |
| 140 final Map<SourceString, Selector> selectorsCalledInLoop; | 140 final Map<SourceString, Selector> selectorsCalledInLoop; |
| 141 final JavaScriptBackend backend; | |
| 142 | 141 |
| 143 String get name() => 'SSA builder'; | 142 String get name() => 'SSA builder'; |
| 144 | 143 |
| 145 SsaBuilderTask(JavaScriptBackend backend) | 144 SsaBuilderTask(JavaScriptBackend backend) |
| 146 : interceptors = new Interceptors(backend.compiler), | 145 : interceptors = new Interceptors(backend.compiler), |
| 147 closureDataCache = new HashMap<Node, ClosureData>(), | 146 closureDataCache = new HashMap<Node, ClosureData>(), |
| 148 emitter = backend.emitter, | 147 emitter = backend.emitter, |
| 149 functionsCalledInLoop = new Set<FunctionElement>(), | 148 functionsCalledInLoop = new Set<FunctionElement>(), |
| 150 selectorsCalledInLoop = new Map<SourceString, Selector>(), | 149 selectorsCalledInLoop = new Map<SourceString, Selector>(), |
| 151 backend = backend, | |
| 152 super(backend.compiler); | 150 super(backend.compiler); |
| 153 | 151 |
| 154 HGraph build(WorkItem work) { | 152 HGraph build(WorkItem work) { |
| 155 return measure(() { | 153 return measure(() { |
| 156 FunctionElement element = work.element; | 154 FunctionElement element = work.element; |
| 157 HInstruction.idCounter = 0; | 155 HInstruction.idCounter = 0; |
| 158 SsaBuilder builder = new SsaBuilder(this, work); | 156 SsaBuilder builder = new SsaBuilder(this, work); |
| 159 HGraph graph; | 157 HGraph graph; |
| 160 ElementKind kind = element.kind; | 158 ElementKind kind = element.kind; |
| 161 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { | 159 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 162 graph = compileConstructor(builder, work); | 160 graph = compileConstructor(builder, work); |
| 163 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || | 161 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || |
| 164 kind === ElementKind.FUNCTION || | 162 kind === ElementKind.FUNCTION || |
| 165 kind === ElementKind.GETTER || | 163 kind === ElementKind.GETTER || |
| 166 kind === ElementKind.SETTER) { | 164 kind === ElementKind.SETTER) { |
| 167 graph = builder.buildMethod(work.element); | 165 graph = builder.buildMethod(work.element); |
| 168 } | 166 } |
| 169 assert(graph.isValid()); | 167 assert(graph.isValid()); |
| 170 bool inLoop = functionsCalledInLoop.contains(element); | 168 bool inLoop = functionsCalledInLoop.contains(element); |
| 171 if (!inLoop) { | 169 if (!inLoop) { |
| 172 Selector selector = selectorsCalledInLoop[element.name]; | 170 Selector selector = selectorsCalledInLoop[element.name]; |
| 173 inLoop = selector !== null && selector.applies(element, compiler); | 171 inLoop = selector !== null && selector.applies(element, compiler); |
| 174 } | 172 } |
| 175 graph.calledInLoop = inLoop; | 173 graph.calledInLoop = inLoop; |
| 176 | |
| 177 // If there is an estimate of the parameter types assume these types when | |
| 178 // compiling. | |
| 179 List<HType> parameterTypes = | |
| 180 backend.optimisticParameterTypesWithRecompilationOnTypeChange( | |
| 181 element); | |
| 182 if (parameterTypes != null) { | |
| 183 FunctionSignature signature = element.computeSignature(compiler); | |
| 184 int i = 0; | |
| 185 signature.forEachParameter((Element param) { | |
| 186 builder.parameters[param].guaranteedType = parameterTypes[i++]; | |
| 187 }); | |
| 188 } | |
| 189 | |
| 190 if (compiler.tracer.enabled) { | 174 if (compiler.tracer.enabled) { |
| 191 String name; | 175 String name; |
| 192 if (element.enclosingElement !== null && | 176 if (element.enclosingElement !== null && |
| 193 element.enclosingElement.kind == ElementKind.CLASS) { | 177 element.enclosingElement.kind == ElementKind.CLASS) { |
| 194 String className = element.enclosingElement.name.slowToString(); | 178 String className = element.enclosingElement.name.slowToString(); |
| 195 String memberName = element.name.slowToString(); | 179 String memberName = element.name.slowToString(); |
| 196 name = "$className.$memberName"; | 180 name = "$className.$memberName"; |
| 197 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 181 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 198 name = "$name (body)"; | 182 name = "$name (body)"; |
| 199 } | 183 } |
| (...skipping 3415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3615 new HSubGraphBlockInformation(elseBranch.graph)); | 3599 new HSubGraphBlockInformation(elseBranch.graph)); |
| 3616 | 3600 |
| 3617 HBasicBlock conditionStartBlock = conditionBranch.block; | 3601 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 3618 conditionStartBlock.setBlockFlow(info, joinBlock); | 3602 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 3619 SubGraph conditionGraph = conditionBranch.graph; | 3603 SubGraph conditionGraph = conditionBranch.graph; |
| 3620 HIf branch = conditionGraph.end.last; | 3604 HIf branch = conditionGraph.end.last; |
| 3621 assert(branch is HIf); | 3605 assert(branch is HIf); |
| 3622 branch.blockInformation = conditionStartBlock.blockFlow; | 3606 branch.blockInformation = conditionStartBlock.blockFlow; |
| 3623 } | 3607 } |
| 3624 } | 3608 } |
| OLD | NEW |