Chromium Code Reviews| Index: runtime/vm/flow_graph_optimizer.cc |
| =================================================================== |
| --- runtime/vm/flow_graph_optimizer.cc (revision 36052) |
| +++ runtime/vm/flow_graph_optimizer.cc (working copy) |
| @@ -61,6 +61,24 @@ |
| } |
| +// Optimize instructions that rely on constants. |
| +void FlowGraphOptimizer::ApplyConstants() { |
| + ASSERT(current_iterator_ == NULL); |
| + for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| + BlockEntryInstr* entry = block_order_[i]; |
| + ForwardInstructionIterator it(entry); |
| + current_iterator_ = ⁢ |
| + for (; !it.Done(); it.Advance()) { |
| + Instruction* instr = it.Current(); |
| + if (instr->IsStaticCall()) { |
| + VisitStaticCall(instr->AsStaticCall()); |
| + } |
| + } |
| + current_iterator_ = NULL; |
| + } |
| +} |
| + |
| + |
| // Optimize instance calls using cid. This is called after optimizer |
| // converted instance calls to instructions. Any remaining |
| // instance calls are either megamorphic calls, cannot be optimized or |
| @@ -4228,6 +4246,18 @@ |
| recognized_kind, |
| call->token_pos()); |
| ReplaceCall(call, invoke); |
| + } else if (recognized_kind == MethodRecognizer::kObjectArrayConstructor) { |
| + Value* type = new Value(call->ArgumentAt(0)); |
| + Value* num_elements = new Value(call->ArgumentAt(1)); |
| + if (num_elements->BindsToConstant() && |
| + num_elements->BoundConstant().IsSmi()) { |
|
Florian Schneider
2014/05/13 11:17:32
Why does num_elements need to be constant? CreateA
srdjan
2014/05/13 18:07:18
CreateArrayInstr expects a positive integer. Added
Florian Schneider
2014/05/14 08:23:28
Sorry to be not precise enough: I meant checking f
srdjan
2014/05/14 15:21:02
This code is just the first step for optimized all
|
| + const intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); |
| + if (length >= 0 && length <= Array::kMaxElements) { |
| + CreateArrayInstr* create_array = |
|
Florian Schneider
2014/05/13 11:17:32
How about doing this in the flow graph builder ins
srdjan
2014/05/13 18:07:18
Done.
srdjan
2014/05/13 18:24:44
Actually not done. FlowGraphBuilder is run in unop
|
| + new CreateArrayInstr(call->token_pos(), type, num_elements); |
| + ReplaceCall(call, create_array); |
| + } |
| + } |
| } else if (Library::PrivateCoreLibName(Symbols::ClassId()).Equals( |
| String::Handle(call->function().name()))) { |
| // Check for core library get:_classId. |
| @@ -4239,9 +4269,7 @@ |
| (cid == kImmutableArrayCid) || (cid == kArrayCid)); |
| ConstantInstr* cid_instr = new ConstantInstr(Smi::Handle(Smi::New(cid))); |
| ReplaceCall(call, cid_instr); |
| - } |
| - |
| - if (call->function().IsFactory()) { |
| + } else if (call->function().IsFactory()) { |
| const Class& function_class = Class::Handle(call->function().Owner()); |
| if ((function_class.library() == Library::CoreLibrary()) || |
| (function_class.library() == Library::TypedDataLibrary())) { |