Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: src/crankshaft/hydrogen.cc

Issue 2403003002: Speedup access to global_proxy.* attributes/accessors. (Closed)
Patch Set: Check for nullptr return in InlineGlobalPropertyStore. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/crankshaft/hydrogen.cc
diff --git a/src/crankshaft/hydrogen.cc b/src/crankshaft/hydrogen.cc
index 922ce7a1daa7a9f8d9743475fb28aa7e1ac53928..d97461b1a9582d103736bd6902b6d6f9d82d7c0b 100644
--- a/src/crankshaft/hydrogen.cc
+++ b/src/crankshaft/hydrogen.cc
@@ -5199,12 +5199,16 @@ void HOptimizedGraphBuilder::VisitConditional(Conditional* expr) {
}
}
+bool HOptimizedGraphBuilder::CanInlineGlobalPropertyAccess(
+ Variable* var, LookupIterator* it, PropertyAccessType access_type) {
+ if (var->is_this()) return false;
+ return CanInlineGlobalPropertyAccess(it, access_type);
+}
-HOptimizedGraphBuilder::GlobalPropertyAccess
-HOptimizedGraphBuilder::LookupGlobalProperty(Variable* var, LookupIterator* it,
- PropertyAccessType access_type) {
- if (var->is_this() || !current_info()->has_global_object()) {
- return kUseGeneric;
+bool HOptimizedGraphBuilder::CanInlineGlobalPropertyAccess(
+ LookupIterator* it, PropertyAccessType access_type) {
+ if (!current_info()->has_global_object()) {
+ return false;
}
switch (it->state()) {
@@ -5213,17 +5217,17 @@ HOptimizedGraphBuilder::LookupGlobalProperty(Variable* var, LookupIterator* it,
case LookupIterator::INTERCEPTOR:
case LookupIterator::INTEGER_INDEXED_EXOTIC:
case LookupIterator::NOT_FOUND:
- return kUseGeneric;
+ return false;
case LookupIterator::DATA:
- if (access_type == STORE && it->IsReadOnly()) return kUseGeneric;
- if (!it->GetHolder<JSObject>()->IsJSGlobalObject()) return kUseGeneric;
- return kUseCell;
+ if (access_type == STORE && it->IsReadOnly()) return false;
+ if (!it->GetHolder<JSObject>()->IsJSGlobalObject()) return false;
+ return true;
case LookupIterator::JSPROXY:
case LookupIterator::TRANSITION:
UNREACHABLE();
}
UNREACHABLE();
- return kUseGeneric;
+ return false;
}
@@ -5239,6 +5243,55 @@ HValue* HOptimizedGraphBuilder::BuildContextChainWalk(Variable* var) {
return context;
}
+void HOptimizedGraphBuilder::InlineGlobalPropertyLoad(LookupIterator* it,
+ BailoutId ast_id) {
+ Handle<PropertyCell> cell = it->GetPropertyCell();
+ top_info()->dependencies()->AssumePropertyCell(cell);
+ auto cell_type = it->property_details().cell_type();
+ if (cell_type == PropertyCellType::kConstant ||
+ cell_type == PropertyCellType::kUndefined) {
+ Handle<Object> constant_object(cell->value(), isolate());
+ if (constant_object->IsConsString()) {
+ constant_object = String::Flatten(Handle<String>::cast(constant_object));
+ }
+ HConstant* constant = New<HConstant>(constant_object);
+ return ast_context()->ReturnInstruction(constant, ast_id);
+ } else {
+ auto access = HObjectAccess::ForPropertyCellValue();
+ UniqueSet<Map>* field_maps = nullptr;
+ if (cell_type == PropertyCellType::kConstantType) {
+ switch (cell->GetConstantType()) {
+ case PropertyCellConstantType::kSmi:
+ access = access.WithRepresentation(Representation::Smi());
+ break;
+ case PropertyCellConstantType::kStableMap: {
+ // Check that the map really is stable. The heap object could
+ // have mutated without the cell updating state. In that case,
+ // make no promises about the loaded value except that it's a
+ // heap object.
+ access = access.WithRepresentation(Representation::HeapObject());
+ Handle<Map> map(HeapObject::cast(cell->value())->map());
+ if (map->is_stable()) {
+ field_maps = new (zone())
+ UniqueSet<Map>(Unique<Map>::CreateImmovable(map), zone());
+ }
+ break;
+ }
+ }
+ }
+ HConstant* cell_constant = Add<HConstant>(cell);
+ HLoadNamedField* instr;
+ if (field_maps == nullptr) {
+ instr = New<HLoadNamedField>(cell_constant, nullptr, access);
+ } else {
+ instr = New<HLoadNamedField>(cell_constant, nullptr, access, field_maps,
+ HType::HeapObject());
+ }
+ instr->ClearDependsOnFlag(kInobjectFields);
+ instr->SetDependsOnFlag(kGlobalVars);
+ return ast_context()->ReturnInstruction(instr, ast_id);
+ }
+}
void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
DCHECK(!HasStackOverflow());
@@ -5287,57 +5340,9 @@ void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
}
LookupIterator it(global, variable->name(), LookupIterator::OWN);
- GlobalPropertyAccess type = LookupGlobalProperty(variable, &it, LOAD);
-
- if (type == kUseCell) {
- Handle<PropertyCell> cell = it.GetPropertyCell();
- top_info()->dependencies()->AssumePropertyCell(cell);
- auto cell_type = it.property_details().cell_type();
- if (cell_type == PropertyCellType::kConstant ||
- cell_type == PropertyCellType::kUndefined) {
- Handle<Object> constant_object(cell->value(), isolate());
- if (constant_object->IsConsString()) {
- constant_object =
- String::Flatten(Handle<String>::cast(constant_object));
- }
- HConstant* constant = New<HConstant>(constant_object);
- return ast_context()->ReturnInstruction(constant, expr->id());
- } else {
- auto access = HObjectAccess::ForPropertyCellValue();
- UniqueSet<Map>* field_maps = nullptr;
- if (cell_type == PropertyCellType::kConstantType) {
- switch (cell->GetConstantType()) {
- case PropertyCellConstantType::kSmi:
- access = access.WithRepresentation(Representation::Smi());
- break;
- case PropertyCellConstantType::kStableMap: {
- // Check that the map really is stable. The heap object could
- // have mutated without the cell updating state. In that case,
- // make no promises about the loaded value except that it's a
- // heap object.
- access =
- access.WithRepresentation(Representation::HeapObject());
- Handle<Map> map(HeapObject::cast(cell->value())->map());
- if (map->is_stable()) {
- field_maps = new (zone())
- UniqueSet<Map>(Unique<Map>::CreateImmovable(map), zone());
- }
- break;
- }
- }
- }
- HConstant* cell_constant = Add<HConstant>(cell);
- HLoadNamedField* instr;
- if (field_maps == nullptr) {
- instr = New<HLoadNamedField>(cell_constant, nullptr, access);
- } else {
- instr = New<HLoadNamedField>(cell_constant, nullptr, access,
- field_maps, HType::HeapObject());
- }
- instr->ClearDependsOnFlag(kInobjectFields);
- instr->SetDependsOnFlag(kGlobalVars);
- return ast_context()->ReturnInstruction(instr, expr->id());
- }
+ if (CanInlineGlobalPropertyAccess(variable, &it, LOAD)) {
+ InlineGlobalPropertyLoad(&it, expr->id());
+ return;
} else {
Handle<TypeFeedbackVector> vector(current_feedback_vector(), isolate());
@@ -6441,6 +6446,67 @@ void HOptimizedGraphBuilder::HandlePropertyAssignment(Assignment* expr) {
expr->AssignmentId(), expr->IsUninitialized());
}
+HInstruction* HOptimizedGraphBuilder::InlineGlobalPropertyStore(
+ LookupIterator* it, HValue* value, BailoutId ast_id) {
+ Handle<PropertyCell> cell = it->GetPropertyCell();
+ top_info()->dependencies()->AssumePropertyCell(cell);
+ auto cell_type = it->property_details().cell_type();
+ if (cell_type == PropertyCellType::kConstant ||
+ cell_type == PropertyCellType::kUndefined) {
+ Handle<Object> constant(cell->value(), isolate());
+ if (value->IsConstant()) {
+ HConstant* c_value = HConstant::cast(value);
+ if (!constant.is_identical_to(c_value->handle(isolate()))) {
+ Add<HDeoptimize>(DeoptimizeReason::kConstantGlobalVariableAssignment,
+ Deoptimizer::EAGER);
+ }
+ } else {
+ HValue* c_constant = Add<HConstant>(constant);
+ IfBuilder builder(this);
+ if (constant->IsNumber()) {
+ builder.If<HCompareNumericAndBranch>(value, c_constant, Token::EQ);
+ } else {
+ builder.If<HCompareObjectEqAndBranch>(value, c_constant);
+ }
+ builder.Then();
+ builder.Else();
+ Add<HDeoptimize>(DeoptimizeReason::kConstantGlobalVariableAssignment,
+ Deoptimizer::EAGER);
+ builder.End();
+ }
+ }
+ HConstant* cell_constant = Add<HConstant>(cell);
+ auto access = HObjectAccess::ForPropertyCellValue();
+ if (cell_type == PropertyCellType::kConstantType) {
+ switch (cell->GetConstantType()) {
+ case PropertyCellConstantType::kSmi:
+ access = access.WithRepresentation(Representation::Smi());
+ break;
+ case PropertyCellConstantType::kStableMap: {
+ // First check that the previous value of the {cell} still has the
+ // map that we are about to check the new {value} for. If not, then
+ // the stable map assumption was invalidated and we cannot continue
+ // with the optimized code.
+ Handle<HeapObject> cell_value(HeapObject::cast(cell->value()));
+ Handle<Map> cell_value_map(cell_value->map());
+ if (!cell_value_map->is_stable()) {
+ Bailout(kUnstableConstantTypeHeapObject);
+ return nullptr;
+ }
+ top_info()->dependencies()->AssumeMapStable(cell_value_map);
+ // Now check that the new {value} is a HeapObject with the same map
+ Add<HCheckHeapObject>(value);
+ value = Add<HCheckMaps>(value, cell_value_map);
+ access = access.WithRepresentation(Representation::HeapObject());
+ break;
+ }
+ }
+ }
+ HInstruction* instr = New<HStoreNamedField>(cell_constant, access, value);
+ instr->ClearChangesFlag(kInobjectFields);
+ instr->SetChangesFlag(kGlobalVars);
+ return instr;
+}
// Because not every expression has a position and there is not common
// superclass of Assignment and CountOperation, we cannot just pass the
@@ -6481,64 +6547,10 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment(
}
LookupIterator it(global, var->name(), LookupIterator::OWN);
- GlobalPropertyAccess type = LookupGlobalProperty(var, &it, STORE);
- if (type == kUseCell) {
- Handle<PropertyCell> cell = it.GetPropertyCell();
- top_info()->dependencies()->AssumePropertyCell(cell);
- auto cell_type = it.property_details().cell_type();
- if (cell_type == PropertyCellType::kConstant ||
- cell_type == PropertyCellType::kUndefined) {
- Handle<Object> constant(cell->value(), isolate());
- if (value->IsConstant()) {
- HConstant* c_value = HConstant::cast(value);
- if (!constant.is_identical_to(c_value->handle(isolate()))) {
- Add<HDeoptimize>(DeoptimizeReason::kConstantGlobalVariableAssignment,
- Deoptimizer::EAGER);
- }
- } else {
- HValue* c_constant = Add<HConstant>(constant);
- IfBuilder builder(this);
- if (constant->IsNumber()) {
- builder.If<HCompareNumericAndBranch>(value, c_constant, Token::EQ);
- } else {
- builder.If<HCompareObjectEqAndBranch>(value, c_constant);
- }
- builder.Then();
- builder.Else();
- Add<HDeoptimize>(DeoptimizeReason::kConstantGlobalVariableAssignment,
- Deoptimizer::EAGER);
- builder.End();
- }
- }
- HConstant* cell_constant = Add<HConstant>(cell);
- auto access = HObjectAccess::ForPropertyCellValue();
- if (cell_type == PropertyCellType::kConstantType) {
- switch (cell->GetConstantType()) {
- case PropertyCellConstantType::kSmi:
- access = access.WithRepresentation(Representation::Smi());
- break;
- case PropertyCellConstantType::kStableMap: {
- // First check that the previous value of the {cell} still has the
- // map that we are about to check the new {value} for. If not, then
- // the stable map assumption was invalidated and we cannot continue
- // with the optimized code.
- Handle<HeapObject> cell_value(HeapObject::cast(cell->value()));
- Handle<Map> cell_value_map(cell_value->map());
- if (!cell_value_map->is_stable()) {
- return Bailout(kUnstableConstantTypeHeapObject);
- }
- top_info()->dependencies()->AssumeMapStable(cell_value_map);
- // Now check that the new {value} is a HeapObject with the same map.
- Add<HCheckHeapObject>(value);
- value = Add<HCheckMaps>(value, cell_value_map);
- access = access.WithRepresentation(Representation::HeapObject());
- break;
- }
- }
- }
- HInstruction* instr = Add<HStoreNamedField>(cell_constant, access, value);
- instr->ClearChangesFlag(kInobjectFields);
- instr->SetChangesFlag(kGlobalVars);
+ if (CanInlineGlobalPropertyAccess(var, &it, STORE)) {
+ HInstruction* instr = InlineGlobalPropertyStore(&it, value, ast_id);
+ if (!instr) return;
+ AddInstruction(instr);
if (instr->HasObservableSideEffects()) {
Add<HSimulate>(ast_id, REMOVABLE_SIMULATE);
}
@@ -7460,7 +7472,35 @@ HValue* HOptimizedGraphBuilder::BuildNamedAccess(
ComputeReceiverTypes(expr, object, &maps, this);
DCHECK(maps != NULL);
+ // Check for special case: Access via a single map to the global proxy
+ // can also be handled monomorphically.
if (maps->length() > 0) {
+ Handle<Object> map_constructor =
+ handle(maps->first()->GetConstructor(), isolate());
+ if (map_constructor->IsJSFunction()) {
+ Handle<Context> map_context =
+ handle(Handle<JSFunction>::cast(map_constructor)->context());
+ Handle<Context> current_context(current_info()->context());
+ bool is_same_context_global_proxy_access =
+ maps->length() == 1 && // >1 map => fallback to polymorphic
+ maps->first()->IsJSGlobalProxyMap() &&
+ (*map_context == *current_context);
+ if (is_same_context_global_proxy_access) {
+ Handle<JSGlobalObject> global_object(current_info()->global_object());
+ LookupIterator it(global_object, name, LookupIterator::OWN);
+ if (CanInlineGlobalPropertyAccess(&it, access)) {
+ BuildCheckHeapObject(object);
+ Add<HCheckMaps>(object, maps);
+ if (access == LOAD) {
+ InlineGlobalPropertyLoad(&it, expr->id());
+ return nullptr;
+ } else {
+ return InlineGlobalPropertyStore(&it, value, expr->id());
+ }
+ }
+ }
+ }
+
PropertyAccessInfo info(this, access, maps->first(), name);
if (!info.CanAccessAsMonomorphic(maps)) {
HandlePolymorphicNamedFieldAccess(access, expr, slot, ast_id, return_id,
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698