From 790b9d9cb153e9958715e07c1d34546fb68e6dc7 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Fri, 14 Oct 2016 17:34:07 -0700 Subject: [PATCH] Enable GVN on HForeignNew R=sigmund@google.com Review URL: https://codereview.chromium.org/2422003002 . --- pkg/compiler/lib/src/ssa/nodes.dart | 13 ++++++++++++- sdk/lib/_internal/js_runtime/lib/js_number.dart | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/compiler/lib/src/ssa/nodes.dart b/pkg/compiler/lib/src/ssa/nodes.dart index 64e12387c58..1b06943251b 100644 --- a/pkg/compiler/lib/src/ssa/nodes.dart +++ b/pkg/compiler/lib/src/ssa/nodes.dart @@ -873,6 +873,8 @@ abstract class HInstruction implements Spannable { static const int TYPE_INFO_READ_VARIABLE_TYPECODE = 39; static const int TYPE_INFO_EXPRESSION_TYPECODE = 40; + static const int FOREIGN_CODE_TYPECODE = 41; + HInstruction(this.inputs, this.instructionType) : id = idCounter++, usedBy = [] { @@ -1901,6 +1903,9 @@ class HForeignCode extends HForeign { assert(this.throwBehavior != null); if (effects != null) sideEffects.add(effects); + if (nativeBehavior != null && nativeBehavior.useGvn) { + setUseGvn(); + } } HForeignCode.statement(js.Template codeTemplate, List inputs, @@ -1927,7 +1932,13 @@ class HForeignCode extends HForeign { bool get isAllocation => nativeBehavior != null && nativeBehavior.isAllocation && !canBeNull(); - String toString() => 'HForeignCode("${codeTemplate.source}",$inputs)'; + int typeCode() => HInstruction.FOREIGN_CODE_TYPECODE; + bool typeEquals(other) => other is HForeignCode; + bool dataEquals(HForeignCode other) { + return codeTemplate.source == other.codeTemplate.source; + } + + String toString() => 'HForeignCode("${codeTemplate.source}", $inputs)'; } abstract class HInvokeBinary extends HInstruction { diff --git a/sdk/lib/_internal/js_runtime/lib/js_number.dart b/sdk/lib/_internal/js_runtime/lib/js_number.dart index 1f9748c6bdb..7513b1e93c5 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_number.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_number.dart @@ -56,7 +56,7 @@ class JSNumber extends Interceptor implements num { return JS('num', r'# % #', this, b); } - num abs() => JS('returns:num;effects:none;depends:none;throws:never', + num abs() => JS('returns:num;effects:none;depends:none;throws:never;gvn:true', r'Math.abs(#)', this); num get sign => this > 0 ? 1 : this < 0 ? -1 : this;