Lower.h 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. #define ASSERT_INLINEE_FUNC(instr) Assert(instr->m_func->IsInlinee() ? (instr->m_func != this->m_func) : (instr->m_func == this->m_func))
  7. enum IndirScale : BYTE {
  8. IndirScale1 = 0,
  9. IndirScale2 = 1,
  10. IndirScale4 = 2,
  11. IndirScale8 = 3
  12. };
  13. enum RoundMode : BYTE {
  14. RoundModeTowardZero = 0,
  15. RoundModeTowardInteger = 1,
  16. RoundModeHalfToEven = 2
  17. };
  18. #if DBG
  19. enum HelperCallCheckState : BYTE {
  20. HelperCallCheckState_None = 0,
  21. HelperCallCheckState_ImplicitCallsBailout = 1 << 0,
  22. HelperCallCheckState_NoHelperCalls = 1 << 1
  23. };
  24. #endif
  25. #if defined(_M_IX86) || defined(_M_AMD64)
  26. #include "LowerMDShared.h"
  27. #elif defined(_M_ARM32_OR_ARM64)
  28. #include "LowerMD.h"
  29. #endif
  30. #define IR_HELPER_OP_FULL_OR_INPLACE(op) IR::HelperOp_##op##_Full, IR::HelperOp_##op##InPlace
  31. ///---------------------------------------------------------------------------
  32. ///
  33. /// class Lowerer
  34. ///
  35. /// Lower machine independent IR to machine dependent instrs.
  36. ///
  37. ///---------------------------------------------------------------------------
  38. class Lowerer
  39. {
  40. friend class LowererMD;
  41. friend class LowererMDArch;
  42. friend class Encoder;
  43. friend class Func;
  44. friend class ExternalLowerer;
  45. public:
  46. Lowerer(Func * func) : m_func(func), m_lowererMD(func), nextStackFunctionOpnd(nullptr), outerMostLoopLabel(nullptr),
  47. initializedTempSym(nullptr), addToLiveOnBackEdgeSyms(nullptr), currentRegion(nullptr),
  48. m_lowerGeneratorHelper(LowerGeneratorHelper(func, this, this->m_lowererMD))
  49. {
  50. #ifdef RECYCLER_WRITE_BARRIER_JIT
  51. m_func->m_lowerer = this;
  52. #endif
  53. #if DBG
  54. this->helperCallCheckState = HelperCallCheckState_None;
  55. this->oldHelperCallCheckState = HelperCallCheckState_None;
  56. #endif
  57. }
  58. ~Lowerer()
  59. {
  60. #ifdef RECYCLER_WRITE_BARRIER_JIT
  61. m_func->m_lowerer = nullptr;
  62. #endif
  63. }
  64. void Lower();
  65. void LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFastPath, bool defaultDoLoopFastPath);
  66. void LowerPrologEpilog();
  67. void LowerPrologEpilogAsmJs();
  68. void DoInterruptProbes();
  69. static IR::Instr * TryShiftAdd(IR::Instr *instrAdd, IR::Opnd * opndFold, IR::Opnd * opndAdd);
  70. static IR::Instr *PeepShiftAdd(IR::Instr *instr);
  71. IR::Instr *PreLowerPeepInstr(IR::Instr *instr, IR::Instr **pInstrPrev);
  72. IR::Instr *PeepShl(IR::Instr *instr);
  73. IR::Instr *PeepBrBool(IR::Instr *instr);
  74. uint DoLoopProbeAndNumber(IR::BranchInstr *branchInstr);
  75. void InsertOneLoopProbe(IR::Instr *insertInstr, IR::LabelInstr *loopLabel);
  76. void FinalLower();
  77. void InsertLazyBailOutThunk();
  78. void EHBailoutPatchUp();
  79. inline Js::ScriptContext* GetScriptContext()
  80. {
  81. return m_func->GetScriptContext();
  82. }
  83. StackSym * GetTempNumberSym(IR::Opnd * opnd, bool isTempTransferred);
  84. static bool HasSideEffects(IR::Instr *instr);
  85. static bool IsArgSaveRequired(Func *func);
  86. #if DBG
  87. static bool ValidOpcodeAfterLower(IR::Instr* instr, Func * func);
  88. #endif
  89. private:
  90. IR::Instr * LowerNewRegEx(IR::Instr * instr);
  91. void LowerNewScObjectSimple(IR::Instr *instr);
  92. void LowerNewScObjectLiteral(IR::Instr *instr);
  93. IR::Instr * LowerInitCachedFuncs(IR::Instr *instrInit);
  94. IR::Instr * LowerNewScObject(IR::Instr *instr, bool callCtor, bool hasArgs, bool isBaseClassConstructorNewScObject = false);
  95. IR::Instr * LowerNewScObjArray(IR::Instr *instr);
  96. IR::Instr * LowerNewScObjArrayNoArg(IR::Instr *instr);
  97. bool TryLowerNewScObjectWithFixedCtorCache(IR::Instr* newObjInstr, IR::RegOpnd* newObjDst, IR::LabelInstr* helperOrBailoutLabel, IR::LabelInstr* callCtorLabel,
  98. bool& skipNewScObj, bool& returnNewScObj, bool& emitHelper);
  99. void GenerateRecyclerAllocAligned(IR::JnHelperMethod allocHelper, size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, bool inOpHelper = false);
  100. IR::Instr * LowerGetNewScObject(IR::Instr *const instr);
  101. void LowerGetNewScObjectCommon(IR::RegOpnd *const resultObjOpnd, IR::RegOpnd *const constructorReturnOpnd, IR::RegOpnd *const newObjOpnd, IR::Instr *insertBeforeInstr);
  102. IR::Instr * LowerUpdateNewScObjectCache(IR::Instr * updateInstr, IR::Opnd *dst, IR::Opnd *src1, const bool isCtorFunction);
  103. bool GenerateLdFldWithCachedType(IR::Instr * instrLdFld, bool* continueAsHelperOut, IR::LabelInstr** labelHelperOut, IR::RegOpnd** typeOpndOut);
  104. bool GenerateCheckFixedFld(IR::Instr * instrChkFld);
  105. void GenerateCheckObjType(IR::Instr * instrChkObjType);
  106. void LowerAdjustObjType(IR::Instr * instrAdjustObjType);
  107. bool GenerateNonConfigurableLdRootFld(IR::Instr * instrLdFld);
  108. IR::Instr * LowerProfiledLdFld(IR::JitProfilingInstr *instr);
  109. void LowerProfiledBeginSwitch(IR::JitProfilingInstr *instr);
  110. void LowerFunctionExit(IR::Instr* funcExit);
  111. void LowerFunctionEntry(IR::Instr* funcEntry);
  112. void LowerFunctionBodyCallCountChange(IR::Instr *const insertBeforeInstr);
  113. IR::Instr* LowerProfiledNewArray(IR::JitProfilingInstr* instr, bool hasArgs);
  114. IR::Instr * LowerProfiledLdSlot(IR::JitProfilingInstr *instr);
  115. void LowerProfileLdSlot(IR::Opnd *const valueOpnd, Func *const ldSlotFunc, const Js::ProfileId profileId, IR::Instr *const insertBeforeInstr);
  116. void LowerProfiledBinaryOp(IR::JitProfilingInstr* instr, IR::JnHelperMethod meth);
  117. IR::Instr * LowerLdFld(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod, bool useInlineCache, IR::LabelInstr *labelBailOut = nullptr, bool isHelper = false);
  118. template<bool isRoot>
  119. IR::Instr* GenerateCompleteLdFld(IR::Instr* instr, bool emitFastPath, IR::JnHelperMethod monoHelperAfterFastPath, IR::JnHelperMethod polyHelperAfterFastPath,
  120. IR::JnHelperMethod monoHelperWithoutFastPath, IR::JnHelperMethod polyHelperWithoutFastPath);
  121. IR::Instr * LowerScopedLdFld(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool withInlineCache);
  122. IR::Instr * LowerScopedLdInst(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  123. IR::Instr * LowerDelFld(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool useInlineCache, bool strictMode);
  124. IR::Instr * LowerIsInst(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  125. IR::Instr * LowerScopedDelFld(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool withInlineCache, bool strictMode);
  126. IR::Instr * LowerNewScFunc(IR::Instr *instr);
  127. IR::Instr * LowerNewScGenFunc(IR::Instr *instr);
  128. IR::Instr * LowerNewScFuncHomeObj(IR::Instr *instr);
  129. IR::Instr * LowerNewScGenFuncHomeObj(IR::Instr *instr);
  130. IR::Instr * LowerStPropIdArrFromVar(IR::Instr *instr);
  131. IR::Instr * LowerRestify(IR::Instr *instr);
  132. IR::Instr* GenerateCompleteStFld(IR::Instr* instr, bool emitFastPath, IR::JnHelperMethod monoHelperAfterFastPath, IR::JnHelperMethod polyHelperAfterFastPath,
  133. IR::JnHelperMethod monoHelperWithoutFastPath, IR::JnHelperMethod polyHelperWithoutFastPath, bool withPutFlags, Js::PropertyOperationFlags flags);
  134. bool GenerateStFldWithCachedType(IR::Instr * instrStFld, bool* continueAsHelperOut, IR::LabelInstr** labelHelperOut, IR::RegOpnd** typeOpndOut);
  135. bool GenerateStFldWithCachedFinalType(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd);
  136. IR::RegOpnd * GenerateCachedTypeCheck(IR::Instr *instrInsert, IR::PropertySymOpnd *propertySymOpnd,
  137. IR::LabelInstr* labelObjCheckFailed, IR::LabelInstr *labelTypeCheckFailed, IR::LabelInstr *labelSecondChance = nullptr);
  138. void GenerateCachedTypeWithoutPropertyCheck(IR::Instr *instrInsert, IR::PropertySymOpnd *propertySymOpnd, IR::Opnd *typeOpnd, IR::LabelInstr *labelTypeCheckFailed);
  139. IR::RegOpnd * GeneratePolymorphicTypeIndex(IR::RegOpnd * typeOpnd, Js::PropertyGuard * typeCheckGuard, IR::Instr * instrInsert);
  140. void GenerateLeaOfOOPData(IR::RegOpnd * regOpnd, void * address, int32 offset, IR::Instr * instrInsert);
  141. IR::Opnd * GenerateIndirOfOOPData(void * address, int32 offset, IR::Instr * instrInsert);
  142. bool GenerateFixedFieldGuardCheck(IR::Instr *insertPointInstr, IR::PropertySymOpnd *propertySymOpnd, IR::LabelInstr *labelBailOut);
  143. Js::JitTypePropertyGuard* CreateTypePropertyGuardForGuardedProperties(JITTypeHolder type, IR::PropertySymOpnd* propertySymOpnd);
  144. Js::JitEquivalentTypeGuard* CreateEquivalentTypeGuardAndLinkToGuardedProperties(IR::PropertySymOpnd* propertySymOpnd);
  145. bool LinkCtorCacheToGuardedProperties(JITTimeConstructorCache* cache);
  146. template<typename LinkFunc>
  147. bool LinkGuardToGuardedProperties(const BVSparse<JitArenaAllocator>* guardedPropOps, LinkFunc link);
  148. bool GeneratePropertyGuardCheck(IR::Instr *insertPointInstr, IR::PropertySymOpnd *propertySymOpnd, IR::LabelInstr *labelBailOut);
  149. IR::Instr * GeneratePropertyGuardCheckBailoutAndLoadType(IR::Instr *insertInstr);
  150. void GenerateFieldStoreWithTypeChange(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  151. void GenerateDirectFieldStore(IR::Instr* instrStFld, IR::PropertySymOpnd* propertySymOpnd);
  152. void GenerateAdjustSlots(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  153. bool GenerateAdjustBaseSlots(IR::Instr * instrStFld, IR::RegOpnd *baseOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  154. void PinTypeRef(JITTypeHolder type, void* typeRef, IR::Instr* instr, Js::PropertyId propertyId);
  155. IR::RegOpnd * GenerateIsBuiltinRecyclableObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool checkObjectAndDynamicObject = true, IR::LabelInstr *labelFastExternal = nullptr, bool isInHelper = false);
  156. void GenerateIsDynamicObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool fContinueLabel = false);
  157. void GenerateIsRecyclableObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool checkObjectAndDynamicObject = true);
  158. bool GenerateLdThisCheck(IR::Instr * instr);
  159. bool GenerateFastIsInst(IR::Instr * instr);
  160. void GenerateFastArrayIsIn(IR::Instr * instr);
  161. void GenerateFastObjectIsIn(IR::Instr * instr);
  162. void GenerateProtoLdFldFromFlagInlineCache(
  163. IR::Instr * insertBeforeInstr,
  164. IR::Opnd * opndDst,
  165. IR::RegOpnd * opndInlineCache,
  166. IR::LabelInstr * labelFallThru,
  167. bool isInlineSlot);
  168. void GenerateLocalLdFldFromFlagInlineCache(
  169. IR::Instr * insertBeforeInstr,
  170. IR::RegOpnd * opndBase,
  171. IR::Opnd * opndDst,
  172. IR::RegOpnd * opndInlineCache,
  173. IR::LabelInstr * labelFallThru,
  174. bool isInlineSlot);
  175. IR::LabelInstr* EnsureEpilogueLabel() const;
  176. void GenerateFlagProtoCheck(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFail);
  177. void GenerateFlagInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  178. bool GenerateFastLdMethodFromFlags(IR::Instr * instrLdFld);
  179. void EnsureStackFunctionListStackSym();
  180. void EnsureZeroLastStackFunctionNext();
  181. void AllocStackClosure();
  182. IR::Instr * GenerateNewStackScFunc(IR::Instr * newScFuncInstr, IR::RegOpnd ** ppEnvOpnd);
  183. void GenerateStackScriptFunctionInit(StackSym * stackSym, Js::FunctionInfoPtrPtr nestedInfo);
  184. void GenerateScriptFunctionInit(IR::RegOpnd * regOpnd, IR::Opnd * vtableAddressOpnd,
  185. Js::FunctionInfoPtrPtr nestedInfo, IR::Opnd * envOpnd, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  186. void GenerateStackScriptFunctionInit(IR::RegOpnd * regOpnd, Js::FunctionInfoPtrPtr nestedInfo, IR::Opnd * envOpnd, IR::Instr * insertBeforeInstr);
  187. IR::Instr * LowerProfiledStFld(IR::JitProfilingInstr * instr, Js::PropertyOperationFlags flags);
  188. IR::Instr * LowerStFld(IR::Instr * stFldInstr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod, bool withInlineCache, IR::LabelInstr *ppBailOutLabel = nullptr, bool isHelper = false, bool withPutFlags = false, Js::PropertyOperationFlags flags = Js::PropertyOperation_None);
  189. void MapStFldHelper(IR::PropertySymOpnd * propertySymOpnd, IR::JnHelperMethod &helperMethod, IR::JnHelperMethod &polymorphicHelperMethod);
  190. IR::Instr * LowerScopedStFld(IR::Instr * stFldInstr, IR::JnHelperMethod helperMethod, bool withInlineCache,
  191. bool withPropertyOperationFlags = false, Js::PropertyOperationFlags flags = Js::PropertyOperation_None);
  192. void LowerProfiledLdElemI(IR::JitProfilingInstr *const instr);
  193. void LowerProfiledStElemI(IR::JitProfilingInstr *const instr, const Js::PropertyOperationFlags flags);
  194. IR::Instr * LowerStElemI(IR::Instr *instr, Js::PropertyOperationFlags flags, bool isHelper, IR::JnHelperMethod helperMethod = IR::HelperOp_SetElementI);
  195. IR::Instr * LowerLdElemI(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool isHelper);
  196. void LowerLdLen(IR::Instr *const instr, const bool isHelper);
  197. IR::Instr * LowerMemOp(IR::Instr * instr);
  198. IR::Instr * LowerMemset(IR::Instr * instr, IR::RegOpnd * helperRet);
  199. IR::Instr * LowerMemcopy(IR::Instr * instr, IR::RegOpnd * helperRet);
  200. IR::Instr * LowerWasmArrayBoundsCheck(IR::Instr * instr, IR::Opnd *addrOpnd);
  201. IR::Instr * LowerLdArrViewElem(IR::Instr * instr);
  202. IR::Instr * LowerStArrViewElem(IR::Instr * instr);
  203. IR::Instr * LowerStAtomicsWasm(IR::Instr * instr);
  204. IR::Instr * LowerLdAtomicsWasm(IR::Instr * instr);
  205. IR::Instr * LowerLdArrViewElemWasm(IR::Instr * instr);
  206. IR::Instr * LowerArrayDetachedCheck(IR::Instr * instr);
  207. IR::Instr * LowerDeleteElemI(IR::Instr *instr, bool strictMode);
  208. IR::Instr * LowerStElemC(IR::Instr *instr);
  209. void LowerLdArrHead(IR::Instr *instr);
  210. IR::Instr* AddSlotArrayCheck(PropertySym *propertySym, IR::Instr* instr);
  211. IR::Instr * LowerStSlot(IR::Instr *instr);
  212. IR::Instr * LowerStSlotChkUndecl(IR::Instr *instr);
  213. void LowerStLoopBodyCount(IR::Instr* instr);
  214. #if !FLOATVAR
  215. IR::Instr * LowerStSlotBoxTemp(IR::Instr *instr);
  216. #endif
  217. void LowerLdSlot(IR::Instr *instr);
  218. IR::Instr * LowerChkUndecl(IR::Instr *instr);
  219. void GenUndeclChk(IR::Instr *insertInsert, IR::Opnd *opnd);
  220. IR::Instr * LoadPropertySymAsArgument(IR::Instr *instr, IR::Opnd *fieldSrc);
  221. IR::Instr * LoadFunctionBodyAsArgument(IR::Instr *instr, IR::IntConstOpnd * functionBodySlotOpnd, IR::RegOpnd * envOpnd);
  222. IR::Instr * LoadHelperTemp(IR::Instr * instr, IR::Instr * instrInsert);
  223. IR::Instr * LowerLoadVar(IR::Instr *instr, IR::Opnd *opnd);
  224. void LoadArgumentCount(IR::Instr *const instr);
  225. void LoadStackArgPtr(IR::Instr *const instr);
  226. IR::Instr * InsertLoadStackAddress(StackSym *sym, IR::Instr * instrInsert, IR::RegOpnd *optionalDstOpnd = nullptr);
  227. void LoadArgumentsFromFrame(IR::Instr *const instr);
  228. IR::Instr * LowerUnaryHelper(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::Opnd* opndBailoutArg = nullptr);
  229. IR::Instr * LowerUnaryHelperMem(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::Opnd* opndBailoutArg = nullptr);
  230. IR::Instr * LowerUnaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  231. IR::Instr * LowerUnaryHelperMemWithFunctionInfo(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  232. IR::Instr * LowerBinaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  233. IR::Instr * LowerUnaryHelperMemWithTemp(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  234. IR::Instr * LowerUnaryHelperMemWithTemp2(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod helperMethodWithTemp);
  235. IR::Instr * LowerUnaryHelperMemWithBoolReference(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool useBoolForBailout);
  236. IR::Instr * LowerBinaryHelperMem(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  237. IR::Instr * LowerBinaryHelperMemWithTemp(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  238. IR::Instr * LowerBinaryHelperMemWithTemp2(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod helperMethodWithTemp);
  239. IR::Instr * LowerBinaryHelperMemWithTemp3(IR::Instr *instr, IR::JnHelperMethod helperMethod,
  240. IR::JnHelperMethod helperMethodWithTemp, IR::JnHelperMethod helperMethodLeftDead);
  241. IR::Instr * LowerAddLeftDeadForString(IR::Instr *instr);
  242. IR::Instr * LowerBinaryHelper(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  243. #ifdef ENABLE_WASM
  244. IR::Instr * LowerCheckWasmSignature(IR::Instr * instr);
  245. IR::Instr * LowerLdWasmFunc(IR::Instr* instr);
  246. IR::Instr * LowerGrowWasmMemory(IR::Instr* instr);
  247. #endif
  248. IR::Instr * LowerInitCachedScope(IR::Instr * instr);
  249. IR::Instr * LowerBrBReturn(IR::Instr * instr, IR::JnHelperMethod helperMethod, bool isHelper);
  250. IR::Instr * LowerBrBMem(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  251. IR::Instr * LowerBrOnObject(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  252. IR::Instr * LowerStrictBrOrCm(IR::Instr * instr, IR::JnHelperMethod helperMethod, bool noMathFastPath, bool isBranch, bool isHelper = true);
  253. IR::Instr * LowerBrCMem(IR::Instr * instr, IR::JnHelperMethod helperMethod, bool noMathFastPath, bool isHelper = true);
  254. IR::Instr * LowerBrFncApply(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  255. IR::Instr * LowerBrProperty(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  256. IR::Instr * LowerBrOnClassConstructor(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  257. IR::Instr* LowerMultiBr(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  258. IR::Instr* LowerMultiBr(IR::Instr * instr);
  259. IR::Instr * LowerElementUndefined(IR::Instr * instr, IR::JnHelperMethod helper);
  260. IR::Instr * LowerElementUndefinedMem(IR::Instr * instr, IR::JnHelperMethod helper);
  261. IR::Instr * LowerElementUndefinedScoped(IR::Instr * instr, IR::JnHelperMethod helper);
  262. IR::Instr * LowerElementUndefinedScopedMem(IR::Instr * instr, IR::JnHelperMethod helper);
  263. IR::Instr * LowerLdElemUndef(IR::Instr * instr);
  264. IR::Instr * LowerRestParameter(IR::Opnd *formalsOpnd, IR::Opnd *dstOpnd, IR::Opnd *excessOpnd, IR::Instr *instr, IR::RegOpnd *generatorArgsPtrOpnd);
  265. IR::Instr * LowerArgIn(IR::Instr *instr);
  266. IR::Instr * LowerArgInAsmJs(IR::Instr *instr);
  267. IR::Instr * LowerProfiledNewScArray(IR::JitProfilingInstr* arrInstr);
  268. IR::Instr * LowerNewScArray(IR::Instr *arrInstr);
  269. IR::Instr * LowerNewScIntArray(IR::Instr *arrInstr);
  270. IR::Instr * LowerNewScFltArray(IR::Instr *arrInstr);
  271. IR::Instr * LowerArraySegmentVars(IR::Instr *instr);
  272. IR::Instr * LowerEqualityBranch(IR::Instr* instr, IR::JnHelperMethod helper);
  273. IR::Instr * LowerEqualityCompare(IR::Instr* instr, IR::JnHelperMethod helper);
  274. template <typename ArrayType>
  275. BOOL IsSmallObject(uint32 length);
  276. void GenerateProfiledNewScIntArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef);
  277. void GenerateArrayInfoIsNativeIntArrayTest(IR::Instr * instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, IR::LabelInstr * helperLabel);
  278. void GenerateProfiledNewScFloatArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef);
  279. void GenerateArrayInfoIsNativeFloatAndNotIntArrayTest(IR::Instr * instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, IR::LabelInstr * helperLabel);
  280. bool IsEmitTempDst(IR::Opnd *opnd);
  281. bool IsEmitTempSrc(IR::Opnd *opnd);
  282. bool IsNullOrUndefRegOpnd(IR::RegOpnd *opnd) const;
  283. bool IsConstRegOpnd(IR::RegOpnd *opnd) const;
  284. IR::Opnd * GetConstRegOpnd(IR::RegOpnd *opnd, IR::Instr *instr);
  285. IR::Instr * GenerateRuntimeError(IR::Instr * insertBeforeInstr, Js::MessageId errorCode, IR::JnHelperMethod helper = IR::JnHelperMethod::HelperOp_RuntimeTypeError);
  286. bool InlineBuiltInLibraryCall(IR::Instr *callInstr);
  287. void LowerInlineBuiltIn(IR::Instr* instr);
  288. intptr_t GetObjRefForBuiltInTarget(IR::RegOpnd * opnd);
  289. bool TryGenerateFastCmSrXx(IR::Instr * instr);
  290. bool TryGenerateFastBrEq(IR::Instr * instr);
  291. bool TryGenerateFastBrNeq(IR::Instr * instr);
  292. bool TryGenerateFastBrSrXx(IR::Instr * instr, IR::RegOpnd * srcReg1, IR::RegOpnd * srcReg2, IR::Instr ** pInstrPrev, bool noMathFastPath);
  293. IR::BranchInstr* GenerateFastBrConst(IR::BranchInstr *branchInstr, IR::Opnd * constOpnd, bool isEqual);
  294. bool GenerateFastCondBranch(IR::BranchInstr * instrBranch, bool *pIsHelper);
  295. void GenerateBooleanNegate(IR::Instr * instr, IR::Opnd * srcBool, IR::Opnd * dst);
  296. bool GenerateJSBooleanTest(IR::RegOpnd * regSrc, IR::Instr * insertInstr, IR::LabelInstr * labelTarget, bool fContinueLabel = false);
  297. bool GenerateFastEqBoolInt(IR::Instr * instr, bool *pIsHelper, bool isInHelper);
  298. bool GenerateFastBrOrCmEqDefinite(IR::Instr * instrBranch, IR::JnHelperMethod helperMethod, bool *pNeedHelper, bool isBranch, bool isInHelper);
  299. bool GenerateFastBrEqLikely(IR::BranchInstr * instrBranch, bool *pNeedHelper, bool isInHelper);
  300. bool GenerateFastBooleanAndObjectEqLikely(IR::Instr * instr, IR::Opnd *src1, IR::Opnd *src2, IR::LabelInstr * labelHelper, IR::LabelInstr * labelEqualLikely, bool *pNeedHelper, bool isInHelper);
  301. bool GenerateFastCmEqLikely(IR::Instr * instr, bool *pNeedHelper, bool isInHelper);
  302. bool GenerateFastBrBool(IR::BranchInstr *const instr);
  303. bool GenerateFastStringCheck(IR::Instr *instr, IR::RegOpnd *srcReg1, IR::RegOpnd *srcReg2, bool isEqual, bool isStrict, IR::LabelInstr *labelHelper, IR::LabelInstr *labelBranchSuccess, IR::LabelInstr *labelBranchFail);
  304. bool GenerateFastBrOrCmString(IR::Instr* instr);
  305. void GenerateDynamicLoadPolymorphicInlineCacheSlot(IR::Instr * instrInsert, IR::RegOpnd * inlineCacheOpnd, IR::Opnd * objectTypeOpnd);
  306. static IR::Instr *LoadFloatFromNonReg(IR::Opnd * opndOrig, IR::Opnd * regOpnd, IR::Instr * instrInsert);
  307. void LoadInt32FromUntaggedVar(IR::Instr *const instrLoad);
  308. bool GetValueFromIndirOpnd(IR::IndirOpnd *indirOpnd, IR::Opnd **pValueOpnd, IntConstType *pValue);
  309. void GenerateFastBrOnObject(IR::Instr *instr);
  310. void GenerateObjectTypeTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr *labelHelper);
  311. static IR::LabelInstr* InsertContinueAfterExceptionLabelForDebugger(Func* func, IR::Instr* insertAfterInstr, bool isHelper);
  312. void GenerateObjectHeaderInliningTest(IR::RegOpnd *baseOpnd, IR::LabelInstr * target, IR::Instr *insertBeforeInstr);
  313. // Static tables that will be used by the GetArray* methods below
  314. private:
  315. static const VTableValue VtableAddresses[static_cast<ValueType::TSize>(ObjectType::Count)];
  316. static const uint32 OffsetsOfHeadSegment[static_cast<ValueType::TSize>(ObjectType::Count)];
  317. static const uint32 OffsetsOfLength[static_cast<ValueType::TSize>(ObjectType::Count)];
  318. static const IRType IndirTypes[static_cast<ValueType::TSize>(ObjectType::Count)];
  319. static const BYTE IndirScales[static_cast<ValueType::TSize>(ObjectType::Count)];
  320. private:
  321. static VTableValue GetArrayVtableAddress(const ValueType valueType, bool getVirtual = false);
  322. public:
  323. static uint32 GetArrayOffsetOfHeadSegment(const ValueType valueType);
  324. static uint32 GetArrayOffsetOfLength(const ValueType valueType);
  325. static IRType GetArrayIndirType(const ValueType valueType);
  326. static BYTE GetArrayIndirScale(const ValueType valueType);
  327. static int SimdGetElementCountFromBytes(ValueType arrValueType, uint8 dataWidth);
  328. private:
  329. bool ShouldGenerateArrayFastPath(const IR::Opnd *const arrayOpnd, const bool supportsObjectsWithArrays, const bool supportsTypedArrays, const bool requiresSse2ForFloatArrays) const;
  330. IR::RegOpnd * LoadObjectArray(IR::RegOpnd *const baseOpnd, IR::Instr *const insertBeforeInstr);
  331. IR::RegOpnd * GenerateArrayTest(IR::RegOpnd *const baseOpnd, IR::LabelInstr *const isNotObjectLabel, IR::LabelInstr *const isNotArrayLabel, IR::Instr *const insertBeforeInstr, const bool forceFloat, const bool isStore = false, const bool allowDefiniteArray = false);
  332. void GenerateIsEnabledArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  333. void GenerateIsEnabledIntArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  334. void GenerateIsEnabledFloatArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  335. void GenerateStringTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr * failLabel, IR::LabelInstr * succeedLabel = nullptr, bool generateObjectCheck = true);
  336. void GenerateSymbolTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr * failLabel, IR::LabelInstr * succeedLabel = nullptr, bool generateObjectCheck = true);
  337. void GeneratePropertyStringTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr *labelHelper, bool usePoison);
  338. IR::RegOpnd * GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * labelFail, IR::Instr * insertBeforeInstr, bool generateTagCheck = true);
  339. void GenerateNotZeroTest( IR::Opnd * opndSrc, IR::LabelInstr * labelZero, IR::Instr * instrInsert);
  340. IR::Opnd * CreateOpndForSlotAccess(IR::Opnd * opnd);
  341. IR::RegOpnd * GetRegOpnd(IR::Opnd * opnd, IR::Instr * insertInstr, Func * func, IRType type);
  342. void GenerateSwitchStringLookup(IR::Instr * instr);
  343. void GenerateSingleCharStrJumpTableLookup(IR::Instr * instr);
  344. void LowerJumpTableMultiBranch(IR::MultiBranchInstr * multiBrInstr, IR::RegOpnd * indexOpnd);
  345. void LowerConvNum(IR::Instr *instrLoad, bool noMathFastPath);
  346. void InsertBitTestBranch(IR::Opnd * bitMaskOpnd, IR::Opnd * bitIndex, bool jumpIfBitOn, IR::LabelInstr * targetLabel, IR::Instr * insertBeforeInstr);
  347. void GenerateGetSingleCharString(IR::RegOpnd * charCodeOpnd, IR::Opnd * resultOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * doneLabel, IR::Instr * instr, bool isCodePoint);
  348. void GenerateFastBrBReturn(IR::Instr * instr);
  349. public:
  350. static IR::Instr *HoistIndirOffset(IR::Instr* instr, IR::IndirOpnd *indirOpnd, RegNum regNum);
  351. static IR::Instr *HoistIndirOffsetAsAdd(IR::Instr* instr, IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum);
  352. static IR::Instr *HoistIndirIndexOpndAsAdd(IR::Instr* instr, IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, IR::Opnd *indexOpnd, RegNum regNum);
  353. static IR::Instr *HoistSymOffset(IR::Instr *instr, IR::SymOpnd *symOpnd, RegNum baseReg, uint32 offset, RegNum regNum);
  354. static IR::Instr *HoistSymOffsetAsAdd(IR::Instr* instr, IR::SymOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum);
  355. static IR::LabelInstr * InsertLabel(const bool isHelper, IR::Instr *const insertBeforeInstr);
  356. static IR::Instr * InsertMove(IR::Opnd *dst, IR::Opnd *src, IR::Instr *const insertBeforeInstr, bool generateWriteBarrier = true);
  357. static IR::Instr * InsertMoveWithBarrier(IR::Opnd *dst, IR::Opnd *src, IR::Instr *const insertBeforeInstr);
  358. #if _M_X64
  359. static IR::Instr * InsertMoveBitCast(IR::Opnd *const dst, IR::Opnd *const src1, IR::Instr *const insertBeforeInstr);
  360. #endif
  361. static IR::BranchInstr * InsertBranch(const Js::OpCode opCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  362. static IR::BranchInstr * InsertBranch(const Js::OpCode opCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  363. static IR::Instr * InsertCompare(IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  364. IR::BranchInstr * InsertCompareBranch(IR::Opnd *const compareSrc1, IR::Opnd *const compareSrc2, Js::OpCode branchOpCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr, const bool ignoreNaN = false);
  365. IR::BranchInstr * InsertCompareBranch(IR::Opnd *compareSrc1, IR::Opnd *compareSrc2, Js::OpCode branchOpCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr, const bool ignoreNaN = false);
  366. static IR::Instr * InsertTest(IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  367. static IR::BranchInstr * InsertTestBranch(IR::Opnd *const testSrc1, IR::Opnd *const testSrc2, const Js::OpCode branchOpCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  368. static IR::BranchInstr * InsertTestBranch(IR::Opnd *const testSrc1, IR::Opnd *const testSrc2, const Js::OpCode branchOpCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  369. static IR::Instr * InsertAdd(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
  370. static IR::Instr * InsertSub(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
  371. static IR::Instr * InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  372. static IR::Instr * ChangeToLea(IR::Instr *const instr);
  373. static IR::Instr * InsertXor(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  374. static IR::Instr * InsertAnd(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  375. static IR::Instr * InsertOr(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  376. static IR::Instr * InsertShift(const Js::OpCode opCode, const bool needFlags, IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  377. static IR::Instr * InsertShiftBranch(const Js::OpCode shiftOpCode, IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, const Js::OpCode branchOpCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  378. static IR::Instr * InsertShiftBranch(const Js::OpCode shiftOpCode, IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, const Js::OpCode branchOpCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  379. static IR::Instr * InsertConvertFloat32ToFloat64(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  380. static IR::Instr * InsertConvertFloat64ToFloat32(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  381. public:
  382. static void InsertDecUInt32PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
  383. static void InsertAddWithOverflowCheck(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr, IR::Instr **const onOverflowInsertBeforeInstrRef);
  384. void InsertFloatCheckForZeroOrNanBranch(IR::Opnd *const src, const bool branchOnZeroOrNan, IR::LabelInstr *const target, IR::LabelInstr *const fallthroughLabel, IR::Instr *const insertBeforeInstr);
  385. public:
  386. static IR::HelperCallOpnd* CreateHelperCallOpnd(IR::JnHelperMethod helperMethod, int helperArgCount, Func* func);
  387. static IR::Opnd * GetMissingItemOpnd(IRType type, Func *func);
  388. static IR::Opnd * GetMissingItemOpndForAssignment(IRType type, Func *func);
  389. static IR::Opnd * GetMissingItemOpndForCompare(IRType type, Func *func);
  390. static IR::Opnd * GetImplicitCallFlagsOpnd(Func * func);
  391. inline static IR::IntConstOpnd* MakeCallInfoConst(ushort flags, int32 argCount, Func* func) {
  392. argCount = Js::CallInfo::GetArgCountWithoutExtraArgs((Js::CallFlags)flags, (uint16)argCount);
  393. #ifdef _M_X64
  394. // This was defined differently for x64
  395. Js::CallInfo callInfo = Js::CallInfo((Js::CallFlags)flags, (unsigned __int16)argCount);
  396. return IR::IntConstOpnd::New(*((IntConstType *)((void *)&callInfo)), TyInt32, func, true);
  397. #else
  398. AssertMsg(!(argCount & 0xFF000000), "Too many arguments"); //final 8 bits are for flags
  399. AssertMsg(!(flags & ~0xFF), "Flags are invalid!"); //8 bits for flags
  400. return IR::IntConstOpnd::New(argCount | (flags << 24), TyMachReg, func, true);
  401. #endif
  402. }
  403. static void InsertAndLegalize(IR::Instr * instr, IR::Instr* insertBeforeInstr);
  404. private:
  405. IR::IndirOpnd* GenerateFastElemICommon(
  406. _In_ IR::Instr* elemInstr,
  407. _In_ bool isStore,
  408. _In_ IR::IndirOpnd* indirOpnd,
  409. _In_ IR::LabelInstr* labelHelper,
  410. _In_ IR::LabelInstr* labelCantUseArray,
  411. _In_opt_ IR::LabelInstr* labelFallthrough,
  412. _Out_ bool* pIsTypedArrayElement,
  413. _Out_ bool* pIsStringIndex,
  414. _Out_opt_ bool* emitBailoutRef,
  415. _Outptr_opt_result_maybenull_ IR::Opnd** maskOpnd,
  416. _Outptr_opt_result_maybenull_ IR::LabelInstr** pLabelSegmentLengthIncreased = nullptr,
  417. _In_ bool checkArrayLengthOverflow = true,
  418. _In_ bool forceGenerateFastPath = false,
  419. _In_ bool returnLength = false,
  420. _In_opt_ IR::LabelInstr* bailOutLabelInstr = nullptr,
  421. _Out_opt_ bool* indirOpndOverflowed = nullptr,
  422. _In_ Js::FldInfoFlags flags = Js::FldInfo_NoInfo);
  423. IR::IndirOpnd * GenerateFastElemIIntIndexCommon(
  424. IR::Instr * ldElem,
  425. bool isStore,
  426. IR::IndirOpnd * indirOpnd,
  427. IR::LabelInstr * labelHelper,
  428. IR::LabelInstr * labelCantUseArray,
  429. IR::LabelInstr *labelFallthrough,
  430. bool * pIsTypedArrayElement,
  431. bool *emitBailoutRef,
  432. IR::LabelInstr **pLabelSegmentLengthIncreased,
  433. bool checkArrayLengthOverflow,
  434. IR::Opnd** maskOpnd,
  435. bool forceGenerateFastPath = false,
  436. bool returnLength = false,
  437. IR::LabelInstr *bailOutLabelInstr = nullptr,
  438. bool * indirOpndOverflowed = nullptr);
  439. IR::IndirOpnd* GenerateFastElemIStringIndexCommon(
  440. _In_ IR::Instr* elemInstr,
  441. _In_ bool isStore,
  442. _In_ IR::IndirOpnd* indirOpnd,
  443. _In_ IR::LabelInstr* labelHelper,
  444. _In_ Js::FldInfoFlags flags);
  445. IR::IndirOpnd* GenerateFastElemISymbolIndexCommon(
  446. _In_ IR::Instr* elemInstr,
  447. _In_ bool isStore,
  448. _In_ IR::IndirOpnd* indirOpnd,
  449. _In_ IR::LabelInstr* labelHelper,
  450. _In_ Js::FldInfoFlags flags);
  451. IR::IndirOpnd* GenerateFastElemISymbolOrStringIndexCommon(
  452. _In_ IR::Instr* instrInsert,
  453. _In_ IR::RegOpnd* indexOpnd,
  454. _In_ IR::RegOpnd* baseOpnd,
  455. _In_ const uint32 inlineCacheOffset,
  456. _In_ const uint32 hitRateOffset,
  457. _In_ IR::LabelInstr* labelHelper,
  458. _In_ Js::FldInfoFlags flags);
  459. void GenerateLookUpInIndexCache(
  460. _In_ IR::Instr* instrInsert,
  461. _In_ IR::RegOpnd* indexOpnd,
  462. _In_ IR::RegOpnd* baseOpnd,
  463. _In_opt_ IR::RegOpnd* opndSlotArray,
  464. _In_opt_ IR::RegOpnd* opndSlotIndex,
  465. _In_ const uint32 inlineCacheOffset,
  466. _In_ const uint32 hitRateOffset,
  467. _In_ IR::LabelInstr* labelHelper,
  468. _In_ Js::FldInfoFlags flags = Js::FldInfo_NoInfo);
  469. template <bool CheckLocal, bool CheckInlineSlot, bool DoAdd>
  470. void GenerateLookUpInIndexCacheHelper(
  471. _In_ IR::Instr* instrInsert,
  472. _In_ IR::RegOpnd* baseOpnd,
  473. _In_opt_ IR::RegOpnd* opndSlotArray,
  474. _In_opt_ IR::RegOpnd* opndSlotIndex,
  475. _In_ IR::RegOpnd* objectTypeOpnd,
  476. _In_ IR::RegOpnd* inlineCacheOpnd,
  477. _In_ IR::LabelInstr* doneLabel,
  478. _In_ IR::LabelInstr* helperLabel,
  479. _Outptr_ IR::LabelInstr** nextLabel,
  480. _Outptr_ IR::BranchInstr** branchToPatch,
  481. _Inout_ IR::RegOpnd** taggedTypeOpnd);
  482. void GenerateFastIsInSymbolOrStringIndex(IR::Instr * instrInsert, IR::RegOpnd *indexOpnd, IR::RegOpnd *baseOpnd, IR::Opnd *dest, uint32 inlineCacheOffset, const uint32 hitRateOffset, IR::LabelInstr * labelHelper, IR::LabelInstr * labelDone);
  483. IR::BranchInstr* InsertMissingItemCompareBranch(IR::Opnd* compareSrc, Js::OpCode opcode, IR::LabelInstr* target, IR::Instr* insertBeforeInstr);
  484. bool GenerateFastLdElemI(IR::Instr *& ldElem, bool *instrIsInHelperBlockRef);
  485. bool GenerateFastStElemI(IR::Instr *& StElem, bool *instrIsInHelperBlockRef);
  486. bool GenerateFastLdLen(IR::Instr *ldLen, bool *instrIsInHelperBlockRef);
  487. bool GenerateFastCharAt(Js::BuiltinFunction index, IR::Opnd *dst, IR::Opnd *srcStr, IR::Opnd *srcIndex, IR::Instr *callInstr, IR::Instr *insertInstr,
  488. IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  489. bool GenerateFastInlineGlobalObjectParseInt(IR::Instr *instr);
  490. bool GenerateFastInlineStringFromCharCode(IR::Instr* instr);
  491. bool GenerateFastInlineStringFromCodePoint(IR::Instr* instr);
  492. void GenerateFastInlineStringCodePointAt(IR::Instr* doneLabel, Func* func, IR::Opnd *strLength, IR::Opnd *srcIndex, IR::RegOpnd *lowerChar, IR::RegOpnd *strPtr);
  493. bool GenerateFastInlineStringCharCodeAt(IR::Instr* instr, Js::BuiltinFunction index);
  494. bool GenerateFastInlineStringReplace(IR::Instr* instr);
  495. void GenerateFastInlineIsArray(IR::Instr * instr);
  496. void GenerateFastInlineHasOwnProperty(IR::Instr * instr);
  497. void GenerateFastInlineArrayPush(IR::Instr * instr);
  498. void GenerateFastInlineArrayPop(IR::Instr * instr);
  499. void GenerateFastInlineStringSplitMatch(IR::Instr * instr);
  500. void GenerateFastInlineMathImul(IR::Instr* instr);
  501. void GenerateFastInlineMathClz(IR::Instr* instr);
  502. void GenerateCtz(IR::Instr* instr);
  503. void GeneratePopCnt(IR::Instr* instr);
  504. template <bool Saturate> void GenerateTruncWithCheck(_In_ IR::Instr* instr);
  505. void GenerateFastInlineMathFround(IR::Instr* instr);
  506. void GenerateFastInlineRegExpExec(IR::Instr * instr);
  507. bool GenerateFastPush(IR::Opnd *baseOpndParam, IR::Opnd *src, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel, IR::LabelInstr * bailOutLabelHelper, bool returnLength = false);
  508. bool GenerateFastReplace(IR::Opnd* strOpnd, IR::Opnd* src1, IR::Opnd* src2, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  509. bool ShouldGenerateStringReplaceFastPath(IR::Instr * instr, IntConstType argCount);
  510. bool GenerateFastPop(IR::Opnd *baseOpndParam, IR::Instr *callInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel, IR::LabelInstr * bailOutLabelHelper);
  511. bool GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelper, IR::LabelInstr * labelFallThru);
  512. IR::Instr * LowerCallDirect(IR::Instr * instr);
  513. IR::Instr * GenerateDirectCall(IR::Instr* inlineInstr, IR::Opnd* funcObj, ushort callflags);
  514. IR::Instr * GenerateFastInlineBuiltInMathRandom(IR::Instr* instr);
  515. IR::Instr * GenerateHelperToArrayPushFastPath(IR::Instr * instr, IR::LabelInstr * bailOutLabelHelper);
  516. IR::Instr * GenerateHelperToArrayPopFastPath(IR::Instr * instr, IR::LabelInstr * doneLabel, IR::LabelInstr * bailOutLabelHelper);
  517. IR::Instr * LowerCondBranchCheckBailOut(IR::BranchInstr * instr, IR::Instr * helperCall, bool isHelper);
  518. IR::Instr * LowerBailOnEqualOrNotEqual(IR::Instr * instr, IR::BranchInstr * branchInstr = nullptr, IR::LabelInstr * labelBailOut = nullptr, IR::PropertySymOpnd * propSymOpnd = nullptr, bool isHelper = false);
  519. void LowerBailOnNegative(IR::Instr *const instr);
  520. void LowerBailoutCheckAndLabel(IR::Instr *instr, bool onEqual, bool isHelper);
  521. IR::Instr * LowerBailOnNotSpreadable(IR::Instr *instr);
  522. IR::Instr * LowerBailOnNotPolymorphicInlinee(IR::Instr * instr);
  523. IR::Instr * LowerBailOnNotStackArgs(IR::Instr * instr);
  524. IR::Instr * LowerBailOnNotObject(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  525. IR::Instr * LowerCheckIsFuncObj(IR::Instr *instr, bool checkFuncInfo = false);
  526. IR::Instr * LowerBailOnTrue(IR::Instr *instr, IR::LabelInstr *labelBailOut = nullptr);
  527. IR::Instr * LowerBailOnNotBuiltIn(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  528. IR::Instr * LowerBailOnNotInteger(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  529. IR::Instr * LowerBailOnIntMin(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  530. void LowerBailOnNotString(IR::Instr *instr);
  531. IR::Instr * LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper = false);
  532. IR::Instr * LowerBailOnException(IR::Instr* instr);
  533. void LowerReinterpretPrimitive(IR::Instr* instr);
  534. IR::Instr * LowerBailOnEarlyExit(IR::Instr* instr);
  535. void LowerOneBailOutKind(IR::Instr *const instr, const IR::BailOutKind bailOutKindToLower, const bool isInHelperBlock, const bool preserveBailOutKindInInstr = false);
  536. void SplitBailOnNotArray(IR::Instr *const instr, IR::Instr * *const bailOnNotArrayRef, IR::Instr * *const bailOnMissingValueRef);
  537. IR::RegOpnd * LowerBailOnNotArray(IR::Instr *const instr);
  538. void LowerBailOnMissingValue(IR::Instr *const instr, IR::RegOpnd *const arrayOpnd);
  539. void LowerBailOnInvalidatedArrayHeadSegment(IR::Instr *const instr, const bool isInHelperBlock);
  540. void LowerBailOnInvalidatedArrayLength(IR::Instr *const instr, const bool isInHelperBlock);
  541. void LowerBailOnCreatedMissingValue(IR::Instr *const instr, const bool isInHelperBlock);
  542. void LowerBoundCheck(IR::Instr *const instr);
  543. IR::Opnd* GetFuncObjectOpnd(IR::Instr* insertBeforeInstr);
  544. IR::Instr* LoadFuncExpression(IR::Instr *instrFuncExpr);
  545. IR::Instr * LowerBailTarget(IR::Instr * instr);
  546. IR::Instr * SplitBailOnImplicitCall(IR::Instr *& instr);
  547. IR::Instr * SplitBailOnImplicitCall(IR::Instr * instr, IR::Instr * helperCall, IR::Instr * insertBeforeInstr);
  548. IR::Instr * SplitBailForDebugger(IR::Instr* instr);
  549. IR::Instr * SplitBailOnResultCondition(IR::Instr *const instr) const;
  550. void LowerBailOnResultCondition(IR::Instr *const instr, IR::LabelInstr * *const bailOutLabel, IR::LabelInstr * *const skipBailOutLabel);
  551. void PreserveSourcesForBailOnResultCondition(IR::Instr *const instr, IR::LabelInstr *const skipBailOutLabel) const;
  552. void LowerInstrWithBailOnResultCondition(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel) const;
  553. void GenerateObjectTestAndTypeLoad(IR::Instr *instrLdSt, IR::RegOpnd *opndBase, IR::RegOpnd *opndType, IR::LabelInstr *labelHelper);
  554. void InsertMoveForPolymorphicCacheIndex(IR::Instr * instr, BailOutInfo * bailOutInfo, int bailOutRecordOffset, uint polymorphicCacheIndexValue);
  555. IR::LabelInstr *GenerateBailOut(IR::Instr * instr, IR::BranchInstr * branchInstr = nullptr, IR::LabelInstr * labelBailOut = nullptr, IR::LabelInstr * collectRuntimeStatsLabel = nullptr);
  556. void GenerateJumpToEpilogForBailOut(BailOutInfo * bailOutInfo, IR::Instr *instrAfter, IR::LabelInstr *exitTargetInstr);
  557. void GenerateThrow(IR::Opnd* errorCode, IR::Instr * instr);
  558. void LowerDivI4(IR::Instr * const instr);
  559. void LowerRemI4(IR::Instr * const instr);
  560. void LowerTrapIfZero(IR::Instr * const instr);
  561. void LowerTrapIfMinIntOverNegOne(IR::Instr * const instr);
  562. IR::Instr* LowerTrapIfUnalignedAccess(IR::Instr * const instr);
  563. void LowerDivI4Common(IR::Instr * const instr);
  564. void LowerRemR8(IR::Instr * const instr);
  565. void LowerRemR4(IR::Instr * const instr);
  566. IR::Instr* LowerInlineeStart(IR::Instr * instr);
  567. void LowerInlineeEnd(IR::Instr * instr);
  568. static
  569. IR::SymOpnd* LoadCallInfo(IR::Instr * instrInsert);
  570. IR::Instr * LowerCallIDynamic(IR::Instr * callInstr, ushort callFlags);
  571. IR::Opnd* GenerateArgOutForInlineeStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
  572. IR::Opnd* GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
  573. void GenerateLoadStackArgumentByIndex(IR::Opnd *dst, IR::RegOpnd *indexOpnd, IR::Instr *instr, int32 offset, Func *func);
  574. bool GenerateFastStackArgumentsLdElemI(IR::Instr* ldElem);
  575. IR::IndirOpnd* GetArgsIndirOpndForInlinee(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  576. IR::IndirOpnd* GetArgsIndirOpndForTopFunction(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  577. void GenerateCheckForArgumentsLength(IR::Instr* ldElem, IR::LabelInstr* labelCreateHeapArgs, IR::Opnd* actualParamOpnd, IR::Opnd* valueOpnd, Js::OpCode opcode);
  578. bool GenerateFastArgumentsLdElemI(IR::Instr* ldElem, IR::LabelInstr *labelFallThru);
  579. bool GenerateFastRealStackArgumentsLdLen(IR::Instr *ldLen);
  580. bool GenerateFastArgumentsLdLen(IR::Instr *ldLen, IR::LabelInstr* labelFallThru);
  581. static uint16 GetFormalParamOffset() { /*formal start after frame pointer, return address, function object, callInfo*/ return 4;};
  582. IR::RegOpnd* GenerateFunctionTypeFromFixedFunctionObject(IR::Instr *callInstr, IR::Opnd* functionObjOpnd);
  583. bool GenerateFastLdFld(IR::Instr * const instrLdFld, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod,
  584. IR::LabelInstr ** labelBailOut, IR::RegOpnd* typeOpnd, bool* pIsHelper, IR::LabelInstr** pLabelHelper);
  585. void GenerateAuxSlotAdjustmentRequiredCheck(IR::Instr * instrToInsertBefore, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelHelper);
  586. void GenerateSetObjectTypeFromInlineCache(IR::Instr * instrToInsertBefore, IR::RegOpnd * opndBase, IR::RegOpnd * opndInlineCache, bool isTypeTagged);
  587. bool GenerateFastStFld(IR::Instr * const instrStFld, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod,
  588. IR::LabelInstr ** labelBailOut, IR::RegOpnd* typeOpnd, bool* pIsHelper, IR::LabelInstr** pLabelHelper, bool withPutFlags = false, Js::PropertyOperationFlags flags = Js::PropertyOperation_None);
  589. void GenerateAuxSlotPtrLoad(IR::PropertySymOpnd *propertySymOpnd, IR::Instr *insertInstr);
  590. bool GenerateFastStFldForCustomProperty(IR::Instr *const instr, IR::LabelInstr * *const labelHelperRef);
  591. void RelocateCallDirectToHelperPath(IR::Instr* argoutInlineSpecialized, IR::LabelInstr* labelHelper);
  592. bool TryGenerateFastBrOrCmTypeOf(IR::Instr *instr, IR::Instr **prev, bool isNeqOp, bool *pfNoLower);
  593. void GenerateFastBrTypeOf(IR::Instr *branch, IR::RegOpnd *object, IR::IntConstOpnd *typeIdOpnd, IR::Instr *typeOf, bool *pfNoLower, bool isNeqOp);
  594. void GenerateFastCmTypeOf(IR::Instr *compare, IR::RegOpnd *object, IR::IntConstOpnd *typeIdOpnd, IR::Instr *typeOf, bool *pfNoLower, bool isNeqOp);
  595. void GenerateFalsyObjectTest(IR::Instr *insertInstr, IR::RegOpnd *typeOpnd, Js::TypeId typeIdToCheck, IR::LabelInstr* target, IR::LabelInstr* done, bool isNeqOp);
  596. void GenerateFalsyObjectTest(IR::Instr * insertInstr, IR::RegOpnd * typeOpnd, IR::LabelInstr * falsyLabel);
  597. void GenerateJavascriptOperatorsIsConstructorGotoElse(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelTrue, IR::LabelInstr *labelFalse);
  598. void GenerateRecyclableObjectGetPrototypeNullptrGoto(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelReturnNullptr);
  599. void GenerateRecyclableObjectIsElse(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelFalse);
  600. void GenerateLdHomeObj(IR::Instr* instr);
  601. void GenerateLdHomeObjProto(IR::Instr* instr);
  602. void GenerateLdFuncObj(IR::Instr* instr);
  603. void GenerateLdFuncObjProto(IR::Instr* instr);
  604. void GenerateLoadNewTarget(IR::Instr* instrInsert);
  605. void GenerateCheckForCallFlagNew(IR::Instr* instrInsert);
  606. void GenerateGetCurrentFunctionObject(IR::Instr * instr);
  607. IR::Opnd * GetInlineCacheFromFuncObjectForRuntimeUse(IR::Instr * instr, IR::PropertySymOpnd * propSymOpnd, bool isHelper);
  608. IR::Instr * LowerNewClassConstructor(IR::Instr * instr);
  609. IR::RegOpnd * GenerateGetImmutableOrScriptUnreferencedString(IR::RegOpnd * strOpnd, IR::Instr * insertBeforeInstr, IR::JnHelperMethod helperMethod, bool loweringCloneStr = false, bool reloadDst = true);
  610. void LowerNewConcatStrMulti(IR::Instr * instr);
  611. void LowerNewConcatStrMultiBE(IR::Instr * instr);
  612. void LowerSetConcatStrMultiItem(IR::Instr * instr);
  613. void LowerConvStr(IR::Instr * instr);
  614. void LowerCoerseStr(IR::Instr * instr);
  615. void LowerCoerseRegex(IR::Instr * instr);
  616. void LowerCoerseStrOrRegex(IR::Instr * instr);
  617. void LowerConvPrimStr(IR::Instr * instr);
  618. void LowerConvStrCommon(IR::JnHelperMethod helper, IR::Instr * instr);
  619. void LowerConvPropertyKey(IR::Instr* instr);
  620. void GenerateRecyclerAlloc(IR::JnHelperMethod allocHelper, size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, bool inOpHelper = false);
  621. template <typename ArrayType>
  622. IR::RegOpnd * GenerateArrayAllocHelper(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed, bool isArrayObjCtor, bool isNoArgs);
  623. template <typename ArrayType>
  624. IR::RegOpnd * GenerateArrayLiteralsAlloc(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed);
  625. template <typename ArrayType>
  626. IR::RegOpnd * GenerateArrayObjectsAlloc(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed, bool isNoArgs);
  627. template <typename ArrayType>
  628. IR::RegOpnd * GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * sizeOpnd, Js::ArrayCallSiteInfo * arrayInfo);
  629. bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
  630. template <typename ArrayType>
  631. bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel, IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef);
  632. bool GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
  633. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  634. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  635. void GenerateMemInitNull(IR::RegOpnd * opnd, int32 offset, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  636. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, IR::Opnd * value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  637. void GenerateMemInit(IR::RegOpnd * opnd, IR::RegOpnd * offset, IR::Opnd * value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  638. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr);
  639. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr);
  640. void GenerateRecyclerMemInitNull(IR::RegOpnd * opnd, int32 offset, IR::Instr * insertBeforeInstr);
  641. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, IR::Opnd * value, IR::Instr * insertBeforeInstr);
  642. void GenerateMemCopy(IR::Opnd * dst, IR::Opnd * src, uint32 size, IR::Instr * insertBeforeInstr);
  643. void GenerateDynamicObjectAlloc(IR::Instr * newObjInstr, uint inlineSlotCount, uint slotCount, IR::RegOpnd * newObjDst, IR::Opnd * typeSrc);
  644. bool GenerateSimplifiedInt4Rem(IR::Instr *const remInstr, IR::LabelInstr *const skipBailOutLabel = nullptr) const;
  645. IR::Instr* GenerateCallProfiling(Js::ProfileId profileId, Js::InlineCacheIndex inlineCacheIndex, IR::Opnd* retval, IR::Opnd*calleeFunctionObjOpnd, IR::Opnd* callInfo, bool returnTypeOnly, IR::Instr*callInstr, IR::Instr*insertAfter);
  646. IR::Opnd* GetImplicitCallFlagsOpnd();
  647. IR::Opnd* CreateClearImplicitCallFlagsOpnd();
  648. void GenerateFlagInlineCacheCheckForGetterSetter(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  649. void GenerateLdFldFromFlagInlineCache(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  650. static IR::BranchInstr * GenerateLocalInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext, bool checkTypeWithoutProperty = false);
  651. static IR::BranchInstr * GenerateProtoInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  652. static void GenerateLdFldFromLocalInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  653. static void GenerateLdFldFromProtoInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  654. IR::Instr * LoadScriptContext(IR::Instr *instr);
  655. IR::Instr * LoadFunctionBody(IR::Instr * instr);
  656. IR::Opnd * LoadFunctionBodyOpnd(IR::Instr *instr);
  657. IR::Opnd * LoadFunctionInfoOpnd(IR::Instr *instr);
  658. IR::Opnd * LoadScriptContextOpnd(IR::Instr *instr);
  659. IR::Opnd * LoadScriptContextValueOpnd(IR::Instr * instr, ScriptContextValue valueType);
  660. IR::Opnd * LoadLibraryValueOpnd(IR::Instr * instr, LibraryValue valueType);
  661. IR::Opnd * LoadVTableValueOpnd(IR::Instr * instr, VTableValue vtableType);
  662. IR::Opnd * LoadOptimizationOverridesValueOpnd(IR::Instr *instr, OptimizationOverridesValue valueType);
  663. IR::Opnd * LoadNumberAllocatorValueOpnd(IR::Instr *instr, NumberAllocatorValue valueType);
  664. IR::Opnd * LoadIsInstInlineCacheOpnd(IR::Instr *instr, uint inlineCacheIndex);
  665. IR::Opnd * LoadRuntimeInlineCacheOpnd(IR::Instr * instr, IR::PropertySymOpnd * sym, bool isHelper = false);
  666. void LowerSpreadArrayLiteral(IR::Instr *instr);
  667. IR::Instr* LowerSpreadCall(IR::Instr *instr, Js::CallFlags callFlags, bool setupProfiledVersion = false);
  668. void LowerInlineSpreadArgOutLoopUsingRegisters(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd);
  669. IR::Instr* LowerCallIDynamicSpread(IR::Instr * callInstr, ushort callFlags);
  670. void LowerNewScopeSlots(IR::Instr * instr, bool doStackSlots);
  671. void LowerLdFrameDisplay(IR::Instr * instr, bool doStackDisplay);
  672. void LowerLdInnerFrameDisplay(IR::Instr * instr);
  673. IR::AddrOpnd * CreateFunctionBodyOpnd(Func *const func) const;
  674. IR::AddrOpnd * CreateFunctionBodyOpnd(Js::FunctionBody *const functionBody) const;
  675. bool GenerateRecyclerOrMarkTempAlloc(IR::Instr * instr, IR::RegOpnd * dstOpnd, IR::JnHelperMethod allocHelper, size_t allocSize, IR::SymOpnd ** tempObjectSymOpnd);
  676. IR::SymOpnd * GenerateMarkTempAlloc(IR::RegOpnd *const dstOpnd, const size_t allocSize, IR::Instr *const insertBeforeInstr);
  677. void LowerBrFncCachedScopeEq(IR::Instr *instr);
  678. IR::Instr* InsertLoweredRegionStartMarker(IR::Instr* instrToInsertBefore);
  679. IR::Instr* RemoveLoweredRegionStartMarker(IR::Instr* startMarkerInstr);
  680. void ConvertArgOpndIfGeneratorFunction(IR::Instr *instrArgIn, IR::RegOpnd *generatorArgsPtrOpnd);
  681. static IR::RegOpnd * LoadGeneratorArgsPtr(IR::Instr *instrInsert);
  682. static IR::Instr * LoadGeneratorObject(IR::Instr *instrInsert);
  683. IR::Opnd * LoadSlotArrayWithCachedLocalType(IR::Instr * instrInsert, IR::PropertySymOpnd *propertySymOpnd);
  684. IR::Opnd * LoadSlotArrayWithCachedProtoType(IR::Instr * instrInsert, IR::PropertySymOpnd *propertySymOpnd);
  685. IR::Instr * LowerLdAsmJsEnv(IR::Instr *instr);
  686. IR::Instr * LowerLdEnv(IR::Instr *instr);
  687. IR::Instr * LowerLdSuper(IR::Instr *instr, IR::JnHelperMethod helperOpCode);
  688. IR::Instr * LowerLdNativeCodeData(IR::Instr *instr);
  689. IR::Instr * LowerFrameDisplayCheck(IR::Instr * instr);
  690. IR::Instr * LowerSlotArrayCheck(IR::Instr * instr);
  691. static void InsertObjectPoison(IR::Opnd* poisonedOpnd, IR::BranchInstr* branchInstr, IR::Instr* insertInstr, bool isForStore);
  692. IR::RegOpnd * LoadIndexFromLikelyFloat(IR::RegOpnd *indexOpnd, const bool skipNegativeCheck, IR::LabelInstr *const notTaggedIntLabel, IR::LabelInstr *const negativeLabel, IR::Instr *const insertBeforeInstr);
  693. void MarkConstantAddressRegOpndLiveOnBackEdge(IR::LabelInstr * loopTop);
  694. #if DBG
  695. static void LegalizeVerifyRange(IR::Instr * instrStart, IR::Instr * instrLast);
  696. void ReconcileWithLowererStateOnHelperCall(IR::Instr * callInstr, IR::JnHelperMethod helperMethod);
  697. void ClearAndSaveImplicitCallCheckOnHelperCallCheckState();
  698. void RestoreImplicitCallCheckOnHelperCallCheckState();
  699. IR::Instr* LowerCheckLowerIntBound(IR::Instr * instr);
  700. IR::Instr* LowerCheckUpperIntBound(IR::Instr * instr);
  701. #endif
  702. IR::Instr * LowerGetCachedFunc(IR::Instr *instr);
  703. IR::Instr * LowerCommitScope(IR::Instr *instr);
  704. IR::Instr* LowerTry(IR::Instr* instr, bool tryCatch);
  705. IR::Instr * LowerCatch(IR::Instr *instr);
  706. IR::Instr * LowerLeave(IR::Instr *instr, IR::LabelInstr * targetInstr, bool fromFinalLower, bool isOrphanedLeave = false);
  707. void InsertReturnThunkForRegion(Region* region, IR::LabelInstr* restoreLabel);
  708. void SetHasBailedOut(IR::Instr * bailoutInstr);
  709. IR::Instr* EmitEHBailoutStackRestore(IR::Instr * bailoutInstr);
  710. void EmitSaveEHBailoutReturnValueAndJumpToRetThunk(IR::Instr * instr);
  711. void EmitRestoreReturnValueFromEHBailout(IR::LabelInstr * restoreLabel, IR::LabelInstr * epilogLabel);
  712. void LowerInitForInEnumerator(IR::Instr * instr);
  713. void AllocStackForInObjectEnumeratorArray();
  714. IR::RegOpnd * GenerateForInEnumeratorLoad(IR::Opnd * forInEnumeratorOpnd, IR::Instr * insertBeforeInstr);
  715. IR::Opnd * GetForInEnumeratorFieldOpnd(IR::Opnd * forInEnumeratorOpnd, uint fieldOffset, IRType type);
  716. void GenerateInitForInEnumeratorFastPath(IR::Instr * instr, Js::EnumeratorCache * forInCache);
  717. void GenerateHasObjectArrayCheck(IR::RegOpnd * objectOpnd, IR::RegOpnd * typeOpnd, IR::LabelInstr * hasObjectArray, IR::Instr * insertBeforeInstr);
  718. IR::LabelInstr* InsertLoopTopLabel(IR::Instr * insertBeforeInstr);
  719. IR::Instr * AddBailoutToHelperCallInstr(IR::Instr * helperCallInstr, BailOutInfo * bailoutInfo, IR::BailOutKind bailoutKind, IR::Instr * primaryBailoutInstr);
  720. IR::Instr* InsertObjectCheck(IR::RegOpnd *funcOpnd, IR::Instr *insertBeforeInstr, IR::BailOutKind bailOutKind, BailOutInfo *bailOutInfo);
  721. IR::Instr* InsertFunctionTypeIdCheck(IR::RegOpnd *funcOpnd, IR::Instr *insertBeforeInstr, IR::BailOutKind bailOutKind, BailOutInfo *bailOutInfo);
  722. IR::Instr* InsertFunctionInfoCheck(IR::RegOpnd *funcOpnd, IR::Instr *insertBeforeInstr, IR::AddrOpnd *inlinedFuncInfo, IR::BailOutKind bailOutKind, BailOutInfo *bailOutInfo);
  723. public:
  724. static IRType GetImplicitCallFlagsType()
  725. {
  726. static_assert(sizeof(Js::ImplicitCallFlags) == 1, "If this size changes, change TyUint8 in the line below to the right type.");
  727. return TyUint8;
  728. }
  729. static IRType GetFldInfoFlagsType()
  730. {
  731. static_assert(sizeof(Js::FldInfoFlags) == 1, "If this size changes, change TyUint8 in the line below to the right type.");
  732. return TyUint8;
  733. }
  734. static bool IsSpreadCall(IR::Instr *instr);
  735. static
  736. IR::Instr* GetLdSpreadIndicesInstr(IR::Instr *instr);
  737. static bool ShouldDoLazyFixedTypeBailout(Func* func) { return func->ShouldDoLazyBailOut() && PHASE_ON1(Js::LazyFixedTypeBailoutPhase); }
  738. static bool ShouldDoLazyFixedDataBailout(Func* func) { return func->ShouldDoLazyBailOut() && !PHASE_OFF1(Js::LazyFixedDataBailoutPhase); }
  739. LowererMD * GetLowererMD() { return &m_lowererMD; }
  740. private:
  741. Func * m_func;
  742. LowererMD m_lowererMD;
  743. JitArenaAllocator *m_alloc;
  744. IR::Opnd * nextStackFunctionOpnd;
  745. IR::LabelInstr * outerMostLoopLabel;
  746. BVSparse<JitArenaAllocator> * initializedTempSym;
  747. BVSparse<JitArenaAllocator> * addToLiveOnBackEdgeSyms;
  748. Region * currentRegion;
  749. #if DBG
  750. HelperCallCheckState helperCallCheckState;
  751. HelperCallCheckState oldHelperCallCheckState;
  752. Js::OpCode m_currentInstrOpCode;
  753. #endif
  754. //
  755. // Generator
  756. //
  757. class LowerGeneratorHelper
  758. {
  759. Func* const func;
  760. LowererMD &lowererMD;
  761. Lowerer* const lowerer;
  762. IR::LabelInstr* epilogueForReturnStatements = nullptr;
  763. IR::LabelInstr* epilogueForBailOut = nullptr;
  764. void EnsureEpilogueLabels();
  765. IR::SymOpnd* CreateResumeYieldOpnd() const;
  766. public:
  767. LowerGeneratorHelper(Func* func, Lowerer* lowerer, LowererMD &lowererMD);
  768. // Insert code to set generator->interpreterFrame to nullptr so that we know the
  769. // generator has finished executing and has no more yield points.
  770. // This will be inserted at the epilogue of the jitted function.
  771. void InsertNullOutGeneratorFrameInEpilogue(IR::LabelInstr* epilogueLabel);
  772. // Normally, after every bail out, we would do a jump to the epilogue and pop off the current frame.
  773. // However, in the case of generator, we also want to null out the interpreter frame to signal that
  774. // the generator is completed in the epilogue (i.e: there are no more yield points). This makes
  775. // jumping to the epilogue after the bailout call returns not possible because we wouldn't know if
  776. // the jump was because we actually want to return or because we have just bailed out.
  777. //
  778. // To deal with this, generators will have two kinds of epilogue label:
  779. // - one that nulls out the generator's interpreter frame
  780. // - one that doesn't
  781. //
  782. // Both of them share the register restore code, only the jump point differs:
  783. //
  784. // $Label_GeneratorEpilogueFrameNullOut: (intended for return statement)
  785. // null out generator's interpreter frame
  786. // $Label_GeneratorEpilogueNoFrameNullOut: (intended for jumping after bailout call returns)
  787. // pop ...
  788. // pop ...
  789. // ret
  790. //
  791. IR::LabelInstr* GetEpilogueForReturnStatements();
  792. IR::LabelInstr* GetEpilogueForBailOut();
  793. // Introduce a BailOutNoSave label if there were yield points that were elided due to optimizations.
  794. // They could still be hit if an active generator object had been paused at such a yield point when
  795. // the function body was JITed. So safe guard such a case by having the native code simply jump back
  796. // to the interpreter for such yield points.
  797. IR::LabelInstr* InsertBailOutForElidedYield();
  798. void LowerGeneratorResumeJumpTable(IR::Instr* jumpTableInstr);
  799. void LowerCreateInterpreterStackFrameForGenerator(IR::Instr* instr);
  800. void LowerYield(IR::Instr* instr);
  801. void LowerGeneratorResumeYield(IR::Instr* instr);
  802. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  803. void LowerGeneratorTraceBailIn(IR::Instr* instr);
  804. #endif
  805. };
  806. LowerGeneratorHelper m_lowerGeneratorHelper;
  807. };