2017-09-20 12:25:58 +08:00
|
|
|
//===- AMDGPUInline.cpp - Code to perform simple function inlining --------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-20 12:25:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This is AMDGPU specific replacement of the standard inliner.
|
2017-09-20 12:25:58 +08:00
|
|
|
/// The main purpose is to account for the fact that calls not only expensive
|
|
|
|
/// on the AMDGPU, but much more expensive if a private memory pointer is
|
|
|
|
/// passed to a function as an argument. In this situation, we are unable to
|
|
|
|
/// eliminate private memory in the caller unless inlined and end up with slow
|
|
|
|
/// and expensive scratch access. Thus, we boost the inline threshold for such
|
|
|
|
/// functions here.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
|
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
#include "llvm/Analysis/InlineCost.h"
|
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2017-09-20 12:25:58 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-09-20 12:25:58 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2017-09-20 12:25:58 +08:00
|
|
|
#include "llvm/Transforms/IPO/Inliner.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "inline"
|
|
|
|
|
|
|
|
static cl::opt<int>
|
[AMDGPU] Tune inlining parameters for AMDGPU target (part 2)
Summary:
Most of IR instructions got better code size estimations after commit 47a5c36b.
So default parameters values should be updated to improve inlining and
unrolling for the target.
Reviewers: rampitec, arsenm
Reviewed By: rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, zzheng, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70391
2019-11-18 21:42:34 +08:00
|
|
|
ArgAllocaCost("amdgpu-inline-arg-alloca-cost", cl::Hidden, cl::init(4000),
|
2017-09-20 12:25:58 +08:00
|
|
|
cl::desc("Cost of alloca argument"));
|
|
|
|
|
|
|
|
// If the amount of scratch memory to eliminate exceeds our ability to allocate
|
2018-11-07 22:35:36 +08:00
|
|
|
// it into registers we gain nothing by aggressively inlining functions for that
|
2017-09-20 12:25:58 +08:00
|
|
|
// heuristic.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
ArgAllocaCutoff("amdgpu-inline-arg-alloca-cutoff", cl::Hidden, cl::init(256),
|
|
|
|
cl::desc("Maximum alloca size to use for inline cost"));
|
|
|
|
|
2019-06-07 20:16:46 +08:00
|
|
|
// Inliner constraint to achieve reasonable compilation time
|
|
|
|
static cl::opt<size_t>
|
[AMDGPU] Improve code size cost model
Summary:
Added estimation for zero size insertelement, extractelement
and llvm.fabs operators.
Updated inline/unroll parameters default values.
Reviewers: rampitec, arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68881
llvm-svn: 375109
2019-10-17 20:15:35 +08:00
|
|
|
MaxBB("amdgpu-inline-max-bb", cl::Hidden, cl::init(1100),
|
2019-06-07 20:16:46 +08:00
|
|
|
cl::desc("Maximum BB number allowed in a function after inlining"
|
|
|
|
" (compile time constraint)"));
|
|
|
|
|
2017-09-20 12:25:58 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUInliner : public LegacyInlinerBase {
|
|
|
|
|
|
|
|
public:
|
|
|
|
AMDGPUInliner() : LegacyInlinerBase(ID) {
|
|
|
|
initializeAMDGPUInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
Params = getInlineParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
unsigned getInlineThreshold(CallBase &CB) const;
|
2017-09-20 12:25:58 +08:00
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
InlineCost getInlineCost(CallBase &CB) override;
|
2017-09-20 12:25:58 +08:00
|
|
|
|
|
|
|
bool runOnSCC(CallGraphSCC &SCC) override;
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TargetTransformInfoWrapperPass *TTIWP;
|
|
|
|
|
|
|
|
InlineParams Params;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char AMDGPUInliner::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(AMDGPUInliner, "amdgpu-inline",
|
|
|
|
"AMDGPU Function Integration/Inlining", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(AMDGPUInliner, "amdgpu-inline",
|
|
|
|
"AMDGPU Function Integration/Inlining", false, false)
|
|
|
|
|
|
|
|
Pass *llvm::createAMDGPUFunctionInliningPass() { return new AMDGPUInliner(); }
|
|
|
|
|
|
|
|
bool AMDGPUInliner::runOnSCC(CallGraphSCC &SCC) {
|
|
|
|
TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
|
|
|
|
return LegacyInlinerBase::runOnSCC(SCC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInliner::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
|
|
|
LegacyInlinerBase::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
unsigned AMDGPUInliner::getInlineThreshold(CallBase &CB) const {
|
2017-09-20 12:25:58 +08:00
|
|
|
int Thres = Params.DefaultThreshold;
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
Function *Caller = CB.getCaller();
|
2017-09-20 12:25:58 +08:00
|
|
|
// Listen to the inlinehint attribute when it would increase the threshold
|
|
|
|
// and the caller does not need to minimize its size.
|
2020-04-14 07:39:52 +08:00
|
|
|
Function *Callee = CB.getCalledFunction();
|
2017-09-20 12:25:58 +08:00
|
|
|
bool InlineHint = Callee && !Callee->isDeclaration() &&
|
|
|
|
Callee->hasFnAttribute(Attribute::InlineHint);
|
|
|
|
if (InlineHint && Params.HintThreshold && Params.HintThreshold > Thres
|
|
|
|
&& !Caller->hasFnAttribute(Attribute::MinSize))
|
2019-06-01 00:19:26 +08:00
|
|
|
Thres = Params.HintThreshold.getValue() *
|
|
|
|
TTIWP->getTTI(*Callee).getInliningThresholdMultiplier();
|
2017-09-20 12:25:58 +08:00
|
|
|
|
|
|
|
const DataLayout &DL = Caller->getParent()->getDataLayout();
|
|
|
|
if (!Callee)
|
|
|
|
return (unsigned)Thres;
|
|
|
|
|
|
|
|
// If we have a pointer to private array passed into a function
|
|
|
|
// it will not be optimized out, leaving scratch usage.
|
|
|
|
// Increase the inline threshold to allow inliniting in this case.
|
|
|
|
uint64_t AllocaSize = 0;
|
|
|
|
SmallPtrSet<const AllocaInst *, 8> AIVisited;
|
2020-04-14 07:39:52 +08:00
|
|
|
for (Value *PtrArg : CB.args()) {
|
2019-05-25 00:52:35 +08:00
|
|
|
PointerType *Ty = dyn_cast<PointerType>(PtrArg->getType());
|
|
|
|
if (!Ty || (Ty->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS &&
|
|
|
|
Ty->getAddressSpace() != AMDGPUAS::FLAT_ADDRESS))
|
2017-09-20 12:25:58 +08:00
|
|
|
continue;
|
2019-05-25 00:52:35 +08:00
|
|
|
|
2020-07-31 17:09:54 +08:00
|
|
|
PtrArg = getUnderlyingObject(PtrArg);
|
2017-09-20 12:25:58 +08:00
|
|
|
if (const AllocaInst *AI = dyn_cast<AllocaInst>(PtrArg)) {
|
|
|
|
if (!AI->isStaticAlloca() || !AIVisited.insert(AI).second)
|
|
|
|
continue;
|
|
|
|
AllocaSize += DL.getTypeAllocSize(AI->getAllocatedType());
|
|
|
|
// If the amount of stack memory is excessive we will not be able
|
|
|
|
// to get rid of the scratch anyway, bail out.
|
|
|
|
if (AllocaSize > ArgAllocaCutoff) {
|
|
|
|
AllocaSize = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (AllocaSize)
|
|
|
|
Thres += ArgAllocaCost;
|
|
|
|
|
|
|
|
return (unsigned)Thres;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if call is just a wrapper around another call.
|
|
|
|
// In this case we only have call and ret instructions.
|
2020-04-14 07:39:52 +08:00
|
|
|
static bool isWrapperOnlyCall(CallBase &CB) {
|
|
|
|
Function *Callee = CB.getCalledFunction();
|
2017-09-20 12:25:58 +08:00
|
|
|
if (!Callee || Callee->size() != 1)
|
|
|
|
return false;
|
|
|
|
const BasicBlock &BB = Callee->getEntryBlock();
|
|
|
|
if (const Instruction *I = BB.getFirstNonPHI()) {
|
|
|
|
if (!isa<CallInst>(I)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isa<ReturnInst>(*std::next(I->getIterator()))) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " Wrapper only call detected: "
|
|
|
|
<< Callee->getName() << '\n');
|
2017-09-20 12:25:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
InlineCost AMDGPUInliner::getInlineCost(CallBase &CB) {
|
|
|
|
Function *Callee = CB.getCalledFunction();
|
|
|
|
Function *Caller = CB.getCaller();
|
2017-09-20 12:25:58 +08:00
|
|
|
|
Enrich inline messages
Summary:
This patch improves Inliner to provide causes/reasons for negative inline decisions.
1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message.
2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision.
3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost.
4. Adjusted tests for changed printing.
Patch by: yrouban (Yevgeny Rouban)
Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00
Reviewed By: tejohnson, xbolva00
Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith
Differential Revision: https://reviews.llvm.org/D49412
llvm-svn: 338969
2018-08-05 22:53:08 +08:00
|
|
|
if (!Callee || Callee->isDeclaration())
|
|
|
|
return llvm::InlineCost::getNever("undefined callee");
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
if (CB.isNoInline())
|
Enrich inline messages
Summary:
This patch improves Inliner to provide causes/reasons for negative inline decisions.
1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message.
2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision.
3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost.
4. Adjusted tests for changed printing.
Patch by: yrouban (Yevgeny Rouban)
Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00
Reviewed By: tejohnson, xbolva00
Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith
Differential Revision: https://reviews.llvm.org/D49412
llvm-svn: 338969
2018-08-05 22:53:08 +08:00
|
|
|
return llvm::InlineCost::getNever("noinline");
|
|
|
|
|
2019-04-30 01:38:18 +08:00
|
|
|
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
|
Enrich inline messages
Summary:
This patch improves Inliner to provide causes/reasons for negative inline decisions.
1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message.
2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision.
3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost.
4. Adjusted tests for changed printing.
Patch by: yrouban (Yevgeny Rouban)
Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00
Reviewed By: tejohnson, xbolva00
Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith
Differential Revision: https://reviews.llvm.org/D49412
llvm-svn: 338969
2018-08-05 22:53:08 +08:00
|
|
|
if (!TTI.areInlineCompatible(Caller, Callee))
|
|
|
|
return llvm::InlineCost::getNever("incompatible");
|
2017-09-20 12:25:58 +08:00
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
if (CB.hasFnAttr(Attribute::AlwaysInline)) {
|
2019-02-01 18:44:43 +08:00
|
|
|
auto IsViable = isInlineViable(*Callee);
|
[NFC] Refactor InlineResult for readability
Summary:
InlineResult is used both in APIs assessing whether a call site is
inlinable (e.g. llvm::isInlineViable) as well as in the function
inlining utility (llvm::InlineFunction). It means slightly different
things (can/should inlining happen, vs did it happen), and the
implicit casting may introduce ambiguity (casting from 'false' in
InlineFunction will default a message about hight costs,
which is incorrect here).
The change renames the type to a more generic name, and disables
implicit constructors.
Reviewers: eraman, davidxl
Reviewed By: davidxl
Subscribers: kerbowa, arsenm, jvesely, nhaehnle, eraman, hiraditya, haicheng, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72744
2020-01-16 05:33:58 +08:00
|
|
|
if (IsViable.isSuccess())
|
Enrich inline messages
Summary:
This patch improves Inliner to provide causes/reasons for negative inline decisions.
1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message.
2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision.
3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost.
4. Adjusted tests for changed printing.
Patch by: yrouban (Yevgeny Rouban)
Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00
Reviewed By: tejohnson, xbolva00
Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith
Differential Revision: https://reviews.llvm.org/D49412
llvm-svn: 338969
2018-08-05 22:53:08 +08:00
|
|
|
return llvm::InlineCost::getAlways("alwaysinline viable");
|
[NFC] Refactor InlineResult for readability
Summary:
InlineResult is used both in APIs assessing whether a call site is
inlinable (e.g. llvm::isInlineViable) as well as in the function
inlining utility (llvm::InlineFunction). It means slightly different
things (can/should inlining happen, vs did it happen), and the
implicit casting may introduce ambiguity (casting from 'false' in
InlineFunction will default a message about hight costs,
which is incorrect here).
The change renames the type to a more generic name, and disables
implicit constructors.
Reviewers: eraman, davidxl
Reviewed By: davidxl
Subscribers: kerbowa, arsenm, jvesely, nhaehnle, eraman, hiraditya, haicheng, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72744
2020-01-16 05:33:58 +08:00
|
|
|
return llvm::InlineCost::getNever(IsViable.getFailureReason());
|
2017-09-20 12:25:58 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 07:39:52 +08:00
|
|
|
if (isWrapperOnlyCall(CB))
|
Enrich inline messages
Summary:
This patch improves Inliner to provide causes/reasons for negative inline decisions.
1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message.
2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision.
3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost.
4. Adjusted tests for changed printing.
Patch by: yrouban (Yevgeny Rouban)
Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00
Reviewed By: tejohnson, xbolva00
Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith
Differential Revision: https://reviews.llvm.org/D49412
llvm-svn: 338969
2018-08-05 22:53:08 +08:00
|
|
|
return llvm::InlineCost::getAlways("wrapper-only call");
|
2017-09-20 12:25:58 +08:00
|
|
|
|
|
|
|
InlineParams LocalParams = Params;
|
2020-04-14 07:39:52 +08:00
|
|
|
LocalParams.DefaultThreshold = (int)getInlineThreshold(CB);
|
2017-09-20 12:25:58 +08:00
|
|
|
bool RemarksEnabled = false;
|
|
|
|
const auto &BBs = Caller->getBasicBlockList();
|
|
|
|
if (!BBs.empty()) {
|
|
|
|
auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
|
|
|
|
if (DI.isEnabled())
|
|
|
|
RemarksEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptimizationRemarkEmitter ORE(Caller);
|
2020-05-15 13:38:41 +08:00
|
|
|
auto GetAssumptionCache = [this](Function &F) -> AssumptionCache & {
|
2017-09-20 12:25:58 +08:00
|
|
|
return ACT->getAssumptionCache(F);
|
|
|
|
};
|
|
|
|
|
2020-05-15 13:38:41 +08:00
|
|
|
auto IC = llvm::getInlineCost(CB, Callee, LocalParams, TTI,
|
|
|
|
GetAssumptionCache, GetTLI, nullptr, PSI,
|
|
|
|
RemarksEnabled ? &ORE : nullptr);
|
2019-06-07 20:16:46 +08:00
|
|
|
|
[AMDGPU] Don't constrain callees with inlinehint from inlining on MaxBB check
Summary: Function bodies marked inline in an opencl source are eliminated but MaxBB check may prevent inlining them leaving undefined references.
Reviewers: rampitec, arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, Anastasia, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63337
llvm-svn: 363418
2019-06-15 00:37:33 +08:00
|
|
|
if (IC && !IC.isAlways() && !Callee->hasFnAttribute(Attribute::InlineHint)) {
|
2019-06-07 20:16:46 +08:00
|
|
|
// Single BB does not increase total BB amount, thus subtract 1
|
|
|
|
size_t Size = Caller->size() + Callee->size() - 1;
|
|
|
|
if (MaxBB && Size > MaxBB)
|
|
|
|
return llvm::InlineCost::getNever("max number of bb exceeded");
|
|
|
|
}
|
|
|
|
return IC;
|
2017-09-20 12:25:58 +08:00
|
|
|
}
|