InliningHeuristics.h 2.5 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. struct InliningThreshold
  7. {
  8. Js::FunctionBody * topFunc;
  9. int inlineThreshold;
  10. int constructorInlineThreshold;
  11. int outsideLoopInlineThreshold;
  12. int leafInlineThreshold;
  13. int loopInlineThreshold;
  14. int polymorphicInlineThreshold;
  15. int inlineCountMax;
  16. int maxNumberOfInlineesWithLoop;
  17. int constantArgumentInlineThreshold;
  18. InliningThreshold(Js::FunctionBody * topFunc, bool aggressive = false);
  19. void SetHeuristics();
  20. void SetAggressiveHeuristics();
  21. void Reset();
  22. };
  23. class InliningHeuristics
  24. {
  25. friend class InliningDecider;
  26. Js::FunctionBody * topFunc;
  27. InliningThreshold threshold;
  28. public:
  29. public:
  30. InliningHeuristics(Js::FunctionBody * topFunc) :topFunc(topFunc), threshold(topFunc) {};
  31. bool DeciderInlineIntoInliner(Js::FunctionBody* inlinee, Js::FunctionBody *inliner, bool isConstructorCall, bool isPolymorphicCall, InliningDecider* inliningDecider, uint16 constantArgInfo, uint recursiveInlineDepth, bool allowRecursiveInlining);
  32. bool CanRecursivelyInline(Js::FunctionBody* inlinee, Js::FunctionBody *inliner, bool allowRecursiveInlining, uint recursiveInlineDepth);
  33. bool BackendInlineIntoInliner(Js::FunctionBody* inlinee,
  34. Js::FunctionBody *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. bool ContinueInliningUserDefinedFunctions(uint32 bytecodeInlinedCount) const;
  45. private:
  46. static bool IsInlineeLeaf(Js::FunctionBody* inlinee)
  47. {
  48. return inlinee->HasDynamicProfileInfo()
  49. && (!PHASE_OFF(Js::InlineBuiltInCallerPhase, inlinee) ? !inlinee->HasNonBuiltInCallee() : inlinee->GetProfiledCallSiteCount() == 0)
  50. && !inlinee->GetAnyDynamicProfileInfo()->hasLdFldCallSiteInfo();
  51. }
  52. };