From: svenpanne@chromium.org Date: Fri, 27 Jul 2012 06:27:47 +0000 (+0000) Subject: Cleaned up BuildLoadNamed/BuildStoreNamed. X-Git-Tag: upstream/4.7.83~16235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eddf5edb6259c44424ab51858d9cdbb5db8d6bfb;p=platform%2Fupstream%2Fv8.git Cleaned up BuildLoadNamed/BuildStoreNamed. This is a refactoring-only CL and the second one in a series for enabling inlining of accessors. It makes BuildLoadNamed and BuildStoreNamed a bit more uniform and makes it clear that they both handle monomorphic accesses only. Review URL: https://chromiumcodereview.appspot.com/10820028 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12205 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/hydrogen.cc b/src/hydrogen.cc index e49bbb4fa..312e30d02 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -4764,12 +4764,18 @@ void HGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { property->RecordTypeFeedback(oracle()); CHECK_ALIVE(VisitForValue(value)); HValue* value = Pop(); + Handle map = property->GetReceiverType(); Handle name = property->key()->AsPropertyName(); HInstruction* store; - CHECK_ALIVE(store = BuildStoreNamed(literal, - name, - value, - property->GetReceiverType())); + if (map.is_null()) { + // If we don't know the monomorphic type, do a generic store. + CHECK_ALIVE(store = BuildStoreNamedGeneric(literal, name, value)); + } else { + CHECK_ALIVE(store = BuildStoreNamedMonomorphic(literal, + name, + value, + map)); + } AddInstruction(store); if (store->HasObservableSideEffects()) AddSimulate(key->id()); } else { @@ -5039,13 +5045,10 @@ HInstruction* HGraphBuilder::BuildCallSetter(HValue* object, } -HInstruction* HGraphBuilder::BuildStoreNamed(HValue* object, - Handle name, - HValue* value, - Handle map) { - // If we don't know the monomorphic type, do a generic store. - if (map.is_null()) return BuildStoreNamedGeneric(object, name, value); - +HInstruction* HGraphBuilder::BuildStoreNamedMonomorphic(HValue* object, + Handle name, + HValue* value, + Handle map) { // Handle a store to a known field. LookupResult lookup(isolate()); if (ComputeLoadStoreField(map, name, &lookup, true)) { @@ -5233,11 +5236,8 @@ void HGraphBuilder::HandlePropertyAssignment(Assignment* expr) { SmallMapList* types = expr->GetReceiverTypes(); if (expr->IsMonomorphic()) { - CHECK_ALIVE(instr = BuildStoreNamed(object, - name, - value, - types->first())); - + Handle map = types->first(); + CHECK_ALIVE(instr = BuildStoreNamedMonomorphic(object, name, value, map)); } else if (types != NULL && types->length() > 1) { HandlePolymorphicStoreNamedField(expr, object, value, types, name); return; @@ -5401,7 +5401,7 @@ void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { HInstruction* load; if (prop->IsMonomorphic()) { map = prop->GetReceiverTypes()->first(); - load = BuildLoadNamed(object, name, prop, map); + load = BuildLoadNamedMonomorphic(object, name, prop, map); } else { load = BuildLoadNamedGeneric(object, name, prop); } @@ -5417,7 +5417,15 @@ void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { if (instr->HasObservableSideEffects()) AddSimulate(operation->id()); HInstruction* store; - CHECK_ALIVE(store = BuildStoreNamed(object, name, instr, map)); + if (map.is_null()) { + // If we don't know the monomorphic type, do a generic store. + CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, instr)); + } else { + CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, + name, + instr, + map)); + } AddInstruction(store); // Drop the simulated receiver and value. Return the value. Drop(2); @@ -5640,7 +5648,7 @@ HLoadNamedField* HGraphBuilder::BuildLoadNamedField(HValue* object, } -HInstruction* HGraphBuilder::BuildLoadNamedGeneric(HValue* obj, +HInstruction* HGraphBuilder::BuildLoadNamedGeneric(HValue* object, Handle name, Property* expr) { if (expr->IsUninitialized() && !FLAG_always_opt) { @@ -5648,7 +5656,7 @@ HInstruction* HGraphBuilder::BuildLoadNamedGeneric(HValue* obj, current_block()->MarkAsDeoptimizing(); } HValue* context = environment()->LookupContext(); - return new(zone()) HLoadNamedGeneric(context, obj, name); + return new(zone()) HLoadNamedGeneric(context, object, name); } @@ -5663,20 +5671,27 @@ HInstruction* HGraphBuilder::BuildCallGetter(HValue* object, } -HInstruction* HGraphBuilder::BuildLoadNamed(HValue* object, - Handle name, - Property* expr, - Handle map) { +HInstruction* HGraphBuilder::BuildLoadNamedMonomorphic(HValue* object, + Handle name, + Property* expr, + Handle map) { + // Handle a load from a known field. LookupResult lookup(isolate()); map->LookupDescriptor(NULL, *name, &lookup); if (lookup.IsField()) { return BuildLoadNamedField(object, map, &lookup, true); - } else if (lookup.IsConstantFunction()) { + } + + // Handle a load of a constant known function. + if (lookup.IsConstantFunction()) { AddInstruction(new(zone()) HCheckNonSmi(object)); AddInstruction(HCheckMaps::NewWithTransitions(object, map, zone())); Handle function(lookup.GetConstantFunctionFromMap(*map)); return new(zone()) HConstant(function, Representation::Tagged()); - } else if (lookup.IsPropertyCallbacks()) { + } + + // Handle a known getter directly in the receiver. + if (lookup.IsPropertyCallbacks()) { Handle callback(lookup.GetValueFromMap(*map)); Handle holder; if (!callback->IsAccessorPair()) { @@ -5684,19 +5699,22 @@ HInstruction* HGraphBuilder::BuildLoadNamed(HValue* object, } Handle accessors = Handle::cast(callback); return BuildCallGetter(object, map, accessors, holder); - } else { - LookupInPrototypes(map, name, &lookup); - if (lookup.IsPropertyCallbacks()) { - Handle callback(lookup.GetValue()); + } + + // Handle a known getter somewhere in the prototype chain. + LookupInPrototypes(map, name, &lookup); + if (lookup.IsPropertyCallbacks()) { + Handle callback(lookup.GetValue()); Handle holder(lookup.holder()); if (!callback->IsAccessorPair()) { return BuildLoadNamedGeneric(object, name, expr); } Handle accessors = Handle::cast(callback); return BuildCallGetter(object, map, accessors, holder); - } - return BuildLoadNamedGeneric(object, name, expr); } + + // No luck, do a generic load. + return BuildLoadNamedGeneric(object, name, expr); } @@ -6315,7 +6333,7 @@ void HGraphBuilder::VisitProperty(Property* expr) { HValue* obj = Pop(); if (expr->IsMonomorphic()) { - instr = BuildLoadNamed(obj, name, expr, types->first()); + instr = BuildLoadNamedMonomorphic(obj, name, expr, types->first()); } else if (types != NULL && types->length() > 1) { AddInstruction(new(zone()) HCheckNonSmi(obj)); HandlePolymorphicLoadNamedField(expr, obj, types, name); @@ -7798,16 +7816,16 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { if (returns_original_input) Push(graph_->GetConstantUndefined()); CHECK_ALIVE(VisitForValue(prop->obj())); - HValue* obj = Top(); + HValue* object = Top(); Handle name = prop->key()->AsLiteral()->AsPropertyName(); Handle map; HInstruction* load; if (prop->IsMonomorphic()) { map = prop->GetReceiverTypes()->first(); - load = BuildLoadNamed(obj, name, prop, map); + load = BuildLoadNamedMonomorphic(object, name, prop, map); } else { - load = BuildLoadNamedGeneric(obj, name, prop); + load = BuildLoadNamedGeneric(object, name, prop); } PushAndAdd(load); if (load->HasObservableSideEffects()) AddSimulate(expr->CountId()); @@ -7816,7 +7834,15 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { input = Pop(); HInstruction* store; - CHECK_ALIVE(store = BuildStoreNamed(obj, name, after, map)); + if (map.is_null()) { + // If we don't know the monomorphic type, do a generic store. + CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, after)); + } else { + CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, + name, + after, + map)); + } AddInstruction(store); // Overwrite the receiver in the bailout environment with the result diff --git a/src/hydrogen.h b/src/hydrogen.h index f4c15c781..39e50604f 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -1151,19 +1151,19 @@ class HGraphBuilder: public AstVisitor { Handle map, Handle accessors, Handle holder); - HInstruction* BuildLoadNamed(HValue* object, - Handle name, - Property* expr, - Handle map); + HInstruction* BuildLoadNamedMonomorphic(HValue* object, + Handle name, + Property* expr, + Handle map); HInstruction* BuildCallSetter(HValue* object, HValue* value, Handle map, Handle accessors, Handle holder); - HInstruction* BuildStoreNamed(HValue* object, - Handle name, - HValue* value, - Handle map); + HInstruction* BuildStoreNamedMonomorphic(HValue* object, + Handle name, + HValue* value, + Handle map); HInstruction* BuildStoreNamedField(HValue* object, Handle name, HValue* value,