2003-09-01 03:10:30 +08:00
|
|
|
//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
2003-05-29 23:11:31 +08:00
|
|
|
// This file implements bottom-up inlining of functions into callees.
|
2002-04-19 02:52:03 +08:00
|
|
|
//
|
2001-06-07 04:29:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2014-09-01 17:01:39 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2014-09-07 20:44:26 +08:00
|
|
|
#include "llvm/Analysis/AssumptionTracker.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
#include "llvm/Analysis/InlineCost.h"
|
2014-03-04 19:01:28 +08:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2013-01-02 19:36:10 +08: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-20 06:29:50 +08:00
|
|
|
#include "llvm/Transforms/IPO/InlinerPass.h"
|
2007-06-07 05:59:26 +08:00
|
|
|
|
2003-11-22 05:46:09 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2014-04-22 10:55:47 +08:00
|
|
|
#define DEBUG_TYPE "inline"
|
|
|
|
|
2003-05-29 23:11:31 +08:00
|
|
|
namespace {
|
2003-10-06 23:52:43 +08:00
|
|
|
|
2013-11-03 19:09:39 +08:00
|
|
|
/// \brief Actual inliner pass implementation.
|
2013-01-21 19:39:14 +08: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 19:39:18 +08:00
|
|
|
InlineCostAnalysis *ICA;
|
2013-01-21 19:39:14 +08:00
|
|
|
|
|
|
|
public:
|
2014-04-25 13:29:35 +08:00
|
|
|
SimpleInliner() : Inliner(ID), ICA(nullptr) {
|
2013-01-21 19:39:14 +08:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleInliner(int Threshold)
|
2014-04-25 13:29:35 +08:00
|
|
|
: Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(nullptr) {
|
2013-01-21 19:39:14 +08:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
|
2014-03-05 17:10:37 +08:00
|
|
|
InlineCost getInlineCost(CallSite CS) override {
|
2013-01-21 19:39:18 +08:00
|
|
|
return ICA->getInlineCost(CS, getInlineThreshold(CS));
|
2013-01-21 19:39:14 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 17:10:37 +08:00
|
|
|
bool runOnSCC(CallGraphSCC &SCC) override;
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
2013-01-21 19:39:14 +08:00
|
|
|
};
|
|
|
|
|
2014-03-13 00:12:36 +08:00
|
|
|
static int computeThresholdFromOptLevels(unsigned OptLevel,
|
|
|
|
unsigned SizeOptLevel) {
|
|
|
|
if (OptLevel > 2)
|
|
|
|
return 275;
|
2014-03-13 00:44:17 +08:00
|
|
|
if (SizeOptLevel == 1) // -Os
|
2014-03-13 00:12:36 +08:00
|
|
|
return 75;
|
2014-03-13 00:44:17 +08:00
|
|
|
if (SizeOptLevel == 2) // -Oz
|
2014-03-13 00:12:36 +08:00
|
|
|
return 25;
|
|
|
|
return 225;
|
|
|
|
}
|
|
|
|
|
2013-01-21 19:39:14 +08:00
|
|
|
} // end anonymous namespace
|
2003-05-29 23:11:31 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
char SimpleInliner::ID = 0;
|
2010-10-14 06:00:45 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
|
|
|
|
"Function Integration/Inlining", false, false)
|
2014-09-01 17:01:39 +08:00
|
|
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
2014-09-07 20:44:26 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionTracker)
|
2013-11-26 12:19:30 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
2013-01-21 19:39:18 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis)
|
2010-10-14 06:00:45 +08:00
|
|
|
INITIALIZE_PASS_END(SimpleInliner, "inline",
|
2010-10-08 06:25:06 +08:00
|
|
|
"Function Integration/Inlining", false, false)
|
2008-05-13 08:00:25 +08:00
|
|
|
|
2007-01-26 08:47:38 +08:00
|
|
|
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
2003-11-22 05:46:09 +08:00
|
|
|
|
2011-10-01 09:27:56 +08:00
|
|
|
Pass *llvm::createFunctionInliningPass(int Threshold) {
|
2008-01-12 14:49:13 +08:00
|
|
|
return new SimpleInliner(Threshold);
|
|
|
|
}
|
|
|
|
|
2014-03-13 00:12:36 +08:00
|
|
|
Pass *llvm::createFunctionInliningPass(unsigned OptLevel,
|
|
|
|
unsigned SizeOptLevel) {
|
|
|
|
return new SimpleInliner(
|
|
|
|
computeThresholdFromOptLevels(OptLevel, SizeOptLevel));
|
|
|
|
}
|
|
|
|
|
2013-01-21 19:39:18 +08:00
|
|
|
bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
|
|
|
|
ICA = &getAnalysis<InlineCostAnalysis>();
|
|
|
|
return Inliner::runOnSCC(SCC);
|
2007-06-07 05:59:26 +08:00
|
|
|
}
|
2007-07-26 02:00:25 +08:00
|
|
|
|
2013-01-21 19:39:18 +08:00
|
|
|
void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<InlineCostAnalysis>();
|
|
|
|
Inliner::getAnalysisUsage(AU);
|
|
|
|
}
|