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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-06-19 22:29:50 +00:00
|
|
|
#define DEBUG_TYPE "inline"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
#include "llvm/Analysis/InlineCost.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"
|
2003-08-24 06:59:28 +00:00
|
|
|
#include "llvm/Support/CallSite.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
|
|
|
|
2003-05-29 15:11:31 +00:00
|
|
|
namespace {
|
2003-10-06 15:52:43 +00:00
|
|
|
|
2013-01-21 11:39:14 +00:00
|
|
|
/// \brief Actaul inliner pass implementation.
|
|
|
|
///
|
|
|
|
/// 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:
|
2013-01-21 11:39:18 +00:00
|
|
|
SimpleInliner() : Inliner(ID), ICA(0) {
|
2013-01-21 11:39:14 +00:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleInliner(int Threshold)
|
2013-01-21 11:39:18 +00:00
|
|
|
: Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(0) {
|
2013-01-21 11:39:14 +00:00
|
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
|
|
|
|
InlineCost getInlineCost(CallSite CS) {
|
2013-01-21 11:39:18 +00:00
|
|
|
return ICA->getInlineCost(CS, getInlineThreshold(CS));
|
2013-01-21 11:39:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 11:39:18 +00:00
|
|
|
virtual bool runOnSCC(CallGraphSCC &SCC);
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
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)
|
|
|
|
INITIALIZE_AG_DEPENDENCY(CallGraph)
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|