Page MenuHomePhabricator

[PGO] Add Value Profiling for Loop Trip Count (WIP)
Needs ReviewPublic

Authored by w2yehia on Nov 25 2019, 11:01 AM.
This revision needs review, but there are no reviewers specified.



This is Work In Progress.
I'm posting here to solicit feedback.
One motivation for doing this is to improve the loop versioning currently done by LoopVectorizer (LoopVectorizePass::processLoop).

For certain loops, (TBD what kind), we would like to profile the exact trip count and the
frequency of that trip count. In other words, we want to value profile an expression that
represents the trip count of a loop, whenever it is computable.
The instrumentation point is the loop pre-header, and the value profile (VP) metadata (MD)
is appended to the llvm.loop MD which sits on the branch instruction of the latch block.
In order to find or create a loop pre-header, we run the LoopSimplifyPass pass in the
pipeline for the new pass manager.
The logic in LoopInfoPlugin in determines the instrumentation
point (needed during the -fprofile-generate step) and what to associate the MD (needed
during the -fprofile-use step).
Instead of having the plugin decide the exact instruction for associating the MD to, we allow
the plugin to select a Loop to associate it to, and then in PGOUseFunc::annotateValueSites
in PGOInstrumentation.cpp we call setLoopTripCount(MD) on the Loop object.
This way, the Loop object maintains control (set/get) over what MD is associated to the
loop id MD node (a.k.a. the !llvm.loop MD).

Diff Detail


Event Timeline

w2yehia created this revision.Nov 25 2019, 11:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2019, 11:01 AM
w2yehia edited the summary of this revision. (Show Details)Nov 25 2019, 11:20 AM
w2yehia edited the summary of this revision. (Show Details)Nov 26 2019, 7:22 AM
fhahn added a subscriber: fhahn.Nov 26 2019, 7:42 AM
w2yehia edited the summary of this revision. (Show Details)Nov 26 2019, 8:52 AM