[Inlining] Teach shouldBeDeferred to take the total cost into account
authorKazu Hirata <kazu@google.com>
Mon, 4 May 2020 20:49:27 +0000 (13:49 -0700)
committerKazu Hirata <kazu@google.com>
Tue, 5 May 2020 18:02:06 +0000 (11:02 -0700)
commite8984fe65b949c6e3fcb41053ed7e5bcd2fe11e1
tree24d5c8e2728969e04c4daf0420bd61631407e65b
parent61d5b0e66394d61947d61861685b4223214f023e
[Inlining] Teach shouldBeDeferred to take the total cost into account

Summary:
This patch teaches shouldBeDeferred to take into account the total
cost of inlining.

Suppose we have a call hierarchy {A1,A2,A3,...}->B->C.  (Each of A1,
A2, A3, ... calls B, which in turn calls C.)

Without this patch, shouldBeDeferred essentially returns true if

  TotalSecondaryCost < IC.getCost()

where TotalSecondaryCost is the total cost of inlining B into As.
This means that if B is a small wraper function, for example, it would
get inlined into all of As.  In turn, C gets inlined into all of As.
In other words, shouldBeDeferred ignores the cost of inlining C into
each of As.

This patch adds an option, inline-deferral-scale, to replace the
expression above with:

  TotalCost < Allowance

where

- TotalCost is TotalSecondaryCost + IC.getCost() * # of As, and
- Allowance is IC.getCost() * Scale

For now, the new option defaults to -1, disabling the new scheme.

Reviewers: davidxl

Subscribers: eraman, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79138
llvm/lib/Transforms/IPO/Inliner.cpp