GlobOptArrays.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 GlobOpt::ArraySrcOpt
  7. {
  8. public:
  9. ArraySrcOpt(GlobOpt * glob, IR::Instr ** instrRef, Value ** _src1Val, Value ** _src2Val) :
  10. globOpt(glob),
  11. func(glob->func),
  12. instr(*instrRef),
  13. src1Val(*_src1Val),
  14. src2Val(*_src2Val)
  15. {
  16. Assert(instr != nullptr);
  17. }
  18. ~ArraySrcOpt();
  19. void Optimize();
  20. private:
  21. bool CheckOpCode();
  22. void TypeSpecIndex();
  23. void UpdateValue(StackSym * newHeadSegmentSym, StackSym * newHeadSegmentLengthSym, StackSym * newLengthSym);
  24. void CheckVirtualArrayBounds();
  25. void TryEliminiteBoundsCheck();
  26. void CheckLoops();
  27. void DoArrayChecks();
  28. void DoLengthLoad();
  29. void DoHeadSegmentLengthLoad();
  30. void DoExtractBoundChecks();
  31. void DoLowerBoundCheck();
  32. void DoUpperBoundCheck();
  33. void UpdateHoistedValueInfo();
  34. void InsertHeadSegmentLoad();
  35. void InsertInstrInLandingPad(IR::Instr *const instr, Loop *const hoistOutOfLoop);
  36. void ShareBailOut();
  37. Func * func;
  38. GlobOpt * globOpt;
  39. IR::Instr *& instr;
  40. Value *& src1Val;
  41. Value *& src2Val;
  42. IR::Instr * baseOwnerInstr = nullptr;
  43. IR::IndirOpnd * baseOwnerIndir = nullptr;
  44. IR::RegOpnd * baseOpnd = nullptr;
  45. IR::Opnd * indexOpnd = nullptr;
  46. IR::Opnd * originalIndexOpnd = nullptr;
  47. bool isProfilableLdElem = false;
  48. bool isProfilableStElem = false;
  49. bool isLoad = false;
  50. bool isStore = false;
  51. bool needsHeadSegment = false;
  52. bool needsHeadSegmentLength = false;
  53. bool needsLength = false;
  54. bool needsBoundChecks = false;
  55. Value * baseValue = nullptr;
  56. ValueInfo * baseValueInfo = nullptr;
  57. ValueType baseValueType;
  58. ValueType newBaseValueType;
  59. ArrayValueInfo * baseArrayValueInfo = nullptr;
  60. bool isLikelyJsArray = false;
  61. bool isLikelyVirtualTypedArray = false;
  62. bool doArrayChecks = false;
  63. bool doArraySegmentHoist = false;
  64. bool headSegmentIsAvailable = false;
  65. bool doHeadSegmentLoad = false;
  66. bool doArraySegmentLengthHoist = false;
  67. bool headSegmentLengthIsAvailable = false;
  68. bool doHeadSegmentLengthLoad = false;
  69. bool lengthIsAvailable = false;
  70. bool doLengthLoad = false;
  71. StackSym * newHeadSegmentSym = nullptr;
  72. StackSym * newHeadSegmentLengthSym = nullptr;
  73. StackSym * newLengthSym = nullptr;
  74. bool canBailOutOnArrayAccessHelperCall = false;
  75. bool doExtractBoundChecks = false;
  76. bool eliminatedLowerBoundCheck = false;
  77. bool eliminatedUpperBoundCheck = false;
  78. StackSym * indexVarSym = nullptr;
  79. Value * indexValue = nullptr;
  80. IntConstantBounds indexConstantBounds;
  81. Value * headSegmentLengthValue = nullptr;
  82. IntConstantBounds headSegmentLengthConstantBounds;
  83. Loop * hoistChecksOutOfLoop = nullptr;
  84. Loop * hoistHeadSegmentLoadOutOfLoop = nullptr;
  85. Loop * hoistHeadSegmentLengthLoadOutOfLoop = nullptr;
  86. Loop * hoistLengthLoadOutOfLoop = nullptr;
  87. GlobOpt::ArrayLowerBoundCheckHoistInfo lowerBoundCheckHoistInfo;
  88. GlobOpt::ArrayUpperBoundCheckHoistInfo upperBoundCheckHoistInfo;
  89. bool failedToUpdateCompatibleLowerBoundCheck = false;
  90. bool failedToUpdateCompatibleUpperBoundCheck = false;
  91. StackSym * headSegmentLengthSym = nullptr;
  92. IR::Instr * insertBeforeInstr = nullptr;
  93. BailOutInfo * shareableBailOutInfo = nullptr;
  94. IR::Instr * shareableBailOutInfoOriginalOwner = nullptr;
  95. };