| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 bool isNonNegativeInt32Constant(HInstruction instruction) { | 210 bool isNonNegativeInt32Constant(HInstruction instruction) { |
| 211 if (instruction.isConstantInteger()) { | 211 if (instruction.isConstantInteger()) { |
| 212 int value = instruction.constant.value; | 212 int value = instruction.constant.value; |
| 213 if (value >= 0 && value < (1 << 31)) { | 213 if (value >= 0 && value < (1 << 31)) { |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 return false; | 217 return false; |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool hasNonBitOpUser(HInstruction instruction, Set<HPhi> phiSet) { |
| 221 for (HInstruction use in instruction.usedBy) { |
| 222 if (use is HPhi) { |
| 223 if (!phiSet.contains(use)) { |
| 224 phiSet.add(use); |
| 225 if (hasNonBitOpUser(use, phiSet)) return true; |
| 226 } |
| 227 } else if (use is! HBitNot && use is! HBinaryBitOp) { |
| 228 return true; |
| 229 } |
| 230 } |
| 231 return false; |
| 232 } |
| 233 |
| 220 // We want the outcome of bit-operations to be positive. However, if | 234 // We want the outcome of bit-operations to be positive. However, if |
| 221 // the result of a bit-operation is only used by other bit | 235 // the result of a bit-operation is only used by other bit |
| 222 // operations we do not have to convert to an unsigned | 236 // operations we do not have to convert to an unsigned |
| 223 // integer. Also, if we are using & with a positive constant we know | 237 // integer. Also, if we are using & with a positive constant we know |
| 224 // that the result is positive already and need no conversion. | 238 // that the result is positive already and need no conversion. |
| 225 bool requiresUintConversion(HInstruction instruction) { | 239 bool requiresUintConversion(HInstruction instruction) { |
| 226 if (instruction is HBitAnd && | 240 if (instruction is HBitAnd && |
| 227 (isNonNegativeInt32Constant(instruction.left) || | 241 (isNonNegativeInt32Constant(instruction.left) || |
| 228 isNonNegativeInt32Constant(instruction.right))) { | 242 isNonNegativeInt32Constant(instruction.right))) { |
| 229 return false; | 243 return false; |
| 230 } | 244 } |
| 231 bool result = false; | 245 return hasNonBitOpUser(instruction, new Set<HPhi>()); |
| 232 for (HInstruction use in instruction.usedBy) { | |
| 233 if (use is! HBitNot && use is! HBinaryBitOp) { | |
| 234 result = true; | |
| 235 break; | |
| 236 } | |
| 237 } | |
| 238 return result; | |
| 239 } | 246 } |
| 240 | 247 |
| 241 SsaCodeGenerator(this.backend, | 248 SsaCodeGenerator(this.backend, |
| 242 this.work, | 249 this.work, |
| 243 this.parameters, | 250 this.parameters, |
| 244 this.parameterNames) | 251 this.parameterNames) |
| 245 : declaredVariables = new Set<String>(), | 252 : declaredVariables = new Set<String>(), |
| 246 delayedVariableDeclarations = new Set<String>(), | 253 delayedVariableDeclarations = new Set<String>(), |
| 247 buffer = new StringBuffer(), | 254 buffer = new StringBuffer(), |
| 248 generateAtUseSite = new Set<HInstruction>(), | 255 generateAtUseSite = new Set<HInstruction>(), |
| (...skipping 2852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3101 startBailoutSwitch(); | 3108 startBailoutSwitch(); |
| 3102 } | 3109 } |
| 3103 } | 3110 } |
| 3104 | 3111 |
| 3105 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 3112 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 3106 if (labeledBlockInfo.body.start.hasGuards()) { | 3113 if (labeledBlockInfo.body.start.hasGuards()) { |
| 3107 endBailoutSwitch(); | 3114 endBailoutSwitch(); |
| 3108 } | 3115 } |
| 3109 } | 3116 } |
| 3110 } | 3117 } |
| OLD | NEW |