InlinerPass.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines a simple policy-based bottom-up inliner. This file
  11. // implements all of the boring mechanics of the bottom-up inlining, while the
  12. // subclass determines WHAT to inline, which is the much more interesting
  13. // component.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H
  17. #define LLVM_TRANSFORMS_IPO_INLINERPASS_H
  18. #include "llvm/Analysis/CallGraphSCCPass.h"
  19. namespace llvm {
  20. class CallSite;
  21. class DataLayout;
  22. class InlineCost;
  23. template<class PtrType, unsigned SmallSize>
  24. class SmallPtrSet;
  25. /// Inliner - This class contains all of the helper code which is used to
  26. /// perform the inlining operations that do not depend on the policy.
  27. ///
  28. struct Inliner : public CallGraphSCCPass {
  29. explicit Inliner(char &ID);
  30. explicit Inliner(char &ID, int Threshold, bool InsertLifetime);
  31. /// getAnalysisUsage - For this class, we declare that we require and preserve
  32. /// the call graph. If the derived class implements this method, it should
  33. /// always explicitly call the implementation here.
  34. void getAnalysisUsage(AnalysisUsage &Info) const override;
  35. // Main run interface method, this implements the interface required by the
  36. // Pass class.
  37. bool runOnSCC(CallGraphSCC &SCC) override;
  38. using llvm::Pass::doFinalization;
  39. // doFinalization - Remove now-dead linkonce functions at the end of
  40. // processing to avoid breaking the SCC traversal.
  41. bool doFinalization(CallGraph &CG) override;
  42. /// This method returns the value specified by the -inline-threshold value,
  43. /// specified on the command line. This is typically not directly needed.
  44. ///
  45. unsigned getInlineThreshold() const { return InlineThreshold; }
  46. /// Calculate the inline threshold for given Caller. This threshold is lower
  47. /// if the caller is marked with OptimizeForSize and -inline-threshold is not
  48. /// given on the comand line. It is higher if the callee is marked with the
  49. /// inlinehint attribute.
  50. ///
  51. unsigned getInlineThreshold(CallSite CS) const;
  52. /// getInlineCost - This method must be implemented by the subclass to
  53. /// determine the cost of inlining the specified call site. If the cost
  54. /// returned is greater than the current inline threshold, the call site is
  55. /// not inlined.
  56. ///
  57. virtual InlineCost getInlineCost(CallSite CS) = 0;
  58. /// removeDeadFunctions - Remove dead functions.
  59. ///
  60. /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
  61. /// which restricts it to deleting functions with an 'AlwaysInline'
  62. /// attribute. This is useful for the InlineAlways pass that only wants to
  63. /// deal with that subset of the functions.
  64. bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
  65. // HLSL Change Starts
  66. void applyOptions(PassOptions O) override;
  67. void dumpConfig(raw_ostream &OS) override;
  68. // HLSL Change Ends
  69. private:
  70. // InlineThreshold - Cache the value here for easy access.
  71. unsigned InlineThreshold;
  72. // InsertLifetime - Insert @llvm.lifetime intrinsics.
  73. bool InsertLifetime;
  74. /// shouldInline - Return true if the inliner should attempt to
  75. /// inline at the given CallSite.
  76. bool shouldInline(CallSite CS);
  77. };
  78. } // End llvm namespace
  79. #endif