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

Unified Diff: pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart

Issue 2400853003: dart2js: Constant fold num.round() (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart
diff --git a/pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart b/pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart
index 463c31cfcd2009aff40c5abe25a0efda59d616c4..8bcca400dc94960fa7d885c62b801651f2c6362b 100644
--- a/pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart
+++ b/pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart
@@ -34,6 +34,12 @@ class InvokeDynamicSpecializer {
return null;
}
+ void clearAllSideEffects(HInstruction instruction) {
+ instruction.sideEffects.clearAllSideEffects();
+ instruction.sideEffects.clearAllDependencies();
+ instruction.setUseGvn();
+ }
+
Operation operation(ConstantSystem constantSystem) => null;
static InvokeDynamicSpecializer lookupSpecializer(Selector selector) {
@@ -85,6 +91,11 @@ class InvokeDynamicSpecializer {
return const CodeUnitAtSpecializer();
}
}
+ if (selector.argumentCount == 0 && selector.namedArguments.length == 0) {
+ if (selector.name == 'round') {
+ return const RoundSpecializer();
+ }
+ }
}
return const InvokeDynamicSpecializer();
}
@@ -219,12 +230,6 @@ abstract class BinaryArithmeticSpecializer extends InvokeDynamicSpecializer {
return null;
}
- void clearAllSideEffects(HInstruction instruction) {
- instruction.sideEffects.clearAllSideEffects();
- instruction.sideEffects.clearAllDependencies();
- instruction.setUseGvn();
- }
-
bool inputsArePositiveIntegers(HInstruction instruction, Compiler compiler) {
HInstruction left = instruction.inputs[1];
HInstruction right = instruction.inputs[2];
@@ -759,3 +764,22 @@ class CodeUnitAtSpecializer extends InvokeDynamicSpecializer {
return null;
}
}
+
+class RoundSpecializer extends InvokeDynamicSpecializer {
+ const RoundSpecializer();
+
+ UnaryOperation operation(ConstantSystem constantSystem) {
+ return constantSystem.round;
+ }
+
+ HInstruction tryConvertToBuiltin(
+ HInvokeDynamic instruction, Compiler compiler) {
+ HInstruction receiver = instruction.getDartReceiver(compiler);
+ if (receiver.isNumberOrNull(compiler)) {
+ // Even if there is no builtin equivalent instruction, we know the
+ // instruction does not have any side effect, and that it can be GVN'ed.
+ clearAllSideEffects(instruction);
+ }
+ return null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698