From 33682c6b349deb25ba46c6da2e2955c3e5a9d4e9 Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Thu, 10 Nov 2011 12:32:39 +0000 Subject: [PATCH] Implement inline runtime function %_SetValueOf for Crankshaft. It is frequently used inside our builtins and is implemented purely by HIR instructions: a smi check, an instance-type check and an in-object property store for storing to the value field. Review URL: http://codereview.chromium.org/8507016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9952 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 0f5694f758..4b7528b596 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -6261,7 +6261,44 @@ void HGraphBuilder::GenerateValueOf(CallRuntime* call) { void HGraphBuilder::GenerateSetValueOf(CallRuntime* call) { - return Bailout("inlined runtime function: SetValueOf"); + ASSERT(call->arguments()->length() == 2); + CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); + CHECK_ALIVE(VisitForValue(call->arguments()->at(1))); + HValue* value = Pop(); + HValue* object = Pop(); + // Check if object is a not a smi. + HIsSmiAndBranch* smicheck = new(zone()) HIsSmiAndBranch(object); + HBasicBlock* if_smi = graph()->CreateBasicBlock(); + HBasicBlock* if_heap_object = graph()->CreateBasicBlock(); + HBasicBlock* join = graph()->CreateBasicBlock(); + smicheck->SetSuccessorAt(0, if_smi); + smicheck->SetSuccessorAt(1, if_heap_object); + current_block()->Finish(smicheck); + if_smi->Goto(join); + + // Check if object is a JSValue. + set_current_block(if_heap_object); + HHasInstanceTypeAndBranch* typecheck = + new(zone()) HHasInstanceTypeAndBranch(object, JS_VALUE_TYPE); + HBasicBlock* if_js_value = graph()->CreateBasicBlock(); + HBasicBlock* not_js_value = graph()->CreateBasicBlock(); + typecheck->SetSuccessorAt(0, if_js_value); + typecheck->SetSuccessorAt(1, not_js_value); + current_block()->Finish(typecheck); + not_js_value->Goto(join); + + // Create in-object property store to kValueOffset. + set_current_block(if_js_value); + Handle name = isolate()->factory()->undefined_symbol(); + AddInstruction(new HStoreNamedField(object, + name, + value, + true, // in-object store. + JSValue::kValueOffset)); + if_js_value->Goto(join); + join->SetJoinId(call->id()); + set_current_block(join); + return ast_context()->ReturnValue(value); }