LowerMDShared.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 * ChangeToAssign(IR::Instr * instr);
  77. static IR::Instr * ChangeToAssignNoBarrierCheck(IR::Instr * instr);
  78. static IR::Instr * ChangeToAssign(IR::Instr * instr, IRType type);
  79. static IR::Instr * ChangeToLea(IR::Instr *const instr, bool postRegAlloc = false);
  80. static void ImmedSrcToReg(IR::Instr * instr, IR::Opnd * newOpnd, int srcNum);
  81. IR::Instr * LoadInputParamCount(IR::Instr * instr, int adjust = 0, bool needFlags = false);
  82. IR::Instr * LoadStackArgPtr(IR::Instr * instr);
  83. IR::Opnd * CreateStackArgumentsSlotOpnd();
  84. IR::Instr * LoadArgumentsFromFrame(IR::Instr * instr);
  85. IR::Instr * LoadArgumentCount(IR::Instr * instr);
  86. IR::Instr * LoadHeapArguments(IR::Instr * instr);
  87. IR::Instr * LoadHeapArgsCached(IR::Instr * instr);
  88. IR::Instr * LowerRet(IR::Instr * instr);
  89. IR::Instr * LowerUncondBranch(IR::Instr * instr);
  90. IR::Instr * LowerMultiBranch(IR::Instr * instr);
  91. IR::Instr * LowerCondBranch(IR::Instr * instr);
  92. IR::Instr * LoadFunctionObjectOpnd(IR::Instr *instr, IR::Opnd *&functionObjOpnd);
  93. IR::Instr * LowerLdSuper(IR::Instr *instr, IR::JnHelperMethod helperOpCode);
  94. IR::Instr * LowerNewScObject(IR::Instr *newObjInstr);
  95. IR::Instr * LowerWasmMemOp(IR::Instr *instr, IR::Opnd *addrOpnd);
  96. void ForceDstToReg(IR::Instr *instr);
  97. public:
  98. template <bool verify = false>
  99. static void Legalize(IR::Instr *const instr, bool fPostRegAlloc = false);
  100. private:
  101. template <bool verify>
  102. static void LegalizeOpnds(IR::Instr *const instr, const uint dstForms, const uint src1Forms, uint src2Forms);
  103. template <bool verify>
  104. static void LegalizeDst(IR::Instr *const instr, const uint forms);
  105. template <bool verify>
  106. static void LegalizeSrc(IR::Instr *const instr, IR::Opnd *src, const uint forms);
  107. template <bool verify = false>
  108. static void MakeDstEquSrc1(IR::Instr *const instr);
  109. static bool HoistLargeConstant(IR::IndirOpnd *indirOpnd, IR::Opnd *src, IR::Instr *instr);
  110. public:
  111. IR::Instr * GenerateSmIntPairTest(IR::Instr * instrInsert, IR::Opnd * opndSrc1, IR::Opnd * opndSrc2, IR::LabelInstr * labelFail);
  112. void GenerateSmIntTest(IR::Opnd *opndSrc, IR::Instr *instrInsert, IR::LabelInstr *labelHelper, IR::Instr **instrFirst = nullptr, bool fContinueLabel = false);
  113. void GenerateTaggedZeroTest( IR::Opnd * opndSrc, IR::Instr * instrInsert, IR::LabelInstr * labelHelper = nullptr);
  114. bool GenerateObjectTest(IR::Opnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr * labelInstr, bool fContinueLabel = false);
  115. bool GenerateJSBooleanTest(IR::RegOpnd * regSrc, IR::Instr * insertInstr, IR::LabelInstr * labelTarget, bool fContinueLabel = false);
  116. void GenerateBooleanTest(IR::Opnd * regSrc, IR::Instr * insertInstr, IR::LabelInstr * labelTarget, bool fContinueLabel = false);
  117. void GenerateInt32ToVarConversion( IR::Opnd * opndSrc, IR::Instr * insertInstr );
  118. void GenerateFloatTest( IR::RegOpnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr* labelHelper, const bool checkForNullInLoopBody = false);
  119. #if FLOATVAR
  120. IR::RegOpnd* CheckFloatAndUntag(IR::RegOpnd * opndSrc, IR::Instr * insertInstr, IR::LabelInstr* labelHelper);
  121. #endif
  122. bool GenerateFastCmSrEqConst(IR::Instr *instr);
  123. bool GenerateFastCmXxTaggedInt(IR::Instr *instr, bool isInHelper = false);
  124. void GenerateFastCmXxI4(IR::Instr *instr);
  125. void GenerateFastCmXxR8(IR::Instr *instr);
  126. void GenerateFastCmXx(IR::Instr *instr);
  127. IR::Instr * GenerateConvBool(IR::Instr *instr);
  128. void GenerateFastDivByPow2(IR::Instr *instr);
  129. bool GenerateFastAdd(IR::Instr * instrAdd);
  130. #if DBG
  131. static void GenerateDebugBreak( IR::Instr * insertInstr );
  132. #endif
  133. bool GenerateFastSub(IR::Instr * instrSub);
  134. bool GenerateFastMul(IR::Instr * instrMul);
  135. bool GenerateFastAnd(IR::Instr * instrAnd);
  136. bool GenerateFastXor(IR::Instr * instrXor);
  137. bool GenerateFastOr(IR::Instr * instrOr);
  138. bool GenerateFastNot(IR::Instr * instrNot);
  139. bool GenerateFastShiftLeft(IR::Instr * instrShift);
  140. bool GenerateFastShiftRight(IR::Instr * instrShift);
  141. bool GenerateFastNeg(IR::Instr * instrNeg);
  142. void GenerateFastBrS(IR::BranchInstr *brInstr);
  143. IR::IndirOpnd* GetArgsIndirOpndForTopFunction(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  144. IR::IndirOpnd* GetArgsIndirOpndForInlinee(IR::Instr* ldElem, IR::Opnd* valueOpnd);
  145. void GenerateCheckForArgumentsLength(IR::Instr* ldElem, IR::LabelInstr* labelCreateHeapArgs, IR::Opnd* actualParamOpnd, IR::Opnd* valueOpnd, Js::OpCode);
  146. IR::RegOpnd * LoadNonnegativeIndex(IR::RegOpnd *indexOpnd, const bool skipNegativeCheck, IR::LabelInstr *const notTaggedIntLabel, IR::LabelInstr *const negativeLabel, IR::Instr *const insertBeforeInstr);
  147. IR::RegOpnd * GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * labelFail, IR::Instr * insertBeforeInstr, bool generateTagCheck = true);
  148. bool GenerateFastLdMethodFromFlags(IR::Instr * instrLdFld);
  149. IR::Instr * GenerateFastScopedLdFld(IR::Instr * instrLdFld);
  150. IR::Instr * GenerateFastScopedStFld(IR::Instr * instrStFld);
  151. void GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel);
  152. IR::Instr * GenerateFloatAbs(IR::RegOpnd * regOpnd, IR::Instr * insertInstr);
  153. void GenerateClz(IR::Instr * instr);
  154. void GenerateCtz(IR::Instr * instr);
  155. void GeneratePopCnt(IR::Instr * instr);
  156. void GenerateTruncWithCheck(IR::Instr * instr);
  157. IR::Opnd* GenerateTruncChecks(IR::Instr* instr);
  158. IR::RegOpnd* MaterializeDoubleConstFromInt(intptr_t constAddr, IR::Instr* instr);
  159. IR::RegOpnd* MaterializeConstFromBits(int intConst, IRType type, IR::Instr* instr);
  160. IR::Opnd* Subtract2To31(IR::Opnd* src1, IR::Opnd* intMinFP, IRType type, IR::Instr* instr);
  161. bool TryGenerateFastMulAdd(IR::Instr * instrAdd, IR::Instr ** pInstrPrev);
  162. bool GenerateLdThisStrict(IR::Instr * instr);
  163. BVSparse<JitArenaAllocator>* GatherFltTmps();
  164. void GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMethod helperMethod);
  165. void HelperCallForAsmMathBuiltin(IR::Instr* instr, IR::JnHelperMethod helperMethodFloat, IR::JnHelperMethod helperMethodDouble);
  166. void GenerateFastInlineBuiltInMathAbs(IR::Instr* instr);
  167. void GenerateFastInlineBuiltInMathPow(IR::Instr* instr);
  168. IR::Instr * CheckIsOpndNegZero(IR::Opnd* opnd, IR::Instr* instr, IR::LabelInstr* isNeg0Label);
  169. IR::Instr * CloneSlowPath(IR::Instr * instrEndFloatRange, IR::Instr * instrInsert);
  170. bool IsCloneDone(IR::Instr * instr, BVSparse<JitArenaAllocator> *bvTmps);
  171. IR::Instr * EnsureAdjacentArgs(IR::Instr * instrArg);
  172. void SaveDoubleToVar(IR::RegOpnd * dstOpnd, IR::RegOpnd *opndFloat, IR::Instr *instrOrig, IR::Instr *instrInsert, bool isHelper = false);
  173. #if !FLOATVAR
  174. void GenerateNumberAllocation(IR::RegOpnd * opndDst, IR::Instr * instrInsert, bool isHelper);
  175. #endif
  176. void GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, IR::Instr* insertionPointInstr, IR::LabelInstr* allocHelperLabel, IR::LabelInstr* allocDoneLabel);
  177. #ifdef _CONTROL_FLOW_GUARD
  178. void GenerateCFGCheck(IR::Opnd * entryPointOpnd, IR::Instr * insertBeforeInstr);
  179. #endif
  180. void GenerateCopysign(IR::Instr * instr);
  181. static IR::Instr *LoadFloatZero(IR::Opnd * opndDst, IR::Instr * instrInsert);
  182. template <typename T>
  183. static IR::Instr *LoadFloatValue(IR::Opnd * opndDst, T value, IR::Instr * instrInsert);
  184. IR::Instr * LoadStackAddress(StackSym *sym, IR::RegOpnd *optionalDstOpnd = nullptr);
  185. void EmitInt64Instr(IR::Instr * instr);
  186. static void EmitInt4Instr(IR::Instr *instr);
  187. void EmitLoadVar(IR::Instr *instr, bool isFromUint32 = false, bool isHelper = false);
  188. void EmitLoadVarNoCheck(IR::RegOpnd * dst, IR::RegOpnd * src, IR::Instr *instrLoad, bool isFromUint32, bool isHelper);
  189. bool EmitLoadInt32(IR::Instr *instr, bool conversionFromObjectAllowed, bool bailOutOnHelper = false, IR::LabelInstr * labelBailOut = nullptr);
  190. void EmitIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  191. void EmitUIntToFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  192. void EmitIntToLong(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  193. void EmitUIntToLong(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  194. void EmitLongToInt(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  195. void EmitFloatToInt(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert, IR::Instr * instrBailOut = nullptr, IR::LabelInstr * labelBailOut = nullptr);
  196. void EmitInt64toFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  197. void EmitFloat32ToFloat64(IR::Opnd *dst, IR::Opnd *src, IR::Instr *instrInsert);
  198. void EmitSignExtend(IR::Instr * instr);
  199. static IR::Instr * InsertConvertFloat64ToInt32(const RoundMode roundMode, IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
  200. void ConvertFloatToInt32(IR::Opnd* intOpnd, IR::Opnd* floatOpnd, IR::LabelInstr * labelHelper, IR::LabelInstr * labelDone, IR::Instr * instInsert);
  201. void EmitReinterpretPrimitive(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  202. void EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr);
  203. void EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, IR::Instr * instrBailOut = nullptr, IR::LabelInstr * labelBailOut = nullptr);
  204. static void EmitNon32BitOvfCheck(IR::Instr *instr, IR::Instr *insertInstr, IR::LabelInstr* bailOutLabel);
  205. static void LowerInt4NegWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  206. static void LowerInt4AddWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  207. static void LowerInt4SubWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  208. static void LowerInt4MulWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel);
  209. void LowerInt4RemWithBailOut(IR::Instr *const instr, const IR::BailOutKind bailOutKind, IR::LabelInstr *const bailOutLabel, IR::LabelInstr *const skipBailOutLabel) const;
  210. static bool GenerateSimplifiedInt4Mul(IR::Instr *const mulInstr, const IR::BailOutKind bailOutKind = IR::BailOutInvalid, IR::LabelInstr *const bailOutLabel = nullptr);
  211. static bool GenerateSimplifiedInt4Rem(IR::Instr *const remInstr, IR::LabelInstr *const skipBailOutLabel = nullptr);
  212. IR::Instr * LowerCatch(IR::Instr *instr);
  213. IR::Instr * LowerGetCachedFunc(IR::Instr *instr);
  214. IR::Instr * LowerCommitScope(IR::Instr *instr);
  215. IR::Instr * LowerTry(IR::Instr *instr, IR::JnHelperMethod helperMethod);
  216. IR::Instr * LowerLeave(IR::Instr *instr, IR::LabelInstr * targetInstr, bool fromFinalLower, bool isOrphanedLeave = false);
  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. bool GenerateFastIsInst(IR::Instr * instr);
  225. void GenerateIsJsObjectTest(IR::RegOpnd* instanceReg, IR::Instr* insertInstr, IR::LabelInstr* labelHelper);
  226. void LowerTypeof(IR::Instr * typeOfInstr);
  227. static void InsertObjectPoison(IR::Opnd* poisonedOpnd, IR::BranchInstr* branchInstr, IR::Instr* insertInstr, bool isForStore);
  228. public:
  229. //
  230. // These methods are simply forwarded to lowererMDArch
  231. //
  232. IR::Instr * LowerAsmJsCallI(IR::Instr * callInstr);
  233. IR::Instr * LowerAsmJsCallE(IR::Instr * callInstr);
  234. IR::Instr * LowerAsmJsLdElemHelper(IR::Instr * callInstr);
  235. IR::Instr * LowerAsmJsStElemHelper(IR::Instr * callInstr);
  236. IR::Instr * LowerCall(IR::Instr * callInstr, Js::ArgSlot argCount);
  237. IR::Instr * LowerCallI(IR::Instr * callInstr, ushort callFlags, bool isHelper = false, IR::Instr * insertBeforeInstrForCFG = nullptr);
  238. IR::Instr * LoadInt64HelperArgument(IR::Instr * instr, IR::Opnd* opnd);
  239. IR::Instr * LoadHelperArgument(IR::Instr * instr, IR::Opnd * opndArg);
  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. static IR::BranchInstr * GenerateLocalInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext, bool checkTypeWithoutProperty = false);
  272. static IR::BranchInstr * GenerateProtoInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  273. static IR::BranchInstr * GenerateFlagInlineCacheCheck(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  274. static IR::BranchInstr * GenerateFlagInlineCacheCheckForLocal(IR::Instr * instrLdSt, IR::RegOpnd * opndType, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelNext);
  275. static void GenerateLdFldFromLocalInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  276. static void GenerateLdFldFromProtoInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  277. static void GenerateLdLocalFldFromFlagInlineCache(IR::Instr * instrLdFld, IR::RegOpnd * opndBase, IR::Opnd * opndDst, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  278. void GenerateStFldFromLocalInlineCache(IR::Instr * instrStFld, IR::RegOpnd * opndBase, IR::Opnd * opndSrc, IR::RegOpnd * opndInlineCache, IR::LabelInstr * labelFallThru, bool isInlineSlot);
  279. IR::Instr * LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailOutLabel);
  280. void LowerInlineSpreadArgOutLoop(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd)
  281. {
  282. this->lowererMDArch.LowerInlineSpreadArgOutLoop(callInstr, indexOpnd, arrayElementsStartOpnd);
  283. }
  284. static IR::Instr * InsertCmovCC(const Js::OpCode opCode, IR::Opnd * dst, IR::Opnd* src1, IR::Instr* insertBeforeInstr, bool postRegAlloc = false);
  285. #ifdef ENABLE_SIMDJS
  286. void Simd128InitOpcodeMap();
  287. IR::Instr* Simd128Instruction(IR::Instr* instr);
  288. IR::Instr* Simd128LoadConst(IR::Instr* instr);
  289. bool Simd128TryLowerMappedInstruction(IR::Instr *instr);
  290. IR::Instr* Simd128LowerUnMappedInstruction(IR::Instr *instr);
  291. IR::Instr* Simd128LowerConstructor_2(IR::Instr *instr);
  292. IR::Instr* Simd128LowerConstructor_4(IR::Instr *instr);
  293. IR::Instr* Simd128LowerConstructor_8(IR::Instr *instr);
  294. IR::Instr* Simd128LowerConstructor_16(IR::Instr *instr);
  295. IR::Instr* Simd128LowerLdLane(IR::Instr *instr);
  296. IR::Instr* SIMD128LowerReplaceLane_4(IR::Instr *instr);
  297. IR::Instr* SIMD128LowerReplaceLane_8(IR::Instr *instr);
  298. IR::Instr* SIMD128LowerReplaceLane_16(IR::Instr *instr);
  299. IR::Instr* Simd128LowerSplat(IR::Instr *instr);
  300. IR::Instr* Simd128LowerRcp(IR::Instr *instr, bool removeInstr = true);
  301. IR::Instr* Simd128LowerSqrt(IR::Instr *instr);
  302. IR::Instr* Simd128LowerRcpSqrt(IR::Instr *instr);
  303. IR::Instr* Simd128LowerSelect(IR::Instr *instr);
  304. IR::Instr* Simd128LowerNeg(IR::Instr *instr);
  305. IR::Instr* Simd128LowerMulI4(IR::Instr *instr);
  306. IR::Instr* Simd128LowerShift(IR::Instr *instr);
  307. IR::Instr* Simd128LowerMulI16(IR::Instr *instr);
  308. IR::Instr* Simd128LowerInt32x4FromFloat32x4(IR::Instr *instr);
  309. IR::Instr* Simd128LowerUint32x4FromFloat32x4(IR::Instr *instr);
  310. IR::Instr* Simd128LowerFloat32x4FromUint32x4(IR::Instr *instr);
  311. IR::Instr* Simd128AsmJsLowerLoadElem(IR::Instr *instr);
  312. IR::Instr* Simd128LowerLoadElem(IR::Instr *instr);
  313. IR::Instr* Simd128ConvertToLoad(IR::Opnd *dst, IR::Opnd *src1, uint8 dataWidth, IR::Instr* instr, byte scaleFactor = 0);
  314. IR::Instr* Simd128AsmJsLowerStoreElem(IR::Instr *instr);
  315. IR::Instr* Simd128LowerStoreElem(IR::Instr *instr);
  316. IR::Instr* Simd128ConvertToStore(IR::Opnd *dst, IR::Opnd *src1, uint8 dataWidth, IR::Instr* instr, byte scaleFactor = 0);
  317. void Simd128LoadHeadSegment(IR::IndirOpnd *indirOpnd, ValueType arrType, IR::Instr *instr);
  318. void Simd128GenerateUpperBoundCheck(IR::RegOpnd *indexOpnd, IR::IndirOpnd *indirOpnd, ValueType arrType, IR::Instr *instr);
  319. IR::Instr* Simd128LowerSwizzle_4(IR::Instr *instr);
  320. IR::Instr* Simd128LowerShuffle_4(IR::Instr *instr);
  321. IR::Instr* Simd128LowerShuffle(IR::Instr *instr);
  322. IR::Instr* Simd128LowerNotEqual(IR::Instr* instr);
  323. IR::Instr* Simd128LowerLessThan(IR::Instr* instr);
  324. IR::Instr* Simd128LowerLessThanOrEqual(IR::Instr* instr);
  325. IR::Instr* Simd128LowerGreaterThanOrEqual(IR::Instr* instr);
  326. IR::Instr* Simd128LowerMinMax_F4(IR::Instr* instr);
  327. IR::Instr* Simd128LowerMinMaxNum(IR::Instr* instr);
  328. IR::Instr* Simd128LowerAnyTrue(IR::Instr* instr);
  329. IR::Instr* Simd128LowerAllTrue(IR::Instr* instr);
  330. BYTE Simd128GetTypedArrBytesPerElem(ValueType arrType);
  331. IR::Instr* Simd128CanonicalizeToBools(IR::Instr* instr, const Js::OpCode& cmpOpcode, IR::Opnd& dstOpnd);
  332. IR::Opnd* EnregisterIntConst(IR::Instr* instr, IR::Opnd *constOpnd, IRType type = TyInt32);
  333. SList<IR::Opnd*> * Simd128GetExtendedArgs(IR::Instr *instr);
  334. void GenerateCheckedSimdLoad(IR::Instr * instr);
  335. void GenerateSimdStore(IR::Instr * instr);
  336. void CheckShuffleLanes_4(uint8 lanes[], uint8 lanesSrc[], uint *fromSrc1, uint *fromSrc2);
  337. void InsertShufps(uint8 lanes[], IR::Opnd *dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *insertBeforeInstr);
  338. #endif
  339. private:
  340. void EmitReinterpretFloatToInt(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  341. void EmitReinterpretIntToFloat(IR::Opnd* dst, IR::Opnd* src, IR::Instr* insertBeforeInstr);
  342. IR::Instr * NegZeroBranching(IR::Opnd* opnd, IR::Instr* instr, IR::LabelInstr* isNeg0Label, IR::LabelInstr* isNotNeg0Label);
  343. void GenerateFlagInlineCacheCheckForGetterSetter(
  344. IR::Instr * insertBeforeInstr,
  345. IR::RegOpnd * opndInlineCache,
  346. IR::LabelInstr * labelNext);
  347. void GenerateLdFldFromFlagInlineCache(
  348. IR::Instr * insertBeforeInstr,
  349. IR::RegOpnd * opndBase,
  350. IR::Opnd * opndDst,
  351. IR::RegOpnd * opndInlineCache,
  352. IR::LabelInstr * labelFallThru,
  353. bool isInlineSlot);
  354. IR::LabelInstr* EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, bool needLabelHelper);
  355. #ifdef RECYCLER_WRITE_BARRIER
  356. static IR::Instr* GenerateWriteBarrier(IR::Instr * assignInstr);
  357. #endif
  358. // Data
  359. protected:
  360. Func *m_func;
  361. Lowerer *m_lowerer;
  362. LowererMDArch lowererMDArch;
  363. StackSymMap *floatTmpMap;
  364. BVSparse<JitArenaAllocator> *bvFloatTmpInits;
  365. Js::OpCode *m_simd128OpCodesMap; // used to map single-opcode SIMD operations
  366. };