Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart b/sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c8169c4c23fa8b5fb2b233ab7ca2124c438a0df8 |
| --- /dev/null |
| +++ b/sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
ngeoffray
2013/11/20 14:55:27
2012 -> 2013
lukas
2013/11/21 12:20:21
Done.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of ssa; |
| + |
| +class SsaFromIrInliner extends IrNodesVisitor { |
| + |
| + final SsaBuilder builder; |
| + |
| + SsaFromIrInliner(this.builder); |
| + |
| + final Map<IrNode, HInstruction> emitted = new Map<IrNode, HInstruction>(); |
| + |
| + Compiler get compiler => builder.compiler; |
| + |
| + void visitIrReturn(IrReturn node) { |
| + HInstruction hValue = emitted[node.value]; |
| + builder.localsHandler.updateLocal(builder.returnElement, hValue); |
| + } |
| + |
| + void visitIrConstant(IrConstant node) { |
| + emitted[node] = builder.graph.addConstant(node.value, compiler); |
| + } |
| + |
| + void visitNode(IrNode node) { |
| + compiler.internalError('Unexpected IrNode $node'); |
| + } |
| +} |
| + |
| +class IrInlineWeeder extends IrNodesVisitor { |
| + static bool canBeInlined(IrFunction irFunction, int maxInliningNodes) { |
| + IrInlineWeeder weeder = new IrInlineWeeder(maxInliningNodes); |
| + weeder.visitAll(irFunction.statements); |
| + return !weeder.tooDifficult; |
| + } |
| + |
| + final int maxInliningNodes; |
| + |
| + IrInlineWeeder(this.maxInliningNodes); |
| + |
| + bool seenReturn = false; |
| + bool tooDifficult = false; |
| + int nodeCount = 0; |
| + |
| + bool registerNode() { |
| + if (nodeCount++ > maxInliningNodes) { |
| + tooDifficult = true; |
| + return false; |
| + } else { |
| + return true; |
| + } |
| + } |
| + |
| + void visitNode(IrNode node) { |
| + if (!registerNode()) return; |
| + if (seenReturn) { |
| + tooDifficult = true; |
| + } |
| + } |
| + |
| + void visitIrReturn(IrReturn node) { |
| + visitNode(node); |
| + seenReturn = true; |
| + } |
| + |
| + void visitIrFunction(IrFunction node) { |
| + tooDifficult = true; |
| + } |
| + |
| +} |