| OLD | NEW |
| 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 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
| 7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 8 : this.backend = backend, | 8 : this.backend = backend, |
| 9 super(backend.compiler); | 9 super(backend.compiler); |
| 10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 Compiler get compiler() => backend.compiler; | 177 Compiler get compiler() => backend.compiler; |
| 178 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter; | 178 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter; |
| 179 Enqueuer get world() => backend.compiler.enqueuer.codegen; | 179 Enqueuer get world() => backend.compiler.enqueuer.codegen; |
| 180 | 180 |
| 181 bool isGenerateAtUseSite(HInstruction instruction) { | 181 bool isGenerateAtUseSite(HInstruction instruction) { |
| 182 return generateAtUseSite.contains(instruction); | 182 return generateAtUseSite.contains(instruction); |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool isNonNegativeInt32Constant(HInstruction instruction) { | 185 bool isNonNegativeInt32Constant(HInstruction instruction) { |
| 186 if (instruction.isConstantInteger()) { | 186 if (instruction.isConstantInteger()) { |
| 187 int value = | 187 HConstant constantInstruction = instruction; |
| 188 ((instruction as HConstant).constant as PrimitiveConstant).value; | 188 PrimitiveConstant primitiveConstant = constantInstruction.constant; |
| 189 int value = primitiveConstant.value; |
| 189 if (value >= 0 && value < (1 << 31)) { | 190 if (value >= 0 && value < (1 << 31)) { |
| 190 return true; | 191 return true; |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 return false; | 194 return false; |
| 194 } | 195 } |
| 195 | 196 |
| 196 bool hasNonBitOpUser(HInstruction instruction, Set<HPhi> phiSet) { | 197 bool hasNonBitOpUser(HInstruction instruction, Set<HPhi> phiSet) { |
| 197 for (HInstruction user in instruction.usedBy) { | 198 for (HInstruction user in instruction.usedBy) { |
| 198 if (user is HPhi) { | 199 if (user is HPhi) { |
| 199 if (!phiSet.contains(user)) { | 200 if (!phiSet.contains(user)) { |
| 200 phiSet.add(user); | 201 phiSet.add(user); |
| 201 if (hasNonBitOpUser(user, phiSet)) return true; | 202 if (hasNonBitOpUser(user, phiSet)) return true; |
| 202 } | 203 } |
| 203 } else if (user is! HBitNot && user is! HBinaryBitOp) { | 204 } else if (user is! HBitNot && user is! HBinaryBitOp) { |
| 204 return true; | 205 return true; |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 return false; | 208 return false; |
| 208 } | 209 } |
| 209 | 210 |
| 210 // We want the outcome of bit-operations to be positive. However, if | 211 // We want the outcome of bit-operations to be positive. However, if |
| 211 // the result of a bit-operation is only used by other bit | 212 // the result of a bit-operation is only used by other bit |
| 212 // operations we do not have to convert to an unsigned | 213 // operations we do not have to convert to an unsigned |
| 213 // integer. Also, if we are using & with a positive constant we know | 214 // integer. Also, if we are using & with a positive constant we know |
| 214 // that the result is positive already and need no conversion. | 215 // that the result is positive already and need no conversion. |
| 215 bool requiresUintConversion(HInstruction instruction) { | 216 bool requiresUintConversion(HInstruction instruction) { |
| 216 if (instruction is HBitAnd && | 217 if (instruction is HBitAnd) { |
| 217 (isNonNegativeInt32Constant((instruction as HBitAnd).left) || | 218 HBitAnd bitAnd = instruction; |
| 218 isNonNegativeInt32Constant((instruction as HBitAnd).right))) { | 219 if (isNonNegativeInt32Constant(bitAnd.left) || |
| 219 return false; | 220 isNonNegativeInt32Constant(bitAnd.right)) { |
| 221 return false; |
| 222 } |
| 220 } | 223 } |
| 221 return hasNonBitOpUser(instruction, new Set<HPhi>()); | 224 return hasNonBitOpUser(instruction, new Set<HPhi>()); |
| 222 } | 225 } |
| 223 | 226 |
| 224 /** | 227 /** |
| 225 * If the [instruction] is not `null` it will be used to attach the position | 228 * If the [instruction] is not `null` it will be used to attach the position |
| 226 * to the [statement]. | 229 * to the [statement]. |
| 227 */ | 230 */ |
| 228 void pushStatement(js.Statement statement, [HInstruction instruction]) { | 231 void pushStatement(js.Statement statement, [HInstruction instruction]) { |
| 229 assert(expressionStack.isEmpty()); | 232 assert(expressionStack.isEmpty()); |
| (...skipping 2627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2857 if (leftType.canBeNull() && rightType.canBeNull()) { | 2860 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2858 if (left.isConstantNull() || right.isConstantNull() || | 2861 if (left.isConstantNull() || right.isConstantNull() || |
| 2859 (leftType.isPrimitive() && leftType == rightType)) { | 2862 (leftType.isPrimitive() && leftType == rightType)) { |
| 2860 return '=='; | 2863 return '=='; |
| 2861 } | 2864 } |
| 2862 return null; | 2865 return null; |
| 2863 } else { | 2866 } else { |
| 2864 return '==='; | 2867 return '==='; |
| 2865 } | 2868 } |
| 2866 } | 2869 } |
| OLD | NEW |