Func.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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. struct CodeGenWorkItem;
  7. class Lowerer;
  8. class Inline;
  9. class FlowGraph;
  10. #if defined(_M_ARM32_OR_ARM64)
  11. #include "UnwindInfoManager.h"
  12. #endif
  13. struct Int64RegPair
  14. {
  15. IR::Opnd* high = nullptr;
  16. IR::Opnd* low = nullptr;
  17. };
  18. struct Cloner
  19. {
  20. Cloner(Lowerer *lowerer, JitArenaAllocator *alloc) :
  21. alloc(alloc),
  22. symMap(nullptr),
  23. labelMap(nullptr),
  24. lowerer(lowerer),
  25. instrFirst(nullptr),
  26. instrLast(nullptr),
  27. fRetargetClonedBranch(FALSE),
  28. clonedInstrGetOrigArgSlotSym(false)
  29. {
  30. }
  31. ~Cloner()
  32. {
  33. if (symMap)
  34. {
  35. Adelete(alloc, symMap);
  36. }
  37. if (labelMap)
  38. {
  39. Adelete(alloc, labelMap);
  40. }
  41. }
  42. void AddInstr(IR::Instr * instrOrig, IR::Instr * instrClone);
  43. void Finish();
  44. void RetargetClonedBranches();
  45. JitArenaAllocator *alloc;
  46. HashTable<StackSym*> *symMap;
  47. HashTable<IR::LabelInstr*> *labelMap;
  48. Lowerer * lowerer;
  49. IR::Instr * instrFirst;
  50. IR::Instr * instrLast;
  51. BOOL fRetargetClonedBranch;
  52. bool clonedInstrGetOrigArgSlotSym;
  53. };
  54. /*
  55. * This class keeps track of various information required for Stack Arguments optimization with formals.
  56. */
  57. class StackArgWithFormalsTracker
  58. {
  59. private:
  60. BVSparse<JitArenaAllocator> * formalsArraySyms; //Tracks Formal parameter Array - Is this Bv required explicitly?
  61. StackSym** formalsIndexToStackSymMap; //Tracks the stack sym for each formal
  62. StackSym* m_scopeObjSym; // Tracks the stack sym for the scope object that is created.
  63. JitArenaAllocator* alloc;
  64. public:
  65. StackArgWithFormalsTracker(JitArenaAllocator *alloc):
  66. formalsArraySyms(nullptr),
  67. formalsIndexToStackSymMap(nullptr),
  68. m_scopeObjSym(nullptr),
  69. alloc(alloc)
  70. {
  71. }
  72. BVSparse<JitArenaAllocator> * GetFormalsArraySyms();
  73. void SetFormalsArraySyms(SymID symId);
  74. StackSym ** GetFormalsIndexToStackSymMap();
  75. void SetStackSymInFormalsIndexMap(StackSym * sym, Js::ArgSlot formalsIndex, Js::ArgSlot formalsCount);
  76. void SetScopeObjSym(StackSym * sym);
  77. StackSym * GetScopeObjSym();
  78. };
  79. typedef JsUtil::Pair<uint32, IR::LabelInstr*> YieldOffsetResumeLabel;
  80. typedef JsUtil::List<YieldOffsetResumeLabel, JitArenaAllocator> YieldOffsetResumeLabelList;
  81. typedef HashTable<uint32, JitArenaAllocator> SlotArrayCheckTable;
  82. struct FrameDisplayCheckRecord
  83. {
  84. SlotArrayCheckTable *table;
  85. uint32 slotId;
  86. FrameDisplayCheckRecord() : table(nullptr), slotId((uint32)-1) {}
  87. };
  88. typedef HashTable<FrameDisplayCheckRecord*, JitArenaAllocator> FrameDisplayCheckTable;
  89. class Func
  90. {
  91. public:
  92. Func(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
  93. ThreadContextInfo * threadContextInfo,
  94. ScriptContextInfo * scriptContextInfo,
  95. JITOutputIDL * outputData,
  96. Js::EntryPointInfo* epInfo,
  97. const FunctionJITRuntimeInfo *const runtimeInfo,
  98. JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, void * const codeGenAllocators,
  99. #if !FLOATVAR
  100. CodeGenNumberAllocator * numberAllocator,
  101. #endif
  102. Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT, Func * parentFunc = nullptr,
  103. uint postCallByteCodeOffset = Js::Constants::NoByteCodeOffset,
  104. Js::RegSlot returnValueRegSlot = Js::Constants::NoRegister, const bool isInlinedConstructor = false,
  105. Js::ProfileId callSiteIdInParentFunc = UINT16_MAX, bool isGetterSetter = false);
  106. public:
  107. void * const GetCodeGenAllocators()
  108. {
  109. return this->GetTopFunc()->m_codeGenAllocators;
  110. }
  111. InProcCodeGenAllocators * const GetInProcCodeGenAllocators()
  112. {
  113. Assert(!JITManager::GetJITManager()->IsJITServer());
  114. return reinterpret_cast<InProcCodeGenAllocators*>(this->GetTopFunc()->m_codeGenAllocators);
  115. }
  116. #if ENABLE_OOP_NATIVE_CODEGEN
  117. OOPCodeGenAllocators * const GetOOPCodeGenAllocators()
  118. {
  119. Assert(JITManager::GetJITManager()->IsJITServer());
  120. return reinterpret_cast<OOPCodeGenAllocators*>(this->GetTopFunc()->m_codeGenAllocators);
  121. }
  122. #endif
  123. NativeCodeData::Allocator *GetNativeCodeDataAllocator()
  124. {
  125. return &this->GetTopFunc()->nativeCodeDataAllocator;
  126. }
  127. NativeCodeData::Allocator *GetTransferDataAllocator()
  128. {
  129. return &this->GetTopFunc()->transferDataAllocator;
  130. }
  131. #if !FLOATVAR
  132. CodeGenNumberAllocator * GetNumberAllocator()
  133. {
  134. return this->numberAllocator;
  135. }
  136. #endif
  137. #if !FLOATVAR
  138. XProcNumberPageSegmentImpl* GetXProcNumberAllocator()
  139. {
  140. if (this->GetJITOutput()->GetOutputData()->numberPageSegments == nullptr)
  141. {
  142. XProcNumberPageSegmentImpl* seg = (XProcNumberPageSegmentImpl*)midl_user_allocate(sizeof(XProcNumberPageSegment));
  143. if (seg == nullptr)
  144. {
  145. Js::Throw::OutOfMemory();
  146. }
  147. this->GetJITOutput()->GetOutputData()->numberPageSegments = new (seg) XProcNumberPageSegmentImpl();
  148. }
  149. return (XProcNumberPageSegmentImpl*)this->GetJITOutput()->GetOutputData()->numberPageSegments;
  150. }
  151. #endif
  152. Js::ScriptContextProfiler *GetCodeGenProfiler() const
  153. {
  154. #ifdef PROFILE_EXEC
  155. return m_codeGenProfiler;
  156. #else
  157. return nullptr;
  158. #endif
  159. }
  160. bool IsOOPJIT() const { return JITManager::GetJITManager()->IsOOPJITEnabled(); }
  161. void InitLocalClosureSyms();
  162. bool HasAnyStackNestedFunc() const { return this->hasAnyStackNestedFunc; }
  163. bool DoStackNestedFunc() const { return this->stackNestedFunc; }
  164. bool DoStackFrameDisplay() const { return this->stackClosure; }
  165. bool DoStackScopeSlots() const { return this->stackClosure; }
  166. bool IsBackgroundJIT() const { return this->m_isBackgroundJIT; }
  167. bool HasArgumentSlot() const { return this->GetInParamsCount() != 0 && !this->IsLoopBody(); }
  168. bool IsLoopBody() const { return m_workItem->IsLoopBody(); }
  169. bool IsLoopBodyInTry() const;
  170. bool IsLoopBodyInTryFinally() const;
  171. bool CanAllocInPreReservedHeapPageSegment();
  172. void SetDoFastPaths();
  173. bool DoFastPaths() const { Assert(this->hasCalledSetDoFastPaths); return this->m_doFastPaths; }
  174. bool DoLoopFastPaths() const
  175. {
  176. return
  177. (!IsSimpleJit() || CONFIG_FLAG(NewSimpleJit)) &&
  178. !PHASE_OFF(Js::FastPathPhase, this) &&
  179. !PHASE_OFF(Js::LoopFastPathPhase, this);
  180. }
  181. bool DoGlobOpt() const
  182. {
  183. return
  184. !PHASE_OFF(Js::GlobOptPhase, this) && !IsSimpleJit() &&
  185. (!GetTopFunc()->HasTry() || GetTopFunc()->CanOptimizeTryCatch()) &&
  186. (!GetTopFunc()->HasFinally() || GetTopFunc()->CanOptimizeTryFinally());
  187. }
  188. bool DoInline() const
  189. {
  190. #ifdef _M_IX86
  191. return DoGlobOpt() && !GetTopFunc()->HasTry();
  192. #else
  193. return DoGlobOpt();
  194. #endif
  195. }
  196. bool DoOptimizeTry() const
  197. {
  198. Assert(IsTopFunc());
  199. return DoGlobOpt();
  200. }
  201. bool CanOptimizeTryFinally() const
  202. {
  203. return !this->m_workItem->IsLoopBody() && !PHASE_OFF(Js::OptimizeTryFinallyPhase, this) &&
  204. (!this->HasProfileInfo() || !this->GetReadOnlyProfileInfo()->IsOptimizeTryFinallyDisabled());
  205. }
  206. bool CanOptimizeTryCatch() const
  207. {
  208. return !this->m_workItem->IsLoopBody() && !PHASE_OFF(Js::OptimizeTryCatchPhase, this);
  209. }
  210. bool DoSimpleJitDynamicProfile() const;
  211. bool IsSimpleJit() const { return m_workItem->GetJitMode() == ExecutionMode::SimpleJit; }
  212. JITTimeWorkItem * GetWorkItem() const
  213. {
  214. return m_workItem;
  215. }
  216. ThreadContext * GetInProcThreadContext() const
  217. {
  218. Assert(!IsOOPJIT());
  219. return (ThreadContext*)m_threadContextInfo;
  220. }
  221. ServerThreadContext* GetOOPThreadContext() const
  222. {
  223. Assert(IsOOPJIT());
  224. return (ServerThreadContext*)m_threadContextInfo;
  225. }
  226. ThreadContextInfo * GetThreadContextInfo() const
  227. {
  228. return m_threadContextInfo;
  229. }
  230. ScriptContextInfo * GetScriptContextInfo() const
  231. {
  232. return m_scriptContextInfo;
  233. }
  234. JITOutput* GetJITOutput()
  235. {
  236. return &m_output;
  237. }
  238. const JITOutput* GetJITOutput() const
  239. {
  240. return &m_output;
  241. }
  242. const JITTimeFunctionBody * const GetJITFunctionBody() const
  243. {
  244. return m_workItem->GetJITFunctionBody();
  245. }
  246. Js::EntryPointInfo* GetInProcJITEntryPointInfo() const
  247. {
  248. Assert(!IsOOPJIT());
  249. return m_entryPointInfo;
  250. }
  251. char16* GetDebugNumberSet(wchar(&bufferToWriteTo)[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE]) const
  252. {
  253. return m_workItem->GetJITTimeInfo()->GetDebugNumberSet(bufferToWriteTo);
  254. }
  255. void TryCodegen();
  256. static void Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
  257. ThreadContextInfo * threadContextInfo,
  258. ScriptContextInfo * scriptContextInfo,
  259. JITOutputIDL * outputData,
  260. Js::EntryPointInfo* epInfo, // for in-proc jit only
  261. const FunctionJITRuntimeInfo *const runtimeInfo,
  262. JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, void * const codeGenAllocators,
  263. #if !FLOATVAR
  264. CodeGenNumberAllocator * numberAllocator,
  265. #endif
  266. Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT);
  267. int32 StackAllocate(int size);
  268. int32 StackAllocate(StackSym *stackSym, int size);
  269. void SetArgOffset(StackSym *stackSym, int32 offset);
  270. int32 GetLocalVarSlotOffset(int32 slotId);
  271. int32 GetHasLocalVarChangedOffset();
  272. bool IsJitInDebugMode() const;
  273. bool IsNonTempLocalVar(uint32 slotIndex);
  274. void OnAddSym(Sym* sym);
  275. uint GetLocalFunctionId() const
  276. {
  277. return m_workItem->GetJITTimeInfo()->GetLocalFunctionId();
  278. }
  279. uint GetSourceContextId() const
  280. {
  281. return m_workItem->GetJITFunctionBody()->GetSourceContextId();
  282. }
  283. #ifdef MD_GROW_LOCALS_AREA_UP
  284. void AjustLocalVarSlotOffset();
  285. #endif
  286. bool DoGlobOptsForGeneratorFunc() const;
  287. static int32 AdjustOffsetValue(int32 offset);
  288. static inline uint32 GetDiagLocalSlotSize()
  289. {
  290. // For the debug purpose we will have fixed stack slot size
  291. // We will allocated the 8 bytes for each variable.
  292. return MachDouble;
  293. }
  294. #ifdef DBG
  295. // The pattern used to pre-fill locals for CHK builds.
  296. // When we restore bailout values we check for this pattern, this is how we assert for non-initialized variables/garbage.
  297. static const uint32 c_debugFillPattern4 = 0xcececece;
  298. static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
  299. #if defined(TARGET_32)
  300. static const uint32 c_debugFillPattern = c_debugFillPattern4;
  301. #elif defined(TARGET_64)
  302. static const unsigned __int64 c_debugFillPattern = c_debugFillPattern8;
  303. #else
  304. #error unsupported platform
  305. #endif
  306. #endif
  307. uint32 GetInstrCount();
  308. inline Js::ScriptContext* GetScriptContext() const
  309. {
  310. Assert(!IsOOPJIT());
  311. return static_cast<Js::ScriptContext*>(this->GetScriptContextInfo());
  312. }
  313. void NumberInstrs();
  314. bool IsTopFunc() const { return this->parentFunc == nullptr; }
  315. Func const * GetTopFunc() const { return this->topFunc; }
  316. Func * GetTopFunc() { return this->topFunc; }
  317. void SetFirstArgOffset(IR::Instr* inlineeStart);
  318. uint GetFunctionNumber() const
  319. {
  320. return m_workItem->GetJITFunctionBody()->GetFunctionNumber();
  321. }
  322. BOOL HasTry() const
  323. {
  324. Assert(this->IsTopFunc());
  325. return this->GetJITFunctionBody()->HasTry();
  326. }
  327. bool HasFinally() const
  328. {
  329. Assert(this->IsTopFunc());
  330. return this->GetJITFunctionBody()->HasFinally();
  331. }
  332. bool HasThis() const
  333. {
  334. Assert(this->IsTopFunc());
  335. Assert(this->GetJITFunctionBody()); // For now we always have a function body
  336. return this->GetJITFunctionBody()->HasThis();
  337. }
  338. Js::ArgSlot GetInParamsCount() const
  339. {
  340. Assert(this->IsTopFunc());
  341. return this->GetJITFunctionBody()->GetInParamsCount();
  342. }
  343. bool IsGlobalFunc() const
  344. {
  345. Assert(this->IsTopFunc());
  346. return this->GetJITFunctionBody()->IsGlobalFunc();
  347. }
  348. uint16 GetArgUsedForBranch() const;
  349. intptr_t GetWeakFuncRef() const;
  350. const FunctionJITRuntimeInfo * GetRuntimeInfo() const { return m_runtimeInfo; }
  351. bool IsLambda() const
  352. {
  353. Assert(this->IsTopFunc());
  354. Assert(this->GetJITFunctionBody()); // For now we always have a function body
  355. return this->GetJITFunctionBody()->IsLambda();
  356. }
  357. bool IsTrueLeaf() const
  358. {
  359. return !GetHasCalls() && !GetHasImplicitCalls();
  360. }
  361. StackSym *EnsureLoopParamSym();
  362. void UpdateForInLoopMaxDepth(uint forInLoopMaxDepth);
  363. int GetForInEnumeratorArrayOffset() const;
  364. StackSym *GetFuncObjSym() const { return m_funcObjSym; }
  365. void SetFuncObjSym(StackSym *sym) { m_funcObjSym = sym; }
  366. StackSym *GetJavascriptLibrarySym() const { return m_javascriptLibrarySym; }
  367. void SetJavascriptLibrarySym(StackSym *sym) { m_javascriptLibrarySym = sym; }
  368. StackSym *GetScriptContextSym() const { return m_scriptContextSym; }
  369. void SetScriptContextSym(StackSym *sym) { m_scriptContextSym = sym; }
  370. StackSym *GetFunctionBodySym() const { return m_functionBodySym; }
  371. void SetFunctionBodySym(StackSym *sym) { m_functionBodySym = sym; }
  372. StackSym *GetLocalClosureSym() const { return m_localClosureSym; }
  373. void SetLocalClosureSym(StackSym *sym) { m_localClosureSym = sym; }
  374. StackSym *GetParamClosureSym() const { return m_paramClosureSym; }
  375. void SetParamClosureSym(StackSym *sym) { m_paramClosureSym = sym; }
  376. StackSym *GetLocalFrameDisplaySym() const { return m_localFrameDisplaySym; }
  377. void SetLocalFrameDisplaySym(StackSym *sym) { m_localFrameDisplaySym = sym; }
  378. intptr_t GetJittedLoopIterationsSinceLastBailoutAddress() const;
  379. void EnsurePinnedTypeRefs();
  380. void PinTypeRef(void* typeRef);
  381. void EnsureSingleTypeGuards();
  382. Js::JitTypePropertyGuard* GetOrCreateSingleTypeGuard(intptr_t typeAddr);
  383. void EnsureEquivalentTypeGuards();
  384. void InitializeEquivalentTypeGuard(Js::JitEquivalentTypeGuard * guard);
  385. Js::JitEquivalentTypeGuard * CreateEquivalentTypeGuard(JITTypeHolder type, uint32 objTypeSpecFldId);
  386. Js::JitPolyEquivalentTypeGuard * CreatePolyEquivalentTypeGuard(uint32 objTypeSpecFldId);
  387. void ThrowIfScriptClosed();
  388. void EnsurePropertyGuardsByPropertyId();
  389. void EnsureCtorCachesByPropertyId();
  390. void LinkGuardToPropertyId(Js::PropertyId propertyId, Js::JitIndexedPropertyGuard* guard);
  391. void LinkCtorCacheToPropertyId(Js::PropertyId propertyId, JITTimeConstructorCache* cache);
  392. JITTimeConstructorCache * GetConstructorCache(const Js::ProfileId profiledCallSiteId);
  393. void SetConstructorCache(const Js::ProfileId profiledCallSiteId, JITTimeConstructorCache* constructorCache);
  394. void EnsurePropertiesWrittenTo();
  395. void EnsureCallSiteToArgumentsOffsetFixupMap();
  396. IR::LabelInstr * EnsureFuncStartLabel();
  397. IR::LabelInstr * GetFuncStartLabel();
  398. IR::LabelInstr * EnsureFuncEndLabel();
  399. IR::LabelInstr * GetFuncEndLabel();
  400. #ifdef _M_X64
  401. void SetSpillSize(int32 spillSize)
  402. {
  403. m_spillSize = spillSize;
  404. }
  405. int32 GetSpillSize()
  406. {
  407. return m_spillSize;
  408. }
  409. void SetArgsSize(int32 argsSize)
  410. {
  411. m_argsSize = argsSize;
  412. }
  413. int32 GetArgsSize()
  414. {
  415. return m_argsSize;
  416. }
  417. void SetSavedRegSize(int32 savedRegSize)
  418. {
  419. m_savedRegSize = savedRegSize;
  420. }
  421. int32 GetSavedRegSize()
  422. {
  423. return m_savedRegSize;
  424. }
  425. #endif
  426. bool IsInlinee() const
  427. {
  428. Assert(m_inlineeFrameStartSym ? (m_inlineeFrameStartSym->m_offset != -1) : true);
  429. return m_inlineeFrameStartSym != nullptr;
  430. }
  431. void SetInlineeFrameStartSym(StackSym *sym)
  432. {
  433. Assert(m_inlineeFrameStartSym == nullptr);
  434. m_inlineeFrameStartSym = sym;
  435. }
  436. void SetInlineeStart(IR::Instr *inlineeStartInstr)
  437. {
  438. Assert(inlineeStart == nullptr);
  439. inlineeStart = inlineeStartInstr;
  440. }
  441. IR::Instr* GetInlineeStart()
  442. {
  443. return inlineeStart;
  444. }
  445. IR::SymOpnd *GetInlineeArgCountSlotOpnd()
  446. {
  447. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argc * MachPtr);
  448. }
  449. IR::SymOpnd *GetNextInlineeFrameArgCountSlotOpnd()
  450. {
  451. Assert(!this->m_hasInlineArgsOpt);
  452. if (this->m_hasInlineArgsOpt)
  453. {
  454. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  455. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  456. throw Js::OperationAbortedException();
  457. }
  458. return GetInlineeOpndAtOffset((Js::Constants::InlineeMetaArgCount + actualCount) * MachPtr);
  459. }
  460. IR::SymOpnd *GetInlineeFunctionObjectSlotOpnd()
  461. {
  462. Assert(!this->m_hasInlineArgsOpt);
  463. if (this->m_hasInlineArgsOpt)
  464. {
  465. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  466. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  467. throw Js::OperationAbortedException();
  468. }
  469. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_FunctionObject * MachPtr);
  470. }
  471. IR::SymOpnd *GetInlineeArgumentsObjectSlotOpnd()
  472. {
  473. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_ArgumentsObject * MachPtr);
  474. }
  475. IR::SymOpnd *GetInlineeArgvSlotOpnd()
  476. {
  477. Assert(!this->m_hasInlineArgsOpt);
  478. if (this->m_hasInlineArgsOpt)
  479. {
  480. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  481. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  482. throw Js::OperationAbortedException();
  483. }
  484. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argv * MachPtr);
  485. }
  486. bool IsInlined() const
  487. {
  488. return this->parentFunc != nullptr;
  489. }
  490. bool IsInlinedConstructor() const
  491. {
  492. return this->isInlinedConstructor;
  493. }
  494. bool IsTJLoopBody()const {
  495. return this->isTJLoopBody;
  496. }
  497. Js::Var AllocateNumber(double value);
  498. ObjTypeSpecFldInfo* GetObjTypeSpecFldInfo(const uint index) const;
  499. ObjTypeSpecFldInfo* GetGlobalObjTypeSpecFldInfo(uint propertyInfoId) const;
  500. // Gets an inline cache pointer to use in jitted code. Cached data may not be stable while jitting. Does not return null.
  501. intptr_t GetRuntimeInlineCache(const uint index) const;
  502. JITTimePolymorphicInlineCache * GetRuntimePolymorphicInlineCache(const uint index) const;
  503. byte GetPolyCacheUtil(const uint index) const;
  504. byte GetPolyCacheUtilToInitialize(const uint index) const;
  505. #if LOWER_SPLIT_INT64
  506. Int64RegPair FindOrCreateInt64Pair(IR::Opnd*);
  507. void Int64SplitExtendLoopLifetime(Loop* loop);
  508. #endif
  509. #if defined(_M_ARM32_OR_ARM64)
  510. RegNum GetLocalsPointer() const;
  511. #endif
  512. #if DBG_DUMP
  513. void Dump(IRDumpFlags flags);
  514. void Dump();
  515. void DumpHeader();
  516. #endif
  517. #if DBG_DUMP || defined(ENABLE_IR_VIEWER)
  518. LPCSTR GetVtableName(INT_PTR address);
  519. #endif
  520. #if DBG_DUMP | defined(VTUNE_PROFILING)
  521. bool DoRecordNativeMap() const;
  522. #endif
  523. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  524. void DumpFullFunctionName();
  525. #endif
  526. public:
  527. JitArenaAllocator * m_alloc;
  528. const FunctionJITRuntimeInfo *const m_runtimeInfo;
  529. ThreadContextInfo * m_threadContextInfo;
  530. ScriptContextInfo * m_scriptContextInfo;
  531. JITTimeWorkItem * m_workItem;
  532. JITTimePolymorphicInlineCacheInfo *const m_polymorphicInlineCacheInfo;
  533. // This indicates how many constructor caches we inserted into the constructorCaches array, not the total size of the array.
  534. uint constructorCacheCount;
  535. // This array maps callsite ids to constructor caches. The size corresponds to the number of callsites in the function.
  536. JITTimeConstructorCache** constructorCaches;
  537. typedef JsUtil::BaseHashSet<void*, JitArenaAllocator, PowerOf2SizePolicy> TypeRefSet;
  538. TypeRefSet* pinnedTypeRefs;
  539. typedef JsUtil::BaseDictionary<intptr_t, Js::JitTypePropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> TypePropertyGuardDictionary;
  540. TypePropertyGuardDictionary* singleTypeGuards;
  541. typedef SListCounted<Js::JitEquivalentTypeGuard*> EquivalentTypeGuardList;
  542. EquivalentTypeGuardList* equivalentTypeGuards;
  543. typedef JsUtil::BaseHashSet<Js::JitIndexedPropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> IndexedPropertyGuardSet;
  544. typedef JsUtil::BaseDictionary<Js::PropertyId, IndexedPropertyGuardSet*, JitArenaAllocator, PowerOf2SizePolicy> PropertyGuardByPropertyIdMap;
  545. PropertyGuardByPropertyIdMap* propertyGuardsByPropertyId;
  546. typedef JsUtil::BaseHashSet<intptr_t, JitArenaAllocator, PowerOf2SizePolicy> CtorCacheSet;
  547. typedef JsUtil::BaseDictionary<Js::PropertyId, CtorCacheSet*, JitArenaAllocator, PowerOf2SizePolicy> CtorCachesByPropertyIdMap;
  548. CtorCachesByPropertyIdMap* ctorCachesByPropertyId;
  549. typedef JsUtil::BaseDictionary<Js::ProfileId, int32, JitArenaAllocator, PrimeSizePolicy> CallSiteToArgumentsOffsetFixupMap;
  550. CallSiteToArgumentsOffsetFixupMap* callSiteToArgumentsOffsetFixupMap;
  551. int indexedPropertyGuardCount;
  552. typedef JsUtil::BaseHashSet<Js::PropertyId, JitArenaAllocator> PropertyIdSet;
  553. PropertyIdSet* propertiesWrittenTo;
  554. PropertyIdSet lazyBailoutProperties;
  555. bool anyPropertyMayBeWrittenTo;
  556. SlotArrayCheckTable *slotArrayCheckTable;
  557. FrameDisplayCheckTable *frameDisplayCheckTable;
  558. IR::Instr * m_headInstr;
  559. IR::Instr * m_exitInstr;
  560. IR::Instr * m_tailInstr;
  561. #ifdef _M_X64
  562. int32 m_spillSize;
  563. int32 m_argsSize;
  564. int32 m_savedRegSize;
  565. PrologEncoder m_prologEncoder;
  566. #endif
  567. SymTable * m_symTable;
  568. StackSym * m_loopParamSym;
  569. StackSym * m_funcObjSym;
  570. StackSym * m_javascriptLibrarySym;
  571. StackSym * m_scriptContextSym;
  572. StackSym * m_functionBodySym;
  573. StackSym * m_localClosureSym;
  574. StackSym * m_paramClosureSym;
  575. StackSym * m_localFrameDisplaySym;
  576. StackSym * m_bailoutReturnValueSym;
  577. StackSym * m_hasBailedOutSym;
  578. uint m_forInLoopMaxDepth;
  579. uint m_forInLoopBaseDepth;
  580. int32 m_forInEnumeratorArrayOffset;
  581. int32 m_localStackHeight;
  582. uint frameSize;
  583. uint32 inlineDepth;
  584. uint32 postCallByteCodeOffset;
  585. Js::RegSlot returnValueRegSlot;
  586. Js::RegSlot firstIRTemp;
  587. Js::ArgSlot actualCount;
  588. int32 firstActualStackOffset;
  589. uint32 tryCatchNestingLevel;
  590. uint32 m_totalJumpTableSizeInBytesForSwitchStatements;
  591. #if defined(_M_ARM32_OR_ARM64)
  592. //Offset to arguments from sp + m_localStackHeight;
  593. //For non leaf functions this is (callee saved register count + LR + R11) * MachRegInt
  594. //For leaf functions this is (saved registers) * MachRegInt
  595. int32 m_ArgumentsOffset;
  596. UnwindInfoManager m_unwindInfo;
  597. IR::LabelInstr * m_epilogLabel;
  598. #endif
  599. IR::LabelInstr * m_funcStartLabel;
  600. IR::LabelInstr * m_funcEndLabel;
  601. // Keep track of the maximum number of args on the stack.
  602. uint32 m_argSlotsForFunctionsCalled;
  603. #if DBG
  604. uint32 m_callSiteCount;
  605. #endif
  606. FlowGraph * m_fg;
  607. unsigned int m_labelCount;
  608. BitVector m_regsUsed;
  609. StackSym * tempSymDouble;
  610. StackSym * tempSymBool;
  611. uint32 loopCount;
  612. uint32 unoptimizableArgumentsObjReference;
  613. Js::ProfileId callSiteIdInParentFunc;
  614. InlineeFrameInfo* cachedInlineeFrameInfo;
  615. bool m_hasCalls: 1; // This is more accurate compared to m_isLeaf
  616. bool m_hasInlineArgsOpt : 1;
  617. bool m_doFastPaths : 1;
  618. bool hasBailout: 1;
  619. bool hasBailoutInEHRegion : 1;
  620. bool hasStackArgs: 1;
  621. bool hasArgLenAndConstOpt : 1;
  622. bool hasImplicitParamLoad : 1; // True if there is a load of CallInfo, FunctionObject
  623. bool hasThrow : 1;
  624. bool hasUnoptimizedArgumentsAccess : 1; // True if there are any arguments access beyond the simple case of this.apply pattern
  625. bool m_canDoInlineArgsOpt : 1;
  626. bool applyTargetInliningRemovedArgumentsAccess : 1;
  627. bool isGetterSetter : 1;
  628. const bool isInlinedConstructor: 1;
  629. bool hasImplicitCalls: 1;
  630. bool hasTempObjectProducingInstr:1; // At least one instruction which can produce temp object
  631. bool isTJLoopBody : 1;
  632. bool isFlowGraphValid : 1;
  633. bool legalizePostRegAlloc : 1;
  634. #if DBG
  635. bool hasCalledSetDoFastPaths:1;
  636. bool isPostLower:1;
  637. bool isPostRegAlloc:1;
  638. bool isPostPeeps:1;
  639. bool isPostLayout:1;
  640. bool isPostFinalLower:1;
  641. struct InstrByteCodeRegisterUses
  642. {
  643. Js::OpCode capturingOpCode;
  644. BVSparse<JitArenaAllocator>* bv;
  645. };
  646. typedef JsUtil::BaseDictionary<uint32, InstrByteCodeRegisterUses, JitArenaAllocator> ByteCodeRegisterUses;
  647. ByteCodeRegisterUses* byteCodeRegisterUses = nullptr;
  648. BVSparse<JitArenaAllocator>* GetByteCodeOffsetUses(uint offset) const;
  649. typedef JsUtil::Stack<Js::Phase> CurrentPhasesStack;
  650. CurrentPhasesStack currentPhases;
  651. bool IsInPhase(Js::Phase tag);
  652. #endif
  653. void BeginPhase(Js::Phase tag);
  654. void EndPhase(Js::Phase tag, bool dump = true);
  655. void EndProfiler(Js::Phase tag);
  656. void BeginClone(Lowerer *lowerer, JitArenaAllocator *alloc);
  657. void EndClone();
  658. Cloner * GetCloner() const { return GetTopFunc()->m_cloner; }
  659. InstrMap * GetCloneMap() const { return GetTopFunc()->m_cloneMap; }
  660. void ClearCloneMap() { Assert(this->IsTopFunc()); this->m_cloneMap = nullptr; }
  661. bool HasByteCodeOffset() const { return !this->GetTopFunc()->hasInstrNumber; }
  662. bool DoMaintainByteCodeOffset() const { return this->HasByteCodeOffset() && this->GetTopFunc()->maintainByteCodeOffset; }
  663. void StopMaintainByteCodeOffset() { this->GetTopFunc()->maintainByteCodeOffset = false; }
  664. Func * GetParentFunc() const { return parentFunc; }
  665. uint GetMaxInlineeArgOutSize() const { return this->maxInlineeArgOutSize; }
  666. void UpdateMaxInlineeArgOutSize(uint inlineeArgOutSize);
  667. #if DBG_DUMP
  668. ptrdiff_t m_codeSize;
  669. #endif
  670. bool GetHasCalls() const { return this->m_hasCalls; }
  671. void SetHasCallsOnSelfAndParents()
  672. {
  673. Func *curFunc = this;
  674. while (curFunc)
  675. {
  676. curFunc->m_hasCalls = true;
  677. curFunc = curFunc->GetParentFunc();
  678. }
  679. }
  680. void SetHasInstrNumber(bool has) { this->GetTopFunc()->hasInstrNumber = has; }
  681. bool HasInstrNumber() const { return this->GetTopFunc()->hasInstrNumber; }
  682. bool HasInlinee() const { Assert(this->IsTopFunc()); return this->hasInlinee; }
  683. void SetHasInlinee() { Assert(this->IsTopFunc()); this->hasInlinee = true; }
  684. bool GetThisOrParentInlinerHasArguments() const { return thisOrParentInlinerHasArguments; }
  685. bool GetHasStackArgs() const
  686. {
  687. return this->hasStackArgs && !IsStackArgOptDisabled() && !PHASE_OFF1(Js::StackArgOptPhase);
  688. }
  689. void SetHasStackArgs(bool has) { this->hasStackArgs = has;}
  690. bool IsStackArgsEnabled()
  691. {
  692. Func* curFunc = this;
  693. bool isStackArgsEnabled = GetJITFunctionBody()->UsesArgumentsObject() && curFunc->GetHasStackArgs();
  694. Func * topFunc = curFunc->GetTopFunc();
  695. if (topFunc != nullptr)
  696. {
  697. isStackArgsEnabled = isStackArgsEnabled && topFunc->GetHasStackArgs();
  698. }
  699. return isStackArgsEnabled;
  700. }
  701. bool GetHasImplicitParamLoad() const { return this->hasImplicitParamLoad; }
  702. void SetHasImplicitParamLoad() { this->hasImplicitParamLoad = true; }
  703. bool GetHasThrow() const { return this->hasThrow; }
  704. void SetHasThrow() { this->hasThrow = true; }
  705. bool GetHasUnoptimizedArgumentsAccess() const { return this->hasUnoptimizedArgumentsAccess; }
  706. void SetHasUnoptimizedArgumentsAccess(bool args)
  707. {
  708. // Once set to 'true' make sure this does not become false
  709. if (!this->hasUnoptimizedArgumentsAccess)
  710. {
  711. this->hasUnoptimizedArgumentsAccess = args;
  712. }
  713. if (args)
  714. {
  715. Func *curFunc = this->GetParentFunc();
  716. while (curFunc)
  717. {
  718. curFunc->hasUnoptimizedArgumentsAccess = args;
  719. curFunc = curFunc->GetParentFunc();
  720. }
  721. }
  722. }
  723. void DisableCanDoInlineArgOpt()
  724. {
  725. Func* curFunc = this;
  726. while (curFunc)
  727. {
  728. curFunc->m_canDoInlineArgsOpt = false;
  729. curFunc->m_hasInlineArgsOpt = false;
  730. curFunc = curFunc->GetParentFunc();
  731. }
  732. }
  733. bool ShouldLegalizePostRegAlloc() const { return topFunc->legalizePostRegAlloc; }
  734. bool GetApplyTargetInliningRemovedArgumentsAccess() const { return this->applyTargetInliningRemovedArgumentsAccess;}
  735. void SetApplyTargetInliningRemovedArgumentsAccess() { this->applyTargetInliningRemovedArgumentsAccess = true;}
  736. bool GetHasMarkTempObjects() const { return this->hasMarkTempObjects; }
  737. void SetHasMarkTempObjects() { this->hasMarkTempObjects = true; }
  738. bool GetHasNonSimpleParams() const { return this->hasNonSimpleParams; }
  739. void SetHasNonSimpleParams() { this->hasNonSimpleParams = true; }
  740. bool GetHasImplicitCalls() const { return this->hasImplicitCalls;}
  741. void SetHasImplicitCalls(bool has) { this->hasImplicitCalls = has;}
  742. void SetHasImplicitCallsOnSelfAndParents()
  743. {
  744. this->SetHasImplicitCalls(true);
  745. Func *curFunc = this->GetParentFunc();
  746. while (curFunc && !curFunc->IsTopFunc())
  747. {
  748. curFunc->SetHasImplicitCalls(true);
  749. curFunc = curFunc->GetParentFunc();
  750. }
  751. }
  752. bool GetHasTempObjectProducingInstr() const { return this->hasTempObjectProducingInstr; }
  753. void SetHasTempObjectProducingInstr(bool has) { this->hasTempObjectProducingInstr = has; }
  754. const JITTimeProfileInfo * GetReadOnlyProfileInfo() const { return GetJITFunctionBody()->GetReadOnlyProfileInfo(); }
  755. bool HasProfileInfo() const { return GetJITFunctionBody()->HasProfileInfo(); }
  756. bool HasArrayInfo()
  757. {
  758. const auto top = this->GetTopFunc();
  759. return this->HasProfileInfo() && this->GetWeakFuncRef() && !(top->HasTry() && !top->DoOptimizeTry()) &&
  760. top->DoGlobOpt() && !PHASE_OFF(Js::LoopFastPathPhase, top);
  761. }
  762. static Js::OpCode GetLoadOpForType(IRType type)
  763. {
  764. if (type == TyVar || IRType_IsFloat(type))
  765. {
  766. return Js::OpCode::Ld_A;
  767. }
  768. else
  769. {
  770. Assert(IRType_IsNativeInt(type));
  771. return Js::OpCode::Ld_I4;
  772. }
  773. }
  774. static Js::BuiltinFunction GetBuiltInIndex(IR::Opnd* opnd)
  775. {
  776. Assert(opnd);
  777. Js::BuiltinFunction index;
  778. if (opnd->IsRegOpnd())
  779. {
  780. index = opnd->AsRegOpnd()->m_sym->m_builtInIndex;
  781. }
  782. else if (opnd->IsSymOpnd())
  783. {
  784. PropertySym *propertySym = opnd->AsSymOpnd()->m_sym->AsPropertySym();
  785. index = Js::JavascriptLibrary::GetBuiltinFunctionForPropId(propertySym->m_propertyId);
  786. }
  787. else
  788. {
  789. index = Js::BuiltinFunction::None;
  790. }
  791. return index;
  792. }
  793. static bool IsBuiltInInlinedInLowerer(IR::Opnd* opnd)
  794. {
  795. Assert(opnd);
  796. Js::BuiltinFunction index = Func::GetBuiltInIndex(opnd);
  797. switch (index)
  798. {
  799. case Js::BuiltinFunction::JavascriptString_CharAt:
  800. case Js::BuiltinFunction::JavascriptString_CharCodeAt:
  801. case Js::BuiltinFunction::JavascriptString_CodePointAt:
  802. case Js::BuiltinFunction::Math_Abs:
  803. case Js::BuiltinFunction::JavascriptArray_Push:
  804. case Js::BuiltinFunction::JavascriptString_Replace:
  805. case Js::BuiltinFunction::JavascriptObject_HasOwnProperty:
  806. case Js::BuiltinFunction::JavascriptArray_IsArray:
  807. return true;
  808. default:
  809. return false;
  810. }
  811. }
  812. void AddYieldOffsetResumeLabel(uint32 offset, IR::LabelInstr* label)
  813. {
  814. m_yieldOffsetResumeLabelList->Add(YieldOffsetResumeLabel(offset, label));
  815. }
  816. template <typename Fn>
  817. void MapYieldOffsetResumeLabels(Fn fn)
  818. {
  819. m_yieldOffsetResumeLabelList->Map(fn);
  820. }
  821. template <typename Fn>
  822. bool MapUntilYieldOffsetResumeLabels(Fn fn)
  823. {
  824. return m_yieldOffsetResumeLabelList->MapUntil(fn);
  825. }
  826. void RemoveYieldOffsetResumeLabel(const YieldOffsetResumeLabel& yorl)
  827. {
  828. m_yieldOffsetResumeLabelList->Remove(yorl);
  829. }
  830. void RemoveDeadYieldOffsetResumeLabel(IR::LabelInstr* label)
  831. {
  832. uint32 offset;
  833. bool found = m_yieldOffsetResumeLabelList->MapUntil([&offset, &label](int i, YieldOffsetResumeLabel& yorl)
  834. {
  835. if (yorl.Second() == label)
  836. {
  837. offset = yorl.First();
  838. return true;
  839. }
  840. return false;
  841. });
  842. Assert(found);
  843. RemoveYieldOffsetResumeLabel(YieldOffsetResumeLabel(offset, label));
  844. AddYieldOffsetResumeLabel(offset, nullptr);
  845. }
  846. IR::Instr * GetFunctionEntryInsertionPoint();
  847. IR::IndirOpnd * GetConstantAddressIndirOpnd(intptr_t address, IR::Opnd *largeConstOpnd, IR::AddrOpndKind kind, IRType type, Js::OpCode loadOpCode);
  848. void MarkConstantAddressSyms(BVSparse<JitArenaAllocator> * bv);
  849. void DisableConstandAddressLoadHoist() { canHoistConstantAddressLoad = false; }
  850. void AddSlotArrayCheck(IR::SymOpnd *fieldOpnd);
  851. void AddFrameDisplayCheck(IR::SymOpnd *fieldOpnd, uint32 slotId = (uint32)-1);
  852. void EnsureStackArgWithFormalsTracker();
  853. BOOL IsFormalsArraySym(SymID symId);
  854. void TrackFormalsArraySym(SymID symId);
  855. void TrackStackSymForFormalIndex(Js::ArgSlot formalsIndex, StackSym * sym);
  856. StackSym* GetStackSymForFormal(Js::ArgSlot formalsIndex);
  857. bool HasStackSymForFormal(Js::ArgSlot formalsIndex);
  858. void SetScopeObjSym(StackSym * sym);
  859. StackSym * GetScopeObjSym();
  860. bool IsTrackCompoundedIntOverflowDisabled() const;
  861. bool IsArrayCheckHoistDisabled() const;
  862. bool IsStackArgOptDisabled() const;
  863. bool IsSwitchOptDisabled() const;
  864. bool IsAggressiveIntTypeSpecDisabled() const;
  865. #if DBG
  866. bool allowRemoveBailOutArgInstr;
  867. #endif
  868. #if defined(_M_ARM32_OR_ARM64)
  869. int32 GetInlineeArgumentStackSize()
  870. {
  871. int32 size = this->GetMaxInlineeArgOutSize();
  872. if (size)
  873. {
  874. return size + MachPtr; // +1 for the dedicated zero out argc slot
  875. }
  876. return 0;
  877. }
  878. #endif
  879. public:
  880. BVSparse<JitArenaAllocator> * argObjSyms;
  881. BVSparse<JitArenaAllocator> * m_nonTempLocalVars; // Only populated in debug mode as part of IRBuilder. Used in GlobOpt and BackwardPass.
  882. InlineeFrameInfo* frameInfo;
  883. Js::ArgSlot argInsCount; // This count doesn't include the ArgIn instr for "this".
  884. uint32 m_inlineeId;
  885. IR::LabelInstr * m_bailOutNoSaveLabel;
  886. StackSym * GetNativeCodeDataSym() const;
  887. void SetNativeCodeDataSym(StackSym * sym);
  888. private:
  889. Js::EntryPointInfo* m_entryPointInfo; // for in-proc JIT only
  890. JITOutput m_output;
  891. #ifdef PROFILE_EXEC
  892. Js::ScriptContextProfiler *const m_codeGenProfiler;
  893. #endif
  894. Func * const topFunc;
  895. Func * const parentFunc;
  896. StackSym * m_inlineeFrameStartSym;
  897. IR::Instr * inlineeStart;
  898. uint maxInlineeArgOutSize;
  899. const bool m_isBackgroundJIT;
  900. bool hasInstrNumber;
  901. bool maintainByteCodeOffset;
  902. bool hasInlinee;
  903. bool thisOrParentInlinerHasArguments;
  904. bool useRuntimeStats;
  905. bool stackNestedFunc;
  906. bool stackClosure;
  907. bool hasAnyStackNestedFunc;
  908. bool hasMarkTempObjects;
  909. bool hasNonSimpleParams;
  910. Cloner * m_cloner;
  911. InstrMap * m_cloneMap;
  912. NativeCodeData::Allocator nativeCodeDataAllocator;
  913. NativeCodeData::Allocator transferDataAllocator;
  914. #if !FLOATVAR
  915. CodeGenNumberAllocator * numberAllocator;
  916. #endif
  917. int32 m_localVarSlotsOffset;
  918. int32 m_hasLocalVarChangedOffset; // Offset on stack of 1 byte which indicates if any local var has changed.
  919. void * const m_codeGenAllocators;
  920. YieldOffsetResumeLabelList * m_yieldOffsetResumeLabelList;
  921. StackArgWithFormalsTracker * stackArgWithFormalsTracker;
  922. ObjTypeSpecFldInfo ** m_globalObjTypeSpecFldInfoArray;
  923. StackSym *CreateInlineeStackSym();
  924. IR::SymOpnd *GetInlineeOpndAtOffset(int32 offset);
  925. bool HasLocalVarSlotCreated() const { return m_localVarSlotsOffset != Js::Constants::InvalidOffset; }
  926. void EnsureLocalVarSlots();
  927. StackSym * m_nativeCodeDataSym;
  928. SList<IR::RegOpnd *> constantAddressRegOpnd;
  929. IR::Instr * lastConstantAddressRegLoadInstr;
  930. bool canHoistConstantAddressLoad;
  931. #if DBG
  932. VtableHashMap * vtableMap;
  933. #endif
  934. #if LOWER_SPLIT_INT64
  935. struct Int64SymPair {StackSym* high = nullptr; StackSym* low = nullptr;};
  936. // Key is an int64 symId, value is a pair of int32 StackSym
  937. typedef JsUtil::BaseDictionary<SymID, Int64SymPair, JitArenaAllocator> Int64SymPairMap;
  938. Int64SymPairMap* m_int64SymPairMap;
  939. #endif
  940. #ifdef RECYCLER_WRITE_BARRIER_JIT
  941. public:
  942. Lowerer* m_lowerer;
  943. #endif
  944. };
  945. class AutoCodeGenPhase
  946. {
  947. public:
  948. AutoCodeGenPhase(Func * func, Js::Phase phase) : func(func), phase(phase), dump(false), isPhaseComplete(false)
  949. {
  950. func->BeginPhase(phase);
  951. }
  952. ~AutoCodeGenPhase()
  953. {
  954. if(this->isPhaseComplete)
  955. {
  956. func->EndPhase(phase, dump);
  957. }
  958. else
  959. {
  960. //End the profiler tag
  961. func->EndProfiler(phase);
  962. }
  963. }
  964. void EndPhase(Func * func, Js::Phase phase, bool dump, bool isPhaseComplete)
  965. {
  966. Assert(this->func == func);
  967. Assert(this->phase == phase);
  968. this->dump = dump && (PHASE_DUMP(Js::SimpleJitPhase, func) || !func->IsSimpleJit());
  969. this->isPhaseComplete = isPhaseComplete;
  970. }
  971. private:
  972. Func * func;
  973. Js::Phase phase;
  974. bool dump;
  975. bool isPhaseComplete;
  976. };
  977. class AutoRestoreLegalize
  978. {
  979. public:
  980. AutoRestoreLegalize(Func * func, bool val) :
  981. m_func(func->GetTopFunc()),
  982. m_originalValue(m_func->legalizePostRegAlloc)
  983. {
  984. m_func->legalizePostRegAlloc = val;
  985. }
  986. ~AutoRestoreLegalize()
  987. {
  988. m_func->legalizePostRegAlloc = m_originalValue;
  989. }
  990. private:
  991. Func * m_func;
  992. bool m_originalValue;
  993. };
  994. #define BEGIN_CODEGEN_PHASE(func, phase) { AutoCodeGenPhase __autoCodeGen(func, phase);
  995. #define END_CODEGEN_PHASE(func, phase) __autoCodeGen.EndPhase(func, phase, true, true); }
  996. #define END_CODEGEN_PHASE_NO_DUMP(func, phase) __autoCodeGen.EndPhase(func, phase, false, true); }
  997. #ifdef PERF_HINT
  998. void WritePerfHint(PerfHints hint, Func* func, uint byteCodeOffset = Js::Constants::NoByteCodeOffset);
  999. #endif