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/CallingConv.h"
19 #include "llvm/DataLayout.h"
20 #include "llvm/Instructions.h"
21 #include "llvm/IntrinsicInst.h"
22 #include "llvm/Module.h"
23 #include "llvm/Support/CallSite.h"
24 #include "llvm/Transforms/IPO/InlinerPass.h"
25 #include "llvm/Type.h"
31 class SimpleInliner : public Inliner {
32 InlineCostAnalyzer CA;
34 SimpleInliner() : Inliner(ID) {
35 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
37 SimpleInliner(int Threshold) : Inliner(ID, Threshold,
38 /*InsertLifetime*/true) {
39 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
41 static char ID; // Pass identification, replacement for typeid
42 InlineCost getInlineCost(CallSite CS) {
43 return CA.getInlineCost(CS, getInlineThreshold(CS));
45 using llvm::Pass::doInitialization;
46 virtual bool doInitialization(CallGraph &CG);
50 char SimpleInliner::ID = 0;
51 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
52 "Function Integration/Inlining", false, false)
53 INITIALIZE_AG_DEPENDENCY(CallGraph)
54 INITIALIZE_PASS_END(SimpleInliner, "inline",
55 "Function Integration/Inlining", false, false)
57 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
59 Pass *llvm::createFunctionInliningPass(int Threshold) {
60 return new SimpleInliner(Threshold);
63 // doInitialization - Initializes the vector of functions that have been
64 // annotated with the noinline attribute.
65 bool SimpleInliner::doInitialization(CallGraph &CG) {
66 CA.setDataLayout(getAnalysisIfAvailable<DataLayout>());