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

Unified Diff: src/crankshaft/hydrogen.cc

Issue 2369933005: Speedup global_proxy.* attributes/accessors (specialize GlobalProxy access). (Closed)
Patch Set: Cleanup + better naming Created 4 years, 3 months 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 da0ea4c318da50cde89c07f7e86b34a4b7ccf9f8..e68c642cc259782783034db870b89707a3918207 100644
--- a/src/crankshaft/hydrogen.cc
+++ b/src/crankshaft/hydrogen.cc
@@ -5448,12 +5448,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()) {
@@ -5462,17 +5466,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;
}
@@ -5488,6 +5492,55 @@ HValue* HOptimizedGraphBuilder::BuildContextChainWalk(Variable* var) {
return context;
}
+void HOptimizedGraphBuilder::InlineGlobalPropertyAccess(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());
@@ -5536,57 +5589,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)) {
+ InlineGlobalPropertyAccess(&it, expr->id());
+ return;
} else {
Handle<TypeFeedbackVector> vector(current_feedback_vector(), isolate());
HLoadGlobalGeneric* instr = New<HLoadGlobalGeneric>(
@@ -6722,8 +6727,7 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment(
}
LookupIterator it(global, var->name(), LookupIterator::OWN);
- GlobalPropertyAccess type = LookupGlobalProperty(var, &it, STORE);
- if (type == kUseCell) {
+ if (CanInlineGlobalPropertyAccess(var, &it, STORE)) {
Handle<PropertyCell> cell = it.GetPropertyCell();
top_info()->dependencies()->AssumePropertyCell(cell);
auto cell_type = it.property_details().cell_type();
@@ -7690,6 +7694,25 @@ HValue* HOptimizedGraphBuilder::BuildNamedAccess(
DCHECK(maps != NULL);
if (maps->length() > 0) {
+ Handle<JSGlobalObject> global_object(current_info()->global_object());
+ Handle<Context> current_context(current_info()->context());
+ Handle<JSObject> global_proxy(current_context->global_proxy());
+
+ // Check for special case: Access via a single map to the global proxy
+ // can also be handled monomorphically.
+ bool is_global_proxy_access =
+ maps->length() == 1 // More than one map, fallback to polymorphic?.
+ && maps->first()->IsJSGlobalProxyMap() &&
vogelheim 2016/09/29 15:21:13 style nitpick: " && xxxxx && " is odd. Put the op
+ isolate()->MayAccess(current_context, global_proxy);
+
+ if (is_global_proxy_access) {
+ LookupIterator it(global_object, name, LookupIterator::OWN);
+ if (CanInlineGlobalPropertyAccess(&it, LOAD)) {
+ InlineGlobalPropertyAccess(&it, expr->id());
+ return NULL;
+ }
+ }
vogelheim 2016/09/29 15:21:13 This is a much nicer place for the logic than what
+
PropertyAccessInfo info(this, access, maps->first(), name);
if (!info.CanAccessAsMonomorphic(maps)) {
HandlePolymorphicNamedFieldAccess(access, expr, slot, ast_id, return_id,
@@ -7707,6 +7730,7 @@ HValue* HOptimizedGraphBuilder::BuildNamedAccess(
} else {
checked_object = Add<HCheckMaps>(object, maps);
}
+
return BuildMonomorphicAccess(
&info, object, checked_object, value, 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