Lower.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. {
  49. #ifdef RECYCLER_WRITE_BARRIER_JIT
  50. m_func->m_lowerer = this;
  51. #endif
  52. #if DBG
  53. this->helperCallCheckState = HelperCallCheckState_None;
  54. this->oldHelperCallCheckState = HelperCallCheckState_None;
  55. #endif
  56. }
  57. ~Lowerer()
  58. {
  59. #ifdef RECYCLER_WRITE_BARRIER_JIT
  60. m_func->m_lowerer = nullptr;
  61. #endif
  62. }
  63. void Lower();
  64. void LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFastPath, bool defaultDoLoopFastPath);
  65. void LowerPrologEpilog();
  66. void LowerPrologEpilogAsmJs();
  67. void LowerGeneratorResumeJumpTable();
  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 EHBailoutPatchUp();
  78. inline Js::ScriptContext* GetScriptContext()
  79. {
  80. return m_func->GetScriptContext();
  81. }
  82. StackSym * GetTempNumberSym(IR::Opnd * opnd, bool isTempTransferred);
  83. static bool HasSideEffects(IR::Instr *instr);
  84. static bool IsArgSaveRequired(Func *func);
  85. #if DBG
  86. static bool ValidOpcodeAfterLower(IR::Instr* instr, Func * func);
  87. #endif
  88. private:
  89. IR::Instr * LowerNewRegEx(IR::Instr * instr);
  90. void LowerNewScObjectSimple(IR::Instr *instr);
  91. void LowerNewScObjectLiteral(IR::Instr *instr);
  92. IR::Instr * LowerInitCachedFuncs(IR::Instr *instrInit);
  93. IR::Instr * LowerNewScObject(IR::Instr *instr, bool callCtor, bool hasArgs, bool isBaseClassConstructorNewScObject = false);
  94. IR::Instr * LowerNewScObjArray(IR::Instr *instr);
  95. IR::Instr * LowerNewScObjArrayNoArg(IR::Instr *instr);
  96. bool TryLowerNewScObjectWithFixedCtorCache(IR::Instr* newObjInstr, IR::RegOpnd* newObjDst, IR::LabelInstr* helperOrBailoutLabel, IR::LabelInstr* callCtorLabel,
  97. bool& skipNewScObj, bool& returnNewScObj, bool& emitHelper);
  98. void GenerateRecyclerAllocAligned(IR::JnHelperMethod allocHelper, size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, bool inOpHelper = false);
  99. IR::Instr * LowerGetNewScObject(IR::Instr *const instr);
  100. void LowerGetNewScObjectCommon(IR::RegOpnd *const resultObjOpnd, IR::RegOpnd *const constructorReturnOpnd, IR::RegOpnd *const newObjOpnd, IR::Instr *insertBeforeInstr);
  101. IR::Instr * LowerUpdateNewScObjectCache(IR::Instr * updateInstr, IR::Opnd *dst, IR::Opnd *src1, const bool isCtorFunction);
  102. bool GenerateLdFldWithCachedType(IR::Instr * instrLdFld, bool* continueAsHelperOut, IR::LabelInstr** labelHelperOut, IR::RegOpnd** typeOpndOut);
  103. bool GenerateCheckFixedFld(IR::Instr * instrChkFld);
  104. void GenerateCheckObjType(IR::Instr * instrChkObjType);
  105. void LowerAdjustObjType(IR::Instr * instrAdjustObjType);
  106. bool GenerateNonConfigurableLdRootFld(IR::Instr * instrLdFld);
  107. IR::Instr * LowerProfiledLdFld(IR::JitProfilingInstr *instr);
  108. void LowerProfiledBeginSwitch(IR::JitProfilingInstr *instr);
  109. void LowerFunctionExit(IR::Instr* funcExit);
  110. void LowerFunctionEntry(IR::Instr* funcEntry);
  111. void GenerateNullOutGeneratorFrame(IR::Instr* instrInsert);
  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* GenerateCompleteStFld(IR::Instr* instr, bool emitFastPath, IR::JnHelperMethod monoHelperAfterFastPath, IR::JnHelperMethod polyHelperAfterFastPath,
  131. IR::JnHelperMethod monoHelperWithoutFastPath, IR::JnHelperMethod polyHelperWithoutFastPath, bool withPutFlags, Js::PropertyOperationFlags flags);
  132. bool GenerateStFldWithCachedType(IR::Instr * instrStFld, bool* continueAsHelperOut, IR::LabelInstr** labelHelperOut, IR::RegOpnd** typeOpndOut);
  133. bool GenerateStFldWithCachedFinalType(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd);
  134. IR::RegOpnd * GenerateCachedTypeCheck(IR::Instr *instrInsert, IR::PropertySymOpnd *propertySymOpnd,
  135. IR::LabelInstr* labelObjCheckFailed, IR::LabelInstr *labelTypeCheckFailed, IR::LabelInstr *labelSecondChance = nullptr);
  136. void GenerateCachedTypeWithoutPropertyCheck(IR::Instr *instrInsert, IR::PropertySymOpnd *propertySymOpnd, IR::Opnd *typeOpnd, IR::LabelInstr *labelTypeCheckFailed);
  137. IR::RegOpnd * GeneratePolymorphicTypeIndex(IR::RegOpnd * typeOpnd, Js::PropertyGuard * typeCheckGuard, IR::Instr * instrInsert);
  138. void GenerateLeaOfOOPData(IR::RegOpnd * regOpnd, void * address, int32 offset, IR::Instr * instrInsert);
  139. IR::Opnd * GenerateIndirOfOOPData(void * address, int32 offset, IR::Instr * instrInsert);
  140. void GenerateFixedFieldGuardCheck(IR::Instr *insertPointInstr, IR::PropertySymOpnd *propertySymOpnd, IR::LabelInstr *labelBailOut);
  141. Js::JitTypePropertyGuard* CreateTypePropertyGuardForGuardedProperties(JITTypeHolder type, IR::PropertySymOpnd* propertySymOpnd);
  142. Js::JitEquivalentTypeGuard* CreateEquivalentTypeGuardAndLinkToGuardedProperties(IR::PropertySymOpnd* propertySymOpnd);
  143. bool LinkCtorCacheToGuardedProperties(JITTimeConstructorCache* cache);
  144. template<typename LinkFunc>
  145. bool LinkGuardToGuardedProperties(const BVSparse<JitArenaAllocator>* guardedPropOps, LinkFunc link);
  146. void GeneratePropertyGuardCheck(IR::Instr *insertPointInstr, IR::PropertySymOpnd *propertySymOpnd, IR::LabelInstr *labelBailOut);
  147. IR::Instr * GeneratePropertyGuardCheckBailoutAndLoadType(IR::Instr *insertInstr);
  148. void GenerateFieldStoreWithTypeChange(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  149. void GenerateDirectFieldStore(IR::Instr* instrStFld, IR::PropertySymOpnd* propertySymOpnd);
  150. void GenerateAdjustSlots(IR::Instr * instrStFld, IR::PropertySymOpnd *propertySymOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  151. bool GenerateAdjustBaseSlots(IR::Instr * instrStFld, IR::RegOpnd *baseOpnd, JITTypeHolder initialType, JITTypeHolder finalType);
  152. void PinTypeRef(JITTypeHolder type, void* typeRef, IR::Instr* instr, Js::PropertyId propertyId);
  153. IR::RegOpnd * GenerateIsBuiltinRecyclableObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool checkObjectAndDynamicObject = true, IR::LabelInstr *labelFastExternal = nullptr, bool isInHelper = false);
  154. void GenerateIsDynamicObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool fContinueLabel = false);
  155. void GenerateIsRecyclableObject(IR::RegOpnd *regOpnd, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, bool checkObjectAndDynamicObject = true);
  156. bool GenerateLdThisCheck(IR::Instr * instr);
  157. bool GenerateLdThisStrict(IR::Instr * instr);
  158. bool GenerateFastIsInst(IR::Instr * instr);
  159. void GenerateFastArrayIsIn(IR::Instr * instr);
  160. void GenerateFastObjectIsIn(IR::Instr * instr);
  161. void GenerateProtoLdFldFromFlagInlineCache(
  162. IR::Instr * insertBeforeInstr,
  163. IR::Opnd * opndDst,
  164. IR::RegOpnd * opndInlineCache,
  165. IR::LabelInstr * labelFallThru,
  166. bool isInlineSlot);
  167. void GenerateLocalLdFldFromFlagInlineCache(
  168. IR::Instr * insertBeforeInstr,
  169. IR::RegOpnd * opndBase,
  170. IR::Opnd * opndDst,
  171. IR::RegOpnd * opndInlineCache,
  172. IR::LabelInstr * labelFallThru,
  173. bool isInlineSlot);
  174. void GenerateFlagProtoCheck(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFail);
  175. void GenerateFlagInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  176. bool GenerateFastLdMethodFromFlags(IR::Instr * instrLdFld);
  177. void EnsureStackFunctionListStackSym();
  178. void EnsureZeroLastStackFunctionNext();
  179. void AllocStackClosure(StackSym * symInlineeFrameDisplayEnd);
  180. void InitializeInlineeFrameDisplays(StackSym * symInlineeFrameDisplayEnd);
  181. IR::Instr * GenerateNewStackScFunc(IR::Instr * newScFuncInstr, IR::RegOpnd ** ppEnvOpnd);
  182. void GenerateStackScriptFunctionInit(StackSym * stackSym, Js::FunctionInfoPtrPtr nestedInfo);
  183. void GenerateScriptFunctionInit(IR::RegOpnd * regOpnd, IR::Opnd * vtableAddressOpnd,
  184. Js::FunctionInfoPtrPtr nestedInfo, IR::Opnd * envOpnd, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  185. void GenerateStackScriptFunctionInit(IR::RegOpnd * regOpnd, Js::FunctionInfoPtrPtr nestedInfo, IR::Opnd * envOpnd, IR::Instr * insertBeforeInstr);
  186. IR::Instr * LowerProfiledStFld(IR::JitProfilingInstr * instr, Js::PropertyOperationFlags flags);
  187. 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);
  188. void MapStFldHelper(IR::PropertySymOpnd * propertySymOpnd, IR::JnHelperMethod &helperMethod, IR::JnHelperMethod &polymorphicHelperMethod);
  189. IR::Instr * LowerScopedStFld(IR::Instr * stFldInstr, IR::JnHelperMethod helperMethod, bool withInlineCache,
  190. bool withPropertyOperationFlags = false, Js::PropertyOperationFlags flags = Js::PropertyOperation_None);
  191. void LowerProfiledLdElemI(IR::JitProfilingInstr *const instr);
  192. void LowerProfiledStElemI(IR::JitProfilingInstr *const instr, const Js::PropertyOperationFlags flags);
  193. IR::Instr * LowerStElemI(IR::Instr *instr, Js::PropertyOperationFlags flags, bool isHelper, IR::JnHelperMethod helperMethod = IR::HelperOp_SetElementI);
  194. IR::Instr * LowerLdElemI(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool isHelper);
  195. void LowerLdLen(IR::Instr *const instr, const bool isHelper);
  196. IR::Instr * LowerMemOp(IR::Instr * instr);
  197. IR::Instr * LowerMemset(IR::Instr * instr, IR::RegOpnd * helperRet);
  198. IR::Instr * LowerMemcopy(IR::Instr * instr, IR::RegOpnd * helperRet);
  199. IR::Instr * LowerWasmArrayBoundsCheck(IR::Instr * instr, IR::Opnd *addrOpnd);
  200. IR::Instr * LowerLdArrViewElem(IR::Instr * instr);
  201. IR::Instr * LowerStArrViewElem(IR::Instr * instr);
  202. IR::Instr * LowerStAtomicsWasm(IR::Instr * instr);
  203. IR::Instr * LowerLdAtomicsWasm(IR::Instr * instr);
  204. IR::Instr * LowerLdArrViewElemWasm(IR::Instr * instr);
  205. IR::Instr * LowerArrayDetachedCheck(IR::Instr * instr);
  206. IR::Instr * LowerDeleteElemI(IR::Instr *instr, bool strictMode);
  207. IR::Instr * LowerStElemC(IR::Instr *instr);
  208. void LowerLdArrHead(IR::Instr *instr);
  209. IR::Instr * LowerStSlot(IR::Instr *instr);
  210. IR::Instr * LowerStSlotChkUndecl(IR::Instr *instr);
  211. void LowerStLoopBodyCount(IR::Instr* instr);
  212. #if !FLOATVAR
  213. IR::Instr * LowerStSlotBoxTemp(IR::Instr *instr);
  214. #endif
  215. void LowerLdSlot(IR::Instr *instr);
  216. IR::Instr * LowerChkUndecl(IR::Instr *instr);
  217. void GenUndeclChk(IR::Instr *insertInsert, IR::Opnd *opnd);
  218. IR::Instr * LoadPropertySymAsArgument(IR::Instr *instr, IR::Opnd *fieldSrc);
  219. IR::Instr * LoadFunctionBodyAsArgument(IR::Instr *instr, IR::IntConstOpnd * functionBodySlotOpnd, IR::RegOpnd * envOpnd);
  220. IR::Instr * LoadHelperTemp(IR::Instr * instr, IR::Instr * instrInsert);
  221. IR::Instr * LowerLoadVar(IR::Instr *instr, IR::Opnd *opnd);
  222. void LoadArgumentCount(IR::Instr *const instr);
  223. void LoadStackArgPtr(IR::Instr *const instr);
  224. IR::Instr * InsertLoadStackAddress(StackSym *sym, IR::Instr * instrInsert, IR::RegOpnd *optionalDstOpnd = nullptr);
  225. void LoadArgumentsFromFrame(IR::Instr *const instr);
  226. IR::Instr * LowerUnaryHelper(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::Opnd* opndBailoutArg = nullptr);
  227. IR::Instr * LowerUnaryHelperMem(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::Opnd* opndBailoutArg = nullptr);
  228. IR::Instr * LowerUnaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  229. IR::Instr * LowerUnaryHelperMemWithFunctionInfo(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  230. IR::Instr * LowerBinaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  231. IR::Instr * LowerUnaryHelperMemWithTemp(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  232. IR::Instr * LowerUnaryHelperMemWithTemp2(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod helperMethodWithTemp);
  233. IR::Instr * LowerUnaryHelperMemWithBoolReference(IR::Instr *instr, IR::JnHelperMethod helperMethod, bool useBoolForBailout);
  234. IR::Instr * LowerBinaryHelperMem(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  235. IR::Instr * LowerBinaryHelperMemWithTemp(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  236. IR::Instr * LowerBinaryHelperMemWithTemp2(IR::Instr *instr, IR::JnHelperMethod helperMethod, IR::JnHelperMethod helperMethodWithTemp);
  237. IR::Instr * LowerBinaryHelperMemWithTemp3(IR::Instr *instr, IR::JnHelperMethod helperMethod,
  238. IR::JnHelperMethod helperMethodWithTemp, IR::JnHelperMethod helperMethodLeftDead);
  239. IR::Instr * LowerAddLeftDeadForString(IR::Instr *instr);
  240. IR::Instr * LowerBinaryHelper(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  241. #ifdef ENABLE_WASM
  242. IR::Instr * LowerCheckWasmSignature(IR::Instr * instr);
  243. IR::Instr * LowerLdWasmFunc(IR::Instr* instr);
  244. IR::Instr * LowerGrowWasmMemory(IR::Instr* instr);
  245. #endif
  246. IR::Instr * LowerInitCachedScope(IR::Instr * instr);
  247. IR::Instr * LowerBrBReturn(IR::Instr * instr, IR::JnHelperMethod helperMethod, bool isHelper);
  248. IR::Instr * LowerBrBMem(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  249. IR::Instr * LowerBrOnObject(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  250. IR::Instr * LowerBrCMem(IR::Instr * instr, IR::JnHelperMethod helperMethod, bool noMathFastPath, bool isHelper = true);
  251. IR::Instr * LowerBrFncApply(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  252. IR::Instr * LowerBrProperty(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  253. IR::Instr * LowerBrOnClassConstructor(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  254. IR::Instr* LowerMultiBr(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  255. IR::Instr* LowerMultiBr(IR::Instr * instr);
  256. IR::Instr * LowerElementUndefined(IR::Instr * instr, IR::JnHelperMethod helper);
  257. IR::Instr * LowerElementUndefinedMem(IR::Instr * instr, IR::JnHelperMethod helper);
  258. IR::Instr * LowerElementUndefinedScoped(IR::Instr * instr, IR::JnHelperMethod helper);
  259. IR::Instr * LowerElementUndefinedScopedMem(IR::Instr * instr, IR::JnHelperMethod helper);
  260. IR::Instr * LowerLdElemUndef(IR::Instr * instr);
  261. IR::Instr * LowerRestParameter(IR::Opnd *formalsOpnd, IR::Opnd *dstOpnd, IR::Opnd *excessOpnd, IR::Instr *instr, IR::RegOpnd *generatorArgsPtrOpnd);
  262. IR::Instr * LowerArgIn(IR::Instr *instr);
  263. IR::Instr * LowerArgInAsmJs(IR::Instr *instr);
  264. IR::Instr * LowerProfiledNewScArray(IR::JitProfilingInstr* arrInstr);
  265. IR::Instr * LowerNewScArray(IR::Instr *arrInstr);
  266. IR::Instr * LowerNewScIntArray(IR::Instr *arrInstr);
  267. IR::Instr * LowerNewScFltArray(IR::Instr *arrInstr);
  268. IR::Instr * LowerArraySegmentVars(IR::Instr *instr);
  269. IR::Instr * LowerEqualityBranch(IR::Instr* instr, IR::JnHelperMethod helper);
  270. IR::Instr * LowerEqualityCompare(IR::Instr* instr, IR::JnHelperMethod helper);
  271. template <typename ArrayType>
  272. BOOL IsSmallObject(uint32 length);
  273. #ifdef ENABLE_DOM_FAST_PATH
  274. void LowerFastInlineDOMFastPathGetter(IR::Instr* getterInstr);
  275. #endif
  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::Instr * GenerateRuntimeError(IR::Instr * insertBeforeInstr, Js::MessageId errorCode, IR::JnHelperMethod helper = IR::JnHelperMethod::HelperOp_RuntimeTypeError);
  285. bool InlineBuiltInLibraryCall(IR::Instr *callInstr);
  286. void LowerInlineBuiltIn(IR::Instr* instr);
  287. intptr_t GetObjRefForBuiltInTarget(IR::RegOpnd * opnd);
  288. bool TryGenerateFastCmSrEq(IR::Instr * instr);
  289. bool TryGenerateFastBrEq(IR::Instr * instr);
  290. bool TryGenerateFastBrNeq(IR::Instr * instr);
  291. bool GenerateFastBrSrEq(IR::Instr * instr, IR::RegOpnd * srcReg1, IR::RegOpnd * srcReg2, IR::Instr ** pInstrPrev, bool noMathFastPath);
  292. bool GenerateFastBrSrNeq(IR::Instr * instr, IR::Instr ** pInstrPrev);
  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 GenerateFastBrEqLikely(IR::BranchInstr * instrBranch, bool *pNeedHelper, bool isInHelper);
  299. bool GenerateFastBooleanAndObjectEqLikely(IR::Instr * instr, IR::Opnd *src1, IR::Opnd *src2, IR::LabelInstr * labelHelper, IR::LabelInstr * labelEqualLikely, bool *pNeedHelper, bool isInHelper);
  300. bool GenerateFastCmEqLikely(IR::Instr * instr, bool *pNeedHelper, bool isInHelper);
  301. bool GenerateFastBrBool(IR::BranchInstr *const instr);
  302. bool GenerateFastStringCheck(IR::Instr *instr, IR::RegOpnd *srcReg1, IR::RegOpnd *srcReg2, bool isEqual, bool isStrict, IR::LabelInstr *labelHelper, IR::LabelInstr *labelBranchSuccess, IR::LabelInstr *labelBranchFail);
  303. bool GenerateFastBrOrCmString(IR::Instr* instr);
  304. void GenerateDynamicLoadPolymorphicInlineCacheSlot(IR::Instr * instrInsert, IR::RegOpnd * inlineCacheOpnd, IR::Opnd * objectTypeOpnd);
  305. static IR::Instr *LoadFloatFromNonReg(IR::Opnd * opndOrig, IR::Opnd * regOpnd, IR::Instr * instrInsert);
  306. void LoadInt32FromUntaggedVar(IR::Instr *const instrLoad);
  307. bool GetValueFromIndirOpnd(IR::IndirOpnd *indirOpnd, IR::Opnd **pValueOpnd, IntConstType *pValue);
  308. void GenerateFastBrOnObject(IR::Instr *instr);
  309. void GenerateObjectTypeTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr *labelHelper);
  310. static IR::LabelInstr* InsertContinueAfterExceptionLabelForDebugger(Func* func, IR::Instr* insertAfterInstr, bool isHelper);
  311. void GenerateObjectHeaderInliningTest(IR::RegOpnd *baseOpnd, IR::LabelInstr * target, IR::Instr *insertBeforeInstr);
  312. // Static tables that will be used by the GetArray* methods below
  313. private:
  314. static const VTableValue VtableAddresses[static_cast<ValueType::TSize>(ObjectType::Count)];
  315. static const uint32 OffsetsOfHeadSegment[static_cast<ValueType::TSize>(ObjectType::Count)];
  316. static const uint32 OffsetsOfLength[static_cast<ValueType::TSize>(ObjectType::Count)];
  317. static const IRType IndirTypes[static_cast<ValueType::TSize>(ObjectType::Count)];
  318. static const BYTE IndirScales[static_cast<ValueType::TSize>(ObjectType::Count)];
  319. private:
  320. static VTableValue GetArrayVtableAddress(const ValueType valueType, bool getVirtual = false);
  321. public:
  322. static uint32 GetArrayOffsetOfHeadSegment(const ValueType valueType);
  323. static uint32 GetArrayOffsetOfLength(const ValueType valueType);
  324. static IRType GetArrayIndirType(const ValueType valueType);
  325. static BYTE GetArrayIndirScale(const ValueType valueType);
  326. static int SimdGetElementCountFromBytes(ValueType arrValueType, uint8 dataWidth);
  327. private:
  328. bool ShouldGenerateArrayFastPath(const IR::Opnd *const arrayOpnd, const bool supportsObjectsWithArrays, const bool supportsTypedArrays, const bool requiresSse2ForFloatArrays) const;
  329. IR::RegOpnd * LoadObjectArray(IR::RegOpnd *const baseOpnd, IR::Instr *const insertBeforeInstr);
  330. 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);
  331. void GenerateIsEnabledArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  332. void GenerateIsEnabledIntArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  333. void GenerateIsEnabledFloatArraySetElementFastPathCheck(IR::LabelInstr * isDisabledLabel, IR::Instr * const insertBeforeInstr);
  334. void GenerateStringTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr * failLabel, IR::LabelInstr * succeedLabel = nullptr, bool generateObjectCheck = true);
  335. void GenerateSymbolTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr * failLabel, IR::LabelInstr * succeedLabel = nullptr, bool generateObjectCheck = true);
  336. void GeneratePropertyStringTest(IR::RegOpnd *srcReg, IR::Instr *instrInsert, IR::LabelInstr *labelHelper, bool usePoison);
  337. IR::RegOpnd * GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * labelFail, IR::Instr * insertBeforeInstr, bool generateTagCheck = true);
  338. void GenerateNotZeroTest( IR::Opnd * opndSrc, IR::LabelInstr * labelZero, IR::Instr * instrInsert);
  339. IR::Opnd * CreateOpndForSlotAccess(IR::Opnd * opnd);
  340. IR::RegOpnd * GetRegOpnd(IR::Opnd * opnd, IR::Instr * insertInstr, Func * func, IRType type);
  341. void GenerateSwitchStringLookup(IR::Instr * instr);
  342. void GenerateSingleCharStrJumpTableLookup(IR::Instr * instr);
  343. void LowerJumpTableMultiBranch(IR::MultiBranchInstr * multiBrInstr, IR::RegOpnd * indexOpnd);
  344. void LowerConvNum(IR::Instr *instrLoad, bool noMathFastPath);
  345. void InsertBitTestBranch(IR::Opnd * bitMaskOpnd, IR::Opnd * bitIndex, bool jumpIfBitOn, IR::LabelInstr * targetLabel, IR::Instr * insertBeforeInstr);
  346. void GenerateGetSingleCharString(IR::RegOpnd * charCodeOpnd, IR::Opnd * resultOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * doneLabel, IR::Instr * instr, bool isCodePoint);
  347. void GenerateFastBrBReturn(IR::Instr * instr);
  348. public:
  349. static IR::Instr *Lowerer::HoistIndirOffset(IR::Instr* instr, IR::IndirOpnd *indirOpnd, RegNum regNum);
  350. static IR::Instr *Lowerer::HoistIndirOffsetAsAdd(IR::Instr* instr, IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum);
  351. static IR::Instr *Lowerer::HoistIndirIndexOpndAsAdd(IR::Instr* instr, IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, IR::Opnd *indexOpnd, RegNum regNum);
  352. static IR::Instr *Lowerer::HoistSymOffset(IR::Instr *instr, IR::SymOpnd *symOpnd, RegNum baseReg, uint32 offset, RegNum regNum);
  353. static IR::Instr *Lowerer::HoistSymOffsetAsAdd(IR::Instr* instr, IR::SymOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum);
  354. static IR::LabelInstr * InsertLabel(const bool isHelper, IR::Instr *const insertBeforeInstr);
  355. static IR::Instr * InsertMove(IR::Opnd *dst, IR::Opnd *src, IR::Instr *const insertBeforeInstr, bool generateWriteBarrier = true);
  356. static IR::Instr * InsertMoveWithBarrier(IR::Opnd *dst, IR::Opnd *src, IR::Instr *const insertBeforeInstr);
  357. #if _M_X64
  358. static IR::Instr * InsertMoveBitCast(IR::Opnd *const dst, IR::Opnd *const src1, IR::Instr *const insertBeforeInstr);
  359. #endif
  360. static IR::BranchInstr * InsertBranch(const Js::OpCode opCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  361. static IR::BranchInstr * InsertBranch(const Js::OpCode opCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  362. static IR::Instr * InsertCompare(IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  363. 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);
  364. 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);
  365. static IR::Instr * InsertTest(IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  366. static IR::BranchInstr * InsertTestBranch(IR::Opnd *const testSrc1, IR::Opnd *const testSrc2, const Js::OpCode branchOpCode, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  367. 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);
  368. static IR::Instr * InsertAdd(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
  369. static IR::Instr * InsertSub(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
  370. static IR::Instr * InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  371. static IR::Instr * ChangeToLea(IR::Instr *const instr);
  372. static IR::Instr * InsertXor(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  373. static IR::Instr * InsertAnd(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  374. static IR::Instr * InsertOr(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
  375. 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);
  376. 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);
  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, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
  378. static IR::Instr * InsertConvertFloat32ToFloat64(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  379. static IR::Instr * InsertConvertFloat64ToFloat32(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  380. public:
  381. static void InsertDecUInt32PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
  382. static void InsertAddWithOverflowCheck(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr, IR::Instr **const onOverflowInsertBeforeInstrRef);
  383. void InsertFloatCheckForZeroOrNanBranch(IR::Opnd *const src, const bool branchOnZeroOrNan, IR::LabelInstr *const target, IR::LabelInstr *const fallthroughLabel, IR::Instr *const insertBeforeInstr);
  384. public:
  385. static IR::HelperCallOpnd* CreateHelperCallOpnd(IR::JnHelperMethod helperMethod, int helperArgCount, Func* func);
  386. static IR::Opnd * GetMissingItemOpnd(IRType type, Func *func);
  387. static IR::Opnd * GetMissingItemOpndForAssignment(IRType type, Func *func);
  388. static IR::Opnd * GetMissingItemOpndForCompare(IRType type, Func *func);
  389. static IR::Opnd * GetImplicitCallFlagsOpnd(Func * func);
  390. inline static IR::IntConstOpnd* MakeCallInfoConst(ushort flags, int32 argCount, Func* func) {
  391. argCount = Js::CallInfo::GetArgCountWithoutExtraArgs((Js::CallFlags)flags, (uint16)argCount);
  392. #ifdef _M_X64
  393. // This was defined differently for x64
  394. Js::CallInfo callInfo = Js::CallInfo((Js::CallFlags)flags, (unsigned __int16)argCount);
  395. return IR::IntConstOpnd::New(*((IntConstType *)((void *)&callInfo)), TyInt32, func, true);
  396. #else
  397. AssertMsg(!(argCount & 0xFF000000), "Too many arguments"); //final 8 bits are for flags
  398. AssertMsg(!(flags & ~0xFF), "Flags are invalid!"); //8 bits for flags
  399. return IR::IntConstOpnd::New(argCount | (flags << 24), TyMachReg, func, true);
  400. #endif
  401. }
  402. static void InsertAndLegalize(IR::Instr * instr, IR::Instr* insertBeforeInstr);
  403. private:
  404. IR::IndirOpnd* GenerateFastElemICommon(
  405. _In_ IR::Instr* elemInstr,
  406. _In_ bool isStore,
  407. _In_ IR::IndirOpnd* indirOpnd,
  408. _In_ IR::LabelInstr* labelHelper,
  409. _In_ IR::LabelInstr* labelCantUseArray,
  410. _In_opt_ IR::LabelInstr* labelFallthrough,
  411. _Out_ bool* pIsTypedArrayElement,
  412. _Out_ bool* pIsStringIndex,
  413. _Out_opt_ bool* emitBailoutRef,
  414. _Outptr_opt_result_maybenull_ IR::Opnd** maskOpnd,
  415. _Outptr_opt_result_maybenull_ IR::LabelInstr** pLabelSegmentLengthIncreased = nullptr,
  416. _In_ bool checkArrayLengthOverflow = true,
  417. _In_ bool forceGenerateFastPath = false,
  418. _In_ bool returnLength = false,
  419. _In_opt_ IR::LabelInstr* bailOutLabelInstr = nullptr,
  420. _Out_opt_ bool* indirOpndOverflowed = nullptr,
  421. _In_ Js::FldInfoFlags flags = Js::FldInfo_NoInfo);
  422. IR::IndirOpnd * GenerateFastElemIIntIndexCommon(
  423. IR::Instr * ldElem,
  424. bool isStore,
  425. IR::IndirOpnd * indirOpnd,
  426. IR::LabelInstr * labelHelper,
  427. IR::LabelInstr * labelCantUseArray,
  428. IR::LabelInstr *labelFallthrough,
  429. bool * pIsTypedArrayElement,
  430. bool *emitBailoutRef,
  431. IR::LabelInstr **pLabelSegmentLengthIncreased,
  432. bool checkArrayLengthOverflow,
  433. IR::Opnd** maskOpnd,
  434. bool forceGenerateFastPath = false,
  435. bool returnLength = false,
  436. IR::LabelInstr *bailOutLabelInstr = nullptr,
  437. bool * indirOpndOverflowed = nullptr);
  438. IR::IndirOpnd* GenerateFastElemIStringIndexCommon(
  439. _In_ IR::Instr* elemInstr,
  440. _In_ bool isStore,
  441. _In_ IR::IndirOpnd* indirOpnd,
  442. _In_ IR::LabelInstr* labelHelper,
  443. _In_ Js::FldInfoFlags flags);
  444. IR::IndirOpnd* GenerateFastElemISymbolIndexCommon(
  445. _In_ IR::Instr* elemInstr,
  446. _In_ bool isStore,
  447. _In_ IR::IndirOpnd* indirOpnd,
  448. _In_ IR::LabelInstr* labelHelper,
  449. _In_ Js::FldInfoFlags flags);
  450. IR::IndirOpnd* GenerateFastElemISymbolOrStringIndexCommon(
  451. _In_ IR::Instr* instrInsert,
  452. _In_ IR::RegOpnd* indexOpnd,
  453. _In_ IR::RegOpnd* baseOpnd,
  454. _In_ const uint32 inlineCacheOffset,
  455. _In_ const uint32 hitRateOffset,
  456. _In_ IR::LabelInstr* labelHelper,
  457. _In_ Js::FldInfoFlags flags);
  458. void GenerateLookUpInIndexCache(
  459. _In_ IR::Instr* instrInsert,
  460. _In_ IR::RegOpnd* indexOpnd,
  461. _In_ IR::RegOpnd* baseOpnd,
  462. _In_opt_ IR::RegOpnd* opndSlotArray,
  463. _In_opt_ IR::RegOpnd* opndSlotIndex,
  464. _In_ const uint32 inlineCacheOffset,
  465. _In_ const uint32 hitRateOffset,
  466. _In_ IR::LabelInstr* labelHelper,
  467. _In_ Js::FldInfoFlags flags = Js::FldInfo_NoInfo);
  468. template <bool CheckLocal, bool CheckInlineSlot, bool DoAdd>
  469. void GenerateLookUpInIndexCacheHelper(
  470. _In_ IR::Instr* instrInsert,
  471. _In_ IR::RegOpnd* baseOpnd,
  472. _In_opt_ IR::RegOpnd* opndSlotArray,
  473. _In_opt_ IR::RegOpnd* opndSlotIndex,
  474. _In_ IR::RegOpnd* objectTypeOpnd,
  475. _In_ IR::RegOpnd* inlineCacheOpnd,
  476. _In_ IR::LabelInstr* doneLabel,
  477. _In_ IR::LabelInstr* helperLabel,
  478. _Outptr_ IR::LabelInstr** nextLabel,
  479. _Outptr_ IR::BranchInstr** branchToPatch,
  480. _Inout_ IR::RegOpnd** taggedTypeOpnd);
  481. 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);
  482. IR::BranchInstr* InsertMissingItemCompareBranch(IR::Opnd* compareSrc, Js::OpCode opcode, IR::LabelInstr* target, IR::Instr* insertBeforeInstr);
  483. bool GenerateFastLdElemI(IR::Instr *& ldElem, bool *instrIsInHelperBlockRef);
  484. bool GenerateFastStElemI(IR::Instr *& StElem, bool *instrIsInHelperBlockRef);
  485. bool GenerateFastLdLen(IR::Instr *ldLen, bool *instrIsInHelperBlockRef);
  486. bool GenerateFastCharAt(Js::BuiltinFunction index, IR::Opnd *dst, IR::Opnd *srcStr, IR::Opnd *srcIndex, IR::Instr *callInstr, IR::Instr *insertInstr,
  487. IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  488. bool GenerateFastInlineGlobalObjectParseInt(IR::Instr *instr);
  489. bool GenerateFastInlineStringFromCharCode(IR::Instr* instr);
  490. bool GenerateFastInlineStringFromCodePoint(IR::Instr* instr);
  491. void GenerateFastInlineStringCodePointAt(IR::Instr* doneLabel, Func* func, IR::Opnd *strLength, IR::Opnd *srcIndex, IR::RegOpnd *lowerChar, IR::RegOpnd *strPtr);
  492. bool GenerateFastInlineStringCharCodeAt(IR::Instr* instr, Js::BuiltinFunction index);
  493. bool GenerateFastInlineStringReplace(IR::Instr* instr);
  494. void GenerateFastInlineIsArray(IR::Instr * instr);
  495. void GenerateFastInlineHasOwnProperty(IR::Instr * instr);
  496. void GenerateFastInlineArrayPush(IR::Instr * instr);
  497. void GenerateFastInlineArrayPop(IR::Instr * instr);
  498. void GenerateFastInlineStringSplitMatch(IR::Instr * instr);
  499. void GenerateFastInlineMathImul(IR::Instr* instr);
  500. void GenerateFastInlineMathClz(IR::Instr* instr);
  501. void GenerateCtz(IR::Instr* instr);
  502. void GeneratePopCnt(IR::Instr* instr);
  503. template <bool Saturate> void GenerateTruncWithCheck(_In_ IR::Instr* instr);
  504. void GenerateFastInlineMathFround(IR::Instr* instr);
  505. void GenerateFastInlineRegExpExec(IR::Instr * instr);
  506. 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);
  507. bool GenerateFastReplace(IR::Opnd* strOpnd, IR::Opnd* src1, IR::Opnd* src2, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  508. bool ShouldGenerateStringReplaceFastPath(IR::Instr * instr, IntConstType argCount);
  509. bool GenerateFastPop(IR::Opnd *baseOpndParam, IR::Instr *callInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel, IR::LabelInstr * bailOutLabelHelper);
  510. bool GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelper, IR::LabelInstr * labelFallThru);
  511. IR::Instr * LowerCallDirect(IR::Instr * instr);
  512. IR::Instr * GenerateDirectCall(IR::Instr* inlineInstr, IR::Opnd* funcObj, ushort callflags);
  513. IR::Instr * GenerateFastInlineBuiltInMathRandom(IR::Instr* instr);
  514. IR::Instr * GenerateHelperToArrayPushFastPath(IR::Instr * instr, IR::LabelInstr * bailOutLabelHelper);
  515. IR::Instr * GenerateHelperToArrayPopFastPath(IR::Instr * instr, IR::LabelInstr * doneLabel, IR::LabelInstr * bailOutLabelHelper);
  516. IR::Instr * LowerCondBranchCheckBailOut(IR::BranchInstr * instr, IR::Instr * helperCall, bool isHelper);
  517. IR::Instr * LowerBailOnEqualOrNotEqual(IR::Instr * instr, IR::BranchInstr * branchInstr = nullptr, IR::LabelInstr * labelBailOut = nullptr, IR::PropertySymOpnd * propSymOpnd = nullptr, bool isHelper = false);
  518. void LowerBailOnNegative(IR::Instr *const instr);
  519. void LowerBailoutCheckAndLabel(IR::Instr *instr, bool onEqual, bool isHelper);
  520. IR::Instr * LowerBailOnNotSpreadable(IR::Instr *instr);
  521. IR::Instr * LowerBailOnNotPolymorphicInlinee(IR::Instr * instr);
  522. IR::Instr * LowerBailOnNotStackArgs(IR::Instr * instr);
  523. IR::Instr * LowerBailOnNotObject(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  524. IR::Instr * LowerBailOnTrue(IR::Instr *instr, IR::LabelInstr *labelBailOut = nullptr);
  525. IR::Instr * LowerBailOnNotBuiltIn(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  526. IR::Instr * LowerBailOnNotInteger(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  527. IR::Instr * LowerBailOnIntMin(IR::Instr *instr, IR::BranchInstr *branchInstr = nullptr, IR::LabelInstr *labelBailOut = nullptr);
  528. void LowerBailOnNotString(IR::Instr *instr);
  529. IR::Instr * LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper = false);
  530. IR::Instr * LowerBailOnException(IR::Instr* instr);
  531. void LowerReinterpretPrimitive(IR::Instr* instr);
  532. IR::Instr * LowerBailOnEarlyExit(IR::Instr* instr);
  533. void LowerOneBailOutKind(IR::Instr *const instr, const IR::BailOutKind bailOutKindToLower, const bool isInHelperBlock, const bool preserveBailOutKindInInstr = false);
  534. void SplitBailOnNotArray(IR::Instr *const instr, IR::Instr * *const bailOnNotArrayRef, IR::Instr * *const bailOnMissingValueRef);
  535. IR::RegOpnd * LowerBailOnNotArray(IR::Instr *const instr);
  536. void LowerBailOnMissingValue(IR::Instr *const instr, IR::RegOpnd *const arrayOpnd);
  537. void LowerBailOnInvalidatedArrayHeadSegment(IR::Instr *const instr, const bool isInHelperBlock);
  538. void LowerBailOnInvalidatedArrayLength(IR::Instr *const instr, const bool isInHelperBlock);
  539. void LowerBailOnCreatedMissingValue(IR::Instr *const instr, const bool isInHelperBlock);
  540. void LowerBoundCheck(IR::Instr *const instr);
  541. IR::Opnd* GetFuncObjectOpnd(IR::Instr* insertBeforeInstr);
  542. IR::Instr* LoadFuncExpression(IR::Instr *instrFuncExpr);
  543. IR::Instr * LowerBailTarget(IR::Instr * instr);
  544. IR::Instr * SplitBailOnImplicitCall(IR::Instr *& instr);
  545. IR::Instr * SplitBailOnImplicitCall(IR::Instr * instr, IR::Instr * helperCall, IR::Instr * insertBeforeInstr);
  546. IR::Instr * SplitBailForDebugger(IR::Instr* instr);
  547. IR::Instr * SplitBailOnResultCondition(IR::Instr *const instr) const;
  548. void LowerBailOnResultCondition(IR::Instr *const instr, IR::LabelInstr * *const bailOutLabel, IR::LabelInstr * *const skipBailOutLabel);
  549. void PreserveSourcesForBailOnResultCondition(IR::Instr *const instr, IR::LabelInstr *const skipBailOutLabel) const;
  550. void LowerInstrWithBailOnResultCondition(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel) const;
  551. void GenerateObjectTestAndTypeLoad(IR::Instr *instrLdSt, IR::RegOpnd *opndBase, IR::RegOpnd *opndType, IR::LabelInstr *labelHelper);
  552. void InsertMoveForPolymorphicCacheIndex(IR::Instr * instr, BailOutInfo * bailOutInfo, int bailOutRecordOffset, uint polymorphicCacheIndexValue);
  553. IR::LabelInstr *GenerateBailOut(IR::Instr * instr, IR::BranchInstr * branchInstr = nullptr, IR::LabelInstr * labelBailOut = nullptr, IR::LabelInstr * collectRuntimeStatsLabel = nullptr);
  554. void GenerateJumpToEpilogForBailOut(BailOutInfo * bailOutInfo, IR::Instr *instrAfter);
  555. void GenerateThrow(IR::Opnd* errorCode, IR::Instr * instr);
  556. void LowerDivI4(IR::Instr * const instr);
  557. void LowerRemI4(IR::Instr * const instr);
  558. void LowerTrapIfZero(IR::Instr * const instr);
  559. void LowerTrapIfMinIntOverNegOne(IR::Instr * const instr);
  560. IR::Instr* LowerTrapIfUnalignedAccess(IR::Instr * const instr);
  561. void LowerDivI4Common(IR::Instr * const instr);
  562. void LowerRemR8(IR::Instr * const instr);
  563. void LowerRemR4(IR::Instr * const instr);
  564. IR::Instr* LowerInlineeStart(IR::Instr * instr);
  565. void LowerInlineeEnd(IR::Instr * instr);
  566. static
  567. IR::SymOpnd* LoadCallInfo(IR::Instr * instrInsert);
  568. IR::Instr * LowerCallIDynamic(IR::Instr * callInstr, ushort callFlags);
  569. IR::Opnd* GenerateArgOutForInlineeStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
  570. IR::Opnd* GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
  571. void GenerateLoadStackArgumentByIndex(IR::Opnd *dst, IR::RegOpnd *indexOpnd, IR::Instr *instr, int32 offset, Func *func);
  572. bool GenerateFastStackArgumentsLdElemI(IR::Instr* ldElem);
  573. IR::IndirOpnd* GetArgsIndirOpndForInlinee(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  574. IR::IndirOpnd* GetArgsIndirOpndForTopFunction(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  575. void GenerateCheckForArgumentsLength(IR::Instr* ldElem, IR::LabelInstr* labelCreateHeapArgs, IR::Opnd* actualParamOpnd, IR::Opnd* valueOpnd, Js::OpCode opcode);
  576. bool GenerateFastArgumentsLdElemI(IR::Instr* ldElem, IR::LabelInstr *labelFallThru);
  577. bool GenerateFastRealStackArgumentsLdLen(IR::Instr *ldLen);
  578. bool GenerateFastArgumentsLdLen(IR::Instr *ldLen, IR::LabelInstr* labelFallThru);
  579. static const uint16 GetFormalParamOffset() { /*formal start after frame pointer, return address, function object, callInfo*/ return 4;};
  580. IR::RegOpnd* GenerateFunctionTypeFromFixedFunctionObject(IR::Instr *callInstr, IR::Opnd* functionObjOpnd);
  581. bool GenerateFastLdFld(IR::Instr * const instrLdFld, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod,
  582. IR::LabelInstr ** labelBailOut, IR::RegOpnd* typeOpnd, bool* pIsHelper, IR::LabelInstr** pLabelHelper);
  583. void GenerateAuxSlotAdjustmentRequiredCheck(IR::Instr * instrToInsertBefore, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelHelper);
  584. void GenerateSetObjectTypeFromInlineCache(IR::Instr * instrToInsertBefore, IR::RegOpnd * opndBase, IR::RegOpnd * opndInlineCache, bool isTypeTagged);
  585. bool GenerateFastStFld(IR::Instr * const instrStFld, IR::JnHelperMethod helperMethod, IR::JnHelperMethod polymorphicHelperMethod,
  586. IR::LabelInstr ** labelBailOut, IR::RegOpnd* typeOpnd, bool* pIsHelper, IR::LabelInstr** pLabelHelper, bool withPutFlags = false, Js::PropertyOperationFlags flags = Js::PropertyOperation_None);
  587. bool GenerateFastStFldForCustomProperty(IR::Instr *const instr, IR::LabelInstr * *const labelHelperRef);
  588. void RelocateCallDirectToHelperPath(IR::Instr* argoutInlineSpecialized, IR::LabelInstr* labelHelper);
  589. bool TryGenerateFastBrOrCmTypeOf(IR::Instr *instr, IR::Instr **prev, bool isNeqOp, bool *pfNoLower);
  590. void GenerateFastBrTypeOf(IR::Instr *branch, IR::RegOpnd *object, IR::IntConstOpnd *typeIdOpnd, IR::Instr *typeOf, bool *pfNoLower, bool isNeqOp);
  591. void GenerateFastCmTypeOf(IR::Instr *compare, IR::RegOpnd *object, IR::IntConstOpnd *typeIdOpnd, IR::Instr *typeOf, bool *pfNoLower, bool isNeqOp);
  592. void GenerateFalsyObjectTest(IR::Instr *insertInstr, IR::RegOpnd *typeOpnd, Js::TypeId typeIdToCheck, IR::LabelInstr* target, IR::LabelInstr* done, bool isNeqOp);
  593. void GenerateFalsyObjectTest(IR::Instr * insertInstr, IR::RegOpnd * typeOpnd, IR::LabelInstr * falsyLabel);
  594. void GenerateJavascriptOperatorsIsConstructorGotoElse(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelTrue, IR::LabelInstr *labelFalse);
  595. void GenerateRecyclableObjectGetPrototypeNullptrGoto(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelReturnNullptr);
  596. void GenerateRecyclableObjectIsElse(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelFalse);
  597. void GenerateLdHomeObj(IR::Instr* instr);
  598. void GenerateLdHomeObjProto(IR::Instr* instr);
  599. void GenerateLdFuncObj(IR::Instr* instr);
  600. void GenerateLdFuncObjProto(IR::Instr* instr);
  601. void GenerateLoadNewTarget(IR::Instr* instrInsert);
  602. void GenerateCheckForCallFlagNew(IR::Instr* instrInsert);
  603. void GenerateGetCurrentFunctionObject(IR::Instr * instr);
  604. IR::Opnd * GetInlineCacheFromFuncObjectForRuntimeUse(IR::Instr * instr, IR::PropertySymOpnd * propSymOpnd, bool isHelper);
  605. IR::Instr * LowerInitClass(IR::Instr * instr);
  606. IR::RegOpnd * GenerateGetImmutableOrScriptUnreferencedString(IR::RegOpnd * strOpnd, IR::Instr * insertBeforeInstr, IR::JnHelperMethod helperMethod, bool reloadDst = true);
  607. void LowerNewConcatStrMulti(IR::Instr * instr);
  608. void LowerNewConcatStrMultiBE(IR::Instr * instr);
  609. void LowerSetConcatStrMultiItem(IR::Instr * instr);
  610. void LowerConvStr(IR::Instr * instr);
  611. void LowerCoerseStr(IR::Instr * instr);
  612. void LowerCoerseRegex(IR::Instr * instr);
  613. void LowerCoerseStrOrRegex(IR::Instr * instr);
  614. void LowerConvPrimStr(IR::Instr * instr);
  615. void LowerConvStrCommon(IR::JnHelperMethod helper, IR::Instr * instr);
  616. void LowerConvPropertyKey(IR::Instr* instr);
  617. void GenerateRecyclerAlloc(IR::JnHelperMethod allocHelper, size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, bool inOpHelper = false);
  618. template <typename ArrayType>
  619. IR::RegOpnd * GenerateArrayAllocHelper(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed, bool isArrayObjCtor, bool isNoArgs);
  620. template <typename ArrayType>
  621. IR::RegOpnd * GenerateArrayLiteralsAlloc(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed);
  622. template <typename ArrayType>
  623. IR::RegOpnd * GenerateArrayObjectsAlloc(IR::Instr *instr, uint32 * psize, Js::ArrayCallSiteInfo * arrayInfo, bool * pIsHeadSegmentZeroed, bool isNoArgs);
  624. template <typename ArrayType>
  625. IR::RegOpnd * GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * sizeOpnd, Js::ArrayCallSiteInfo * arrayInfo);
  626. bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
  627. template <typename ArrayType>
  628. 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);
  629. bool GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
  630. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  631. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  632. void GenerateMemInitNull(IR::RegOpnd * opnd, int32 offset, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  633. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, IR::Opnd * value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  634. void GenerateMemInit(IR::RegOpnd * opnd, IR::RegOpnd * offset, IR::Opnd * value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  635. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr);
  636. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr);
  637. void GenerateRecyclerMemInitNull(IR::RegOpnd * opnd, int32 offset, IR::Instr * insertBeforeInstr);
  638. void GenerateRecyclerMemInit(IR::RegOpnd * opnd, int32 offset, IR::Opnd * value, IR::Instr * insertBeforeInstr);
  639. void GenerateMemCopy(IR::Opnd * dst, IR::Opnd * src, uint32 size, IR::Instr * insertBeforeInstr);
  640. void GenerateDynamicObjectAlloc(IR::Instr * newObjInstr, uint inlineSlotCount, uint slotCount, IR::RegOpnd * newObjDst, IR::Opnd * typeSrc);
  641. bool GenerateSimplifiedInt4Rem(IR::Instr *const remInstr, IR::LabelInstr *const skipBailOutLabel = nullptr) const;
  642. 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);
  643. IR::Opnd* GetImplicitCallFlagsOpnd();
  644. IR::Opnd* CreateClearImplicitCallFlagsOpnd();
  645. void GenerateFlagInlineCacheCheckForGetterSetter(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  646. void GenerateLdFldFromFlagInlineCache(IR::Instr * insertBeforeInstr, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  647. static IR::BranchInstr * GenerateLocalInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext, bool checkTypeWithoutProperty = false);
  648. static IR::BranchInstr * GenerateProtoInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  649. static void GenerateLdFldFromLocalInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  650. static void GenerateLdFldFromProtoInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  651. IR::Instr * LoadScriptContext(IR::Instr *instr);
  652. IR::Instr * LoadFunctionBody(IR::Instr * instr);
  653. IR::Opnd * LoadFunctionBodyOpnd(IR::Instr *instr);
  654. IR::Opnd * LoadFunctionInfoOpnd(IR::Instr *instr);
  655. IR::Opnd * LoadScriptContextOpnd(IR::Instr *instr);
  656. IR::Opnd * LoadScriptContextValueOpnd(IR::Instr * instr, ScriptContextValue valueType);
  657. IR::Opnd * LoadLibraryValueOpnd(IR::Instr * instr, LibraryValue valueType);
  658. IR::Opnd * LoadVTableValueOpnd(IR::Instr * instr, VTableValue vtableType);
  659. IR::Opnd * LoadOptimizationOverridesValueOpnd(IR::Instr *instr, OptimizationOverridesValue valueType);
  660. IR::Opnd * LoadNumberAllocatorValueOpnd(IR::Instr *instr, NumberAllocatorValue valueType);
  661. IR::Opnd * LoadIsInstInlineCacheOpnd(IR::Instr *instr, uint inlineCacheIndex);
  662. IR::Opnd * LoadRuntimeInlineCacheOpnd(IR::Instr * instr, IR::PropertySymOpnd * sym, bool isHelper = false);
  663. void LowerSpreadArrayLiteral(IR::Instr *instr);
  664. IR::Instr* LowerSpreadCall(IR::Instr *instr, Js::CallFlags callFlags, bool setupProfiledVersion = false);
  665. void LowerInlineSpreadArgOutLoopUsingRegisters(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd);
  666. IR::Instr* LowerCallIDynamicSpread(IR::Instr * callInstr, ushort callFlags);
  667. void LowerNewScopeSlots(IR::Instr * instr, bool doStackSlots);
  668. void LowerLdFrameDisplay(IR::Instr * instr, bool doStackDisplay);
  669. void LowerLdInnerFrameDisplay(IR::Instr * instr);
  670. IR::AddrOpnd * CreateFunctionBodyOpnd(Func *const func) const;
  671. IR::AddrOpnd * CreateFunctionBodyOpnd(Js::FunctionBody *const functionBody) const;
  672. bool GenerateRecyclerOrMarkTempAlloc(IR::Instr * instr, IR::RegOpnd * dstOpnd, IR::JnHelperMethod allocHelper, size_t allocSize, IR::SymOpnd ** tempObjectSymOpnd);
  673. IR::SymOpnd * GenerateMarkTempAlloc(IR::RegOpnd *const dstOpnd, const size_t allocSize, IR::Instr *const insertBeforeInstr);
  674. void LowerBrFncCachedScopeEq(IR::Instr *instr);
  675. IR::Instr* InsertLoweredRegionStartMarker(IR::Instr* instrToInsertBefore);
  676. IR::Instr* RemoveLoweredRegionStartMarker(IR::Instr* startMarkerInstr);
  677. void ConvertArgOpndIfGeneratorFunction(IR::Instr *instrArgIn, IR::RegOpnd *generatorArgsPtrOpnd);
  678. static IR::RegOpnd * LoadGeneratorArgsPtr(IR::Instr *instrInsert);
  679. static IR::Instr * LoadGeneratorObject(IR::Instr *instrInsert);
  680. IR::Opnd * LoadSlotArrayWithCachedLocalType(IR::Instr * instrInsert, IR::PropertySymOpnd *propertySymOpnd, bool canReuseAuxSlotPtr);
  681. IR::Opnd * LoadSlotArrayWithCachedProtoType(IR::Instr * instrInsert, IR::PropertySymOpnd *propertySymOpnd);
  682. IR::Instr * LowerLdAsmJsEnv(IR::Instr *instr);
  683. IR::Instr * LowerLdEnv(IR::Instr *instr);
  684. IR::Instr * LowerLdSuper(IR::Instr *instr, IR::JnHelperMethod helperOpCode);
  685. IR::Instr * LowerLdNativeCodeData(IR::Instr *instr);
  686. IR::Instr * LowerFrameDisplayCheck(IR::Instr * instr);
  687. IR::Instr * LowerSlotArrayCheck(IR::Instr * instr);
  688. void InsertSlotArrayCheck(IR::Instr * instr, StackSym * dstSym, uint32 slotId);
  689. void InsertFrameDisplayCheck(IR::Instr * instr, StackSym * dstSym, FrameDisplayCheckRecord * record);
  690. static void InsertObjectPoison(IR::Opnd* poisonedOpnd, IR::BranchInstr* branchInstr, IR::Instr* insertInstr, bool isForStore);
  691. IR::RegOpnd * LoadIndexFromLikelyFloat(IR::RegOpnd *indexOpnd, const bool skipNegativeCheck, IR::LabelInstr *const notTaggedIntLabel, IR::LabelInstr *const negativeLabel, IR::Instr *const insertBeforeInstr);
  692. void MarkConstantAddressRegOpndLiveOnBackEdge(IR::LabelInstr * loopTop);
  693. #if DBG
  694. static void LegalizeVerifyRange(IR::Instr * instrStart, IR::Instr * instrLast);
  695. void ReconcileWithLowererStateOnHelperCall(IR::Instr * callInstr, IR::JnHelperMethod helperMethod);
  696. void ClearAndSaveImplicitCallCheckOnHelperCallCheckState();
  697. void RestoreImplicitCallCheckOnHelperCallCheckState();
  698. IR::Instr* LowerCheckLowerIntBound(IR::Instr * instr);
  699. IR::Instr* LowerCheckUpperIntBound(IR::Instr * instr);
  700. #endif
  701. IR::Instr * LowerGetCachedFunc(IR::Instr *instr);
  702. IR::Instr * LowerCommitScope(IR::Instr *instr);
  703. IR::Instr* LowerTry(IR::Instr* instr, bool tryCatch);
  704. IR::Instr * LowerCatch(IR::Instr *instr);
  705. IR::Instr * LowerLeave(IR::Instr *instr, IR::LabelInstr * targetInstr, bool fromFinalLower, bool isOrphanedLeave = false);
  706. void EnsureBailoutReturnValueSym();
  707. void EnsureHasBailedOutSym();
  708. void InsertReturnThunkForRegion(Region* region, IR::LabelInstr* restoreLabel);
  709. void SetHasBailedOut(IR::Instr * bailoutInstr);
  710. IR::Instr* EmitEHBailoutStackRestore(IR::Instr * bailoutInstr);
  711. void EmitSaveEHBailoutReturnValueAndJumpToRetThunk(IR::Instr * instr);
  712. void EmitRestoreReturnValueFromEHBailout(IR::LabelInstr * restoreLabel, IR::LabelInstr * epilogLabel);
  713. void LowerInitForInEnumerator(IR::Instr * instr);
  714. void AllocStackForInObjectEnumeratorArray();
  715. IR::RegOpnd * GenerateForInEnumeratorLoad(IR::Opnd * forInEnumeratorOpnd, IR::Instr * insertBeforeInstr);
  716. IR::Opnd * GetForInEnumeratorFieldOpnd(IR::Opnd * forInEnumeratorOpnd, uint fieldOffset, IRType type);
  717. void GenerateInitForInEnumeratorFastPath(IR::Instr * instr, Js::EnumeratorCache * forInCache);
  718. void GenerateHasObjectArrayCheck(IR::RegOpnd * objectOpnd, IR::RegOpnd * typeOpnd, IR::LabelInstr * hasObjectArray, IR::Instr * insertBeforeInstr);
  719. IR::LabelInstr* InsertLoopTopLabel(IR::Instr * insertBeforeInstr);
  720. IR::Instr * AddBailoutToHelperCallInstr(IR::Instr * helperCallInstr, BailOutInfo * bailoutInfo, IR::BailOutKind bailoutKind, IR::Instr * primaryBailoutInstr);
  721. public:
  722. static IRType GetImplicitCallFlagsType()
  723. {
  724. static_assert(sizeof(Js::ImplicitCallFlags) == 1, "If this size changes, change TyUint8 in the line below to the right type.");
  725. return TyUint8;
  726. }
  727. static IRType GetFldInfoFlagsType()
  728. {
  729. static_assert(sizeof(Js::FldInfoFlags) == 1, "If this size changes, change TyUint8 in the line below to the right type.");
  730. return TyUint8;
  731. }
  732. static bool IsSpreadCall(IR::Instr *instr);
  733. static
  734. IR::Instr* GetLdSpreadIndicesInstr(IR::Instr *instr);
  735. static bool DoLazyBailout(Func* func) { return PHASE_ON(Js::LazyBailoutPhase, func) && !func->IsLoopBody(); }
  736. static bool DoLazyFixedTypeBailout(Func* func) { return DoLazyBailout(func) && !PHASE_OFF(Js::LazyFixedTypeBailoutPhase, func); }
  737. static bool DoLazyFixedDataBailout(Func* func) { return DoLazyBailout(func) && !PHASE_OFF(Js::LazyFixedDataBailoutPhase, func); }
  738. LowererMD * GetLowererMD() { return &m_lowererMD; }
  739. private:
  740. Func * m_func;
  741. LowererMD m_lowererMD;
  742. JitArenaAllocator *m_alloc;
  743. IR::Opnd * nextStackFunctionOpnd;
  744. IR::LabelInstr * outerMostLoopLabel;
  745. BVSparse<JitArenaAllocator> * initializedTempSym;
  746. BVSparse<JitArenaAllocator> * addToLiveOnBackEdgeSyms;
  747. Region * currentRegion;
  748. #if DBG
  749. HelperCallCheckState helperCallCheckState;
  750. HelperCallCheckState oldHelperCallCheckState;
  751. Js::OpCode m_currentInstrOpCode;
  752. #endif
  753. };