InlinerPass.h revision c5e1ec47c719806fcc882470595960512edc7441
19933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===// 29933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 39933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// The LLVM Compiler Infrastructure 49933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 79933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 89933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===----------------------------------------------------------------------===// 99933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 109933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// This file defines a simple policy-based bottom-up inliner. This file 119933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// implements all of the boring mechanics of the bottom-up inlining, while the 129933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// subclass determines WHAT to inline, which is the much more interesting 139933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// component. 149933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 159933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===----------------------------------------------------------------------===// 169933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 179933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#ifndef INLINER_H 189933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#define INLINER_H 199933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 209933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#include "llvm/CallGraphSCCPass.h" 21c5e1ec47c719806fcc882470595960512edc7441Daniel Dunbar#include "llvm/Transforms/Utils/InlineCost.h" 229933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 239933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnernamespace llvm { 249933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner class CallSite; 259933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 269933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// Inliner - This class contains all of the helper code which is used to 271a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar/// perform the inlining operations that do not depend on the policy. 289933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// 299933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnerstruct Inliner : public CallGraphSCCPass { 30ae73dc1448d25b02cabc7c64c86c64371453dda8Dan Gohman explicit Inliner(void *ID); 31ae73dc1448d25b02cabc7c64c86c64371453dda8Dan Gohman explicit Inliner(void *ID, int Threshold); 329933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 339933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getAnalysisUsage - For this class, we declare that we require and preserve 349933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// the call graph. If the derived class implements this method, it should 359933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// always explicitly call the implementation here. 369933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner virtual void getAnalysisUsage(AnalysisUsage &Info) const; 379933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 389933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Main run interface method, this implements the interface required by the 399933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Pass class. 409933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC); 419933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 429933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // doFinalization - Remove now-dead linkonce functions at the end of 439933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // processing to avoid breaking the SCC traversal. 449933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner virtual bool doFinalization(CallGraph &CG); 459933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 469933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 479933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// This method returns the value specified by the -inline-threshold value, 489933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// specified on the command line. This is typically not directly needed. 499933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// 509933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner unsigned getInlineThreshold() const { return InlineThreshold; } 519933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 529933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getInlineCost - This method must be implemented by the subclass to 539933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// determine the cost of inlining the specified call site. If the cost 549933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// returned is greater than the current inline threshold, the call site is 559933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// not inlined. 569933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// 57c5e1ec47c719806fcc882470595960512edc7441Daniel Dunbar virtual InlineCost getInlineCost(CallSite CS) = 0; 589933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 598d84d5b62cdf2a772d51338136c7022a6e1ff931Evan Cheng // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a 608d84d5b62cdf2a772d51338136c7022a6e1ff931Evan Cheng // higher threshold to determine if the function call should be inlined. 618d84d5b62cdf2a772d51338136c7022a6e1ff931Evan Cheng /// 62652f7ea955bb433d6b7a4d33685dca9485fd7b8bEvan Cheng virtual float getInlineFudgeFactor(CallSite CS) = 0; 638d84d5b62cdf2a772d51338136c7022a6e1ff931Evan Cheng 649933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnerprivate: 659933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // InlineThreshold - Cache the value here for easy access. 669933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner unsigned InlineThreshold; 671a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar 681a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// shouldInline - Return true if the inliner should attempt to 691a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// inline at the given CallSite. 701a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar bool shouldInline(CallSite CS); 719933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner}; 729933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 739933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner} // End llvm namespace 749933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 759933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#endif 76