Chris Lattner | 237ef56 | 2003-08-31 19:10:30 +0000 | [diff] [blame] | 1 | //===- InlineSimple.cpp - Code to perform simple function inlining --------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | ca398dc | 2003-05-29 15:11:31 +0000 | [diff] [blame] | 10 | // This file implements bottom-up inlining of functions into callees. |
Chris Lattner | 0154505 | 2002-04-18 18:52:03 +0000 | [diff] [blame] | 11 | // |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tanya Lattner | 6f7426e | 2007-06-19 22:29:50 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "inline" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/Transforms/IPO.h" |
| 16 | #include "llvm/Analysis/CallGraph.h" |
| 17 | #include "llvm/Analysis/InlineCost.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 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" |
Chris Lattner | e544533 | 2003-08-24 06:59:28 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CallSite.h" |
Tanya Lattner | 6f7426e | 2007-06-19 22:29:50 +0000 | [diff] [blame] | 25 | #include "llvm/Transforms/IPO/InlinerPass.h" |
Tanya Lattner | 682f683 | 2007-06-06 21:59:26 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 869adc2 | 2003-11-21 21:46:09 +0000 | [diff] [blame] | 27 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 28 | |
Chris Lattner | bd0ef77 | 2002-02-26 21:46:54 +0000 | [diff] [blame] | 29 | namespace { |
Chris Lattner | 884d6c4 | 2003-10-06 15:52:43 +0000 | [diff] [blame] | 30 | |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 31 | /// \brief Actaul inliner pass implementation. |
| 32 | /// |
| 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 { |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 37 | InlineCostAnalysis *ICA; |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 38 | |
| 39 | public: |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 40 | SimpleInliner() : Inliner(ID), ICA(0) { |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 41 | initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
| 42 | } |
| 43 | |
| 44 | SimpleInliner(int Threshold) |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 45 | : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(0) { |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 46 | initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
| 47 | } |
| 48 | |
| 49 | static char ID; // Pass identification, replacement for typeid |
| 50 | |
| 51 | InlineCost getInlineCost(CallSite CS) { |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 52 | return ICA->getInlineCost(CS, getInlineThreshold(CS)); |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 55 | virtual bool runOnSCC(CallGraphSCC &SCC); |
| 56 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
Chandler Carruth | 5a47127 | 2013-01-21 11:39:14 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // end anonymous namespace |
Chris Lattner | bd0ef77 | 2002-02-26 21:46:54 +0000 | [diff] [blame] | 60 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 61 | char SimpleInliner::ID = 0; |
Owen Anderson | ae0a7bc | 2010-10-13 22:00:45 +0000 | [diff] [blame] | 62 | INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", |
| 63 | "Function Integration/Inlining", false, false) |
| 64 | INITIALIZE_AG_DEPENDENCY(CallGraph) |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 65 | INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis) |
Owen Anderson | ae0a7bc | 2010-10-13 22:00:45 +0000 | [diff] [blame] | 66 | INITIALIZE_PASS_END(SimpleInliner, "inline", |
Owen Anderson | ce665bd | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 67 | "Function Integration/Inlining", false, false) |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 68 | |
Devang Patel | c71ca3c | 2007-01-26 00:47:38 +0000 | [diff] [blame] | 69 | Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); } |
Chris Lattner | 869adc2 | 2003-11-21 21:46:09 +0000 | [diff] [blame] | 70 | |
Andrew Trick | 5c65541 | 2011-10-01 01:27:56 +0000 | [diff] [blame] | 71 | Pass *llvm::createFunctionInliningPass(int Threshold) { |
Chris Lattner | 120d053 | 2008-01-12 06:49:13 +0000 | [diff] [blame] | 72 | return new SimpleInliner(Threshold); |
| 73 | } |
| 74 | |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 75 | bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { |
| 76 | ICA = &getAnalysis<InlineCostAnalysis>(); |
| 77 | return Inliner::runOnSCC(SCC); |
Tanya Lattner | 682f683 | 2007-06-06 21:59:26 +0000 | [diff] [blame] | 78 | } |
Devang Patel | 6899b31 | 2007-07-25 18:00:25 +0000 | [diff] [blame] | 79 | |
Chandler Carruth | 86953b5 | 2013-01-21 11:39:18 +0000 | [diff] [blame^] | 80 | void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const { |
| 81 | AU.addRequired<InlineCostAnalysis>(); |
| 82 | Inliner::getAnalysisUsage(AU); |
| 83 | } |