ebd13e891f
dart --use-bytecode-compiler NavierStokes.dart Before: NavierStokes(RunTime): 8909.053017777778 us. After: NavierStokes(RunTime): 7221.510314079423 us. Issue: https://github.com/dart-lang/sdk/issues/36429 Issue: https://github.com/dart-lang/sdk/issues/36428 Change-Id: Ib1be4dd20cdc25e3b979a91a098f67a7bc00df8a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98945 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Régis Crelier <regis@google.com>
81 lines
2.1 KiB
Dart
81 lines
2.1 KiB
Dart
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library vm.bytecode.recognized_methods;
|
|
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/type_environment.dart' show TypeEnvironment;
|
|
|
|
import 'dbc.dart';
|
|
import 'generics.dart' show getStaticType;
|
|
|
|
class RecognizedMethods {
|
|
static const binaryIntOps = <String, Opcode>{
|
|
'+': Opcode.kAddInt,
|
|
'-': Opcode.kSubInt,
|
|
'*': Opcode.kMulInt,
|
|
'~/': Opcode.kTruncDivInt,
|
|
'%': Opcode.kModInt,
|
|
'&': Opcode.kBitAndInt,
|
|
'|': Opcode.kBitOrInt,
|
|
'^': Opcode.kBitXorInt,
|
|
'<<': Opcode.kShlInt,
|
|
'>>': Opcode.kShrInt,
|
|
'==': Opcode.kCompareIntEq,
|
|
'>': Opcode.kCompareIntGt,
|
|
'<': Opcode.kCompareIntLt,
|
|
'>=': Opcode.kCompareIntGe,
|
|
'<=': Opcode.kCompareIntLe,
|
|
};
|
|
|
|
final TypeEnvironment typeEnv;
|
|
|
|
RecognizedMethods(this.typeEnv);
|
|
|
|
DartType staticType(Expression expr) => getStaticType(expr, typeEnv);
|
|
|
|
bool isInt(Expression expr) => staticType(expr) == typeEnv.intType;
|
|
|
|
Opcode specializedBytecodeFor(MethodInvocation node) {
|
|
final args = node.arguments;
|
|
if (!args.named.isEmpty) {
|
|
return null;
|
|
}
|
|
|
|
final Expression receiver = node.receiver;
|
|
final String selector = node.name.name;
|
|
|
|
switch (args.positional.length) {
|
|
case 0:
|
|
return specializedBytecodeForUnaryOp(selector, receiver);
|
|
case 1:
|
|
return specializedBytecodeForBinaryOp(
|
|
selector, receiver, args.positional.single);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Opcode specializedBytecodeForUnaryOp(String selector, Expression arg) {
|
|
if (selector == 'unary-' && isInt(arg)) {
|
|
return Opcode.kNegateInt;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
Opcode specializedBytecodeForBinaryOp(
|
|
String selector, Expression a, Expression b) {
|
|
if (selector == '==' && (a is NullLiteral || b is NullLiteral)) {
|
|
return Opcode.kEqualsNull;
|
|
}
|
|
|
|
if (isInt(a) && isInt(b)) {
|
|
return binaryIntOps[selector];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|