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

Side by Side Diff: lib/compiler/implementation/js_backend/constant_system_javascript.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 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); 5 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem();
6 6
7 class JavaScriptBitNotOperation extends BitNotOperation { 7 class JavaScriptBitNotOperation extends BitNotOperation {
8 const JavaScriptBitNotOperation(); 8 const JavaScriptBitNotOperation();
9 9
10 Constant fold(Constant constant) { 10 Constant fold(Constant constant) {
(...skipping 24 matching lines...) Expand all
35 // In JavaScript we don't check for -0 and treat it as if it was zero. 35 // In JavaScript we don't check for -0 and treat it as if it was zero.
36 if (left.isMinusZero()) left = DART_CONSTANT_SYSTEM.createInt(0); 36 if (left.isMinusZero()) left = DART_CONSTANT_SYSTEM.createInt(0);
37 if (right.isMinusZero()) right = DART_CONSTANT_SYSTEM.createInt(0); 37 if (right.isMinusZero()) right = DART_CONSTANT_SYSTEM.createInt(0);
38 IntConstant result = dartBitOperation.fold(left, right); 38 IntConstant result = dartBitOperation.fold(left, right);
39 if (result != null) { 39 if (result != null) {
40 // We convert the result of bit-operations to 32 bit unsigned integers. 40 // We convert the result of bit-operations to 32 bit unsigned integers.
41 return JAVA_SCRIPT_CONSTANT_SYSTEM.createInt32(result.value); 41 return JAVA_SCRIPT_CONSTANT_SYSTEM.createInt32(result.value);
42 } 42 }
43 return result; 43 return result;
44 } 44 }
45
46 apply(left, right) => dartBitOperation.apply(left, right);
45 } 47 }
46 48
47 class JavaScriptShiftRightOperation extends JavaScriptBinaryBitOperation { 49 class JavaScriptShiftRightOperation extends JavaScriptBinaryBitOperation {
48 const JavaScriptShiftRightOperation() : super(const ShiftRightOperation()); 50 const JavaScriptShiftRightOperation() : super(const ShiftRightOperation());
49 51
50 Constant fold(Constant left, Constant right) { 52 Constant fold(Constant left, Constant right) {
51 // Truncate the input value to 32 bits if necessary. 53 // Truncate the input value to 32 bits if necessary.
52 if (left.isInt()) { 54 if (left.isInt()) {
53 IntConstant intConstant = left; 55 IntConstant intConstant = left;
54 int value = intConstant.value; 56 int value = intConstant.value;
(...skipping 25 matching lines...) Expand all
80 82
81 Constant fold(Constant constant) { 83 Constant fold(Constant constant) {
82 if (constant.isInt()) { 84 if (constant.isInt()) {
83 IntConstant intConstant = constant; 85 IntConstant intConstant = constant;
84 if (intConstant.value == 0) { 86 if (intConstant.value == 0) {
85 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); 87 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0);
86 } 88 }
87 } 89 }
88 return dartNegateOperation.fold(constant); 90 return dartNegateOperation.fold(constant);
89 } 91 }
92 apply(value) => -value;
90 } 93 }
91 94
92 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { 95 class JavaScriptBinaryArithmeticOperation implements BinaryOperation {
93 final BinaryOperation dartArithmeticOperation; 96 final BinaryOperation dartArithmeticOperation;
94 97
95 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); 98 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation);
96 99
97 bool isUserDefinable() => dartArithmeticOperation.isUserDefinable(); 100 bool isUserDefinable() => dartArithmeticOperation.isUserDefinable();
98 SourceString get name => dartArithmeticOperation.name; 101 SourceString get name => dartArithmeticOperation.name;
99 102
100 Constant fold(Constant left, Constant right) { 103 Constant fold(Constant left, Constant right) {
101 Constant result = dartArithmeticOperation.fold(left, right); 104 Constant result = dartArithmeticOperation.fold(left, right);
102 if (result == null) return result; 105 if (result == null) return result;
103 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result); 106 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result);
104 } 107 }
108
109 apply(left, right) => dartArithmeticOperation.apply(left, right);
105 } 110 }
106 111
107 class JavaScriptIdentityOperation implements BinaryOperation { 112 class JavaScriptIdentityOperation implements BinaryOperation {
108 final IdentityOperation dartIdentityOperation = const IdentityOperation(); 113 final IdentityOperation dartIdentityOperation = const IdentityOperation();
109 114
110 const JavaScriptIdentityOperation(); 115 const JavaScriptIdentityOperation();
111 116
112 bool isUserDefinable() => dartIdentityOperation.isUserDefinable(); 117 bool isUserDefinable() => dartIdentityOperation.isUserDefinable();
113 SourceString get name => dartIdentityOperation.name; 118 SourceString get name => dartIdentityOperation.name;
114 119
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // At runtime, an integer is both an integer and a double: the 227 // At runtime, an integer is both an integer and a double: the
223 // integer type check is Math.floor, which will return true only 228 // integer type check is Math.floor, which will return true only
224 // for real integers, and our double type check is 'typeof number' 229 // for real integers, and our double type check is 'typeof number'
225 // which will return true for both integers and doubles. 230 // which will return true for both integers and doubles.
226 if (s.element == compiler.intClass && t.element == compiler.doubleClass) { 231 if (s.element == compiler.intClass && t.element == compiler.doubleClass) {
227 return true; 232 return true;
228 } 233 }
229 return compiler.types.isSubtype(s, t); 234 return compiler.types.isSubtype(s, t);
230 } 235 }
231 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698