Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart

Issue 85813002: Revert "Revert "Build new IR for functions returning a constant."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: feedback by kasper Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9a67f394cb3428265cc6fae98f75a385ebc2b758
--- /dev/null
+++ b/sdk/lib/_internal/compiler/implementation/ssa/from_ir_inliner.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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,
+ bool useMaxInliningNodes) {
+ IrInlineWeeder weeder =
+ new IrInlineWeeder(maxInliningNodes, useMaxInliningNodes);
+ weeder.visitAll(irFunction.statements);
+ return !weeder.tooDifficult;
+ }
+
+ final int maxInliningNodes;
+ final bool useMaxInliningNodes;
+
+ IrInlineWeeder(this.maxInliningNodes, this.useMaxInliningNodes);
+
+ bool seenReturn = false;
+ bool tooDifficult = false;
+ int nodeCount = 0;
+
+ bool registerNode() {
+ if (!useMaxInliningNodes) return true;
+ 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;
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698