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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2014-09-01 09:01:39 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2015-01-04 12:03:27 +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"
|
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"
|
2007-06-19 22:29:50 +00:00
|
|
|
#include "llvm/Transforms/IPO/InlinerPass.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"
|
|
|
|
|
2003-05-29 15:11:31 +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.
|
|
|
|
class SimpleInliner : public Inliner {
|
2013-01-21 11:39:18 +00:00
|
|
|
InlineCostAnalysis *ICA;
|
2013-01-21 11:39:14 +00:00
|
|
|
|
|
|
|
public:
|
2014-04-25 05:29:35 +00:00
|
|
|
SimpleInliner() : Inliner(ID), ICA(nullptr) {
|
2013-01-21 11:39:14 +00:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleInliner(int Threshold)
|
2014-04-25 05:29:35 +00:00
|
|
|
: Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(nullptr) {
|
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 {
|
2013-01-21 11:39:18 +00:00
|
|
|
return ICA->getInlineCost(CS, getInlineThreshold(CS));
|
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;
|
2013-01-21 11:39:14 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 16:12:36 +00:00
|
|
|
static int computeThresholdFromOptLevels(unsigned OptLevel,
|
|
|
|
unsigned SizeOptLevel) {
|
|
|
|
if (OptLevel > 2)
|
|
|
|
return 275;
|
2014-03-12 16:44:17 +00:00
|
|
|
if (SizeOptLevel == 1) // -Os
|
2014-03-12 16:12:36 +00:00
|
|
|
return 75;
|
2014-03-12 16:44:17 +00:00
|
|
|
if (SizeOptLevel == 2) // -Oz
|
2014-03-12 16:12:36 +00:00
|
|
|
return 25;
|
|
|
|
return 225;
|
|
|
|
}
|
|
|
|
|
2013-01-21 11:39:14 +00:00
|
|
|
} // end anonymous namespace
|
2003-05-29 15:11:31 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
char SimpleInliner::ID = 0;
|
2010-10-13 22:00:45 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
|
|
|
|
"Function Integration/Inlining", false, false)
|
2014-09-01 09:01:39 +00:00
|
|
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
2015-01-04 12:03:27 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
2013-11-26 04:19:30 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
2013-01-21 11:39:18 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis)
|
2010-10-13 22:00:45 +00:00
|
|
|
INITIALIZE_PASS_END(SimpleInliner, "inline",
|
2010-10-07 22:25:06 +00:00
|
|
|
"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) {
|
2008-01-12 06:49:13 +00:00
|
|
|
return new SimpleInliner(Threshold);
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:12:36 +00:00
|
|
|
Pass *llvm::createFunctionInliningPass(unsigned OptLevel,
|
|
|
|
unsigned SizeOptLevel) {
|
|
|
|
return new SimpleInliner(
|
|
|
|
computeThresholdFromOptLevels(OptLevel, SizeOptLevel));
|
|
|
|
}
|
|
|
|
|
2013-01-21 11:39:18 +00:00
|
|
|
bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
|
|
|
|
ICA = &getAnalysis<InlineCostAnalysis>();
|
|
|
|
return Inliner::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 {
|
|
|
|
AU.addRequired<InlineCostAnalysis>();
|
|
|
|
Inliner::getAnalysisUsage(AU);
|
|
|
|
}
|