LLVM API Documentation

InlinerPass.h

Go to the documentation of this file.
00001 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
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 defines a simple policy-based bottom-up inliner.  This file
00011 // implements all of the boring mechanics of the bottom-up inlining, while the
00012 // subclass determines WHAT to inline, which is the much more interesting
00013 // component.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef INLINER_H
00018 #define INLINER_H
00019 
00020 #include "llvm/CallGraphSCCPass.h"
00021 #include "llvm/Transforms/Utils/InlineCost.h"
00022 
00023 namespace llvm {
00024   class CallSite;
00025 
00026 /// Inliner - This class contains all of the helper code which is used to
00027 /// perform the inlining operations that do not depend on the policy.
00028 ///
00029 struct Inliner : public CallGraphSCCPass {
00030   explicit Inliner(void *ID);
00031   explicit Inliner(void *ID, int Threshold);
00032 
00033   /// getAnalysisUsage - For this class, we declare that we require and preserve
00034   /// the call graph.  If the derived class implements this method, it should
00035   /// always explicitly call the implementation here.
00036   virtual void getAnalysisUsage(AnalysisUsage &Info) const;
00037 
00038   // Main run interface method, this implements the interface required by the
00039   // Pass class.
00040   virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
00041 
00042   // doFinalization - Remove now-dead linkonce functions at the end of
00043   // processing to avoid breaking the SCC traversal.
00044   virtual bool doFinalization(CallGraph &CG);
00045 
00046 
00047   /// This method returns the value specified by the -inline-threshold value,
00048   /// specified on the command line.  This is typically not directly needed.
00049   ///
00050   unsigned getInlineThreshold() const { return InlineThreshold; }
00051 
00052   /// getInlineCost - This method must be implemented by the subclass to
00053   /// determine the cost of inlining the specified call site.  If the cost
00054   /// returned is greater than the current inline threshold, the call site is
00055   /// not inlined.
00056   ///
00057   virtual InlineCost getInlineCost(CallSite CS) = 0;
00058 
00059   // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
00060   // higher threshold to determine if the function call should be inlined.
00061   ///
00062   virtual float getInlineFudgeFactor(CallSite CS) = 0;
00063 
00064   /// resetCachedCostInfo - erase any cached cost data from the derived class.
00065   /// If the derived class has no such data this can be empty.
00066   /// 
00067   virtual void resetCachedCostInfo(Function* Caller) = 0;
00068 
00069   /// removeDeadFunctions - Remove dead functions that are not included in
00070   /// DNR (Do Not Remove) list.
00071   bool removeDeadFunctions(CallGraph &CG, 
00072                            SmallPtrSet<const Function *, 16> *DNR = NULL);
00073 private:
00074   // InlineThreshold - Cache the value here for easy access.
00075   unsigned InlineThreshold;
00076 
00077   /// shouldInline - Return true if the inliner should attempt to
00078   /// inline at the given CallSite.
00079   bool shouldInline(CallSite CS);
00080 };
00081 
00082 } // End llvm namespace
00083 
00084 #endif