LLVM API Documentation
00001 //===- InlineSimple.cpp - Code to perform simple function inlining --------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements bottom-up inlining of functions into callees. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #define DEBUG_TYPE "inline" 00015 #include "llvm/Transforms/IPO.h" 00016 #include "llvm/Analysis/CallGraph.h" 00017 #include "llvm/Analysis/InlineCost.h" 00018 #include "llvm/IR/CallingConv.h" 00019 #include "llvm/IR/DataLayout.h" 00020 #include "llvm/IR/Instructions.h" 00021 #include "llvm/IR/IntrinsicInst.h" 00022 #include "llvm/IR/Module.h" 00023 #include "llvm/IR/Type.h" 00024 #include "llvm/Support/CallSite.h" 00025 #include "llvm/Transforms/IPO/InlinerPass.h" 00026 00027 using namespace llvm; 00028 00029 namespace { 00030 00031 /// \brief Actaul inliner pass implementation. 00032 /// 00033 /// The common implementation of the inlining logic is shared between this 00034 /// inliner pass and the always inliner pass. The two passes use different cost 00035 /// analyses to determine when to inline. 00036 class SimpleInliner : public Inliner { 00037 InlineCostAnalysis *ICA; 00038 00039 public: 00040 SimpleInliner() : Inliner(ID), ICA(0) { 00041 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); 00042 } 00043 00044 SimpleInliner(int Threshold) 00045 : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(0) { 00046 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); 00047 } 00048 00049 static char ID; // Pass identification, replacement for typeid 00050 00051 InlineCost getInlineCost(CallSite CS) { 00052 return ICA->getInlineCost(CS, getInlineThreshold(CS)); 00053 } 00054 00055 virtual bool runOnSCC(CallGraphSCC &SCC); 00056 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 00057 }; 00058 00059 } // end anonymous namespace 00060 00061 char SimpleInliner::ID = 0; 00062 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", 00063 "Function Integration/Inlining", false, false) 00064 INITIALIZE_AG_DEPENDENCY(CallGraph) 00065 INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis) 00066 INITIALIZE_PASS_END(SimpleInliner, "inline", 00067 "Function Integration/Inlining", false, false) 00068 00069 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); } 00070 00071 Pass *llvm::createFunctionInliningPass(int Threshold) { 00072 return new SimpleInliner(Threshold); 00073 } 00074 00075 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { 00076 ICA = &getAnalysis<InlineCostAnalysis>(); 00077 return Inliner::runOnSCC(SCC); 00078 } 00079 00080 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const { 00081 AU.addRequired<InlineCostAnalysis>(); 00082 Inliner::getAnalysisUsage(AU); 00083 }