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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 1573693002: dart2js cps: Hoist loop-invariant branches from loop entry. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 library dart2js.ir_nodes; 4 library dart2js.ir_nodes;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'cps_fragment.dart' show CpsFragment; 7 import 'cps_fragment.dart' show CpsFragment;
8 import '../constants/values.dart' as values; 8 import '../constants/values.dart' as values;
9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 final Reference<Continuation> trueContinuation; 1189 final Reference<Continuation> trueContinuation;
1190 final Reference<Continuation> falseContinuation; 1190 final Reference<Continuation> falseContinuation;
1191 1191
1192 /// If true, only the value `true` satisfies the condition. Otherwise, any 1192 /// If true, only the value `true` satisfies the condition. Otherwise, any
1193 /// truthy value satisfies the check. 1193 /// truthy value satisfies the check.
1194 /// 1194 ///
1195 /// Non-strict checks are preferable when the condition is known to be a 1195 /// Non-strict checks are preferable when the condition is known to be a
1196 /// boolean. 1196 /// boolean.
1197 bool isStrictCheck; 1197 bool isStrictCheck;
1198 1198
1199 Branch(Primitive condition,
1200 Continuation trueCont,
1201 Continuation falseCont,
1202 {bool strict})
1203 : this.condition = new Reference<Primitive>(condition),
1204 trueContinuation = new Reference<Continuation>(trueCont),
1205 falseContinuation = new Reference<Continuation>(falseCont),
1206 isStrictCheck = strict {
1207 assert(strict != null);
1208 }
1209
1199 Branch.strict(Primitive condition, 1210 Branch.strict(Primitive condition,
1200 Continuation trueCont, 1211 Continuation trueCont,
1201 Continuation falseCont) 1212 Continuation falseCont)
1202 : this.condition = new Reference<Primitive>(condition), 1213 : this(condition, trueCont, falseCont, strict: true);
1203 trueContinuation = new Reference<Continuation>(trueCont),
1204 falseContinuation = new Reference<Continuation>(falseCont),
1205 isStrictCheck = true;
1206 1214
1207 Branch.loose(Primitive condition, 1215 Branch.loose(Primitive condition,
1208 Continuation trueCont, 1216 Continuation trueCont,
1209 Continuation falseCont) 1217 Continuation falseCont)
1210 : this.condition = new Reference<Primitive>(condition), 1218 : this(condition, trueCont, falseCont, strict: false);
1211 trueContinuation = new Reference<Continuation>(trueCont),
1212 falseContinuation = new Reference<Continuation>(falseCont),
1213 this.isStrictCheck = false;
1214 1219
1215 accept(BlockVisitor visitor) => visitor.visitBranch(this); 1220 accept(BlockVisitor visitor) => visitor.visitBranch(this);
1216 1221
1217 void setParentPointers() { 1222 void setParentPointers() {
1218 condition.parent = this; 1223 condition.parent = this;
1219 trueContinuation.parent = this; 1224 trueContinuation.parent = this;
1220 falseContinuation.parent = this; 1225 falseContinuation.parent = this;
1221 } 1226 }
1222 } 1227 }
1223 1228
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 node = node.next; 1907 node = node.next;
1903 nodes.add(node); 1908 nodes.add(node);
1904 } 1909 }
1905 } 1910 }
1906 walkBlock(root); 1911 walkBlock(root);
1907 while (stack.isNotEmpty) { 1912 while (stack.isNotEmpty) {
1908 walkBlock(stack.removeLast()); 1913 walkBlock(stack.removeLast());
1909 } 1914 }
1910 nodes.reversed.forEach(v.visit); 1915 nodes.reversed.forEach(v.visit);
1911 } 1916 }
1917
1918 /// Visits block-level nodes in lexical pre-order.
1919 ///
1920 /// Continuations and function definitions are considered "block headers".
1921 /// The block itself is the sequence of interior expressions in the body,
1922 /// terminated by a tail expression.
1923 ///
1924 /// Each block is visited starting with its tail expression, then every
1925 /// interior expression from bottom to top, and finally the block header
1926 /// is visited.
1927 ///
1928 /// Blocks are visited in pre-order, so the body of a continuation is always
1929 /// processed after its non-recursive invocation sites.
1930 ///
1931 /// The IR may be transformed during the traversal, but only the original
1932 /// nodes will be visited.
1933 static void traverseInPreOrder(FunctionDefinition root, BlockVisitor v) {
1934 List<Continuation> stack = <Continuation>[];
1935 void walkBlock(InteriorNode block) {
1936 v.visit(block);
1937 Expression node = block.body;
1938 v.visit(node);
1939 while (node.next != null) {
1940 if (node is LetCont) {
1941 stack.addAll(node.continuations);
1942 } else if (node is LetHandler) {
1943 stack.add(node.handler);
1944 }
1945 node = node.next;
1946 v.visit(node);
1947 }
1948 }
1949 walkBlock(root);
1950 while (stack.isNotEmpty) {
1951 walkBlock(stack.removeLast());
1952 }
1953 }
1912 } 1954 }
1913 1955
1914 abstract class Visitor<T> implements BlockVisitor<T> { 1956 abstract class Visitor<T> implements BlockVisitor<T> {
1915 const Visitor(); 1957 const Visitor();
1916 1958
1917 T visit(Node node); 1959 T visit(Node node);
1918 1960
1919 // Definitions. 1961 // Definitions.
1920 T visitInvokeStatic(InvokeStatic node); 1962 T visitInvokeStatic(InvokeStatic node);
1921 T visitInvokeMethod(InvokeMethod node); 1963 T visitInvokeMethod(InvokeMethod node);
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 plug(new Branch.loose(_definitions.getCopy(node.condition), 2836 plug(new Branch.loose(_definitions.getCopy(node.condition),
2795 _copies[node.trueContinuation.definition], 2837 _copies[node.trueContinuation.definition],
2796 _copies[node.falseContinuation.definition]) 2838 _copies[node.falseContinuation.definition])
2797 ..isStrictCheck = node.isStrictCheck); 2839 ..isStrictCheck = node.isStrictCheck);
2798 } 2840 }
2799 2841
2800 visitUnreachable(Unreachable node) { 2842 visitUnreachable(Unreachable node) {
2801 plug(new Unreachable()); 2843 plug(new Unreachable());
2802 } 2844 }
2803 } 2845 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698