This is an archive of the discontinued LLVM Phabricator instance.

[MLGO][AsmPrinter] Call-graph reward calculation
Needs ReviewPublic

Authored by eopXD on Nov 19 2022, 6:45 PM.

Details

Summary

Calculate 2 values characterizing a call graph, starting at an
externally-callable (non-local linkage) function.

One value is a latency estimator, the other is a icache pressure
estimator.

They both use basic block frequencies. When traversing the call graph,
the MBB frequencies of callees are weighed by the frequency of the
callsite, thus, ultimately, the frequencies used are relative to the
entrypoint (graph start).

The calculations are roughly similar, the difference is that for cache
pressure, we treat frequencies larger than 1 as 1 - i.e. probability of
execution (if a MBB is in a hot loop, its prob of execution is 1,
regardless of how hot the loop is).

The values are serialized in a section of the object file. This is
because the cache pressure uses actual MBB size in its calculation -
which is computed by the assembler. See
test/Transforms/Inline/ML/reward-o3.ll and the Inputs/parse_reward.py
accompanying it.

Diff Detail

Event Timeline

eopXD created this revision.Nov 19 2022, 6:45 PM
eopXD requested review of this revision.Nov 19 2022, 6:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2022, 6:45 PM
nikic resigned from this revision.Dec 8 2022, 7:17 AM

(Not familiar with either ML or AsmPrinter)

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
433

Should probably be conditional on CalculateReward.