[InlineAdvisor] Allow replay of inline decisions for the CGSCC inliner from optimizat...
authormodimo <modimo@fb.com>
Mon, 25 Jan 2021 23:25:39 +0000 (15:25 -0800)
committermodimo <modimo@fb.com>
Mon, 25 Jan 2021 23:38:57 +0000 (15:38 -0800)
commitce7f9cdb50a98cef5ee6e232e45e16c150c966e9
tree4ba952bdfa1153364a579db7591e8df8b6bda8ab
parent3333244d77c44e8bb5af57027646596f7714ff62
[InlineAdvisor] Allow replay of inline decisions for the CGSCC inliner from optimization remarks

This change leverages the work done in D83743 to replay in the SampleProfile inliner to also be used in the CGSCC inliner. NOTE: currently restricted to non-ML advisors only.

The added switch `-cgscc-inline-replay=<remarks file>` will replay the inlining decisions in that file where the remarks file is generated via `-Rpass=inline`. The aim here is to make it easier to analyze changes that would modify inlining heuristics to be separated from this behavior. Doing so allows easier examination of assembly and runtime behavior compared to the baseline rather than trying to dig through the large churn caused by inlining.

In LTO compilation, since inlining is done twice you can separately specify replay by passing the flag to the FE (`-cgscc-inline-replay=`) and to the linker (`-Wl,cgscc-inline-replay=`) with the remarks generated from their respective places.

Testing on mysqld by comparing the inline decisions between base (generates remarks.txt) and diff (replay using identical input/tools with remarks.txt) and examining the inlining sites with `diff` shows 14,000 mismatches out of 247,341 for a ~94% replay accuracy. I believe this gap can be narrowed further though for the general case we may never achieve full accuracy. For my personal use, this is close enough to be representative: I set the baseline as the one generated by the replay on identical input/toolset and compare that to my modified input/toolset using the same replay.

Testing:
ninja check-llvm
newly added test correctly replays CGSCC inlining decisions

Reviewed By: mtrofin, wenlei

Differential Revision: https://reviews.llvm.org/D94334
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/include/llvm/Analysis/ReplayInlineAdvisor.h
llvm/include/llvm/Transforms/IPO/Inliner.h
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/ReplayInlineAdvisor.cpp
llvm/lib/Transforms/IPO/Inliner.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/test/Transforms/Inline/Inputs/cgscc-inline-replay.txt [new file with mode: 0644]
llvm/test/Transforms/Inline/cgscc-inline-replay.ll [new file with mode: 0644]