Func.h 39 KB

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