Func.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. IR::SymOpnd *GetInlineeArgCountSlotOpnd()
  437. {
  438. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argc * MachPtr);
  439. }
  440. IR::SymOpnd *GetNextInlineeFrameArgCountSlotOpnd()
  441. {
  442. Assert(!this->m_hasInlineArgsOpt);
  443. if (this->m_hasInlineArgsOpt)
  444. {
  445. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  446. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  447. throw Js::OperationAbortedException();
  448. }
  449. return GetInlineeOpndAtOffset((Js::Constants::InlineeMetaArgCount + actualCount) * MachPtr);
  450. }
  451. IR::SymOpnd *GetInlineeFunctionObjectSlotOpnd()
  452. {
  453. Assert(!this->m_hasInlineArgsOpt);
  454. if (this->m_hasInlineArgsOpt)
  455. {
  456. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  457. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  458. throw Js::OperationAbortedException();
  459. }
  460. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_FunctionObject * MachPtr);
  461. }
  462. IR::SymOpnd *GetInlineeArgumentsObjectSlotOpnd()
  463. {
  464. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_ArgumentsObject * MachPtr);
  465. }
  466. IR::SymOpnd *GetInlineeArgvSlotOpnd()
  467. {
  468. Assert(!this->m_hasInlineArgsOpt);
  469. if (this->m_hasInlineArgsOpt)
  470. {
  471. // If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
  472. // and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
  473. throw Js::OperationAbortedException();
  474. }
  475. return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argv * MachPtr);
  476. }
  477. bool IsInlined() const
  478. {
  479. return this->parentFunc != nullptr;
  480. }
  481. bool IsInlinedConstructor() const
  482. {
  483. return this->isInlinedConstructor;
  484. }
  485. bool IsTJLoopBody()const {
  486. return this->isTJLoopBody;
  487. }
  488. Js::Var AllocateNumber(double value);
  489. ObjTypeSpecFldInfo* GetObjTypeSpecFldInfo(const uint index) const;
  490. ObjTypeSpecFldInfo* GetGlobalObjTypeSpecFldInfo(uint propertyInfoId) const;
  491. // Gets an inline cache pointer to use in jitted code. Cached data may not be stable while jitting. Does not return null.
  492. intptr_t GetRuntimeInlineCache(const uint index) const;
  493. JITTimePolymorphicInlineCache * GetRuntimePolymorphicInlineCache(const uint index) const;
  494. byte GetPolyCacheUtil(const uint index) const;
  495. byte GetPolyCacheUtilToInitialize(const uint index) const;
  496. #if LOWER_SPLIT_INT64
  497. Int64RegPair FindOrCreateInt64Pair(IR::Opnd*);
  498. void Int64SplitExtendLoopLifetime(Loop* loop);
  499. #endif
  500. #if defined(_M_ARM32_OR_ARM64)
  501. RegNum GetLocalsPointer() const;
  502. #endif
  503. #if DBG_DUMP
  504. void Dump(IRDumpFlags flags);
  505. void Dump();
  506. void DumpHeader();
  507. #endif
  508. #if DBG_DUMP || defined(ENABLE_IR_VIEWER)
  509. LPCSTR GetVtableName(INT_PTR address);
  510. #endif
  511. #if DBG_DUMP | defined(VTUNE_PROFILING)
  512. bool DoRecordNativeMap() const;
  513. #endif
  514. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  515. void DumpFullFunctionName();
  516. #endif
  517. public:
  518. JitArenaAllocator * m_alloc;
  519. const FunctionJITRuntimeInfo *const m_runtimeInfo;
  520. ThreadContextInfo * m_threadContextInfo;
  521. ScriptContextInfo * m_scriptContextInfo;
  522. JITTimeWorkItem * m_workItem;
  523. JITTimePolymorphicInlineCacheInfo *const m_polymorphicInlineCacheInfo;
  524. // This indicates how many constructor caches we inserted into the constructorCaches array, not the total size of the array.
  525. uint constructorCacheCount;
  526. // This array maps callsite ids to constructor caches. The size corresponds to the number of callsites in the function.
  527. JITTimeConstructorCache** constructorCaches;
  528. typedef JsUtil::BaseHashSet<void*, JitArenaAllocator, PowerOf2SizePolicy> TypeRefSet;
  529. TypeRefSet* pinnedTypeRefs;
  530. typedef JsUtil::BaseDictionary<intptr_t, Js::JitTypePropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> TypePropertyGuardDictionary;
  531. TypePropertyGuardDictionary* singleTypeGuards;
  532. typedef SListCounted<Js::JitEquivalentTypeGuard*> EquivalentTypeGuardList;
  533. EquivalentTypeGuardList* equivalentTypeGuards;
  534. typedef JsUtil::BaseHashSet<Js::JitIndexedPropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> IndexedPropertyGuardSet;
  535. typedef JsUtil::BaseDictionary<Js::PropertyId, IndexedPropertyGuardSet*, JitArenaAllocator, PowerOf2SizePolicy> PropertyGuardByPropertyIdMap;
  536. PropertyGuardByPropertyIdMap* propertyGuardsByPropertyId;
  537. typedef JsUtil::BaseHashSet<intptr_t, JitArenaAllocator, PowerOf2SizePolicy> CtorCacheSet;
  538. typedef JsUtil::BaseDictionary<Js::PropertyId, CtorCacheSet*, JitArenaAllocator, PowerOf2SizePolicy> CtorCachesByPropertyIdMap;
  539. CtorCachesByPropertyIdMap* ctorCachesByPropertyId;
  540. typedef JsUtil::BaseDictionary<Js::ProfileId, int32, JitArenaAllocator, PrimeSizePolicy> CallSiteToArgumentsOffsetFixupMap;
  541. CallSiteToArgumentsOffsetFixupMap* callSiteToArgumentsOffsetFixupMap;
  542. int indexedPropertyGuardCount;
  543. typedef JsUtil::BaseHashSet<Js::PropertyId, JitArenaAllocator> PropertyIdSet;
  544. PropertyIdSet* propertiesWrittenTo;
  545. PropertyIdSet lazyBailoutProperties;
  546. bool anyPropertyMayBeWrittenTo;
  547. SlotArrayCheckTable *slotArrayCheckTable;
  548. FrameDisplayCheckTable *frameDisplayCheckTable;
  549. IR::Instr * m_headInstr;
  550. IR::Instr * m_exitInstr;
  551. IR::Instr * m_tailInstr;
  552. #ifdef _M_X64
  553. int32 m_spillSize;
  554. int32 m_argsSize;
  555. int32 m_savedRegSize;
  556. PrologEncoder m_prologEncoder;
  557. #endif
  558. SymTable * m_symTable;
  559. StackSym * m_loopParamSym;
  560. StackSym * m_funcObjSym;
  561. StackSym * m_javascriptLibrarySym;
  562. StackSym * m_scriptContextSym;
  563. StackSym * m_functionBodySym;
  564. StackSym * m_localClosureSym;
  565. StackSym * m_paramClosureSym;
  566. StackSym * m_localFrameDisplaySym;
  567. StackSym * m_bailoutReturnValueSym;
  568. StackSym * m_hasBailedOutSym;
  569. uint m_forInLoopMaxDepth;
  570. uint m_forInLoopBaseDepth;
  571. int32 m_forInEnumeratorArrayOffset;
  572. int32 m_localStackHeight;
  573. uint frameSize;
  574. uint32 inlineDepth;
  575. uint32 postCallByteCodeOffset;
  576. Js::RegSlot returnValueRegSlot;
  577. Js::RegSlot firstIRTemp;
  578. Js::ArgSlot actualCount;
  579. int32 firstActualStackOffset;
  580. uint32 tryCatchNestingLevel;
  581. uint32 m_totalJumpTableSizeInBytesForSwitchStatements;
  582. #if defined(_M_ARM32_OR_ARM64)
  583. //Offset to arguments from sp + m_localStackHeight;
  584. //For non leaf functions this is (callee saved register count + LR + R11) * MachRegInt
  585. //For leaf functions this is (saved registers) * MachRegInt
  586. int32 m_ArgumentsOffset;
  587. UnwindInfoManager m_unwindInfo;
  588. IR::LabelInstr * m_epilogLabel;
  589. #endif
  590. IR::LabelInstr * m_funcStartLabel;
  591. IR::LabelInstr * m_funcEndLabel;
  592. // Keep track of the maximum number of args on the stack.
  593. uint32 m_argSlotsForFunctionsCalled;
  594. #if DBG
  595. uint32 m_callSiteCount;
  596. #endif
  597. FlowGraph * m_fg;
  598. unsigned int m_labelCount;
  599. BitVector m_regsUsed;
  600. StackSym * tempSymDouble;
  601. StackSym * tempSymBool;
  602. uint32 loopCount;
  603. Js::ProfileId callSiteIdInParentFunc;
  604. bool m_hasCalls: 1; // This is more accurate compared to m_isLeaf
  605. bool m_hasInlineArgsOpt : 1;
  606. bool m_doFastPaths : 1;
  607. bool hasBailout: 1;
  608. bool hasBailoutInEHRegion : 1;
  609. bool hasStackArgs: 1;
  610. bool hasImplicitParamLoad : 1; // True if there is a load of CallInfo, FunctionObject
  611. bool hasThrow : 1;
  612. bool hasUnoptimizedArgumentsAccess : 1; // True if there are any arguments access beyond the simple case of this.apply pattern
  613. bool m_canDoInlineArgsOpt : 1;
  614. bool applyTargetInliningRemovedArgumentsAccess : 1;
  615. bool isGetterSetter : 1;
  616. const bool isInlinedConstructor: 1;
  617. bool hasImplicitCalls: 1;
  618. bool hasTempObjectProducingInstr:1; // At least one instruction which can produce temp object
  619. bool isTJLoopBody : 1;
  620. bool isFlowGraphValid : 1;
  621. bool legalizePostRegAlloc : 1;
  622. #if DBG
  623. bool hasCalledSetDoFastPaths:1;
  624. bool isPostLower:1;
  625. bool isPostRegAlloc:1;
  626. bool isPostPeeps:1;
  627. bool isPostLayout:1;
  628. bool isPostFinalLower:1;
  629. struct InstrByteCodeRegisterUses
  630. {
  631. Js::OpCode capturingOpCode;
  632. BVSparse<JitArenaAllocator>* bv;
  633. };
  634. typedef JsUtil::BaseDictionary<uint32, InstrByteCodeRegisterUses, JitArenaAllocator> ByteCodeRegisterUses;
  635. ByteCodeRegisterUses* byteCodeRegisterUses = nullptr;
  636. BVSparse<JitArenaAllocator>* GetByteCodeOffsetUses(uint offset) const;
  637. typedef JsUtil::Stack<Js::Phase> CurrentPhasesStack;
  638. CurrentPhasesStack currentPhases;
  639. bool IsInPhase(Js::Phase tag);
  640. #endif
  641. void BeginPhase(Js::Phase tag);
  642. void EndPhase(Js::Phase tag, bool dump = true);
  643. void EndProfiler(Js::Phase tag);
  644. void BeginClone(Lowerer *lowerer, JitArenaAllocator *alloc);
  645. void EndClone();
  646. Cloner * GetCloner() const { return GetTopFunc()->m_cloner; }
  647. InstrMap * GetCloneMap() const { return GetTopFunc()->m_cloneMap; }
  648. void ClearCloneMap() { Assert(this->IsTopFunc()); this->m_cloneMap = nullptr; }
  649. bool HasByteCodeOffset() const { return !this->GetTopFunc()->hasInstrNumber; }
  650. bool DoMaintainByteCodeOffset() const { return this->HasByteCodeOffset() && this->GetTopFunc()->maintainByteCodeOffset; }
  651. void StopMaintainByteCodeOffset() { this->GetTopFunc()->maintainByteCodeOffset = false; }
  652. Func * GetParentFunc() const { return parentFunc; }
  653. uint GetMaxInlineeArgOutSize() const { return this->maxInlineeArgOutSize; }
  654. void UpdateMaxInlineeArgOutSize(uint inlineeArgOutSize);
  655. #if DBG_DUMP
  656. ptrdiff_t m_codeSize;
  657. #endif
  658. bool GetHasCalls() const { return this->m_hasCalls; }
  659. void SetHasCallsOnSelfAndParents()
  660. {
  661. Func *curFunc = this;
  662. while (curFunc)
  663. {
  664. curFunc->m_hasCalls = true;
  665. curFunc = curFunc->GetParentFunc();
  666. }
  667. }
  668. void SetHasInstrNumber(bool has) { this->GetTopFunc()->hasInstrNumber = has; }
  669. bool HasInstrNumber() const { return this->GetTopFunc()->hasInstrNumber; }
  670. bool HasInlinee() const { Assert(this->IsTopFunc()); return this->hasInlinee; }
  671. void SetHasInlinee() { Assert(this->IsTopFunc()); this->hasInlinee = true; }
  672. bool GetThisOrParentInlinerHasArguments() const { return thisOrParentInlinerHasArguments; }
  673. bool GetHasStackArgs() const
  674. {
  675. return this->hasStackArgs && !IsStackArgOptDisabled() && !PHASE_OFF1(Js::StackArgOptPhase);
  676. }
  677. void SetHasStackArgs(bool has) { this->hasStackArgs = has;}
  678. bool IsStackArgsEnabled()
  679. {
  680. Func* curFunc = this;
  681. bool isStackArgsEnabled = GetJITFunctionBody()->UsesArgumentsObject() && curFunc->GetHasStackArgs();
  682. Func * topFunc = curFunc->GetTopFunc();
  683. if (topFunc != nullptr)
  684. {
  685. isStackArgsEnabled = isStackArgsEnabled && topFunc->GetHasStackArgs();
  686. }
  687. return isStackArgsEnabled;
  688. }
  689. bool GetHasImplicitParamLoad() const { return this->hasImplicitParamLoad; }
  690. void SetHasImplicitParamLoad() { this->hasImplicitParamLoad = true; }
  691. bool GetHasThrow() const { return this->hasThrow; }
  692. void SetHasThrow() { this->hasThrow = true; }
  693. bool GetHasUnoptimizedArgumentsAccess() const { return this->hasUnoptimizedArgumentsAccess; }
  694. void SetHasUnoptimizedArgumentsAccess(bool args)
  695. {
  696. // Once set to 'true' make sure this does not become false
  697. if (!this->hasUnoptimizedArgumentsAccess)
  698. {
  699. this->hasUnoptimizedArgumentsAccess = args;
  700. }
  701. if (args)
  702. {
  703. Func *curFunc = this->GetParentFunc();
  704. while (curFunc)
  705. {
  706. curFunc->hasUnoptimizedArgumentsAccess = args;
  707. curFunc = curFunc->GetParentFunc();
  708. }
  709. }
  710. }
  711. void DisableCanDoInlineArgOpt()
  712. {
  713. Func* curFunc = this;
  714. while (curFunc)
  715. {
  716. curFunc->m_canDoInlineArgsOpt = false;
  717. curFunc->m_hasInlineArgsOpt = false;
  718. curFunc = curFunc->GetParentFunc();
  719. }
  720. }
  721. bool ShouldLegalizePostRegAlloc() const { return topFunc->legalizePostRegAlloc; }
  722. bool GetApplyTargetInliningRemovedArgumentsAccess() const { return this->applyTargetInliningRemovedArgumentsAccess;}
  723. void SetApplyTargetInliningRemovedArgumentsAccess() { this->applyTargetInliningRemovedArgumentsAccess = true;}
  724. bool GetHasMarkTempObjects() const { return this->hasMarkTempObjects; }
  725. void SetHasMarkTempObjects() { this->hasMarkTempObjects = true; }
  726. bool GetHasNonSimpleParams() const { return this->hasNonSimpleParams; }
  727. void SetHasNonSimpleParams() { this->hasNonSimpleParams = true; }
  728. bool GetHasImplicitCalls() const { return this->hasImplicitCalls;}
  729. void SetHasImplicitCalls(bool has) { this->hasImplicitCalls = has;}
  730. void SetHasImplicitCallsOnSelfAndParents()
  731. {
  732. this->SetHasImplicitCalls(true);
  733. Func *curFunc = this->GetParentFunc();
  734. while (curFunc && !curFunc->IsTopFunc())
  735. {
  736. curFunc->SetHasImplicitCalls(true);
  737. curFunc = curFunc->GetParentFunc();
  738. }
  739. }
  740. bool GetHasTempObjectProducingInstr() const { return this->hasTempObjectProducingInstr; }
  741. void SetHasTempObjectProducingInstr(bool has) { this->hasTempObjectProducingInstr = has; }
  742. const JITTimeProfileInfo * GetReadOnlyProfileInfo() const { return GetJITFunctionBody()->GetReadOnlyProfileInfo(); }
  743. bool HasProfileInfo() const { return GetJITFunctionBody()->HasProfileInfo(); }
  744. bool HasArrayInfo()
  745. {
  746. const auto top = this->GetTopFunc();
  747. return this->HasProfileInfo() && this->GetWeakFuncRef() && !(top->HasTry() && !top->DoOptimizeTry()) &&
  748. top->DoGlobOpt() && !PHASE_OFF(Js::LoopFastPathPhase, top);
  749. }
  750. static Js::OpCode GetLoadOpForType(IRType type)
  751. {
  752. if (type == TyVar || IRType_IsFloat(type))
  753. {
  754. return Js::OpCode::Ld_A;
  755. }
  756. else
  757. {
  758. Assert(IRType_IsNativeInt(type));
  759. return Js::OpCode::Ld_I4;
  760. }
  761. }
  762. static Js::BuiltinFunction GetBuiltInIndex(IR::Opnd* opnd)
  763. {
  764. Assert(opnd);
  765. Js::BuiltinFunction index;
  766. if (opnd->IsRegOpnd())
  767. {
  768. index = opnd->AsRegOpnd()->m_sym->m_builtInIndex;
  769. }
  770. else if (opnd->IsSymOpnd())
  771. {
  772. PropertySym *propertySym = opnd->AsSymOpnd()->m_sym->AsPropertySym();
  773. index = Js::JavascriptLibrary::GetBuiltinFunctionForPropId(propertySym->m_propertyId);
  774. }
  775. else
  776. {
  777. index = Js::BuiltinFunction::None;
  778. }
  779. return index;
  780. }
  781. static bool IsBuiltInInlinedInLowerer(IR::Opnd* opnd)
  782. {
  783. Assert(opnd);
  784. Js::BuiltinFunction index = Func::GetBuiltInIndex(opnd);
  785. switch (index)
  786. {
  787. case Js::BuiltinFunction::JavascriptString_CharAt:
  788. case Js::BuiltinFunction::JavascriptString_CharCodeAt:
  789. case Js::BuiltinFunction::JavascriptString_CodePointAt:
  790. case Js::BuiltinFunction::Math_Abs:
  791. case Js::BuiltinFunction::JavascriptArray_Push:
  792. case Js::BuiltinFunction::JavascriptString_Replace:
  793. case Js::BuiltinFunction::JavascriptObject_HasOwnProperty:
  794. case Js::BuiltinFunction::JavascriptArray_IsArray:
  795. return true;
  796. default:
  797. return false;
  798. }
  799. }
  800. void AddYieldOffsetResumeLabel(uint32 offset, IR::LabelInstr* label)
  801. {
  802. m_yieldOffsetResumeLabelList->Add(YieldOffsetResumeLabel(offset, label));
  803. }
  804. template <typename Fn>
  805. void MapYieldOffsetResumeLabels(Fn fn)
  806. {
  807. m_yieldOffsetResumeLabelList->Map(fn);
  808. }
  809. template <typename Fn>
  810. bool MapUntilYieldOffsetResumeLabels(Fn fn)
  811. {
  812. return m_yieldOffsetResumeLabelList->MapUntil(fn);
  813. }
  814. void RemoveYieldOffsetResumeLabel(const YieldOffsetResumeLabel& yorl)
  815. {
  816. m_yieldOffsetResumeLabelList->Remove(yorl);
  817. }
  818. void RemoveDeadYieldOffsetResumeLabel(IR::LabelInstr* label)
  819. {
  820. uint32 offset;
  821. bool found = m_yieldOffsetResumeLabelList->MapUntil([&offset, &label](int i, YieldOffsetResumeLabel& yorl)
  822. {
  823. if (yorl.Second() == label)
  824. {
  825. offset = yorl.First();
  826. return true;
  827. }
  828. return false;
  829. });
  830. Assert(found);
  831. RemoveYieldOffsetResumeLabel(YieldOffsetResumeLabel(offset, label));
  832. AddYieldOffsetResumeLabel(offset, nullptr);
  833. }
  834. IR::Instr * GetFunctionEntryInsertionPoint();
  835. IR::IndirOpnd * GetConstantAddressIndirOpnd(intptr_t address, IR::Opnd *largeConstOpnd, IR::AddrOpndKind kind, IRType type, Js::OpCode loadOpCode);
  836. void MarkConstantAddressSyms(BVSparse<JitArenaAllocator> * bv);
  837. void DisableConstandAddressLoadHoist() { canHoistConstantAddressLoad = false; }
  838. void AddSlotArrayCheck(IR::SymOpnd *fieldOpnd);
  839. void AddFrameDisplayCheck(IR::SymOpnd *fieldOpnd, uint32 slotId = (uint32)-1);
  840. void EnsureStackArgWithFormalsTracker();
  841. BOOL IsFormalsArraySym(SymID symId);
  842. void TrackFormalsArraySym(SymID symId);
  843. void TrackStackSymForFormalIndex(Js::ArgSlot formalsIndex, StackSym * sym);
  844. StackSym* GetStackSymForFormal(Js::ArgSlot formalsIndex);
  845. bool HasStackSymForFormal(Js::ArgSlot formalsIndex);
  846. void SetScopeObjSym(StackSym * sym);
  847. StackSym * GetScopeObjSym();
  848. bool IsTrackCompoundedIntOverflowDisabled() const;
  849. bool IsArrayCheckHoistDisabled() const;
  850. bool IsStackArgOptDisabled() const;
  851. bool IsSwitchOptDisabled() const;
  852. bool IsAggressiveIntTypeSpecDisabled() const;
  853. #if DBG
  854. bool allowRemoveBailOutArgInstr;
  855. #endif
  856. #if defined(_M_ARM32_OR_ARM64)
  857. int32 GetInlineeArgumentStackSize()
  858. {
  859. int32 size = this->GetMaxInlineeArgOutSize();
  860. if (size)
  861. {
  862. return size + MachPtr; // +1 for the dedicated zero out argc slot
  863. }
  864. return 0;
  865. }
  866. #endif
  867. public:
  868. BVSparse<JitArenaAllocator> * argObjSyms;
  869. BVSparse<JitArenaAllocator> * m_nonTempLocalVars; // Only populated in debug mode as part of IRBuilder. Used in GlobOpt and BackwardPass.
  870. InlineeFrameInfo* frameInfo;
  871. Js::ArgSlot argInsCount; // This count doesn't include the ArgIn instr for "this".
  872. uint32 m_inlineeId;
  873. IR::LabelInstr * m_bailOutNoSaveLabel;
  874. StackSym * GetNativeCodeDataSym() const;
  875. void SetNativeCodeDataSym(StackSym * sym);
  876. private:
  877. Js::EntryPointInfo* m_entryPointInfo; // for in-proc JIT only
  878. JITOutput m_output;
  879. #ifdef PROFILE_EXEC
  880. Js::ScriptContextProfiler *const m_codeGenProfiler;
  881. #endif
  882. Func * const topFunc;
  883. Func * const parentFunc;
  884. StackSym * m_inlineeFrameStartSym;
  885. uint maxInlineeArgOutSize;
  886. const bool m_isBackgroundJIT;
  887. bool hasInstrNumber;
  888. bool maintainByteCodeOffset;
  889. bool hasInlinee;
  890. bool thisOrParentInlinerHasArguments;
  891. bool useRuntimeStats;
  892. bool stackNestedFunc;
  893. bool stackClosure;
  894. bool hasAnyStackNestedFunc;
  895. bool hasMarkTempObjects;
  896. bool hasNonSimpleParams;
  897. Cloner * m_cloner;
  898. InstrMap * m_cloneMap;
  899. NativeCodeData::Allocator nativeCodeDataAllocator;
  900. NativeCodeData::Allocator transferDataAllocator;
  901. #if !FLOATVAR
  902. CodeGenNumberAllocator * numberAllocator;
  903. #endif
  904. int32 m_localVarSlotsOffset;
  905. int32 m_hasLocalVarChangedOffset; // Offset on stack of 1 byte which indicates if any local var has changed.
  906. void * const m_codeGenAllocators;
  907. YieldOffsetResumeLabelList * m_yieldOffsetResumeLabelList;
  908. StackArgWithFormalsTracker * stackArgWithFormalsTracker;
  909. ObjTypeSpecFldInfo ** m_globalObjTypeSpecFldInfoArray;
  910. StackSym *CreateInlineeStackSym();
  911. IR::SymOpnd *GetInlineeOpndAtOffset(int32 offset);
  912. bool HasLocalVarSlotCreated() const { return m_localVarSlotsOffset != Js::Constants::InvalidOffset; }
  913. void EnsureLocalVarSlots();
  914. StackSym * m_nativeCodeDataSym;
  915. SList<IR::RegOpnd *> constantAddressRegOpnd;
  916. IR::Instr * lastConstantAddressRegLoadInstr;
  917. bool canHoistConstantAddressLoad;
  918. #if DBG
  919. VtableHashMap * vtableMap;
  920. #endif
  921. #if LOWER_SPLIT_INT64
  922. struct Int64SymPair {StackSym* high = nullptr; StackSym* low = nullptr;};
  923. // Key is an int64 symId, value is a pair of int32 StackSym
  924. typedef JsUtil::BaseDictionary<SymID, Int64SymPair, JitArenaAllocator> Int64SymPairMap;
  925. Int64SymPairMap* m_int64SymPairMap;
  926. #endif
  927. #ifdef RECYCLER_WRITE_BARRIER_JIT
  928. public:
  929. Lowerer* m_lowerer;
  930. #endif
  931. };
  932. class AutoCodeGenPhase
  933. {
  934. public:
  935. AutoCodeGenPhase(Func * func, Js::Phase phase) : func(func), phase(phase), dump(false), isPhaseComplete(false)
  936. {
  937. func->BeginPhase(phase);
  938. }
  939. ~AutoCodeGenPhase()
  940. {
  941. if(this->isPhaseComplete)
  942. {
  943. func->EndPhase(phase, dump);
  944. }
  945. else
  946. {
  947. //End the profiler tag
  948. func->EndProfiler(phase);
  949. }
  950. }
  951. void EndPhase(Func * func, Js::Phase phase, bool dump, bool isPhaseComplete)
  952. {
  953. Assert(this->func == func);
  954. Assert(this->phase == phase);
  955. this->dump = dump && (PHASE_DUMP(Js::SimpleJitPhase, func) || !func->IsSimpleJit());
  956. this->isPhaseComplete = isPhaseComplete;
  957. }
  958. private:
  959. Func * func;
  960. Js::Phase phase;
  961. bool dump;
  962. bool isPhaseComplete;
  963. };
  964. class AutoRestoreLegalize
  965. {
  966. public:
  967. AutoRestoreLegalize(Func * func, bool val) :
  968. m_func(func->GetTopFunc()),
  969. m_originalValue(m_func->legalizePostRegAlloc)
  970. {
  971. m_func->legalizePostRegAlloc = val;
  972. }
  973. ~AutoRestoreLegalize()
  974. {
  975. m_func->legalizePostRegAlloc = m_originalValue;
  976. }
  977. private:
  978. Func * m_func;
  979. bool m_originalValue;
  980. };
  981. #define BEGIN_CODEGEN_PHASE(func, phase) { AutoCodeGenPhase __autoCodeGen(func, phase);
  982. #define END_CODEGEN_PHASE(func, phase) __autoCodeGen.EndPhase(func, phase, true, true); }
  983. #define END_CODEGEN_PHASE_NO_DUMP(func, phase) __autoCodeGen.EndPhase(func, phase, false, true); }
  984. #ifdef PERF_HINT
  985. void WritePerfHint(PerfHints hint, Func* func, uint byteCodeOffset = Js::Constants::NoByteCodeOffset);
  986. #endif