LowerMDShared.h 29 KB

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