InliningDecider.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. #include "Backend.h"
  6. InliningDecider::InliningDecider(Js::FunctionBody *const topFunc, bool isLoopBody, bool isInDebugMode, const ExecutionMode jitMode)
  7. : topFunc(topFunc), isLoopBody(isLoopBody), isInDebugMode(isInDebugMode), jitMode(jitMode), bytecodeInlinedCount(0), numberOfInlineesWithLoop(0), threshold(topFunc->GetByteCodeWithoutLDACount(), isLoopBody, topFunc->GetIsAsmjsMode())
  8. {
  9. Assert(topFunc);
  10. }
  11. InliningDecider::~InliningDecider()
  12. {
  13. INLINE_FLUSH();
  14. }
  15. bool InliningDecider::InlineIntoTopFunc() const
  16. {
  17. if (this->jitMode == ExecutionMode::SimpleJit ||
  18. PHASE_OFF(Js::InlinePhase, this->topFunc) ||
  19. PHASE_OFF(Js::GlobOptPhase, this->topFunc))
  20. {
  21. return false;
  22. }
  23. #ifdef _M_IX86
  24. if (this->topFunc->GetHasTry())
  25. {
  26. #if defined(DBG_DUMP) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  27. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  28. #endif
  29. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Has try\tCaller: %s (%s)\n"), this->topFunc->GetDisplayName(),
  30. this->topFunc->GetDebugNumberSet(debugStringBuffer));
  31. // Glob opt doesn't run on function with try, so we can't generate bailout for it
  32. return false;
  33. }
  34. #endif
  35. return InlineIntoInliner(topFunc);
  36. }
  37. bool InliningDecider::InlineIntoInliner(Js::FunctionBody *const inliner) const
  38. {
  39. Assert(inliner);
  40. Assert(this->jitMode == ExecutionMode::FullJit);
  41. #if defined(DBG_DUMP) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  42. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  43. #endif
  44. if (PHASE_OFF(Js::InlinePhase, inliner) ||
  45. PHASE_OFF(Js::GlobOptPhase, inliner))
  46. {
  47. return false;
  48. }
  49. if (!inliner->HasDynamicProfileInfo())
  50. {
  51. INLINE_TESTTRACE(_u("INLINING: Skip Inline: No dynamic profile info\tCaller: %s (%s)\n"), inliner->GetDisplayName(),
  52. inliner->GetDebugNumberSet(debugStringBuffer));
  53. return false;
  54. }
  55. if (inliner->GetProfiledCallSiteCount() == 0 && !inliner->GetAnyDynamicProfileInfo()->HasLdFldCallSiteInfo())
  56. {
  57. INLINE_TESTTRACE_VERBOSE(_u("INLINING: Skip Inline: Leaf function\tCaller: %s (%s)\n"), inliner->GetDisplayName(),
  58. inliner->GetDebugNumberSet(debugStringBuffer));
  59. // Nothing to do
  60. return false;
  61. }
  62. if (!inliner->GetAnyDynamicProfileInfo()->HasCallSiteInfo(inliner))
  63. {
  64. INLINE_TESTTRACE(_u("INLINING: Skip Inline: No call site info\tCaller: %s (#%d)\n"), inliner->GetDisplayName(),
  65. inliner->GetDebugNumberSet(debugStringBuffer));
  66. return false;
  67. }
  68. return true;
  69. }
  70. Js::FunctionInfo *InliningDecider::GetCallSiteFuncInfo(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId, bool* isConstructorCall, bool* isPolymorphicCall)
  71. {
  72. Assert(inliner);
  73. Assert(profiledCallSiteId < inliner->GetProfiledCallSiteCount());
  74. const auto profileData = inliner->GetAnyDynamicProfileInfo();
  75. Assert(profileData);
  76. return profileData->GetCallSiteInfo(inliner, profiledCallSiteId, isConstructorCall, isPolymorphicCall);
  77. }
  78. Js::FunctionInfo * InliningDecider::GetCallSiteCallbackInfo(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId)
  79. {
  80. Assert(inliner != nullptr);
  81. Assert(profiledCallSiteId < inliner->GetProfiledCallSiteCount());
  82. Js::DynamicProfileInfo * profileData = inliner->GetAnyDynamicProfileInfo();
  83. Assert(profileData != nullptr);
  84. return profileData->GetCallbackInfo(inliner, profiledCallSiteId);
  85. }
  86. uint16 InliningDecider::GetConstantArgInfo(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId)
  87. {
  88. Assert(inliner);
  89. Assert(profiledCallSiteId < inliner->GetProfiledCallSiteCount());
  90. const auto profileData = inliner->GetAnyDynamicProfileInfo();
  91. Assert(profileData);
  92. return profileData->GetConstantArgInfo(profiledCallSiteId);
  93. }
  94. bool InliningDecider::HasCallSiteInfo(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId)
  95. {
  96. Assert(inliner);
  97. Assert(profiledCallSiteId < inliner->GetProfiledCallSiteCount());
  98. const auto profileData = inliner->GetAnyDynamicProfileInfo();
  99. Assert(profileData);
  100. return profileData->HasCallSiteInfo(inliner, profiledCallSiteId);
  101. }
  102. Js::FunctionInfo *InliningDecider::InlineCallSite(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId, uint recursiveInlineDepth)
  103. {
  104. bool isConstructorCall;
  105. bool isPolymorphicCall;
  106. Js::FunctionInfo *functionInfo = GetCallSiteFuncInfo(inliner, profiledCallSiteId, &isConstructorCall, &isPolymorphicCall);
  107. if (functionInfo)
  108. {
  109. return Inline(inliner, functionInfo, isConstructorCall, false, false, GetConstantArgInfo(inliner, profiledCallSiteId), profiledCallSiteId, recursiveInlineDepth, true);
  110. }
  111. return nullptr;
  112. }
  113. Js::FunctionInfo * InliningDecider::InlineCallback(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId, uint recursiveInlineDepth)
  114. {
  115. Js::FunctionInfo * functionInfo = GetCallSiteCallbackInfo(inliner, profiledCallSiteId);
  116. if (functionInfo)
  117. {
  118. return Inline(inliner, functionInfo, false, false, true, GetConstantArgInfo(inliner, profiledCallSiteId), profiledCallSiteId, recursiveInlineDepth, true);
  119. }
  120. return nullptr;
  121. }
  122. uint InliningDecider::InlinePolymorphicCallSite(Js::FunctionBody *const inliner, const Js::ProfileId profiledCallSiteId,
  123. Js::FunctionBody** functionBodyArray, uint functionBodyArrayLength, bool* canInlineArray, uint recursiveInlineDepth)
  124. {
  125. Assert(inliner);
  126. Assert(profiledCallSiteId < inliner->GetProfiledCallSiteCount());
  127. Assert(functionBodyArray);
  128. const auto profileData = inliner->GetAnyDynamicProfileInfo();
  129. Assert(profileData);
  130. bool isConstructorCall;
  131. if (!profileData->GetPolymorphicCallSiteInfo(inliner, profiledCallSiteId, &isConstructorCall, functionBodyArray, functionBodyArrayLength))
  132. {
  133. return 0;
  134. }
  135. uint inlineeCount = 0;
  136. uint actualInlineeCount = 0;
  137. for (inlineeCount = 0; inlineeCount < functionBodyArrayLength; inlineeCount++)
  138. {
  139. if (!functionBodyArray[inlineeCount])
  140. {
  141. AssertMsg(inlineeCount >= 2, "There are at least two polymorphic call site");
  142. break;
  143. }
  144. if (Inline(inliner, functionBodyArray[inlineeCount]->GetFunctionInfo(), isConstructorCall, true /*isPolymorphicCall*/, false /*isCallback*/, 0, profiledCallSiteId, recursiveInlineDepth, false))
  145. {
  146. canInlineArray[inlineeCount] = true;
  147. actualInlineeCount++;
  148. }
  149. }
  150. if (inlineeCount != actualInlineeCount)
  151. {
  152. // We generate polymorphic dispatch and call even if there are no inlinees as it's seen to provide a perf boost
  153. // Skip loop bodies for now as we do not handle re-jit scenarios for the bailouts from them
  154. if (!PHASE_OFF(Js::PartialPolymorphicInlinePhase, inliner) && !this->isLoopBody)
  155. {
  156. #if defined(DBG_DUMP) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  157. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  158. char16 debugStringBuffer2[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  159. #endif
  160. INLINE_TESTTRACE(_u("Partial inlining of polymorphic call: %s (%s)\tCaller: %s (%s)\n"),
  161. functionBodyArray[inlineeCount - 1]->GetDisplayName(), functionBodyArray[inlineeCount - 1]->GetDebugNumberSet(debugStringBuffer),
  162. inliner->GetDisplayName(),
  163. inliner->GetDebugNumberSet(debugStringBuffer2));
  164. }
  165. else
  166. {
  167. return 0;
  168. }
  169. }
  170. return inlineeCount;
  171. }
  172. Js::FunctionInfo *InliningDecider::Inline(Js::FunctionBody *const inliner,
  173. Js::FunctionInfo* functionInfo,
  174. bool isConstructorCall,
  175. bool isPolymorphicCall,
  176. bool isCallback,
  177. uint16 constantArgInfo,
  178. Js::ProfileId callSiteId,
  179. uint recursiveInlineDepth,
  180. bool allowRecursiveInlining)
  181. {
  182. #if defined(DBG_DUMP) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  183. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  184. char16 debugStringBuffer2[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  185. #endif
  186. Js::FunctionProxy * proxy = functionInfo->GetFunctionProxy();
  187. if (proxy && proxy->IsFunctionBody())
  188. {
  189. if (isLoopBody && PHASE_OFF(Js::InlineInJitLoopBodyPhase, this->topFunc))
  190. {
  191. INLINE_TESTTRACE_VERBOSE(_u("INLINING: Skip Inline: Jit loop body: %s (%s)\n"), this->topFunc->GetDisplayName(),
  192. this->topFunc->GetDebugNumberSet(debugStringBuffer));
  193. return nullptr;
  194. }
  195. // Note: disable inline for debugger, as we can't bailout at return from function.
  196. // Alternative can be generate this bailout as part of inline, which can be done later as perf improvement.
  197. const auto inlinee = proxy->GetFunctionBody();
  198. Assert(this->jitMode == ExecutionMode::FullJit);
  199. if (PHASE_OFF(Js::InlinePhase, inlinee) ||
  200. PHASE_OFF(Js::GlobOptPhase, inlinee) ||
  201. !ContinueInliningUserDefinedFunctions(this->bytecodeInlinedCount) ||
  202. this->isInDebugMode)
  203. {
  204. return nullptr;
  205. }
  206. if (functionInfo->IsDeferred() || inlinee->GetByteCode() == nullptr)
  207. {
  208. // DeferredParse...
  209. INLINE_TESTTRACE(_u("INLINING: Skip Inline: No bytecode\tInlinee: %s (%s)\tCaller: %s (%s)\n"),
  210. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inliner->GetDisplayName(),
  211. inliner->GetDebugNumberSet(debugStringBuffer2));
  212. return nullptr;
  213. }
  214. #ifdef _M_IX86
  215. if (inlinee->GetHasTry())
  216. {
  217. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Has try\tInlinee: %s (%s)\tCaller: %s (%s)\n"),
  218. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inliner->GetDisplayName(),
  219. inliner->GetDebugNumberSet(debugStringBuffer2));
  220. return nullptr;
  221. }
  222. #endif
  223. // This is a hard limit as the argOuts array is statically sized.
  224. if (inlinee->GetInParamsCount() > Js::InlineeCallInfo::MaxInlineeArgoutCount)
  225. {
  226. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Params count greater then MaxInlineeArgoutCount\tInlinee: %s (%s)\tParamcount: %d\tMaxInlineeArgoutCount: %d\tCaller: %s (%s)\n"),
  227. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inlinee->GetInParamsCount(), Js::InlineeCallInfo::MaxInlineeArgoutCount,
  228. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2));
  229. return nullptr;
  230. }
  231. // Wasm functions can have no params
  232. if (inlinee->GetInParamsCount() == 0 && !inlinee->GetIsAsmjsMode())
  233. {
  234. // Inline candidate has no params, not even a this pointer. This can only be the global function,
  235. // which we shouldn't inline.
  236. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Params count is zero!\tInlinee: %s (%s)\tParamcount: %d\tCaller: %s (%s)\n"),
  237. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inlinee->GetInParamsCount(),
  238. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2));
  239. return nullptr;
  240. }
  241. if (inlinee->GetDontInline())
  242. {
  243. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Do not inline\tInlinee: %s (%s)\tCaller: %s (%s)\n"),
  244. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inliner->GetDisplayName(),
  245. inliner->GetDebugNumberSet(debugStringBuffer2));
  246. return nullptr;
  247. }
  248. // Do not inline a call to a class constructor if it isn't part of a new expression since the call will throw a TypeError anyway.
  249. if (inlinee->IsClassConstructor() && !isConstructorCall)
  250. {
  251. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Class constructor without new keyword\tInlinee: %s (%s)\tCaller: %s (%s)\n"),
  252. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inliner->GetDisplayName(),
  253. inliner->GetDebugNumberSet(debugStringBuffer2));
  254. return nullptr;
  255. }
  256. if (!DeciderInlineIntoInliner(inlinee, inliner, isConstructorCall, isPolymorphicCall, constantArgInfo, recursiveInlineDepth, allowRecursiveInlining))
  257. {
  258. return nullptr;
  259. }
  260. #if defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  261. TraceInlining(inliner, inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inlinee->GetByteCodeCount(), this->topFunc, this->bytecodeInlinedCount, inlinee, callSiteId, this->isLoopBody, isCallback);
  262. #endif
  263. this->bytecodeInlinedCount += inlinee->GetByteCodeCount();
  264. return inlinee->GetFunctionInfo();
  265. }
  266. Js::OpCode builtInInlineCandidateOpCode;
  267. ValueType builtInReturnType;
  268. GetBuiltInInfo(functionInfo, &builtInInlineCandidateOpCode, &builtInReturnType);
  269. if(builtInInlineCandidateOpCode == 0 && builtInReturnType.IsUninitialized())
  270. {
  271. return nullptr;
  272. }
  273. Assert(this->jitMode == ExecutionMode::FullJit);
  274. if (builtInInlineCandidateOpCode != 0 &&
  275. (
  276. PHASE_OFF(Js::InlinePhase, inliner) ||
  277. PHASE_OFF(Js::GlobOptPhase, inliner) ||
  278. isConstructorCall
  279. ))
  280. {
  281. return nullptr;
  282. }
  283. // Note: for built-ins at this time we don't have enough data (the instr) to decide whether it's going to be inlined.
  284. return functionInfo;
  285. }
  286. // TODO OOP JIT: add FunctionInfo interface so we can combine these?
  287. /* static */
  288. bool InliningDecider::GetBuiltInInfo(
  289. const FunctionJITTimeInfo *const funcInfo,
  290. Js::OpCode *const inlineCandidateOpCode,
  291. ValueType *const returnType
  292. )
  293. {
  294. Assert(funcInfo);
  295. Assert(inlineCandidateOpCode);
  296. Assert(returnType);
  297. *inlineCandidateOpCode = (Js::OpCode)0;
  298. *returnType = ValueType::Uninitialized;
  299. if (funcInfo->HasBody())
  300. {
  301. return false;
  302. }
  303. return InliningDecider::GetBuiltInInfoCommon(
  304. funcInfo->GetLocalFunctionId(),
  305. inlineCandidateOpCode,
  306. returnType);
  307. }
  308. /* static */
  309. bool InliningDecider::GetBuiltInInfo(
  310. Js::FunctionInfo *const funcInfo,
  311. Js::OpCode *const inlineCandidateOpCode,
  312. ValueType *const returnType
  313. )
  314. {
  315. Assert(funcInfo);
  316. Assert(inlineCandidateOpCode);
  317. Assert(returnType);
  318. *inlineCandidateOpCode = (Js::OpCode)0;
  319. *returnType = ValueType::Uninitialized;
  320. if (funcInfo->HasBody())
  321. {
  322. return false;
  323. }
  324. return InliningDecider::GetBuiltInInfoCommon(
  325. funcInfo->GetLocalFunctionId(),
  326. inlineCandidateOpCode,
  327. returnType);
  328. }
  329. bool InliningDecider::GetBuiltInInfoCommon(
  330. uint localFuncId,
  331. Js::OpCode *const inlineCandidateOpCode,
  332. ValueType *const returnType
  333. )
  334. {
  335. // TODO: consider adding another column to JavascriptBuiltInFunctionList.h/LibraryFunction.h
  336. // and getting helper method from there instead of multiple switch labels. And for return value types too.
  337. switch (localFuncId)
  338. {
  339. case Js::JavascriptBuiltInFunction::Math_Abs:
  340. *inlineCandidateOpCode = Js::OpCode::InlineMathAbs;
  341. break;
  342. case Js::JavascriptBuiltInFunction::Math_Acos:
  343. *inlineCandidateOpCode = Js::OpCode::InlineMathAcos;
  344. break;
  345. case Js::JavascriptBuiltInFunction::Math_Asin:
  346. *inlineCandidateOpCode = Js::OpCode::InlineMathAsin;
  347. break;
  348. case Js::JavascriptBuiltInFunction::Math_Atan:
  349. *inlineCandidateOpCode = Js::OpCode::InlineMathAtan;
  350. break;
  351. case Js::JavascriptBuiltInFunction::Math_Atan2:
  352. *inlineCandidateOpCode = Js::OpCode::InlineMathAtan2;
  353. break;
  354. case Js::JavascriptBuiltInFunction::Math_Cos:
  355. *inlineCandidateOpCode = Js::OpCode::InlineMathCos;
  356. break;
  357. case Js::JavascriptBuiltInFunction::Math_Exp:
  358. *inlineCandidateOpCode = Js::OpCode::InlineMathExp;
  359. break;
  360. case Js::JavascriptBuiltInFunction::Math_Log:
  361. *inlineCandidateOpCode = Js::OpCode::InlineMathLog;
  362. break;
  363. case Js::JavascriptBuiltInFunction::Math_Pow:
  364. *inlineCandidateOpCode = Js::OpCode::InlineMathPow;
  365. break;
  366. case Js::JavascriptBuiltInFunction::Math_Sin:
  367. *inlineCandidateOpCode = Js::OpCode::InlineMathSin;
  368. break;
  369. case Js::JavascriptBuiltInFunction::Math_Sqrt:
  370. *inlineCandidateOpCode = Js::OpCode::InlineMathSqrt;
  371. break;
  372. case Js::JavascriptBuiltInFunction::Math_Tan:
  373. *inlineCandidateOpCode = Js::OpCode::InlineMathTan;
  374. break;
  375. case Js::JavascriptBuiltInFunction::Math_Floor:
  376. *inlineCandidateOpCode = Js::OpCode::InlineMathFloor;
  377. break;
  378. case Js::JavascriptBuiltInFunction::Math_Ceil:
  379. *inlineCandidateOpCode = Js::OpCode::InlineMathCeil;
  380. break;
  381. case Js::JavascriptBuiltInFunction::Math_Round:
  382. *inlineCandidateOpCode = Js::OpCode::InlineMathRound;
  383. break;
  384. case Js::JavascriptBuiltInFunction::Math_Min:
  385. *inlineCandidateOpCode = Js::OpCode::InlineMathMin;
  386. break;
  387. case Js::JavascriptBuiltInFunction::Math_Max:
  388. *inlineCandidateOpCode = Js::OpCode::InlineMathMax;
  389. break;
  390. case Js::JavascriptBuiltInFunction::Math_Imul:
  391. *inlineCandidateOpCode = Js::OpCode::InlineMathImul;
  392. break;
  393. case Js::JavascriptBuiltInFunction::Math_Clz32:
  394. *inlineCandidateOpCode = Js::OpCode::InlineMathClz;
  395. break;
  396. case Js::JavascriptBuiltInFunction::Math_Random:
  397. *inlineCandidateOpCode = Js::OpCode::InlineMathRandom;
  398. break;
  399. case Js::JavascriptBuiltInFunction::Math_Fround:
  400. *inlineCandidateOpCode = Js::OpCode::InlineMathFround;
  401. *returnType = ValueType::Float;
  402. break;
  403. case Js::JavascriptBuiltInFunction::JavascriptArray_Push:
  404. *inlineCandidateOpCode = Js::OpCode::InlineArrayPush;
  405. break;
  406. case Js::JavascriptBuiltInFunction::JavascriptArray_Pop:
  407. *inlineCandidateOpCode = Js::OpCode::InlineArrayPop;
  408. break;
  409. case Js::JavascriptBuiltInFunction::JavascriptArray_Concat:
  410. case Js::JavascriptBuiltInFunction::JavascriptArray_Reverse:
  411. case Js::JavascriptBuiltInFunction::JavascriptArray_Shift:
  412. case Js::JavascriptBuiltInFunction::JavascriptArray_Slice:
  413. case Js::JavascriptBuiltInFunction::JavascriptArray_Splice:
  414. case Js::JavascriptBuiltInFunction::JavascriptString_Link:
  415. goto CallDirectCommon;
  416. case Js::JavascriptBuiltInFunction::JavascriptArray_Join:
  417. case Js::JavascriptBuiltInFunction::JavascriptString_CharAt:
  418. case Js::JavascriptBuiltInFunction::JavascriptString_Concat:
  419. case Js::JavascriptBuiltInFunction::JavascriptString_FromCharCode:
  420. case Js::JavascriptBuiltInFunction::JavascriptString_FromCodePoint:
  421. case Js::JavascriptBuiltInFunction::JavascriptString_Replace:
  422. case Js::JavascriptBuiltInFunction::JavascriptString_Slice:
  423. case Js::JavascriptBuiltInFunction::JavascriptString_Substr:
  424. case Js::JavascriptBuiltInFunction::JavascriptString_Substring:
  425. case Js::JavascriptBuiltInFunction::JavascriptString_ToLocaleLowerCase:
  426. case Js::JavascriptBuiltInFunction::JavascriptString_ToLocaleUpperCase:
  427. case Js::JavascriptBuiltInFunction::JavascriptString_ToLowerCase:
  428. case Js::JavascriptBuiltInFunction::JavascriptString_ToUpperCase:
  429. case Js::JavascriptBuiltInFunction::JavascriptString_Trim:
  430. case Js::JavascriptBuiltInFunction::JavascriptString_TrimLeft:
  431. case Js::JavascriptBuiltInFunction::JavascriptString_TrimRight:
  432. case Js::JavascriptBuiltInFunction::JavascriptString_PadStart:
  433. case Js::JavascriptBuiltInFunction::JavascriptString_PadEnd:
  434. *returnType = ValueType::String;
  435. goto CallDirectCommon;
  436. case Js::JavascriptBuiltInFunction::JavascriptArray_Includes:
  437. case Js::JavascriptBuiltInFunction::JavascriptObject_HasOwnProperty:
  438. case Js::JavascriptBuiltInFunction::JavascriptArray_IsArray:
  439. *returnType = ValueType::Boolean;
  440. goto CallDirectCommon;
  441. case Js::JavascriptBuiltInFunction::JavascriptArray_IndexOf:
  442. case Js::JavascriptBuiltInFunction::JavascriptArray_LastIndexOf:
  443. case Js::JavascriptBuiltInFunction::JavascriptArray_Unshift:
  444. case Js::JavascriptBuiltInFunction::JavascriptString_CharCodeAt:
  445. case Js::JavascriptBuiltInFunction::JavascriptString_IndexOf:
  446. case Js::JavascriptBuiltInFunction::JavascriptString_LastIndexOf:
  447. case Js::JavascriptBuiltInFunction::JavascriptString_Search:
  448. case Js::JavascriptBuiltInFunction::JavascriptRegExp_SymbolSearch:
  449. case Js::JavascriptBuiltInFunction::GlobalObject_ParseInt:
  450. *returnType = ValueType::GetNumberAndLikelyInt(true);
  451. goto CallDirectCommon;
  452. case Js::JavascriptBuiltInFunction::JavascriptString_Split:
  453. *returnType = ValueType::GetObject(ObjectType::Array).SetHasNoMissingValues(true).SetArrayTypeId(Js::TypeIds_Array);
  454. goto CallDirectCommon;
  455. case Js::JavascriptBuiltInFunction::JavascriptString_Match:
  456. case Js::JavascriptBuiltInFunction::JavascriptRegExp_Exec:
  457. *returnType =
  458. ValueType::GetObject(ObjectType::Array).SetHasNoMissingValues(true).SetArrayTypeId(Js::TypeIds_Array)
  459. .Merge(ValueType::Null);
  460. goto CallDirectCommon;
  461. CallDirectCommon:
  462. *inlineCandidateOpCode = Js::OpCode::CallDirect;
  463. break;
  464. case Js::JavascriptBuiltInFunction::JavascriptFunction_Apply:
  465. *inlineCandidateOpCode = Js::OpCode::InlineFunctionApply;
  466. break;
  467. case Js::JavascriptBuiltInFunction::JavascriptFunction_Call:
  468. *inlineCandidateOpCode = Js::OpCode::InlineFunctionCall;
  469. break;
  470. // The following are not currently inlined, but are tracked for their return type
  471. // TODO: Add more built-ins that return objects. May consider tracking all built-ins.
  472. case Js::JavascriptBuiltInFunction::JavascriptArray_NewInstance:
  473. *returnType = ValueType::GetObject(ObjectType::Array).SetHasNoMissingValues(true).SetArrayTypeId(Js::TypeIds_Array);
  474. break;
  475. case Js::JavascriptBuiltInFunction::Int8Array_NewInstance:
  476. #ifdef _M_X64
  477. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Int8MixedArray) : ValueType::GetObject(ObjectType::Int8Array);
  478. #else
  479. *returnType = ValueType::GetObject(ObjectType::Int8Array);
  480. #endif
  481. break;
  482. case Js::JavascriptBuiltInFunction::Uint8Array_NewInstance:
  483. #ifdef _M_X64
  484. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Uint8MixedArray) : ValueType::GetObject(ObjectType::Uint8Array);
  485. #else
  486. *returnType = ValueType::GetObject(ObjectType::Uint8Array);
  487. #endif
  488. break;
  489. case Js::JavascriptBuiltInFunction::Uint8ClampedArray_NewInstance:
  490. #ifdef _M_X64
  491. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Uint8ClampedMixedArray) : ValueType::GetObject(ObjectType::Uint8ClampedArray);
  492. #else
  493. *returnType = ValueType::GetObject(ObjectType::Uint8ClampedArray);
  494. #endif
  495. break;
  496. case Js::JavascriptBuiltInFunction::Int16Array_NewInstance:
  497. #ifdef _M_X64
  498. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Int16MixedArray) : ValueType::GetObject(ObjectType::Int16Array);
  499. #else
  500. *returnType = ValueType::GetObject(ObjectType::Int16Array);
  501. #endif
  502. break;
  503. case Js::JavascriptBuiltInFunction::Uint16Array_NewInstance:
  504. #ifdef _M_X64
  505. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Uint16MixedArray) : ValueType::GetObject(ObjectType::Uint16Array);
  506. #else
  507. *returnType = ValueType::GetObject(ObjectType::Uint16Array);
  508. #endif
  509. break;
  510. case Js::JavascriptBuiltInFunction::Int32Array_NewInstance:
  511. #ifdef _M_X64
  512. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Int32MixedArray) : ValueType::GetObject(ObjectType::Int32Array);
  513. #else
  514. *returnType = ValueType::GetObject(ObjectType::Int32Array);
  515. #endif
  516. break;
  517. case Js::JavascriptBuiltInFunction::Uint32Array_NewInstance:
  518. #ifdef _M_X64
  519. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Uint32MixedArray) : ValueType::GetObject(ObjectType::Uint32Array);
  520. #else
  521. *returnType = ValueType::GetObject(ObjectType::Uint32Array);
  522. #endif
  523. break;
  524. case Js::JavascriptBuiltInFunction::Float32Array_NewInstance:
  525. #ifdef _M_X64
  526. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Float32MixedArray) : ValueType::GetObject(ObjectType::Float32Array);
  527. #else
  528. *returnType = ValueType::GetObject(ObjectType::Float32Array);
  529. #endif
  530. break;
  531. case Js::JavascriptBuiltInFunction::Float64Array_NewInstance:
  532. #ifdef _M_X64
  533. *returnType = (!PHASE_OFF1(Js::TypedArrayVirtualPhase)) ? ValueType::GetObject(ObjectType::Float64MixedArray) : ValueType::GetObject(ObjectType::Float64Array);
  534. #else
  535. *returnType = ValueType::GetObject(ObjectType::Float64Array);
  536. #endif
  537. break;
  538. case Js::JavascriptBuiltInFunction::Int64Array_NewInstance:
  539. *returnType = ValueType::GetObject(ObjectType::Int64Array);
  540. break;
  541. case Js::JavascriptBuiltInFunction::Uint64Array_NewInstance:
  542. *returnType = ValueType::GetObject(ObjectType::Uint64Array);
  543. break;
  544. case Js::JavascriptBuiltInFunction::BoolArray_NewInstance:
  545. *returnType = ValueType::GetObject(ObjectType::BoolArray);
  546. break;
  547. case Js::JavascriptBuiltInFunction::CharArray_NewInstance:
  548. *returnType = ValueType::GetObject(ObjectType::CharArray);
  549. break;
  550. #ifdef ENABLE_DOM_FAST_PATH
  551. case Js::JavascriptBuiltInFunction::DOMFastPathGetter:
  552. *inlineCandidateOpCode = Js::OpCode::DOMFastPathGetter;
  553. break;
  554. #endif
  555. default:
  556. return false;
  557. }
  558. return true;
  559. }
  560. bool InliningDecider::CanRecursivelyInline(Js::FunctionBody * inlinee, Js::FunctionBody *inliner, bool allowRecursiveInlining, uint recursiveInlineDepth)
  561. {
  562. #if defined(DBG_DUMP) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  563. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  564. char16 debugStringBuffer2[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  565. #endif
  566. if (!PHASE_OFF(Js::InlineRecursivePhase, inliner)
  567. && allowRecursiveInlining
  568. && inlinee == inliner
  569. && inlinee->CanInlineRecursively(recursiveInlineDepth))
  570. {
  571. INLINE_TESTTRACE(_u("INLINING: Inlined recursively\tInlinee: %s (%s)\tCaller: %s (%s)\tDepth: %d\n"),
  572. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  573. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2), recursiveInlineDepth);
  574. return true;
  575. }
  576. if (!inlinee->CanInlineAgain())
  577. {
  578. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Do not inline recursive functions\tInlinee: %s (%s)\tCaller: %s (%s)\n"),
  579. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  580. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2));
  581. return false;
  582. }
  583. return true;
  584. }
  585. // This only enables collection of the inlinee data, we are much more aggressive here.
  586. // Actual decision of whether something is inlined or not is taken in CommitInlineIntoInliner
  587. bool InliningDecider::DeciderInlineIntoInliner(Js::FunctionBody * inlinee, Js::FunctionBody * inliner, bool isConstructorCall, bool isPolymorphicCall, uint16 constantArgInfo, uint recursiveInlineDepth, bool allowRecursiveInlining)
  588. {
  589. if (!CanRecursivelyInline(inlinee, inliner, allowRecursiveInlining, recursiveInlineDepth))
  590. {
  591. return false;
  592. }
  593. if (inliner->GetIsAsmjsMode() != inlinee->GetIsAsmjsMode())
  594. {
  595. return false;
  596. }
  597. // Force inline all Js Builtins functions
  598. // The existing JsBuiltInForceInline flag can work only when we explictly create scriptFunction
  599. // We can also have methods that we define on the prototype like next of ArrayIterator for which we don't explictly create a script function
  600. // TODO (megupta) : use forceInline for methods defined on the prototype using ObjectDefineProperty
  601. if (inlinee->GetSourceContextId() == Js::Constants::JsBuiltInSourceContextId ||
  602. PHASE_FORCE(Js::InlinePhase, this->topFunc) ||
  603. PHASE_FORCE(Js::InlinePhase, inliner) ||
  604. PHASE_FORCE(Js::InlinePhase, inlinee))
  605. {
  606. return true;
  607. }
  608. if (PHASE_OFF(Js::InlinePhase, this->topFunc) ||
  609. PHASE_OFF(Js::InlinePhase, inliner) ||
  610. PHASE_OFF(Js::InlinePhase, inlinee))
  611. {
  612. return false;
  613. }
  614. if (PHASE_FORCE(Js::InlineTreePhase, this->topFunc) ||
  615. PHASE_FORCE(Js::InlineTreePhase, inliner))
  616. {
  617. return true;
  618. }
  619. if (PHASE_FORCE(Js::InlineAtEveryCallerPhase, inlinee))
  620. {
  621. return true;
  622. }
  623. uint inlineeByteCodeCount = inlinee->GetByteCodeWithoutLDACount();
  624. // Heuristics are hit in the following order (Note *order* is important)
  625. // 1. Leaf function: If the inlinee is a leaf (but not a constructor or a polymorphic call) inline threshold is LeafInlineThreshold (60). Also it can have max 1 loop
  626. // 2. Constant Function Argument: If the inlinee candidate has a constant argument and that argument is used for branching, then the inline threshold is ConstantArgumentInlineThreshold (157)
  627. // 3. InlineThreshold: If an inlinee candidate exceeds InlineThreshold just don't inline no matter what.
  628. // Following are additional constraint for an inlinee which meets InlineThreshold (Rule no 3)
  629. // 4. Rule for inlinee with loops:
  630. // 4a. Only single loop in inlinee is permitted.
  631. // 4b. Should not have polymorphic field access.
  632. // 4c. Should not be a constructor.
  633. // 4d. Should meet LoopInlineThreshold (25)
  634. // 5. Rule for polymorphic inlinee:
  635. // 4a. Should meet PolymorphicInlineThreshold (32)
  636. // 6. Rule for constructors:
  637. // 5a. Always inline if inlinee has polymorphic field access (as we have cloned runtime data).
  638. // 5b. If inlinee is monomorphic, inline only small constructors. They are governed by ConstructorInlineThreshold (21)
  639. // 7. Rule for inlinee which is not interpreted enough (as we might not have all the profile data):
  640. // 7a. As of now it is still governed by the InlineThreshold. Plan to play with this in future.
  641. // 8. Rest should be inlined.
  642. uint16 mask = constantArgInfo & inlinee->m_argUsedForBranch;
  643. if (mask && inlineeByteCodeCount < (uint)CONFIG_FLAG(ConstantArgumentInlineThreshold))
  644. {
  645. return true;
  646. }
  647. int inlineThreshold = threshold.inlineThreshold;
  648. if (!isPolymorphicCall && !isConstructorCall && IsInlineeLeaf(inlinee) && (inlinee->GetLoopCount() <= 2))
  649. {
  650. // Inlinee is a leaf function
  651. if (inlinee->GetLoopCount() == 0 || GetNumberOfInlineesWithLoop() <= (uint)threshold.maxNumberOfInlineesWithLoop) // Don't inlinee too many inlinees with loops.
  652. {
  653. // Negative LeafInlineThreshold disable the threshold
  654. if (threshold.leafInlineThreshold >= 0)
  655. {
  656. inlineThreshold += threshold.leafInlineThreshold - threshold.inlineThreshold;
  657. }
  658. }
  659. }
  660. #if ENABLE_DEBUG_CONFIG_OPTIONS
  661. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  662. char16 debugStringBuffer2[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  663. char16 debugStringBuffer3[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  664. #endif
  665. if (inlinee->GetHasLoops())
  666. {
  667. if (threshold.loopInlineThreshold < 0 || // Negative LoopInlineThreshold disable inlining with loop
  668. GetNumberOfInlineesWithLoop() >(uint)threshold.maxNumberOfInlineesWithLoop || // See if we are inlining too many inlinees with loops.
  669. (inlinee->GetLoopCount() > 2) || // Allow at most 2 loops.
  670. inlinee->GetHasNestedLoop() || // Nested loops are not a good inlinee candidate
  671. isConstructorCall || // If the function is constructor with loops, don't inline.
  672. PHASE_OFF(Js::InlineFunctionsWithLoopsPhase, this->topFunc))
  673. {
  674. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Has loops \tBytecode size: %d \tgetNumberOfInlineesWithLoop: %d\tloopCount: %d\thasNestedLoop: %d\tisConstructorCall:%d\tInlinee: %s (%s)\tCaller: %s (%s) \tRoot: %s (%s)\n"),
  675. inlinee->GetByteCodeCount(),
  676. GetNumberOfInlineesWithLoop(),
  677. inlinee->GetLoopCount(),
  678. inlinee->GetHasNestedLoop(),
  679. isConstructorCall,
  680. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  681. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2),
  682. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer3));
  683. // Don't inline function with loops
  684. return false;
  685. }
  686. else
  687. {
  688. inlineThreshold -= (threshold.inlineThreshold > threshold.loopInlineThreshold) ? threshold.inlineThreshold - threshold.loopInlineThreshold : 0;
  689. }
  690. }
  691. if (isPolymorphicCall)
  692. {
  693. if (threshold.polymorphicInlineThreshold < 0 || // Negative PolymorphicInlineThreshold disable inlining
  694. isConstructorCall)
  695. {
  696. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Polymorphic call under PolymorphicInlineThreshold: %d \tBytecode size: %d\tInlinee: %s (%s)\tCaller: %s (%s) \tRoot: %s (%s)\n"),
  697. threshold.polymorphicInlineThreshold,
  698. inlinee->GetByteCodeCount(),
  699. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  700. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2),
  701. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer3));
  702. return false;
  703. }
  704. else
  705. {
  706. inlineThreshold -= (threshold.inlineThreshold > threshold.polymorphicInlineThreshold) ? threshold.inlineThreshold - threshold.polymorphicInlineThreshold : 0;
  707. }
  708. }
  709. if (isConstructorCall)
  710. {
  711. #pragma prefast(suppress: 6285, "logical-or of constants is by design")
  712. if (PHASE_OFF(Js::InlineConstructorsPhase, this->topFunc) ||
  713. PHASE_OFF(Js::InlineConstructorsPhase, inliner) ||
  714. PHASE_OFF(Js::InlineConstructorsPhase, inlinee) ||
  715. !CONFIG_FLAG(CloneInlinedPolymorphicCaches))
  716. {
  717. return false;
  718. }
  719. if (PHASE_FORCE(Js::InlineConstructorsPhase, this->topFunc) ||
  720. PHASE_FORCE(Js::InlineConstructorsPhase, inliner) ||
  721. PHASE_FORCE(Js::InlineConstructorsPhase, inlinee))
  722. {
  723. return true;
  724. }
  725. if (inlinee->HasDynamicProfileInfo() && inlinee->GetAnyDynamicProfileInfo()->HasPolymorphicFldAccess())
  726. {
  727. // As of now this is not dependent on bytecodeInlinedThreshold.
  728. return true;
  729. }
  730. // Negative ConstructorInlineThreshold always disable constructor inlining
  731. if (threshold.constructorInlineThreshold < 0)
  732. {
  733. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Constructor with no polymorphic field access \tBytecode size: %d\tInlinee: %s (%s)\tCaller: %s (%s) \tRoot: %s (%s)\n"),
  734. inlinee->GetByteCodeCount(),
  735. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  736. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2),
  737. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer3));
  738. // Don't inline constructor that does not have a polymorphic field access, or if cloning polymorphic inline
  739. // caches is disabled
  740. return false;
  741. }
  742. else
  743. {
  744. inlineThreshold -= (threshold.inlineThreshold > threshold.constructorInlineThreshold) ? threshold.inlineThreshold - threshold.constructorInlineThreshold : 0;
  745. }
  746. }
  747. if (threshold.forLoopBody)
  748. {
  749. inlineThreshold /= CONFIG_FLAG(InlineInLoopBodyScaleDownFactor);
  750. }
  751. if (inlineThreshold > 0 && inlineeByteCodeCount <= (uint)inlineThreshold)
  752. {
  753. if (inlinee->GetLoopCount())
  754. {
  755. IncrementNumberOfInlineesWithLoop();
  756. }
  757. return true;
  758. }
  759. else
  760. {
  761. INLINE_TESTTRACE(_u("INLINING: Skip Inline: Too long \tBytecode size: %d\tThreshold: %d\tInlinee: %s (%s)\tCaller: %s (%s) \tRoot: %s (%s)\n"),
  762. inlinee->GetByteCodeCount(),
  763. inlineThreshold,
  764. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer),
  765. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2),
  766. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer3));
  767. return false;
  768. }
  769. }
  770. bool InliningDecider::ContinueInliningUserDefinedFunctions(uint32 bytecodeInlinedCount) const
  771. {
  772. #if ENABLE_DEBUG_CONFIG_OPTIONS
  773. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  774. #endif
  775. if (PHASE_FORCE(Js::InlinePhase, this->topFunc) || bytecodeInlinedCount <= (uint)this->threshold.inlineCountMax)
  776. {
  777. return true;
  778. }
  779. INLINE_TESTTRACE(_u("INLINING: Skip Inline: InlineCountMax threshold %d, reached: %s (#%s)\n"),
  780. (uint)this->threshold.inlineCountMax,
  781. this->topFunc->GetDisplayName(), this->topFunc->GetDebugNumberSet(debugStringBuffer));
  782. return false;
  783. }
  784. #if defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  785. // static
  786. void InliningDecider::TraceInlining(Js::FunctionBody *const inliner, const char16* inlineeName, const char16* inlineeFunctionIdandNumberString, uint inlineeByteCodeCount,
  787. Js::FunctionBody* topFunc, uint inlinedByteCodeCount, Js::FunctionBody *const inlinee, uint callSiteId, bool inLoopBody, bool isCallback, uint builtIn)
  788. {
  789. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  790. char16 debugStringBuffer2[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  791. char16 debugStringBuffer3[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  792. if (inlineeName == nullptr)
  793. {
  794. int len = swprintf_s(debugStringBuffer3, MAX_FUNCTION_BODY_DEBUG_STRING_SIZE, _u("built In Id: %u"), builtIn);
  795. Assert(len > 14);
  796. inlineeName = debugStringBuffer3;
  797. }
  798. INLINE_TRACE_AND_TESTTRACE(_u("INLINING%s %s: Inlinee: %s (%s)\tSize: %d\tCaller: %s (%s)\tSize: %d\tInlineCount: %d\tRoot: %s (%s)\tSize: %d\tCallSiteId: %d\n"),
  799. isCallback ? _u(" CALLBACK") : _u(""),
  800. inLoopBody ? _u(" IN LOOP BODY") : _u(""),
  801. inlineeName, inlineeFunctionIdandNumberString, inlineeByteCodeCount,
  802. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer), inliner->GetByteCodeCount(),
  803. inlinedByteCodeCount,
  804. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer2), topFunc->GetByteCodeCount(),
  805. callSiteId
  806. );
  807. // Now Trace inlining across files cases
  808. if (builtIn != -1) // built-in functions
  809. {
  810. return;
  811. }
  812. Assert(inliner && inlinee);
  813. if (inliner->GetSourceContextId() != inlinee->GetSourceContextId())
  814. {
  815. INLINE_TRACE_AND_TESTTRACE(_u("INLINING_ACROSS_FILES: Inlinee: %s (%s)\tSize: %d\tCaller: %s (%s)\tSize: %d\tInlineCount: %d\tRoot: %s (%s)\tSize: %d\n"),
  816. inlinee->GetDisplayName(), inlinee->GetDebugNumberSet(debugStringBuffer), inlinee->GetByteCodeCount(),
  817. inliner->GetDisplayName(), inliner->GetDebugNumberSet(debugStringBuffer2), inliner->GetByteCodeCount(), inlinedByteCodeCount,
  818. topFunc->GetDisplayName(), topFunc->GetDebugNumberSet(debugStringBuffer3), topFunc->GetByteCodeCount()
  819. );
  820. }
  821. }
  822. #endif