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

Unified Diff: runtime/vm/aot_optimizer.cc

Issue 2273943002: VM: More refactoring of recognized methods inlining. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | runtime/vm/flow_graph.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/aot_optimizer.cc
diff --git a/runtime/vm/aot_optimizer.cc b/runtime/vm/aot_optimizer.cc
index 0fce824983e06c8838e640c7a2d3dd695d7b094f..2dc0be48ad8acfaa668b5c703f871ef0bbf3de88 100644
--- a/runtime/vm/aot_optimizer.cc
+++ b/runtime/vm/aot_optimizer.cc
@@ -1216,28 +1216,6 @@ void AotOptimizer::ReplaceWithMathCFunction(
}
-static bool IsSupportedByteArrayViewCid(intptr_t cid) {
- switch (cid) {
- case kTypedDataInt8ArrayCid:
- case kTypedDataUint8ArrayCid:
- case kExternalTypedDataUint8ArrayCid:
- case kTypedDataUint8ClampedArrayCid:
- case kExternalTypedDataUint8ClampedArrayCid:
- case kTypedDataInt16ArrayCid:
- case kTypedDataUint16ArrayCid:
- case kTypedDataInt32ArrayCid:
- case kTypedDataUint32ArrayCid:
- case kTypedDataFloat32ArrayCid:
- case kTypedDataFloat64ArrayCid:
- case kTypedDataFloat32x4ArrayCid:
- case kTypedDataInt32x4ArrayCid:
- return true;
- default:
- return false;
- }
-}
-
-
// Inline only simple, frequently called core library methods.
bool AotOptimizer::TryInlineInstanceMethod(InstanceCallInstr* call) {
ASSERT(call->HasICData());
@@ -1253,48 +1231,6 @@ bool AotOptimizer::TryInlineInstanceMethod(InstanceCallInstr* call) {
MethodRecognizer::Kind recognized_kind =
MethodRecognizer::RecognizeKind(target);
- if ((recognized_kind == MethodRecognizer::kOneByteStringCodeUnitAt) ||
- (recognized_kind == MethodRecognizer::kTwoByteStringCodeUnitAt) ||
- (recognized_kind == MethodRecognizer::kExternalOneByteStringCodeUnitAt) ||
- (recognized_kind == MethodRecognizer::kExternalTwoByteStringCodeUnitAt) ||
- (recognized_kind == MethodRecognizer::kGrowableArraySetData) ||
- (recognized_kind == MethodRecognizer::kGrowableArraySetLength) ||
- (recognized_kind == MethodRecognizer::kSmi_bitAndFromSmi)) {
- return FlowGraphInliner::TryReplaceInstanceCallWithInline(
- flow_graph_, current_iterator(), call);
- }
-
- if (recognized_kind == MethodRecognizer::kStringBaseCharAt) {
- ASSERT((class_ids[0] == kOneByteStringCid) ||
- (class_ids[0] == kTwoByteStringCid) ||
- (class_ids[0] == kExternalOneByteStringCid) ||
- (class_ids[0] == kExternalTwoByteStringCid));
- return FlowGraphInliner::TryReplaceInstanceCallWithInline(
- flow_graph_, current_iterator(), call);
- }
-
- if (class_ids[0] == kOneByteStringCid) {
- if (recognized_kind == MethodRecognizer::kOneByteStringSetAt) {
- // This is an internal method, no need to check argument types nor
- // range.
- Definition* str = call->ArgumentAt(0);
- Definition* index = call->ArgumentAt(1);
- Definition* value = call->ArgumentAt(2);
- StoreIndexedInstr* store_op = new(Z) StoreIndexedInstr(
- new(Z) Value(str),
- new(Z) Value(index),
- new(Z) Value(value),
- kNoStoreBarrier,
- 1, // Index scale
- kOneByteStringCid,
- call->deopt_id(),
- call->token_pos());
- ReplaceCall(call, store_op);
- return true;
- }
- return false;
- }
-
if (CanUnboxDouble() &&
(recognized_kind == MethodRecognizer::kIntegerToDouble)) {
if (class_ids[0] == kSmiCid) {
@@ -1353,27 +1289,13 @@ bool AotOptimizer::TryInlineInstanceMethod(InstanceCallInstr* call) {
ReplaceCall(call, d2d_instr);
}
return true;
- case MethodRecognizer::kDoubleAdd:
- case MethodRecognizer::kDoubleSub:
- case MethodRecognizer::kDoubleMul:
- case MethodRecognizer::kDoubleDiv:
- return FlowGraphInliner::TryReplaceInstanceCallWithInline(
- flow_graph_, current_iterator(), call);
default:
- // Unsupported method.
- return false;
+ break;
}
}
- if (IsSupportedByteArrayViewCid(class_ids[0]) ||
- (class_ids[0] == kFloat32x4Cid) ||
- (class_ids[0] == kInt32x4Cid) ||
- (class_ids[0] == kFloat64x2Cid)) {
- return FlowGraphInliner::TryReplaceInstanceCallWithInline(
- flow_graph_, current_iterator(), call);
- }
-
- return false;
+ return FlowGraphInliner::TryReplaceInstanceCallWithInline(
+ flow_graph_, current_iterator(), call);
}
@@ -2030,33 +1952,15 @@ void AotOptimizer::VisitInstanceCall(InstanceCallInstr* instr) {
void AotOptimizer::VisitStaticCall(StaticCallInstr* call) {
- if (!CanUnboxDouble()) {
+ if (!IsAllowedForInlining(call->deopt_id())) {
+ // Inlining disabled after a speculative inlining attempt.
return;
}
MethodRecognizer::Kind recognized_kind =
MethodRecognizer::RecognizeKind(call->function());
- MathUnaryInstr::MathUnaryKind unary_kind;
- switch (recognized_kind) {
- case MethodRecognizer::kMathSqrt:
- unary_kind = MathUnaryInstr::kSqrt;
- break;
- case MethodRecognizer::kMathSin:
- unary_kind = MathUnaryInstr::kSin;
- break;
- case MethodRecognizer::kMathCos:
- unary_kind = MathUnaryInstr::kCos;
- break;
- default:
- unary_kind = MathUnaryInstr::kIllegal;
- break;
- }
- if (unary_kind != MathUnaryInstr::kIllegal) {
- ASSERT(FLAG_precompiled_mode);
- // TODO(srdjan): Adapt MathUnaryInstr to allow tagged inputs as well.
- return;
- }
-
switch (recognized_kind) {
+ case MethodRecognizer::kObjectConstructor:
+ case MethodRecognizer::kObjectArrayAllocate:
case MethodRecognizer::kFloat32x4Zero:
case MethodRecognizer::kFloat32x4Splat:
case MethodRecognizer::kFloat32x4Constructor:
@@ -2067,31 +1971,25 @@ void AotOptimizer::VisitStaticCall(StaticCallInstr* call) {
case MethodRecognizer::kFloat64x2FromFloat32x4:
case MethodRecognizer::kInt32x4BoolConstructor:
case MethodRecognizer::kInt32x4Constructor:
- if (!ShouldInlineSimd() || !IsAllowedForInlining(call->deopt_id())) {
- return;
- }
+ case MethodRecognizer::kMathSqrt:
+ case MethodRecognizer::kMathDoublePow:
+ case MethodRecognizer::kMathSin:
+ case MethodRecognizer::kMathCos:
+ case MethodRecognizer::kMathTan:
+ case MethodRecognizer::kMathAsin:
+ case MethodRecognizer::kMathAcos:
+ case MethodRecognizer::kMathAtan:
+ case MethodRecognizer::kMathAtan2:
FlowGraphInliner::TryReplaceStaticCallWithInline(
flow_graph_, current_iterator(), call);
break;
- case MethodRecognizer::kObjectConstructor: {
- // Remove the original push arguments.
- for (intptr_t i = 0; i < call->ArgumentCount(); ++i) {
- PushArgumentInstr* push = call->PushArgumentAt(i);
- push->ReplaceUsesWith(push->value()->definition());
- push->RemoveFromGraph();
- }
- // Manually replace call with global null constant. ReplaceCall can't
- // be used for definitions that are already in the graph.
- call->ReplaceUsesWith(flow_graph_->constant_null());
- ASSERT(current_iterator()->Current() == call);
- current_iterator()->RemoveCurrentFromGraph();
- break;
- }
case MethodRecognizer::kMathMin:
case MethodRecognizer::kMathMax: {
// We can handle only monomorphic min/max call sites with both arguments
// being either doubles or smis.
- if (call->HasICData() && (call->ic_data()->NumberOfChecks() == 1)) {
+ if (CanUnboxDouble() &&
+ call->HasICData() &&
+ (call->ic_data()->NumberOfChecks() == 1)) {
const ICData& ic_data = *call->ic_data();
intptr_t result_cid = kIllegalCid;
if (ICDataHasReceiverArgumentClassIds(ic_data,
@@ -2125,16 +2023,6 @@ void AotOptimizer::VisitStaticCall(StaticCallInstr* call) {
}
break;
}
- case MethodRecognizer::kMathDoublePow:
- case MethodRecognizer::kMathTan:
- case MethodRecognizer::kMathAsin:
- case MethodRecognizer::kMathAcos:
- case MethodRecognizer::kMathAtan:
- case MethodRecognizer::kMathAtan2: {
- ASSERT(FLAG_precompiled_mode);
- // No UnboxDouble instructions allowed.
- return;
- }
case MethodRecognizer::kDoubleFromInteger: {
if (call->HasICData() && (call->ic_data()->NumberOfChecks() == 1)) {
const ICData& ic_data = *call->ic_data();
@@ -2156,35 +2044,8 @@ void AotOptimizer::VisitStaticCall(StaticCallInstr* call) {
}
break;
}
- default: {
- if (call->function().IsFactory()) {
- const Class& function_class =
- Class::Handle(Z, call->function().Owner());
- if ((function_class.library() == Library::CoreLibrary()) ||
- (function_class.library() == Library::TypedDataLibrary())) {
- intptr_t cid = FactoryRecognizer::ResultCid(call->function());
- switch (cid) {
- case kArrayCid: {
- Value* type = new(Z) Value(call->ArgumentAt(0));
- Value* num_elements = new(Z) Value(call->ArgumentAt(1));
- if (num_elements->BindsToConstant() &&
- num_elements->BoundConstant().IsSmi()) {
- intptr_t length =
- Smi::Cast(num_elements->BoundConstant()).Value();
- if (length >= 0 && length <= Array::kMaxElements) {
- CreateArrayInstr* create_array =
- new(Z) CreateArrayInstr(
- call->token_pos(), type, num_elements);
- ReplaceCall(call, create_array);
- }
- }
- }
- default:
- break;
- }
- }
- }
- }
+ default:
+ break;
}
}
« no previous file with comments | « no previous file | runtime/vm/flow_graph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698