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

Side by Side Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 2294123003: Revert "Fold HTypeInfoReadVariable of instance creation." (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/27198_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import '../common/codegen.dart' show CodegenWorkItem; 5 import '../common/codegen.dart' show CodegenWorkItem;
6 import '../common/tasks.dart' show CompilerTask; 6 import '../common/tasks.dart' show CompilerTask;
7 import '../compiler.dart' show Compiler; 7 import '../compiler.dart' show Compiler;
8 import '../constants/constant_system.dart'; 8 import '../constants/constant_system.dart';
9 import '../constants/values.dart'; 9 import '../constants/values.dart';
10 import '../core_types.dart' show CoreClasses; 10 import '../core_types.dart' show CoreClasses;
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 HInstruction replacement = new HTypeInfoExpression( 1050 HInstruction replacement = new HTypeInfoExpression(
1051 TypeInfoExpressionKind.COMPLETE, 1051 TypeInfoExpressionKind.COMPLETE,
1052 typeArgument, 1052 typeArgument,
1053 const <HInstruction>[], 1053 const <HInstruction>[],
1054 backend.dynamicType); 1054 backend.dynamicType);
1055 return replacement; 1055 return replacement;
1056 } 1056 }
1057 return node; 1057 return node;
1058 } 1058 }
1059 1059
1060 /// Read the type variable from an allocation of type [createdClass], where
1061 /// [selectTypeArgumentFromObjectCreation] extracts the type argument from
1062 /// the allocation for factory constructor call.
1063 HInstruction finishSubstituted(ClassElement createdClass,
1064 HInstruction selectTypeArgumentFromObjectCreation(int index)) {
1065 HInstruction instructionForTypeVariable(TypeVariableType tv) {
1066 return selectTypeArgumentFromObjectCreation(
1067 createdClass.thisType.typeArguments.indexOf(tv));
1068 }
1069
1070 DartType type = createdClass.thisType
1071 .asInstanceOf(variable.element.enclosingClass)
1072 .typeArguments[variable.element.index];
1073 if (type is TypeVariableType) {
1074 return instructionForTypeVariable(type);
1075 }
1076 List<HInstruction> arguments = <HInstruction>[];
1077 type.forEachTypeVariable((v) {
1078 arguments.add(instructionForTypeVariable(v));
1079 });
1080 HInstruction replacement = new HTypeInfoExpression(
1081 TypeInfoExpressionKind.COMPLETE,
1082 type,
1083 arguments,
1084 backend.dynamicType);
1085 return replacement;
1086 }
1087
1088 // Type variable evaluated in the context of a constant can be replaced with 1060 // Type variable evaluated in the context of a constant can be replaced with
1089 // a ground term type. 1061 // a ground term type.
1090 if (object is HConstant) { 1062 if (object is HConstant) {
1091 ConstantValue value = object.constant; 1063 ConstantValue value = object.constant;
1092 if (value is ConstructedConstantValue) { 1064 if (value is ConstructedConstantValue) {
1093 return finishGroundType(value.type); 1065 return finishGroundType(value.type);
1094 } 1066 }
1095 return node; 1067 return node;
1096 } 1068 }
1097 1069
1098 // Look for an allocation with type information and re-write type variable 1070 // TODO(sra): HTypeInfoReadVariable on an instance creation can be replaced
1099 // as a function of the type parameters of the allocation. This effectively 1071 // with an input of the instance creation's HTypeInfoExpression (or a
1100 // store-forwards a type variable read through an allocation. 1072 // HTypeInfoExpression of an input). This would in effect store-forward the
1101 1073 // type parameters.
1102 // Match:
1103 //
1104 // setRuntimeTypeInfo(
1105 // HForeignNew(ClassElement),
1106 // HTypeInfoExpression(t_0, t_1, t_2, ...));
1107 //
1108 // The `t_i` are the values of the type parameters of ClassElement.
1109 if (object is HInvokeStatic) {
1110 if (object.element == helpers.setRuntimeTypeInfo) {
1111 HInstruction allocation = object.inputs[0];
1112 if (allocation is HForeignNew) {
1113 HInstruction typeInfo = object.inputs[1];
1114 if (typeInfo is HTypeInfoExpression) {
1115 return finishSubstituted(
1116 allocation.element, (int index) => typeInfo.inputs[index]);
1117 }
1118 }
1119 return node;
1120 }
1121 // TODO(sra): Factory constructors pass type arguments after the value
1122 // arguments. The [select] argument indexes into these type arguments.
1123 }
1124
1125 // Non-generic type (which extends or mixes in a generic type, for example
1126 // CodeUnits extends UnmodifiableListBase<int>).
1127 // Also used for raw-type when the type parameters are elided.
1128 if (object is HForeignNew) {
1129 return finishSubstituted(
1130 object.element,
1131 // If there are type arguments, all type arguments are 'dynamic'.
1132 (int i) => graph.addConstantNull(compiler));
1133 }
1134 1074
1135 return node; 1075 return node;
1136 } 1076 }
1137 } 1077 }
1138 1078
1139 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { 1079 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
1140 final Set<HInstruction> boundsChecked; 1080 final Set<HInstruction> boundsChecked;
1141 final CodegenWorkItem work; 1081 final CodegenWorkItem work;
1142 final bool trustPrimitives; 1082 final bool trustPrimitives;
1143 final JavaScriptBackend backend; 1083 final JavaScriptBackend backend;
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2465
2526 keyedValues.forEach((receiver, values) { 2466 keyedValues.forEach((receiver, values) {
2527 result.keyedValues[receiver] = 2467 result.keyedValues[receiver] =
2528 new Map<HInstruction, HInstruction>.from(values); 2468 new Map<HInstruction, HInstruction>.from(values);
2529 }); 2469 });
2530 2470
2531 result.nonEscapingReceivers.addAll(nonEscapingReceivers); 2471 result.nonEscapingReceivers.addAll(nonEscapingReceivers);
2532 return result; 2472 return result;
2533 } 2473 }
2534 } 2474 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/27198_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698