| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- #include "BackEnd.h"
- namespace IR
- {
- void
- Instr::Init(Js::OpCode opcode, IRKind kind, Func * func)
- {
- Assert(!OpCodeAttr::ByteCodeOnly(opcode));
- this->m_opcode = opcode;
- this->m_kind = kind;
- this->m_func = func;
- #ifdef BAILOUT_INJECTION
- this->bailOutByteCodeLocation = (uint)-1;
- #endif
- }
- uint32
- Instr::GetByteCodeOffset() const
- {
- Assert(m_func->HasByteCodeOffset());
- return m_number;
- }
- void
- Instr::SetByteCodeOffset(uint32 offset)
- {
- Assert(m_func->HasByteCodeOffset());
- Assert(m_number == Js::Constants::NoByteCodeOffset);
- m_number = offset;
- }
- void
- Instr::SetByteCodeOffset(IR::Instr * instr)
- {
- SetByteCodeOffset(instr->GetByteCodeOffset());
- }
- void
- Instr::ClearByteCodeOffset()
- {
- Assert(m_func->HasByteCodeOffset());
- m_number = Js::Constants::NoByteCodeOffset;
- }
- uint32
- Instr::GetNumber() const
- {
- Assert(m_func->HasInstrNumber());
- return m_number;
- }
- void
- Instr::SetNumber(uint32 number)
- {
- Assert(m_func->HasInstrNumber());
- m_number = number;
- }
- bool
- Instr::IsPlainInstr() const
- {
- return this->GetKind() == IR::InstrKindInstr;
- }
- bool
- Instr::DoStackArgsOpt(Func *topFunc) const
- {
- return this->usesStackArgumentsObject && this->m_func->GetHasStackArgs() && topFunc->GetHasStackArgs();
- }
- bool
- Instr::HasTypeCheckBailOut() const
- {
- return this->HasBailOutInfo() && IR::IsTypeCheckBailOutKind(this->GetBailOutKind());
- }
- bool
- Instr::HasEquivalentTypeCheckBailOut() const
- {
- return this->HasBailOutInfo() && IR::IsEquivalentTypeCheckBailOutKind(this->GetBailOutKind());
- }
- void
- Instr::ChangeEquivalentToMonoTypeCheckBailOut()
- {
- Assert(this->HasEquivalentTypeCheckBailOut());
- this->SetBailOutKind(IR::EquivalentToMonoTypeCheckBailOutKind(this->GetBailOutKind()));
- }
- Js::Var
- Instr::TryOptimizeInstrWithFixedDataProperty(IR::Instr **pInstr, GlobOpt * globopt)
- {
- IR::Instr *&instr = *pInstr;
- Assert(OpCodeAttr::CanLoadFixedFields(instr->m_opcode));
- IR::Opnd * src1 = instr->GetSrc1();
- Assert(src1 && src1->IsSymOpnd() && src1->AsSymOpnd()->IsPropertySymOpnd());
- IR::PropertySymOpnd * propSymOpnd = src1->AsSymOpnd()->AsPropertySymOpnd();
- if (propSymOpnd->HasFixedValue() && !propSymOpnd->IsPoly())
- {
- Js::Var fixedValue = propSymOpnd->GetFieldValueAsFixedData();
- Assert(instr->IsProfiledInstr());
- ValueType valType = instr->AsProfiledInstr()->u.FldInfo().valueType;
- if (fixedValue && ((Js::TaggedInt::Is(fixedValue) && (valType.IsUninitialized() || valType.IsLikelyInt())) || PHASE_ON1(Js::FixDataVarPropsPhase)))
- {
- // Change Ld[Root]Fld to CheckFixedFld, which doesn't need a dst.
- instr->m_opcode = Js::OpCode::CheckFixedFld;
- IR::RegOpnd* dataValueDstOpnd = instr->UnlinkDst()->AsRegOpnd();
- if (globopt)
- {
- globopt->GenerateBailAtOperation(&instr, !propSymOpnd->HasEquivalentTypeSet() ? IR::BailOutFailedFixedFieldTypeCheck : IR::BailOutFailedEquivalentFixedFieldTypeCheck);
- }
- else
- {
- instr = instr->ConvertToBailOutInstr(instr, !propSymOpnd->HasEquivalentTypeSet() ? IR::BailOutFailedFixedFieldTypeCheck : IR::BailOutFailedEquivalentFixedFieldTypeCheck);
- }
- IR::Instr* loadInstr = IR::Instr::NewConstantLoad(dataValueDstOpnd, fixedValue, instr->m_func);
- OUTPUT_VERBOSE_TRACE(Js::UseFixedDataPropsPhase,
- L"FixedFields: Replacing the source (fixed Data prop) with property id %s with 0x%x .\n",
- propSymOpnd->GetPropertySym()->GetName(), fixedValue);
- instr->InsertAfter(loadInstr);
- propSymOpnd->SetUsesFixedValue(true);
- return fixedValue;
- }
- }
- return nullptr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::IsEqual
- /// Check if this instruction is the same instruction as compareInstr. Two
- /// instructions are equal if kind, opcode, dst, src1 and src2 from both instrs
- /// are the same.
- ///
- ///----------------------------------------------------------------------------
- bool
- Instr::IsEqual(IR::Instr *compareInstr) const
- {
- Assert(this && compareInstr);
- if (this->GetKind() == compareInstr->GetKind()
- && this->m_opcode == compareInstr->m_opcode)
- {
- IR::Opnd *dst = this->GetDst();
- IR::Opnd *src1 = this->GetSrc1();
- IR::Opnd *src2 = this->GetSrc2();
- IR::Opnd *compareDst = compareInstr->GetDst();
- IR::Opnd *compareSrc1 = compareInstr->GetSrc1();
- IR::Opnd *compareSrc2 = compareInstr->GetSrc2();
- // when both dst and compareDst are null, they are equal, same applies to src1, src2
- if ((dst != compareDst) && (!dst || !compareDst || !dst->IsEqual(compareDst)))
- {
- return false;
- }
- if ((src1 != compareSrc1) && (!src1 || !compareSrc1 || !src1->IsEqual(compareSrc1)))
- {
- return false;
- }
- if ((src2 != compareSrc2) && (!src2 || !compareSrc2 || !src2->IsEqual(compareSrc2)))
- {
- return false;
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertBefore
- ///
- /// Insert 'instr' before 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertBefore(Instr *instr)
- {
- Assert(!instr->IsLinked());
- Instr * prevInstr = this->m_prev;
- instr->m_prev = prevInstr;
- this->m_prev = instr;
- if (prevInstr)
- {
- prevInstr->m_next = instr;
- }
- instr->m_next = this;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertAfter
- ///
- /// Insert 'instr' after 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertAfter(Instr *instr)
- {
- Assert(!instr->IsLinked());
- Instr * nextInstr = this->m_next;
- instr->m_next = nextInstr;
- this->m_next = instr;
- if (nextInstr)
- {
- nextInstr->m_prev = instr;
- }
- instr->m_prev = this;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertRangeBefore
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertRangeBefore(Instr *startInstr, Instr *endInstr)
- {
- Instr * prevInstr = this->m_prev;
- startInstr->m_prev = prevInstr;
- this->m_prev = endInstr;
- if (prevInstr)
- {
- prevInstr->m_next = startInstr;
- }
- endInstr->m_next = this;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertMultipleBefore - Inserts multiple instr
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertMultipleBefore(Instr *endInstr)
- {
- Instr *startInstr = endInstr->m_prev;
- if (startInstr) // more than one instruction to insert
- {
- while (startInstr->m_prev)
- {
- startInstr = startInstr->m_prev;
- }
- return this->InsertRangeBefore(startInstr, endInstr);
- }
- return this->InsertBefore(endInstr);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertRangeAfter
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertRangeAfter(Instr *startInstr, Instr *endInstr)
- {
- Instr * nextInstr = this->m_next;
- endInstr->m_next = nextInstr;
- this->m_next = startInstr;
- if (nextInstr)
- {
- nextInstr->m_prev = endInstr;
- }
- startInstr->m_prev = this;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::InsertMultipleAfter - Inserts multiple instr
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::InsertMultipleAfter(Instr *endInstr)
- {
- Instr *startInstr = endInstr->m_prev;
- if (startInstr) //more than one instruction to insert
- {
- while (startInstr->m_prev)
- {
- startInstr = startInstr->m_prev;
- }
- return this->InsertRangeAfter(startInstr, endInstr);
- }
- return this->InsertAfter(endInstr);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::Free
- ///
- /// Free this instruction by putting it on a free list.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::Free()
- {
- AssertMsg(!this->IsLabelInstr() || !this->AsLabelInstr()->m_hasNonBranchRef,
- "Cannot free label with non-branch reference");
- switch (this->GetKind())
- {
- case InstrKindBranch:
- {
- IR::BranchInstr *branchInstr = this->AsBranchInstr();
- branchInstr->ClearTarget();
- break;
- }
- }
- IR::Opnd * dstOpnd = this->GetDst();
- if (dstOpnd)
- {
- StackSym * stackSym = dstOpnd->GetStackSym();
- if (stackSym)
- {
- if (stackSym->m_isSingleDef)
- {
- Assert(!stackSym->m_isEncodedConstant);
- if (stackSym->m_instrDef == this)
- {
- Assert(!dstOpnd->isFakeDst);
- if (stackSym->IsConst())
- {
- // keep the instruction around so we can get the constant value
- // from the symbol
- return;
- }
- Assert(this->m_func->GetTopFunc()->allowRemoveBailOutArgInstr || !stackSym->m_isBailOutReferenced);
- stackSym->m_instrDef = nullptr;
- }
- else
- {
- Assert(dstOpnd->isFakeDst);
- }
- }
- else
- {
- // Encoded constants are not single-defs anymore, and therefore not isConst.
- Assert((!stackSym->m_isConst && stackSym->constantValue == 0)
- || (stackSym->m_isEncodedConstant && stackSym->constantValue != 0));
- }
- }
- }
- ClearBailOutInfo();
- JitAdelete(this->m_func->m_alloc, this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::Unlink
- ///
- /// Unlink this instr from the instr list.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::Unlink()
- {
- m_prev->m_next = m_next;
- if (m_next)
- {
- m_next->m_prev = m_prev;
- }
- else
- {
- Assert(this == this->m_func->m_tailInstr);
- }
- #if DBG_DUMP
- // Transferring the globOptInstrString to the next non-Label Instruction
- if(this->globOptInstrString != nullptr && m_next && m_next->globOptInstrString == nullptr && !m_next->IsLabelInstr())
- {
- m_next->globOptInstrString = this->globOptInstrString;
- }
- #endif
- #if DBG
- m_prev = nullptr;
- m_next = nullptr;
- #endif
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::Remove
- ///
- /// Unlink and free this instr.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::Remove()
- {
- this->Unlink();
- this->Free();
- }
- void
- Instr::SwapOpnds()
- {
- IR::Opnd *opndTemp = m_src1;
- m_src1 = m_src2;
- m_src2 = opndTemp;
- }
- // Copy a vanilla instruction.
- Instr *
- Instr::Copy()
- {
- Instr * instrCopy;
- if (this->HasBailOutInfo() || this->HasAuxBailOut())
- {
- instrCopy = BailOutInstr::New(this->m_opcode, this->GetBailOutKind(), this->GetBailOutInfo(), this->m_func);
- instrCopy->SetByteCodeOffset(this->GetByteCodeOffset());
- if (this->HasAuxBailOut())
- {
- instrCopy->hasAuxBailOut = true;
- instrCopy->SetAuxBailOutKind(this->GetAuxBailOutKind());
- }
- }
- else
- {
- switch (this->GetKind())
- {
- case InstrKindInstr:
- instrCopy = Instr::New(this->m_opcode, this->m_func);
- break;
- case InstrKindProfiled:
- instrCopy = this->AsProfiledInstr()->CopyProfiledInstr();
- break;
- case InstrKindJitProfiling:
- instrCopy = this->AsJitProfilingInstr()->CopyJitProfiling();
- break;
- case InstrKindPragma:
- instrCopy = this->AsPragmaInstr()->CopyPragma();
- break;
- default:
- instrCopy = nullptr;
- AnalysisAssertMsg(UNREACHED, "Copy of other instr kinds NYI");
- }
- }
- Opnd * opnd = this->GetDst();
- if (opnd)
- {
- instrCopy->SetDst(opnd->Copy(this->m_func));
- }
- opnd = this->GetSrc1();
- if (opnd)
- {
- instrCopy->SetSrc1(opnd->Copy(this->m_func));
- opnd = this->GetSrc2();
- if (opnd)
- {
- instrCopy->SetSrc2(opnd->Copy(this->m_func));
- }
- }
- instrCopy->isInlineeEntryInstr = this->isInlineeEntryInstr;
- if (this->m_func->DoMaintainByteCodeOffset())
- {
- instrCopy->SetByteCodeOffset(this->GetByteCodeOffset());
- }
- instrCopy->usesStackArgumentsObject = this->usesStackArgumentsObject;
- return instrCopy;
- }
- LabelInstr *
- LabelInstr::CloneLabel(BOOL fCreate)
- {
- Func * func = this->m_func;
- Cloner * cloner = func->GetCloner();
- IR::LabelInstr * instrLabel = nullptr;
- AssertMsg(cloner, "Use Func::BeginClone to initialize cloner");
- if (cloner->labelMap == nullptr)
- {
- if (!fCreate)
- {
- return nullptr;
- }
- cloner->labelMap = HashTable<LabelInstr*>::New(cloner->alloc, 7);
- }
- else
- {
- IR::LabelInstr ** map = cloner->labelMap->Get(this->m_id);
- if (map)
- {
- instrLabel = *map;
- }
- }
- if (instrLabel == nullptr)
- {
- if (!fCreate)
- {
- return nullptr;
- }
- if (this->IsProfiledLabelInstr())
- {
- instrLabel = IR::ProfiledLabelInstr::New(this->m_opcode, func, this->AsProfiledLabelInstr()->loopImplicitCallFlags, this->AsProfiledLabelInstr()->loopFlags);
- #if DBG
- instrLabel->AsProfiledLabelInstr()->loopNum = this->AsProfiledLabelInstr()->loopNum;
- #endif
- }
- else
- {
- instrLabel = IR::LabelInstr::New(this->m_opcode, func, this->isOpHelper);
- }
- instrLabel->m_isLoopTop = this->m_isLoopTop;
- cloner->labelMap->FindOrInsert(instrLabel, this->m_id);
- }
- return instrLabel;
- }
- ProfiledLabelInstr::ProfiledLabelInstr(JitArenaAllocator * allocator)
- : LabelInstr(allocator)
- {
- }
- ProfiledLabelInstr *
- ProfiledLabelInstr::New(Js::OpCode opcode, Func *func, Js::ImplicitCallFlags flags, Js::LoopFlags loopFlags)
- {
- ProfiledLabelInstr * profiledLabelInstr = JitAnew(func->m_alloc, ProfiledLabelInstr, func->m_alloc);
- profiledLabelInstr->Init(opcode, InstrKindProfiledLabel, func, false);
- profiledLabelInstr->loopImplicitCallFlags = flags;
- profiledLabelInstr->loopFlags = loopFlags;
- return profiledLabelInstr;
- }
- void
- BranchInstr::RetargetClonedBranch()
- {
- IR::LabelInstr * instrLabel = this->m_branchTarget->CloneLabel(false);
- if (instrLabel == nullptr)
- {
- // Jumping outside the cloned range. No retarget.
- return;
- }
- this->SetTarget(instrLabel);
- }
- PragmaInstr *
- PragmaInstr::ClonePragma()
- {
- return this->CopyPragma();
- }
- PragmaInstr *
- PragmaInstr::CopyPragma()
- {
- IR::PragmaInstr * instrPragma = IR::PragmaInstr::New(this->m_opcode, 0, this->m_func);
- return instrPragma;
- }
- Instr *
- Instr::CloneInstr() const
- {
- if (this->HasBailOutInfo() || this->HasAuxBailOut())
- {
- return ((BailOutInstr *)this)->CloneBailOut();
- }
- IR::Instr *clone = IR::Instr::New(this->m_opcode, this->m_func);
- clone->isInlineeEntryInstr = this->isInlineeEntryInstr;
- return clone;
- }
- // Clone a vanilla instruction, replacing single-def StackSym's with new syms where appropriate.
- Instr *
- Instr::Clone()
- {
- Func * func = this->m_func;
- Cloner *cloner = func->GetCloner();
- IR::Instr * instrClone;
- IR::Opnd * opnd;
- switch (this->GetKind())
- {
- case InstrKindInstr:
- instrClone = this->CloneInstr();
- break;
- case InstrKindBranch:
- instrClone = this->AsBranchInstr()->CloneBranchInstr();
- break;
- case InstrKindProfiled:
- instrClone = this->AsProfiledInstr()->CloneProfiledInstr();
- break;
- case InstrKindLabel:
- case InstrKindProfiledLabel:
- instrClone = this->AsLabelInstr()->CloneLabel(true);
- break;
- case InstrKindPragma:
- instrClone = this->AsPragmaInstr()->ClonePragma();
- break;
- case InstrKindJitProfiling:
- instrClone = this->AsJitProfilingInstr()->CloneJitProfiling();
- break;
- default:
- AssertMsg(0, "Clone of this instr kind NYI");
- return nullptr;
- }
- opnd = this->GetDst();
- if (opnd)
- {
- instrClone->SetDst(opnd->CloneDef(func));
- }
- opnd = this->GetSrc1();
- if (opnd)
- {
- instrClone->SetSrc1(opnd->CloneUse(func));
- opnd = this->GetSrc2();
- if (opnd)
- {
- instrClone->SetSrc2(opnd->CloneUse(func));
- }
- }
- if (this->m_func->DoMaintainByteCodeOffset())
- {
- instrClone->SetByteCodeOffset(this->GetByteCodeOffset());
- }
- instrClone->usesStackArgumentsObject = this->usesStackArgumentsObject;
- cloner->AddInstr(this, instrClone);
- return instrClone;
- }
- // Clone a range of instructions.
- Instr *
- Instr::CloneRange(
- Instr * instrStart, Instr * instrLast, Instr * instrAfter, Lowerer *lowerer, JitArenaAllocator * alloc, bool (*fMapTest)(IR::Instr*), bool clonedInstrGetOrigArgSlotSym)
- {
- IR::Instr * instrReturn = instrAfter;
- Func * topFunc = instrStart->m_func->GetTopFunc();
- topFunc->BeginClone(lowerer, alloc);
- topFunc->GetCloner()->clonedInstrGetOrigArgSlotSym = clonedInstrGetOrigArgSlotSym;
- FOREACH_INSTR_IN_RANGE(instr, instrStart, instrLast)
- {
- Instr * instrClone = instr->Clone();
- instrAfter->InsertAfter(instrClone);
- instrAfter = instrClone;
- instr->isCloned = true;
- if (fMapTest(instrClone))
- {
- IR::LabelInstr *instrLabel = IR::LabelInstr::New(Js::OpCode::Label, instr->m_func);
- instrClone->InsertBefore(instrLabel);
- topFunc->GetCloneMap()->Item(instr, instrLabel);
- }
- }
- NEXT_INSTR_IN_RANGE;
- topFunc->EndClone();
- return instrReturn;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::MoveRangeAfter
- ///
- /// Move a range of instruction after another instruction
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::MoveRangeAfter(Instr * instrStart, Instr * instrLast, Instr * instrAfter)
- {
- if (instrLast->m_next != nullptr)
- {
- instrLast->m_next->m_prev = instrStart->m_prev;
- }
- else
- {
- instrLast->m_func->m_tailInstr = instrStart->m_prev;
- }
- if (instrStart->m_prev != nullptr)
- {
- instrStart->m_prev->m_next = instrLast->m_next;
- }
- else
- {
- instrStart->m_func->m_headInstr = instrLast->m_next;
- }
- instrStart->m_prev = instrAfter;
- instrLast->m_next = instrAfter->m_next;
- if (instrAfter->m_next != nullptr)
- {
- instrAfter->m_next->m_prev = instrLast;
- }
- else
- {
- instrAfter->m_func->m_tailInstr = instrLast;
- }
- instrAfter->m_next = instrStart;
- }
- JitProfilingInstr *
- JitProfilingInstr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Opnd *src2Opnd, Func * func)
- {
- JitProfilingInstr * profiledInstr = JitProfilingInstr::New(opcode, dstOpnd, src1Opnd, func);
- profiledInstr->SetSrc2(src2Opnd);
- return profiledInstr;
- }
- JitProfilingInstr *
- JitProfilingInstr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Func * func)
- {
- Assert(func->DoSimpleJitDynamicProfile());
- JitProfilingInstr * profiledInstr = JitAnew(func->m_alloc, IR::JitProfilingInstr);
- profiledInstr->Init(opcode, InstrKindJitProfiling, func);
- if (dstOpnd)
- {
- profiledInstr->SetDst(dstOpnd);
- }
- if (src1Opnd)
- {
- profiledInstr->SetSrc1(src1Opnd);
- }
- #if DBG
- profiledInstr->profileId = Js::Constants::NoProfileId;
- profiledInstr->arrayProfileId = Js::Constants::NoProfileId;
- profiledInstr->inlineCacheIndex = Js::Constants::NoInlineCacheIndex;
- Assert(profiledInstr->loopNumber == 0u - 1);
- #endif
- // default these to false.
- profiledInstr->isProfiledReturnCall = false;
- profiledInstr->isBeginSwitch = false;
- profiledInstr->isNewArray = false;
- profiledInstr->isLoopHelper = false;
- return profiledInstr;
- }
- JitProfilingInstr*
- JitProfilingInstr::CloneJitProfiling() const
- {
- // Adapted from Profiled::CloneProfiledInstr. Note that the dst and srcs are not set.
- Assert(!(this->HasBailOutInfo() || this->HasAuxBailOut())); // Shouldn't have bailout info in a jitprofiling instr
- return this->CopyJitProfiling();
- }
- JitProfilingInstr*
- JitProfilingInstr::CopyJitProfiling() const
- {
- // Adapted from Profiled::CopyProfiledInstr. Note that the dst and srcs are not set.
- IR::JitProfilingInstr * jitProfInstr;
- jitProfInstr = JitAnew(this->m_func->m_alloc, IR::JitProfilingInstr);
- jitProfInstr->Init(this->m_opcode, InstrKindProfiled, this->m_func);
- jitProfInstr->isProfiledReturnCall = this->isProfiledReturnCall;
- jitProfInstr->isBeginSwitch = this->isBeginSwitch;
- jitProfInstr->isNewArray = this->isNewArray;
- jitProfInstr->isLoopHelper = this->isLoopHelper;
- jitProfInstr->profileId = this->profileId;
- jitProfInstr->arrayProfileId = this->arrayProfileId;
- jitProfInstr->inlineCacheIndex = this->inlineCacheIndex;
- Assert(jitProfInstr->loopNumber == this->loopNumber);
- return jitProfInstr;
- }
- ProfiledInstr *
- ProfiledInstr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Opnd *src2Opnd, Func * func)
- {
- ProfiledInstr * profiledInstr = ProfiledInstr::New(opcode, dstOpnd, src1Opnd, func);
- profiledInstr->SetSrc2(src2Opnd);
- return profiledInstr;
- }
- ProfiledInstr *
- ProfiledInstr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Func * func)
- {
- ProfiledInstr * profiledInstr = JitAnew(func->m_alloc, IR::ProfiledInstr);
- profiledInstr->Init(opcode, InstrKindProfiled, func);
- if (dstOpnd)
- {
- profiledInstr->SetDst(dstOpnd);
- }
- if (src1Opnd)
- {
- profiledInstr->SetSrc1(src1Opnd);
- }
- profiledInstr->u.ldElemInfo = nullptr;
- return profiledInstr;
- }
- ProfiledInstr *
- ProfiledInstr::CloneProfiledInstr() const
- {
- IR::ProfiledInstr * profiledInstr;
- if (this->HasBailOutInfo() || this->HasAuxBailOut())
- {
- profiledInstr = ((ProfiledBailOutInstr *)this)->CloneBailOut();
- profiledInstr->u = this->u;
- }
- else
- {
- profiledInstr = this->CopyProfiledInstr();
- }
- return profiledInstr;
- }
- ProfiledInstr *
- ProfiledInstr::CopyProfiledInstr() const
- {
- IR::ProfiledInstr * profiledInstr;
- profiledInstr = JitAnew(this->m_func->m_alloc, IR::ProfiledInstr);
- profiledInstr->Init(this->m_opcode, InstrKindProfiled, this->m_func);
- profiledInstr->u = this->u;
- return profiledInstr;
- }
- ByteCodeUsesInstr *
- ByteCodeUsesInstr::New(Func * func)
- {
- ByteCodeUsesInstr * byteCodeUses = JitAnew(func->m_alloc, IR::ByteCodeUsesInstr);
- byteCodeUses->Init(Js::OpCode::ByteCodeUses, InstrKindByteCodeUses, func);
- byteCodeUses->byteCodeUpwardExposedUsed = nullptr;
- byteCodeUses->propertySymUse = nullptr;
- return byteCodeUses;
- }
- ByteCodeUsesInstr *
- ByteCodeUsesInstr::New(IR::Instr* originalBytecodeInstr, SymID symid)
- {
- Func* func = originalBytecodeInstr->m_func;
- ByteCodeUsesInstr * byteCodeUses = JitAnew(func->m_alloc, IR::ByteCodeUsesInstr);
- byteCodeUses->Init(Js::OpCode::ByteCodeUses, InstrKindByteCodeUses, func);
- byteCodeUses->byteCodeUpwardExposedUsed = JitAnew(func->m_alloc, BVSparse<JitArenaAllocator>, func->m_alloc);
- byteCodeUses->byteCodeUpwardExposedUsed->Set(symid);
- byteCodeUses->SetByteCodeOffset(originalBytecodeInstr);
- byteCodeUses->propertySymUse = nullptr;
- return byteCodeUses;
- }
- void ByteCodeUsesInstr::Set(uint symId)
- {
- if(!byteCodeUpwardExposedUsed)
- {
- byteCodeUpwardExposedUsed = JitAnew(m_func->m_alloc, BVSparse<JitArenaAllocator>, m_func->m_alloc);
- }
- byteCodeUpwardExposedUsed->Set(symId);
- }
- BailOutInfo *
- Instr::GetBailOutInfo() const
- {
- Assert(this->HasBailOutInfo() || this->HasAuxBailOut());
- switch (this->m_kind)
- {
- case InstrKindInstr:
- return ((BailOutInstr const *)this)->bailOutInfo;
- case InstrKindProfiled:
- return ((ProfiledBailOutInstr const *)this)->bailOutInfo;
- case InstrKindBranch:
- return ((BranchBailOutInstr const *)this)->bailOutInfo;
- default:
- Assert(false);
- __assume(false);
- }
- }
- BailOutKind
- Instr::GetBailOutKind() const
- {
- Assert(this->HasBailOutInfo());
- switch (this->m_kind)
- {
- case InstrKindInstr:
- return ((BailOutInstr const *)this)->bailOutKind;
- case InstrKindProfiled:
- return ((ProfiledBailOutInstr const *)this)->bailOutKind;
- case InstrKindBranch:
- return ((BranchBailOutInstr const *)this)->bailOutKind;
- default:
- Assert(false);
- return BailOutInvalid;
- }
- }
- BailOutKind
- Instr::GetBailOutKindNoBits() const
- {
- return GetBailOutKind() & ~IR::BailOutKindBits;
- }
- BailOutKind
- Instr::GetAuxBailOutKind() const
- {
- Assert(this->HasAuxBailOut());
- switch (this->m_kind)
- {
- case InstrKindInstr:
- return ((BailOutInstr const *)this)->auxBailOutKind;
- case InstrKindProfiled:
- return ((ProfiledBailOutInstr const *)this)->auxBailOutKind;
- case InstrKindBranch:
- return ((BranchBailOutInstr const *)this)->auxBailOutKind;
- default:
- Assert(false);
- return BailOutInvalid;
- }
- }
- void Instr::SetBailOutKind(const IR::BailOutKind bailOutKind)
- {
- Assert(this->HasBailOutInfo());
- Assert(bailOutKind != IR::BailOutInvalid);
- this->SetBailOutKind_NoAssert(bailOutKind);
- }
- // Helper to set bail out kind, doesn't assert.
- void Instr::SetBailOutKind_NoAssert(const IR::BailOutKind bailOutKind)
- {
- Assert(IsValidBailOutKindAndBits(bailOutKind));
- switch (this->m_kind)
- {
- case InstrKindInstr:
- ((BailOutInstr *)this)->bailOutKind = bailOutKind;
- break;
- case InstrKindProfiled:
- ((ProfiledBailOutInstr *)this)->bailOutKind = bailOutKind;
- break;
- case InstrKindBranch:
- ((BranchBailOutInstr *)this)->bailOutKind = bailOutKind;
- break;
- default:
- Assert(false);
- __assume(false);
- }
- }
- void Instr::SetAuxBailOutKind(const IR::BailOutKind bailOutKind)
- {
- switch (this->m_kind)
- {
- case InstrKindInstr:
- ((BailOutInstr *)this)->auxBailOutKind = bailOutKind;
- break;
- case InstrKindProfiled:
- ((ProfiledBailOutInstr *)this)->auxBailOutKind = bailOutKind;
- break;
- case InstrKindBranch:
- ((BranchBailOutInstr *)this)->auxBailOutKind = bailOutKind;
- break;
- default:
- Assert(false);
- __assume(false);
- }
- }
- BailOutInfo *
- Instr::UnlinkBailOutInfo()
- {
- BailOutInfo *bailOutInfo;
- Assert(this->HasBailOutInfo() || this->HasAuxBailOut());
- switch (this->m_kind)
- {
- case InstrKindInstr:
- bailOutInfo = ((BailOutInstr const *)this)->bailOutInfo;
- ((BailOutInstr *)this)->bailOutInfo = nullptr;
- break;
- case InstrKindProfiled:
- bailOutInfo = ((ProfiledBailOutInstr const *)this)->bailOutInfo;
- ((ProfiledBailOutInstr *)this)->bailOutInfo = nullptr;
- break;
- case InstrKindBranch:
- bailOutInfo = ((BranchBailOutInstr const *)this)->bailOutInfo;
- ((BranchBailOutInstr *)this)->bailOutInfo = nullptr;
- break;
- default:
- Assert(false);
- return nullptr;
- }
- Assert(bailOutInfo);
- #if 0
- if (bailOutInfo->bailOutInstr == this)
- {
- bailOutInfo->bailOutInstr = nullptr;
- }
- #endif
- this->hasBailOutInfo = false;
- this->hasAuxBailOut = false;
- return bailOutInfo;
- }
- void
- Instr::ReplaceBailOutInfo(BailOutInfo *newBailOutInfo)
- {
- BailOutInfo *oldBailOutInfo;
- #if DBG
- newBailOutInfo->wasCopied = true;
- #endif
- Assert(this->HasBailOutInfo() || this->HasAuxBailOut());
- switch (this->m_kind)
- {
- case InstrKindInstr:
- oldBailOutInfo = ((BailOutInstr *)this)->bailOutInfo;
- ((BailOutInstr *)this)->bailOutInfo = newBailOutInfo;
- break;
- case InstrKindProfiled:
- oldBailOutInfo = ((ProfiledBailOutInstr *)this)->bailOutInfo;
- ((ProfiledBailOutInstr *)this)->bailOutInfo = newBailOutInfo;
- break;
- case InstrKindBranch:
- AssertMsg(!this->HasBailOutInfo() && this->HasAuxBailOut(), "ReplaceBailOutInfo is not used with InstrKindBranch for non-aux bailout");
- oldBailOutInfo = ((BranchBailOutInstr *)this)->bailOutInfo;
- ((BranchBailOutInstr *)this)->bailOutInfo = newBailOutInfo;
- break;
- default:
- Assert(false);
- __assume(UNREACHED);
- }
- Assert(!oldBailOutInfo->wasCloned && !oldBailOutInfo->wasCopied);
- if (oldBailOutInfo->bailOutInstr == this)
- {
- JitArenaAllocator * alloc = this->m_func->m_alloc;
- oldBailOutInfo->Clear(alloc);
- JitAdelete(alloc, oldBailOutInfo);
- }
- }
- IR::Instr *Instr::ShareBailOut()
- {
- BailOutInfo *const bailOutInfo = GetBailOutInfo();
- bailOutInfo->bailOutInstr = nullptr;
- #if DBG
- bailOutInfo->wasCopied = true;
- #endif
- IR::Instr *const sharedBail =
- IR::BailOutInstr::New(Js::OpCode::BailTarget, IR::BailOutShared, bailOutInfo, bailOutInfo->bailOutFunc);
- sharedBail->SetByteCodeOffset(this);
- InsertAfter(sharedBail);
- Assert(bailOutInfo->bailOutInstr == sharedBail);
- return sharedBail;
- }
- void
- Instr::UnlinkStartCallFromBailOutInfo(IR::Instr *endInstr) const
- {
- #ifdef _M_IX86
- // The StartCall instruction is being deleted, or is being moved and may later be deleted,
- // so remove its references from bailouts in the given range.
- // This only happens during cloning, which is rare, and only across the range of instructions
- // that evaluate outgoing arguments, which is long only in synthetic cases.
- Assert(this->m_opcode == Js::OpCode::StartCall);
- if (!this->m_func->hasBailout)
- {
- return;
- }
- FOREACH_INSTR_IN_RANGE(instr, this->m_next, endInstr)
- {
- if (instr->HasBailOutInfo())
- {
- BailOutInfo *bailOutInfo = instr->GetBailOutInfo();
- bailOutInfo->UnlinkStartCall(this);
- }
- }
- NEXT_INSTR_IN_RANGE;
- #endif
- }
- Opnd *Instr::FindCallArgumentOpnd(const Js::ArgSlot argSlot, IR::Instr * *const ownerInstrRef)
- {
- Assert(OpCodeAttr::CallInstr(m_opcode));
- Assert(argSlot != static_cast<Js::ArgSlot>(0));
- IR::Instr *argInstr = this;
- Assert(argInstr->GetSrc2());
- Assert(argInstr->GetSrc2()->IsSymOpnd());
- do
- {
- StackSym *const linkSym = argInstr->GetSrc2()->AsSymOpnd()->m_sym->AsStackSym();
- Assert(linkSym->IsSingleDef());
- Assert(linkSym->IsArgSlotSym());
- argInstr = linkSym->m_instrDef;
- Assert(argInstr->GetSrc2());
- if(argInstr->m_opcode == Js::OpCode::ArgOut_A_InlineSpecialized)
- {
- // This is a fake ArgOut, skip it
- continue;
- }
- if(linkSym->GetArgSlotNum() == argSlot)
- {
- if(ownerInstrRef)
- {
- *ownerInstrRef = argInstr;
- }
- return argInstr->GetSrc1();
- }
- } while(argInstr->GetSrc2()->IsSymOpnd());
- return nullptr;
- }
- bool
- Instr::FetchOperands(_Out_writes_(argsOpndLength) IR::Opnd **argsOpnd, uint argsOpndLength)
- {
- return this->ForEachCallDirectArgOutInstrBackward([&](IR::Instr *argOutInstr, uint argNum)
- {
- argsOpnd[argNum] = argOutInstr->GetSrc1();
- return argNum == 0;
- }, argsOpndLength);
- }
- bool Instr::ShouldCheckForNegativeZero() const
- {
- return !ignoreNegativeZero;
- }
- bool Instr::IsDstNotAlwaysConvertedToInt32() const
- {
- return !dstIsAlwaysConvertedToInt32;
- }
- bool Instr::IsDstNotAlwaysConvertedToNumber() const
- {
- return !dstIsAlwaysConvertedToNumber;
- }
- bool Instr::ShouldCheckForIntOverflow() const
- {
- return ShouldCheckFor32BitOverflow() || ShouldCheckForNon32BitOverflow();
- }
- bool Instr::ShouldCheckFor32BitOverflow() const
- {
- return !(ignoreIntOverflow || ignoreIntOverflowInRange);
- }
- bool Instr::ShouldCheckForNon32BitOverflow() const
- {
- return ignoreOverflowBitCount != 32;
- }
- template <typename InstrType> struct IRKindMap;
- template <> struct IRKindMap<IR::Instr> { static const IRKind InstrKind = InstrKindInstr; };
- template <> struct IRKindMap<IR::ProfiledInstr> { static const IRKind InstrKind = InstrKindProfiled; };
- template <> struct IRKindMap<IR::BranchInstr> { static const IRKind InstrKind = InstrKindBranch; };
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::New(Js::OpCode opcode, BailOutKind kind, IR::Instr * bailOutTarget, Func * func)
- {
- Assert(func == bailOutTarget->m_func);
- BailOutInfo * bailOutInfo = JitAnew(func->m_alloc, BailOutInfo, bailOutTarget->GetByteCodeOffset(), func);
- #if ENABLE_DEBUG_CONFIG_OPTIONS
- bailOutInfo->bailOutOpcode = opcode;
- #endif
- return BailOutInstrTemplate::New(opcode, kind, bailOutInfo, func);
- }
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::New(Js::OpCode opcode, IR::Opnd *dst, BailOutKind kind, IR::Instr * bailOutTarget, Func * func)
- {
- BailOutInstrTemplate *instr = BailOutInstrTemplate::New(opcode, kind, bailOutTarget, func);
- instr->SetDst(dst);
- return instr;
- }
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::New(Js::OpCode opcode, IR::Opnd *dst, IR::Opnd *src1, BailOutKind kind, IR::Instr * bailOutTarget, Func * func)
- {
- BailOutInstrTemplate *instr = BailOutInstrTemplate::New(opcode, dst, kind, bailOutTarget, func);
- instr->SetSrc1(src1);
- return instr;
- }
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::New(Js::OpCode opcode, IR::Opnd *dst, IR::Opnd *src1, IR::Opnd *src2, BailOutKind kind, IR::Instr * bailOutTarget, Func * func)
- {
- BailOutInstrTemplate *instr = BailOutInstrTemplate::New(opcode, dst, src1, kind, bailOutTarget, func);
- instr->SetSrc2(src2);
- return instr;
- }
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::New(Js::OpCode opcode, BailOutKind kind, BailOutInfo * bailOutInfo, Func * func)
- {
- Assert(func == bailOutInfo->bailOutFunc);
- Assert(IsValidBailOutKindAndBits(kind));
- BailOutInstrTemplate * bailOutInstr = JitAnew(func->m_alloc, BailOutInstrTemplate);
- bailOutInstr->Init(opcode, IRKindMap<InstrType>::InstrKind, func);
- #if ENABLE_DEBUG_CONFIG_OPTIONS
- bailOutInfo->bailOutOpcode = opcode;
- #endif
- bailOutInstr->bailOutInfo = bailOutInfo;
- bailOutInstr->bailOutKind = kind;
- bailOutInstr->auxBailOutKind = BailOutInvalid;
- if (bailOutInfo->bailOutInstr == nullptr)
- {
- bailOutInfo->bailOutInstr = bailOutInstr;
- }
- else if (bailOutInfo->sharedBailOutKind)
- {
- if (bailOutInfo->bailOutInstr->HasBailOutInfo())
- {
- bailOutInfo->sharedBailOutKind = bailOutInfo->bailOutInstr->GetBailOutKind() == kind;
- }
- else
- {
- // Rare cases where we have already generated the bailout record. Unlikely they share the same bailout kind as this is hit only when we try to
- // share bailout in lowerer. See Instr::ShareBailOut.
- bailOutInfo->sharedBailOutKind = false;
- }
- }
- func->hasBailout = true;
- // Indicate that the function has bailout instructions
- // This information is used to determine whether to free jitted loop bodies
- // If the function has bailout instructions, we keep the loop bodies alive
- // in case we bail out to the interpreter, so that we can reuse the jitted
- // loop bodies
- func->GetJnFunction()->SetHasBailoutInstrInJittedCode(true);
- return bailOutInstr;
- }
- template <typename InstrType>
- BailOutInstrTemplate<InstrType> *
- BailOutInstrTemplate<InstrType>::CloneBailOut() const
- {
- Assert(this->m_func->hasBailout);
- Assert(!this->bailOutInfo->wasCloned);
- BailOutInstrTemplate * bailOutInstr = BailOutInstrTemplate::New(this->m_opcode, this->bailOutKind, this->bailOutInfo, this->bailOutInfo->bailOutFunc);
- bailOutInstr->hasAuxBailOut = this->hasAuxBailOut;
- bailOutInstr->auxBailOutKind = this->auxBailOutKind;
- bailOutInstr->bailOutInfo->wasCloned = true;
- // the new copy is in the slow path and generate the real bailout
- bailOutInstr->bailOutInfo->bailOutInstr = bailOutInstr;
- return bailOutInstr;
- }
- template class BailOutInstrTemplate<IR::Instr>;
- ///----------------------------------------------------------------------------
- ///
- /// EntryInstr::New
- ///
- /// Create an EntryInstr.
- ///
- ///----------------------------------------------------------------------------
- EntryInstr *
- EntryInstr::New(Js::OpCode opcode, Func *func)
- {
- EntryInstr * entryInstr;
- entryInstr = JitAnew(func->m_alloc, IR::EntryInstr);
- entryInstr->Init(opcode, InstrKindEntry, func);
- return entryInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// ExitInstr::New
- ///
- /// Create an ExitInstr.
- ///
- ///----------------------------------------------------------------------------
- ExitInstr *
- ExitInstr::New(Js::OpCode opcode, Func *func)
- {
- ExitInstr * exitInstr;
- exitInstr = JitAnew(func->m_alloc, IR::ExitInstr);
- exitInstr->Init(opcode, InstrKindExit, func);
- return exitInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// LabelInstr::New
- ///
- /// Create a label.
- ///
- ///----------------------------------------------------------------------------
- LabelInstr *
- LabelInstr::New(Js::OpCode opcode, Func *func, bool isOpHelper)
- {
- LabelInstr * labelInstr;
- labelInstr = JitAnew(func->m_alloc, IR::LabelInstr, func->m_alloc);
- labelInstr->Init(opcode, InstrKindLabel, func, isOpHelper);
- return labelInstr;
- }
- void
- LabelInstr::Init(Js::OpCode opcode, IRKind kind, Func *func, bool isOpHelper)
- {
- // Pass in the region when this is called from anywhere between the Lowerer and EHBailoutPatchUp code?
- __super::Init(opcode, kind, func);
- this->isOpHelper = isOpHelper;
- this->m_pc.pc = nullptr;
- this->m_id = ++(func->GetTopFunc()->m_labelCount);
- AssertMsg(this->m_id != 0, "Label numbers wrapped around??!?");
- }
- ///----------------------------------------------------------------------------
- ///
- /// LabelInstr::AddLabelRef
- ///
- /// Add a branch to the list of label references.
- ///
- ///----------------------------------------------------------------------------
- void
- LabelInstr::AddLabelRef(BranchInstr *branchRef)
- {
- this->labelRefs.Prepend(branchRef);
- }
- ///----------------------------------------------------------------------------
- ///
- /// LabelInstr::RemoveLabelRef
- ///
- /// Remove a branch from the list of label references.
- ///
- ///----------------------------------------------------------------------------
- void
- LabelInstr::RemoveLabelRef(BranchInstr *branchRef)
- {
- FOREACH_SLISTCOUNTED_ENTRY_EDITING(BranchInstr*, branchEntry, &this->labelRefs, iter)
- {
- if (branchEntry == branchRef)
- {
- iter.RemoveCurrent();
- return;
- }
- } NEXT_SLISTCOUNTED_ENTRY_EDITING;
- AssertMsg(UNREACHED, "Branch not found on labelRef list");
- }
- ///----------------------------------------------------------------------------
- ///
- /// BranchInstr::New
- ///
- /// Create a Br (unconditional) BranchInstr.
- ///
- ///----------------------------------------------------------------------------
- BranchInstr *
- BranchInstr::New(Js::OpCode opcode, LabelInstr * branchTarget, Func *func)
- {
- BranchInstr * branchInstr;
- branchInstr = JitAnew(func->m_alloc, IR::BranchInstr);
- branchInstr->Init(opcode, InstrKindBranch, func);
- branchInstr->SetTarget(branchTarget);
- branchInstr->m_dst = nullptr;
- branchInstr->m_src1 = nullptr;
- branchInstr->m_src2 = nullptr;
- branchInstr->m_byteCodeReg = Js::Constants::NoRegister;
- #if DBG
- branchInstr->m_isHelperToNonHelperBranch = false;
- #endif
- return branchInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// BranchInstr::New
- ///
- /// Create a BrB BranchInstr (1-operand conditional branch).
- ///
- ///----------------------------------------------------------------------------
- BranchInstr *
- BranchInstr::New(Js::OpCode opcode, LabelInstr * branchTarget, Opnd *srcOpnd, Func *func)
- {
- BranchInstr * branchInstr;
- branchInstr = BranchInstr::New(opcode, branchTarget, func);
- branchInstr->SetSrc1(srcOpnd);
- return branchInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// BranchInstr::New
- ///
- /// Create a BrBReturn BranchInstr (1-operand conditional branch. If condition fails return the result of the condition).
- ///
- ///----------------------------------------------------------------------------
- BranchInstr *
- BranchInstr::New(Js::OpCode opcode, Opnd* destOpnd, LabelInstr * branchTarget, Opnd *srcOpnd, Func *func)
- {
- BranchInstr * branchInstr;
- branchInstr = BranchInstr::New(opcode, branchTarget, func);
- branchInstr->SetSrc1(srcOpnd);
- branchInstr->SetDst(destOpnd);
- return branchInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// BranchInstr::New
- ///
- /// Create a BrReg2 BranchInstr (2-operand conditional branch).
- ///
- ///----------------------------------------------------------------------------
- BranchInstr *
- BranchInstr::New(Js::OpCode opcode, LabelInstr * branchTarget, Opnd *src1Opnd, Opnd *src2Opnd, Func *func)
- {
- BranchInstr * branchInstr;
- branchInstr = BranchInstr::New(opcode, branchTarget, src1Opnd, func);
- branchInstr->SetSrc2(src2Opnd);
- return branchInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// MultiBranchInstr::New
- ///
- /// Create a MultiBr BranchInstr (unconditional multi branch).
- ///
- ///----------------------------------------------------------------------------
- MultiBranchInstr *
- MultiBranchInstr::New(Js::OpCode opcode, IR::Opnd * srcOpnd, Func * func)
- {
- MultiBranchInstr * multiBranchInstr;
- multiBranchInstr = MultiBranchInstr::New(opcode, func);
- multiBranchInstr->SetSrc1(srcOpnd);
- return multiBranchInstr;
- }
- MultiBranchInstr *
- MultiBranchInstr::New(Js::OpCode opcode, Func * func)
- {
- JitArenaAllocator * m_funcAlloc = func->m_alloc;
- MultiBranchInstr * multiBranchInstr;
- multiBranchInstr = JitAnew(m_funcAlloc, IR::MultiBranchInstr);
- multiBranchInstr->Init(opcode, InstrKindBranch, func);
- return multiBranchInstr;
- }
- bool
- BranchInstr::ReplaceTarget(IR::LabelInstr * oldLabelInstr, IR::LabelInstr * newLabelInstr)
- {
- if (this->IsMultiBranch())
- {
- return this->AsMultiBrInstr()->ReplaceTarget(oldLabelInstr, newLabelInstr);
- }
- if (this->GetTarget() == oldLabelInstr)
- {
- this->SetTarget(newLabelInstr);
- return true;
- }
- return false;
- }
- bool
- MultiBranchInstr::ReplaceTarget(IR::LabelInstr * oldLabelInstr, IR::LabelInstr * newLabelInstr)
- {
- Assert(this->IsMultiBranch());
- bool remapped = false;
- this->UpdateMultiBrLabels([=, &remapped](IR::LabelInstr * targetLabel) -> IR::LabelInstr *
- {
- if (targetLabel == oldLabelInstr)
- {
- this->ChangeLabelRef(targetLabel, newLabelInstr);
- remapped = true;
- return newLabelInstr;
- }
- return targetLabel;
- });
- return remapped;
- }
- void
- MultiBranchInstr::ClearTarget()
- {
- Assert(IsMultiBranch());
- MapMultiBrLabels([&](LabelInstr *const targetLabel)
- {
- ChangeLabelRef(targetLabel, nullptr);
- });
- m_branchTargets = nullptr;
- }
- BranchInstr *
- BranchInstr::CloneBranchInstr() const
- {
- AssertMsg(!this->IsMultiBranch(),"Cloning Not supported for MultiBranchInstr");
- Func * func = this->m_func;
- // See if the target has already been cloned.
- IR::LabelInstr * instrLabel = this->GetTarget()->CloneLabel(false);
- if (instrLabel == nullptr)
- {
- // We didn't find a clone for this label.
- // We'll go back and retarget the cloned branch if the target turns up in the cloned range.
- instrLabel = this->GetTarget();
- func->GetCloner()->fRetargetClonedBranch = TRUE;
- }
- return IR::BranchInstr::New(this->m_opcode, instrLabel, func);
- }
- void
- BranchInstr::Invert()
- {
- /*
- * If one of the operands to a relational operator is 'undefined', the result
- * is always false. Don't invert such branches as they result in a jump to
- * the wrong target.
- */
- switch (this->m_opcode)
- {
- case Js::OpCode::BrGt_A:
- this->m_opcode = Js::OpCode::BrNotGt_A;
- break;
- case Js::OpCode::BrNotGt_A:
- this->m_opcode = Js::OpCode::BrGt_A;
- break;
- case Js::OpCode::BrGe_A:
- this->m_opcode = Js::OpCode::BrNotGe_A;
- break;
- case Js::OpCode::BrNotGe_A:
- this->m_opcode = Js::OpCode::BrGe_A;
- break;
- case Js::OpCode::BrLt_A:
- this->m_opcode = Js::OpCode::BrNotLt_A;
- break;
- case Js::OpCode::BrNotLt_A:
- this->m_opcode = Js::OpCode::BrLt_A;
- break;
- case Js::OpCode::BrLe_A:
- this->m_opcode = Js::OpCode::BrNotLe_A;
- break;
- case Js::OpCode::BrNotLe_A:
- this->m_opcode = Js::OpCode::BrLe_A;
- break;
- case Js::OpCode::BrEq_A:
- this->m_opcode = Js::OpCode::BrNotEq_A;
- break;
- case Js::OpCode::BrNotEq_A:
- this->m_opcode = Js::OpCode::BrEq_A;
- break;
- case Js::OpCode::BrNeq_A:
- this->m_opcode = Js::OpCode::BrNotNeq_A;
- break;
- case Js::OpCode::BrNotNeq_A:
- this->m_opcode = Js::OpCode::BrNeq_A;
- break;
- case Js::OpCode::Br:
- break;
- case Js::OpCode::BrFalse_A:
- this->m_opcode = Js::OpCode::BrTrue_A;
- break;
- case Js::OpCode::BrTrue_A:
- this->m_opcode = Js::OpCode::BrFalse_A;
- break;
- case Js::OpCode::BrSrEq_A:
- this->m_opcode = Js::OpCode::BrSrNotEq_A;
- break;
- case Js::OpCode::BrSrNotEq_A:
- this->m_opcode = Js::OpCode::BrSrEq_A;
- break;
- case Js::OpCode::BrSrNeq_A:
- this->m_opcode = Js::OpCode::BrSrNotNeq_A;
- break;
- case Js::OpCode::BrSrNotNeq_A:
- this->m_opcode = Js::OpCode::BrSrNeq_A;
- break;
- case Js::OpCode::BrOnHasProperty:
- this->m_opcode = Js::OpCode::BrOnNoProperty;
- break;
- case Js::OpCode::BrOnNoProperty:
- this->m_opcode = Js::OpCode::BrOnHasProperty;
- break;
- case Js::OpCode::BrTrue_I4:
- this->m_opcode = Js::OpCode::BrFalse_I4;
- break;
- case Js::OpCode::BrFalse_I4:
- this->m_opcode = Js::OpCode::BrTrue_I4;
- break;
- case Js::OpCode::BrEq_I4:
- this->m_opcode = Js::OpCode::BrNeq_I4;
- break;
- case Js::OpCode::BrNeq_I4:
- this->m_opcode = Js::OpCode::BrEq_I4;
- break;
- case Js::OpCode::BrGe_I4:
- this->m_opcode = Js::OpCode::BrLt_I4;
- break;
- case Js::OpCode::BrGt_I4:
- this->m_opcode = Js::OpCode::BrLe_I4;
- break;
- case Js::OpCode::BrLe_I4:
- this->m_opcode = Js::OpCode::BrGt_I4;
- break;
- case Js::OpCode::BrLt_I4:
- this->m_opcode = Js::OpCode::BrGe_I4;
- break;
- case Js::OpCode::BrUnGe_A:
- this->m_opcode = Js::OpCode::BrUnLt_A;
- break;
- case Js::OpCode::BrUnGt_A:
- this->m_opcode = Js::OpCode::BrUnLe_A;
- break;
- case Js::OpCode::BrUnLe_A:
- this->m_opcode = Js::OpCode::BrUnGt_A;
- break;
- case Js::OpCode::BrUnLt_A:
- this->m_opcode = Js::OpCode::BrUnGe_A;
- break;
- case Js::OpCode::BrUnGe_I4:
- this->m_opcode = Js::OpCode::BrUnLt_I4;
- break;
- case Js::OpCode::BrUnGt_I4:
- this->m_opcode = Js::OpCode::BrUnLe_I4;
- break;
- case Js::OpCode::BrUnLe_I4:
- this->m_opcode = Js::OpCode::BrUnGt_I4;
- break;
- case Js::OpCode::BrUnLt_I4:
- this->m_opcode = Js::OpCode::BrUnGe_I4;
- break;
- case Js::OpCode::BrOnEmpty:
- this->m_opcode = Js::OpCode::BrOnNotEmpty;
- break;
- case Js::OpCode::BrOnNotEmpty:
- this->m_opcode = Js::OpCode::BrOnEmpty;
- break;
- case Js::OpCode::BrHasSideEffects:
- this->m_opcode = Js::OpCode::BrNotHasSideEffects;
- break;
- case Js::OpCode::BrFncEqApply:
- this->m_opcode = Js::OpCode::BrFncNeqApply;
- break;
- case Js::OpCode::BrFncNeqApply:
- this->m_opcode = Js::OpCode::BrFncEqApply;
- break;
- case Js::OpCode::BrNotHasSideEffects:
- this->m_opcode = Js::OpCode::BrHasSideEffects;
- break;
- case Js::OpCode::BrNotAddr_A:
- this->m_opcode = Js::OpCode::BrAddr_A;
- break;
- case Js::OpCode::BrAddr_A:
- this->m_opcode = Js::OpCode::BrNotAddr_A;
- break;
- case Js::OpCode::BrFncCachedScopeEq:
- this->m_opcode = Js::OpCode::BrFncCachedScopeNeq;
- break;
- case Js::OpCode::BrFncCachedScopeNeq:
- this->m_opcode = Js::OpCode::BrFncCachedScopeEq;
- break;
- case Js::OpCode::BrOnException:
- this->m_opcode = Js::OpCode::BrOnNoException;
- break;
- default:
- AssertMsg(UNREACHED, "Unhandled branch");
- }
- }
- bool
- BranchInstr::IsLoopTail(Func * func)
- {
- Assert(func->isPostLower);
- IR::LabelInstr * target = this->GetTarget();
- if (!target->m_isLoopTop)
- {
- return false;
- }
- IR::BranchInstr * lastBranchInstr = nullptr;
- uint32 lastBranchNum = 0;
- FOREACH_SLISTCOUNTED_ENTRY(IR::BranchInstr *, ref, &target->labelRefs)
- {
- if (ref->GetNumber() > lastBranchNum)
- {
- lastBranchInstr = ref;
- lastBranchNum = lastBranchInstr->GetNumber();
- }
- }
- NEXT_SLISTCOUNTED_ENTRY;
- if (this == lastBranchInstr)
- {
- return true;
- }
- return false;
- }
- ///----------------------------------------------------------------------------
- ///
- /// PragmaInstr::New
- ///
- /// Create a PragmaInstr.
- ///
- ///----------------------------------------------------------------------------
- PragmaInstr *
- PragmaInstr::New(Js::OpCode opcode, uint32 index, Func *func)
- {
- PragmaInstr * pragmaInstr;
- pragmaInstr = JitAnew(func->m_alloc, IR::PragmaInstr);
- pragmaInstr->Init(opcode, InstrKindPragma, func);
- pragmaInstr->m_statementIndex = index;
- return pragmaInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// PragmaInstr::Instr
- ///
- /// Record the information encoded in the pragma
- ///
- ///----------------------------------------------------------------------------
- #if DBG_DUMP | defined(VTUNE_PROFILING)
- void
- PragmaInstr::Record(uint32 nativeBufferOffset)
- {
- // Currently the only pragma instructions are for Source Info
- Assert(this->m_func->GetTopFunc()->DoRecordNativeMap());
- this->m_func->GetTopFunc()->m_workItem->RecordNativeMap(nativeBufferOffset, m_statementIndex);
- }
- #endif
- void
- PragmaInstr::RecordThrowMap(Js::SmallSpanSequenceIter& iter, uint32 nativeBufferOffset)
- {
- m_func->GetTopFunc()->m_workItem->RecordNativeThrowMap(iter, nativeBufferOffset, m_statementIndex);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::New
- ///
- /// Create an Instr.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::New(Js::OpCode opcode, Func *func)
- {
- Instr * instr;
- instr = JitAnew(func->m_alloc, IR::Instr);
- instr->Init(opcode, InstrKindInstr, func);
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::New
- ///
- /// Create an Instr with dst.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::New(Js::OpCode opcode, Opnd *dstOpnd, Func *func)
- {
- Instr * instr;
- instr = Instr::New(opcode, func);
- instr->SetDst(dstOpnd);
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::New
- ///
- /// Create an Instr with dst and a src.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Func *func)
- {
- Instr * instr;
- instr = Instr::New(opcode, dstOpnd, func);
- instr->SetSrc1(src1Opnd);
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::New
- ///
- /// Create an Instr with dst and 2 srcs.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::New(Js::OpCode opcode, Opnd *dstOpnd, Opnd *src1Opnd, Opnd *src2Opnd, Func *func)
- {
- Instr * instr;
- instr = Instr::New(opcode, dstOpnd, src1Opnd, func);
- instr->SetSrc2(src2Opnd);
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::SetDst
- ///
- /// Set the dst for 'this' instruction. Automatically maintain isSingleDef
- /// and instrDef of stackSyms.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::SetDst(Opnd * newDst)
- {
- AssertMsg(newDst != nullptr, "Calling SetDst with a NULL dst");
- AssertMsg(this->m_dst == nullptr, "Calling SetDst without unlinking/freeing the current dst");
- Assert(!(newDst->IsRegOpnd() && newDst->AsRegOpnd()->IsSymValueFrozen()));
- newDst = newDst->Use(m_func);
- this->m_dst = newDst;
- // If newDst isSingleDef, set instrDef
- StackSym *stackSym;
- if (newDst->IsRegOpnd() && newDst->AsRegOpnd()->m_sym)
- {
- stackSym = newDst->AsRegOpnd()->m_sym->AsStackSym();
- }
- else if (newDst->IsSymOpnd() && newDst->AsSymOpnd()->m_sym->IsStackSym())
- {
- stackSym = newDst->AsSymOpnd()->m_sym->AsStackSym();
- }
- else
- {
- stackSym = nullptr;
- }
- if (stackSym && stackSym->m_isSingleDef)
- {
- if (stackSym->m_instrDef)
- {
- AssertMsg(!stackSym->IsArgSlotSym(), "Arg Slot sym needs to be single def to maintain the StartCall arg links");
- // Multiple defs, clear isSingleDef flag
- stackSym->m_isSingleDef = false;
- stackSym->m_instrDef = nullptr;
- stackSym->m_isConst = false;
- stackSym->m_isIntConst = false;
- stackSym->m_isTaggableIntConst = false;
- stackSym->m_isNotInt = false;
- stackSym->m_isStrConst = false;
- stackSym->m_isStrEmpty = false;
- stackSym->m_isFltConst = false;
- }
- else
- {
- stackSym->m_instrDef = this;
- }
- }
- return newDst;
- }
- Opnd *
- Instr::SetFakeDst(Opnd * newDst)
- {
- AssertMsg(newDst != nullptr, "Calling SetDst with a NULL dst");
- AssertMsg(this->m_dst == nullptr, "Calling SetDst without unlinking/freeing the current dst");
- Assert(!(newDst->IsRegOpnd() && newDst->AsRegOpnd()->IsSymValueFrozen()));
- newDst = newDst->Use(m_func);
- this->m_dst = newDst;
- #if DBG
- newDst->isFakeDst = true;
- #endif
- return newDst;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::UnlinkDst
- ///
- /// Unlinks the dst for 'this' instruction. Automatically maintains
- /// instrDef of stackSyms.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::UnlinkDst()
- {
- Opnd * oldDst = this->m_dst;
- StackSym *stackSym = nullptr;
- // If oldDst isSingleDef, clear instrDef
- if (oldDst->IsRegOpnd())
- {
- stackSym = oldDst->AsRegOpnd()->m_sym;
- }
- else if (oldDst->IsSymOpnd())
- {
- Sym *sym = oldDst->AsSymOpnd()->m_sym;
- if (sym->IsStackSym())
- {
- stackSym = sym->AsStackSym();
- }
- }
- #if DBG
- if (oldDst->isFakeDst)
- {
- oldDst->isFakeDst = false;
- }
- #endif
- if (stackSym && stackSym->m_isSingleDef)
- {
- AssertMsg(stackSym->m_instrDef == this, "m_instrDef incorrectly set");
- stackSym->m_instrDef = nullptr;
- }
- oldDst->UnUse();
- this->m_dst = nullptr;
- return oldDst;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::FreeDst
- ///
- /// Unlinks and free the dst for 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::FreeDst()
- {
- Opnd * unlinkedDst;
- unlinkedDst = this->UnlinkDst();
- unlinkedDst->Free(this->m_func);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::ReplaceDst
- ///
- /// Unlink this dst from this instr, free it, and replace it with newDst.
- /// The new dst is returned.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::ReplaceDst(Opnd * newDst)
- {
- this->FreeDst();
- return this->SetDst(newDst);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::SinkDst
- ///
- /// Replace current dst with new symbol, and assign new symbol using the
- /// given opcode to the previous dst.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::SinkDst(Js::OpCode assignOpcode, RegNum regNum, IR::Instr *insertAfterInstr)
- {
- return SinkDst(assignOpcode, StackSym::New(TyVar, m_func), regNum, insertAfterInstr);
- }
- Instr *
- Instr::SinkDst(Js::OpCode assignOpcode, StackSym * stackSym, RegNum regNum, IR::Instr *insertAfterInstr)
- {
- if(!insertAfterInstr)
- {
- insertAfterInstr = this;
- }
- Opnd *oldDst, *newDst;
- Instr * newInstr;
- IRType type;
- oldDst = this->UnlinkDst();
- type = oldDst->GetType();
- newDst = this->SetDst(RegOpnd::New(stackSym, regNum, type, m_func));
- newInstr = Instr::New(assignOpcode, oldDst, newDst, m_func);
- insertAfterInstr->InsertAfter(newInstr);
- return newInstr;
- }
- IR::Instr *
- Instr::SinkInstrBefore(IR::Instr * instrTarget)
- {
- // Move this instruction down to the target location, preserving
- // the use(s), if necessary, from redefinition between the original
- // location and the new one.
- if (this->m_next == instrTarget)
- {
- return this->m_prev;
- }
- StackSym *sym;
- if (this->m_src1)
- {
- sym = this->m_src1->GetStackSym();
- if (sym && !sym->m_isSingleDef)
- {
- this->HoistSrc1(Js::OpCode::Ld_A);
- }
- if (this->m_src2)
- {
- sym = this->m_src2->GetStackSym();
- if (sym && !sym->m_isSingleDef)
- {
- this->HoistSrc2(Js::OpCode::Ld_A);
- }
- }
- }
- // Move the instruction down to the target. Return the instruction
- // that preceded the sunk instruction at its original location.
- // (This lets the caller find a Ld_A that this call inserted.)
- IR::Instr * instrPrev = this->m_prev;
- this->Unlink();
- instrTarget->InsertBefore(this);
- return instrPrev;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::UnlinkSrc1
- ///
- /// Unlinks the src1 for 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::UnlinkSrc1()
- {
- Opnd * oldSrc = this->m_src1;
- oldSrc->UnUse();
- this->m_src1 = nullptr;
- return oldSrc;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::FreeSrc1
- ///
- /// Unlinks and free the src1 for 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::FreeSrc1()
- {
- Opnd * unlinkedSrc;
- unlinkedSrc = this->UnlinkSrc1();
- unlinkedSrc->Free(this->m_func);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::ReplaceSrc1
- ///
- /// Unlink src1 from this instr, free it, and replace it with newSrc.
- /// The new src is returned.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::ReplaceSrc1(Opnd * newSrc)
- {
- this->FreeSrc1();
- return this->SetSrc1(newSrc);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::HoistSrc1
- ///
- /// Replace current src with new symbol, and assign new symbol using the
- /// given opcode from the previous src.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::HoistSrc1(Js::OpCode assignOpcode, RegNum regNum, StackSym *newSym)
- {
- Opnd *oldSrc, *newSrc;
- Instr * newInstr;
- IRType type;
- oldSrc = this->UnlinkSrc1();
- type = oldSrc->GetType();
- const bool creatingNewSym = !newSym;
- if(creatingNewSym)
- {
- newSym = StackSym::New(type, m_func);
- }
- newSrc = this->SetSrc1(RegOpnd::New(newSym, regNum, type, m_func));
- newSrc->SetValueType(oldSrc->GetValueType());
- newInstr = Instr::New(assignOpcode, newSrc, oldSrc, m_func);
- this->InsertBefore(newInstr);
- if(creatingNewSym)
- {
- if (oldSrc->IsRegOpnd())
- {
- newSym->CopySymAttrs(oldSrc->AsRegOpnd()->m_sym);
- }
- else if (oldSrc->IsImmediateOpnd())
- {
- newSym->SetIsConst();
- }
- }
- return newInstr;
- }
- bool
- Instr::IsSrc1FunctionObject()
- {
- if (!this->GetSrc1())
- {
- return false;
- }
- if (this->GetSrc1()->IsAddrOpnd())
- {
- return this->GetSrc1()->AsAddrOpnd()->m_isFunction;
- }
- if (this->GetSrc1()->IsRegOpnd())
- {
- return (this->GetSrc1()->AsRegOpnd()->m_sym->AsStackSym()->IsSingleDef() &&
- this->GetSrc1()->AsRegOpnd()->m_sym->AsStackSym()->GetInstrDef()->GetSrc1()->IsAddrOpnd() &&
- this->GetSrc1()->AsRegOpnd()->m_sym->AsStackSym()->GetInstrDef()->GetSrc1()->AsAddrOpnd()->m_isFunction);
- }
- return false;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::UnlinkSrc2
- ///
- /// Unlinks the src2 for 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::UnlinkSrc2()
- {
- Opnd * oldSrc = this->m_src2;
- oldSrc->UnUse();
- this->m_src2 = nullptr;
- return oldSrc;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::FreeSrc2
- ///
- /// Unlinks and free the src2 for 'this' instruction.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::FreeSrc2()
- {
- Opnd * unlinkedSrc;
- unlinkedSrc = this->UnlinkSrc2();
- unlinkedSrc->Free(this->m_func);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::ReplaceSrc2
- ///
- /// Unlink src2 from this instr, free it, and replace it with newSrc.
- /// The new src is returned.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::ReplaceSrc2(Opnd * newSrc)
- {
- this->FreeSrc2();
- return this->SetSrc2(newSrc);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::HoistSrc2
- ///
- /// Replace current src with new symbol, and assign new symbol using the
- /// given opcode from the previous src.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::HoistSrc2(Js::OpCode assignOpcode, RegNum regNum, StackSym *newSym)
- {
- Opnd *oldSrc, *newSrc;
- Instr * newInstr;
- IRType type;
- oldSrc = this->UnlinkSrc2();
- type = oldSrc->GetType();
- const bool creatingNewSym = !newSym;
- if(creatingNewSym)
- {
- newSym = StackSym::New(type, m_func);
- }
- newSrc = this->SetSrc2(RegOpnd::New(newSym, regNum, type, m_func));
- newSrc->SetValueType(oldSrc->GetValueType());
- newInstr = Instr::New(assignOpcode, newSrc, oldSrc, m_func);
- this->InsertBefore(newInstr);
- if(creatingNewSym)
- {
- if (oldSrc->IsRegOpnd())
- {
- newSym->CopySymAttrs(oldSrc->AsRegOpnd()->m_sym);
- }
- else if (oldSrc->IsIntConstOpnd())
- {
- newSym->SetIsIntConst(oldSrc->AsIntConstOpnd()->GetValue());
- }
- }
- return newInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::HoistIndirOffset
- ///
- /// Replace the offset of the given indir with a new symbol, which becomes the indir index.
- /// Assign the new symbol by creating an assignment from the constant offset.
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::HoistIndirOffset(IR::IndirOpnd *indirOpnd, RegNum regNum)
- {
- int32 offset = indirOpnd->GetOffset();
- if (indirOpnd->GetIndexOpnd())
- {
- return HoistIndirOffsetAsAdd(indirOpnd, indirOpnd->GetBaseOpnd(), offset, regNum);
- }
- IntConstOpnd *offsetOpnd = IntConstOpnd::New(offset, TyInt32, this->m_func);
- RegOpnd *indexOpnd = RegOpnd::New(StackSym::New(TyMachReg, this->m_func), regNum, TyMachReg, this->m_func);
- #if defined(DBG) && defined(_M_ARM)
- if (regNum == SCRATCH_REG)
- {
- AssertMsg(indirOpnd->GetBaseOpnd()->GetReg()!= SCRATCH_REG, "Why both are SCRATCH_REG");
- if (this->GetSrc1() && this->GetSrc1()->IsRegOpnd())
- {
- Assert(this->GetSrc1()->AsRegOpnd()->GetReg() != SCRATCH_REG);
- }
- if (this->GetSrc2() && this->GetSrc2()->IsRegOpnd())
- {
- Assert(this->GetSrc2()->AsRegOpnd()->GetReg() != SCRATCH_REG);
- }
- if (this->GetDst() && this->GetDst()->IsRegOpnd())
- {
- Assert(this->GetDst()->AsRegOpnd()->GetReg() != SCRATCH_REG);
- }
- }
- #endif
- // Clear the offset and add a new reg as the index.
- indirOpnd->SetOffset(0);
- indirOpnd->SetIndexOpnd(indexOpnd);
- Instr *instrAssign = LowererMD::CreateAssign(indexOpnd, offsetOpnd, this);
- indexOpnd->m_sym->SetIsIntConst(offset);
- return instrAssign;
- }
- IndirOpnd *
- Instr::HoistMemRefAddress(MemRefOpnd *const memRefOpnd, const Js::OpCode loadOpCode)
- {
- Assert(memRefOpnd);
- #if defined(_M_IX86) || defined(_M_X64)
- Assert(!LowererMDArch::IsLegalMemLoc(memRefOpnd));
- #endif
- void * address = memRefOpnd->GetMemLoc();
- IR::AddrOpndKind kind = memRefOpnd->GetAddrKind();
- Func *const func = m_func;
- IR::IndirOpnd * indirOpnd = func->GetTopFunc()->GetConstantAddressIndirOpnd(address, kind, memRefOpnd->GetType(), loadOpCode);
- if (indirOpnd == nullptr)
- {
- IR::RegOpnd * addressRegOpnd = IR::RegOpnd::New(TyMachPtr, func);
- IR::Instr *const newInstr =
- IR::Instr::New(
- loadOpCode,
- addressRegOpnd,
- IR::AddrOpnd::New(address, kind, func, true),
- func);
- InsertBefore(newInstr);
- indirOpnd = IR::IndirOpnd::New(addressRegOpnd, 0, memRefOpnd->GetType(), func, true);
- #if DBG_DUMP
- indirOpnd->SetAddrKind(kind, address);
- #endif
- }
- return DeepReplace(memRefOpnd, indirOpnd)->AsIndirOpnd();
- }
- Opnd *
- Instr::Replace(Opnd *oldOpnd, Opnd *newOpnd)
- {
- if (oldOpnd == this->GetDst())
- {
- return this->ReplaceDst(newOpnd);
- }
- else
- {
- return this->ReplaceSrc(oldOpnd, newOpnd);
- }
- }
- Opnd *Instr::DeepReplace(Opnd *const oldOpnd, Opnd *const newOpnd)
- {
- Assert(oldOpnd);
- Assert(newOpnd);
- IR::Opnd *opnd = GetDst();
- if(opnd && oldOpnd != opnd && oldOpnd->IsEqual(opnd))
- {
- ReplaceDst(newOpnd);
- }
- opnd = GetSrc1();
- if(opnd && oldOpnd != opnd && oldOpnd->IsEqual(opnd))
- {
- ReplaceSrc1(newOpnd);
- }
- opnd = GetSrc2();
- if(opnd && oldOpnd != opnd && oldOpnd->IsEqual(opnd))
- {
- ReplaceSrc2(newOpnd);
- }
- // Do this last because Replace will delete oldOpnd
- return Replace(oldOpnd, newOpnd);
- }
- Instr *
- Instr::HoistIndirOffsetAsAdd(IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum)
- {
- IR::RegOpnd *newBaseOpnd = IR::RegOpnd::New(StackSym::New(TyMachPtr, this->m_func), regNum, TyMachPtr, this->m_func);
- IR::IntConstOpnd *src2 = IR::IntConstOpnd::New(offset, TyInt32, this->m_func);
- IR::Instr * instrAdd = IR::Instr::New(Js::OpCode::ADD, newBaseOpnd, baseOpnd, src2, this->m_func);
- this->InsertBefore(instrAdd);
- orgOpnd->ReplaceBaseOpnd(newBaseOpnd);
- orgOpnd->SetOffset(0);
- return instrAdd;
- }
- Instr *
- Instr::HoistIndirIndexOpndAsAdd(IR::IndirOpnd *orgOpnd, IR::Opnd *baseOpnd, IR::Opnd *indexOpnd, RegNum regNum)
- {
- IR::RegOpnd *newBaseOpnd = IR::RegOpnd::New(StackSym::New(TyMachPtr, this->m_func), regNum, TyMachPtr, this->m_func);
- IR::Instr * instrAdd = IR::Instr::New(Js::OpCode::ADD, newBaseOpnd, baseOpnd, indexOpnd, this->m_func);
- this->InsertBefore(instrAdd);
- orgOpnd->ReplaceBaseOpnd(newBaseOpnd);
- orgOpnd->SetIndexOpnd(nullptr);
- return instrAdd;
- }
- Instr *
- Instr::HoistSymOffsetAsAdd(IR::SymOpnd *orgOpnd, IR::Opnd *baseOpnd, int offset, RegNum regNum)
- {
- IR::IndirOpnd *newIndirOpnd = IR::IndirOpnd::New(baseOpnd->AsRegOpnd(), 0, TyMachPtr, this->m_func);
- this->Replace(orgOpnd, newIndirOpnd); // Replace SymOpnd with IndirOpnd
- return this->HoistIndirOffsetAsAdd(newIndirOpnd, baseOpnd, offset, regNum);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::HoistSymOffset
- ///
- /// Replace the given sym with an indir using the given base and offset.
- /// (This is used, for instance, to hoist a sym offset that is too large to encode.)
- ///
- ///----------------------------------------------------------------------------
- Instr *
- Instr::HoistSymOffset(SymOpnd *symOpnd, RegNum baseReg, uint32 offset, RegNum regNum)
- {
- IR::RegOpnd *baseOpnd = IR::RegOpnd::New(nullptr, baseReg, TyMachPtr, this->m_func);
- IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(baseOpnd, offset, symOpnd->GetType(), this->m_func);
- if (symOpnd == this->GetDst())
- {
- this->ReplaceDst(indirOpnd);
- }
- else
- {
- this->ReplaceSrc(symOpnd, indirOpnd);
- }
- return this->HoistIndirOffset(indirOpnd, regNum);
- }
- Opnd *
- Instr::UnlinkSrc(Opnd *src)
- {
- if (src == this->GetSrc1())
- {
- return this->UnlinkSrc1();
- }
- else
- {
- AssertMsg(src == this->GetSrc2(), "Src not found");
- return this->UnlinkSrc2();
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::ReplaceSrc
- ///
- /// Unlink oldSrc from this instr, free it, and replace it with newSrc.
- /// The new src is returned.
- ///
- ///----------------------------------------------------------------------------
- Opnd *
- Instr::ReplaceSrc(Opnd *oldSrc, Opnd * newSrc)
- {
- if (oldSrc == this->GetSrc1())
- {
- return this->ReplaceSrc1(newSrc);
- }
- else
- {
- AssertMsg(oldSrc == this->GetSrc2(), "OldSrc not found");
- return this->ReplaceSrc2(newSrc);
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::IsRealInstr
- ///
- /// Does this instr generate code?
- ///
- ///----------------------------------------------------------------------------
- bool
- Instr::IsRealInstr() const
- {
- switch (m_opcode)
- {
- case Js::OpCode::Label:
- case Js::OpCode::StatementBoundary:
- case Js::OpCode::NoImplicitCallUses:
- case Js::OpCode::NoIntOverflowBoundary:
- return false;
- default:
- return true;
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetNextRealInstr
- ///
- ///----------------------------------------------------------------------------
- IR::Instr *
- Instr::GetNextRealInstr() const
- {
- IR::Instr *instr = this->m_next;
- while (instr != nullptr && !instr->IsRealInstr())
- {
- AssertMsg(instr->m_next || instr->IsPragmaInstr(), "GetNextRealInstr() failed...");
- instr = instr->m_next;
- }
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetNextRealInstrOrLabel
- ///
- ///----------------------------------------------------------------------------
- IR::Instr *
- Instr::GetNextRealInstrOrLabel() const
- {
- IR::Instr *instr = this->m_next;
- while (instr != nullptr && !instr->IsLabelInstr() && !instr->IsRealInstr())
- {
- instr = instr->m_next;
- AssertMsg(instr, "GetNextRealInstrOrLabel() failed...");
- }
- return instr;
- }
- IR::Instr *
- Instr::GetNextBranchOrLabel() const
- {
- IR::Instr *instr = this->m_next;
- while (instr != nullptr && !instr->IsLabelInstr() && !instr->IsBranchInstr())
- {
- instr = instr->m_next;
- }
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetPrevRealInstr
- ///
- ///----------------------------------------------------------------------------
- IR::Instr *
- Instr::GetPrevRealInstr() const
- {
- IR::Instr *instr = this->m_prev;
- while (!instr->IsRealInstr())
- {
- instr = instr->m_prev;
- AssertMsg(instr, "GetPrevRealInstr() failed...");
- }
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetPrevRealInstrOrLabel
- ///
- ///----------------------------------------------------------------------------
- IR::Instr *
- Instr::GetPrevRealInstrOrLabel() const
- {
- IR::Instr *instr = this->m_prev;
- while (!instr->IsLabelInstr() && !instr->IsRealInstr())
- {
- instr = instr->m_prev;
- AssertMsg(instr, "GetPrevRealInstrOrLabel() failed...");
- }
- return instr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetInsertBeforeByteCodeUsesInstr
- /// Finds the instruction before which new instructions can be inserted, by skipping ByteCodeUses instructions associated with
- /// this instruction.
- ///
- ///----------------------------------------------------------------------------
- IR::Instr *Instr::GetInsertBeforeByteCodeUsesInstr()
- {
- const uint32 byteCodeOffset = GetByteCodeOffset();
- IR::Instr *insertBeforeInstr = this;
- IR::Instr *prevInstr = insertBeforeInstr->m_prev;
- while(prevInstr && prevInstr->IsByteCodeUsesInstr() && prevInstr->GetByteCodeOffset() == byteCodeOffset)
- {
- insertBeforeInstr = prevInstr;
- prevInstr = prevInstr->m_prev;
- }
- return insertBeforeInstr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::GetOrCreateContinueLabel
- ///
- ///----------------------------------------------------------------------------
- IR::LabelInstr *
- Instr::GetOrCreateContinueLabel(const bool isHelper)
- {
- if(m_next && m_next->IsLabelInstr() && m_next->AsLabelInstr()->isOpHelper == isHelper)
- {
- return m_next->AsLabelInstr();
- }
- IR::LabelInstr *const label = IR::LabelInstr::New(Js::OpCode::Label, m_func, isHelper);
- InsertAfter(label);
- return label;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::FindRegUse
- ///
- /// Search a reg use of the given sym. Return the RegOpnd that uses it.
- ///
- ///----------------------------------------------------------------------------
- IR::RegOpnd *
- Instr::FindRegUse(StackSym *sym)
- {
- IR::Opnd *src1 = this->GetSrc1();
- // Check src1
- if (src1)
- {
- if (src1->IsRegOpnd())
- {
- RegOpnd *regOpnd = src1->AsRegOpnd();
- if (regOpnd->m_sym == sym)
- {
- return regOpnd;
- }
- }
- else if (src1->IsIndirOpnd())
- {
- IR::IndirOpnd *indirOpnd = src1->AsIndirOpnd();
- if (indirOpnd->GetBaseOpnd()->m_sym == sym)
- {
- return indirOpnd->GetBaseOpnd();
- }
- else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
- {
- return indirOpnd->GetIndexOpnd();
- }
- }
- IR::Opnd *src2 = this->GetSrc2();
- // Check src2
- if (src2)
- {
- if (src2->IsRegOpnd())
- {
- RegOpnd *regOpnd = src2->AsRegOpnd();
- if (regOpnd->m_sym == sym)
- {
- return regOpnd;
- }
- }
- else if (src2->IsIndirOpnd())
- {
- IR::IndirOpnd *indirOpnd = src2->AsIndirOpnd();
- if (indirOpnd->GetBaseOpnd()->m_sym == sym)
- {
- return indirOpnd->GetBaseOpnd();
- }
- else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
- {
- return indirOpnd->GetIndexOpnd();
- }
- }
- }
- }
- // Check uses in dst
- IR::Opnd *dst = this->GetDst();
- if (dst != nullptr && dst->IsIndirOpnd())
- {
- IR::IndirOpnd *indirOpnd = dst->AsIndirOpnd();
- if (indirOpnd->GetBaseOpnd()->m_sym == sym)
- {
- return indirOpnd->GetBaseOpnd();
- }
- else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
- {
- return indirOpnd->GetIndexOpnd();
- }
- }
- return nullptr;
- }
- IR::RegOpnd *
- Instr::FindRegUseInRange(StackSym *sym, IR::Instr *instrBegin, IR::Instr *instrEnd)
- {
- FOREACH_INSTR_IN_RANGE(instr, instrBegin, instrEnd)
- {
- Assert(instr);
- IR::RegOpnd *opnd = instr->FindRegUse(sym);
- if (opnd)
- {
- return opnd;
- }
- }
- NEXT_INSTR_IN_RANGE;
- return nullptr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::FindRegDef
- ///
- /// Search a reg def of the given sym. Return the RegOpnd that defines it.
- ///
- ///----------------------------------------------------------------------------
- IR::RegOpnd *
- Instr::FindRegDef(StackSym *sym)
- {
- IR::Opnd *dst = this->GetDst();
- if (dst)
- {
- if (dst->IsRegOpnd())
- {
- RegOpnd *regOpnd = dst->AsRegOpnd();
- if (regOpnd->m_sym == sym)
- {
- return regOpnd;
- }
- }
- }
- return nullptr;
- }
- void
- Instr::TransferDstAttributesTo(Instr * instr)
- {
- instr->dstIsTempNumber = this->dstIsTempNumber;
- instr->dstIsTempNumberTransferred = this->dstIsTempNumberTransferred;
- instr->dstIsTempObject = this->dstIsTempObject;
- }
- void
- Instr::TransferTo(Instr * instr)
- {
- Assert(instr->m_dst == nullptr);
- Assert(instr->m_src1 == nullptr);
- Assert(instr->m_src2 == nullptr);
- this->TransferDstAttributesTo(instr);
- instr->usesStackArgumentsObject = this->usesStackArgumentsObject;
- instr->isCloned = this->isCloned;
- instr->ignoreNegativeZero = this->ignoreNegativeZero;
- instr->ignoreIntOverflow = this->ignoreIntOverflow;
- instr->ignoreIntOverflowInRange = this->ignoreIntOverflowInRange;
- instr->ignoreOverflowBitCount = this->ignoreOverflowBitCount;
- instr->loadedArrayHeadSegment = this->loadedArrayHeadSegment;
- instr->loadedArrayHeadSegmentLength = this->loadedArrayHeadSegmentLength;
- instr->extractedUpperBoundCheckWithoutHoisting = this->extractedUpperBoundCheckWithoutHoisting;
- instr->m_number = this->m_number;
- instr->m_src1 = this->m_src1;
- instr->m_src2 = this->m_src2;
- instr->dstIsAlwaysConvertedToInt32 = this->dstIsAlwaysConvertedToInt32;
- instr->dstIsAlwaysConvertedToNumber = this->dstIsAlwaysConvertedToNumber;
- IR::Opnd * dst = this->m_dst;
- if (dst)
- {
- instr->m_dst = dst;
- this->m_dst = nullptr;
- if (dst->IsRegOpnd())
- {
- Sym * sym = dst->AsRegOpnd()->m_sym;
- if (sym->IsStackSym() && sym->AsStackSym()->m_isSingleDef)
- {
- Assert(sym->AsStackSym()->m_instrDef == this);
- StackSym * stackSym = sym->AsStackSym();
- stackSym->m_instrDef = instr;
- }
- }
- }
- this->m_src1 = nullptr;
- this->m_src2 = nullptr;
- }
- IR::Instr *
- Instr::ConvertToBailOutInstr(IR::Instr * bailOutTarget, IR::BailOutKind kind)
- {
- Func * func = bailOutTarget->m_func;
- BailOutInfo * bailOutInfo = JitAnew(func->m_alloc, BailOutInfo, bailOutTarget->GetByteCodeOffset(), func);
- #if ENABLE_DEBUG_CONFIG_OPTIONS
- bailOutInfo->bailOutOpcode = this->m_opcode;
- #endif
- return this->ConvertToBailOutInstr(bailOutInfo, kind);
- }
- // Notes:
- // - useAuxBailout = true specifies that this bailout further will be invisible to globopt, etc, and we'll use auxBailoutKind instead of BailoutKind.
- // Currently this is used for BailOutIgnoreException for debugger.
- //
- // Here's typical workflow for scenario useAuxBailout = true.
- // - IRBuilder::Build calls this with kind == BailOutIgnoreException
- // - In here we save the kind to auxBailOut and save bail out info but set hasBailOutInfo to false.
- // - During globopt optimizations presence of this bail out is not detected and instrs can add/remove bailouts as they need.
- // - If they call to convert this instr to bail out instr, we set bailOutKind to what they want and replace bailOutInfo.
- // ** This assumes that for aux bail out bailoutInfo does not really matter (if its pre/post op, etc) **
- // - This is the case for ignore exception.
- // - This will cause to share aux bail out with regular bail out.
- // - In globopt right after OptInstr we check if there is aux bail out which wasn't shared with regular bail out,
- // and if it's not, we convert it back to regular bail out.
- IR::Instr *
- Instr::ConvertToBailOutInstr(BailOutInfo * bailOutInfo, IR::BailOutKind kind, bool useAuxBailOut /* = false */)
- {
- Assert(!this->HasBailOutInfo());
- AssertMsg(!useAuxBailOut || !this->HasAuxBailOut(), "Already aux bail out!");
- Assert(!this->HasAuxBailOut() || this->GetAuxBailOutKind() != IR::BailOutInvalid);
- IR::Instr * bailOutInstr = nullptr;
- if (this->HasAuxBailOut())
- {
- // This instr has already been converted to bailout instr. Only possible with aux bail out.
- // Typical scenario is when globopt calls to convert to e.g. BailOutOnImplcitCalls for the instr which
- // was already converted to bail out instr with HasBailOutInfo() == false and HasAuxBailOutInfo() == true,
- // so that aux bail out is hidden in between IRBuilder and lowerer.
- AssertMsg((this->GetAuxBailOutKind() & ~(IR::BailOutIgnoreException | IR::BailOutForceByFlag)) == 0, "Only IR::BailOutIgnoreException|ForceByFlag supported here.");
- // What we rely on here is:
- // - bailout doesn't have any args.
- // - bailout doesn't use offset as we get it from DebuggingFlags at time of bailout.
- // Use prev debugger bailout kind as decoration, while keeping new kind as main.
- this->SetBailOutKind_NoAssert(kind);
- // Clear old (aux) info and set to the new bailOutInfo.
- this->ReplaceBailOutInfo(bailOutInfo);
- bailOutInfo->bailOutInstr = this;
- this->hasBailOutInfo = true;
- bailOutInstr = this;
- }
- else
- {
- switch (this->m_kind)
- {
- case InstrKindInstr:
- bailOutInstr = IR::BailOutInstr::New(this->m_opcode, kind, bailOutInfo, bailOutInfo->bailOutFunc);
- break;
- case InstrKindProfiled:
- bailOutInstr = IR::ProfiledBailOutInstr::New(this->m_opcode, kind, bailOutInfo, bailOutInfo->bailOutFunc);
- bailOutInstr->AsProfiledInstr()->u = this->AsProfiledInstr()->u;
- break;
- case InstrKindBranch:
- {
- IR::BranchInstr * branchInstr = this->AsBranchInstr();
- Assert(!branchInstr->IsMultiBranch());
- IR::BranchBailOutInstr * branchBailOutInstr = IR::BranchBailOutInstr::New(this->m_opcode, kind, bailOutInfo, bailOutInfo->bailOutFunc);
- branchBailOutInstr->SetTarget(branchInstr->GetTarget());
- branchBailOutInstr->SetByteCodeReg(branchInstr->GetByteCodeReg());
- bailOutInstr = branchBailOutInstr;
- break;
- }
- default:
- AnalysisAssert(false);
- };
- this->m_next->m_prev = bailOutInstr;
- this->m_prev->m_next = bailOutInstr;
- bailOutInstr->m_next = this->m_next;
- bailOutInstr->m_prev = this->m_prev;
- this->TransferTo(bailOutInstr);
- this->Free();
- }
- if (useAuxBailOut)
- {
- // Move bail out kind from bailOutKind to auxBailOutKind and hide bailOutInfo as if this is not a bail out instr.
- bailOutInstr->SetAuxBailOutKind(kind);
- bailOutInstr->SetBailOutKind_NoAssert(IR::BailOutInvalid);
- bailOutInstr->hasBailOutInfo = false;
- bailOutInstr->hasAuxBailOut = true;
- }
- return bailOutInstr;
- }
- // Convert aux bailout to regular bail out.
- // Called by globopt after all optimizations are done, in case we still have aux bail out on the instr.
- void Instr::PromoteAuxBailOut()
- {
- Assert(!this->HasBailOutInfo());
- Assert(this->GetAuxBailOutKind() != IR::BailOutInvalid);
- this->SetBailOutKind_NoAssert(this->GetAuxBailOutKind());
- this->SetAuxBailOutKind(IR::BailOutInvalid);
- this->hasBailOutInfo = true;
- this->hasAuxBailOut = false;
- }
- // Reset all tracks of aux bailout but don't rest the bail out info.
- // Used after we extract aux bail out in lowerer.
- void Instr::ResetAuxBailOut()
- {
- this->SetAuxBailOutKind(IR::BailOutInvalid);
- this->hasAuxBailOut = false;
- }
- void
- Instr::ClearBailOutInfo()
- {
- if (this->HasBailOutInfo() || this->HasAuxBailOut())
- {
- BailOutInfo * bailOutInfo = this->GetBailOutInfo();
- Assert(bailOutInfo);
- if (bailOutInfo->bailOutInstr == this)
- {
- JitArenaAllocator * alloc = this->m_func->m_alloc;
- bailOutInfo->Clear(alloc);
- JitAdelete(alloc, bailOutInfo);
- }
- this->hasBailOutInfo = false;
- this->hasAuxBailOut = false;
- }
- }
- bool Instr::CanHaveArgOutChain() const
- {
- return
- this->m_opcode == Js::OpCode::CallI ||
- this->m_opcode == Js::OpCode::CallIFixed ||
- this->m_opcode == Js::OpCode::NewScObject ||
- this->m_opcode == Js::OpCode::NewScObjectSpread ||
- this->m_opcode == Js::OpCode::NewScObjArray ||
- this->m_opcode == Js::OpCode::NewScObjArraySpread;
- }
- bool Instr::HasEmptyArgOutChain(IR::Instr** startCallInstrOut)
- {
- Assert(CanHaveArgOutChain());
- if (GetSrc2()->IsRegOpnd())
- {
- IR::RegOpnd * argLinkOpnd = GetSrc2()->AsRegOpnd();
- StackSym *argLinkSym = argLinkOpnd->m_sym->AsStackSym();
- AssertMsg(!argLinkSym->IsArgSlotSym() && argLinkSym->m_isSingleDef, "Arg tree not single def...");
- IR::Instr* startCallInstr = argLinkSym->m_instrDef;
- AssertMsg(startCallInstr->m_opcode == Js::OpCode::StartCall, "Problem with arg chain.");
- if (startCallInstrOut != nullptr)
- {
- *startCallInstrOut = startCallInstr;
- }
- return true;
- }
- return false;
- }
- bool Instr::HasFixedFunctionAddressTarget() const
- {
- Assert(
- this->m_opcode == Js::OpCode::CallI ||
- this->m_opcode == Js::OpCode::CallIFixed ||
- this->m_opcode == Js::OpCode::NewScObject ||
- this->m_opcode == Js::OpCode::NewScObjectSpread ||
- this->m_opcode == Js::OpCode::NewScObjArray ||
- this->m_opcode == Js::OpCode::NewScObjArraySpread ||
- this->m_opcode == Js::OpCode::NewScObjectNoCtor);
- return
- this->GetSrc1() != nullptr &&
- this->GetSrc1()->IsAddrOpnd() &&
- this->GetSrc1()->AsAddrOpnd()->GetAddrOpndKind() == IR::AddrOpndKind::AddrOpndKindDynamicVar &&
- this->GetSrc1()->AsAddrOpnd()->m_isFunction;
- }
- void Instr::MoveArgs(bool generateByteCodeCapture)
- {
- Assert(this->m_opcode == Js::OpCode::InlineeStart || this->m_opcode == Js::OpCode::CallDirect ||
- this->m_opcode == Js::OpCode::CallI || this->m_opcode == Js::OpCode::CallIFixed);
- IR::Instr *argInsertInstr = this;
- this->IterateArgInstrs([&](IR::Instr* argInstr)
- {
- if (generateByteCodeCapture)
- {
- argInstr->GenerateBytecodeArgOutCapture();
- }
- argInstr->Move(argInsertInstr);
- argInsertInstr = argInstr;
- return false;
- });
- }
- void Instr::Move(IR::Instr* insertInstr)
- {
- this->Unlink();
- this->ClearByteCodeOffset();
- this->SetByteCodeOffset(insertInstr);
- insertInstr->InsertBefore(this);
- }
- IR::Instr* Instr::GetBytecodeArgOutCapture()
- {
- Assert(this->m_opcode == Js::OpCode::ArgOut_A_Inline ||
- this->m_opcode == Js::OpCode::ArgOut_A ||
- this->m_opcode == Js::OpCode::ArgOut_A_InlineBuiltIn);
- Assert(this->m_dst->GetStackSym()->m_isArgCaptured);
- IR::Instr* instr = this->GetSrc1()->GetStackSym()->m_instrDef;
- Assert(instr->m_opcode == Js::OpCode::BytecodeArgOutCapture);
- return instr;
- }
- bool Instr::HasByteCodeArgOutCapture()
- {
- Assert(this->m_opcode == Js::OpCode::ArgOut_A_FixupForStackArgs ||
- this->m_opcode == Js::OpCode::ArgOut_A_Inline ||
- this->m_opcode == Js::OpCode::ArgOut_A ||
- this->m_opcode == Js::OpCode::ArgOut_A_InlineBuiltIn ||
- this->m_opcode == Js::OpCode::ArgOut_A_FromStackArgs);
- if (this->m_dst->GetStackSym()->m_isArgCaptured)
- {
- Assert(GetBytecodeArgOutCapture() != nullptr);
- return true;
- }
- return false;
- }
- void Instr::GenerateBytecodeArgOutCapture()
- {
- if (!HasByteCodeArgOutCapture())
- {
- this->m_dst->GetStackSym()->m_isArgCaptured = true;
- StackSym* tmpSym = StackSym::NewArgSlotRegSym(this->GetDst()->GetStackSym()->GetArgSlotNum(), this->m_func, this->GetDst()->GetType());
- IR::Instr* instr = this->HoistSrc1(Js::OpCode::BytecodeArgOutCapture, RegNOREG, tmpSym);
- instr->SetByteCodeOffset(this);
- }
- }
- void Instr::GenerateArgOutSnapshot()
- {
- StackSym* tmpSym = StackSym::NewArgSlotRegSym(this->GetDst()->GetStackSym()->GetArgSlotNum(), this->m_func);
- IR::Instr* instr = this->HoistSrc1(Js::OpCode::Ld_A, RegNOREG, tmpSym);
- instr->SetByteCodeOffset(this);
- }
- IR::Instr* Instr::GetArgOutSnapshot()
- {
- Assert(this->m_opcode == Js::OpCode::ArgOut_A_FixupForStackArgs);
- IR::Instr* instr = this->GetSrc1()->GetStackSym()->m_instrDef;
- Assert(instr->m_opcode == Js::OpCode::Ld_A);
- return instr;
- }
- bool Instr::HasAnyImplicitCalls() const
- {
- // there can be no implicit calls in asm.js
- if (m_func->GetJnFunction()->GetIsAsmjsMode())
- {
- return false;
- }
- if (OpCodeAttr::HasImplicitCall(this->m_opcode))
- {
- return true;
- }
- if (OpCodeAttr::CallsValueOf(this->m_opcode))
- {
- IR::Opnd *src1 = this->GetSrc1();
- if (src1)
- {
- if (!src1->GetValueType().IsPrimitive())
- {
- return true;
- }
- IR::Opnd *src2 = this->GetSrc2();
- if(src2 && !src2->GetValueType().IsPrimitive())
- {
- return true;
- }
- }
- }
- return false;
- }
- bool Instr::HasAnySideEffects() const
- {
- if (OpCodeAttr::HasSideEffects(this->m_opcode))
- {
- return true;
- }
- if (this->HasAnyImplicitCalls())
- {
- return true;
- }
- return false;
- }
- Js::JavascriptFunction* Instr::GetFixedFunction() const
- {
- Assert(HasFixedFunctionAddressTarget());
- Js::JavascriptFunction* function = Js::JavascriptFunction::FromVar(this->m_src1->AsAddrOpnd()->m_address);
- return function;
- }
- IR::Instr* Instr::GetNextArg()
- {
- Assert(this->m_opcode == Js::OpCode::ArgOut_A_FixupForStackArgs ||
- this->m_opcode == Js::OpCode::ArgOut_A_Inline ||
- this->m_opcode == Js::OpCode::ArgOut_A ||
- this->m_opcode == Js::OpCode::ArgOut_A_InlineBuiltIn ||
- this->m_opcode == Js::OpCode::InlineeStart);
- IR::Instr* argInstr = this;
- while (true)
- {
- StackSym* linkSym;
- if (argInstr->GetSrc2()->IsRegOpnd())
- {
- linkSym = argInstr->GetSrc2()->AsRegOpnd()->m_sym->AsStackSym();
- }
- else
- {
- linkSym = argInstr->GetSrc2()->AsSymOpnd()->m_sym->AsStackSym();
- Assert(linkSym->IsArgSlotSym());
- }
- Assert(linkSym->IsSingleDef());
- argInstr = linkSym->m_instrDef;
- if (argInstr->m_opcode == Js::OpCode::ArgOut_A_InlineSpecialized)
- {
- continue;
- }
- if (argInstr->m_opcode == Js::OpCode::StartCall)
- {
- break;
- }
- return argInstr;
- }
- return nullptr;
- }
- uint Instr::GetArgOutCount(bool getInterpreterArgOutCount)
- {
- // There are cases of inlining like .apply and .call target inlining, where we muck around with the ArgOut sequence,
- // and make it different from the one the interpreter sees (and expects, on a bailout).
- // In such cases, we set the interpreter version of the number of ArgOuts as the src2 of StartCall,
- // and any code that queries the argout count for bailout purposes should look at the src2 (if available) of these instructions.
- // If the src2 is not set, that means that the interpreter and the JIT versions of the argout count are the same.
- Js::OpCode opcode = this->m_opcode;
- Assert(opcode == Js::OpCode::StartCall ||
- opcode == Js::OpCode::InlineeEnd || opcode == Js::OpCode::InlineBuiltInEnd|| opcode == Js::OpCode::InlineNonTrackingBuiltInEnd ||
- opcode == Js::OpCode::EndCallForPolymorphicInlinee || opcode == Js::OpCode::LoweredStartCall);
- if (!getInterpreterArgOutCount)
- {
- return this->GetSrc1()->AsIntConstOpnd()->AsUint32();
- }
- Assert(opcode == Js::OpCode::StartCall);
- IntConstType argOutCount = !this->GetSrc2() ? this->GetSrc1()->AsIntConstOpnd()->GetValue() : this->GetSrc2()->AsIntConstOpnd()->GetValue();
- Assert(argOutCount >= 0 && argOutCount < UINT32_MAX);
- return (uint)argOutCount;
- }
- PropertySymOpnd *Instr::GetPropertySymOpnd() const
- {
- if (m_src1 && m_src1->IsSymOpnd() && m_src1->AsSymOpnd()->IsPropertySymOpnd())
- {
- return m_src1->AsPropertySymOpnd();
- }
- if (m_dst && m_dst->IsSymOpnd() && m_dst->AsSymOpnd()->IsPropertySymOpnd())
- {
- return m_dst->AsPropertySymOpnd();
- }
- return nullptr;
- }
- bool Instr::CallsAccessor(IR::PropertySymOpnd* methodOpnd)
- {
- if (methodOpnd)
- {
- Assert(methodOpnd->HasObjTypeSpecFldInfo());
- return methodOpnd->UsesAccessor();
- }
- return CallsGetter() || CallsSetter();
- }
- bool Instr::CallsSetter(IR::PropertySymOpnd* methodOpnd)
- {
- return
- this->IsProfiledInstr() &&
- (this->m_dst && this->m_dst->IsSymOpnd() && this->m_dst->AsSymOpnd()->IsPropertySymOpnd()) &&
- ((this->AsProfiledInstr()->u.FldInfo().flags & Js::FldInfo_FromAccessor) != 0);
- }
- bool Instr::CallsGetter(IR::PropertySymOpnd* methodOpnd)
- {
- return
- this->IsProfiledInstr() &&
- (this->m_src1 && this->m_src1->IsSymOpnd() && this->m_src1->AsSymOpnd()->IsPropertySymOpnd()) &&
- ((this->AsProfiledInstr()->u.FldInfo().flags & Js::FldInfo_FromAccessor) != 0);
- }
- IR::Instr* IR::Instr::NewConstantLoad(IR::RegOpnd* dstOpnd, Js::Var varConst, Func* func)
- {
- IR::Opnd *srcOpnd = nullptr;
- IR::Instr *instr;
- if (Js::TaggedInt::Is(varConst))
- {
- IntConstType value = Js::TaggedInt::ToInt32(varConst);
- instr = IR::Instr::New(Js::OpCode::LdC_A_I4, dstOpnd, IR::IntConstOpnd::New(value, TyInt32, func), func);
- if (dstOpnd->m_sym->IsSingleDef())
- {
- dstOpnd->m_sym->SetIsIntConst(value);
- }
- }
- else
- {
- Js::RecyclableObject *obj;
- if (varConst == (Js::Var)&Js::NullFrameDisplay)
- {
- instr = IR::Instr::New(Js::OpCode::Ld_A, dstOpnd,
- IR::AddrOpnd::New((Js::Var)&Js::NullFrameDisplay, IR::AddrOpndKindDynamicMisc, func), func);
- }
- else if (varConst == (Js::Var)&Js::StrictNullFrameDisplay)
- {
- instr = IR::Instr::New(Js::OpCode::Ld_A, dstOpnd,
- IR::AddrOpnd::New((Js::Var)&Js::StrictNullFrameDisplay, IR::AddrOpndKindDynamicMisc, func), func);
- }
- else
- {
- ValueType valueType;
- switch (Js::JavascriptOperators::GetTypeId(varConst))
- {
- case Js::TypeIds_String:
- {
- obj = Js::RecyclableObject::FromVar(varConst);
- srcOpnd = IR::AddrOpnd::New(obj, IR::AddrOpndKindDynamicVar, func, true);
- instr = IR::Instr::New(Js::OpCode::LdStr, dstOpnd, srcOpnd, func);
- Assert(dstOpnd->m_sym->m_isSingleDef);
- if (dstOpnd->m_sym->IsSingleDef())
- {
- dstOpnd->m_sym->m_isStrConst = true;
- dstOpnd->m_sym->m_isConst = true;
- }
- dstOpnd->SetValueType(ValueType::String);
- srcOpnd->SetValueType(ValueType::String);
- break;
- }
- case Js::TypeIds_Number:
- {
- Assert(Js::JavascriptNumber::Is(varConst));
- srcOpnd = IR::FloatConstOpnd::New(varConst, TyFloat64, func);
- instr = IR::Instr::New(Js::OpCode::LdC_A_R8, dstOpnd, srcOpnd, func);
- if (dstOpnd->m_sym->IsSingleDef())
- {
- dstOpnd->m_sym->SetIsFloatConst();
- #if FLOATVAR
- dstOpnd->m_sym->m_isNotInt = FALSE;
- #else
- // Don't set m_isNotInt to true if the float constant value is an int32 or uint32. Uint32s may sometimes be
- // treated as int32s for the purposes of int specialization.
- dstOpnd->m_sym->m_isNotInt = !Js::JavascriptNumber::IsInt32OrUInt32_NoChecks(varConst);
- #endif
- }
- break;
- }
- case Js::TypeIds_Undefined:
- valueType = ValueType::Undefined;
- goto dynamicVar;
- case Js::TypeIds_Null:
- valueType = ValueType::Null;
- goto dynamicVar;
- case Js::TypeIds_Boolean:
- valueType = ValueType::Boolean;
- goto dynamicVar;
- default:
- valueType = ValueType::GetObject(ObjectType::Object);
- dynamicVar:
- obj = Js::RecyclableObject::FromVar(varConst);
- srcOpnd = IR::AddrOpnd::New(obj, IR::AddrOpndKindDynamicVar, func, true);
- instr = IR::Instr::New(Js::OpCode::Ld_A, dstOpnd, srcOpnd, func);
- if (dstOpnd->m_sym->IsSingleDef())
- {
- dstOpnd->m_sym->m_isConst = true;
- }
- dstOpnd->SetValueType(valueType);
- srcOpnd->SetValueType(valueType);
- break;
- }
- }
- }
- return instr;
- }
- bool Instr::UsesAllFields()
- {
- return OpCodeAttr::UseAllFields(this->m_opcode) || this->CallsAccessor();
- }
- BranchInstr *
- Instr::ChangeCmCCToBranchInstr(LabelInstr *targetInstr)
- {
- Js::OpCode newOpcode;
- switch (this->m_opcode)
- {
- case Js::OpCode::CmEq_A:
- newOpcode = Js::OpCode::BrEq_A;
- break;
- case Js::OpCode::CmGe_A:
- newOpcode = Js::OpCode::BrGe_A;
- break;
- case Js::OpCode::CmGt_A:
- newOpcode = Js::OpCode::BrGt_A;
- break;
- case Js::OpCode::CmLt_A:
- newOpcode = Js::OpCode::BrLt_A;
- break;
- case Js::OpCode::CmLe_A:
- newOpcode = Js::OpCode::BrLe_A;
- break;
- case Js::OpCode::CmUnGe_A:
- newOpcode = Js::OpCode::BrUnGe_A;
- break;
- case Js::OpCode::CmUnGt_A:
- newOpcode = Js::OpCode::BrUnGt_A;
- break;
- case Js::OpCode::CmUnLt_A:
- newOpcode = Js::OpCode::BrUnLt_A;
- break;
- case Js::OpCode::CmUnLe_A:
- newOpcode = Js::OpCode::BrUnLe_A;
- break;
- case Js::OpCode::CmNeq_A:
- newOpcode = Js::OpCode::BrNeq_A;
- break;
- case Js::OpCode::CmSrEq_A:
- newOpcode = Js::OpCode::BrSrEq_A;
- break;
- case Js::OpCode::CmSrNeq_A:
- newOpcode = Js::OpCode::BrSrNeq_A;
- break;
- case Js::OpCode::CmEq_I4:
- newOpcode = Js::OpCode::BrEq_I4;
- break;
- case Js::OpCode::CmGe_I4:
- newOpcode = Js::OpCode::BrGe_I4;
- break;
- case Js::OpCode::CmGt_I4:
- newOpcode = Js::OpCode::BrGt_I4;
- break;
- case Js::OpCode::CmLt_I4:
- newOpcode = Js::OpCode::BrLt_I4;
- break;
- case Js::OpCode::CmLe_I4:
- newOpcode = Js::OpCode::BrLe_I4;
- break;
- case Js::OpCode::CmUnGe_I4:
- newOpcode = Js::OpCode::BrUnGe_I4;
- break;
- case Js::OpCode::CmUnGt_I4:
- newOpcode = Js::OpCode::BrUnGt_I4;
- break;
- case Js::OpCode::CmUnLt_I4:
- newOpcode = Js::OpCode::BrUnLt_I4;
- break;
- case Js::OpCode::CmUnLe_I4:
- newOpcode = Js::OpCode::BrUnLe_I4;
- break;
- case Js::OpCode::CmNeq_I4:
- newOpcode = Js::OpCode::BrNeq_I4;
- break;
- default:
- Assert(UNREACHED);
- __assume(UNREACHED);
- }
- BranchInstr *instrBr = BranchInstr::New(newOpcode, targetInstr, this->m_func);
- this->InsertBefore(instrBr);
- instrBr->SetByteCodeOffset(this);
- instrBr->SetSrc1(this->UnlinkSrc1());
- instrBr->SetSrc2(this->UnlinkSrc2());
- this->Remove();
- return instrBr;
- }
- bool Instr::IsCmCC_A()
- {
- return (this->m_opcode >= Js::OpCode::CmEq_A && this->m_opcode <= Js::OpCode::CmSrNeq_A) && this->GetSrc1()->IsVar();
- }
- bool Instr::IsCmCC_R8()
- {
- return (this->m_opcode >= Js::OpCode::CmEq_A && this->m_opcode <= Js::OpCode::CmSrNeq_A) && this->GetSrc1()->IsFloat64();
- }
- bool Instr::IsCmCC_I4()
- {
- return (this->m_opcode >= Js::OpCode::CmEq_I4 && this->m_opcode <= Js::OpCode::CmUnGe_I4);
- }
- bool Instr::BinaryCalculator(IntConstType src1Const, IntConstType src2Const, IntConstType *pResult)
- {
- IntConstType value = 0;
- switch (this->m_opcode)
- {
- case Js::OpCode::Add_A:
- if (IntConstMath::Add(src1Const, src2Const, &value))
- {
- return false;
- }
- break;
- case Js::OpCode::Sub_A:
- if (IntConstMath::Sub(src1Const, src2Const, &value))
- {
- return false;
- }
- break;
- case Js::OpCode::Mul_A:
- if (IntConstMath::Mul(src1Const, src2Const, &value))
- {
- return false;
- }
- if (value == 0)
- {
- // might be -0
- // Bail for now...
- return false;
- }
- break;
- case Js::OpCode::Div_A:
- if (src2Const == 0)
- {
- // Could fold to INF/-INF
- // instr->HoistSrc1(Js::OpCode::Ld_A);
- return false;
- }
- if (src1Const == 0 && src2Const < 0)
- {
- // folds to -0. Bail for now...
- return false;
- }
- if (IntConstMath::Div(src1Const, src2Const, &value))
- {
- return false;
- }
- if (src1Const % src2Const != 0)
- {
- // Bail for now...
- return false;
- }
- break;
- case Js::OpCode::Rem_A:
- if (src2Const == 0)
- {
- // Bail for now...
- return false;
- }
- if (IntConstMath::Mod(src1Const, src2Const, &value))
- {
- return false;
- }
- if (value == 0)
- {
- // might be -0
- // Bail for now...
- return false;
- }
- break;
- case Js::OpCode::Shl_A:
- // We don't care about overflow here
- IntConstMath::Shl(src1Const, src2Const & 0x1F, &value);
- break;
- case Js::OpCode::Shr_A:
- // We don't care about overflow here, and there shouldn't be any
- IntConstMath::Shr(src1Const, src2Const & 0x1F, &value);
- break;
- case Js::OpCode::ShrU_A:
- // We don't care about overflow here, and there shouldn't be any
- IntConstMath::ShrU(src1Const, src2Const & 0x1F, &value);
- if (value < 0)
- {
- // ShrU produces a UInt32. If it doesn't fit in a Int32, bail as we don't
- // track signs of int values.
- return false;
- }
- break;
- case Js::OpCode::And_A:
- // We don't care about overflow here, and there shouldn't be any
- IntConstMath::And(src1Const, src2Const, &value);
- break;
- case Js::OpCode::Or_A:
- // We don't care about overflow here, and there shouldn't be any
- IntConstMath::Or(src1Const, src2Const, &value);
- break;
- case Js::OpCode::Xor_A:
- // We don't care about overflow here, and there shouldn't be any
- IntConstMath::Xor(src1Const, src2Const, &value);
- break;
- case Js::OpCode::InlineMathMin:
- value = src1Const < src2Const ? src1Const : src2Const;
- break;
- case Js::OpCode::InlineMathMax:
- value = src1Const > src2Const ? src1Const : src2Const;
- break;
- default:
- return false;
- }
- *pResult = value;
- return true;
- }
- bool Instr::UnaryCalculator(IntConstType src1Const, IntConstType *pResult)
- {
- IntConstType value = 0;
- switch (this->m_opcode)
- {
- case Js::OpCode::Neg_A:
- if (src1Const == 0)
- {
- // Could fold to -0.0
- return false;
- }
- if (IntConstMath::Neg(src1Const, &value))
- {
- return false;
- }
- break;
- case Js::OpCode::Not_A:
- IntConstMath::Not(src1Const, &value);
- break;
- case Js::OpCode::Ld_A:
- if (this->HasBailOutInfo())
- {
- Assert(this->GetBailOutKind() == IR::BailOutExpectingInteger);
- this->ClearBailOutInfo();
- }
- value = src1Const;
- break;
- case Js::OpCode::Conv_Num:
- case Js::OpCode::LdC_A_I4:
- value = src1Const;
- break;
- case Js::OpCode::Incr_A:
- if (IntConstMath::Inc(src1Const, &value))
- {
- return false;
- }
- break;
- case Js::OpCode::Decr_A:
- if (IntConstMath::Dec(src1Const, &value))
- {
- return false;
- }
- break;
- case Js::OpCode::InlineMathAbs:
- if (src1Const == IntConstMin)
- {
- return false;
- }
- else
- {
- value = src1Const < 0 ? -src1Const : src1Const;
- }
- break;
- case Js::OpCode::InlineMathClz32:
- DWORD clz;
- DWORD src1Const32;
- src1Const32 = (DWORD)src1Const;
- if (_BitScanReverse(&clz, src1Const32))
- {
- value = 31 - clz;
- }
- else
- {
- value = 32;
- }
- this->ClearBailOutInfo();
- break;
- case Js::OpCode::InlineMathFloor:
- value = src1Const;
- this->ClearBailOutInfo();
- break;
- case Js::OpCode::InlineMathCeil:
- value = src1Const;
- this->ClearBailOutInfo();
- break;
- case Js::OpCode::InlineMathRound:
- value = src1Const;
- this->ClearBailOutInfo();
- break;
- case Js::OpCode::ToVar:
- if (Js::TaggedInt::IsOverflow(src1Const))
- {
- return false;
- }
- else
- {
- value = src1Const;
- this->ClearBailOutInfo();
- break;
- }
- default:
- return false;
- }
- *pResult = value;
- return true;
- }
- #if ENABLE_DEBUG_CONFIG_OPTIONS
- ///----------------------------------------------------------------------------
- ///
- /// Instr::DumpTestTrace
- ///
- /// Dump this instr in TestTrace.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::DumpTestTrace()
- {
- Output::Print(L"opcode: %s ", Js::OpCodeUtil::GetOpCodeName(m_opcode));
- SymOpnd * symOpnd;
- if (this->m_opcode == Js::OpCode::NewScFunc || this->m_opcode == Js::OpCode::NewScGenFunc)
- {
- Output::Print(L"\n");
- return;
- }
- Opnd * src1 = this->GetSrc1();
- if (!src1)
- {
- Output::Print(L"\n");
- return;
- }
- if (src1->GetKind() != OpndKindSym)
- {
- Output::Print(L"\n");
- return;
- }
- symOpnd = src1->AsSymOpnd();
- if (symOpnd->m_sym->IsPropertySym())
- {
- PropertySym *propertySym = symOpnd->m_sym->AsPropertySym();
- switch (propertySym->m_fieldKind)
- {
- case PropertyKindData:
- {
- Js::ScriptContext* scriptContext;
- scriptContext = propertySym->GetFunc()->GetScriptContext();
- Js::PropertyRecord const* fieldName = scriptContext->GetPropertyNameLocked(propertySym->m_propertyId);
- Output::Print(L"field: %s ", fieldName->GetBuffer());
- break;
- }
- case PropertyKindSlots:
- Output::Print(L"field: [%d] ", propertySym->m_propertyId);
- break;
- case PropertyKindLocalSlots:
- Output::Print(L"field: l[%d] ", propertySym->m_propertyId);
- break;
- default:
- break;
- }
- Output::Print(L"\n");
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::DumpFieldCopyPropTestTrace
- ///
- /// Dump fieldcopyprop when testtrace is enabled.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::DumpFieldCopyPropTestTrace()
- {
- switch (m_opcode)
- {
- case Js::OpCode::LdSlot:
- case Js::OpCode::LdSlotArr:
- case Js::OpCode::LdFld:
- case Js::OpCode::LdFldForTypeOf:
- case Js::OpCode::LdRootFld:
- case Js::OpCode::LdRootFldForTypeOf:
- case Js::OpCode::LdMethodFld:
- case Js::OpCode::LdRootMethodFld:
- case Js::OpCode::LdMethodFromFlags:
- case Js::OpCode::ScopedLdMethodFld:
- case Js::OpCode::TypeofElem:
- wchar_t debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
- Output::Print(L"TestTrace fieldcopyprop: function %s (%s) ", this->m_func->GetJnFunction()->GetDisplayName(), this->m_func->GetJnFunction()->GetDebugNumberSet(debugStringBuffer));
- if (this->IsInlined())
- {
- Js::FunctionBody* topFunctionBody = this->m_func->GetTopFunc()->GetJnFunction();
- Output::Print(L"inlined caller function %s (%s) ", topFunctionBody->GetDisplayName(), topFunctionBody->GetDebugNumberSet(debugStringBuffer));
- }
- this->DumpTestTrace();
- default:
- break;
- }
- }
- #endif
- #if ENABLE_DEBUG_CONFIG_OPTIONS
- const char *
- Instr::GetBailOutKindName() const
- {
- IR::BailOutKind kind = (IR::BailOutKind)0;
- if (this->HasBailOutInfo())
- {
- kind |= this->GetBailOutKind();
- }
- if (this->HasAuxBailOut())
- {
- kind |= this->GetAuxBailOutKind();
- }
- return ::GetBailOutKindName(kind);
- }
- #endif
- //
- // Debug dumpers
- //
- #if DBG_DUMP
- void
- Instr::DumpByteCodeOffset()
- {
- if (m_func->HasByteCodeOffset())
- {
- Output::SkipToColumn(78);
- Output::Print(L"#");
- if (this->m_number != Js::Constants::NoByteCodeOffset)
- {
- Output::Print(L"%04x", this->m_number);
- Output::Print(this->IsCloned()? L"*" : L" ");
- }
- }
- if (!this->m_func->IsTopFunc())
- {
- Output::SkipToColumn(78);
- wchar_t debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
- Output::Print(L" Func #%s", this->m_func->GetJnFunction()->GetDebugNumberSet(debugStringBuffer));
- }
- #ifdef BAILOUT_INJECTION
- if (this->bailOutByteCodeLocation != (uint)-1)
- {
- Output::SkipToColumn(85);
- Output::Print(L"@%4d", this->bailOutByteCodeLocation);
- }
- #endif
- if (this->m_opcode == Js::OpCode::InlineeStart)
- {
- Output::Print(L" %s", this->m_func->GetJnFunction()->GetDisplayName());
- }
- }
- void
- Instr::DumpGlobOptInstrString()
- {
- if(this->globOptInstrString)
- {
- Output::Print(L"\n\n GLOBOPT INSTR: %s\n\n", this->globOptInstrString);
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::Dump
- ///
- /// Dump this instr.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::Dump(IRDumpFlags flags)
- {
- bool const AsmDumpMode = flags & IRDumpFlags_AsmDumpMode;
- bool const SimpleForm = !!(flags & IRDumpFlags_SimpleForm);
- bool const SkipByteCodeOffset = !!(flags & IRDumpFlags_SkipByteCodeOffset);
- const auto PrintOpCodeName = [&]() {
- Output::SkipToColumn(23);
- Output::Print(L"%s ", Js::OpCodeUtil::GetOpCodeName(m_opcode));
- Output::SkipToColumn(38);
- };
- if(m_opcode == Js::OpCode::BoundCheck || m_opcode == Js::OpCode::UnsignedBoundCheck)
- {
- PrintOpCodeName();
- // src1 <= src2 + dst
- Assert(GetSrc1());
- if(GetSrc1()->IsIntConstOpnd())
- {
- Output::Print(L"%d", GetSrc1()->AsIntConstOpnd()->GetValue());
- }
- else
- {
- GetSrc1()->Dump(flags, m_func);
- }
- bool useLessThanOrEqual = true;
- bool usePlus = true;
- bool dumpSrc2 = false;
- int32 offset = GetDst() ? GetDst()->AsIntConstOpnd()->AsInt32() : 0;
- if(GetSrc2())
- {
- if(GetSrc2()->IsIntConstOpnd())
- {
- #if DBG
- int32 temp;
- Assert(!Int32Math::Add(offset, GetSrc2()->AsIntConstOpnd()->AsInt32(), &temp));
- #endif
- offset += GetSrc2()->AsIntConstOpnd()->AsInt32();
- }
- else
- {
- dumpSrc2 = true;
- if(offset == -1)
- {
- useLessThanOrEqual = false; // < instead of <=
- offset = 0;
- }
- else if(offset < 0 && offset != IntConstMin)
- {
- usePlus = false;
- offset = -offset;
- }
- }
- }
- Output::Print(L" %S ", useLessThanOrEqual ? "<=" : "<");
- if(dumpSrc2)
- {
- GetSrc2()->Dump(flags, m_func);
- }
- if(offset != 0)
- {
- if(dumpSrc2)
- {
- Output::Print(L" %C ", usePlus ? '+' : '-');
- }
- Output::Print(L"%d", offset);
- }
- goto PrintByteCodeOffsetEtc;
- }
- Output::SkipToColumn(4);
- Opnd * dst = this->GetDst();
- if (dst)
- {
- dst->Dump(flags, this->m_func);
- bool const dumpMarkTemp = PHASE_DUMP(Js::MarkTempPhase, m_func->GetJnFunction())
- || PHASE_TRACE(Js::MarkTempPhase, m_func->GetJnFunction());
- bool const dumpMarkTempNumber = dumpMarkTemp || PHASE_DUMP(Js::MarkTempNumberPhase, m_func->GetJnFunction())
- || PHASE_TRACE(Js::MarkTempNumberPhase, m_func->GetJnFunction());
- bool const dumpMarkTempObject = dumpMarkTemp || PHASE_DUMP(Js::MarkTempObjectPhase, m_func->GetJnFunction())
- || PHASE_TRACE(Js::MarkTempObjectPhase, m_func->GetJnFunction());
- if ((dumpMarkTempNumber && (this->dstIsTempNumberTransferred || this->dstIsTempNumber))
- || (dumpMarkTempObject && this->dstIsTempObject))
- {
- Output::Print(L"[");
- if (dumpMarkTempNumber)
- {
- if (Js::Configuration::Global.flags.Verbose || OpCodeAttr::TempNumberProducing(this->m_opcode))
- {
- if (this->dstIsTempNumberTransferred)
- {
- Assert(this->dstIsTempNumber);
- Output::Print(L"x");
- }
- else if (this->dstIsTempNumber)
- {
- Output::Print(L"#");
- }
- }
- }
- if (dumpMarkTempObject)
- {
- if (Js::Configuration::Global.flags.Verbose || OpCodeAttr::TempObjectProducing(this->m_opcode))
- {
- if (this->dstIsTempObject)
- {
- Output::Print(L"o");
- }
- }
- }
- Output::Print(L"tmp]");
- }
- if(PHASE_DUMP(Js::TrackNegativeZeroPhase, m_func->GetTopFunc()) && !ShouldCheckForNegativeZero())
- {
- Output::Print(L"[-0]");
- }
- if (PHASE_DUMP(Js::TypedArrayVirtualPhase, m_func->GetTopFunc()) && (!IsDstNotAlwaysConvertedToInt32() || !IsDstNotAlwaysConvertedToNumber()))
- {
- if (!IsDstNotAlwaysConvertedToInt32())
- Output::Print(L"[->i]");
- else
- Output::Print(L"[->n]");
- }
- if(PHASE_DUMP(Js::TrackIntOverflowPhase, m_func->GetTopFunc()))
- {
- // ignoring 32-bit overflow ?
- if(!ShouldCheckFor32BitOverflow())
- {
- // ignoring 32-bits or more ?
- if(ShouldCheckForNon32BitOverflow())
- Output::Print(L"[OF %d]", ignoreOverflowBitCount);
- else
- Output::Print(L"[OF]");
- }
- }
- Output::SkipToColumn(20);
- Output::Print(L"=");
- }
- PrintOpCodeName();
- if (this->IsBranchInstr())
- {
- BranchInstr * branchInstr = this->AsBranchInstr();
- LabelInstr * targetInstr = branchInstr->GetTarget();
- if (targetInstr == NULL)
- {
- // Checking the 'm_isMultiBranch' field here directly as well to bypass asserting when tracing IR builder
- if(branchInstr->m_isMultiBranch && branchInstr->IsMultiBranch())
- {
- IR::MultiBranchInstr * multiBranchInstr = branchInstr->AsMultiBrInstr();
- multiBranchInstr->MapMultiBrLabels([](IR::LabelInstr * labelInstr) -> void
- {
- Output::Print(L"$L%d ", labelInstr->m_id);
- });
- }
- else
- {
- Output::Print(L"??");
- }
- }
- else
- {
- Output::Print(L"$L%d", targetInstr->m_id);
- }
- if (this->GetSrc1())
- {
- Output::Print(L", ");
- }
- }
- else if (this->IsPragmaInstr() && this->m_opcode == Js::OpCode::StatementBoundary)
- {
- Output::Print(L"#%d", this->AsPragmaInstr()->m_statementIndex);
- }
- Opnd * src1 = this->GetSrc1();
- if (this->m_opcode == Js::OpCode::NewScFunc || this->m_opcode == Js::OpCode::NewScGenFunc)
- {
- Assert(src1->IsIntConstOpnd());
- Js::ParseableFunctionInfo *function = this->m_func->GetJnFunction()->GetNestedFunctionForExecution((uint)src1->AsIntConstOpnd()->GetValue())->GetParseableFunctionInfo();
- Output::Print(L"func:%s()", function ? function->GetDisplayName() : L"???");
- Output::Print(L", env:");
- this->GetSrc2()->AsRegOpnd()->m_sym->Dump(flags);
- }
- else if (src1)
- {
- src1->Dump(flags, this->m_func);
- Opnd * src2 = this->GetSrc2();
- if (src2)
- {
- Output::Print(L", ");
- src2->Dump(flags, this->m_func);
- }
- }
- if (this->IsByteCodeUsesInstr())
- {
- if (this->AsByteCodeUsesInstr()->byteCodeUpwardExposedUsed)
- {
- bool first = true;
- FOREACH_BITSET_IN_SPARSEBV(id, this->AsByteCodeUsesInstr()->byteCodeUpwardExposedUsed)
- {
- Output::Print(first? L"s%d" : L", s%d", id);
- first = false;
- }
- NEXT_BITSET_IN_SPARSEBV;
- }
- if (this->AsByteCodeUsesInstr()->propertySymUse)
- {
- Output::Print(L" PropSym: %d", this->AsByteCodeUsesInstr()->propertySymUse->m_id);
- }
- }
- PrintByteCodeOffsetEtc:
- if (!AsmDumpMode && !SkipByteCodeOffset)
- {
- this->DumpByteCodeOffset();
- }
- if (!SimpleForm)
- {
- if (this->HasBailOutInfo() || this->HasAuxBailOut())
- {
- BailOutInfo * bailOutInfo = this->GetBailOutInfo();
- Output::SkipToColumn(85);
- if (!AsmDumpMode)
- {
- Output::Print(L"Bailout: #%04x", bailOutInfo->bailOutOffset);
- }
- if (!bailOutInfo->bailOutFunc->IsTopFunc())
- {
- wchar_t debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
- Output::Print(L" Func %s", bailOutInfo->bailOutFunc->GetJnFunction()->GetDebugNumberSet(debugStringBuffer));
- }
- Output::Print(L" (%S)", this->GetBailOutKindName());
- }
- }
- if ((flags & IRDumpFlags_SkipEndLine) == 0)
- {
- Output::Print(L"\n");
- }
- }
- ///----------------------------------------------------------------------------
- ///
- /// LabelInstr::Dump
- ///
- /// Dump this label.
- ///
- ///----------------------------------------------------------------------------
- void
- LabelInstr::Dump(IRDumpFlags flags)
- {
- if (this->m_block != NULL)
- {
- this->m_block->DumpHeader();
- }
- Output::Print(L"$L%d:", this->m_id);
- if (this->isOpHelper)
- {
- Output::Print(L" [helper]");
- }
- if (this->m_isLoopTop)
- {
- Output::Print(L" >>>>>>>>>>>>> LOOP TOP >>>>>>>>>>>>>");
- }
- if (this->IsProfiledLabelInstr())
- {
- Output::SkipToColumn(50);
- switch (this->AsProfiledLabelInstr()->loopImplicitCallFlags)
- {
- case Js::ImplicitCall_HasNoInfo:
- Output::Print(L"Implicit call: ???");
- break;
- case Js::ImplicitCall_None:
- Output::Print(L"Implicit call: no");
- break;
- default:
- Output::Print(L"Implicit call: yes");
- break;
- }
- }
- if ((flags & (IRDumpFlags_AsmDumpMode | IRDumpFlags_SkipByteCodeOffset)) == 0)
- {
- this->DumpByteCodeOffset();
- }
- Output::Print(L"\n");
- }
- void
- PragmaInstr::Dump(IRDumpFlags flags)
- {
- if (Js::Configuration::Global.flags.PrintSrcInDump && this->m_opcode == Js::OpCode::StatementBoundary)
- {
- this->m_func->GetJnFunction()->PrintStatementSourceLine(this->m_statementIndex);
- }
- __super::Dump(flags);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Instr::Dump
- ///
- /// Dump a window of instructions around this instr.
- ///
- ///----------------------------------------------------------------------------
- void
- Instr::Dump(int window)
- {
- Instr * instr;
- int i;
- Output::Print(L"-------------------------------------------------------------------------------");
- if (this == NULL)
- {
- return;
- }
- for (i = 0, instr = this; (instr->m_prev != NULL && i < window/2); instr = instr->m_prev, ++i)
- {} // Nothing
- for (i = 0; (instr != nullptr && i < window); instr = instr->m_next, ++i)
- {
- if (instr == this)
- {
- Output::Print(L"=>");
- }
- instr->Dump();
- }
- }
- void
- Instr::Dump()
- {
- this->Dump(IRDumpFlags_None);
- }
- void
- Instr::DumpSimple()
- {
- this->Dump(IRDumpFlags_SimpleForm);
- }
- wchar_t *
- Instr::DumpString()
- {
- Output::CaptureStart();
- this->Dump();
- return Output::CaptureEnd();
- }
- void
- Instr::DumpRange(Instr *instrEnd)
- {
- Output::Print(L"-------------------------------------------------------------------------------\n");
- FOREACH_INSTR_IN_RANGE(instr, this, instrEnd)
- {
- instr->Dump();
- }
- NEXT_INSTR_IN_RANGE;
- Output::Print(L"-------------------------------------------------------------------------------\n");
- }
- #endif
- } // namespace IR
|