LowerMDShared.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class Lowerer;
  7. enum LegalForms : uint8
  8. {
  9. L_None = 0,
  10. L_Reg = 1 << 0,
  11. L_Mem = 1 << 1,
  12. L_Imm32 = 1 << 2, // supports 8-bit, 16-bit, and 32-bit immediate values
  13. L_Ptr = 1 << 3, // supports 8-bit, 16-bit, 32-bit, and 64-bit immediate values on 64-bit architectures
  14. L_FormMask = (L_Ptr << 1) - 1,
  15. // Start flags for common behavior
  16. LF_Custom = 1 << 4, // Legal Form Flag: Custom Legal forms, must be handled in the Legalizer Switch-Case
  17. #if DBG
  18. LF_Optional = 1 << 5, // Legal Form Flag: legal for the opnd to be missing
  19. #else
  20. LF_Optional = 0, // Legal Form Flag: legal for the opnd to be missing
  21. #endif
  22. };
  23. ENUM_CLASS_HELPERS(LegalForms, uint8);
  24. #include "LowererMDArch.h"
  25. ///---------------------------------------------------------------------------
  26. ///
  27. /// class LowererMD
  28. ///
  29. ///---------------------------------------------------------------------------
  30. class LowererMD
  31. {
  32. public:
  33. LowererMD(Func *func) :
  34. m_func(func),
  35. lowererMDArch(func),
  36. floatTmpMap(nullptr),
  37. bvFloatTmpInits(nullptr),
  38. m_simd128OpCodesMap(nullptr)
  39. {
  40. }
  41. friend class LowererMDArch;
  42. static bool IsAssign(IR::Instr *instr);
  43. static bool IsCall(IR::Instr *instr);
  44. static bool IsUnconditionalBranch(const IR::Instr *instr);
  45. static void InvertBranch(IR::BranchInstr *instr);
  46. static void ReverseBranch(IR::BranchInstr *branchInstr);
  47. static Js::OpCode MDBranchOpcode(Js::OpCode opcode);
  48. static Js::OpCode MDUnsignedBranchOpcode(Js::OpCode opcode);
  49. static Js::OpCode MDCompareWithZeroBranchOpcode(Js::OpCode opcode);
  50. static Js::OpCode MDConvertFloat64ToInt32Opcode(const RoundMode roundMode);
  51. static void ChangeToAdd(IR::Instr *const instr, const bool needFlags);
  52. static void ChangeToSub(IR::Instr *const instr, const bool needFlags);
  53. static void ChangeToShift(IR::Instr *const instr, const bool needFlags);
  54. static void ChangeToIMul(IR::Instr *const instr, const bool hasOverflowCheck = false);
  55. static const uint16 GetFormalParamOffset();
  56. static const Js::OpCode MDUncondBranchOpcode;
  57. static const Js::OpCode MDMultiBranchOpcode;
  58. static const Js::OpCode MDExtend32Opcode;
  59. static const Js::OpCode MDTestOpcode;
  60. static const Js::OpCode MDOrOpcode;
  61. static const Js::OpCode MDXorOpcode;
  62. #if _M_X64
  63. static const Js::OpCode MDMovUint64ToFloat64Opcode;
  64. #endif
  65. static const Js::OpCode MDOverflowBranchOpcode;
  66. static const Js::OpCode MDNotOverflowBranchOpcode;
  67. static const Js::OpCode MDConvertFloat32ToFloat64Opcode;
  68. static const Js::OpCode MDConvertFloat64ToFloat32Opcode;
  69. static const Js::OpCode MDCallOpcode;
  70. static const Js::OpCode MDImulOpcode;
  71. static const Js::OpCode MDLea;
  72. static const Js::OpCode MDSpecBlockNEOpcode;
  73. static const Js::OpCode MDSpecBlockFNEOpcode;
  74. UINT FloatPrefThreshold;
  75. void Init(Lowerer *lowerer);
  76. IR::Opnd * GenerateMemRef(intptr_t addr, IRType type, IR::Instr *instr, bool dontEncode = false);
  77. void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, size_t value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
  78. IR::Instr * ChangeToHelperCall(IR::Instr * instr, IR::JnHelperMethod helperMethod, IR::LabelInstr *labelBailOut = nullptr,
  79. IR::Opnd *opndInstance = nullptr, IR::PropertySymOpnd * propSymOpnd = nullptr, bool isHelperContinuation = false);
  80. void FinalLower();
  81. #ifdef _M_X64
  82. void FlipHelperCallArgsOrder()
  83. {
  84. lowererMDArch.FlipHelperCallArgsOrder();
  85. }
  86. #endif
  87. IR::Instr * ChangeToHelperCallMem(IR::Instr * instr, IR::JnHelperMethod helperMethod);
  88. static IR::Instr * ChangeToAssign(IR::Instr * instr);
  89. static IR::Instr * ChangeToAssignNoBarrierCheck(IR::Instr * instr);
  90. static IR::Instr * ChangeToAssign(IR::Instr * instr, IRType type);
  91. static void ImmedSrcToReg(IR::Instr * instr, IR::Opnd * newOpnd, int srcNum);
  92. IR::Instr * LoadInputParamCount(IR::Instr * instr, int adjust = 0, bool needFlags = false);
  93. IR::Instr * LoadStackArgPtr(IR::Instr * instr);
  94. IR::Opnd * CreateStackArgumentsSlotOpnd();
  95. IR::Instr * LoadArgumentsFromFrame(IR::Instr * instr);
  96. IR::Instr * LoadArgumentCount(IR::Instr * instr);
  97. IR::Instr * LoadHeapArguments(IR::Instr * instr);
  98. IR::Instr * LoadHeapArgsCached(IR::Instr * instr);
  99. IR::Instr * LowerRet(IR::Instr * instr);
  100. IR::Instr * LowerCondBranch(IR::Instr * instr);
  101. IR::Instr * LoadFunctionObjectOpnd(IR::Instr *instr, IR::Opnd *&functionObjOpnd);
  102. IR::Instr * LowerNewScObject(IR::Instr *newObjInstr);
  103. IR::Instr * LowerWasmArrayBoundsCheck(IR::Instr *instr, IR::Opnd *addrOpnd);
  104. void LowerAtomicStore(IR::Opnd * dst, IR::Opnd * src1, IR::Instr * insertBeforeInstr);
  105. void LowerAtomicLoad(IR::Opnd* dst, IR::Opnd* src1, IR::Instr* insertBeforeInstr);
  106. void ForceDstToReg(IR::Instr *instr);
  107. public:
  108. template <bool verify = false>
  109. static void Legalize(IR::Instr *const instr, bool fPostRegAlloc = false);
  110. private:
  111. template <bool verify>
  112. static void LegalizeOpnds(IR::Instr *const instr, const LegalForms dstForms, LegalForms src1Forms, LegalForms src2Forms);
  113. template <bool verify>
  114. static void LegalizeDst(IR::Instr *const instr, const LegalForms forms);
  115. template <bool verify>
  116. static void LegalizeSrc(IR::Instr *const instr, IR::Opnd *src, const LegalForms forms);
  117. template <bool verify = false>
  118. static void MakeDstEquSrc1(IR::Instr *const instr);
  119. static bool HoistLargeConstant(IR::IndirOpnd *indirOpnd, IR::Opnd *src, IR::Instr *instr);
  120. public:
  121. IR::Instr * GenerateSmIntPairTest(IR::Instr * instrInsert, IR::Opnd * opndSrc1, IR::Opnd * opndSrc2, IR::LabelInstr * labelFail);
  122. void GenerateSmIntTest(IR::Opnd *opndSrc, IR::Instr *instrInsert, IR::LabelInstr *labelHelper, IR::Instr **instrFirst = nullptr, bool fContinueLabel = false);
  123. void GenerateTaggedZeroTest( IR::Opnd * opndSrc, IR::Instr * instrInsert, IR::LabelInstr * labelHelper = nullptr);
  124. bool GenerateObjectTest(IR::Opnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr * labelInstr, bool fContinueLabel = false);
  125. void GenerateInt32ToVarConversion( IR::Opnd * opndSrc, IR::Instr * insertInstr );
  126. void GenerateFloatTest( IR::RegOpnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr* labelHelper, const bool checkForNullInLoopBody = false);
  127. #if FLOATVAR
  128. IR::RegOpnd* CheckFloatAndUntag(IR::RegOpnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr* labelHelper);
  129. #endif
  130. bool GenerateFastCmSrEqConst(IR::Instr *instr);
  131. bool GenerateFastCmXxTaggedInt(IR::Instr *instr, bool isInHelper = false);
  132. void GenerateFastCmXxI4(IR::Instr *instr);
  133. void GenerateFastCmXxR8(IR::Instr *instr);
  134. void GenerateFastCmXx(IR::Instr *instr);
  135. IR::Instr * GenerateConvBool(IR::Instr *instr);
  136. void GenerateFastDivByPow2(IR::Instr *instrDiv);
  137. bool GenerateFastAdd(IR::Instr * instrAdd);
  138. bool GenerateFastDivAndRem(IR::Instr* instr, IR::LabelInstr* bailoutLabel = nullptr);
  139. #if DBG
  140. static void GenerateDebugBreak( IR::Instr * insertInstr );
  141. #endif
  142. bool GenerateFastSub(IR::Instr * instrSub);
  143. bool GenerateFastMul(IR::Instr * instrMul);
  144. bool GenerateFastAnd(IR::Instr * instrAnd);
  145. bool GenerateFastXor(IR::Instr * instrXor);
  146. bool GenerateFastOr(IR::Instr * instrOr);
  147. bool GenerateFastNot(IR::Instr * instrNot);
  148. bool GenerateFastShiftLeft(IR::Instr * instrShift);
  149. bool GenerateFastShiftRight(IR::Instr * instrShift);
  150. bool GenerateFastNeg(IR::Instr * instrNeg);
  151. void GenerateFastBrS(IR::BranchInstr *brInstr);
  152. IR::IndirOpnd* GetArgsIndirOpndForTopFunction(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  153. IR::IndirOpnd* GetArgsIndirOpndForInlinee(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  154. void GenerateCheckForArgumentsLength(IR::Instr* ldElem, IR::LabelInstr* labelCreateHeapArgs, IR::Opnd* actualParamOpnd, IR::Opnd* valueOpnd, Js::OpCode);
  155. IR::RegOpnd * LoadNonnegativeIndex(IR::RegOpnd *indexOpnd, const bool skipNegativeCheck, IR::LabelInstr *const notTaggedIntLabel, IR::LabelInstr *const negativeLabel, IR::Instr *const insertBeforeInstr);
  156. IR::RegOpnd * GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * labelFail, IR::Instr * insertBeforeInstr, bool generateTagCheck = true);
  157. bool GenerateFastLdMethodFromFlags(IR::Instr * instrLdFld);
  158. IR::Instr * GenerateFastScopedLdFld(IR::Instr * instrLdFld);
  159. IR::Instr * GenerateFastScopedStFld(IR::Instr * instrStFld);
  160. void GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  161. IR::Instr * GenerateFloatAbs(IR::RegOpnd * regOpnd, IR::Instr * insertInstr);
  162. void GenerateClz(IR::Instr * instr);
  163. void GenerateCtz(IR::Instr * instr);
  164. void GeneratePopCnt(IR::Instr * instr);
  165. template <bool Saturate> void GenerateTruncWithCheck(_In_ IR::Instr * instr);
  166. template <bool Saturate> IR::Opnd* GenerateTruncChecks(_In_ IR::Instr* instr, _In_opt_ IR::LabelInstr* doneLabel);
  167. IR::RegOpnd* MaterializeDoubleConstFromInt(intptr_t constAddr, IR::Instr* instr);
  168. IR::RegOpnd* MaterializeConstFromBits(int intConst, IRType type, IR::Instr* instr);
  169. IR::Opnd* Subtract2To31(IR::Opnd* src1, IR::Opnd* intMinFP, IRType type, IR::Instr* instr);
  170. bool TryGenerateFastMulAdd(IR::Instr * instrAdd, IR::Instr ** pInstrPrev);
  171. void GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMethod helperMethod);
  172. void HelperCallForAsmMathBuiltin(IR::Instr* instr, IR::JnHelperMethod helperMethodFloat, IR::JnHelperMethod helperMethodDouble);
  173. void GenerateFastInlineBuiltInMathAbs(IR::Instr* instr);
  174. void GenerateFastInlineBuiltInMathPow(IR::Instr* instr);
  175. IR::Instr * EnsureAdjacentArgs(IR::Instr * instrArg);
  176. void SaveDoubleToVar(IR::RegOpnd * dstOpnd, IR::RegOpnd *opndFloat, IR::Instr *instrOrig, IR::Instr *instrInsert, bool isHelper = false);
  177. #if !FLOATVAR
  178. void GenerateNumberAllocation(IR::RegOpnd * opndDst, IR::Instr * instrInsert, bool isHelper);
  179. #endif
  180. void GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, IR::LabelInstr* allocHelperLabel, IR::LabelInstr* allocDoneLabel);
  181. #ifdef _CONTROL_FLOW_GUARD
  182. void GenerateCFGCheck(IR::Opnd * entryPointOpnd, IR::Instr * insertBeforeInstr);
  183. #endif
  184. void GenerateCopysign(IR::Instr * instr);
  185. static IR::Instr *LoadFloatZero(IR::Opnd * opndDst, IR::Instr * instrInsert);
  186. template <typename T>
  187. static IR::Instr *LoadFloatValue(IR::Opnd * opndDst, T value, IR::Instr * instrInsert);
  188. void EmitInt64Instr(IR::Instr * instr);
  189. static void EmitInt4Instr(IR::Instr *instr);
  190. void EmitLoadVar(IR::Instr *instr, bool isFromUint32 = false, bool isHelper = false);
  191. void EmitLoadVarNoCheck(IR::RegOpnd * dst, IR::RegOpnd * src, IR::Instr *instrLoad, bool isFromUint32, bool isHelper);
  192. bool EmitLoadInt32(IR::Instr *instr, bool conversionFromObjectAllowed, bool bailOutOnHelper = false, IR::LabelInstr * labelBailOut = nullptr);
  193. void EmitIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  194. void EmitUIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  195. void EmitIntToLong(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  196. void EmitUIntToLong(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  197. void EmitLongToInt(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  198. void EmitFloatToInt(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert, IR::Instr * instrBailOut = nullptr, IR::LabelInstr * labelBailOut = nullptr);
  199. void EmitInt64toFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  200. void EmitFloat32ToFloat64(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  201. void EmitSignExtend(IR::Instr * instr);
  202. static IR::Instr * InsertConvertFloat64ToInt32(const RoundMode roundMode, IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  203. void ConvertFloatToInt32(IR::Opnd* intOpnd, IR::Opnd* floatOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * labelDone, IR::Instr * instInsert);
  204. void EmitReinterpretPrimitive(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  205. void EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr);
  206. void EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, IR::Instr * instrBailOut = nullptr, IR::LabelInstr * labelBailOut = nullptr);
  207. static void EmitNon32BitOvfCheck(IR::Instr *instr, IR::Instr *insertInstr, IR::LabelInstr* bailOutLabel);
  208. IR::BranchInstr* InsertMissingItemCompareBranch(IR::Opnd* compareSrc, IR::Opnd* missingItemOpnd, Js::OpCode opcode, IR::LabelInstr* target, IR::Instr* insertBeforeInstr);
  209. static void LowerInt4NegWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  210. static void LowerInt4AddWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  211. static void LowerInt4SubWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  212. static void LowerInt4MulWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  213. void LowerInt4RemWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel) const;
  214. static bool GenerateSimplifiedInt4Mul(IR::Instr *const mulInstr, const IR::BailOutKind bailOutKind = IR::BailOutInvalid, IR::LabelInstr *const bailOutLabel = nullptr);
  215. static bool GenerateSimplifiedInt4Rem(IR::Instr *const remInstr, IR::LabelInstr *const skipBailOutLabel = nullptr);
  216. IR::Instr * LowerTry(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  217. IR::Instr * LowerEHRegionReturn(IR::Instr * insertBeforeInstr, IR::Opnd * targetOpnd);
  218. IR::Instr * LowerLeaveNull(IR::Instr *instr);
  219. IR::Instr * LowerCallHelper(IR::Instr *instrCall);
  220. IR::LabelInstr *GetBailOutStackRestoreLabel(BailOutInfo * bailOutInfo, IR::LabelInstr * exitTargetInstr);
  221. StackSym * GetImplicitParamSlotSym(Js::ArgSlot argSlot);
  222. static StackSym * GetImplicitParamSlotSym(Js::ArgSlot argSlot, Func * func);
  223. Lowerer* GetLowerer() { return m_lowerer; }
  224. void GenerateIsJsObjectTest(IR::RegOpnd* instanceReg, IR::Instr* insertInstr, IR::LabelInstr* labelHelper);
  225. void LowerTypeof(IR::Instr * typeOfInstr);
  226. static void InsertObjectPoison(IR::Opnd* poisonedOpnd, IR::BranchInstr* branchInstr, IR::Instr* insertInstr, bool isForStore);
  227. public:
  228. //
  229. // These methods are simply forwarded to lowererMDArch
  230. //
  231. IR::Instr * LowerAsmJsCallI(IR::Instr * callInstr);
  232. IR::Instr * LowerAsmJsCallE(IR::Instr * callInstr);
  233. IR::Instr * LowerAsmJsLdElemHelper(IR::Instr * callInstr);
  234. IR::Instr * LowerAsmJsStElemHelper(IR::Instr * callInstr);
  235. IR::Instr * LowerCall(IR::Instr * callInstr, Js::ArgSlot argCount);
  236. IR::Instr * LowerCallI(IR::Instr * callInstr, ushort callFlags, bool isHelper = false, IR::Instr * insertBeforeInstrForCFG = nullptr);
  237. IR::Instr * LoadInt64HelperArgument(IR::Instr * instr, IR::Opnd* opnd);
  238. IR::Instr * LoadHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  239. IR::MemRefOpnd * LoadSimdHelperArgument(IR::Instr * instr, uint8 index);
  240. IR::Instr * LoadDoubleHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  241. IR::Instr * LoadFloatHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  242. IR::Instr * LowerEntryInstr(IR::EntryInstr * entryInstr);
  243. IR::Instr * LowerExitInstr(IR::ExitInstr * exitInstr);
  244. IR::Instr * LowerExitInstrAsmJs(IR::ExitInstr * exitInstr);
  245. IR::Instr * LoadNewScObjFirstArg(IR::Instr * instr, IR::Opnd * dst, ushort extraArgs = 0);
  246. IR::Instr * LowerToFloat(IR::Instr *instr);
  247. static IR::BranchInstr * LowerFloatCondBranch(IR::BranchInstr *instrBranch, bool ignoreNan = false);
  248. static Js::OpCode GetLoadOp(IRType type) { return LowererMDArch::GetAssignOp(type); }
  249. static Js::OpCode GetStoreOp(IRType type) { return LowererMDArch::GetAssignOp(type); }
  250. static RegNum GetRegStackPointer() { return LowererMDArch::GetRegStackPointer(); }
  251. static RegNum GetRegArgI4(int32 argNum) { return LowererMDArch::GetRegArgI4(argNum); }
  252. static RegNum GetRegArgR8(int32 argNum) { return LowererMDArch::GetRegArgR8(argNum); }
  253. static RegNum GetRegReturn(IRType type) { return LowererMDArch::GetRegReturn(type); }
  254. //All the following functions delegate to lowererMDArch
  255. IR::Instr * LowerCallIDynamic(IR::Instr * callInstr, IR::Instr* saveThis, IR::Opnd* argsLengthOpnd, ushort callFlags, IR::Instr * insertBeforeInstrForCFG = nullptr)
  256. {
  257. return this->lowererMDArch.LowerCallIDynamic(callInstr, saveThis, argsLengthOpnd, callFlags, insertBeforeInstrForCFG);
  258. }
  259. IR::Instr * LoadDynamicArgument(IR::Instr * instr, uint argNumber = 1) { return this->lowererMDArch.LoadDynamicArgument(instr, argNumber);}
  260. IR::Opnd* GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr) { return lowererMDArch.GenerateArgOutForStackArgs(callInstr, stackArgsInstr);}
  261. static RegNum GetRegFramePointer() { return LowererMDArch::GetRegFramePointer(); }
  262. static BYTE GetDefaultIndirScale() { return LowererMDArch::GetDefaultIndirScale(); }
  263. IR::Instr * LoadDynamicArgumentUsingLength(IR::Instr *instr) { return this->lowererMDArch.LoadDynamicArgumentUsingLength(instr); }
  264. void GenerateFunctionObjectTest(IR::Instr * callInstr, IR::RegOpnd *functionObjOpnd, bool isHelper, IR::LabelInstr* afterCallLabel = nullptr) { this->lowererMDArch.GenerateFunctionObjectTest(callInstr, functionObjOpnd, isHelper, afterCallLabel); }
  265. int32 LowerCallArgs(IR::Instr *callInstr, ushort callFlags, ushort extraArgsCount = 1 /* for function object */) { return this->lowererMDArch.LowerCallArgs(callInstr, callFlags, extraArgsCount); }
  266. static void GenerateLoadTaggedType(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndTaggedType);
  267. static void GenerateLoadPolymorphicInlineCacheSlot(IR::Instr * instrLdSt, IR::RegOpnd * opndInlineCache, IR::RegOpnd * opndType, uint polymorphicInlineCacheSize);
  268. void GenerateWriteBarrierAssign(IR::IndirOpnd * opndDst, IR::Opnd * opndSrc, IR::Instr * insertBeforeInstr);
  269. void GenerateWriteBarrierAssign(IR::MemRefOpnd * opndDst, IR::Opnd * opndSrc, IR::Instr * insertBeforeInstr);
  270. static IR::Instr * ChangeToWriteBarrierAssign(IR::Instr * assignInstr, const Func* func);
  271. void GenerateStFldFromLocalInlineCache(IR::Instr * instrStFld, IR::RegOpnd * opndBase, IR::Opnd * opndSrc, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  272. IR::Instr * LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailOutLabel);
  273. void LowerInlineSpreadArgOutLoop(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd)
  274. {
  275. this->lowererMDArch.LowerInlineSpreadArgOutLoop(callInstr, indexOpnd, arrayElementsStartOpnd);
  276. }
  277. static IR::Instr * InsertCmovCC(const Js::OpCode opCode, IR::Opnd * dst, IR::Opnd* src1, IR::Instr* insertBeforeInstr, bool postRegAlloc = false);
  278. #ifdef ENABLE_WASM_SIMD
  279. void Simd128InitOpcodeMap();
  280. IR::Instr* Simd128Instruction(IR::Instr* instr);
  281. IR::Instr* Simd128LoadConst(IR::Instr* instr);
  282. IR::Instr* LowerSimd128BitSelect(IR::Instr* instr);
  283. bool Simd128TryLowerMappedInstruction(IR::Instr *instr);
  284. IR::Instr* Simd128LowerUnMappedInstruction(IR::Instr *instr);
  285. IR::Instr* Simd128LowerLdLane(IR::Instr *instr);
  286. IR::Instr* SIMD128LowerReplaceLane_2(IR::Instr *instr);
  287. void EmitExtractInt64(IR::Opnd* dst, IR::Opnd* src, uint index, IR::Instr *instr);
  288. void EmitInsertInt64(IR::Opnd* dst, uint index, IR::Instr *instr);
  289. void EmitShiftByScalarI2(IR::Instr *instr, IR::JnHelperMethod helper);
  290. IR::Instr* EmitSimdConversion(IR::Instr *instr, IR::JnHelperMethod helper);
  291. IR::Instr* SIMD128LowerReplaceLane_4(IR::Instr *instr);
  292. IR::Instr* SIMD128LowerReplaceLane_8(IR::Instr *instr);
  293. IR::Instr* SIMD128LowerReplaceLane_16(IR::Instr *instr);
  294. IR::Instr* Simd128LowerSplat(IR::Instr *instr);
  295. IR::Instr* Simd128LowerSqrt(IR::Instr *instr);
  296. IR::Instr* Simd128LowerNeg(IR::Instr *instr);
  297. IR::Instr* Simd128LowerMulI4(IR::Instr *instr);
  298. IR::Instr* Simd128LowerShift(IR::Instr *instr);
  299. IR::Instr* Simd128LowerMulI16(IR::Instr *instr);
  300. IR::Instr* Simd128LowerInt32x4FromFloat32x4(IR::Instr *instr);
  301. IR::Instr* Simd128LowerUint32x4FromFloat32x4(IR::Instr *instr);
  302. IR::Instr* Simd128LowerFloat32x4FromUint32x4(IR::Instr *instr);
  303. IR::Instr* Simd128AsmJsLowerLoadElem(IR::Instr *instr);
  304. IR::Instr* Simd128LowerLoadElem(IR::Instr *instr);
  305. IR::Instr* Simd128ConvertToLoad(IR::Opnd *dst, IR::Opnd *src1, uint8 dataWidth, IR::Instr* instr, byte scaleFactor = 0);
  306. IR::Instr* Simd128AsmJsLowerStoreElem(IR::Instr *instr);
  307. IR::Instr* Simd128LowerStoreElem(IR::Instr *instr);
  308. IR::Instr* Simd128ConvertToStore(IR::Opnd *dst, IR::Opnd *src1, uint8 dataWidth, IR::Instr* instr, byte scaleFactor = 0);
  309. void Simd128LoadHeadSegment(IR::IndirOpnd *indirOpnd, ValueType arrType, IR::Instr *instr);
  310. void Simd128GenerateUpperBoundCheck(IR::RegOpnd *indexOpnd, IR::IndirOpnd *indirOpnd, ValueType arrType, IR::Instr *instr);
  311. IR::Instr* Simd128LowerSwizzle_4(IR::Instr *instr);
  312. IR::Instr* Simd128LowerShuffle_4(IR::Instr *instr);
  313. IR::Instr* Simd128LowerShuffle(IR::Instr *instr);
  314. IR::Instr* Simd128LowerNotEqual(IR::Instr* instr);
  315. IR::Instr* Simd128LowerLessThan(IR::Instr* instr);
  316. IR::Instr* Simd128LowerLessThanOrEqual(IR::Instr* instr);
  317. IR::Instr* Simd128LowerGreaterThanOrEqual(IR::Instr* instr);
  318. IR::Instr* Simd128LowerMinMax_F4(IR::Instr* instr);
  319. IR::Instr* Simd128LowerAnyTrue(IR::Instr* instr);
  320. IR::Instr* Simd128LowerAllTrue(IR::Instr* instr);
  321. IR::Opnd* Simd128CanonicalizeToBoolsBeforeReduction(IR::Instr* instr);
  322. BYTE Simd128GetTypedArrBytesPerElem(ValueType arrType);
  323. IR::Instr* Simd128CanonicalizeToBools(IR::Instr* instr, const Js::OpCode& cmpOpcode, IR::Opnd& dstOpnd);
  324. IR::Opnd* EnregisterIntConst(IR::Instr* instr, IR::Opnd *constOpnd, IRType type = TyInt32);
  325. IR::Opnd* EnregisterBoolConst(IR::Instr* instr, IR::Opnd *opnd, IRType type);
  326. SList<IR::Opnd*> * Simd128GetExtendedArgs(IR::Instr *instr);
  327. void CheckShuffleLanes_4(uint8 lanes[], uint8 lanesSrc[], uint *fromSrc1, uint *fromSrc2);
  328. void InsertShufps(uint8 lanes[], IR::Opnd *dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *insertBeforeInstr);
  329. #endif
  330. private:
  331. void EmitReinterpretFloatToInt(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  332. void EmitReinterpretIntToFloat(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  333. IR::Instr * NegZeroBranching(IR::Opnd* opnd, IR::Instr* instr, IR::LabelInstr* isNeg0Label, IR::LabelInstr* isNotNeg0Label);
  334. IR::LabelInstr* EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, bool needLabelHelper);
  335. #ifdef RECYCLER_WRITE_BARRIER
  336. static IR::Instr* GenerateWriteBarrier(IR::Instr * assignInstr);
  337. #endif
  338. // Data
  339. protected:
  340. Func *m_func;
  341. Lowerer *m_lowerer;
  342. LowererMDArch lowererMDArch;
  343. StackSymMap *floatTmpMap;
  344. BVSparse<JitArenaAllocator> *bvFloatTmpInits;
  345. Js::OpCode *m_simd128OpCodesMap; // used to map single-opcode SIMD operations
  346. };