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

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

Issue 87783003: Add UInt32 and UInt31 types to better infer bit operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
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 part of ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 continueAction = new Map<Element, ElementAction>(); 182 continueAction = new Map<Element, ElementAction>();
183 183
184 Compiler get compiler => backend.compiler; 184 Compiler get compiler => backend.compiler;
185 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 185 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
186 CodegenEnqueuer get world => backend.compiler.enqueuer.codegen; 186 CodegenEnqueuer get world => backend.compiler.enqueuer.codegen;
187 187
188 bool isGenerateAtUseSite(HInstruction instruction) { 188 bool isGenerateAtUseSite(HInstruction instruction) {
189 return generateAtUseSite.contains(instruction); 189 return generateAtUseSite.contains(instruction);
190 } 190 }
191 191
192 bool isNonNegativeInt32Constant(HInstruction instruction) {
193 if (instruction.isConstantInteger()) {
194 HConstant constantInstruction = instruction;
195 PrimitiveConstant primitiveConstant = constantInstruction.constant;
196 int value = primitiveConstant.value;
197 if (value >= 0 && value < (1 << 31)) {
198 return true;
199 }
200 }
201 return false;
202 }
203
204 bool hasNonBitOpUser(HInstruction instruction, Set<HPhi> phiSet) { 192 bool hasNonBitOpUser(HInstruction instruction, Set<HPhi> phiSet) {
205 for (HInstruction user in instruction.usedBy) { 193 for (HInstruction user in instruction.usedBy) {
206 if (user is HPhi) { 194 if (user is HPhi) {
207 if (!phiSet.contains(user)) { 195 if (!phiSet.contains(user)) {
208 phiSet.add(user); 196 phiSet.add(user);
209 if (hasNonBitOpUser(user, phiSet)) return true; 197 if (hasNonBitOpUser(user, phiSet)) return true;
210 } 198 }
211 } else if (user is! HBitNot && user is! HBinaryBitOp) { 199 } else if (user is! HBitNot && user is! HBinaryBitOp) {
212 return true; 200 return true;
213 } 201 }
214 } 202 }
215 return false; 203 return false;
216 } 204 }
217 205
218 // We want the outcome of bit-operations to be positive. However, if 206 bool requiresUintConversion(instruction) {
219 // the result of a bit-operation is only used by other bit 207 if (instruction.isUInt31(compiler)) return false;
220 // operations we do not have to convert to an unsigned 208 // If the result of a bit-operation is only used by other bit
221 // integer. Also, if we are using & with a positive constant we know 209 // operations, we do not have to convert to an unsigned integer.
222 // that the result is positive already and need no conversion.
223 bool requiresUintConversion(HInstruction instruction) {
224 if (instruction is HShiftRight) {
225 return false;
226 }
227 if (instruction is HBitAnd) {
228 HBitAnd bitAnd = instruction;
229 if (isNonNegativeInt32Constant(bitAnd.left) ||
230 isNonNegativeInt32Constant(bitAnd.right)) {
231 return false;
232 }
233 }
234 return hasNonBitOpUser(instruction, new Set<HPhi>()); 210 return hasNonBitOpUser(instruction, new Set<HPhi>());
235 } 211 }
236 212
237 /** 213 /**
238 * If the [instruction] is not `null` it will be used to attach the position 214 * If the [instruction] is not `null` it will be used to attach the position
239 * to the [statement]. 215 * to the [statement].
240 */ 216 */
241 void pushStatement(js.Statement statement, [HInstruction instruction]) { 217 void pushStatement(js.Statement statement, [HInstruction instruction]) {
242 assert(expressionStack.isEmpty); 218 assert(expressionStack.isEmpty);
243 if (instruction != null) { 219 if (instruction != null) {
(...skipping 2338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2582 if (left.isConstantNull() || right.isConstantNull() || 2558 if (left.isConstantNull() || right.isConstantNull() ||
2583 (left.isPrimitive(compiler) && 2559 (left.isPrimitive(compiler) &&
2584 left.instructionType == right.instructionType)) { 2560 left.instructionType == right.instructionType)) {
2585 return '=='; 2561 return '==';
2586 } 2562 }
2587 return null; 2563 return null;
2588 } else { 2564 } else {
2589 return '==='; 2565 return '===';
2590 } 2566 }
2591 } 2567 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698