Func.h 40 KB

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