InliningHeuristics.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class InliningDecider;
  7. struct InliningThreshold
  8. {
  9. uint nonLoadByteCodeCount;
  10. bool forLoopBody;
  11. int inlineThreshold;
  12. int constructorInlineThreshold;
  13. int outsideLoopInlineThreshold;
  14. int leafInlineThreshold;
  15. int loopInlineThreshold;
  16. int polymorphicInlineThreshold;
  17. int inlineCountMax;
  18. int maxNumberOfInlineesWithLoop;
  19. int constantArgumentInlineThreshold;
  20. InliningThreshold(uint nonLoadByteCodeCount, bool forLoopBody, bool aggressive = false);
  21. void SetHeuristics();
  22. void SetAggressiveHeuristics();
  23. void Reset();
  24. };
  25. class InliningHeuristics
  26. {
  27. friend class ::InliningDecider;
  28. const FunctionJITTimeInfo * topFunc;
  29. InliningThreshold threshold;
  30. public:
  31. public:
  32. InliningHeuristics(const FunctionJITTimeInfo * topFunc, bool forLoopBody) :topFunc(topFunc), threshold(topFunc->GetBody()->GetNonLoadByteCodeCount(), forLoopBody) {};
  33. bool BackendInlineIntoInliner(const FunctionJITTimeInfo * inlinee,
  34. Func * inliner,
  35. Func *topFunc,
  36. Js::ProfileId,
  37. bool isConstructorCall,
  38. bool isFixedMethodCall,
  39. bool isCallOutsideLoopInTopFunc,
  40. bool isCallInsideLoop,
  41. uint recursiveInlineDepth,
  42. uint16 constantArguments
  43. );
  44. private:
  45. static bool IsInlineeLeaf(const FunctionJITTimeInfo * inlinee)
  46. {
  47. return inlinee->GetBody()->HasProfileInfo()
  48. && (!PHASE_OFF(Js::InlineBuiltInCallerPhase, inlinee) ? !inlinee->GetBody()->HasNonBuiltInCallee() : inlinee->GetBody()->GetProfiledCallSiteCount() == 0)
  49. && !inlinee->GetBody()->GetReadOnlyProfileInfo()->HasLdFldCallSiteInfo();
  50. }
  51. };