2
0

LowerMD.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 Lowerer;
  7. ///---------------------------------------------------------------------------
  8. ///
  9. /// class LowererMD
  10. ///
  11. ///---------------------------------------------------------------------------
  12. #ifdef DBG
  13. #define INSERTDEBUGBREAK(instrInsert)\
  14. {\
  15. IR::Instr *int3 = IR::Instr::New(Js::OpCode::DEBUGBREAK, m_func);\
  16. instrInsert->InsertBefore(int3);\
  17. }
  18. #else
  19. #define INSERTDEBUGBREAK(instrInsert)
  20. #endif
  21. class LowererMD
  22. {
  23. public:
  24. static const int MaxArgumentsToHelper = 16;
  25. LowererMD(Func *func) :
  26. m_func(func),
  27. helperCallArgsCount(0),
  28. helperCallDoubleArgsCount(0)
  29. {
  30. }
  31. static bool IsUnconditionalBranch(const IR::Instr *instr);
  32. static bool IsAssign(const IR::Instr *instr);
  33. static bool IsCall(const IR::Instr *instr);
  34. static bool IsIndirectBranch(const IR::Instr *instr);
  35. static bool IsReturnInstr(const IR::Instr *instr);
  36. static void InvertBranch(IR::BranchInstr *instr);
  37. static Js::OpCode MDBranchOpcode(Js::OpCode opcode);
  38. static Js::OpCode MDUnsignedBranchOpcode(Js::OpCode opcode);
  39. static Js::OpCode MDCompareWithZeroBranchOpcode(Js::OpCode opcode);
  40. static Js::OpCode MDConvertFloat64ToInt32Opcode(const RoundMode roundMode);
  41. static void ChangeToAdd(IR::Instr *const instr, const bool needFlags);
  42. static void ChangeToSub(IR::Instr *const instr, const bool needFlags);
  43. static void ChangeToShift(IR::Instr *const instr, const bool needFlags);
  44. static const uint16 GetFormalParamOffset();
  45. static const Js::OpCode MDUncondBranchOpcode;
  46. static const Js::OpCode MDTestOpcode;
  47. static const Js::OpCode MDOrOpcode;
  48. static const Js::OpCode MDXorOpcode;
  49. static const Js::OpCode MDOverflowBranchOpcode;
  50. static const Js::OpCode MDNotOverflowBranchOpcode;
  51. static const Js::OpCode MDConvertFloat32ToFloat64Opcode;
  52. static const Js::OpCode MDConvertFloat64ToFloat32Opcode;
  53. static const Js::OpCode MDCallOpcode;
  54. static const Js::OpCode MDImulOpcode;
  55. public:
  56. void Init(Lowerer *lowerer);
  57. void FinalLower();
  58. bool FinalLowerAssign(IR::Instr* instr);
  59. IR::Opnd * GenerateMemRef(void *addr, IRType type, IR::Instr *instr, bool dontEncode = false);
  60. IR::Instr * ChangeToHelperCall(IR::Instr * instr, IR::JnHelperMethod helperMethod, IR::LabelInstr *labelBailOut = nullptr,
  61. IR::Opnd *opndInstance = nullptr, IR::PropertySymOpnd * propSymOpnd = nullptr, bool isHelperContinuation = false);
  62. IR::Instr * ChangeToHelperCallMem(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  63. static IR::Instr * CreateAssign(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsertPt);
  64. static IR::Instr * ChangeToAssign(IR::Instr * instr);
  65. static IR::Instr * ChangeToAssign(IR::Instr * instr, IRType type);
  66. static IR::Instr * ChangeToLea(IR::Instr *const instr);
  67. static IR::Instr * ForceDstToReg(IR::Instr *instr);
  68. static void ImmedSrcToReg(IR::Instr * instr, IR::Opnd * newOpnd, int srcNum);
  69. IR::Instr * LoadArgumentCount(IR::Instr * instr);
  70. IR::Instr * LoadStackArgPtr(IR::Instr * instr);
  71. IR::Instr * LoadHeapArguments(IR::Instr * instrArgs, bool force = false, IR::Opnd *opndInputParamCount = nullptr);
  72. IR::Instr * LoadHeapArgsCached(IR::Instr * instr);
  73. IR::Instr * LoadInputParamPtr(IR::Instr * instrInsert, IR::RegOpnd * optionalDstOpnd = nullptr);
  74. IR::Instr * LoadInputParamCount(IR::Instr * instr, int adjust = 0, bool needFlags = false);
  75. IR::Instr * LoadArgumentsFromFrame(IR::Instr * instr);
  76. IR::Instr * LoadFuncExpression(IR::Instr * instr);
  77. IR::Instr * LowerRet(IR::Instr * instr);
  78. static IR::Instr * LowerUncondBranch(IR::Instr * instr);
  79. static IR::Instr * LowerMultiBranch(IR::Instr * instr);
  80. IR::Instr * LowerCondBranch(IR::Instr * instr);
  81. IR::Instr * LoadFunctionObjectOpnd(IR::Instr *instr, IR::Opnd *&functionObjOpnd);
  82. IR::Instr * LowerLdEnv(IR::Instr *instr);
  83. IR::Instr * LowerLdSuper(IR::Instr * instr, IR::JnHelperMethod helperOpCode);
  84. IR::Instr * GenerateSmIntPairTest(IR::Instr * instrInsert, IR::Opnd * opndSrc1, IR::Opnd * opndSrc2, IR::LabelInstr * labelFail);
  85. void GenerateTaggedZeroTest( IR::Opnd * opndSrc, IR::Instr * instrInsert, IR::LabelInstr * labelHelper = nullptr);
  86. void GenerateObjectPairTest(IR::Opnd * opndSrc1, IR::Opnd * opndSrc2, IR::Instr * insertInstr, IR::LabelInstr * labelTarget);
  87. bool GenerateObjectTest(IR::Opnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr * labelTarget, bool fContinueLabel = false);
  88. bool GenerateFastBrString(IR::BranchInstr* instr);
  89. bool GenerateFastCmSrEqConst(IR::Instr *instr);
  90. bool GenerateFastCmXxI4(IR::Instr *instr);
  91. bool GenerateFastCmXxR8(IR::Instr *instr) { Assert(UNREACHED); return nullptr; }
  92. bool GenerateFastCmXxTaggedInt(IR::Instr *instr);
  93. IR::Instr * GenerateConvBool(IR::Instr *instr);
  94. void GenerateClz(IR::Instr * instr);
  95. void GenerateFastDivByPow2(IR::Instr *instr);
  96. bool GenerateFastAdd(IR::Instr * instrAdd);
  97. bool GenerateFastSub(IR::Instr * instrSub);
  98. bool GenerateFastMul(IR::Instr * instrMul);
  99. bool GenerateFastAnd(IR::Instr * instrAnd);
  100. bool GenerateFastXor(IR::Instr * instrXor);
  101. bool GenerateFastOr(IR::Instr * instrOr);
  102. bool GenerateFastNot(IR::Instr * instrNot);
  103. bool GenerateFastNeg(IR::Instr * instrNeg);
  104. bool GenerateFastShiftLeft(IR::Instr * instrShift);
  105. bool GenerateFastShiftRight(IR::Instr * instrShift);
  106. void GenerateFastBrS(IR::BranchInstr *brInstr);
  107. IR::IndirOpnd * GenerateFastElemIStringIndexCommon(IR::Instr * instr, bool isStore, IR::IndirOpnd *indirOpnd, IR::LabelInstr * labelHelper);
  108. void GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMethod helperMethod);
  109. void HelperCallForAsmMathBuiltin(IR::Instr* instr, IR::JnHelperMethod helperMethodFloat, IR::JnHelperMethod helperMethodDouble) { Assert(UNREACHED); } // only for asm.js
  110. IR::Opnd * CreateStackArgumentsSlotOpnd();
  111. void GenerateSmIntTest(IR::Opnd *opndSrc, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::Instr **instrFirst = nullptr, bool fContinueLabel = false);
  112. IR::RegOpnd * LoadNonnegativeIndex(IR::RegOpnd *indexOpnd, const bool skipNegativeCheck, IR::LabelInstr *const notTaggedIntLabel, IR::LabelInstr *const negativeLabel, IR::Instr *const insertBeforeInstr);
  113. IR::RegOpnd * GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * labelFail, IR::Instr * insertBeforeInstr, bool generateTagCheck = true);
  114. bool GenerateFastLdMethodFromFlags(IR::Instr * instrLdFld);
  115. void GenerateInt32ToVarConversion( IR::Opnd * opndSrc, IR::Instr * insertInstr );
  116. IR::Instr * GenerateFastScopedFld(IR::Instr * instrScopedFld, bool isLoad);
  117. IR::Instr * GenerateFastScopedLdFld(IR::Instr * instrLdFld);
  118. IR::Instr * GenerateFastScopedStFld(IR::Instr * instrStFld);
  119. bool GenerateJSBooleanTest(IR::RegOpnd * regSrc, IR::Instr * insertInstr, IR::LabelInstr * labelTarget, bool fContinueLabel = false);
  120. void GenerateFastBrBReturn(IR::Instr *instr);
  121. void GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  122. bool GenerateFastCharAt(Js::BuiltinFunction index, IR::Opnd *dst, IR::Opnd *srcStr, IR::Opnd *srcIndex, IR::Instr *callInstr, IR::Instr *insertInstr,
  123. IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  124. bool TryGenerateFastMulAdd(IR::Instr * instrAdd, IR::Instr ** pInstrPrev);
  125. void GenerateIsDynamicObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool fContinueLabel = false);
  126. void GenerateIsRecyclableObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool checkObjectAndDynamicObject = true);
  127. bool GenerateLdThisCheck(IR::Instr * instr);
  128. bool GenerateLdThisStrict(IR::Instr* instr);
  129. void GenerateFloatTest(IR::RegOpnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr* labelHelper, const bool checkForNullInLoopBody = false);
  130. static void EmitInt4Instr(IR::Instr *instr);
  131. static void EmitPtrInstr(IR::Instr *instr);
  132. void EmitLoadVar(IR::Instr *instr, bool isFromUint32 = false, bool isHelper = false);
  133. bool EmitLoadInt32(IR::Instr *instr, bool conversionFromObjectAllowed);
  134. static void LowerInt4NegWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  135. static void LowerInt4AddWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  136. static void LowerInt4SubWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  137. static void LowerInt4MulWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  138. void LowerInt4RemWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel) const;
  139. void MarkOneFltTmpSym(StackSym *sym, BVSparse<JitArenaAllocator> *bvTmps, bool fFltPrefOp);
  140. void GenerateNumberAllocation(IR::RegOpnd * opndDst, IR::Instr * instrInsert, bool isHelper);
  141. void GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, IR::LabelInstr* allocHelperLabel, IR::LabelInstr* allocDoneLabel);
  142. void SaveDoubleToVar(IR::RegOpnd * dstOpnd, IR::RegOpnd *opndFloat, IR::Instr *instrOrig, IR::Instr *instrInsert, bool isHelper = false);
  143. IR::RegOpnd * EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr);
  144. IR::Instr * LoadCheckedFloat(IR::RegOpnd *opndOrig, IR::RegOpnd *opndFloat, IR::LabelInstr *labelInline, IR::LabelInstr *labelHelper, IR::Instr *instrInsert, const bool checkForNullInLoopBody = false);
  145. void LoadFloatValue(IR::RegOpnd * javascriptNumber, IR::RegOpnd * opndFloat, IR::LabelInstr * labelHelper, IR::Instr * instrInsert, const bool checkFornullptrInLoopBody = false);
  146. IR::Instr * LoadStackAddress(StackSym *sym, IR::RegOpnd *regDst = nullptr);
  147. IR::Instr * LowerCatch(IR::Instr *instr);
  148. IR::Instr * LowerGetCachedFunc(IR::Instr *instr);
  149. IR::Instr * LowerCommitScope(IR::Instr *instr);
  150. IR::Instr * LowerCallHelper(IR::Instr *instrCall);
  151. IR::LabelInstr *GetBailOutStackRestoreLabel(BailOutInfo * bailOutInfo, IR::LabelInstr * exitTargetInstr);
  152. bool AnyFloatTmps(void);
  153. IR::LabelInstr* InsertBeforeRecoveryForFloatTemps(IR::Instr * insertBefore, IR::LabelInstr * labelRecover, const bool isInHelperBlock = true);
  154. StackSym * GetImplicitParamSlotSym(Js::ArgSlot argSlot);
  155. static StackSym * GetImplicitParamSlotSym(Js::ArgSlot argSlot, Func * func);
  156. bool GenerateFastIsInst(IR::Instr * instr, Js::ScriptContext * scriptContext);
  157. IR::Instr * LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailOutLabel);
  158. bool GenerateFastIsInst(IR::Instr * instr);
  159. public:
  160. IR::Instr * LowerCall(IR::Instr * callInstr, Js::ArgSlot argCount);
  161. IR::Instr * LowerCallI(IR::Instr * callInstr, ushort callFlags, bool isHelper = false, IR::Instr* insertBeforeInstrForCFG = nullptr);
  162. IR::Instr * LowerCallPut(IR::Instr * callInstr);
  163. int32 LowerCallArgs(IR::Instr * callInstr, IR::Instr * stackParamInsert, ushort callFlags, Js::ArgSlot extraParams = 1 /* for function object */, IR::IntConstOpnd **callInfoOpndRef = nullptr);
  164. int32 LowerCallArgs(IR::Instr * callInstr, ushort callFlags, Js::ArgSlot extraParams = 1 /* for function object */, IR::IntConstOpnd **callInfoOpndRef = nullptr) { return LowerCallArgs(callInstr, callInstr, callFlags, extraParams, callInfoOpndRef); }
  165. IR::Instr * LowerStartCall(IR::Instr * instr);
  166. IR::Instr * LowerAsmJsCallI(IR::Instr * callInstr) { Assert(UNREACHED); return nullptr; }
  167. IR::Instr * LowerAsmJsCallE(IR::Instr * callInstr) { Assert(UNREACHED); return nullptr; }
  168. IR::Instr * LowerAsmJsStElemHelper(IR::Instr * callInstr) { Assert(UNREACHED); return nullptr; }
  169. IR::Instr * LowerAsmJsLdElemHelper(IR::Instr * callInstr) { Assert(UNREACHED); return nullptr; }
  170. IR::Instr * LowerCallIDynamic(IR::Instr *callInstr, IR::Instr*saveThisArgOutInstr, IR::Opnd *argsLength, ushort callFlags, IR::Instr * insertBeforeInstrForCFG = nullptr);
  171. IR::Instr * LoadHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  172. IR::Instr * LoadDynamicArgument(IR::Instr * instr, uint argNumber = 1);
  173. IR::Instr * LoadDynamicArgumentUsingLength(IR::Instr *instr);
  174. IR::Instr * LoadDoubleHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  175. IR::Instr * LoadFloatHelperArgument(IR::Instr * instr, IR::Opnd * opndArg) { Assert(UNREACHED); return nullptr; } // only used for asm.js right now
  176. IR::Instr * LowerToFloat(IR::Instr *instr);
  177. static IR::BranchInstr * LowerFloatCondBranch(IR::BranchInstr *instrBranch, bool ignoreNaN = false);
  178. void ConvertFloatToInt32(IR::Opnd* intOpnd, IR::Opnd* floatOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * labelDone, IR::Instr * instInsert);
  179. void CheckOverflowOnFloatToInt32(IR::Instr* instr, IR::Opnd* intOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * labelDone);
  180. void EmitLoadVarNoCheck(IR::RegOpnd * dst, IR::RegOpnd * src, IR::Instr *instrLoad, bool isFromUint32, bool isHelper);
  181. void EmitIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  182. void EmitUIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  183. void EmitFloatToInt(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  184. void EmitFloat32ToFloat64(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert) { Assert(UNREACHED); }
  185. static IR::Instr * InsertConvertFloat64ToInt32(const RoundMode roundMode, IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  186. void EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr);
  187. IR::LabelInstr* EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, bool needHelperLabel);
  188. static IR::Instr * LoadFloatZero(IR::Opnd * opndDst, IR::Instr * instrInsert);
  189. static IR::Instr * LoadFloatValue(IR::Opnd * opndDst, double value, IR::Instr * instrInsert);
  190. IR::Instr * LowerEntryInstr(IR::EntryInstr * entryInstr);
  191. IR::Instr * LowerExitInstr(IR::ExitInstr * exitInstr);
  192. IR::Instr * LowerEntryInstrAsmJs(IR::EntryInstr * entryInstr) { Assert(UNREACHED); return nullptr; }
  193. IR::Instr * LowerExitInstrAsmJs(IR::ExitInstr * exitInstr) { Assert(UNREACHED); return nullptr; }
  194. IR::Instr * LoadNewScObjFirstArg(IR::Instr * instr, IR::Opnd * dst, ushort extraArgs = 0);
  195. IR::Instr * LowerTry(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  196. IR::Instr * LowerLeave(IR::Instr *instr, IR::LabelInstr * targetInstr, bool fromFinalLower, bool isOrphanedLeave = false);
  197. IR::Instr * LowerLeaveNull(IR::Instr *instr);
  198. IR::LabelInstr * EnsureEpilogLabel();
  199. IR::Instr * LowerEHRegionReturn(IR::Instr * insertBeforeInstr, IR::Opnd * targetOpnd);
  200. void FinishArgLowering();
  201. IR::Opnd * GetOpndForArgSlot(Js::ArgSlot argSlot, bool isDoubleArgument = false);
  202. void GenerateStackAllocation(IR::Instr *instr, uint32 allocSize, uint32 probeSize);
  203. void GenerateStackDeallocation(IR::Instr *instr, uint32 allocSize);
  204. void GenerateStackProbe(IR::Instr *instr, bool afterProlog);
  205. IR::Opnd* GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
  206. template <bool verify = false>
  207. static void Legalize(IR::Instr *const instr, bool fPostRegAlloc = false);
  208. IR::Opnd* IsOpndNegZero(IR::Opnd* opnd, IR::Instr* instr);
  209. void GenerateFastInlineBuiltInMathAbs(IR::Instr *callInstr);
  210. void GenerateFastInlineBuiltInMathFloor(IR::Instr *callInstr);
  211. void GenerateFastInlineBuiltInMathCeil(IR::Instr *callInstr);
  212. void GenerateFastInlineBuiltInMathRound(IR::Instr *callInstr);
  213. static RegNum GetRegStackPointer() { return RegSP; }
  214. static RegNum GetRegFramePointer() { return RegR11; }
  215. static RegNum GetRegReturn(IRType type) { return IRType_IsFloat(type) ? RegNOREG : RegR0; }
  216. static RegNum GetRegArgI4(int32 argNum) { return RegNOREG; }
  217. static RegNum GetRegArgR8(int32 argNum) { return RegNOREG; }
  218. static Js::OpCode GetLoadOp(IRType type) { return type == TyFloat64? Js::OpCode::VLDR : ((type == TyFloat32)? Js::OpCode::VLDR32 : Js::OpCode::LDR); }
  219. static Js::OpCode GetStoreOp(IRType type) { return type == TyFloat64? Js::OpCode::VSTR : ((type == TyFloat32)? Js::OpCode::VSTR32 : Js::OpCode::STR); }
  220. static Js::OpCode GetMoveOp(IRType type) { return IRType_IsFloat(type) ? Js::OpCode::VMOV : Js::OpCode::MOV; }
  221. static BYTE GetDefaultIndirScale()
  222. {
  223. return IndirScale4;
  224. }
  225. // -4 is to avoid alignment issues popping up, we are conservative here.
  226. // We might check for IsSmallStack first to push R4 register & then align.
  227. static bool IsSmallStack(uint32 size) { return (size < (PAGESIZE - 4));}
  228. static void GenerateLoadTaggedType(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndTaggedType);
  229. static void GenerateLoadPolymorphicInlineCacheSlot(IR::Instr * instrLdSt, IR::RegOpnd * opndInlineCache, IR::RegOpnd * opndType, uint polymorphicInlineCacheSize);
  230. static IR::BranchInstr * GenerateLocalInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext, bool checkTypeWithoutProperty = false);
  231. static IR::BranchInstr * GenerateProtoInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  232. static IR::BranchInstr * GenerateFlagInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  233. static IR::BranchInstr * GenerateFlagInlineCacheCheckForNoGetterSetter(IR::Instr * instrLdSt, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  234. static IR::BranchInstr * GenerateFlagInlineCacheCheckForLocal(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  235. static void GenerateLdFldFromLocalInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  236. static void GenerateLdFldFromProtoInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  237. static void GenerateLdLocalFldFromFlagInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  238. static void GenerateStFldFromLocalInlineCache(IR::Instr * instrStFld, IR::RegOpnd * opndBase, IR::Opnd * opndSrc, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  239. void GenerateFunctionObjectTest(IR::Instr * callInstr, IR::RegOpnd *functionOpnd, bool isHelper, IR::LabelInstr* continueAfterExLabel = nullptr);
  240. static void ChangeToWriteBarrierAssign(IR::Instr * assignInstr);
  241. int GetHelperArgsCount() { return this->helperCallArgsCount; }
  242. void ResetHelperArgsCount() { this->helperCallArgsCount = 0; }
  243. void LowerInlineSpreadArgOutLoop(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd);
  244. public:
  245. static void InsertIncUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
  246. static void InsertDecUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
  247. private:
  248. void GenerateFlagInlineCacheCheckForGetterSetter(
  249. IR::Instr * insertBeforeInstr,
  250. IR::RegOpnd * opndInlineCache,
  251. IR::LabelInstr * labelNext);
  252. void GenerateLdFldFromFlagInlineCache(
  253. IR::Instr * insertBeforeInstr,
  254. IR::RegOpnd * opndBase,
  255. IR::RegOpnd * opndInlineCache,
  256. IR::Opnd * opndDst,
  257. IR::LabelInstr * labelFallThru,
  258. bool isInlineSlot);
  259. void GenerateAssignForBuiltinArg(
  260. RegNum dstReg,
  261. IR::Opnd* srcOpnd,
  262. IR::Instr* instr);
  263. IR::Instr* GeneratePreCall(IR::Instr * callInstr, IR::Opnd *functionOpnd);
  264. void SetMaxArgSlots(Js::ArgSlot actualCount /*including this*/);
  265. // Data
  266. protected:
  267. Func * m_func;
  268. Lowerer * m_lowerer;
  269. //
  270. // Support to load helper arguments.
  271. //
  272. static const int MaxDoubleArgumentsToHelper = 8;
  273. // Only 8 double values can be passed through double registers, rest has to go through stack and
  274. // need to following a different calling convention. We should never hit that case as there is no helper call with more
  275. // than 8 double arguments.
  276. uint16 helperCallArgsCount; //consists of both integer & double arguments
  277. uint16 helperCallDoubleArgsCount; //consists of only double arguments
  278. IR::Opnd * helperCallArgs[MaxArgumentsToHelper];
  279. void FlipHelperCallArgsOrder();
  280. };