Commit 2a4336d9 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Use sorted set in JSInliningHeuristic.

This changes the inlining candidates to be stored in a sorted set of
unique entries instead of a vector. We can avoid the final sorting
operation by amortizing the cost across insertions and also duplicate
entries are not created in the first place. Duplicate entries cause
crashes when candidates are processed.

R=bmeurer@chromium.org
BUG=chromium:549113
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#31742}
parent 2e1bdea8
......@@ -72,14 +72,13 @@ Reduction JSInliningHeuristic::Reduce(Node* node) {
// ---------------------------------------------------------------------------
// In the general case we remember the candidate for later.
candidates_.push_back({function, node, calls});
candidates_.insert({function, node, calls});
return NoChange();
}
void JSInliningHeuristic::ProcessCandidates() {
if (candidates_.empty()) return; // Nothing to do without candidates.
std::sort(candidates_.begin(), candidates_.end(), Compare);
if (FLAG_trace_turbo_inlining) PrintCandidates();
int cumulative_count = 0;
......@@ -99,10 +98,9 @@ void JSInliningHeuristic::ProcessCandidates() {
}
// static
bool JSInliningHeuristic::Compare(const Candidate& left,
const Candidate& right) {
return left.calls > right.calls;
bool JSInliningHeuristic::CandidateCompare::operator()(
const Candidate& left, const Candidate& right) const {
return left.node != right.node && left.calls >= right.calls;
}
......
......@@ -37,14 +37,22 @@ class JSInliningHeuristic final : public AdvancedReducer {
int calls; // Number of times the call site was hit.
};
static bool Compare(const Candidate& left, const Candidate& right);
// Comparator for candidates.
struct CandidateCompare {
bool operator()(const Candidate& left, const Candidate& right) const;
};
// Candidates are kept in a sorted set of unique candidates.
typedef ZoneSet<Candidate, CandidateCompare> Candidates;
// Dumps candidates to console.
void PrintCandidates();
Mode const mode_;
Zone* local_zone_;
JSGraph* jsgraph_;
JSInliner inliner_;
ZoneVector<Candidate> candidates_;
Candidates candidates_;
CompilationInfo* info_;
};
......
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