Chromium Code Reviews| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class HVisitor<R> { | 7 abstract class HVisitor<R> { |
| 8 R visitAdd(HAdd node); | 8 R visitAdd(HAdd node); |
| 9 R visitBailoutTarget(HBailoutTarget node); | 9 R visitBailoutTarget(HBailoutTarget node); |
| 10 R visitBitAnd(HBitAnd node); | 10 R visitBitAnd(HBitAnd node); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 } | 155 } |
| 156 | 156 |
| 157 HBasicBlock addNewLoopHeaderBlock(TargetElement target, | 157 HBasicBlock addNewLoopHeaderBlock(TargetElement target, |
| 158 List<LabelElement> labels) { | 158 List<LabelElement> labels) { |
| 159 HBasicBlock result = addNewBlock(); | 159 HBasicBlock result = addNewBlock(); |
| 160 result.loopInformation = | 160 result.loopInformation = |
| 161 new HLoopInformation(result, target, labels); | 161 new HLoopInformation(result, target, labels); |
| 162 return result; | 162 return result; |
| 163 } | 163 } |
| 164 | 164 |
| 165 static HType mapConstantTypeToSsaType(Constant constant) { | 165 static HType mapConstantTypeToSsaType(Constant constant, Compiler compiler) { |
| 166 JavaScriptBackend backend = compiler.backend; | |
| 166 if (constant.isNull()) return HType.NULL; | 167 if (constant.isNull()) return HType.NULL; |
| 167 if (constant.isBool()) return HType.BOOLEAN; | 168 if (constant.isBool()) return HType.BOOLEAN; |
| 168 if (constant.isInt()) return HType.INTEGER; | 169 if (constant.isInt()) return HType.INTEGER; |
| 169 if (constant.isDouble()) return HType.DOUBLE; | 170 if (constant.isDouble()) return HType.DOUBLE; |
| 170 if (constant.isString()) return HType.STRING; | 171 if (constant.isString()) return backend.stringType; |
| 171 if (constant.isList()) return HType.READABLE_ARRAY; | 172 if (constant.isList()) return backend.readableArrayType; |
| 172 if (constant.isFunction()) return HType.UNKNOWN; | 173 if (constant.isFunction()) return HType.UNKNOWN; |
| 173 if (constant.isSentinel()) return HType.UNKNOWN; | 174 if (constant.isSentinel()) return HType.UNKNOWN; |
| 174 // TODO(sra): What is the type of the prototype of an interceptor? | 175 // TODO(sra): What is the type of the prototype of an interceptor? |
| 175 if (constant.isInterceptor()) return HType.UNKNOWN; | 176 if (constant.isInterceptor()) return HType.UNKNOWN; |
| 176 // TODO(kasperl): This seems a bit fishy, but we do not have the | |
| 177 // compiler at hand so we cannot use the usual HType factory | |
| 178 // methods. At some point this should go away. | |
| 179 ObjectConstant objectConstant = constant; | 177 ObjectConstant objectConstant = constant; |
| 180 TypeMask mask = new TypeMask.nonNullExact(objectConstant.type); | 178 return new HBoundedType(new TypeMask.nonNullExact(objectConstant.type)); |
| 181 return new HBoundedType(mask); | |
| 182 } | 179 } |
| 183 | 180 |
| 184 HConstant addConstant(Constant constant) { | 181 HConstant addConstant(Constant constant, Compiler compiler) { |
| 185 HConstant result = constants[constant]; | 182 HConstant result = constants[constant]; |
| 186 if (result == null) { | 183 if (result == null) { |
| 187 HType type = mapConstantTypeToSsaType(constant); | 184 HType type = mapConstantTypeToSsaType(constant, compiler); |
| 188 result = new HConstant.internal(constant, type); | 185 result = new HConstant.internal(constant, type); |
| 189 entry.addAtExit(result); | 186 entry.addAtExit(result); |
| 190 constants[constant] = result; | 187 constants[constant] = result; |
| 191 } else if (result.block == null) { | 188 } else if (result.block == null) { |
| 192 // The constant was not used anymore. | 189 // The constant was not used anymore. |
| 193 entry.addAtExit(result); | 190 entry.addAtExit(result); |
| 194 } | 191 } |
| 195 return result; | 192 return result; |
| 196 } | 193 } |
| 197 | 194 |
| 198 HConstant addConstantInt(int i, ConstantSystem constantSystem) { | 195 HConstant addConstantInt(int i, Compiler compiler) { |
| 199 return addConstant(constantSystem.createInt(i)); | 196 return addConstant(compiler.backend.constantSystem.createInt(i), compiler); |
| 200 } | 197 } |
| 201 | 198 |
| 202 HConstant addConstantDouble(double d, ConstantSystem constantSystem) { | 199 HConstant addConstantDouble(double d, Compiler compiler) { |
| 203 return addConstant(constantSystem.createDouble(d)); | 200 return addConstant( |
| 201 compiler.backend.constantSystem.createDouble(d), compiler); | |
| 204 } | 202 } |
| 205 | 203 |
| 206 HConstant addConstantString(DartString str, | 204 HConstant addConstantString(DartString str, |
| 207 Node diagnosticNode, | 205 Node diagnosticNode, |
| 208 ConstantSystem constantSystem) { | 206 Compiler compiler) { |
| 209 return addConstant(constantSystem.createString(str, diagnosticNode)); | 207 return addConstant( |
| 208 compiler.backend.constantSystem.createString(str, diagnosticNode), | |
| 209 compiler); | |
| 210 } | 210 } |
| 211 | 211 |
| 212 HConstant addConstantBool(bool value, ConstantSystem constantSystem) { | 212 HConstant addConstantBool(bool value, Compiler compiler) { |
| 213 return addConstant(constantSystem.createBool(value)); | 213 return addConstant( |
| 214 compiler.backend.constantSystem.createBool(value), compiler); | |
| 214 } | 215 } |
| 215 | 216 |
| 216 HConstant addConstantNull(ConstantSystem constantSystem) { | 217 HConstant addConstantNull(Compiler compiler) { |
| 217 return addConstant(constantSystem.createNull()); | 218 return addConstant(compiler.backend.constantSystem.createNull(), compiler); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void finalize() { | 221 void finalize() { |
| 221 addBlock(exit); | 222 addBlock(exit); |
| 222 exit.open(); | 223 exit.open(); |
| 223 exit.close(new HExit()); | 224 exit.close(new HExit()); |
| 224 assignDominators(); | 225 assignDominators(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void assignDominators() { | 228 void assignDominators() { |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 bool isArray(Compiler compiler) => | 830 bool isArray(Compiler compiler) => |
| 830 instructionType.isArray(compiler); | 831 instructionType.isArray(compiler); |
| 831 bool isReadableArray(Compiler compiler) => | 832 bool isReadableArray(Compiler compiler) => |
| 832 instructionType.isReadableArray(compiler); | 833 instructionType.isReadableArray(compiler); |
| 833 bool isMutableArray(Compiler compiler) => | 834 bool isMutableArray(Compiler compiler) => |
| 834 instructionType.isMutableArray(compiler); | 835 instructionType.isMutableArray(compiler); |
| 835 bool isExtendableArray(Compiler compiler) => | 836 bool isExtendableArray(Compiler compiler) => |
| 836 instructionType.isExtendableArray(compiler); | 837 instructionType.isExtendableArray(compiler); |
| 837 bool isFixedArray(Compiler compiler) => | 838 bool isFixedArray(Compiler compiler) => |
| 838 instructionType.isFixedArray(compiler); | 839 instructionType.isFixedArray(compiler); |
| 840 bool isString(Compiler compiler) => | |
| 841 instructionType.isString(compiler); | |
| 842 bool isPrimitive(Compiler compiler) => | |
| 843 instructionType.isPrimitive(compiler); | |
| 844 bool isPrimitiveOrNull(Compiler compiler) => | |
| 845 instructionType.isPrimitiveOrNull(compiler); | |
| 839 bool isBoolean() => instructionType.isBoolean(); | 846 bool isBoolean() => instructionType.isBoolean(); |
| 840 bool isInteger() => instructionType.isInteger(); | 847 bool isInteger() => instructionType.isInteger(); |
| 841 bool isIntegerOrNull() => instructionType.isIntegerOrNull(); | 848 bool isIntegerOrNull() => instructionType.isIntegerOrNull(); |
| 842 bool isDouble() => instructionType.isDouble(); | 849 bool isDouble() => instructionType.isDouble(); |
| 843 bool isDoubleOrNull() => instructionType.isDoubleOrNull(); | 850 bool isDoubleOrNull() => instructionType.isDoubleOrNull(); |
| 844 bool isNumber() => instructionType.isNumber(); | 851 bool isNumber() => instructionType.isNumber(); |
| 845 bool isNumberOrNull() => instructionType.isNumberOrNull(); | 852 bool isNumberOrNull() => instructionType.isNumberOrNull(); |
| 846 bool isString() => instructionType.isString(); | |
| 847 bool isPrimitive() => instructionType.isPrimitive(); | |
| 848 bool isPrimitiveOrNull() => instructionType.isPrimitiveOrNull(); | |
| 849 bool isNull() => instructionType.isNull(); | 853 bool isNull() => instructionType.isNull(); |
| 850 bool canBeNull() => instructionType.canBeNull(); | 854 bool canBeNull() => instructionType.canBeNull(); |
| 851 bool canBePrimitive(Compiler compiler) => | 855 bool canBePrimitive(Compiler compiler) => |
| 852 instructionType.canBePrimitive(compiler); | 856 instructionType.canBePrimitive(compiler); |
| 853 bool canBePrimitiveArray(Compiler compiler) => | 857 bool canBePrimitiveArray(Compiler compiler) => |
| 854 instructionType.canBePrimitiveArray(compiler); | 858 instructionType.canBePrimitiveArray(compiler); |
| 855 | 859 |
| 856 bool isIndexable(Compiler compiler) => | 860 bool isIndexable(Compiler compiler) => |
| 857 instructionType.isIndexable(compiler); | 861 instructionType.isIndexable(compiler); |
| 858 bool isMutableIndexable(Compiler compiler) => | 862 bool isMutableIndexable(Compiler compiler) => |
| (...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2130 toString() => 'static store ${element.name}'; | 2134 toString() => 'static store ${element.name}'; |
| 2131 accept(HVisitor visitor) => visitor.visitStaticStore(this); | 2135 accept(HVisitor visitor) => visitor.visitStaticStore(this); |
| 2132 | 2136 |
| 2133 int typeCode() => HInstruction.STATIC_STORE_TYPECODE; | 2137 int typeCode() => HInstruction.STATIC_STORE_TYPECODE; |
| 2134 bool typeEquals(other) => other is HStaticStore; | 2138 bool typeEquals(other) => other is HStaticStore; |
| 2135 bool dataEquals(HStaticStore other) => element == other.element; | 2139 bool dataEquals(HStaticStore other) => element == other.element; |
| 2136 bool isJsStatement() => true; | 2140 bool isJsStatement() => true; |
| 2137 } | 2141 } |
| 2138 | 2142 |
| 2139 class HLiteralList extends HInstruction { | 2143 class HLiteralList extends HInstruction { |
| 2140 HLiteralList(inputs) : super(inputs) { | 2144 HLiteralList(inputs) : super(inputs); |
|
Johnni Winther
2013/06/12 08:58:49
Add parameter for [instructionType].
ngeoffray
2013/06/12 09:55:50
Done.
| |
| 2141 instructionType = HType.EXTENDABLE_ARRAY; | |
| 2142 } | |
| 2143 toString() => 'literal list'; | 2145 toString() => 'literal list'; |
| 2144 accept(HVisitor visitor) => visitor.visitLiteralList(this); | 2146 accept(HVisitor visitor) => visitor.visitLiteralList(this); |
| 2145 } | 2147 } |
| 2146 | 2148 |
| 2147 /** | 2149 /** |
| 2148 * The primitive array indexing operation. Note that this instruction | 2150 * The primitive array indexing operation. Note that this instruction |
| 2149 * does not throw because we generate the checks explicitly. | 2151 * does not throw because we generate the checks explicitly. |
| 2150 */ | 2152 */ |
| 2151 class HIndex extends HInstruction { | 2153 class HIndex extends HInstruction { |
| 2152 final Selector selector; | 2154 final Selector selector; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2303 HRangeConversion(HInstruction input) : super(<HInstruction>[input]) { | 2305 HRangeConversion(HInstruction input) : super(<HInstruction>[input]) { |
| 2304 sourceElement = input.sourceElement; | 2306 sourceElement = input.sourceElement; |
| 2305 // We currently only do range analysis for integers. | 2307 // We currently only do range analysis for integers. |
| 2306 instructionType = HType.INTEGER; | 2308 instructionType = HType.INTEGER; |
| 2307 } | 2309 } |
| 2308 accept(HVisitor visitor) => visitor.visitRangeConversion(this); | 2310 accept(HVisitor visitor) => visitor.visitRangeConversion(this); |
| 2309 } | 2311 } |
| 2310 | 2312 |
| 2311 class HStringConcat extends HInstruction { | 2313 class HStringConcat extends HInstruction { |
| 2312 final Node node; | 2314 final Node node; |
| 2313 HStringConcat(HInstruction left, HInstruction right, this.node) | 2315 HStringConcat(HInstruction left, HInstruction right, this.node) |
|
Johnni Winther
2013/06/12 08:58:49
Ditto.
ngeoffray
2013/06/12 09:55:50
Done.
| |
| 2314 : super(<HInstruction>[left, right]) { | 2316 : super(<HInstruction>[left, right]) { |
| 2315 // TODO(sra): Until Issue 9293 is fixed, this false dependency keeps the | 2317 // TODO(sra): Until Issue 9293 is fixed, this false dependency keeps the |
| 2316 // concats bunched with stringified inputs for much better looking code with | 2318 // concats bunched with stringified inputs for much better looking code with |
| 2317 // fewer temps. | 2319 // fewer temps. |
| 2318 sideEffects.setDependsOnSomething(); | 2320 sideEffects.setDependsOnSomething(); |
| 2319 instructionType = HType.STRING; | |
| 2320 } | 2321 } |
| 2321 | 2322 |
| 2322 HInstruction get left => inputs[0]; | 2323 HInstruction get left => inputs[0]; |
| 2323 HInstruction get right => inputs[1]; | 2324 HInstruction get right => inputs[1]; |
| 2324 | 2325 |
| 2325 accept(HVisitor visitor) => visitor.visitStringConcat(this); | 2326 accept(HVisitor visitor) => visitor.visitStringConcat(this); |
| 2326 toString() => "string concat"; | 2327 toString() => "string concat"; |
| 2327 } | 2328 } |
| 2328 | 2329 |
| 2329 /** | 2330 /** |
| 2330 * The part of string interpolation which converts and interpolated expression | 2331 * The part of string interpolation which converts and interpolated expression |
| 2331 * into a String value. | 2332 * into a String value. |
| 2332 */ | 2333 */ |
| 2333 class HStringify extends HInstruction { | 2334 class HStringify extends HInstruction { |
| 2334 final Node node; | 2335 final Node node; |
| 2335 HStringify(HInstruction input, this.node) : super(<HInstruction>[input]) { | 2336 HStringify(HInstruction input, this.node) : super(<HInstruction>[input]) { |
| 2336 sideEffects.setAllSideEffects(); | 2337 sideEffects.setAllSideEffects(); |
| 2337 sideEffects.setDependsOnSomething(); | 2338 sideEffects.setDependsOnSomething(); |
| 2338 instructionType = HType.STRING; | |
| 2339 } | 2339 } |
| 2340 | 2340 |
| 2341 accept(HVisitor visitor) => visitor.visitStringify(this); | 2341 accept(HVisitor visitor) => visitor.visitStringify(this); |
| 2342 toString() => "stringify"; | 2342 toString() => "stringify"; |
| 2343 } | 2343 } |
| 2344 | 2344 |
| 2345 /** Non-block-based (aka. traditional) loop information. */ | 2345 /** Non-block-based (aka. traditional) loop information. */ |
| 2346 class HLoopInformation { | 2346 class HLoopInformation { |
| 2347 final HBasicBlock header; | 2347 final HBasicBlock header; |
| 2348 final List<HBasicBlock> blocks; | 2348 final List<HBasicBlock> blocks; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2675 HBasicBlock get start => expression.start; | 2675 HBasicBlock get start => expression.start; |
| 2676 HBasicBlock get end { | 2676 HBasicBlock get end { |
| 2677 // We don't create a switch block if there are no cases. | 2677 // We don't create a switch block if there are no cases. |
| 2678 assert(!statements.isEmpty); | 2678 assert(!statements.isEmpty); |
| 2679 return statements.last.end; | 2679 return statements.last.end; |
| 2680 } | 2680 } |
| 2681 | 2681 |
| 2682 bool accept(HStatementInformationVisitor visitor) => | 2682 bool accept(HStatementInformationVisitor visitor) => |
| 2683 visitor.visitSwitchInfo(this); | 2683 visitor.visitSwitchInfo(this); |
| 2684 } | 2684 } |
| OLD | NEW |