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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10968060: Add a value range analysis phase to remove bounds checks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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 SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 6
7 final JavaScriptBackend backend; 7 final JavaScriptBackend backend;
8 8
9 SsaCodeGeneratorTask(JavaScriptBackend backend) 9 SsaCodeGeneratorTask(JavaScriptBackend backend)
10 : this.backend = backend, 10 : this.backend = backend,
(...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 1908
1909 visitThrow(HThrow node) { 1909 visitThrow(HThrow node) {
1910 if (node.isRethrow) { 1910 if (node.isRethrow) {
1911 use(node.inputs[0]); 1911 use(node.inputs[0]);
1912 pushStatement(new js.Throw(pop()), node); 1912 pushStatement(new js.Throw(pop()), node);
1913 } else { 1913 } else {
1914 generateThrowWithHelper(@'$throw', node.inputs[0]); 1914 generateThrowWithHelper(@'$throw', node.inputs[0]);
1915 } 1915 }
1916 } 1916 }
1917 1917
1918 visitRangeConversion(HRangeConversion node) {
1919 // Range conversion instructions are removed by the value range
1920 // analyzer.
1921 assert(false);
1922 }
1923
1918 visitBoundsCheck(HBoundsCheck node) { 1924 visitBoundsCheck(HBoundsCheck node) {
1919 // TODO(ngeoffray): Separate the two checks of the bounds check, so, 1925 // TODO(ngeoffray): Separate the two checks of the bounds check, so,
1920 // e.g., the zero checks can be shared if possible. 1926 // e.g., the zero checks can be shared if possible.
1921 1927
1922 // If the checks always succeeds, we would have removed the bounds check 1928 // If the checks always succeeds, we would have removed the bounds check
1923 // completely. 1929 // completely.
1924 assert(node.staticChecks != HBoundsCheck.ALWAYS_TRUE); 1930 assert(node.staticChecks != HBoundsCheck.ALWAYS_TRUE);
1925 if (node.staticChecks != HBoundsCheck.ALWAYS_FALSE) { 1931 if (node.staticChecks != HBoundsCheck.ALWAYS_FALSE) {
1926 js.Binary under; 1932 js.Expression under;
1933 js.Expression over;
1927 if (node.staticChecks != HBoundsCheck.ALWAYS_ABOVE_ZERO) { 1934 if (node.staticChecks != HBoundsCheck.ALWAYS_ABOVE_ZERO) {
1928 assert(node.staticChecks == HBoundsCheck.FULL_CHECK);
1929 use(node.index); 1935 use(node.index);
1930 under = new js.Binary("<", pop(), new js.LiteralNumber("0")); 1936 under = new js.Binary("<", pop(), new js.LiteralNumber("0"));
1931 } 1937 }
1932 use(node.index); 1938 if (node.staticChecks != HBoundsCheck.ALWAYS_BELOW_LENGTH) {
1933 js.Expression index = pop(); 1939 var index = node.index;
1934 use(node.length); 1940 use(index);
1935 js.Binary over = new js.Binary(">=", index, pop()); 1941 js.Expression jsIndex = pop();
1936 js.Binary underOver = 1942 use(node.length);
1937 under == null ? over : new js.Binary("||", under, over); 1943 over = new js.Binary(">=", jsIndex, pop());
1944 }
Søren Gjesse 2012/09/26 14:00:15 Maybe assert that not both under and over are null
ngeoffray 2012/09/27 13:22:02 Done.
1945 js.Expression underOver = under == null
1946 ? over
1947 : over == null
1948 ? under
1949 : new js.Binary("||", under, over);
1938 js.Statement thenBody = new js.Block.empty(); 1950 js.Statement thenBody = new js.Block.empty();
1939 js.Block oldContainer = currentContainer; 1951 js.Block oldContainer = currentContainer;
1940 currentContainer = thenBody; 1952 currentContainer = thenBody;
1941 generateThrowWithHelper('ioore', node.index); 1953 generateThrowWithHelper('ioore', node.index);
1942 currentContainer = oldContainer; 1954 currentContainer = oldContainer;
1943 thenBody = unwrapStatement(thenBody); 1955 thenBody = unwrapStatement(thenBody);
1944 pushStatement(new js.If.noElse(underOver, thenBody), node); 1956 pushStatement(new js.If.noElse(underOver, thenBody), node);
1945 } else { 1957 } else {
1946 generateThrowWithHelper('ioore', node.index); 1958 generateThrowWithHelper('ioore', node.index);
1947 } 1959 }
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2994 if (leftType.canBeNull() && rightType.canBeNull()) { 3006 if (leftType.canBeNull() && rightType.canBeNull()) {
2995 if (left.isConstantNull() || right.isConstantNull() || 3007 if (left.isConstantNull() || right.isConstantNull() ||
2996 (leftType.isPrimitive() && leftType == rightType)) { 3008 (leftType.isPrimitive() && leftType == rightType)) {
2997 return '=='; 3009 return '==';
2998 } 3010 }
2999 return null; 3011 return null;
3000 } else { 3012 } else {
3001 return '==='; 3013 return '===';
3002 } 3014 }
3003 } 3015 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698