diff --git a/src/flag-definitions.h b/src/flag-definitions.h index d1457397c5..7f92871c2f 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -166,6 +166,7 @@ DEFINE_bool(use_osr, true, "use on-stack replacement") DEFINE_bool(trace_osr, false, "trace on-stack replacement") DEFINE_int(stress_runs, 0, "number of stress runs") DEFINE_bool(optimize_closures, true, "optimize closures") +DEFINE_int(loop_weight, 1, "loop weight for representation inference") // assembler-ia32.cc / assembler-arm.cc / assembler-x64.cc DEFINE_bool(debug_code, false, diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 7ae0b44a27..4372c06f61 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -67,6 +67,14 @@ const char* Representation::Mnemonic() const { } +int HValue::LoopWeight() const { + const int w = FLAG_loop_weight; + static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; + return weights[Min(block()->LoopNestingDepth(), + static_cast(ARRAY_SIZE(weights)-1))]; +} + + void HValue::AssumeRepresentation(Representation r) { if (CheckFlag(kFlexibleRepresentation)) { ChangeRepresentation(r); @@ -1139,7 +1147,7 @@ void HPhi::InitRealUses(int phi_id) { HValue* value = it.value(); if (!value->IsPhi()) { Representation rep = value->RequiredInputRepresentation(it.index()); - ++non_phi_uses_[rep.kind()]; + non_phi_uses_[rep.kind()] += value->LoopWeight(); } } } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 38277e9557..b2b3a61830 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -569,6 +569,7 @@ class HValue: public ZoneObject { HBasicBlock* block() const { return block_; } void SetBlock(HBasicBlock* block); + int LoopWeight() const; int id() const { return id_; } void set_id(int id) { id_ = id; } diff --git a/src/hydrogen.cc b/src/hydrogen.cc index ec5ea2cab6..3e6f0504b4 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -1672,7 +1672,7 @@ Representation HInferRepresentation::TryChange(HValue* value) { Representation rep = use->RequiredInputRepresentation(it.index()); if (rep.IsNone()) continue; if (use->IsPhi()) HPhi::cast(use)->AddIndirectUsesTo(&use_count[0]); - ++use_count[rep.kind()]; + use_count[rep.kind()] += use->LoopWeight(); } int tagged_count = use_count[Representation::kTagged]; int double_count = use_count[Representation::kDouble];