GlobOptFields.cpp 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  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. bool
  7. GlobOpt::DoFieldCopyProp() const
  8. {
  9. BasicBlock *block = this->currentBlock;
  10. Loop *loop = block->loop;
  11. if (this->isRecursiveCallOnLandingPad)
  12. {
  13. // The landing pad at this point only contains load hosted by PRE.
  14. // These need to be copy-prop'd into the loop.
  15. // We want to look at the implicit-call info of the loop, not it's parent.
  16. Assert(block->IsLandingPad());
  17. loop = block->next->loop;
  18. Assert(loop);
  19. }
  20. return DoFieldCopyProp(loop);
  21. }
  22. bool
  23. GlobOpt::DoFunctionFieldCopyProp() const
  24. {
  25. return DoFieldCopyProp(nullptr);
  26. }
  27. bool
  28. GlobOpt::DoFieldCopyProp(Loop * loop) const
  29. {
  30. if (PHASE_OFF(Js::CopyPropPhase, this->func))
  31. {
  32. // Can't do field copy prop without copy prop
  33. return false;
  34. }
  35. if (PHASE_FORCE(Js::FieldCopyPropPhase, this->func))
  36. {
  37. // Force always turns on field copy prop
  38. return true;
  39. }
  40. if (PHASE_OFF(Js::FieldCopyPropPhase, this->func))
  41. {
  42. return false;
  43. }
  44. return this->DoFieldOpts(loop);
  45. }
  46. bool
  47. GlobOpt::DoObjTypeSpec() const
  48. {
  49. return this->DoObjTypeSpec(this->currentBlock->loop);
  50. }
  51. bool
  52. GlobOpt::DoObjTypeSpec(Loop *loop) const
  53. {
  54. if (!this->func->DoFastPaths())
  55. {
  56. return false;
  57. }
  58. if (PHASE_FORCE(Js::ObjTypeSpecPhase, this->func))
  59. {
  60. return true;
  61. }
  62. if (PHASE_OFF(Js::ObjTypeSpecPhase, this->func))
  63. {
  64. return false;
  65. }
  66. if (this->func->IsLoopBody() && this->func->HasProfileInfo() && this->func->GetReadOnlyProfileInfo()->IsObjTypeSpecDisabledInJitLoopBody())
  67. {
  68. return false;
  69. }
  70. if (this->ImplicitCallFlagsAllowOpts(this->func))
  71. {
  72. Assert(loop == nullptr || loop->CanDoFieldCopyProp());
  73. return true;
  74. }
  75. return loop != nullptr && loop->CanDoFieldCopyProp();
  76. }
  77. bool
  78. GlobOpt::DoFieldOpts(Loop * loop) const
  79. {
  80. if (this->ImplicitCallFlagsAllowOpts(this->func))
  81. {
  82. Assert(loop == nullptr || loop->CanDoFieldCopyProp());
  83. return true;
  84. }
  85. return loop != nullptr && loop->CanDoFieldCopyProp();
  86. }
  87. bool GlobOpt::DoFieldPRE() const
  88. {
  89. Loop *loop = this->currentBlock->loop;
  90. return DoFieldPRE(loop);
  91. }
  92. bool
  93. GlobOpt::DoFieldPRE(Loop *loop) const
  94. {
  95. if (PHASE_OFF(Js::FieldPREPhase, this->func))
  96. {
  97. return false;
  98. }
  99. if (PHASE_FORCE(Js::FieldPREPhase, func))
  100. {
  101. // Force always turns on field PRE
  102. return true;
  103. }
  104. if (this->func->HasProfileInfo() && this->func->GetReadOnlyProfileInfo()->IsFieldPREDisabled())
  105. {
  106. return false;
  107. }
  108. return DoFieldOpts(loop);
  109. }
  110. bool GlobOpt::HasMemOp(Loop *loop)
  111. {
  112. #pragma prefast(suppress: 6285, "logical-or of constants is by design")
  113. return (
  114. loop &&
  115. loop->doMemOp &&
  116. (
  117. !PHASE_OFF(Js::MemSetPhase, this->func) ||
  118. !PHASE_OFF(Js::MemCopyPhase, this->func)
  119. ) &&
  120. loop->memOpInfo &&
  121. loop->memOpInfo->candidates &&
  122. !loop->memOpInfo->candidates->Empty()
  123. );
  124. }
  125. void
  126. GlobOpt::KillLiveFields(StackSym * stackSym, BVSparse<JitArenaAllocator> * bv)
  127. {
  128. if (stackSym->IsTypeSpec())
  129. {
  130. stackSym = stackSym->GetVarEquivSym(this->func);
  131. }
  132. Assert(stackSym);
  133. // If the sym has no objectSymInfo, it must not represent an object and, hence, has no type sym or
  134. // property syms to kill.
  135. if (!stackSym->HasObjectInfo() || stackSym->IsSingleDef())
  136. {
  137. return;
  138. }
  139. // Note that the m_writeGuardSym is killed here as well, because it is part of the
  140. // m_propertySymList of the object.
  141. ObjectSymInfo * objectSymInfo = stackSym->GetObjectInfo();
  142. PropertySym * propertySym = objectSymInfo->m_propertySymList;
  143. while (propertySym != nullptr)
  144. {
  145. Assert(propertySym->m_stackSym == stackSym);
  146. bv->Clear(propertySym->m_id);
  147. if (this->IsLoopPrePass())
  148. {
  149. for (Loop * loop = this->rootLoopPrePass; loop != nullptr; loop = loop->parent)
  150. {
  151. loop->fieldKilled->Set(propertySym->m_id);
  152. }
  153. }
  154. else if (bv->IsEmpty())
  155. {
  156. // shortcut
  157. break;
  158. }
  159. propertySym = propertySym->m_nextInStackSymList;
  160. }
  161. this->KillObjectType(stackSym, bv);
  162. }
  163. void
  164. GlobOpt::KillLiveFields(PropertySym * propertySym, BVSparse<JitArenaAllocator> * bv)
  165. {
  166. KillLiveFields(propertySym->m_propertyEquivSet, bv);
  167. }
  168. void GlobOpt::KillLiveFields(BVSparse<JitArenaAllocator> *const fieldsToKill, BVSparse<JitArenaAllocator> *const bv) const
  169. {
  170. Assert(bv);
  171. if (fieldsToKill)
  172. {
  173. bv->Minus(fieldsToKill);
  174. if (this->IsLoopPrePass())
  175. {
  176. for (Loop * loop = this->rootLoopPrePass; loop != nullptr; loop = loop->parent)
  177. {
  178. loop->fieldKilled->Or(fieldsToKill);
  179. }
  180. }
  181. }
  182. }
  183. void
  184. GlobOpt::KillLiveElems(IR::IndirOpnd * indirOpnd, IR::Opnd * valueOpnd, BVSparse<JitArenaAllocator> * bv, bool inGlobOpt, Func *func)
  185. {
  186. IR::RegOpnd *indexOpnd = indirOpnd->GetIndexOpnd();
  187. // obj.x = 10;
  188. // obj["x"] = ...; // This needs to kill obj.x... We need to kill all fields...
  189. //
  190. // Also, 'arguments[i] =' needs to kill all slots even if 'i' is an int.
  191. //
  192. // NOTE: we only need to kill slots here, not all fields. It may be good to separate these one day.
  193. //
  194. // Regarding the check for type specialization:
  195. // - Type specialization does not always update the value to a definite type.
  196. // - The loop prepass is conservative on values even when type specialization occurs.
  197. // - We check the type specialization status for the sym as well. For the purpose of doing kills, we can assume that
  198. // if type specialization happened, that fields don't need to be killed. Note that they may be killed in the next
  199. // pass based on the value.
  200. bool isSafeToTransfer = true;
  201. if (func->GetThisOrParentInlinerHasArguments() || this->IsNonNumericRegOpnd(indexOpnd, inGlobOpt, &isSafeToTransfer))
  202. {
  203. this->KillAllFields(bv); // This also kills all property type values, as the same bit-vector tracks those stack syms
  204. SetAnyPropertyMayBeWrittenTo();
  205. }
  206. else if (inGlobOpt)
  207. {
  208. Value * indexValue = indexOpnd ? this->currentBlock->globOptData.FindValue(indexOpnd->GetSym()) : nullptr;
  209. ValueInfo * indexValueInfo = indexValue ? indexValue->GetValueInfo() : nullptr;
  210. int indexLowerBound = 0;
  211. if (!isSafeToTransfer || indirOpnd->GetOffset() < 0 || (indexOpnd && (!indexValueInfo || !indexValueInfo->TryGetIntConstantLowerBound(&indexLowerBound, false) || indexLowerBound < 0)))
  212. {
  213. // Write/delete to a non-integer numeric index can't alias a name on the RHS of a dot, but it change object layout
  214. this->KillAllObjectTypes(bv);
  215. }
  216. else if ((!valueOpnd || valueOpnd->IsVar()) && this->objectTypeSyms != nullptr)
  217. {
  218. // If we wind up converting a native array, block final-type opt at this point, because we could evolve
  219. // to a type with the wrong type ID. Do this by noting that we may have evolved any type and so must
  220. // check it before evolving it further.
  221. IR::RegOpnd *baseOpnd = indirOpnd->GetBaseOpnd();
  222. Value * baseValue = baseOpnd ? this->currentBlock->globOptData.FindValue(baseOpnd->m_sym) : nullptr;
  223. ValueInfo * baseValueInfo = baseValue ? baseValue->GetValueInfo() : nullptr;
  224. if (!baseValueInfo || !baseValueInfo->IsNotNativeArray() ||
  225. (this->IsLoopPrePass() && !this->IsSafeToTransferInPrepass(baseOpnd->m_sym, baseValueInfo)))
  226. {
  227. if (this->currentBlock->globOptData.maybeWrittenTypeSyms == nullptr)
  228. {
  229. this->currentBlock->globOptData.maybeWrittenTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  230. }
  231. this->currentBlock->globOptData.maybeWrittenTypeSyms->Or(this->objectTypeSyms);
  232. }
  233. }
  234. }
  235. }
  236. void
  237. GlobOpt::KillAllFields(BVSparse<JitArenaAllocator> * bv)
  238. {
  239. bv->ClearAll();
  240. if (this->IsLoopPrePass())
  241. {
  242. for (Loop * loop = this->rootLoopPrePass; loop != nullptr; loop = loop->parent)
  243. {
  244. loop->allFieldsKilled = true;
  245. }
  246. }
  247. }
  248. void
  249. GlobOpt::SetAnyPropertyMayBeWrittenTo()
  250. {
  251. this->func->anyPropertyMayBeWrittenTo = true;
  252. }
  253. void
  254. GlobOpt::AddToPropertiesWrittenTo(Js::PropertyId propertyId)
  255. {
  256. this->func->EnsurePropertiesWrittenTo();
  257. this->func->propertiesWrittenTo->Item(propertyId);
  258. }
  259. void
  260. GlobOpt::ProcessFieldKills(IR::Instr *instr, BVSparse<JitArenaAllocator> *bv, bool inGlobOpt)
  261. {
  262. if (bv->IsEmpty() && (!this->IsLoopPrePass() || this->rootLoopPrePass->allFieldsKilled))
  263. {
  264. return;
  265. }
  266. if (instr->m_opcode == Js::OpCode::FromVar || instr->m_opcode == Js::OpCode::Conv_Prim)
  267. {
  268. return;
  269. }
  270. IR::Opnd * dstOpnd = instr->GetDst();
  271. if (dstOpnd)
  272. {
  273. if (dstOpnd->IsRegOpnd())
  274. {
  275. Sym * sym = dstOpnd->AsRegOpnd()->m_sym;
  276. if (sym->IsStackSym())
  277. {
  278. KillLiveFields(sym->AsStackSym(), bv);
  279. }
  280. }
  281. else if (dstOpnd->IsSymOpnd())
  282. {
  283. Sym * sym = dstOpnd->AsSymOpnd()->m_sym;
  284. if (sym->IsStackSym())
  285. {
  286. KillLiveFields(sym->AsStackSym(), bv);
  287. }
  288. else
  289. {
  290. Assert(sym->IsPropertySym());
  291. if (instr->m_opcode == Js::OpCode::InitLetFld || instr->m_opcode == Js::OpCode::InitConstFld || instr->m_opcode == Js::OpCode::InitFld)
  292. {
  293. // These can grow the aux slot of the activation object.
  294. // We need to kill the slot array sym as well.
  295. PropertySym * slotArraySym = PropertySym::Find(sym->AsPropertySym()->m_stackSym->m_id,
  296. (Js::DynamicObject::GetOffsetOfAuxSlots())/sizeof(Js::Var) /*, PropertyKindSlotArray */, instr->m_func);
  297. if (slotArraySym)
  298. {
  299. bv->Clear(slotArraySym->m_id);
  300. }
  301. }
  302. }
  303. }
  304. }
  305. if (bv->IsEmpty() && (!this->IsLoopPrePass() || this->rootLoopPrePass->allFieldsKilled))
  306. {
  307. return;
  308. }
  309. Sym *sym;
  310. IR::JnHelperMethod fnHelper;
  311. switch(instr->m_opcode)
  312. {
  313. case Js::OpCode::StElemC:
  314. case Js::OpCode::StElemI_A:
  315. case Js::OpCode::StElemI_A_Strict:
  316. Assert(dstOpnd != nullptr);
  317. KillLiveFields(this->lengthEquivBv, bv);
  318. KillLiveElems(dstOpnd->AsIndirOpnd(), instr->GetSrc1(), bv, inGlobOpt, instr->m_func);
  319. if (inGlobOpt)
  320. {
  321. KillObjectHeaderInlinedTypeSyms(this->currentBlock, false);
  322. }
  323. break;
  324. case Js::OpCode::InitComputedProperty:
  325. case Js::OpCode::InitGetElemI:
  326. case Js::OpCode::InitSetElemI:
  327. KillLiveElems(dstOpnd->AsIndirOpnd(), instr->GetSrc1(), bv, inGlobOpt, instr->m_func);
  328. if (inGlobOpt)
  329. {
  330. KillObjectHeaderInlinedTypeSyms(this->currentBlock, false);
  331. }
  332. break;
  333. case Js::OpCode::DeleteElemI_A:
  334. case Js::OpCode::DeleteElemIStrict_A:
  335. Assert(dstOpnd != nullptr);
  336. KillLiveElems(instr->GetSrc1()->AsIndirOpnd(), nullptr, bv, inGlobOpt, instr->m_func);
  337. break;
  338. case Js::OpCode::DeleteFld:
  339. case Js::OpCode::DeleteRootFld:
  340. case Js::OpCode::DeleteFldStrict:
  341. case Js::OpCode::DeleteRootFldStrict:
  342. case Js::OpCode::ScopedDeleteFld:
  343. case Js::OpCode::ScopedDeleteFldStrict:
  344. sym = instr->GetSrc1()->AsSymOpnd()->m_sym;
  345. KillLiveFields(sym->AsPropertySym(), bv);
  346. if (inGlobOpt)
  347. {
  348. AddToPropertiesWrittenTo(sym->AsPropertySym()->m_propertyId);
  349. this->KillAllObjectTypes(bv);
  350. }
  351. break;
  352. case Js::OpCode::InitSetFld:
  353. case Js::OpCode::InitGetFld:
  354. case Js::OpCode::InitClassMember:
  355. case Js::OpCode::InitClassMemberGet:
  356. case Js::OpCode::InitClassMemberSet:
  357. sym = instr->GetDst()->AsSymOpnd()->m_sym;
  358. KillLiveFields(sym->AsPropertySym(), bv);
  359. if (inGlobOpt)
  360. {
  361. AddToPropertiesWrittenTo(sym->AsPropertySym()->m_propertyId);
  362. this->KillAllObjectTypes(bv);
  363. }
  364. break;
  365. case Js::OpCode::ConsoleScopedStFld:
  366. case Js::OpCode::ConsoleScopedStFldStrict:
  367. case Js::OpCode::ScopedStFld:
  368. case Js::OpCode::ScopedStFldStrict:
  369. // This is already taken care of for FastFld opcodes
  370. if (inGlobOpt)
  371. {
  372. KillObjectHeaderInlinedTypeSyms(this->currentBlock, false);
  373. if (this->objectTypeSyms)
  374. {
  375. if (this->currentBlock->globOptData.maybeWrittenTypeSyms == nullptr)
  376. {
  377. this->currentBlock->globOptData.maybeWrittenTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  378. }
  379. this->currentBlock->globOptData.maybeWrittenTypeSyms->Or(this->objectTypeSyms);
  380. }
  381. }
  382. // fall through
  383. case Js::OpCode::InitFld:
  384. case Js::OpCode::InitConstFld:
  385. case Js::OpCode::InitLetFld:
  386. case Js::OpCode::InitRootFld:
  387. case Js::OpCode::InitRootConstFld:
  388. case Js::OpCode::InitRootLetFld:
  389. #if !FLOATVAR
  390. case Js::OpCode::StSlotBoxTemp:
  391. #endif
  392. case Js::OpCode::StFld:
  393. case Js::OpCode::StRootFld:
  394. case Js::OpCode::StFldStrict:
  395. case Js::OpCode::StRootFldStrict:
  396. case Js::OpCode::StSlot:
  397. case Js::OpCode::StSlotChkUndecl:
  398. case Js::OpCode::StSuperFld:
  399. Assert(dstOpnd != nullptr);
  400. sym = dstOpnd->AsSymOpnd()->m_sym;
  401. if (inGlobOpt)
  402. {
  403. AddToPropertiesWrittenTo(sym->AsPropertySym()->m_propertyId);
  404. }
  405. if ((inGlobOpt && (sym->AsPropertySym()->m_propertyId == Js::PropertyIds::valueOf || sym->AsPropertySym()->m_propertyId == Js::PropertyIds::toString)) ||
  406. instr->CallsAccessor())
  407. {
  408. // If overriding valueof/tostring, we might have expected a previous LdFld to bailout on implicitCalls but didn't.
  409. // CSE's for example would have expected a bailout. Clear all fields to prevent optimizing across.
  410. this->KillAllFields(bv);
  411. }
  412. else
  413. {
  414. KillLiveFields(sym->AsPropertySym(), bv);
  415. }
  416. break;
  417. case Js::OpCode::InlineArrayPush:
  418. case Js::OpCode::InlineArrayPop:
  419. if(instr->m_func->GetThisOrParentInlinerHasArguments())
  420. {
  421. this->KillAllFields(bv);
  422. this->SetAnyPropertyMayBeWrittenTo();
  423. }
  424. else
  425. {
  426. KillLiveFields(this->lengthEquivBv, bv);
  427. if (inGlobOpt)
  428. {
  429. // Deleting an item, or pushing a property to a non-array, may change object layout
  430. KillAllObjectTypes(bv);
  431. }
  432. }
  433. break;
  434. case Js::OpCode::InlineeStart:
  435. case Js::OpCode::InlineeEnd:
  436. Assert(!instr->UsesAllFields());
  437. // Kill all live 'arguments' and 'caller' fields, as 'inlineeFunction.arguments' and 'inlineeFunction.caller'
  438. // cannot be copy-propped across different instances of the same inlined function.
  439. KillLiveFields(argumentsEquivBv, bv);
  440. KillLiveFields(callerEquivBv, bv);
  441. break;
  442. case Js::OpCode::CallDirect:
  443. fnHelper = instr->GetSrc1()->AsHelperCallOpnd()->m_fnHelper;
  444. switch (fnHelper)
  445. {
  446. case IR::JnHelperMethod::HelperArray_Shift:
  447. case IR::JnHelperMethod::HelperArray_Splice:
  448. case IR::JnHelperMethod::HelperArray_Unshift:
  449. // Kill length field for built-ins that can update it.
  450. if (nullptr != this->lengthEquivBv)
  451. {
  452. // If has arguments, all fields are killed in fall through
  453. if (!instr->m_func->GetThisOrParentInlinerHasArguments())
  454. {
  455. KillLiveFields(this->lengthEquivBv, bv);
  456. }
  457. }
  458. // fall through
  459. case IR::JnHelperMethod::HelperArray_Reverse:
  460. if (instr->m_func->GetThisOrParentInlinerHasArguments())
  461. {
  462. this->KillAllFields(bv);
  463. this->SetAnyPropertyMayBeWrittenTo();
  464. }
  465. else if (inGlobOpt)
  466. {
  467. // Deleting an item may change object layout
  468. KillAllObjectTypes(bv);
  469. }
  470. break;
  471. case IR::JnHelperMethod::HelperArray_Slice:
  472. case IR::JnHelperMethod::HelperArray_Concat:
  473. if (inGlobOpt && this->objectTypeSyms)
  474. {
  475. if (this->currentBlock->globOptData.maybeWrittenTypeSyms == nullptr)
  476. {
  477. this->currentBlock->globOptData.maybeWrittenTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  478. }
  479. this->currentBlock->globOptData.maybeWrittenTypeSyms->Or(this->objectTypeSyms);
  480. }
  481. break;
  482. case IR::JnHelperMethod::HelperRegExp_Exec:
  483. case IR::JnHelperMethod::HelperRegExp_ExecResultNotUsed:
  484. case IR::JnHelperMethod::HelperRegExp_ExecResultUsed:
  485. case IR::JnHelperMethod::HelperRegExp_ExecResultUsedAndMayBeTemp:
  486. case IR::JnHelperMethod::HelperRegExp_MatchResultNotUsed:
  487. case IR::JnHelperMethod::HelperRegExp_MatchResultUsed:
  488. case IR::JnHelperMethod::HelperRegExp_MatchResultUsedAndMayBeTemp:
  489. case IR::JnHelperMethod::HelperRegExp_ReplaceStringResultUsed:
  490. case IR::JnHelperMethod::HelperRegExp_ReplaceStringResultNotUsed:
  491. case IR::JnHelperMethod::HelperRegExp_SplitResultNotUsed:
  492. case IR::JnHelperMethod::HelperRegExp_SplitResultUsed:
  493. case IR::JnHelperMethod::HelperRegExp_SplitResultUsedAndMayBeTemp:
  494. case IR::JnHelperMethod::HelperRegExp_SymbolSearch:
  495. case IR::JnHelperMethod::HelperString_Match:
  496. case IR::JnHelperMethod::HelperString_Search:
  497. case IR::JnHelperMethod::HelperString_Split:
  498. case IR::JnHelperMethod::HelperString_Replace:
  499. // Consider: We may not need to kill all fields here.
  500. // We need to kill all the built-in properties that can be written, though, and there are a lot of those.
  501. this->KillAllFields(bv);
  502. break;
  503. }
  504. break;
  505. case Js::OpCode::LdHeapArguments:
  506. case Js::OpCode::LdLetHeapArguments:
  507. case Js::OpCode::LdHeapArgsCached:
  508. case Js::OpCode::LdLetHeapArgsCached:
  509. if (inGlobOpt) {
  510. this->KillLiveFields(this->slotSyms, bv);
  511. }
  512. break;
  513. case Js::OpCode::InitClass:
  514. case Js::OpCode::InitProto:
  515. case Js::OpCode::NewScObjectNoCtor:
  516. case Js::OpCode::NewScObjectNoCtorFull:
  517. if (inGlobOpt)
  518. {
  519. // Opcodes that make an object into a prototype may break object-header-inlining and final type opt.
  520. // Kill all known object layouts.
  521. KillAllObjectTypes(bv);
  522. }
  523. break;
  524. default:
  525. if (instr->UsesAllFields())
  526. {
  527. // This also kills all property type values, as the same bit-vector tracks those stack syms.
  528. this->KillAllFields(bv);
  529. }
  530. break;
  531. }
  532. }
  533. void
  534. GlobOpt::ProcessFieldKills(IR::Instr * instr)
  535. {
  536. if (!this->DoFieldCopyProp() && !this->DoFieldRefOpts() && !DoCSE())
  537. {
  538. Assert(this->currentBlock->globOptData.liveFields->IsEmpty());
  539. return;
  540. }
  541. ProcessFieldKills(instr, this->currentBlock->globOptData.liveFields, true);
  542. }
  543. Value *
  544. GlobOpt::CreateFieldSrcValue(PropertySym * sym, PropertySym * originalSym, IR::Opnd ** ppOpnd, IR::Instr * instr)
  545. {
  546. #if DBG
  547. // If the opcode going to kill all field values immediate anyway, we shouldn't be giving it a value
  548. Assert(!instr->UsesAllFields());
  549. AssertCanCopyPropOrCSEFieldLoad(instr);
  550. Assert(instr->GetSrc1() == *ppOpnd);
  551. #endif
  552. // Only give a value to fields if we are doing field copy prop.
  553. // Consider: We should always copy prop local slots, but the only use right now is LdSlot from jit loop body.
  554. // This should have one onus load, and thus no need for copy prop of field itself. We may want to support
  555. // copy prop LdSlot if there are other uses of local slots
  556. if (!this->DoFieldCopyProp())
  557. {
  558. return nullptr;
  559. }
  560. BOOL wasLive = this->currentBlock->globOptData.liveFields->TestAndSet(sym->m_id);
  561. if (sym != originalSym)
  562. {
  563. this->currentBlock->globOptData.liveFields->TestAndSet(originalSym->m_id);
  564. }
  565. if (!wasLive)
  566. {
  567. // We don't clear the value when we kill the field.
  568. // Clear it to make sure we don't use the old value.
  569. this->currentBlock->globOptData.ClearSymValue(sym);
  570. this->currentBlock->globOptData.ClearSymValue(originalSym);
  571. }
  572. Assert((*ppOpnd)->AsSymOpnd()->m_sym == sym || this->IsLoopPrePass());
  573. // We don't use the sym store to do copy prop on hoisted fields, but create a value
  574. // in case it can be copy prop out of the loop.
  575. return this->NewGenericValue(ValueType::Uninitialized, *ppOpnd);
  576. }
  577. bool
  578. GlobOpt::NeedBailOnImplicitCallWithFieldOpts(Loop *loop, bool hasLiveFields) const
  579. {
  580. if (!(((this->DoFieldRefOpts(loop) ||
  581. this->DoFieldCopyProp(loop)) &&
  582. hasLiveFields)))
  583. {
  584. return false;
  585. }
  586. return true;
  587. }
  588. IR::Instr *
  589. GlobOpt::EnsureDisableImplicitCallRegion(Loop * loop)
  590. {
  591. Assert(loop->bailOutInfo != nullptr);
  592. IR::Instr * endDisableImplicitCall = loop->endDisableImplicitCall;
  593. if (endDisableImplicitCall)
  594. {
  595. return endDisableImplicitCall;
  596. }
  597. IR::Instr * bailOutTarget = EnsureBailTarget(loop);
  598. Func * bailOutFunc = loop->GetFunc();
  599. Assert(loop->bailOutInfo->bailOutFunc == bailOutFunc);
  600. IR::MemRefOpnd * disableImplicitCallAddress = IR::MemRefOpnd::New(this->func->GetThreadContextInfo()->GetDisableImplicitFlagsAddr(), TyInt8, bailOutFunc);
  601. IR::IntConstOpnd * disableImplicitCallAndExceptionValue = IR::IntConstOpnd::New(DisableImplicitCallAndExceptionFlag, TyInt8, bailOutFunc, true);
  602. IR::IntConstOpnd * enableImplicitCallAndExceptionValue = IR::IntConstOpnd::New(DisableImplicitNoFlag, TyInt8, bailOutFunc, true);
  603. IR::Opnd * implicitCallFlags = Lowerer::GetImplicitCallFlagsOpnd(bailOutFunc);
  604. IR::IntConstOpnd * noImplicitCall = IR::IntConstOpnd::New(Js::ImplicitCall_None, TyInt8, bailOutFunc, true);
  605. // Consider: if we are already doing implicit call in the outer loop, we don't need to clear the implicit call bit again
  606. IR::Instr * clearImplicitCall = IR::Instr::New(Js::OpCode::Ld_A, implicitCallFlags, noImplicitCall, bailOutFunc);
  607. bailOutTarget->InsertBefore(clearImplicitCall);
  608. IR::Instr * disableImplicitCall = IR::Instr::New(Js::OpCode::Ld_A, disableImplicitCallAddress, disableImplicitCallAndExceptionValue, bailOutFunc);
  609. bailOutTarget->InsertBefore(disableImplicitCall);
  610. endDisableImplicitCall = IR::Instr::New(Js::OpCode::Ld_A, disableImplicitCallAddress, enableImplicitCallAndExceptionValue, bailOutFunc);
  611. bailOutTarget->InsertBefore(endDisableImplicitCall);
  612. IR::BailOutInstr * bailOutInstr = IR::BailOutInstr::New(Js::OpCode::BailOnNotEqual, IR::BailOutOnImplicitCalls, loop->bailOutInfo, loop->bailOutInfo->bailOutFunc);
  613. bailOutInstr->SetSrc1(implicitCallFlags);
  614. bailOutInstr->SetSrc2(noImplicitCall);
  615. bailOutTarget->InsertBefore(bailOutInstr);
  616. loop->endDisableImplicitCall = endDisableImplicitCall;
  617. return endDisableImplicitCall;
  618. }
  619. #if DBG
  620. bool
  621. GlobOpt::IsPropertySymId(SymID symId) const
  622. {
  623. return this->func->m_symTable->Find(symId)->IsPropertySym();
  624. }
  625. void
  626. GlobOpt::AssertCanCopyPropOrCSEFieldLoad(IR::Instr * instr)
  627. {
  628. // Consider: Hoisting LdRootFld may have complication with exception if the field doesn't exist.
  629. // We need to have another opcode for the hoisted version to avoid the exception and bailout.
  630. Assert(instr->m_opcode == Js::OpCode::LdSlot || instr->m_opcode == Js::OpCode::LdSlotArr
  631. || instr->m_opcode == Js::OpCode::LdFld || instr->m_opcode == Js::OpCode::LdFldForCallApplyTarget
  632. || instr->m_opcode == Js::OpCode::LdLen_A
  633. || instr->m_opcode == Js::OpCode::LdRootFld || instr->m_opcode == Js::OpCode::LdSuperFld
  634. || instr->m_opcode == Js::OpCode::LdFldForTypeOf || instr->m_opcode == Js::OpCode::LdRootFldForTypeOf
  635. || instr->m_opcode == Js::OpCode::LdMethodFld || instr->m_opcode == Js::OpCode::LdMethodFldPolyInlineMiss
  636. || instr->m_opcode == Js::OpCode::LdRootMethodFld
  637. || instr->m_opcode == Js::OpCode::LdMethodFromFlags
  638. || instr->m_opcode == Js::OpCode::ScopedLdMethodFld
  639. || instr->m_opcode == Js::OpCode::CheckFixedFld
  640. || instr->m_opcode == Js::OpCode::CheckPropertyGuardAndLoadType
  641. || instr->m_opcode == Js::OpCode::ScopedLdFld
  642. || instr->m_opcode == Js::OpCode::ScopedLdFldForTypeOf);
  643. Assert(instr->m_opcode == Js::OpCode::CheckFixedFld || instr->GetDst()->GetType() == TyVar || instr->m_func->GetJITFunctionBody()->IsAsmJsMode());
  644. Assert(instr->GetSrc1()->GetType() == TyVar || instr->m_func->GetJITFunctionBody()->IsAsmJsMode());
  645. Assert(instr->GetSrc1()->AsSymOpnd()->m_sym->IsPropertySym());
  646. Assert(instr->GetSrc2() == nullptr);
  647. }
  648. #endif
  649. StackSym *
  650. GlobOpt::EnsureObjectTypeSym(StackSym * objectSym)
  651. {
  652. Assert(!objectSym->IsTypeSpec());
  653. objectSym->EnsureObjectInfo(this->func);
  654. if (objectSym->HasObjectTypeSym())
  655. {
  656. Assert(this->objectTypeSyms);
  657. return objectSym->GetObjectTypeSym();
  658. }
  659. if (this->objectTypeSyms == nullptr)
  660. {
  661. this->objectTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  662. }
  663. StackSym * typeSym = StackSym::New(TyVar, this->func);
  664. objectSym->GetObjectInfo()->m_typeSym = typeSym;
  665. this->objectTypeSyms->Set(typeSym->m_id);
  666. return typeSym;
  667. }
  668. PropertySym *
  669. GlobOpt::EnsurePropertyWriteGuardSym(PropertySym * propertySym)
  670. {
  671. // Make sure that the PropertySym has a proto cache sym which is chained into the propertySym list.
  672. if (!propertySym->m_writeGuardSym)
  673. {
  674. propertySym->m_writeGuardSym = PropertySym::New(propertySym->m_stackSym, propertySym->m_propertyId, (uint32)-1, (uint)-1, PropertyKindWriteGuard, this->func);
  675. }
  676. return propertySym->m_writeGuardSym;
  677. }
  678. void
  679. GlobOpt::PreparePropertySymForTypeCheckSeq(PropertySym *propertySym)
  680. {
  681. Assert(!propertySym->m_stackSym->IsTypeSpec());
  682. EnsureObjectTypeSym(propertySym->m_stackSym);
  683. EnsurePropertyWriteGuardSym(propertySym);
  684. }
  685. bool
  686. GlobOpt::IsPropertySymPreparedForTypeCheckSeq(PropertySym *propertySym)
  687. {
  688. Assert(!propertySym->m_stackSym->IsTypeSpec());
  689. // The following doesn't need to be true. We may copy prop a constant into an object sym, which has
  690. // previously been prepared for type check sequence optimization.
  691. // Assert(!propertySym->m_stackSym->m_isIntConst || !propertySym->HasObjectTypeSym());
  692. // The following doesn't need to be true. We may copy prop the object sym into a field load or store
  693. // that doesn't have object type spec info and hence the operand wasn't prepared and doesn't have a write
  694. // guard. The object sym, however, may have other field operations which are object type specialized and
  695. // thus the type sym for it has been created.
  696. // Assert(propertySym->HasObjectTypeSym() == propertySym->HasWriteGuardSym());
  697. return propertySym->HasObjectTypeSym();
  698. }
  699. bool
  700. GlobOpt::PreparePropertySymOpndForTypeCheckSeq(IR::PropertySymOpnd * propertySymOpnd, IR::Instr* instr, Loop * loop)
  701. {
  702. if (!DoFieldRefOpts(loop) || !OpCodeAttr::FastFldInstr(instr->m_opcode) || instr->CallsAccessor())
  703. {
  704. return false;
  705. }
  706. if (!propertySymOpnd->HasObjTypeSpecFldInfo())
  707. {
  708. return false;
  709. }
  710. ObjTypeSpecFldInfo* info = propertySymOpnd->GetObjTypeSpecInfo();
  711. if (info->UsesAccessor() || info->IsRootObjectNonConfigurableFieldLoad())
  712. {
  713. return false;
  714. }
  715. if (info->IsPoly() && !info->GetEquivalentTypeSet())
  716. {
  717. return false;
  718. }
  719. PropertySym * propertySym = propertySymOpnd->m_sym->AsPropertySym();
  720. PreparePropertySymForTypeCheckSeq(propertySym);
  721. propertySymOpnd->SetTypeCheckSeqCandidate(true);
  722. propertySymOpnd->SetIsBeingStored(propertySymOpnd == instr->GetDst());
  723. return true;
  724. }
  725. bool
  726. GlobOpt::CheckIfPropOpEmitsTypeCheck(IR::Instr *instr, IR::PropertySymOpnd *opnd)
  727. {
  728. if (!DoFieldRefOpts() || !OpCodeAttr::FastFldInstr(instr->m_opcode))
  729. {
  730. return false;
  731. }
  732. if (!opnd->IsTypeCheckSeqCandidate())
  733. {
  734. return false;
  735. }
  736. return CheckIfInstrInTypeCheckSeqEmitsTypeCheck(instr, opnd);
  737. }
  738. IR::PropertySymOpnd *
  739. GlobOpt::CreateOpndForTypeCheckOnly(IR::PropertySymOpnd* opnd, Func* func)
  740. {
  741. // Used only for CheckObjType instruction today. Future users should make a call
  742. // whether the new operand is jit optimized in their scenario or not.
  743. Assert(!opnd->IsRootObjectNonConfigurableFieldLoad());
  744. IR::PropertySymOpnd *newOpnd = opnd->CopyCommon(func);
  745. newOpnd->SetObjTypeSpecFldInfo(opnd->GetObjTypeSpecInfo());
  746. newOpnd->SetUsesAuxSlot(opnd->UsesAuxSlot());
  747. newOpnd->SetSlotIndex(opnd->GetSlotIndex());
  748. newOpnd->objTypeSpecFlags = opnd->objTypeSpecFlags;
  749. // If we're turning the instruction owning this operand into a CheckObjType, we will do a type check here
  750. // only for the sake of downstream instructions, so the flags pertaining to this property access are
  751. // irrelevant, because we don't do a property access here.
  752. newOpnd->SetTypeCheckOnly(true);
  753. newOpnd->usesFixedValue = false;
  754. newOpnd->finalType = opnd->finalType;
  755. newOpnd->guardedPropOps = opnd->guardedPropOps != nullptr ? opnd->guardedPropOps->CopyNew() : nullptr;
  756. newOpnd->writeGuards = opnd->writeGuards != nullptr ? opnd->writeGuards->CopyNew() : nullptr;
  757. newOpnd->SetIsJITOptimizedReg(true);
  758. return newOpnd;
  759. }
  760. bool
  761. GlobOpt::FinishOptPropOp(IR::Instr *instr, IR::PropertySymOpnd *opnd, BasicBlock* block, bool* emitsTypeCheckOut, bool* changesTypeValueOut)
  762. {
  763. if (!DoFieldRefOpts() || !OpCodeAttr::FastFldInstr(instr->m_opcode))
  764. {
  765. return false;
  766. }
  767. bool isTypeCheckSeqCandidate = opnd->IsTypeCheckSeqCandidate();
  768. bool isObjTypeSpecialized = false;
  769. bool isObjTypeChecked = false;
  770. if (isTypeCheckSeqCandidate)
  771. {
  772. isObjTypeSpecialized = ProcessPropOpInTypeCheckSeq<true>(instr, opnd, block, emitsTypeCheckOut, changesTypeValueOut, &isObjTypeChecked);
  773. }
  774. if (opnd == instr->GetDst() && this->objectTypeSyms)
  775. {
  776. if (block == nullptr)
  777. {
  778. block = this->currentBlock;
  779. }
  780. // This is a property store that may change the layout of the object that it stores to. This means that
  781. // it may change any aliased object. Do two things to address this:
  782. // - Add all object types in this function to the set that may have had a property added. This will prevent
  783. // final type optimization across this instruction. (Only needed here for non-specialized stores.)
  784. // - Kill all type symbols that currently hold object-header-inlined types. Any of them may have their layout
  785. // changed by the addition of a property.
  786. SymID opndId = opnd->HasObjectTypeSym() ? opnd->GetObjectTypeSym()->m_id : -1;
  787. if (!isObjTypeSpecialized || opnd->IsBeingAdded())
  788. {
  789. if (block->globOptData.maybeWrittenTypeSyms == nullptr)
  790. {
  791. block->globOptData.maybeWrittenTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  792. }
  793. if (isObjTypeSpecialized)
  794. {
  795. // The current object will be protected by a type check, unless no further accesses to it are
  796. // protected by this access.
  797. Assert(this->objectTypeSyms->Test(opndId));
  798. this->objectTypeSyms->Clear(opndId);
  799. }
  800. block->globOptData.maybeWrittenTypeSyms->Or(this->objectTypeSyms);
  801. if (isObjTypeSpecialized)
  802. {
  803. this->objectTypeSyms->Set(opndId);
  804. }
  805. }
  806. if (!isObjTypeSpecialized || opnd->ChangesObjectLayout())
  807. {
  808. this->KillObjectHeaderInlinedTypeSyms(block, isObjTypeSpecialized, opndId);
  809. }
  810. else if (!isObjTypeChecked && this->HasLiveObjectHeaderInlinedTypeSym(block, true, opndId))
  811. {
  812. opnd->SetTypeCheckRequired(true);
  813. }
  814. }
  815. return isObjTypeSpecialized;
  816. }
  817. void
  818. GlobOpt::KillObjectHeaderInlinedTypeSyms(BasicBlock *block, bool isObjTypeSpecialized, SymID opndId)
  819. {
  820. this->MapObjectHeaderInlinedTypeSymsUntil(block, isObjTypeSpecialized, opndId, [&](SymID symId)->bool { this->currentBlock->globOptData.liveFields->Clear(symId); return false; });
  821. }
  822. bool
  823. GlobOpt::HasLiveObjectHeaderInlinedTypeSym(BasicBlock *block, bool isObjTypeSpecialized, SymID opndId)
  824. {
  825. return this->MapObjectHeaderInlinedTypeSymsUntil(block, true, opndId, [&](SymID symId)->bool { return this->currentBlock->globOptData.liveFields->Test(symId); });
  826. }
  827. template<class Fn>
  828. bool
  829. GlobOpt::MapObjectHeaderInlinedTypeSymsUntil(BasicBlock *block, bool isObjTypeSpecialized, SymID opndId, Fn fn)
  830. {
  831. if (this->objectTypeSyms == nullptr)
  832. {
  833. return false;
  834. }
  835. FOREACH_BITSET_IN_SPARSEBV(symId, this->objectTypeSyms)
  836. {
  837. if (symId == opndId && isObjTypeSpecialized)
  838. {
  839. // The current object will be protected by a type check, unless no further accesses to it are
  840. // protected by this access.
  841. continue;
  842. }
  843. Value *value = block->globOptData.FindObjectTypeValue(symId);
  844. if (value)
  845. {
  846. JsTypeValueInfo *valueInfo = value->GetValueInfo()->AsJsType();
  847. Assert(valueInfo);
  848. if (valueInfo->GetJsType() != nullptr)
  849. {
  850. JITTypeHolder type(valueInfo->GetJsType());
  851. if (Js::DynamicType::Is(type->GetTypeId()))
  852. {
  853. if (type->GetTypeHandler()->IsObjectHeaderInlinedTypeHandler())
  854. {
  855. if (fn(symId))
  856. {
  857. return true;
  858. }
  859. }
  860. }
  861. }
  862. else if (valueInfo->GetJsTypeSet())
  863. {
  864. Js::EquivalentTypeSet *typeSet = valueInfo->GetJsTypeSet();
  865. for (uint16 i = 0; i < typeSet->GetCount(); i++)
  866. {
  867. JITTypeHolder type = typeSet->GetType(i);
  868. if (type != nullptr && Js::DynamicType::Is(type->GetTypeId()))
  869. {
  870. if (type->GetTypeHandler()->IsObjectHeaderInlinedTypeHandler())
  871. {
  872. if (fn(symId))
  873. {
  874. return true;
  875. }
  876. break;
  877. }
  878. }
  879. }
  880. }
  881. }
  882. }
  883. NEXT_BITSET_IN_SPARSEBV;
  884. return false;
  885. }
  886. bool
  887. GlobOpt::AreTypeSetsIdentical(Js::EquivalentTypeSet * leftTypeSet, Js::EquivalentTypeSet * rightTypeSet)
  888. {
  889. return Js::EquivalentTypeSet::AreIdentical(leftTypeSet, rightTypeSet);
  890. }
  891. bool
  892. GlobOpt::IsSubsetOf(Js::EquivalentTypeSet * leftTypeSet, Js::EquivalentTypeSet * rightTypeSet)
  893. {
  894. return Js::EquivalentTypeSet::IsSubsetOf(leftTypeSet, rightTypeSet);
  895. }
  896. bool
  897. GlobOpt::CompareCurrentTypesWithExpectedTypes(JsTypeValueInfo *valueInfo, IR::PropertySymOpnd * propertySymOpnd)
  898. {
  899. bool isTypeDead = propertySymOpnd->IsTypeDead();
  900. if (valueInfo == nullptr || (valueInfo->GetJsType() == nullptr && valueInfo->GetJsTypeSet() == nullptr))
  901. {
  902. // No upstream types. Do a type check.
  903. return !isTypeDead;
  904. }
  905. if (!propertySymOpnd->HasEquivalentTypeSet() || propertySymOpnd->NeedsMonoCheck())
  906. {
  907. JITTypeHolder opndType = propertySymOpnd->GetType();
  908. if (valueInfo->GetJsType() != nullptr)
  909. {
  910. if (valueInfo->GetJsType() == propertySymOpnd->GetType())
  911. {
  912. return true;
  913. }
  914. if (propertySymOpnd->HasInitialType() && valueInfo->GetJsType() == propertySymOpnd->GetInitialType())
  915. {
  916. return !isTypeDead;
  917. }
  918. return false;
  919. }
  920. else
  921. {
  922. Assert(valueInfo->GetJsTypeSet());
  923. Js::EquivalentTypeSet *valueTypeSet = valueInfo->GetJsTypeSet();
  924. if (valueTypeSet->Contains(opndType))
  925. {
  926. return !isTypeDead;
  927. }
  928. if (propertySymOpnd->HasInitialType() && valueTypeSet->Contains(propertySymOpnd->GetInitialType()))
  929. {
  930. return !isTypeDead;
  931. }
  932. return false;
  933. }
  934. }
  935. else
  936. {
  937. Js::EquivalentTypeSet * opndTypeSet = propertySymOpnd->GetEquivalentTypeSet();
  938. if (valueInfo->GetJsType() != nullptr)
  939. {
  940. uint16 checkedTypeSetIndex;
  941. if (opndTypeSet->Contains(valueInfo->GetJsType(), &checkedTypeSetIndex))
  942. {
  943. return true;
  944. }
  945. return false;
  946. }
  947. else
  948. {
  949. if (IsSubsetOf(valueInfo->GetJsTypeSet(), opndTypeSet))
  950. {
  951. return true;
  952. }
  953. if (propertySymOpnd->IsMono() ?
  954. valueInfo->GetJsTypeSet()->Contains(propertySymOpnd->GetFirstEquivalentType()) :
  955. IsSubsetOf(opndTypeSet, valueInfo->GetJsTypeSet()))
  956. {
  957. return true;
  958. }
  959. return false;
  960. }
  961. }
  962. }
  963. bool
  964. GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd)
  965. {
  966. return ProcessPropOpInTypeCheckSeq<true>(instr, opnd, this->currentBlock);
  967. }
  968. bool GlobOpt::CheckIfInstrInTypeCheckSeqEmitsTypeCheck(IR::Instr* instr, IR::PropertySymOpnd *opnd)
  969. {
  970. bool emitsTypeCheck;
  971. ProcessPropOpInTypeCheckSeq<false>(instr, opnd, this->currentBlock, &emitsTypeCheck);
  972. return emitsTypeCheck;
  973. }
  974. template<bool makeChanges>
  975. bool
  976. GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd, BasicBlock* block, bool* emitsTypeCheckOut, bool* changesTypeValueOut, bool *isTypeCheckedOut)
  977. {
  978. // We no longer mark types as dead in the backward pass, so we should never see an instr with a dead type here
  979. // during the forward pass. For the time being we've retained the logic below to deal with dead types in case
  980. // we ever wanted to revert back to more aggressive type killing that we had before.
  981. Assert(!opnd->IsTypeDead());
  982. Assert(opnd->IsTypeCheckSeqCandidate());
  983. Assert(opnd->HasObjectTypeSym());
  984. bool isStore = opnd == instr->GetDst();
  985. bool isTypeDead = opnd->IsTypeDead();
  986. bool consumeType = makeChanges && !IsLoopPrePass();
  987. bool produceType = makeChanges && !isTypeDead;
  988. bool isSpecialized = false;
  989. bool emitsTypeCheck = false;
  990. bool addsProperty = false;
  991. if (block == nullptr)
  992. {
  993. block = this->currentBlock;
  994. }
  995. StackSym * typeSym = opnd->GetObjectTypeSym();
  996. #if DBG
  997. uint16 typeCheckSeqFlagsBefore;
  998. Value* valueBefore = nullptr;
  999. JsTypeValueInfo* valueInfoBefore = nullptr;
  1000. if (!makeChanges)
  1001. {
  1002. typeCheckSeqFlagsBefore = opnd->GetTypeCheckSeqFlags();
  1003. valueBefore = block->globOptData.FindObjectTypeValue(typeSym);
  1004. if (valueBefore != nullptr)
  1005. {
  1006. Assert(valueBefore->GetValueInfo() != nullptr && valueBefore->GetValueInfo()->IsJsType());
  1007. valueInfoBefore = valueBefore->GetValueInfo()->AsJsType();
  1008. }
  1009. }
  1010. #endif
  1011. Value *value = block->globOptData.FindObjectTypeValue(typeSym);
  1012. JsTypeValueInfo* valueInfo = value != nullptr ? value->GetValueInfo()->AsJsType() : nullptr;
  1013. if (consumeType && valueInfo != nullptr)
  1014. {
  1015. opnd->SetTypeAvailable(true);
  1016. }
  1017. if (opnd->HasTypeMismatch())
  1018. {
  1019. if (emitsTypeCheckOut != nullptr)
  1020. {
  1021. *emitsTypeCheckOut = false;
  1022. }
  1023. if (changesTypeValueOut != nullptr)
  1024. {
  1025. *changesTypeValueOut = false;
  1026. }
  1027. return false;
  1028. }
  1029. bool doEquivTypeCheck = opnd->HasEquivalentTypeSet() && !opnd->NeedsMonoCheck();
  1030. if (!doEquivTypeCheck)
  1031. {
  1032. AssertOrFailFast(!opnd->NeedsDepolymorphication());
  1033. // We need a monomorphic type check here (e.g., final type opt, fixed field check on non-proto property).
  1034. JITTypeHolder opndType = opnd->GetType();
  1035. if (valueInfo == nullptr || (valueInfo->GetJsType() == nullptr && valueInfo->GetJsTypeSet() == nullptr))
  1036. {
  1037. // This is the initial type check.
  1038. opnd->SetTypeAvailable(false);
  1039. isSpecialized = !isTypeDead;
  1040. emitsTypeCheck = isSpecialized;
  1041. addsProperty = isStore && isSpecialized && opnd->HasInitialType();
  1042. if (produceType)
  1043. {
  1044. SetObjectTypeFromTypeSym(typeSym, opndType, nullptr, block);
  1045. }
  1046. }
  1047. else if (valueInfo->GetJsType() != nullptr)
  1048. {
  1049. // We have a monomorphic type check upstream. Check against initial/final type.
  1050. const JITTypeHolder valueType(valueInfo->GetJsType());
  1051. if (valueType == opndType)
  1052. {
  1053. // The type on this instruction matches the live value in the value table, so there is no need to
  1054. // refresh the value table.
  1055. isSpecialized = true;
  1056. if (isTypeCheckedOut)
  1057. {
  1058. *isTypeCheckedOut = true;
  1059. }
  1060. if (consumeType)
  1061. {
  1062. opnd->SetTypeChecked(true);
  1063. }
  1064. }
  1065. else if (opnd->HasInitialType() && valueType == opnd->GetInitialType())
  1066. {
  1067. // Checked type matches the initial type at this store.
  1068. bool objectMayHaveAcquiredAdditionalProperties =
  1069. block->globOptData.maybeWrittenTypeSyms &&
  1070. block->globOptData.maybeWrittenTypeSyms->Test(typeSym->m_id);
  1071. if (consumeType)
  1072. {
  1073. opnd->SetTypeChecked(!objectMayHaveAcquiredAdditionalProperties);
  1074. opnd->SetInitialTypeChecked(!objectMayHaveAcquiredAdditionalProperties);
  1075. }
  1076. if (produceType)
  1077. {
  1078. SetObjectTypeFromTypeSym(typeSym, opndType, nullptr, block);
  1079. }
  1080. isSpecialized = !isTypeDead || !objectMayHaveAcquiredAdditionalProperties;
  1081. emitsTypeCheck = isSpecialized && objectMayHaveAcquiredAdditionalProperties;
  1082. addsProperty = isSpecialized;
  1083. if (isTypeCheckedOut)
  1084. {
  1085. *isTypeCheckedOut = !objectMayHaveAcquiredAdditionalProperties;
  1086. }
  1087. }
  1088. else
  1089. {
  1090. // This must be a type mismatch situation, because the value is available, but doesn't match either
  1091. // the current type or the initial type. We will not optimize this instruction and we do not produce
  1092. // a new type value here.
  1093. isSpecialized = false;
  1094. if (makeChanges)
  1095. {
  1096. opnd->SetTypeMismatch(true);
  1097. }
  1098. }
  1099. }
  1100. else
  1101. {
  1102. // We have an equivalent type check upstream, but we require a particular type at this point. We
  1103. // can't treat it as "checked", but we may benefit from checking for the required type.
  1104. Assert(valueInfo->GetJsTypeSet());
  1105. Js::EquivalentTypeSet *valueTypeSet = valueInfo->GetJsTypeSet();
  1106. if (valueTypeSet->Contains(opndType))
  1107. {
  1108. // Required type is in the type set we've checked. Check for the required type here, and
  1109. // note in the value info that we've narrowed down to this type. (But leave the type set in the
  1110. // value info so it can be merged with the same type set on other paths.)
  1111. isSpecialized = !isTypeDead;
  1112. emitsTypeCheck = isSpecialized;
  1113. if (produceType)
  1114. {
  1115. SetSingleTypeOnObjectTypeValue(value, opndType);
  1116. }
  1117. }
  1118. else if (opnd->HasInitialType() && valueTypeSet->Contains(opnd->GetInitialType()))
  1119. {
  1120. // Required initial type is in the type set we've checked. Check for the initial type here, and
  1121. // note in the value info that we've narrowed down to this type. (But leave the type set in the
  1122. // value info so it can be merged with the same type set on other paths.)
  1123. isSpecialized = !isTypeDead;
  1124. emitsTypeCheck = isSpecialized;
  1125. addsProperty = isSpecialized;
  1126. if (produceType)
  1127. {
  1128. SetSingleTypeOnObjectTypeValue(value, opndType);
  1129. }
  1130. }
  1131. else
  1132. {
  1133. // This must be a type mismatch situation, because the value is available, but doesn't match either
  1134. // the current type or the initial type. We will not optimize this instruction and we do not produce
  1135. // a new type value here.
  1136. isSpecialized = false;
  1137. if (makeChanges)
  1138. {
  1139. opnd->SetTypeMismatch(true);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. else
  1145. {
  1146. Assert(!opnd->NeedsMonoCheck());
  1147. Js::EquivalentTypeSet * opndTypeSet = opnd->GetEquivalentTypeSet();
  1148. uint16 checkedTypeSetIndex = (uint16)-1;
  1149. if (opnd->NeedsDepolymorphication())
  1150. {
  1151. // The opnd's type set (opndTypeSet) is non-equivalent. Test all the types coming from the valueInfo.
  1152. // If all of them are contained in opndTypeSet, and all of them have the same slot index in opnd's
  1153. // objtypespecfldinfo, then we can use that slot index and treat the set as equivalent.
  1154. // (Also test whether all types do/don't use aux slots.)
  1155. uint16 slotIndex = Js::Constants::NoSlot;
  1156. bool auxSlot = false;
  1157. // Do this work only if there is an upstream type value. We don't attempt to do a type check based on
  1158. // a non-equivalent set.
  1159. if (valueInfo != nullptr)
  1160. {
  1161. if (valueInfo->GetJsType() != nullptr)
  1162. {
  1163. opnd->TryDepolymorphication(valueInfo->GetJsType(), Js::Constants::NoSlot, false, &slotIndex, &auxSlot, &checkedTypeSetIndex);
  1164. }
  1165. else if (valueInfo->GetJsTypeSet() != nullptr)
  1166. {
  1167. Js::EquivalentTypeSet *typeSet = valueInfo->GetJsTypeSet();
  1168. for (uint16 i = 0; i < typeSet->GetCount(); i++)
  1169. {
  1170. opnd->TryDepolymorphication(typeSet->GetType(i), slotIndex, auxSlot, &slotIndex, &auxSlot);
  1171. if (slotIndex == Js::Constants::NoSlot)
  1172. {
  1173. // Indicates failure/mismatch. We're done.
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. if (slotIndex == Js::Constants::NoSlot)
  1180. {
  1181. // Indicates failure/mismatch
  1182. isSpecialized = false;
  1183. if (makeChanges)
  1184. {
  1185. opnd->SetTypeMismatch(true);
  1186. }
  1187. }
  1188. else
  1189. {
  1190. // Indicates we can optimize, as all upstream types are equivalent here.
  1191. opnd->SetSlotIndex(slotIndex);
  1192. opnd->SetUsesAuxSlot(auxSlot);
  1193. opnd->GetObjTypeSpecInfo()->SetSlotIndex(slotIndex);
  1194. opnd->GetObjTypeSpecInfo()->SetUsesAuxSlot(auxSlot);
  1195. isSpecialized = true;
  1196. if (isTypeCheckedOut)
  1197. {
  1198. *isTypeCheckedOut = true;
  1199. }
  1200. if (consumeType)
  1201. {
  1202. opnd->SetTypeChecked(true);
  1203. }
  1204. if (checkedTypeSetIndex != (uint16)-1)
  1205. {
  1206. opnd->SetCheckedTypeSetIndex(checkedTypeSetIndex);
  1207. }
  1208. }
  1209. }
  1210. else if (valueInfo == nullptr || (valueInfo->GetJsType() == nullptr && valueInfo->GetJsTypeSet() == nullptr))
  1211. {
  1212. // If we don't have a value for the type we will have to emit a type check and we produce a new type value here.
  1213. if (produceType)
  1214. {
  1215. if (opnd->IsMono())
  1216. {
  1217. SetObjectTypeFromTypeSym(typeSym, opnd->GetFirstEquivalentType(), nullptr, block);
  1218. }
  1219. else
  1220. {
  1221. SetObjectTypeFromTypeSym(typeSym, nullptr, opndTypeSet, block);
  1222. }
  1223. }
  1224. isSpecialized = !isTypeDead;
  1225. emitsTypeCheck = isSpecialized;
  1226. }
  1227. else if (valueInfo->GetJsType() != nullptr ?
  1228. opndTypeSet->Contains(valueInfo->GetJsType(), &checkedTypeSetIndex) :
  1229. IsSubsetOf(valueInfo->GetJsTypeSet(), opndTypeSet))
  1230. {
  1231. // All the types in the value info are contained in the set required by this access,
  1232. // meaning that they're equivalent to the opnd's type set.
  1233. // We won't have a type check, and we don't need to touch the type value.
  1234. isSpecialized = true;
  1235. if (isTypeCheckedOut)
  1236. {
  1237. *isTypeCheckedOut = true;
  1238. }
  1239. if (consumeType)
  1240. {
  1241. opnd->SetTypeChecked(true);
  1242. }
  1243. if (checkedTypeSetIndex != (uint16)-1)
  1244. {
  1245. opnd->SetCheckedTypeSetIndex(checkedTypeSetIndex);
  1246. }
  1247. }
  1248. else if (valueInfo->GetJsTypeSet() &&
  1249. (opnd->IsMono() ?
  1250. valueInfo->GetJsTypeSet()->Contains(opnd->GetFirstEquivalentType()) :
  1251. IsSubsetOf(opndTypeSet, valueInfo->GetJsTypeSet())
  1252. )
  1253. )
  1254. {
  1255. // We have an equivalent type check upstream, but we require a tighter type check at this point.
  1256. // We can't treat the operand as "checked", but check for equivalence with the tighter set and update the
  1257. // value info.
  1258. if (produceType)
  1259. {
  1260. if (opnd->IsMono())
  1261. {
  1262. SetObjectTypeFromTypeSym(typeSym, opnd->GetFirstEquivalentType(), nullptr, block);
  1263. }
  1264. else
  1265. {
  1266. SetObjectTypeFromTypeSym(typeSym, nullptr, opndTypeSet, block);
  1267. }
  1268. }
  1269. isSpecialized = !isTypeDead;
  1270. emitsTypeCheck = isSpecialized;
  1271. }
  1272. else
  1273. {
  1274. // This must be a type mismatch situation, because the value is available, but doesn't match either
  1275. // the current type or the initial type. We will not optimize this instruction and we do not produce
  1276. // a new type value here.
  1277. isSpecialized = false;
  1278. if (makeChanges)
  1279. {
  1280. opnd->SetTypeMismatch(true);
  1281. }
  1282. }
  1283. }
  1284. Assert(isSpecialized || (!emitsTypeCheck && !addsProperty));
  1285. if (consumeType && opnd->MayNeedWriteGuardProtection())
  1286. {
  1287. Assert(!isStore);
  1288. PropertySym *propertySym = opnd->m_sym->AsPropertySym();
  1289. Assert(propertySym->m_writeGuardSym);
  1290. opnd->SetWriteGuardChecked(!!block->globOptData.liveFields->Test(propertySym->m_writeGuardSym->m_id));
  1291. }
  1292. // Even specialized property adds must kill all types for other property adds. That's because any other object sym
  1293. // may, in fact, be an alias of the instance whose type is being modified here. (see Windows Blue Bug 541876)
  1294. if (makeChanges && addsProperty)
  1295. {
  1296. Assert(isStore && isSpecialized);
  1297. Assert(this->objectTypeSyms != nullptr);
  1298. Assert(this->objectTypeSyms->Test(typeSym->m_id));
  1299. if (block->globOptData.maybeWrittenTypeSyms == nullptr)
  1300. {
  1301. block->globOptData.maybeWrittenTypeSyms = JitAnew(this->alloc, BVSparse<JitArenaAllocator>, this->alloc);
  1302. }
  1303. this->objectTypeSyms->Clear(typeSym->m_id);
  1304. block->globOptData.maybeWrittenTypeSyms->Or(this->objectTypeSyms);
  1305. this->objectTypeSyms->Set(typeSym->m_id);
  1306. }
  1307. if (produceType && emitsTypeCheck && opnd->IsMono())
  1308. {
  1309. // Consider (ObjTypeSpec): Represent maybeWrittenTypeSyms as a flag on value info of the type sym.
  1310. if (block->globOptData.maybeWrittenTypeSyms != nullptr)
  1311. {
  1312. // We're doing a type check here, so objtypespec of property adds is safe for this type
  1313. // from this point forward.
  1314. block->globOptData.maybeWrittenTypeSyms->Clear(typeSym->m_id);
  1315. }
  1316. }
  1317. // Consider (ObjTypeSpec): Enable setting write guards live on instructions hoisted out of loops. Note that produceType
  1318. // is false if the type values on loop back edges don't match (see earlier comments).
  1319. // This means that hoisted instructions won't set write guards live if the type changes in the loop, even if
  1320. // the corresponding properties have not been written inside the loop. This may result in some unnecessary type
  1321. // checks and bailouts inside the loop. To enable this, we would need to verify the write guards are still live
  1322. // on the back edge (much like we're doing for types above).
  1323. // Consider (ObjTypeSpec): Support polymorphic write guards as well. We can't currently distinguish between mono and
  1324. // poly write guards, and a type check can only protect operations matching with respect to polymorphism (see
  1325. // BackwardPass::TrackObjTypeSpecProperties for details), so for now we only target monomorphic operations.
  1326. if (produceType && emitsTypeCheck && opnd->IsMono())
  1327. {
  1328. // If the type check we'll emit here protects some property operations that require a write guard (i.e.
  1329. // they must do an extra type check and property guard check, if they have been written to in this
  1330. // function), let's mark the write guards as live here, so we can accurately track if their properties
  1331. // have been written to. Make sure we only set those that we'll actually guard, i.e. those that match
  1332. // with respect to polymorphism.
  1333. if (opnd->GetWriteGuards() != nullptr)
  1334. {
  1335. block->globOptData.liveFields->Or(opnd->GetWriteGuards());
  1336. }
  1337. }
  1338. if (makeChanges && isTypeDead)
  1339. {
  1340. this->KillObjectType(opnd->GetObjectSym(), block->globOptData.liveFields);
  1341. }
  1342. #if DBG
  1343. if (!makeChanges)
  1344. {
  1345. uint16 typeCheckSeqFlagsAfter = opnd->GetTypeCheckSeqFlags();
  1346. Assert(typeCheckSeqFlagsBefore == typeCheckSeqFlagsAfter);
  1347. Value* valueAfter = block->globOptData.FindObjectTypeValue(typeSym);
  1348. Assert(valueBefore == valueAfter);
  1349. if (valueAfter != nullptr)
  1350. {
  1351. Assert(valueBefore != nullptr);
  1352. Assert(valueAfter->GetValueInfo() != nullptr && valueAfter->GetValueInfo()->IsJsType());
  1353. JsTypeValueInfo* valueInfoAfter = valueAfter->GetValueInfo()->AsJsType();
  1354. Assert(valueInfoBefore == valueInfoAfter);
  1355. Assert(valueInfoBefore->GetJsType() == valueInfoAfter->GetJsType());
  1356. Assert(valueInfoBefore->GetJsTypeSet() == valueInfoAfter->GetJsTypeSet());
  1357. }
  1358. }
  1359. #endif
  1360. if (emitsTypeCheckOut != nullptr)
  1361. {
  1362. *emitsTypeCheckOut = emitsTypeCheck;
  1363. }
  1364. if (changesTypeValueOut != nullptr)
  1365. {
  1366. *changesTypeValueOut = isSpecialized && (emitsTypeCheck || addsProperty);
  1367. }
  1368. return isSpecialized;
  1369. }
  1370. void
  1371. GlobOpt::OptNewScObject(IR::Instr** instrPtr, Value* srcVal)
  1372. {
  1373. IR::Instr *&instr = *instrPtr;
  1374. if (!instr->IsNewScObjectInstr() || IsLoopPrePass() || !this->DoFieldRefOpts() || PHASE_OFF(Js::ObjTypeSpecNewObjPhase, this->func))
  1375. {
  1376. return;
  1377. }
  1378. bool isCtorInlined = instr->m_opcode == Js::OpCode::NewScObjectNoCtor;
  1379. const JITTimeConstructorCache * ctorCache = instr->IsProfiledInstr() ?
  1380. instr->m_func->GetConstructorCache(static_cast<Js::ProfileId>(instr->AsProfiledInstr()->u.profileId)) : nullptr;
  1381. // TODO: OOP JIT, enable assert
  1382. //Assert(ctorCache == nullptr || srcVal->GetValueInfo()->IsVarConstant() && Js::JavascriptFunction::Is(srcVal->GetValueInfo()->AsVarConstant()->VarValue()));
  1383. Assert(ctorCache == nullptr || !ctorCache->IsTypeFinal() || ctorCache->CtorHasNoExplicitReturnValue());
  1384. if (ctorCache != nullptr && !ctorCache->SkipNewScObject() && (isCtorInlined || ctorCache->IsTypeFinal()))
  1385. {
  1386. GenerateBailAtOperation(instrPtr, IR::BailOutFailedCtorGuardCheck);
  1387. }
  1388. }
  1389. void
  1390. GlobOpt::ValueNumberObjectType(IR::Opnd *dstOpnd, IR::Instr *instr)
  1391. {
  1392. if (!dstOpnd->IsRegOpnd())
  1393. {
  1394. return;
  1395. }
  1396. if (dstOpnd->AsRegOpnd()->m_sym->IsTypeSpec())
  1397. {
  1398. return;
  1399. }
  1400. if (instr->IsNewScObjectInstr())
  1401. {
  1402. // If we have a NewScObj* for which we have a valid constructor cache we know what type the created object will have.
  1403. // Let's produce the type value accordingly so we don't insert a type check and bailout in the constructor and
  1404. // potentially further downstream.
  1405. Assert(!PHASE_OFF(Js::ObjTypeSpecNewObjPhase, this->func) || !instr->HasBailOutInfo());
  1406. if (instr->HasBailOutInfo())
  1407. {
  1408. Assert(instr->IsProfiledInstr());
  1409. Assert(instr->GetBailOutKind() == IR::BailOutFailedCtorGuardCheck);
  1410. bool isCtorInlined = instr->m_opcode == Js::OpCode::NewScObjectNoCtor;
  1411. JITTimeConstructorCache * ctorCache = instr->m_func->GetConstructorCache(static_cast<Js::ProfileId>(instr->AsProfiledInstr()->u.profileId));
  1412. Assert(ctorCache != nullptr && (isCtorInlined || ctorCache->IsTypeFinal()));
  1413. StackSym* objSym = dstOpnd->AsRegOpnd()->m_sym;
  1414. StackSym* dstTypeSym = EnsureObjectTypeSym(objSym);
  1415. Assert(this->currentBlock->globOptData.FindValue(dstTypeSym) == nullptr);
  1416. SetObjectTypeFromTypeSym(dstTypeSym, ctorCache->GetType(), nullptr);
  1417. }
  1418. }
  1419. else
  1420. {
  1421. // If the dst opnd is a reg that has a type sym associated with it, then we are either killing
  1422. // the type's existing value or (in the case of a reg copy) assigning it the value of
  1423. // the src's type sym (if any). If the dst doesn't have a type sym, but the src does, let's
  1424. // give dst a new type sym and transfer the value.
  1425. Value *newValue = nullptr;
  1426. IR::Opnd * srcOpnd = instr->GetSrc1();
  1427. if (instr->m_opcode == Js::OpCode::Ld_A && srcOpnd->IsRegOpnd() &&
  1428. !srcOpnd->AsRegOpnd()->m_sym->IsTypeSpec() && srcOpnd->AsRegOpnd()->m_sym->HasObjectTypeSym())
  1429. {
  1430. StackSym *srcTypeSym = srcOpnd->AsRegOpnd()->m_sym->GetObjectTypeSym();
  1431. newValue = this->currentBlock->globOptData.FindValue(srcTypeSym);
  1432. }
  1433. if (newValue == nullptr)
  1434. {
  1435. if (dstOpnd->AsRegOpnd()->m_sym->HasObjectTypeSym())
  1436. {
  1437. StackSym * typeSym = dstOpnd->AsRegOpnd()->m_sym->GetObjectTypeSym();
  1438. this->currentBlock->globOptData.ClearSymValue(typeSym);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. Assert(newValue->GetValueInfo()->IsJsType());
  1444. StackSym * typeSym;
  1445. if (!dstOpnd->AsRegOpnd()->m_sym->HasObjectTypeSym())
  1446. {
  1447. typeSym = nullptr;
  1448. }
  1449. typeSym = EnsureObjectTypeSym(dstOpnd->AsRegOpnd()->m_sym);
  1450. this->currentBlock->globOptData.SetValue(newValue, typeSym);
  1451. }
  1452. }
  1453. }
  1454. IR::Instr *
  1455. GlobOpt::SetTypeCheckBailOut(IR::Opnd *opnd, IR::Instr *instr, BailOutInfo *bailOutInfo)
  1456. {
  1457. if (this->IsLoopPrePass() || !opnd->IsSymOpnd())
  1458. {
  1459. return instr;
  1460. }
  1461. if (!opnd->AsSymOpnd()->IsPropertySymOpnd())
  1462. {
  1463. return instr;
  1464. }
  1465. IR::PropertySymOpnd * propertySymOpnd = opnd->AsPropertySymOpnd();
  1466. AssertMsg(propertySymOpnd->TypeCheckSeqBitsSetOnlyIfCandidate(), "Property sym operand optimized despite not being a candidate?");
  1467. AssertMsg(bailOutInfo == nullptr || !instr->HasBailOutInfo(), "Why are we adding new bailout info to an instruction that already has it?");
  1468. auto HandleBailout = [&](IR::BailOutKind bailOutKind)->void {
  1469. // At this point, we have a cached type that is live downstream or the type check is required
  1470. // for a fixed field load. If we can't do away with the type check, then we're going to need bailout,
  1471. // so lets add bailout info if we don't already have it.
  1472. if (!instr->HasBailOutInfo())
  1473. {
  1474. if (bailOutInfo)
  1475. {
  1476. instr = instr->ConvertToBailOutInstr(bailOutInfo, bailOutKind);
  1477. }
  1478. else
  1479. {
  1480. GenerateBailAtOperation(&instr, bailOutKind);
  1481. BailOutInfo *bailOutInfo = instr->GetBailOutInfo();
  1482. // Consider (ObjTypeSpec): If we're checking a fixed field here the bailout could be due to polymorphism or
  1483. // due to a fixed field turning non-fixed. Consider distinguishing between the two.
  1484. bailOutInfo->polymorphicCacheIndex = propertySymOpnd->m_inlineCacheIndex;
  1485. }
  1486. }
  1487. else if (instr->GetBailOutKind() == IR::BailOutMarkTempObject)
  1488. {
  1489. Assert(!bailOutInfo);
  1490. Assert(instr->GetBailOutInfo()->polymorphicCacheIndex == -1);
  1491. instr->SetBailOutKind(bailOutKind | IR::BailOutMarkTempObject);
  1492. instr->GetBailOutInfo()->polymorphicCacheIndex = propertySymOpnd->m_inlineCacheIndex;
  1493. }
  1494. else
  1495. {
  1496. Assert(bailOutKind == instr->GetBailOutKind());
  1497. }
  1498. };
  1499. bool isTypeCheckProtected;
  1500. IR::BailOutKind bailOutKind;
  1501. if (GlobOpt::NeedsTypeCheckBailOut(instr, propertySymOpnd, opnd == instr->GetDst(), &isTypeCheckProtected, &bailOutKind))
  1502. {
  1503. HandleBailout(bailOutKind);
  1504. }
  1505. else
  1506. {
  1507. if (instr->m_opcode == Js::OpCode::LdMethodFromFlags)
  1508. {
  1509. // If LdMethodFromFlags is hoisted to the top of the loop, we should share the same bailout Info.
  1510. // We don't need to do anything for LdMethodFromFlags that cannot be field hoisted.
  1511. HandleBailout(IR::BailOutFailedInlineTypeCheck);
  1512. }
  1513. else if (instr->HasBailOutInfo())
  1514. {
  1515. // If we already have a bailout info, but don't actually need it, let's remove it. This can happen if
  1516. // a CheckFixedFld added by the inliner (with bailout info) determined that the object's type has
  1517. // been checked upstream and no bailout is necessary here.
  1518. if (instr->m_opcode == Js::OpCode::CheckFixedFld)
  1519. {
  1520. AssertMsg(!PHASE_OFF(Js::FixedMethodsPhase, instr->m_func) ||
  1521. !PHASE_OFF(Js::UseFixedDataPropsPhase, instr->m_func), "CheckFixedFld with fixed method/data phase disabled?");
  1522. Assert(isTypeCheckProtected);
  1523. AssertMsg(instr->GetBailOutKind() == IR::BailOutFailedFixedFieldTypeCheck || instr->GetBailOutKind() == IR::BailOutFailedEquivalentFixedFieldTypeCheck,
  1524. "Only BailOutFailed[Equivalent]FixedFieldTypeCheck can be safely removed. Why does CheckFixedFld carry a different bailout kind?.");
  1525. instr->ClearBailOutInfo();
  1526. }
  1527. else if (propertySymOpnd->MayNeedTypeCheckProtection() && propertySymOpnd->IsTypeCheckProtected())
  1528. {
  1529. // Both the type and (if necessary) the proto object have been checked.
  1530. // We're doing a direct slot access. No possibility of bailout here (not even implicit call).
  1531. Assert(instr->GetBailOutKind() == IR::BailOutMarkTempObject);
  1532. instr->ClearBailOutInfo();
  1533. }
  1534. }
  1535. }
  1536. return instr;
  1537. }
  1538. void
  1539. GlobOpt::SetSingleTypeOnObjectTypeValue(Value* value, const JITTypeHolder type)
  1540. {
  1541. UpdateObjectTypeValue(value, type, true, nullptr, false);
  1542. }
  1543. void
  1544. GlobOpt::SetTypeSetOnObjectTypeValue(Value* value, Js::EquivalentTypeSet* typeSet)
  1545. {
  1546. UpdateObjectTypeValue(value, nullptr, false, typeSet, true);
  1547. }
  1548. void
  1549. GlobOpt::UpdateObjectTypeValue(Value* value, const JITTypeHolder type, bool setType, Js::EquivalentTypeSet* typeSet, bool setTypeSet)
  1550. {
  1551. Assert(value->GetValueInfo() != nullptr && value->GetValueInfo()->IsJsType());
  1552. JsTypeValueInfo* valueInfo = value->GetValueInfo()->AsJsType();
  1553. if (valueInfo->GetIsShared())
  1554. {
  1555. valueInfo = valueInfo->Copy(this->alloc);
  1556. value->SetValueInfo(valueInfo);
  1557. }
  1558. if (setType)
  1559. {
  1560. valueInfo->SetJsType(type);
  1561. }
  1562. if (setTypeSet)
  1563. {
  1564. valueInfo->SetJsTypeSet(typeSet);
  1565. }
  1566. }
  1567. void
  1568. GlobOpt::SetObjectTypeFromTypeSym(StackSym *typeSym, Value* value, BasicBlock* block)
  1569. {
  1570. Assert(typeSym != nullptr);
  1571. Assert(value != nullptr);
  1572. Assert(value->GetValueInfo() != nullptr && value->GetValueInfo()->IsJsType());
  1573. SymID typeSymId = typeSym->m_id;
  1574. if (block == nullptr)
  1575. {
  1576. block = this->currentBlock;
  1577. }
  1578. block->globOptData.SetValue(value, typeSym);
  1579. block->globOptData.liveFields->Set(typeSymId);
  1580. }
  1581. void
  1582. GlobOpt::SetObjectTypeFromTypeSym(StackSym *typeSym, const JITTypeHolder type, Js::EquivalentTypeSet * typeSet, BasicBlock* block)
  1583. {
  1584. if (block == nullptr)
  1585. {
  1586. block = this->currentBlock;
  1587. }
  1588. SetObjectTypeFromTypeSym(typeSym, type, typeSet, &block->globOptData);
  1589. }
  1590. void
  1591. GlobOpt::SetObjectTypeFromTypeSym(StackSym *typeSym, const JITTypeHolder type, Js::EquivalentTypeSet * typeSet, GlobOptBlockData *blockData)
  1592. {
  1593. Assert(typeSym != nullptr);
  1594. SymID typeSymId = typeSym->m_id;
  1595. if (blockData == nullptr)
  1596. {
  1597. blockData = &this->currentBlock->globOptData;
  1598. }
  1599. JsTypeValueInfo* valueInfo = JsTypeValueInfo::New(this->alloc, type, typeSet);
  1600. this->SetSymStoreDirect(valueInfo, typeSym);
  1601. Value* value = NewValue(valueInfo);
  1602. blockData->SetValue(value, typeSym);
  1603. blockData->liveFields->Set(typeSymId);
  1604. }
  1605. void
  1606. GlobOpt::KillObjectType(StackSym* objectSym, BVSparse<JitArenaAllocator>* liveFields)
  1607. {
  1608. if (objectSym->IsTypeSpec())
  1609. {
  1610. objectSym = objectSym->GetVarEquivSym(this->func);
  1611. }
  1612. Assert(objectSym);
  1613. // We may be conservatively attempting to kill type syms from object syms that don't actually
  1614. // participate in object type specialization and hence don't actually have type syms (yet).
  1615. if (!objectSym->HasObjectTypeSym())
  1616. {
  1617. return;
  1618. }
  1619. if (liveFields == nullptr)
  1620. {
  1621. liveFields = this->currentBlock->globOptData.liveFields;
  1622. }
  1623. liveFields->Clear(objectSym->GetObjectTypeSym()->m_id);
  1624. }
  1625. void
  1626. GlobOpt::KillAllObjectTypes(BVSparse<JitArenaAllocator>* liveFields)
  1627. {
  1628. if (this->objectTypeSyms && liveFields)
  1629. {
  1630. liveFields->Minus(this->objectTypeSyms);
  1631. }
  1632. }
  1633. void
  1634. GlobOpt::EndFieldLifetime(IR::SymOpnd *symOpnd)
  1635. {
  1636. this->currentBlock->globOptData.liveFields->Clear(symOpnd->m_sym->m_id);
  1637. }
  1638. PropertySym *
  1639. GlobOpt::CopyPropPropertySymObj(IR::SymOpnd *symOpnd, IR::Instr *instr)
  1640. {
  1641. Assert(symOpnd->m_sym->IsPropertySym());
  1642. PropertySym *propertySym = symOpnd->m_sym->AsPropertySym();
  1643. StackSym *objSym = propertySym->m_stackSym;
  1644. Value * val = this->currentBlock->globOptData.FindValue(objSym);
  1645. if (val && !PHASE_OFF(Js::ObjPtrCopyPropPhase, this->func))
  1646. {
  1647. StackSym *copySym = this->currentBlock->globOptData.GetCopyPropSym(objSym, val);
  1648. if (copySym != nullptr)
  1649. {
  1650. PropertySym *newProp = PropertySym::FindOrCreate(
  1651. copySym->m_id, propertySym->m_propertyId, propertySym->GetPropertyIdIndex(), propertySym->GetInlineCacheIndex(), propertySym->m_fieldKind, this->func);
  1652. if (!this->IsLoopPrePass() || SafeToCopyPropInPrepass(objSym, copySym, val))
  1653. {
  1654. #if DBG_DUMP
  1655. if (Js::Configuration::Global.flags.Trace.IsEnabled(Js::GlobOptPhase, this->func->GetSourceContextId(), this->func->GetLocalFunctionId()))
  1656. {
  1657. Output::Print(_u("TRACE: "));
  1658. symOpnd->Dump();
  1659. Output::Print(_u(" : "));
  1660. Output::Print(_u("Copy prop obj ptr s%d, new property: "), copySym->m_id);
  1661. newProp->Dump();
  1662. Output::Print(_u("\n"));
  1663. }
  1664. #endif
  1665. // Copy prop
  1666. this->CaptureByteCodeSymUses(instr);
  1667. // If the old sym was part of an object type spec type check sequence,
  1668. // let's make sure the new one is prepped for it as well.
  1669. if (IsPropertySymPreparedForTypeCheckSeq(propertySym))
  1670. {
  1671. PreparePropertySymForTypeCheckSeq(newProp);
  1672. }
  1673. symOpnd->m_sym = newProp;
  1674. symOpnd->SetIsJITOptimizedReg(true);
  1675. if (this->IsLoopPrePass())
  1676. {
  1677. this->OnCopyPropInPrePass(copySym, instr, this->currentBlock);
  1678. }
  1679. if (symOpnd->IsPropertySymOpnd())
  1680. {
  1681. IR::PropertySymOpnd *propertySymOpnd = symOpnd->AsPropertySymOpnd();
  1682. if (propertySymOpnd->IsTypeCheckSeqCandidate())
  1683. {
  1684. // If the new pointer sym's expected type(s) don't match those in the inline-cache-based data for this access,
  1685. // we probably have a mismatch and can't safely objtypespec. If the saved objtypespecfldinfo isn't right for
  1686. // the new type, then we'll do an incorrect property access.
  1687. StackSym * newTypeSym = copySym->GetObjectTypeSym();
  1688. Value * newValue = currentBlock->globOptData.FindObjectTypeValueNoLivenessCheck(newTypeSym);
  1689. JsTypeValueInfo * newValueInfo = newValue ? newValue->GetValueInfo()->AsJsType() : nullptr;
  1690. bool shouldOptimize = CompareCurrentTypesWithExpectedTypes(newValueInfo, propertySymOpnd);
  1691. if (!shouldOptimize)
  1692. {
  1693. propertySymOpnd->SetTypeCheckSeqCandidate(false);
  1694. }
  1695. }
  1696. // This is no longer strictly necessary, since we don't set the type dead bits in the initial
  1697. // backward pass, but let's keep it around for now in case we choose to revert to the old model.
  1698. propertySymOpnd->SetTypeDeadIfTypeCheckSeqCandidate(false);
  1699. }
  1700. if (this->IsLoopPrePass())
  1701. {
  1702. this->prePassCopyPropSym->Set(copySym->m_id);
  1703. }
  1704. }
  1705. propertySym = newProp;
  1706. if(instr->GetDst() && symOpnd->IsEqual(instr->GetDst()))
  1707. {
  1708. // Make sure any stack sym uses in the new destination property sym are unspecialized
  1709. instr = ToVarUses(instr, symOpnd, true, nullptr);
  1710. }
  1711. }
  1712. }
  1713. return propertySym;
  1714. }
  1715. void
  1716. GlobOpt::OnCopyPropInPrePass(StackSym * copySym, IR::Instr * instr, BasicBlock * block)
  1717. {
  1718. // Copy prop in the prepass may make upwardExposedUses out of date. Update it now.
  1719. if (block->upwardExposedUses->Test(copySym->m_id))
  1720. {
  1721. // Nothing to do
  1722. return;
  1723. }
  1724. // Use a to-do stack to avoid recursion and a bv to avoid repeated work
  1725. JsUtil::Stack<BasicBlock*, JitArenaAllocator, true> blockStack(this->tempAlloc);
  1726. BVSparse<JitArenaAllocator> blocksProcessed(this->tempAlloc);
  1727. blocksProcessed.Set(block->GetBlockNum());
  1728. this->UpdateUpwardExposedUses(copySym, instr, block, &blockStack, &blocksProcessed);
  1729. while (!blockStack.Empty())
  1730. {
  1731. block = blockStack.Pop();
  1732. Assert(blocksProcessed.Test(block->GetBlockNum()));
  1733. this->UpdateUpwardExposedUses(copySym, block->GetLastInstr(), block, &blockStack, &blocksProcessed);
  1734. }
  1735. }
  1736. void
  1737. GlobOpt::UpdateUpwardExposedUses(StackSym * sym, IR::Instr * instrLast, BasicBlock * block, JsUtil::Stack<BasicBlock*, JitArenaAllocator, true> *blockStack, BVSparse<JitArenaAllocator>* blocksProcessed)
  1738. {
  1739. Assert(blocksProcessed->Test(block->GetBlockNum()));
  1740. Assert(!block->upwardExposedUses->Test(sym->m_id));
  1741. // Walk the block backward looking for a def. If the sym is write-through in this block, though,
  1742. // treat it as upward-exposed regardless of the presence of defs.
  1743. IR::LabelInstr * instrFirst = block->GetFirstInstr()->AsLabelInstr();
  1744. Region * region = instrFirst->GetRegion();
  1745. if (region == nullptr || !region->CheckWriteThroughSym(sym))
  1746. {
  1747. FOREACH_INSTR_BACKWARD_IN_RANGE(instr, instrLast, instrFirst)
  1748. {
  1749. // If the instr defines the sym, quit without setting upwardExposedUses
  1750. IR::Opnd * dst = instr->GetDst();
  1751. if (dst != nullptr && dst->GetStackSym() == sym)
  1752. {
  1753. return;
  1754. }
  1755. Assert(dst == nullptr || dst->GetStackSym() == nullptr || dst->GetStackSym()->m_id != sym->m_id);
  1756. }
  1757. NEXT_INSTR_BACKWARD_IN_RANGE;
  1758. }
  1759. // The sym is upward exposed at this block. Now update the to-do set with the predecessors.
  1760. Assert(block->GetBlockNum() != 0);
  1761. block->upwardExposedUses->Set(sym->m_id);
  1762. FOREACH_PREDECESSOR_BLOCK(blockPred, block)
  1763. {
  1764. if (blockPred->upwardExposedUses == nullptr || blockPred->upwardExposedUses->Test(sym->m_id))
  1765. {
  1766. // If the bv is null, that means the main pass is done with this block
  1767. // and so done with its predecessors
  1768. continue;
  1769. }
  1770. if (!blocksProcessed->TestAndSet(blockPred->GetBlockNum()))
  1771. {
  1772. blockStack->Push(blockPred);
  1773. }
  1774. }
  1775. NEXT_PREDECESSOR_BLOCK;
  1776. }
  1777. void
  1778. GlobOpt::UpdateObjPtrValueType(IR::Opnd * opnd, IR::Instr * instr)
  1779. {
  1780. if (!opnd->IsSymOpnd() || !opnd->AsSymOpnd()->IsPropertySymOpnd())
  1781. {
  1782. return;
  1783. }
  1784. if (!instr->HasTypeCheckBailOut())
  1785. {
  1786. // No type check bailout, we didn't check that type of the object pointer.
  1787. return;
  1788. }
  1789. // Only check that fixed field should have type check bailout in loop prepass.
  1790. Assert(instr->m_opcode == Js::OpCode::CheckFixedFld || !this->IsLoopPrePass());
  1791. if (instr->m_opcode != Js::OpCode::CheckFixedFld)
  1792. {
  1793. // DeadStore pass may remove type check bailout, except CheckFixedFld which always needs
  1794. // type check bailout. So we can only change the type for CheckFixedFld.
  1795. // Consider: See if we can expand that in the future.
  1796. return;
  1797. }
  1798. IR::PropertySymOpnd * propertySymOpnd = opnd->AsPropertySymOpnd();
  1799. StackSym * objectSym = propertySymOpnd->GetObjectSym();
  1800. Value * objVal = this->currentBlock->globOptData.FindValue(objectSym);
  1801. if (!objVal)
  1802. {
  1803. return;
  1804. }
  1805. ValueType objValueType = objVal->GetValueInfo()->Type();
  1806. if (objValueType.IsDefinite())
  1807. {
  1808. return;
  1809. }
  1810. ValueInfo *objValueInfo = objVal->GetValueInfo();
  1811. // It is possible for a valueInfo to be not definite and still have a byteCodeConstant as symStore, this is because we conservatively copy valueInfo in prePass
  1812. if (objValueInfo->GetSymStore() && objValueInfo->GetSymStore()->IsStackSym() && objValueInfo->GetSymStore()->AsStackSym()->IsFromByteCodeConstantTable())
  1813. {
  1814. return;
  1815. }
  1816. // Verify that the types we're checking for here have been locked so that the type ID's can't be changed
  1817. // without changing the type.
  1818. if (!propertySymOpnd->HasObjectTypeSym())
  1819. {
  1820. return;
  1821. }
  1822. StackSym * typeSym = propertySymOpnd->GetObjectTypeSym();
  1823. Assert(typeSym);
  1824. Value * typeValue = currentBlock->globOptData.FindObjectTypeValue(typeSym);
  1825. if (!typeValue)
  1826. {
  1827. return;
  1828. }
  1829. JsTypeValueInfo * typeValueInfo = typeValue->GetValueInfo()->AsJsType();
  1830. JITTypeHolder type = typeValueInfo->GetJsType();
  1831. if (type != nullptr)
  1832. {
  1833. if (Js::DynamicType::Is(type->GetTypeId()) &&
  1834. !type->GetTypeHandler()->IsLocked())
  1835. {
  1836. return;
  1837. }
  1838. }
  1839. else
  1840. {
  1841. Js::EquivalentTypeSet * typeSet = typeValueInfo->GetJsTypeSet();
  1842. Assert(typeSet);
  1843. for (uint16 i = 0; i < typeSet->GetCount(); i++)
  1844. {
  1845. type = typeSet->GetType(i);
  1846. if (Js::DynamicType::Is(type->GetTypeId()) &&
  1847. !type->GetTypeHandler()->IsLocked())
  1848. {
  1849. return;
  1850. }
  1851. }
  1852. }
  1853. AnalysisAssert(type != nullptr);
  1854. Js::TypeId typeId = type->GetTypeId();
  1855. // Passing false for useVirtual as we would never have a virtual typed array hitting this code path
  1856. ValueType newValueType = ValueType::FromTypeId(typeId, false);
  1857. if (newValueType == ValueType::Uninitialized)
  1858. {
  1859. switch (typeId)
  1860. {
  1861. default:
  1862. // Can't mark as definite object because it may actually be object-with-array.
  1863. // Consider: a value type that subsumes object, array, and object-with-array.
  1864. break;
  1865. case Js::TypeIds_NativeIntArray:
  1866. case Js::TypeIds_NativeFloatArray:
  1867. // Do not mark these values as definite to protect against array conversion
  1868. break;
  1869. case Js::TypeIds_Array:
  1870. // Because array can change type id, we can only make it definite if we are doing array check hoist
  1871. // so that implicit call will be installed between the array checks.
  1872. if (!DoArrayCheckHoist() ||
  1873. (currentBlock->loop
  1874. ? !this->ImplicitCallFlagsAllowOpts(currentBlock->loop)
  1875. : !this->ImplicitCallFlagsAllowOpts(this->func)))
  1876. {
  1877. break;
  1878. }
  1879. if (objValueType.IsLikelyArrayOrObjectWithArray())
  1880. {
  1881. // If we have likely no missing values before, keep the likely, because, we haven't proven that
  1882. // the array really has no missing values
  1883. if (!objValueType.HasNoMissingValues())
  1884. {
  1885. newValueType = ValueType::GetObject(ObjectType::Array).SetArrayTypeId(typeId);
  1886. }
  1887. }
  1888. else
  1889. {
  1890. newValueType = ValueType::GetObject(ObjectType::Array).SetArrayTypeId(typeId);
  1891. }
  1892. break;
  1893. }
  1894. }
  1895. if (newValueType != ValueType::Uninitialized)
  1896. {
  1897. ChangeValueType(currentBlock, objVal, newValueType, false, true);
  1898. }
  1899. }