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

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

Issue 1376603003: dart2js: improve ssa utilization of bool value types (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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 OptimizationPhase { 7 abstract class OptimizationPhase {
8 String get name; 8 String get name;
9 void visitGraph(HGraph graph); 9 void visitGraph(HGraph graph);
10 } 10 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 block.remove(instruction); 193 block.remove(instruction);
194 } 194 }
195 instruction = next; 195 instruction = next;
196 } 196 }
197 } 197 }
198 198
199 HInstruction visitInstruction(HInstruction node) { 199 HInstruction visitInstruction(HInstruction node) {
200 return node; 200 return node;
201 } 201 }
202 202
203 void replaceUsesWithConstant(HInstruction known) {
204 if (known.isValue() && !known.canBeNull()) {
205 ValueTypeMask valueMask = known.instructionType;
206 if (valueMask.value.isBool) {
207 bool knownValue = valueMask.value.isTrue;
208 var users = new List.from(known.usedBy);
209 users.forEach((HInstruction user) {
sra1 2015/09/30 16:49:39 maybe just write: for (HInstruction user in known
Harry Terkelsen 2015/09/30 18:39:26 Done.
210 user.changeUse(known, graph.addConstantBool(knownValue, compiler));
sra1 2015/09/30 16:49:39 Factor this into (1) finding the HConstant (if any
Harry Terkelsen 2015/09/30 18:39:26 Done.
211 });
212 }
213 }
214 }
215
216 HInstruction visitParameterValue(HParameterValue node) {
217 replaceUsesWithConstant(node);
sra1 2015/09/30 16:49:40 Reading this I ask 'why'? Maybe call it propagateC
Harry Terkelsen 2015/09/30 18:39:26 Done.
218 return node;
219 }
220
203 HInstruction visitBoolify(HBoolify node) { 221 HInstruction visitBoolify(HBoolify node) {
204 List<HInstruction> inputs = node.inputs; 222 List<HInstruction> inputs = node.inputs;
205 assert(inputs.length == 1); 223 assert(inputs.length == 1);
206 HInstruction input = inputs[0]; 224 HInstruction input = inputs[0];
207 if (input.isBoolean(compiler)) return input; 225 if (input.isBoolean(compiler)) return input;
208 226
209 // If the code is unreachable, remove the HBoolify. This can happen when 227 // If the code is unreachable, remove the HBoolify. This can happen when
210 // there is a throw expression in a short-circuit conditional. Removing the 228 // there is a throw expression in a short-circuit conditional. Removing the
211 // unreachable HBoolify makes it easier to reconstruct the short-circuit 229 // unreachable HBoolify makes it easier to reconstruct the short-circuit
212 // operation. 230 // operation.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // TODO(ngeoffray): If the method has optional parameters, 413 // TODO(ngeoffray): If the method has optional parameters,
396 // we should pass the default values. 414 // we should pass the default values.
397 FunctionSignature parameters = method.functionSignature; 415 FunctionSignature parameters = method.functionSignature;
398 if (parameters.optionalParameterCount == 0 || 416 if (parameters.optionalParameterCount == 0 ||
399 parameters.parameterCount == 417 parameters.parameterCount ==
400 node.selector.argumentCount) { 418 node.selector.argumentCount) {
401 node.element = element; 419 node.element = element;
402 } 420 }
403 } 421 }
404 } 422 }
423 replaceUsesWithConstant(node);
sra1 2015/09/30 16:49:40 Any reason not to do this first? It might require
Harry Terkelsen 2015/09/30 18:39:26 Done.
405 return node; 424 return node;
406 } 425 }
407 426
408 HInstruction tryInlineNativeMethod(HInvokeDynamicMethod node, 427 HInstruction tryInlineNativeMethod(HInvokeDynamicMethod node,
409 FunctionElement method) { 428 FunctionElement method) {
410 // Enable direct calls to a native method only if we don't run in checked 429 // Enable direct calls to a native method only if we don't run in checked
411 // mode, where the Dart version may have type annotations on parameters and 430 // mode, where the Dart version may have type annotations on parameters and
412 // return type that it should check. 431 // return type that it should check.
413 // Also check that the parameters are not functions: it's the callee that 432 // Also check that the parameters are not functions: it's the callee that
414 // will translate them to JS functions. 433 // will translate them to JS functions.
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 823 }
805 return node; 824 return node;
806 } 825 }
807 826
808 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { 827 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) {
809 if (node.isInterceptedCall) { 828 if (node.isInterceptedCall) {
810 HInstruction folded = handleInterceptedCall(node); 829 HInstruction folded = handleInterceptedCall(node);
811 if (folded != node) return folded; 830 if (folded != node) return folded;
812 } 831 }
813 HInstruction receiver = node.getDartReceiver(compiler); 832 HInstruction receiver = node.getDartReceiver(compiler);
833 replaceUsesWithConstant(node);
sra1 2015/09/30 16:49:39 Any reason not to do this first? We might know we
Harry Terkelsen 2015/09/30 18:39:26 Done.
814 Element field = findConcreteFieldForDynamicAccess( 834 Element field = findConcreteFieldForDynamicAccess(
815 receiver, node.selector); 835 receiver, node.selector);
816 if (field == null) return node; 836 if (field == null) return node;
817 return directFieldGet(receiver, field); 837 return directFieldGet(receiver, field);
818 } 838 }
819 839
820 HInstruction directFieldGet(HInstruction receiver, Element field) { 840 HInstruction directFieldGet(HInstruction receiver, Element field) {
821 bool isAssignable = !compiler.world.fieldNeverChanges(field); 841 bool isAssignable = !compiler.world.fieldNeverChanges(field);
822 842
823 TypeMask type; 843 TypeMask type;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 HTypeConversion.CHECKED_MODE_CHECK); 880 HTypeConversion.CHECKED_MODE_CHECK);
861 if (other != value) { 881 if (other != value) {
862 node.block.addBefore(node, other); 882 node.block.addBefore(node, other);
863 value = other; 883 value = other;
864 } 884 }
865 } 885 }
866 return new HFieldSet(field, receiver, value); 886 return new HFieldSet(field, receiver, value);
867 } 887 }
868 888
869 HInstruction visitInvokeStatic(HInvokeStatic node) { 889 HInstruction visitInvokeStatic(HInvokeStatic node) {
890 replaceUsesWithConstant(node);
870 if (node.element == backend.getCheckConcurrentModificationError()) { 891 if (node.element == backend.getCheckConcurrentModificationError()) {
871 if (node.inputs.length == 2) { 892 if (node.inputs.length == 2) {
872 HInstruction firstArgument = node.inputs[0]; 893 HInstruction firstArgument = node.inputs[0];
873 if (firstArgument is HConstant) { 894 if (firstArgument is HConstant) {
874 HConstant constant = firstArgument; 895 HConstant constant = firstArgument;
875 if (constant.constant.isTrue) return constant; 896 if (constant.constant.isTrue) return constant;
876 } 897 }
877 } 898 }
878 } 899 }
879 return node; 900 return node;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 } 1320 }
1300 1321
1301 void visitIf(HIf instruction) { 1322 void visitIf(HIf instruction) {
1302 HInstruction condition = instruction.condition; 1323 HInstruction condition = instruction.condition;
1303 if (condition.isConstant()) { 1324 if (condition.isConstant()) {
1304 if (condition.isConstantTrue()) { 1325 if (condition.isConstantTrue()) {
1305 markBlockLive(instruction.thenBlock); 1326 markBlockLive(instruction.thenBlock);
1306 } else { 1327 } else {
1307 markBlockLive(instruction.elseBlock); 1328 markBlockLive(instruction.elseBlock);
1308 } 1329 }
1309 } else if (condition.isValue()) {
1310 ValueTypeMask valueType = condition.instructionType;
1311 if (valueType.value == true) {
1312 markBlockLive(instruction.thenBlock);
1313 } else {
1314 markBlockLive(instruction.elseBlock);
1315 }
1316 } else { 1330 } else {
1317 visitControlFlow(instruction); 1331 visitControlFlow(instruction);
1318 } 1332 }
1319 } 1333 }
1320 1334
1321 void visitSwitch(HSwitch node) { 1335 void visitSwitch(HSwitch node) {
1322 if (node.expression.isInteger(compiler)) { 1336 if (node.expression.isInteger(compiler)) {
1323 Range switchRange = ranges[node.expression]; 1337 Range switchRange = ranges[node.expression];
1324 if (switchRange != null && 1338 if (switchRange != null &&
1325 switchRange.lower is IntValue && 1339 switchRange.lower is IntValue &&
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 2373
2360 keyedValues.forEach((receiver, values) { 2374 keyedValues.forEach((receiver, values) {
2361 result.keyedValues[receiver] = 2375 result.keyedValues[receiver] =
2362 new Map<HInstruction, HInstruction>.from(values); 2376 new Map<HInstruction, HInstruction>.from(values);
2363 }); 2377 });
2364 2378
2365 result.nonEscapingReceivers.addAll(nonEscapingReceivers); 2379 result.nonEscapingReceivers.addAll(nonEscapingReceivers);
2366 return result; 2380 return result;
2367 } 2381 }
2368 } 2382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698