This is an archive of the discontinued LLVM Phabricator instance.

[ModuleInliner] Add memorization to MLPriority
Needs ReviewPublic

Authored by kazu on Dec 2 2022, 2:59 PM.

Details

Reviewers
mtrofin
Summary

This patch adds memoization to MLPriority.

The trainer will inject noise, but we don't want the priority function
to produce different values for a given metric input. The reason is
that we could potentially evaluate the priority of a call site over
and over to maintain the priority queue, and it's possible that no
metric has changed since the last evaluation.

Without this patch, Priority is the same as Cost, so we've never
bothered to rename Cost to Priority until now. In future, Priority
will be computed by an ML model, so the mental model is:

Priority = MLModel(Cost);

However, since we don't want to produce different outputs for a given
input, we add memorization as:

Priority = MemoisedMLModel(Cost);

where MemoisedMLModel calls MLModel whenever we encounter a given
value of Cost for the first time.

Diff Detail

Event Timeline

kazu created this revision.Dec 2 2022, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 2:59 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
kazu requested review of this revision.Dec 2 2022, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 2:59 PM
kazu added a reviewer: mtrofin.Dec 2 2022, 3:00 PM

What do you mean by "trainer introduces noise"?

llvm/lib/Analysis/InlineOrder.cpp
243

please initialize it at decl.

272

this could be a non-static member with the user of the priority, to avoid the data hanging out for the duration of the compilation, after it's no longer needed. I assume it's static right now as a placeholder?