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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 part of ssa;
6
7 class SsaFromIrInliner extends IrNodesVisitor {
8
9 final SsaBuilder builder;
10
11 SsaFromIrInliner(this.builder);
12
13 final Map<IrNode, HInstruction> emitted = new Map<IrNode, HInstruction>();
14
15 Compiler get compiler => builder.compiler;
16
17 void visitIrReturn(IrReturn node) {
18 HInstruction hValue = emitted[node.value];
19 builder.localsHandler.updateLocal(builder.returnElement, hValue);
20 }
21
22 void visitIrConstant(IrConstant node) {
23 emitted[node] = builder.graph.addConstant(node.value, compiler);
24 }
25
26 void visitNode(IrNode node) {
27 compiler.internalError('Unexpected IrNode $node');
28 }
29 }
30
31 class IrInlineWeeder extends IrNodesVisitor {
32 static bool canBeInlined(IrFunction irFunction,
33 int maxInliningNodes,
34 bool useMaxInliningNodes) {
35 IrInlineWeeder weeder =
36 new IrInlineWeeder(maxInliningNodes, useMaxInliningNodes);
37 weeder.visitAll(irFunction.statements);
38 return !weeder.tooDifficult;
39 }
40
41 final int maxInliningNodes;
42 final bool useMaxInliningNodes;
43
44 IrInlineWeeder(this.maxInliningNodes, this.useMaxInliningNodes);
45
46 bool seenReturn = false;
47 bool tooDifficult = false;
48 int nodeCount = 0;
49
50 bool registerNode() {
51 if (!useMaxInliningNodes) return true;
52 if (nodeCount++ > maxInliningNodes) {
53 tooDifficult = true;
54 return false;
55 } else {
56 return true;
57 }
58 }
59
60 void visitNode(IrNode node) {
61 if (!registerNode()) return;
62 if (seenReturn) {
63 tooDifficult = true;
64 }
65 }
66
67 void visitIrReturn(IrReturn node) {
68 visitNode(node);
69 seenReturn = true;
70 }
71
72 void visitIrFunction(IrFunction node) {
73 tooDifficult = true;
74 }
75
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698