| Index: runtime/vm/flow_graph_optimizer.cc
|
| ===================================================================
|
| --- runtime/vm/flow_graph_optimizer.cc (revision 30910)
|
| +++ runtime/vm/flow_graph_optimizer.cc (working copy)
|
| @@ -62,7 +62,9 @@
|
| }
|
|
|
|
|
| -// Optimize instance calls using cid.
|
| +// Optimize instance calls using cid. This is called after the optimizer which
|
| +// converts instance calls to instructions has been run. Any remaining
|
| +// instance calls probably do not have IC data.
|
| // Attempts to convert an instance call (IC call) using propagated class-ids,
|
| // e.g., receiver class id, guarded-cid.
|
| void FlowGraphOptimizer::ApplyClassIds() {
|
| @@ -96,12 +98,18 @@
|
| }
|
|
|
|
|
| +// TODO(srdjan): write tests for others.
|
| +static bool IsNumberCid(intptr_t cid) {
|
| + return (cid == kSmiCid) || (cid == kDoubleCid);
|
| +}
|
| +
|
| +
|
| // Attempt to build ICData for call using propagated class-ids.
|
| bool FlowGraphOptimizer::TryCreateICData(InstanceCallInstr* call) {
|
| ASSERT(call->HasICData());
|
| if (call->ic_data()->NumberOfChecks() > 0) {
|
| - // This occurs when an instance call has too many checks.
|
| - // TODO(srdjan): Replace IC call with megamorphic call.
|
| + // This occurs when an instance call has too many checks, will be
|
| + // converted to megamorphic calls.
|
| return false;
|
| }
|
| GrowableArray<intptr_t> class_ids(call->ic_data()->num_args_tested());
|
| @@ -110,8 +118,28 @@
|
| intptr_t cid = call->PushArgumentAt(i)->value()->Type()->ToCid();
|
| class_ids.Add(cid);
|
| }
|
| - // TODO(srdjan): Test for number of arguments checked greater than 1.
|
| - if (class_ids.length() != 1) {
|
| + // Only one or two checked arguments are handled at the moment.
|
| + if (class_ids.length() == 2) {
|
| + // We guess that comparison and binary operations typically
|
| + // have both arguments of the same cid. If only one argument's cid is known,
|
| + // assume the other argument has the same cid.
|
| + const Token::Kind op_kind = call->token_kind();
|
| + if (!Token::IsRelationalOperator(op_kind) &&
|
| + !Token::IsEqualityOperator(op_kind) &&
|
| + !Token::IsBinaryOperator(op_kind)) {
|
| + return false;
|
| + }
|
| + // If left or right is a number -> make the other .
|
| + const intptr_t cid_0 = class_ids[0];
|
| + const intptr_t cid_1 = class_ids[1];
|
| + if ((cid_0 == kDynamicCid) && (IsNumberCid(cid_1))) {
|
| + class_ids[0] = cid_1;
|
| + } else if (IsNumberCid(cid_0) && (cid_1 == kDynamicCid)) {
|
| + class_ids[1] = cid_0;
|
| + } else {
|
| + return false;
|
| + }
|
| + } else if (class_ids.length() != 1) {
|
| return false;
|
| }
|
| if (class_ids[0] != kDynamicCid) {
|
| @@ -128,17 +156,17 @@
|
| if (function.IsNull()) {
|
| return false;
|
| }
|
| - // Create new ICData, do not modify the one attached to the instruction
|
| - // since it is attached to the assembly instruction itself.
|
| - // TODO(srdjan): Prevent modification of ICData object that is
|
| - // referenced in assembly code.
|
| ICData& ic_data = ICData::ZoneHandle(ICData::New(
|
| flow_graph_->parsed_function().function(),
|
| call->function_name(),
|
| Object::empty_array(), // Dummy argument descriptor.
|
| call->deopt_id(),
|
| class_ids.length()));
|
| - ic_data.AddReceiverCheck(class_ids[0], function);
|
| + if (class_ids.length() == 1) {
|
| + ic_data.AddReceiverCheck(class_ids[0], function);
|
| + } else {
|
| + ic_data.AddCheck(class_ids, function);
|
| + }
|
| call->set_ic_data(&ic_data);
|
| return true;
|
| }
|
|
|