Commit e0241e42 authored by jarin's avatar jarin Committed by Commit bot

[crankshaft] Cleanup representation calculation for Phis.

This replaces the counters for use representations with
simple tracking of most-general representation seen so far.

R=bmeurer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30506}
parent 76fb022f
...@@ -74,33 +74,26 @@ void HValue::InferRepresentation(HInferRepresentationPhase* h_infer) { ...@@ -74,33 +74,26 @@ void HValue::InferRepresentation(HInferRepresentationPhase* h_infer) {
Representation HValue::RepresentationFromUses() { Representation HValue::RepresentationFromUses() {
if (HasNoUses()) return Representation::None(); if (HasNoUses()) return Representation::None();
Representation result = Representation::None();
// Array of use counts for each representation.
int use_count[Representation::kNumRepresentations] = { 0 };
for (HUseIterator it(uses()); !it.Done(); it.Advance()) { for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
HValue* use = it.value(); HValue* use = it.value();
Representation rep = use->observed_input_representation(it.index()); Representation rep = use->observed_input_representation(it.index());
if (rep.IsNone()) continue; result = result.generalize(rep);
if (FLAG_trace_representation) { if (FLAG_trace_representation) {
PrintF("#%d %s is used by #%d %s as %s%s\n", PrintF("#%d %s is used by #%d %s as %s%s\n",
id(), Mnemonic(), use->id(), use->Mnemonic(), rep.Mnemonic(), id(), Mnemonic(), use->id(), use->Mnemonic(), rep.Mnemonic(),
(use->CheckFlag(kTruncatingToInt32) ? "-trunc" : "")); (use->CheckFlag(kTruncatingToInt32) ? "-trunc" : ""));
} }
use_count[rep.kind()] += 1;
} }
if (IsPhi()) HPhi::cast(this)->AddIndirectUsesTo(&use_count[0]); if (IsPhi()) {
int tagged_count = use_count[Representation::kTagged]; result = result.generalize(
int double_count = use_count[Representation::kDouble]; HPhi::cast(this)->representation_from_indirect_uses());
int int32_count = use_count[Representation::kInteger32]; }
int smi_count = use_count[Representation::kSmi];
if (tagged_count > 0) return Representation::Tagged();
if (double_count > 0) return Representation::Double();
if (int32_count > 0) return Representation::Integer32();
if (smi_count > 0) return Representation::Smi();
return Representation::None(); // External representations are dealt with separately.
return result.IsExternal() ? Representation::None() : result;
} }
...@@ -2484,11 +2477,8 @@ std::ostream& HPhi::PrintTo(std::ostream& os) const { // NOLINT ...@@ -2484,11 +2477,8 @@ std::ostream& HPhi::PrintTo(std::ostream& os) const { // NOLINT
for (int i = 0; i < OperandCount(); ++i) { for (int i = 0; i < OperandCount(); ++i) {
os << " " << NameOf(OperandAt(i)) << " "; os << " " << NameOf(OperandAt(i)) << " ";
} }
return os << " uses:" << UseCount() << "_" return os << " uses" << UseCount()
<< smi_non_phi_uses() + smi_indirect_uses() << "s_" << representation_from_indirect_uses().Mnemonic() << " "
<< int32_non_phi_uses() + int32_indirect_uses() << "i_"
<< double_non_phi_uses() + double_indirect_uses() << "d_"
<< tagged_non_phi_uses() + tagged_indirect_uses() << "t"
<< TypeOf(this) << "]"; << TypeOf(this) << "]";
} }
...@@ -2547,7 +2537,12 @@ void HPhi::InitRealUses(int phi_id) { ...@@ -2547,7 +2537,12 @@ void HPhi::InitRealUses(int phi_id) {
HValue* value = it.value(); HValue* value = it.value();
if (!value->IsPhi()) { if (!value->IsPhi()) {
Representation rep = value->observed_input_representation(it.index()); Representation rep = value->observed_input_representation(it.index());
non_phi_uses_[rep.kind()] += 1; representation_from_non_phi_uses_ =
representation_from_non_phi_uses().generalize(rep);
if (rep.IsSmi() || rep.IsInteger32() || rep.IsDouble()) {
has_type_feedback_from_uses_ = true;
}
if (FLAG_trace_representation) { if (FLAG_trace_representation) {
PrintF("#%d Phi is used by real #%d %s as %s\n", PrintF("#%d Phi is used by real #%d %s as %s\n",
id(), value->id(), value->Mnemonic(), rep.Mnemonic()); id(), value->id(), value->Mnemonic(), rep.Mnemonic());
...@@ -2567,24 +2562,16 @@ void HPhi::InitRealUses(int phi_id) { ...@@ -2567,24 +2562,16 @@ void HPhi::InitRealUses(int phi_id) {
void HPhi::AddNonPhiUsesFrom(HPhi* other) { void HPhi::AddNonPhiUsesFrom(HPhi* other) {
if (FLAG_trace_representation) { if (FLAG_trace_representation) {
PrintF("adding to #%d Phi uses of #%d Phi: s%d i%d d%d t%d\n", PrintF(
id(), other->id(), "generalizing use representation '%s' of #%d Phi "
other->non_phi_uses_[Representation::kSmi], "with uses of #%d Phi '%s'\n",
other->non_phi_uses_[Representation::kInteger32], representation_from_indirect_uses().Mnemonic(), id(), other->id(),
other->non_phi_uses_[Representation::kDouble], other->representation_from_non_phi_uses().Mnemonic());
other->non_phi_uses_[Representation::kTagged]);
} }
for (int i = 0; i < Representation::kNumRepresentations; i++) { representation_from_indirect_uses_ =
indirect_uses_[i] += other->non_phi_uses_[i]; representation_from_indirect_uses().generalize(
} other->representation_from_non_phi_uses());
}
void HPhi::AddIndirectUsesTo(int* dest) {
for (int i = 0; i < Representation::kNumRepresentations; i++) {
dest[i] += indirect_uses_[i];
}
} }
...@@ -4422,13 +4409,13 @@ void HPhi::InferRepresentation(HInferRepresentationPhase* h_infer) { ...@@ -4422,13 +4409,13 @@ void HPhi::InferRepresentation(HInferRepresentationPhase* h_infer) {
Representation HPhi::RepresentationFromInputs() { Representation HPhi::RepresentationFromInputs() {
bool has_type_feedback =
smi_non_phi_uses() + int32_non_phi_uses() + double_non_phi_uses() > 0;
Representation r = representation(); Representation r = representation();
for (int i = 0; i < OperandCount(); ++i) { for (int i = 0; i < OperandCount(); ++i) {
// Ignore conservative Tagged assumption of parameters if we have // Ignore conservative Tagged assumption of parameters if we have
// reason to believe that it's too conservative. // reason to believe that it's too conservative.
if (has_type_feedback && OperandAt(i)->IsParameter()) continue; if (has_type_feedback_from_uses() && OperandAt(i)->IsParameter()) {
continue;
}
r = r.generalize(OperandAt(i)->KnownOptimalRepresentation()); r = r.generalize(OperandAt(i)->KnownOptimalRepresentation());
} }
......
...@@ -3270,14 +3270,7 @@ class InductionVariableData final : public ZoneObject { ...@@ -3270,14 +3270,7 @@ class InductionVariableData final : public ZoneObject {
class HPhi final : public HValue { class HPhi final : public HValue {
public: public:
HPhi(int merged_index, Zone* zone) HPhi(int merged_index, Zone* zone)
: inputs_(2, zone), : inputs_(2, zone), merged_index_(merged_index) {
merged_index_(merged_index),
phi_id_(-1),
induction_variable_data_(NULL) {
for (int i = 0; i < Representation::kNumRepresentations; i++) {
non_phi_uses_[i] = 0;
indirect_uses_[i] = 0;
}
DCHECK(merged_index >= 0 || merged_index == kInvalidMergedIndex); DCHECK(merged_index >= 0 || merged_index == kInvalidMergedIndex);
SetFlag(kFlexibleRepresentation); SetFlag(kFlexibleRepresentation);
SetFlag(kAllowUndefinedAsNaN); SetFlag(kAllowUndefinedAsNaN);
...@@ -3330,32 +3323,15 @@ class HPhi final : public HValue { ...@@ -3330,32 +3323,15 @@ class HPhi final : public HValue {
void InitRealUses(int id); void InitRealUses(int id);
void AddNonPhiUsesFrom(HPhi* other); void AddNonPhiUsesFrom(HPhi* other);
void AddIndirectUsesTo(int* use_count);
int tagged_non_phi_uses() const { Representation representation_from_indirect_uses() const {
return non_phi_uses_[Representation::kTagged]; return representation_from_indirect_uses_;
}
int smi_non_phi_uses() const {
return non_phi_uses_[Representation::kSmi];
}
int int32_non_phi_uses() const {
return non_phi_uses_[Representation::kInteger32];
}
int double_non_phi_uses() const {
return non_phi_uses_[Representation::kDouble];
}
int tagged_indirect_uses() const {
return indirect_uses_[Representation::kTagged];
}
int smi_indirect_uses() const {
return indirect_uses_[Representation::kSmi];
} }
int int32_indirect_uses() const {
return indirect_uses_[Representation::kInteger32]; bool has_type_feedback_from_uses() const {
} return has_type_feedback_from_uses_;
int double_indirect_uses() const {
return indirect_uses_[Representation::kDouble];
} }
int phi_id() { return phi_id_; } int phi_id() { return phi_id_; }
static HPhi* cast(HValue* value) { static HPhi* cast(HValue* value) {
...@@ -3376,13 +3352,19 @@ class HPhi final : public HValue { ...@@ -3376,13 +3352,19 @@ class HPhi final : public HValue {
} }
private: private:
Representation representation_from_non_phi_uses() const {
return representation_from_non_phi_uses_;
}
ZoneList<HValue*> inputs_; ZoneList<HValue*> inputs_;
int merged_index_; int merged_index_ = 0;
int phi_id_ = -1;
InductionVariableData* induction_variable_data_ = nullptr;
int non_phi_uses_[Representation::kNumRepresentations]; Representation representation_from_indirect_uses_ = Representation::None();
int indirect_uses_[Representation::kNumRepresentations]; Representation representation_from_non_phi_uses_ = Representation::None();
int phi_id_; bool has_type_feedback_from_uses_ = false;
InductionVariableData* induction_variable_data_;
// TODO(titzer): we can't eliminate the receiver for generating backtraces // TODO(titzer): we can't eliminate the receiver for generating backtraces
bool IsDeletable() const override { return !IsReceiver(); } bool IsDeletable() const override { return !IsReceiver(); }
......
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