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

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

Issue 15724021: Move array and string related HType from const to a field in the backend. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 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
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
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
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(List<HInstruction> inputs, HType type) : super(inputs) {
2141 instructionType = HType.EXTENDABLE_ARRAY; 2145 instructionType = type;
2142 } 2146 }
2143 toString() => 'literal list'; 2147 toString() => 'literal list';
2144 accept(HVisitor visitor) => visitor.visitLiteralList(this); 2148 accept(HVisitor visitor) => visitor.visitLiteralList(this);
2145 } 2149 }
2146 2150
2147 /** 2151 /**
2148 * The primitive array indexing operation. Note that this instruction 2152 * The primitive array indexing operation. Note that this instruction
2149 * does not throw because we generate the checks explicitly. 2153 * does not throw because we generate the checks explicitly.
2150 */ 2154 */
2151 class HIndex extends HInstruction { 2155 class HIndex extends HInstruction {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 HRangeConversion(HInstruction input) : super(<HInstruction>[input]) { 2307 HRangeConversion(HInstruction input) : super(<HInstruction>[input]) {
2304 sourceElement = input.sourceElement; 2308 sourceElement = input.sourceElement;
2305 // We currently only do range analysis for integers. 2309 // We currently only do range analysis for integers.
2306 instructionType = HType.INTEGER; 2310 instructionType = HType.INTEGER;
2307 } 2311 }
2308 accept(HVisitor visitor) => visitor.visitRangeConversion(this); 2312 accept(HVisitor visitor) => visitor.visitRangeConversion(this);
2309 } 2313 }
2310 2314
2311 class HStringConcat extends HInstruction { 2315 class HStringConcat extends HInstruction {
2312 final Node node; 2316 final Node node;
2313 HStringConcat(HInstruction left, HInstruction right, this.node) 2317 HStringConcat(HInstruction left, HInstruction right, this.node, HType type)
2314 : super(<HInstruction>[left, right]) { 2318 : super(<HInstruction>[left, right]) {
2315 // TODO(sra): Until Issue 9293 is fixed, this false dependency keeps the 2319 // TODO(sra): Until Issue 9293 is fixed, this false dependency keeps the
2316 // concats bunched with stringified inputs for much better looking code with 2320 // concats bunched with stringified inputs for much better looking code with
2317 // fewer temps. 2321 // fewer temps.
2318 sideEffects.setDependsOnSomething(); 2322 sideEffects.setDependsOnSomething();
2319 instructionType = HType.STRING; 2323 instructionType = type;
2320 } 2324 }
2321 2325
2322 HInstruction get left => inputs[0]; 2326 HInstruction get left => inputs[0];
2323 HInstruction get right => inputs[1]; 2327 HInstruction get right => inputs[1];
2324 2328
2325 accept(HVisitor visitor) => visitor.visitStringConcat(this); 2329 accept(HVisitor visitor) => visitor.visitStringConcat(this);
2326 toString() => "string concat"; 2330 toString() => "string concat";
2327 } 2331 }
2328 2332
2329 /** 2333 /**
2330 * The part of string interpolation which converts and interpolated expression 2334 * The part of string interpolation which converts and interpolated expression
2331 * into a String value. 2335 * into a String value.
2332 */ 2336 */
2333 class HStringify extends HInstruction { 2337 class HStringify extends HInstruction {
2334 final Node node; 2338 final Node node;
2335 HStringify(HInstruction input, this.node) : super(<HInstruction>[input]) { 2339 HStringify(HInstruction input, this.node, HType type)
2340 : super(<HInstruction>[input]) {
2336 sideEffects.setAllSideEffects(); 2341 sideEffects.setAllSideEffects();
2337 sideEffects.setDependsOnSomething(); 2342 sideEffects.setDependsOnSomething();
2338 instructionType = HType.STRING; 2343 instructionType = type;
2339 } 2344 }
2340 2345
2341 accept(HVisitor visitor) => visitor.visitStringify(this); 2346 accept(HVisitor visitor) => visitor.visitStringify(this);
2342 toString() => "stringify"; 2347 toString() => "stringify";
2343 } 2348 }
2344 2349
2345 /** Non-block-based (aka. traditional) loop information. */ 2350 /** Non-block-based (aka. traditional) loop information. */
2346 class HLoopInformation { 2351 class HLoopInformation {
2347 final HBasicBlock header; 2352 final HBasicBlock header;
2348 final List<HBasicBlock> blocks; 2353 final List<HBasicBlock> blocks;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 HBasicBlock get start => expression.start; 2680 HBasicBlock get start => expression.start;
2676 HBasicBlock get end { 2681 HBasicBlock get end {
2677 // We don't create a switch block if there are no cases. 2682 // We don't create a switch block if there are no cases.
2678 assert(!statements.isEmpty); 2683 assert(!statements.isEmpty);
2679 return statements.last.end; 2684 return statements.last.end;
2680 } 2685 }
2681 2686
2682 bool accept(HStatementInformationVisitor visitor) => 2687 bool accept(HStatementInformationVisitor visitor) =>
2683 visitor.visitSwitchInfo(this); 2688 visitor.visitSwitchInfo(this);
2684 } 2689 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698