blob: 9c5feba08b6225b22eca23f764af59216c715b95 [file] [log] [blame]
Chris Lattner237ef562003-08-31 19:10:30 +00001//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
Misha Brukmanfd939082005-04-21 23:48:37 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanfd939082005-04-21 23:48:37 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +00009//
Chris Lattnerca398dc2003-05-29 15:11:31 +000010// This file implements bottom-up inlining of functions into callees.
Chris Lattner01545052002-04-18 18:52:03 +000011//
Chris Lattner00950542001-06-06 20:29:01 +000012//===----------------------------------------------------------------------===//
13
Tanya Lattner6f7426e2007-06-19 22:29:50 +000014#define DEBUG_TYPE "inline"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "llvm/Transforms/IPO.h"
16#include "llvm/Analysis/CallGraph.h"
17#include "llvm/Analysis/InlineCost.h"
Chris Lattner49fbff42005-05-18 04:30:33 +000018#include "llvm/CallingConv.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000019#include "llvm/DataLayout.h"
Chris Lattner869adc22003-11-21 21:46:09 +000020#include "llvm/Instructions.h"
Chris Lattner8db93f12004-11-22 17:21:44 +000021#include "llvm/IntrinsicInst.h"
Tanya Lattner682f6832007-06-06 21:59:26 +000022#include "llvm/Module.h"
Chris Lattnere5445332003-08-24 06:59:28 +000023#include "llvm/Support/CallSite.h"
Tanya Lattner6f7426e2007-06-19 22:29:50 +000024#include "llvm/Transforms/IPO/InlinerPass.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/Type.h"
Tanya Lattner682f6832007-06-06 21:59:26 +000026
Chris Lattner869adc22003-11-21 21:46:09 +000027using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000028
Chris Lattnerbd0ef772002-02-26 21:46:54 +000029namespace {
Chris Lattner884d6c42003-10-06 15:52:43 +000030
Nick Lewycky6726b6d2009-10-25 06:33:48 +000031 class SimpleInliner : public Inliner {
Devang Patel6899b312007-07-25 18:00:25 +000032 InlineCostAnalyzer CA;
Chris Lattner884d6c42003-10-06 15:52:43 +000033 public:
Owen Anderson081c34b2010-10-19 17:21:58 +000034 SimpleInliner() : Inliner(ID) {
35 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
36 }
Chad Rosierdfba3ad2012-02-25 03:07:57 +000037 SimpleInliner(int Threshold) : Inliner(ID, Threshold,
38 /*InsertLifetime*/true) {
Owen Anderson081c34b2010-10-19 17:21:58 +000039 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
40 }
Nick Lewyckyecd94c82007-05-06 13:37:16 +000041 static char ID; // Pass identification, replacement for typeid
Daniel Dunbarc5e1ec42008-10-30 19:26:59 +000042 InlineCost getInlineCost(CallSite CS) {
Chandler Carruthf2286b02012-03-31 12:42:41 +000043 return CA.getInlineCost(CS, getInlineThreshold(CS));
Evan Cheng8d84d5b2008-03-24 06:37:48 +000044 }
Matt Beaumont-Gayee721152012-12-04 05:41:27 +000045 using llvm::Pass::doInitialization;
Tanya Lattner682f6832007-06-06 21:59:26 +000046 virtual bool doInitialization(CallGraph &CG);
Chris Lattnerbd0ef772002-02-26 21:46:54 +000047 };
48}
49
Dan Gohman844731a2008-05-13 00:00:25 +000050char SimpleInliner::ID = 0;
Owen Andersonae0a7bc2010-10-13 22:00:45 +000051INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
52 "Function Integration/Inlining", false, false)
53INITIALIZE_AG_DEPENDENCY(CallGraph)
54INITIALIZE_PASS_END(SimpleInliner, "inline",
Owen Andersonce665bd2010-10-07 22:25:06 +000055 "Function Integration/Inlining", false, false)
Dan Gohman844731a2008-05-13 00:00:25 +000056
Devang Patelc71ca3c2007-01-26 00:47:38 +000057Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
Chris Lattner869adc22003-11-21 21:46:09 +000058
Andrew Trick5c655412011-10-01 01:27:56 +000059Pass *llvm::createFunctionInliningPass(int Threshold) {
Chris Lattner120d0532008-01-12 06:49:13 +000060 return new SimpleInliner(Threshold);
61}
62
Tanya Lattner682f6832007-06-06 21:59:26 +000063// doInitialization - Initializes the vector of functions that have been
64// annotated with the noinline attribute.
65bool SimpleInliner::doInitialization(CallGraph &CG) {
Micah Villmow3574eca2012-10-08 16:38:25 +000066 CA.setDataLayout(getAnalysisIfAvailable<DataLayout>());
Tanya Lattner682f6832007-06-06 21:59:26 +000067 return false;
68}
Devang Patel6899b312007-07-25 18:00:25 +000069