1 //===- InlineSimple.cpp - Code to perform simple function inlining --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements bottom-up inlining of functions into callees.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "inline"
15 #include "llvm/Transforms/IPO.h"
16 #include "llvm/Analysis/CallGraph.h"
17 #include "llvm/Analysis/InlineCost.h"
18 #include "llvm/IR/CallingConv.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/IntrinsicInst.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Support/CallSite.h"
25 #include "llvm/Transforms/IPO/InlinerPass.h"
31 /// \brief Actaul inliner pass implementation.
33 /// The common implementation of the inlining logic is shared between this
34 /// inliner pass and the always inliner pass. The two passes use different cost
35 /// analyses to determine when to inline.
36 class SimpleInliner : public Inliner {
37 InlineCostAnalyzer CA;
40 SimpleInliner() : Inliner(ID) {
41 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
44 SimpleInliner(int Threshold)
45 : Inliner(ID, Threshold, /*InsertLifetime*/ true) {
46 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
49 static char ID; // Pass identification, replacement for typeid
51 InlineCost getInlineCost(CallSite CS) {
52 return CA.getInlineCost(CS, getInlineThreshold(CS));
55 using llvm::Pass::doInitialization;
56 virtual bool doInitialization(CallGraph &CG);
59 } // end anonymous namespace
61 char SimpleInliner::ID = 0;
62 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
63 "Function Integration/Inlining", false, false)
64 INITIALIZE_AG_DEPENDENCY(CallGraph)
65 INITIALIZE_PASS_END(SimpleInliner, "inline",
66 "Function Integration/Inlining", false, false)
68 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
70 Pass *llvm::createFunctionInliningPass(int Threshold) {
71 return new SimpleInliner(Threshold);
74 // doInitialization - Initializes the vector of functions that have been
75 // annotated with the noinline attribute.
76 bool SimpleInliner::doInitialization(CallGraph &CG) {
77 CA.setDataLayout(getAnalysisIfAvailable<DataLayout>());