2003-08-31 19:10:30 +00:00
|
|
|
//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2003-05-29 15:11:31 +00:00
|
|
|
// This file implements bottom-up inlining of functions into callees.
|
2002-04-18 18:52:03 +00:00
|
|
|
//
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2016-12-19 08:22:17 +00:00
|
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
|
#include "llvm/Analysis/InlineCost.h"
|
2016-06-09 22:23:21 +00:00
|
|
|
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
2015-09-09 17:55:00 +00:00
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2015-12-28 20:28:19 +00:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
2014-03-04 11:01:28 +00:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
|
#include "llvm/IR/Type.h"
|
2015-12-28 20:28:19 +00:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2016-12-20 03:15:32 +00:00
|
|
|
#include "llvm/Transforms/IPO/Inliner.h"
|
2007-06-06 21:59:26 +00:00
|
|
|
|
2003-11-21 21:46:09 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2014-04-22 02:55:47 +00:00
|
|
|
#define DEBUG_TYPE "inline"
|
|
|
|
|
|
2002-02-26 21:46:54 +00:00
|
|
|
namespace {
|
2003-10-06 15:52:43 +00:00
|
|
|
|
2013-11-03 11:09:39 +00:00
|
|
|
/// \brief Actual inliner pass implementation.
|
2013-01-21 11:39:14 +00:00
|
|
|
///
|
|
|
|
|
/// The common implementation of the inlining logic is shared between this
|
|
|
|
|
/// inliner pass and the always inliner pass. The two passes use different cost
|
|
|
|
|
/// analyses to determine when to inline.
|
2016-12-20 03:15:32 +00:00
|
|
|
class SimpleInliner : public LegacyInlinerBase {
|
2016-08-10 00:48:04 +00:00
|
|
|
|
|
|
|
|
InlineParams Params;
|
2013-01-21 11:39:14 +00:00
|
|
|
|
|
|
|
|
public:
|
2016-12-20 03:15:32 +00:00
|
|
|
SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
|
2013-01-21 11:39:14 +00:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 03:15:32 +00:00
|
|
|
explicit SimpleInliner(InlineParams Params)
|
2017-01-13 14:39:03 +00:00
|
|
|
: LegacyInlinerBase(ID), Params(std::move(Params)) {
|
2013-01-21 11:39:14 +00:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
|
|
2014-03-05 09:10:37 +00:00
|
|
|
InlineCost getInlineCost(CallSite CS) override {
|
2015-12-28 20:28:19 +00:00
|
|
|
Function *Callee = CS.getCalledFunction();
|
|
|
|
|
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
|
2016-12-19 08:22:17 +00:00
|
|
|
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
|
|
|
|
|
[&](Function &F) -> AssumptionCache & {
|
|
|
|
|
return ACT->getAssumptionCache(F);
|
|
|
|
|
};
|
2017-01-20 22:44:04 +00:00
|
|
|
return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache,
|
|
|
|
|
/*GetBFI=*/None, PSI);
|
2013-01-21 11:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-05 09:10:37 +00:00
|
|
|
bool runOnSCC(CallGraphSCC &SCC) override;
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
2015-12-28 20:28:19 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TargetTransformInfoWrapperPass *TTIWP;
|
2016-08-10 00:48:04 +00:00
|
|
|
|
2013-01-21 11:39:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
2002-02-26 21:46:54 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
char SimpleInliner::ID = 0;
|
2016-08-03 01:02:31 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
|
|
|
|
|
false, false)
|
2016-12-19 08:22:17 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
2013-11-26 04:19:30 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
2016-06-09 22:23:21 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
|
2015-12-28 20:28:19 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
2015-09-09 17:55:00 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
2016-08-03 01:02:31 +00:00
|
|
|
INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
|
|
|
|
|
false, false)
|
2008-05-13 00:00:25 +00:00
|
|
|
|
2007-01-26 00:47:38 +00:00
|
|
|
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
2003-11-21 21:46:09 +00:00
|
|
|
|
2011-10-01 01:27:56 +00:00
|
|
|
Pass *llvm::createFunctionInliningPass(int Threshold) {
|
2016-08-10 00:48:04 +00:00
|
|
|
return new SimpleInliner(llvm::getInlineParams(Threshold));
|
2008-01-12 06:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-12 16:12:36 +00:00
|
|
|
Pass *llvm::createFunctionInliningPass(unsigned OptLevel,
|
|
|
|
|
unsigned SizeOptLevel) {
|
2016-08-10 00:48:04 +00:00
|
|
|
return new SimpleInliner(llvm::getInlineParams(OptLevel, SizeOptLevel));
|
2014-03-12 16:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-11 18:24:08 +00:00
|
|
|
Pass *llvm::createFunctionInliningPass(InlineParams &Params) {
|
|
|
|
|
return new SimpleInliner(Params);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 11:39:18 +00:00
|
|
|
bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
|
2015-12-28 20:28:19 +00:00
|
|
|
TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
|
2016-12-20 03:15:32 +00:00
|
|
|
return LegacyInlinerBase::runOnSCC(SCC);
|
2007-06-06 21:59:26 +00:00
|
|
|
}
|
2007-07-25 18:00:25 +00:00
|
|
|
|
2013-01-21 11:39:18 +00:00
|
|
|
void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
|
2015-12-28 20:28:19 +00:00
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
2016-12-20 03:15:32 +00:00
|
|
|
LegacyInlinerBase::getAnalysisUsage(AU);
|
2013-01-21 11:39:18 +00:00
|
|
|
}
|