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 3295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3306 !link.isEmpty(); | 3306 !link.isEmpty(); |
3307 link = link.tail) { | 3307 link = link.tail) { |
3308 visit(link.head); | 3308 visit(link.head); |
3309 inputs.add(pop()); | 3309 inputs.add(pop()); |
3310 } | 3310 } |
3311 push(new HLiteralList(inputs)); | 3311 push(new HLiteralList(inputs)); |
3312 } | 3312 } |
3313 | 3313 |
3314 visitConditional(Conditional node) { | 3314 visitConditional(Conditional node) { |
3315 SsaBranchBuilder brancher = | 3315 SsaBranchBuilder brancher = |
3316 new SsaBranchBuilder(this, diagnosticNode: node); | 3316 new SsaBranchBuilder(this, node); |
floitsch
2012/10/11 16:52:15
does this fit on one line?
regis
2012/10/11 21:24:19
Done.
| |
3317 brancher.handleConditional(() => visit(node.condition), | 3317 brancher.handleConditional(() => visit(node.condition), |
3318 () => visit(node.thenExpression), | 3318 () => visit(node.thenExpression), |
3319 () => visit(node.elseExpression)); | 3319 () => visit(node.elseExpression)); |
3320 } | 3320 } |
3321 | 3321 |
3322 visitStringInterpolation(StringInterpolation node) { | 3322 visitStringInterpolation(StringInterpolation node) { |
3323 StringBuilderVisitor stringBuilder = new StringBuilderVisitor(this, node); | 3323 StringBuilderVisitor stringBuilder = new StringBuilderVisitor(this, node); |
3324 stringBuilder.visit(node); | 3324 stringBuilder.visit(node); |
3325 stack.add(stringBuilder.result); | 3325 stack.add(stringBuilder.result); |
3326 } | 3326 } |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4273 | 4273 |
4274 conditionBranch.graph = | 4274 conditionBranch.graph = |
4275 new SubExpression(conditionBranch.block, conditionExitBlock); | 4275 new SubExpression(conditionBranch.block, conditionExitBlock); |
4276 } | 4276 } |
4277 | 4277 |
4278 /** | 4278 /** |
4279 * Returns true if the locals of the [fromBranch] may be reused. A [:true:] | 4279 * Returns true if the locals of the [fromBranch] may be reused. A [:true:] |
4280 * return value implies that [mayReuseFromLocals] was set to [:true:]. | 4280 * return value implies that [mayReuseFromLocals] was set to [:true:]. |
4281 */ | 4281 */ |
4282 bool mergeLocals(SsaBranch fromBranch, SsaBranch toBranch, | 4282 bool mergeLocals(SsaBranch fromBranch, SsaBranch toBranch, |
4283 [bool mayReuseFromLocals]) { | 4283 {bool mayReuseFromLocals}) { |
4284 LocalsHandler fromLocals = fromBranch.exitLocals; | 4284 LocalsHandler fromLocals = fromBranch.exitLocals; |
4285 if (toBranch.startLocals == null) { | 4285 if (toBranch.startLocals == null) { |
4286 if (mayReuseFromLocals) { | 4286 if (mayReuseFromLocals) { |
4287 toBranch.startLocals = fromLocals; | 4287 toBranch.startLocals = fromLocals; |
4288 return false; | 4288 return false; |
4289 } else { | 4289 } else { |
4290 toBranch.startLocals = new LocalsHandler.from(fromLocals); | 4290 toBranch.startLocals = new LocalsHandler.from(fromLocals); |
4291 return true; | 4291 return true; |
4292 } | 4292 } |
4293 } else { | 4293 } else { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4332 } | 4332 } |
4333 | 4333 |
4334 _handleDiamondBranch(visitCondition, visitThen, visitElse, false); | 4334 _handleDiamondBranch(visitCondition, visitThen, visitElse, false); |
4335 } | 4335 } |
4336 | 4336 |
4337 handleConditional(void visitCondition(), void visitThen(), void visitElse()) { | 4337 handleConditional(void visitCondition(), void visitThen(), void visitElse()) { |
4338 assert(visitElse != null); | 4338 assert(visitElse != null); |
4339 _handleDiamondBranch(visitCondition, visitThen, visitElse, true); | 4339 _handleDiamondBranch(visitCondition, visitThen, visitElse, true); |
4340 } | 4340 } |
4341 | 4341 |
4342 void handleLogicalAndOr(void left(), void right(), [bool isAnd]) { | 4342 void handleLogicalAndOr(void left(), void right(), {bool isAnd}) { |
4343 // x && y is transformed into: | 4343 // x && y is transformed into: |
4344 // t0 = boolify(x); | 4344 // t0 = boolify(x); |
4345 // if (t0) { | 4345 // if (t0) { |
4346 // t1 = boolify(y); | 4346 // t1 = boolify(y); |
4347 // } | 4347 // } |
4348 // result = phi(t1, false); | 4348 // result = phi(t1, false); |
4349 // | 4349 // |
4350 // x || y is transformed into: | 4350 // x || y is transformed into: |
4351 // t0 = boolify(x); | 4351 // t0 = boolify(x); |
4352 // if (not(t0)) { | 4352 // if (not(t0)) { |
(...skipping 21 matching lines...) Expand all Loading... | |
4374 HConstant notIsAnd = | 4374 HConstant notIsAnd = |
4375 builder.graph.addConstantBool(!isAnd, builder.constantSystem); | 4375 builder.graph.addConstantBool(!isAnd, builder.constantSystem); |
4376 HPhi result = new HPhi.manyInputs(null, | 4376 HPhi result = new HPhi.manyInputs(null, |
4377 <HInstruction>[boolifiedRight, notIsAnd]); | 4377 <HInstruction>[boolifiedRight, notIsAnd]); |
4378 builder.current.addPhi(result); | 4378 builder.current.addPhi(result); |
4379 builder.stack.add(result); | 4379 builder.stack.add(result); |
4380 } | 4380 } |
4381 | 4381 |
4382 void handleLogicalAndOrWithLeftNode(Node left, | 4382 void handleLogicalAndOrWithLeftNode(Node left, |
4383 void visitRight(), | 4383 void visitRight(), |
4384 [bool isAnd]) { | 4384 {bool isAnd}) { |
4385 // This method is similar to [handleLogicalAndOr] but optimizes the case | 4385 // This method is similar to [handleLogicalAndOr] but optimizes the case |
4386 // where left is a logical "and" or logical "or". | 4386 // where left is a logical "and" or logical "or". |
4387 // | 4387 // |
4388 // For example (x && y) && z is transformed into x && (y && z): | 4388 // For example (x && y) && z is transformed into x && (y && z): |
4389 // t0 = boolify(x); | 4389 // t0 = boolify(x); |
4390 // if (t0) { | 4390 // if (t0) { |
4391 // t1 = boolify(y); | 4391 // t1 = boolify(y); |
4392 // if (t1) { | 4392 // if (t1) { |
4393 // t2 = boolify(z); | 4393 // t2 = boolify(z); |
4394 // } | 4394 // } |
4395 // t3 = phi(t2, false); | 4395 // t3 = phi(t2, false); |
4396 // } | 4396 // } |
4397 // result = phi(t3, false); | 4397 // result = phi(t3, false); |
4398 | 4398 |
4399 Send send = left.asSend(); | 4399 Send send = left.asSend(); |
4400 if (send !== null && | 4400 if (send !== null && |
4401 (isAnd ? send.isLogicalAnd : send.isLogicalOr)) { | 4401 (isAnd ? send.isLogicalAnd : send.isLogicalOr)) { |
4402 Node newLeft = send.receiver; | 4402 Node newLeft = send.receiver; |
4403 Link<Node> link = send.argumentsNode.nodes; | 4403 Link<Node> link = send.argumentsNode.nodes; |
4404 assert(link.tail.isEmpty()); | 4404 assert(link.tail.isEmpty()); |
4405 Node middle = link.head; | 4405 Node middle = link.head; |
4406 handleLogicalAndOrWithLeftNode( | 4406 handleLogicalAndOrWithLeftNode( |
4407 newLeft, | 4407 newLeft, |
4408 () => handleLogicalAndOrWithLeftNode(middle, visitRight, isAnd), | 4408 () => handleLogicalAndOrWithLeftNode(middle, visitRight, |
4409 isAnd: isAnd), | |
4409 isAnd: isAnd); | 4410 isAnd: isAnd); |
4410 } else { | 4411 } else { |
4411 handleLogicalAndOr(() => builder.visit(left), visitRight, isAnd); | 4412 handleLogicalAndOr(() => builder.visit(left), visitRight, isAnd: isAnd); |
4412 } | 4413 } |
4413 } | 4414 } |
4414 | 4415 |
4415 void _handleDiamondBranch(void visitCondition(), | 4416 void _handleDiamondBranch(void visitCondition(), |
4416 void visitThen(), | 4417 void visitThen(), |
4417 void visitElse(), | 4418 void visitElse(), |
4418 bool isExpression) { | 4419 bool isExpression) { |
4419 SsaBranch conditionBranch = new SsaBranch(this); | 4420 SsaBranch conditionBranch = new SsaBranch(this); |
4420 SsaBranch thenBranch = new SsaBranch(this); | 4421 SsaBranch thenBranch = new SsaBranch(this); |
4421 SsaBranch elseBranch = new SsaBranch(this); | 4422 SsaBranch elseBranch = new SsaBranch(this); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4454 new HSubGraphBlockInformation(elseBranch.graph)); | 4455 new HSubGraphBlockInformation(elseBranch.graph)); |
4455 | 4456 |
4456 HBasicBlock conditionStartBlock = conditionBranch.block; | 4457 HBasicBlock conditionStartBlock = conditionBranch.block; |
4457 conditionStartBlock.setBlockFlow(info, joinBlock); | 4458 conditionStartBlock.setBlockFlow(info, joinBlock); |
4458 SubGraph conditionGraph = conditionBranch.graph; | 4459 SubGraph conditionGraph = conditionBranch.graph; |
4459 HIf branch = conditionGraph.end.last; | 4460 HIf branch = conditionGraph.end.last; |
4460 assert(branch is HIf); | 4461 assert(branch is HIf); |
4461 branch.blockInformation = conditionStartBlock.blockFlow; | 4462 branch.blockInformation = conditionStartBlock.blockFlow; |
4462 } | 4463 } |
4463 } | 4464 } |
OLD | NEW |