Index: src/code-stubs-hydrogen.cc |
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc |
index 6bb011829c04e7b07b993e9c56442ce37a2d13a1..4068197bd3d66bb3a2b0fbdf4be71d43960b8418 100644 |
--- a/src/code-stubs-hydrogen.cc |
+++ b/src/code-stubs-hydrogen.cc |
@@ -99,8 +99,12 @@ class CodeStubGraphBuilderBase : public HGraphBuilder { |
ArgumentClass argument_class); |
void BuildInstallOptimizedCode(HValue* js_function, HValue* native_context, |
- HValue* code_object); |
+ HValue* code_object, HValue* literals); |
void BuildInstallCode(HValue* js_function, HValue* shared_info); |
+ |
+ HInstruction* LoadFromOptimizedCodeMap(HValue* optimized_map, |
+ HValue* iterator, |
+ int field_offset); |
void BuildInstallFromOptimizedCodeMap(HValue* js_function, |
HValue* shared_info, |
HValue* native_context); |
@@ -1128,7 +1132,8 @@ Handle<Code> ElementsTransitionAndStoreStub::GenerateCode(Isolate* isolate) { |
void CodeStubGraphBuilderBase::BuildInstallOptimizedCode( |
HValue* js_function, |
HValue* native_context, |
- HValue* code_object) { |
+ HValue* code_object, |
+ HValue* literals) { |
Counters* counters = isolate()->counters(); |
AddIncrementCounter(counters->fast_new_closure_install_optimized()); |
@@ -1136,6 +1141,8 @@ void CodeStubGraphBuilderBase::BuildInstallOptimizedCode( |
// map and either unmangle them on marking or do nothing as the whole map is |
// discarded on major GC anyway. |
Add<HStoreCodeEntry>(js_function, code_object); |
+ Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(), |
+ literals); |
// Now link a function into a list of optimized functions. |
HValue* optimized_functions_list = Add<HLoadNamedField>( |
@@ -1163,6 +1170,24 @@ void CodeStubGraphBuilderBase::BuildInstallCode(HValue* js_function, |
} |
+HInstruction* CodeStubGraphBuilderBase::LoadFromOptimizedCodeMap( |
+ HValue* optimized_map, |
+ HValue* iterator, |
+ int field_offset) { |
+ // By making sure to express these loads in the form [<hvalue> + constant] |
+ // the keyed load can be hoisted. |
+ ASSERT(field_offset >= 0 && field_offset < SharedFunctionInfo::kEntryLength); |
+ HValue* field_slot = iterator; |
+ if (field_offset > 0) { |
+ HValue* field_offset_value = Add<HConstant>(field_offset); |
+ field_slot = AddUncasted<HAdd>(iterator, field_offset_value); |
+ } |
+ HInstruction* field_entry = Add<HLoadKeyed>(optimized_map, field_slot, |
+ static_cast<HValue*>(NULL), FAST_ELEMENTS); |
+ return field_entry; |
+} |
+ |
+ |
void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( |
HValue* js_function, |
HValue* shared_info, |
@@ -1202,49 +1227,54 @@ void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( |
HValue* code_object = Add<HLoadNamedField>( |
optimized_map, static_cast<HValue*>(NULL), |
HObjectAccess::ForFirstCodeSlot()); |
- BuildInstallOptimizedCode(js_function, native_context, code_object); |
+ HValue* literals = Add<HLoadNamedField>( |
+ optimized_map, static_cast<HValue*>(NULL), |
+ HObjectAccess::ForFirstLiteralsSlot()); |
+ BuildInstallOptimizedCode(js_function, native_context, code_object, |
+ literals); |
} |
already_in.Else(); |
{ |
- HValue* shared_function_entry_length = |
- Add<HConstant>(SharedFunctionInfo::kEntryLength); |
- LoopBuilder loop_builder(this, |
- context(), |
- LoopBuilder::kPostDecrement, |
- shared_function_entry_length); |
HValue* array_length = Add<HLoadNamedField>( |
optimized_map, static_cast<HValue*>(NULL), |
HObjectAccess::ForFixedArrayLength()); |
- HValue* slot_iterator = loop_builder.BeginBody(array_length, |
- graph()->GetConstant0(), |
- Token::GT); |
+ IfBuilder store_unoptimized(this); |
+ store_unoptimized.If<HCompareNumericAndBranch>( |
+ array_length, Add<HConstant>(SharedFunctionInfo::kInitialLength), |
+ Token::EQ); |
+ store_unoptimized.Then(); |
+ { |
+ // Store the unoptimized code |
+ BuildInstallCode(js_function, shared_info); |
+ } |
+ store_unoptimized.Else(); |
{ |
// Iterate through the rest of map backwards. |
// Do not double check first entry. |
+ // for(i = map.length() - kEntryLength; |
+ // i >= kSecondEntryIndex; |
+ // i -= kEntryLength) { .. } |
+ |
+ HValue* shared_function_entry_length = |
+ Add<HConstant>(SharedFunctionInfo::kEntryLength); |
+ LoopBuilder loop_builder(this, |
+ context(), |
+ LoopBuilder::kPostDecrement, |
+ shared_function_entry_length); |
+ HValue* start_pos = AddUncasted<HSub>(array_length, |
+ shared_function_entry_length); |
HValue* second_entry_index = |
Add<HConstant>(SharedFunctionInfo::kSecondEntryIndex); |
- IfBuilder restore_check(this); |
- restore_check.If<HCompareNumericAndBranch>( |
- slot_iterator, second_entry_index, Token::EQ); |
- restore_check.Then(); |
- { |
- // Store the unoptimized code |
- BuildInstallCode(js_function, shared_info); |
- loop_builder.Break(); |
- } |
- restore_check.Else(); |
+ HValue* slot_iterator = loop_builder.BeginBody(start_pos, |
+ second_entry_index, |
+ Token::GTE); |
{ |
- STATIC_ASSERT(SharedFunctionInfo::kContextOffset == 0); |
- STATIC_ASSERT(SharedFunctionInfo::kEntryLength - |
- SharedFunctionInfo::kOsrAstIdOffset == 1); |
- HValue* native_context_slot = AddUncasted<HSub>( |
- slot_iterator, shared_function_entry_length); |
- HValue* osr_ast_id_slot = AddUncasted<HSub>( |
- slot_iterator, graph()->GetConstant1()); |
- HInstruction* native_context_entry = Add<HLoadKeyed>(optimized_map, |
- native_context_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); |
- HInstruction* osr_ast_id_entry = Add<HLoadKeyed>(optimized_map, |
- osr_ast_id_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); |
+ // slot iterator is pointing behind the record we want to examine. |
Yang
2014/03/03 08:27:02
This comment seems not to match the code...
if the
mvstanton
2014/03/03 09:35:52
Right, the comment was old. I changed the loop ite
|
+ HInstruction* native_context_entry = LoadFromOptimizedCodeMap( |
+ optimized_map, slot_iterator, SharedFunctionInfo::kContextOffset); |
+ HInstruction* osr_ast_id_entry = LoadFromOptimizedCodeMap( |
+ optimized_map, slot_iterator, |
+ SharedFunctionInfo::kOsrAstIdOffset); |
IfBuilder done_check(this); |
done_check.If<HCompareObjectEqAndBranch>(native_context, |
native_context_entry); |
@@ -1253,21 +1283,22 @@ void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( |
done_check.Then(); |
{ |
// Hit: fetch the optimized code. |
- HValue* code_slot = AddUncasted<HAdd>( |
- native_context_slot, graph()->GetConstant1()); |
- HValue* code_object = Add<HLoadKeyed>(optimized_map, |
- code_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); |
- BuildInstallOptimizedCode(js_function, native_context, code_object); |
+ HValue* code_object = LoadFromOptimizedCodeMap(optimized_map, |
+ slot_iterator, SharedFunctionInfo::kCachedCodeOffset); |
+ // and the literals |
+ HValue* literals = LoadFromOptimizedCodeMap(optimized_map, |
+ slot_iterator, SharedFunctionInfo::kLiteralsOffset); |
+ BuildInstallOptimizedCode(js_function, native_context, code_object, |
+ literals); |
// Fall out of the loop |
loop_builder.Break(); |
} |
- done_check.Else(); |
done_check.End(); |
} |
- restore_check.End(); |
+ loop_builder.EndBody(); |
} |
- loop_builder.EndBody(); |
+ store_unoptimized.End(); |
} |
already_in.End(); |
} |