[InlineAdvisor] New inliner advisor to replay inlining from optimization remarks
authorWenlei He <aktoon@gmail.com>
Sat, 15 Aug 2020 21:52:10 +0000 (14:52 -0700)
committerWenlei He <aktoon@gmail.com>
Sun, 16 Aug 2020 03:17:21 +0000 (20:17 -0700)
commit577e58bcc754cea2ae0358a5359ac5cc48d8e9d0
tree0a47e9be625abc6f52532eda6ed8b9e9be21c273
parent5b50a1656ac365d495f568a1f68afb1e215712df
[InlineAdvisor] New inliner advisor to replay inlining from optimization remarks

This change added a new inline advisor that takes optimization remarks from previous inlining as input, and provides the decision as advice so current inlining can replay inline decisions of a different compilation. Dwarf inline stack with line and discriminator is used as anchor for call sites including call context. The change can be useful for Inliner tuning as it provides a channel to allow external input for tweaking inline decisions. Existing alternatives like alwaysinline attribute is per-function, not per-callsite. Per-callsite inline intrinsic can be another solution (not yet existing), but it's intrusive to implement and also does not differentiate call context.

A switch -sample-profile-inline-replay=<inline_remarks_file> is added to hook up the new inline advisor with SampleProfileLoader's inline decision for replay. Since SampleProfileLoader does top-down inlining, inline decision can be specialized for each call context, hence we should be able to replay inlining accurately. However with a bottom-up inliner like CGSCC inlining, the replay can be limited due to lack of specialization for different call context. Apart from that limitation, the new inline advisor can still be used by regular CGSCC inliner later if needed for tuning purpose.

This is a resubmit of https://reviews.llvm.org/D83743
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/include/llvm/Analysis/ReplayInlineAdvisor.h [new file with mode: 0644]
llvm/lib/Analysis/CMakeLists.txt
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/ReplayInlineAdvisor.cpp [new file with mode: 0644]
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/test/Transforms/SampleProfile/Inputs/inline-replay.txt [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/inline-replay.ll [new file with mode: 0644]