Commit 78cf188e authored by Michael Stanton's avatar Michael Stanton

Hydrogen should recognize literal smi arrays as fast literals.

R=hpayer@chromium.org

Review URL: https://codereview.chromium.org/726423002

Cr-Commit-Position: refs/heads/master@{#25387}
parent 72a2ec9e
......@@ -5529,7 +5529,7 @@ static bool IsFastLiteral(Handle<JSObject> boilerplate,
Handle<FixedArrayBase> elements(boilerplate->elements());
if (elements->length() > 0 &&
elements->map() != isolate->heap()->fixed_cow_array_map()) {
if (boilerplate->HasFastObjectElements()) {
if (boilerplate->HasFastSmiOrObjectElements()) {
Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
int length = elements->length();
for (int i = 0; i < length; i++) {
......@@ -5790,17 +5790,13 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
Add<HConstant>(constants),
Add<HConstant>(flags));
// TODO(mvstanton): Consider a flag to turn off creation of any
// AllocationMementos for this call: we are in crankshaft and should have
// learned enough about transition behavior to stop emitting mementos.
Runtime::FunctionId function_id = Runtime::kCreateArrayLiteral;
literal = Add<HCallRuntime>(isolate()->factory()->empty_string(),
Runtime::FunctionForId(function_id),
4);
// De-opt if elements kind changed from boilerplate_elements_kind.
Handle<Map> map = Handle<Map>(boilerplate_object->map(), isolate());
literal = Add<HCheckMaps>(literal, map);
// Register to deopt if the boilerplate ElementsKind changes.
AllocationSite::RegisterForDeoptOnTransitionChange(site, top_info());
}
// The array is expected in the bailout environment during computation
......@@ -9349,8 +9345,7 @@ void HOptimizedGraphBuilder::BuildInlinedCallArray(
HValue* constructor = environment()->ExpressionStackAt(argument_count);
// Register on the site for deoptimization if the transition feedback changes.
AllocationSite::AddDependentCompilationInfo(
site, AllocationSite::TRANSITIONS, top_info());
AllocationSite::RegisterForDeoptOnTransitionChange(site, top_info());
ElementsKind kind = site->GetElementsKind();
HInstruction* site_instruction = Add<HConstant>(site);
......@@ -9480,9 +9475,8 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
Handle<AllocationSite> allocation_site = expr->allocation_site();
allocation_mode = HAllocationMode(allocation_site);
// Take a dependency on allocation site.
AllocationSite::AddDependentCompilationInfo(allocation_site,
AllocationSite::TENURING,
top_info());
AllocationSite::RegisterForDeoptOnTenureChange(allocation_site,
top_info());
}
}
......@@ -10525,8 +10519,7 @@ HValue* HGraphBuilder::BuildBinaryOperation(
if (!allocation_mode.feedback_site().is_null()) {
DCHECK(!graph()->info()->IsStub());
Handle<AllocationSite> site(allocation_mode.feedback_site());
AllocationSite::AddDependentCompilationInfo(
site, AllocationSite::TENURING, top_info());
AllocationSite::RegisterForDeoptOnTenureChange(site, top_info());
}
// Inline the string addition into the stub when creating allocation
......@@ -11121,13 +11114,14 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
boilerplate_object->map()->instance_size());
PretenureFlag pretenure_flag = NOT_TENURED;
Handle<AllocationSite> site(site_context->current());
if (FLAG_allocation_site_pretenuring) {
pretenure_flag = site_context->current()->GetPretenureMode();
Handle<AllocationSite> site(site_context->current());
AllocationSite::AddDependentCompilationInfo(
site, AllocationSite::TENURING, top_info());
AllocationSite::RegisterForDeoptOnTenureChange(site, top_info());
}
AllocationSite::RegisterForDeoptOnTransitionChange(site, top_info());
HInstruction* object = Add<HAllocate>(object_size_constant, type,
pretenure_flag, instance_type, site_context->current());
......
......@@ -1652,21 +1652,6 @@ inline bool AllocationSite::CanTrack(InstanceType type) {
}
inline DependentCode::DependencyGroup AllocationSite::ToDependencyGroup(
Reason reason) {
switch (reason) {
case TENURING:
return DependentCode::kAllocationSiteTenuringChangedGroup;
break;
case TRANSITIONS:
return DependentCode::kAllocationSiteTransitionChangedGroup;
break;
}
UNREACHABLE();
return DependentCode::kAllocationSiteTransitionChangedGroup;
}
inline void AllocationSite::set_memento_found_count(int count) {
int value = pretenure_data()->value();
// Verify that we can count more mementos than we can possibly find in one
......
......@@ -12959,10 +12959,32 @@ void AllocationSite::DigestTransitionFeedback(Handle<AllocationSite> site,
// static
void AllocationSite::AddDependentCompilationInfo(Handle<AllocationSite> site,
Reason reason,
CompilationInfo* info) {
DependentCode::DependencyGroup group = site->ToDependencyGroup(reason);
void AllocationSite::RegisterForDeoptOnTenureChange(Handle<AllocationSite> site,
CompilationInfo* info) {
AddDependentCompilationInfo(
site, DependentCode::kAllocationSiteTenuringChangedGroup, info);
}
// static
void AllocationSite::RegisterForDeoptOnTransitionChange(
Handle<AllocationSite> site, CompilationInfo* info) {
// Do nothing if the object doesn't have any useful element transitions left.
ElementsKind kind =
site->SitePointsToLiteral()
? JSObject::cast(site->transition_info())->GetElementsKind()
: site->GetElementsKind();
if (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) {
AddDependentCompilationInfo(
site, DependentCode::kAllocationSiteTransitionChangedGroup, info);
}
}
// static
void AllocationSite::AddDependentCompilationInfo(
Handle<AllocationSite> site, DependentCode::DependencyGroup group,
CompilationInfo* info) {
Handle<DependentCode> dep(site->dependent_code());
Handle<DependentCode> codes =
DependentCode::Insert(dep, group, info->object_wrapper());
......
......@@ -8353,14 +8353,11 @@ class AllocationSite: public Struct {
static void DigestTransitionFeedback(Handle<AllocationSite> site,
ElementsKind to_kind);
enum Reason {
TENURING,
TRANSITIONS
};
static void RegisterForDeoptOnTenureChange(Handle<AllocationSite> site,
CompilationInfo* info);
static void AddDependentCompilationInfo(Handle<AllocationSite> site,
Reason reason,
CompilationInfo* info);
static void RegisterForDeoptOnTransitionChange(Handle<AllocationSite> site,
CompilationInfo* info);
DECLARE_PRINTER(AllocationSite)
DECLARE_VERIFIER(AllocationSite)
......@@ -8392,7 +8389,10 @@ class AllocationSite: public Struct {
kSize> BodyDescriptor;
private:
inline DependentCode::DependencyGroup ToDependencyGroup(Reason reason);
static void AddDependentCompilationInfo(Handle<AllocationSite> site,
DependentCode::DependencyGroup group,
CompilationInfo* info);
bool PretenuringDecisionMade() {
return pretenure_decision() != kUndecided;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment