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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 ClassElement cls = element.enclosingElement.enclosingElement; | 430 ClassElement cls = element.enclosingElement.enclosingElement; |
| 431 Type type = cls.computeType(builder.compiler); | 431 Type type = cls.computeType(builder.compiler); |
| 432 cachedTypeOfThis = new HBoundedType.nonNull(type); | 432 cachedTypeOfThis = new HBoundedType.nonNull(type); |
| 433 } | 433 } |
| 434 res.guaranteedType = cachedTypeOfThis; | 434 res.guaranteedType = cachedTypeOfThis; |
| 435 } | 435 } |
| 436 return res; | 436 return res; |
| 437 } | 437 } |
| 438 | 438 |
| 439 HParameterValue getActivationParameter(Element element) { | 439 HParameterValue getActivationParameter(Element element) { |
| 440 if (element.isParameter()) { | 440 // If the element is a parameter, we already have a |
|
floitsch
2012/05/30 11:52:38
Can you also add a comment, why we have this 'if'?
ngeoffray
2012/05/30 12:37:26
There is a comment:
If the element is a parameter,
floitsch
2012/05/30 12:59:41
If I'm not wrong this is just to avoid wrapping pa
ngeoffray
2012/05/31 08:18:33
It is necessary because we need to share the same
| |
| 441 HInstruction instruction = directLocals[element]; | 441 // HParameterValue for it. |
| 442 if (instruction is HParameterValue) return instruction; | 442 if (element.isParameter()) return directLocals[element]; |
| 443 } | |
| 444 | 443 |
| 445 return builder.activationVariables.putIfAbsent(element, () { | 444 return builder.activationVariables.putIfAbsent(element, () { |
| 446 HParameterValue parameter = new HParameterValue(element); | 445 HParameterValue parameter = new HParameterValue(element); |
| 447 builder.graph.entry.addAtExit(parameter); | 446 builder.graph.entry.addAtExit(parameter); |
| 448 return parameter; | 447 return parameter; |
| 449 }); | 448 }); |
| 450 } | 449 } |
| 451 | 450 |
| 452 /** | 451 /** |
| 453 * Sets the [element] to [value]. If the element is boxed or stored in a | 452 * Sets the [element] to [value]. If the element is boxed or stored in a |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 537 } |
| 539 | 538 |
| 540 void beginLoopHeader(Node node, HBasicBlock loopEntry) { | 539 void beginLoopHeader(Node node, HBasicBlock loopEntry) { |
| 541 // Create a copy because we modify the map while iterating over | 540 // Create a copy because we modify the map while iterating over |
| 542 // it. | 541 // it. |
| 543 Map<Element, HInstruction> saved = | 542 Map<Element, HInstruction> saved = |
| 544 new Map<Element, HInstruction>.from(directLocals); | 543 new Map<Element, HInstruction>.from(directLocals); |
| 545 | 544 |
| 546 // Create phis for all elements in the definitions environment. | 545 // Create phis for all elements in the definitions environment. |
| 547 saved.forEach((Element element, HInstruction instruction) { | 546 saved.forEach((Element element, HInstruction instruction) { |
| 548 // We know 'this' cannot be modified. | 547 if (isAccessedDirectly(element)) { |
| 549 if (element !== closureData.thisElement) { | 548 // We know 'this' cannot be modified. |
| 550 HPhi phi = new HPhi.singleInput(element, instruction); | 549 if (element !== closureData.thisElement) { |
| 551 loopEntry.addPhi(phi); | 550 HPhi phi = new HPhi.singleInput(element, instruction); |
| 552 directLocals[element] = phi; | 551 loopEntry.addPhi(phi); |
| 553 } else { | 552 directLocals[element] = phi; |
| 554 directLocals[element] = instruction; | 553 } else { |
| 554 directLocals[element] = instruction; | |
| 555 } | |
| 555 } | 556 } |
| 556 }); | 557 }); |
| 557 } | 558 } |
| 558 | 559 |
| 559 void enterLoopBody(Node node) { | 560 void enterLoopBody(Node node) { |
| 560 ClosureScope scopeData = closureData.capturingScopes[node]; | 561 ClosureScope scopeData = closureData.capturingScopes[node]; |
| 561 if (scopeData == null) return; | 562 if (scopeData == null) return; |
| 562 // If there are no declared boxed loop variables then we did not create the | 563 // If there are no declared boxed loop variables then we did not create the |
| 563 // box before the initializer and we have to create the box now. | 564 // box before the initializer and we have to create the box now. |
| 564 if (!scopeData.hasBoxedLoopVariables()) { | 565 if (!scopeData.hasBoxedLoopVariables()) { |
| (...skipping 2546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3111 visitSwitchCase(SwitchCase node) { | 3112 visitSwitchCase(SwitchCase node) { |
| 3112 compiler.internalError('SsaBuilder.visitSwitchCase'); | 3113 compiler.internalError('SsaBuilder.visitSwitchCase'); |
| 3113 } | 3114 } |
| 3114 | 3115 |
| 3115 visitCaseMatch(CaseMatch node) { | 3116 visitCaseMatch(CaseMatch node) { |
| 3116 compiler.internalError('SsaBuilder.visitCaseMatch'); | 3117 compiler.internalError('SsaBuilder.visitCaseMatch'); |
| 3117 } | 3118 } |
| 3118 | 3119 |
| 3119 visitTryStatement(TryStatement node) { | 3120 visitTryStatement(TryStatement node) { |
| 3120 work.allowSpeculativeOptimization = false; | 3121 work.allowSpeculativeOptimization = false; |
| 3122 // Save the current locals. The catch block and the finally block | |
| 3123 // must not reuse the existing locals handler. None of the variables | |
| 3124 // that have been defined in the body-block will be used, but for | |
| 3125 // loops we will add (unnecessary) phis that will reference the body | |
| 3126 // variables. This will make it look as if the variables were used | |
|
Lasse Reichstein Nielsen
2012/05/30 09:35:14
"will make" -> "makes" (prefer active voice where
ngeoffray
2012/05/30 10:19:07
Done.
| |
| 3127 // in a non-dominated block. | |
| 3128 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); | |
| 3121 HBasicBlock enterBlock = openNewBlock(); | 3129 HBasicBlock enterBlock = openNewBlock(); |
| 3122 HTry tryInstruction = new HTry(); | 3130 HTry tryInstruction = new HTry(); |
| 3123 List<HBasicBlock> blocks = <HBasicBlock>[]; | 3131 List<HBasicBlock> blocks = <HBasicBlock>[]; |
| 3124 blocks.add(close(tryInstruction)); | 3132 blocks.add(close(tryInstruction)); |
| 3125 | 3133 |
| 3126 HBasicBlock tryBody = graph.addNewBlock(); | 3134 HBasicBlock tryBody = graph.addNewBlock(); |
| 3127 enterBlock.addSuccessor(tryBody); | 3135 enterBlock.addSuccessor(tryBody); |
| 3128 open(tryBody); | 3136 open(tryBody); |
| 3129 visit(node.tryBlock); | 3137 visit(node.tryBlock); |
| 3130 if (!isAborted()) blocks.add(close(new HGoto())); | 3138 if (!isAborted()) blocks.add(close(new HGoto())); |
| 3131 SubGraph bodyGraph = new SubGraph(tryBody, lastOpenedBlock); | 3139 SubGraph bodyGraph = new SubGraph(tryBody, lastOpenedBlock); |
| 3132 SubGraph catchGraph = null; | 3140 SubGraph catchGraph = null; |
| 3133 HParameterValue exception = null; | 3141 HParameterValue exception = null; |
| 3134 if (!node.catchBlocks.isEmpty()) { | 3142 if (!node.catchBlocks.isEmpty()) { |
| 3143 localsHandler = new LocalsHandler.from(savedLocals); | |
| 3135 HBasicBlock block = graph.addNewBlock(); | 3144 HBasicBlock block = graph.addNewBlock(); |
| 3136 enterBlock.addSuccessor(block); | 3145 enterBlock.addSuccessor(block); |
| 3137 open(block); | 3146 open(block); |
| 3138 // Note that the name of this element is irrelevant. | 3147 // Note that the name of this element is irrelevant. |
| 3139 Element element = new Element( | 3148 Element element = new Element( |
| 3140 const SourceString('exception'), ElementKind.PARAMETER, work.element); | 3149 const SourceString('exception'), ElementKind.PARAMETER, work.element); |
| 3141 exception = new HParameterValue(element); | 3150 exception = new HParameterValue(element); |
| 3142 add(exception); | 3151 add(exception); |
| 3143 HInstruction oldRethrowableException = rethrowableException; | 3152 HInstruction oldRethrowableException = rethrowableException; |
| 3144 rethrowableException = exception; | 3153 rethrowableException = exception; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3191 handleIf(() { pushCondition(newBlock); }, | 3200 handleIf(() { pushCondition(newBlock); }, |
| 3192 visitThen, visitElse); | 3201 visitThen, visitElse); |
| 3193 } | 3202 } |
| 3194 } | 3203 } |
| 3195 | 3204 |
| 3196 CatchBlock firstBlock = link.head; | 3205 CatchBlock firstBlock = link.head; |
| 3197 handleIf(() { pushCondition(firstBlock); }, visitThen, visitElse); | 3206 handleIf(() { pushCondition(firstBlock); }, visitThen, visitElse); |
| 3198 if (!isAborted()) blocks.add(close(new HGoto())); | 3207 if (!isAborted()) blocks.add(close(new HGoto())); |
| 3199 | 3208 |
| 3200 rethrowableException = oldRethrowableException; | 3209 rethrowableException = oldRethrowableException; |
| 3210 tryInstruction.catchBlock = block; | |
| 3201 catchGraph = new SubGraph(block, lastOpenedBlock); | 3211 catchGraph = new SubGraph(block, lastOpenedBlock); |
| 3202 } | 3212 } |
| 3203 | 3213 |
| 3204 SubGraph finallyGraph = null; | 3214 SubGraph finallyGraph = null; |
| 3205 if (node.finallyBlock != null) { | 3215 if (node.finallyBlock != null) { |
| 3216 localsHandler = new LocalsHandler.from(savedLocals); | |
| 3206 HBasicBlock finallyBlock = graph.addNewBlock(); | 3217 HBasicBlock finallyBlock = graph.addNewBlock(); |
| 3207 enterBlock.addSuccessor(finallyBlock); | 3218 enterBlock.addSuccessor(finallyBlock); |
| 3208 open(finallyBlock); | 3219 open(finallyBlock); |
| 3209 visit(node.finallyBlock); | 3220 visit(node.finallyBlock); |
| 3210 if (!isAborted()) blocks.add(close(new HGoto())); | 3221 if (!isAborted()) blocks.add(close(new HGoto())); |
| 3211 tryInstruction.finallyBlock = finallyBlock; | 3222 tryInstruction.finallyBlock = finallyBlock; |
| 3212 finallyGraph = new SubGraph(finallyBlock, lastOpenedBlock); | 3223 finallyGraph = new SubGraph(finallyBlock, lastOpenedBlock); |
| 3213 } | 3224 } |
| 3214 | 3225 |
| 3215 HBasicBlock exitBlock = graph.addNewBlock(); | 3226 HBasicBlock exitBlock = graph.addNewBlock(); |
| 3216 | 3227 |
| 3217 for (HBasicBlock block in blocks) { | 3228 for (HBasicBlock block in blocks) { |
| 3218 block.addSuccessor(exitBlock); | 3229 block.addSuccessor(exitBlock); |
| 3219 } | 3230 } |
| 3220 | 3231 |
| 3232 // Use the locals handler not altered by the catch and finally | |
| 3233 // blocks. | |
| 3234 localsHandler = savedLocals; | |
| 3221 open(exitBlock); | 3235 open(exitBlock); |
| 3222 enterBlock.setBlockFlow( | 3236 enterBlock.setBlockFlow( |
| 3223 new HTryBlockInformation( | 3237 new HTryBlockInformation( |
| 3224 wrapStatementGraph(bodyGraph), | 3238 wrapStatementGraph(bodyGraph), |
| 3225 exception, | 3239 exception, |
| 3226 wrapStatementGraph(catchGraph), | 3240 wrapStatementGraph(catchGraph), |
| 3227 wrapStatementGraph(finallyGraph)), | 3241 wrapStatementGraph(finallyGraph)), |
| 3228 exitBlock); | 3242 exitBlock); |
| 3229 } | 3243 } |
| 3230 | 3244 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3389 <HInstruction>[target, input], | 3403 <HInstruction>[target, input], |
| 3390 HType.STRING)); | 3404 HType.STRING)); |
| 3391 return builder.pop(); | 3405 return builder.pop(); |
| 3392 } | 3406 } |
| 3393 | 3407 |
| 3394 HInstruction result(Node node) { | 3408 HInstruction result(Node node) { |
| 3395 flushLiterals(node); | 3409 flushLiterals(node); |
| 3396 return prefix; | 3410 return prefix; |
| 3397 } | 3411 } |
| 3398 } | 3412 } |
| OLD | NEW |