emit-rtl.c 166 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338
  1. /* Emit RTL for the GCC expander.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* Middle-to-low level generation of rtx code and insns.
  16. This file contains support functions for creating rtl expressions
  17. and manipulating them in the doubly-linked chain of insns.
  18. The patterns of the insns are created by machine-dependent
  19. routines in insn-emit.c, which is generated automatically from
  20. the machine description. These routines make the individual rtx's
  21. of the pattern with `gen_rtx_fmt_ee' and others in genrtl.[ch],
  22. which are automatically generated from rtl.def; what is machine
  23. dependent is the kind of rtx's they make and what arguments they
  24. use. */
  25. #include "config.h"
  26. #include "system.h"
  27. #include "coretypes.h"
  28. #include "tm.h"
  29. #include "diagnostic-core.h"
  30. #include "rtl.h"
  31. #include "hash-set.h"
  32. #include "machmode.h"
  33. #include "vec.h"
  34. #include "double-int.h"
  35. #include "input.h"
  36. #include "alias.h"
  37. #include "symtab.h"
  38. #include "wide-int.h"
  39. #include "inchash.h"
  40. #include "real.h"
  41. #include "tree.h"
  42. #include "fold-const.h"
  43. #include "varasm.h"
  44. #include "predict.h"
  45. #include "hard-reg-set.h"
  46. #include "function.h"
  47. #include "cfgrtl.h"
  48. #include "basic-block.h"
  49. #include "tree-eh.h"
  50. #include "tm_p.h"
  51. #include "flags.h"
  52. #include "stringpool.h"
  53. #include "hashtab.h"
  54. #include "statistics.h"
  55. #include "fixed-value.h"
  56. #include "insn-config.h"
  57. #include "expmed.h"
  58. #include "dojump.h"
  59. #include "explow.h"
  60. #include "calls.h"
  61. #include "emit-rtl.h"
  62. #include "stmt.h"
  63. #include "expr.h"
  64. #include "regs.h"
  65. #include "recog.h"
  66. #include "bitmap.h"
  67. #include "debug.h"
  68. #include "langhooks.h"
  69. #include "df.h"
  70. #include "params.h"
  71. #include "target.h"
  72. #include "builtins.h"
  73. #include "rtl-iter.h"
  74. struct target_rtl default_target_rtl;
  75. #if SWITCHABLE_TARGET
  76. struct target_rtl *this_target_rtl = &default_target_rtl;
  77. #endif
  78. #define initial_regno_reg_rtx (this_target_rtl->x_initial_regno_reg_rtx)
  79. /* Commonly used modes. */
  80. machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
  81. machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
  82. machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
  83. machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
  84. /* Datastructures maintained for currently processed function in RTL form. */
  85. struct rtl_data x_rtl;
  86. /* Indexed by pseudo register number, gives the rtx for that pseudo.
  87. Allocated in parallel with regno_pointer_align.
  88. FIXME: We could put it into emit_status struct, but gengtype is not able to deal
  89. with length attribute nested in top level structures. */
  90. rtx * regno_reg_rtx;
  91. /* This is *not* reset after each function. It gives each CODE_LABEL
  92. in the entire compilation a unique label number. */
  93. static GTY(()) int label_num = 1;
  94. /* We record floating-point CONST_DOUBLEs in each floating-point mode for
  95. the values of 0, 1, and 2. For the integer entries and VOIDmode, we
  96. record a copy of const[012]_rtx and constm1_rtx. CONSTM1_RTX
  97. is set only for MODE_INT and MODE_VECTOR_INT modes. */
  98. rtx const_tiny_rtx[4][(int) MAX_MACHINE_MODE];
  99. rtx const_true_rtx;
  100. REAL_VALUE_TYPE dconst0;
  101. REAL_VALUE_TYPE dconst1;
  102. REAL_VALUE_TYPE dconst2;
  103. REAL_VALUE_TYPE dconstm1;
  104. REAL_VALUE_TYPE dconsthalf;
  105. /* Record fixed-point constant 0 and 1. */
  106. FIXED_VALUE_TYPE fconst0[MAX_FCONST0];
  107. FIXED_VALUE_TYPE fconst1[MAX_FCONST1];
  108. /* We make one copy of (const_int C) where C is in
  109. [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
  110. to save space during the compilation and simplify comparisons of
  111. integers. */
  112. rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
  113. /* Standard pieces of rtx, to be substituted directly into things. */
  114. rtx pc_rtx;
  115. rtx ret_rtx;
  116. rtx simple_return_rtx;
  117. rtx cc0_rtx;
  118. /* A hash table storing CONST_INTs whose absolute value is greater
  119. than MAX_SAVED_CONST_INT. */
  120. struct const_int_hasher : ggc_cache_hasher<rtx>
  121. {
  122. typedef HOST_WIDE_INT compare_type;
  123. static hashval_t hash (rtx i);
  124. static bool equal (rtx i, HOST_WIDE_INT h);
  125. };
  126. static GTY ((cache)) hash_table<const_int_hasher> *const_int_htab;
  127. struct const_wide_int_hasher : ggc_cache_hasher<rtx>
  128. {
  129. static hashval_t hash (rtx x);
  130. static bool equal (rtx x, rtx y);
  131. };
  132. static GTY ((cache)) hash_table<const_wide_int_hasher> *const_wide_int_htab;
  133. /* A hash table storing register attribute structures. */
  134. struct reg_attr_hasher : ggc_cache_hasher<reg_attrs *>
  135. {
  136. static hashval_t hash (reg_attrs *x);
  137. static bool equal (reg_attrs *a, reg_attrs *b);
  138. };
  139. static GTY ((cache)) hash_table<reg_attr_hasher> *reg_attrs_htab;
  140. /* A hash table storing all CONST_DOUBLEs. */
  141. struct const_double_hasher : ggc_cache_hasher<rtx>
  142. {
  143. static hashval_t hash (rtx x);
  144. static bool equal (rtx x, rtx y);
  145. };
  146. static GTY ((cache)) hash_table<const_double_hasher> *const_double_htab;
  147. /* A hash table storing all CONST_FIXEDs. */
  148. struct const_fixed_hasher : ggc_cache_hasher<rtx>
  149. {
  150. static hashval_t hash (rtx x);
  151. static bool equal (rtx x, rtx y);
  152. };
  153. static GTY ((cache)) hash_table<const_fixed_hasher> *const_fixed_htab;
  154. #define cur_insn_uid (crtl->emit.x_cur_insn_uid)
  155. #define cur_debug_insn_uid (crtl->emit.x_cur_debug_insn_uid)
  156. #define first_label_num (crtl->emit.x_first_label_num)
  157. static void set_used_decls (tree);
  158. static void mark_label_nuses (rtx);
  159. #if TARGET_SUPPORTS_WIDE_INT
  160. static rtx lookup_const_wide_int (rtx);
  161. #endif
  162. static rtx lookup_const_double (rtx);
  163. static rtx lookup_const_fixed (rtx);
  164. static reg_attrs *get_reg_attrs (tree, int);
  165. static rtx gen_const_vector (machine_mode, int);
  166. static void copy_rtx_if_shared_1 (rtx *orig);
  167. /* Probability of the conditional branch currently proceeded by try_split.
  168. Set to -1 otherwise. */
  169. int split_branch_probability = -1;
  170. /* Returns a hash code for X (which is a really a CONST_INT). */
  171. hashval_t
  172. const_int_hasher::hash (rtx x)
  173. {
  174. return (hashval_t) INTVAL (x);
  175. }
  176. /* Returns nonzero if the value represented by X (which is really a
  177. CONST_INT) is the same as that given by Y (which is really a
  178. HOST_WIDE_INT *). */
  179. bool
  180. const_int_hasher::equal (rtx x, HOST_WIDE_INT y)
  181. {
  182. return (INTVAL (x) == y);
  183. }
  184. #if TARGET_SUPPORTS_WIDE_INT
  185. /* Returns a hash code for X (which is a really a CONST_WIDE_INT). */
  186. hashval_t
  187. const_wide_int_hasher::hash (rtx x)
  188. {
  189. int i;
  190. unsigned HOST_WIDE_INT hash = 0;
  191. const_rtx xr = x;
  192. for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++)
  193. hash += CONST_WIDE_INT_ELT (xr, i);
  194. return (hashval_t) hash;
  195. }
  196. /* Returns nonzero if the value represented by X (which is really a
  197. CONST_WIDE_INT) is the same as that given by Y (which is really a
  198. CONST_WIDE_INT). */
  199. bool
  200. const_wide_int_hasher::equal (rtx x, rtx y)
  201. {
  202. int i;
  203. const_rtx xr = x;
  204. const_rtx yr = y;
  205. if (CONST_WIDE_INT_NUNITS (xr) != CONST_WIDE_INT_NUNITS (yr))
  206. return false;
  207. for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++)
  208. if (CONST_WIDE_INT_ELT (xr, i) != CONST_WIDE_INT_ELT (yr, i))
  209. return false;
  210. return true;
  211. }
  212. #endif
  213. /* Returns a hash code for X (which is really a CONST_DOUBLE). */
  214. hashval_t
  215. const_double_hasher::hash (rtx x)
  216. {
  217. const_rtx const value = x;
  218. hashval_t h;
  219. if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (value) == VOIDmode)
  220. h = CONST_DOUBLE_LOW (value) ^ CONST_DOUBLE_HIGH (value);
  221. else
  222. {
  223. h = real_hash (CONST_DOUBLE_REAL_VALUE (value));
  224. /* MODE is used in the comparison, so it should be in the hash. */
  225. h ^= GET_MODE (value);
  226. }
  227. return h;
  228. }
  229. /* Returns nonzero if the value represented by X (really a ...)
  230. is the same as that represented by Y (really a ...) */
  231. bool
  232. const_double_hasher::equal (rtx x, rtx y)
  233. {
  234. const_rtx const a = x, b = y;
  235. if (GET_MODE (a) != GET_MODE (b))
  236. return 0;
  237. if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (a) == VOIDmode)
  238. return (CONST_DOUBLE_LOW (a) == CONST_DOUBLE_LOW (b)
  239. && CONST_DOUBLE_HIGH (a) == CONST_DOUBLE_HIGH (b));
  240. else
  241. return real_identical (CONST_DOUBLE_REAL_VALUE (a),
  242. CONST_DOUBLE_REAL_VALUE (b));
  243. }
  244. /* Returns a hash code for X (which is really a CONST_FIXED). */
  245. hashval_t
  246. const_fixed_hasher::hash (rtx x)
  247. {
  248. const_rtx const value = x;
  249. hashval_t h;
  250. h = fixed_hash (CONST_FIXED_VALUE (value));
  251. /* MODE is used in the comparison, so it should be in the hash. */
  252. h ^= GET_MODE (value);
  253. return h;
  254. }
  255. /* Returns nonzero if the value represented by X is the same as that
  256. represented by Y. */
  257. bool
  258. const_fixed_hasher::equal (rtx x, rtx y)
  259. {
  260. const_rtx const a = x, b = y;
  261. if (GET_MODE (a) != GET_MODE (b))
  262. return 0;
  263. return fixed_identical (CONST_FIXED_VALUE (a), CONST_FIXED_VALUE (b));
  264. }
  265. /* Return true if the given memory attributes are equal. */
  266. bool
  267. mem_attrs_eq_p (const struct mem_attrs *p, const struct mem_attrs *q)
  268. {
  269. if (p == q)
  270. return true;
  271. if (!p || !q)
  272. return false;
  273. return (p->alias == q->alias
  274. && p->offset_known_p == q->offset_known_p
  275. && (!p->offset_known_p || p->offset == q->offset)
  276. && p->size_known_p == q->size_known_p
  277. && (!p->size_known_p || p->size == q->size)
  278. && p->align == q->align
  279. && p->addrspace == q->addrspace
  280. && (p->expr == q->expr
  281. || (p->expr != NULL_TREE && q->expr != NULL_TREE
  282. && operand_equal_p (p->expr, q->expr, 0))));
  283. }
  284. /* Set MEM's memory attributes so that they are the same as ATTRS. */
  285. static void
  286. set_mem_attrs (rtx mem, mem_attrs *attrs)
  287. {
  288. /* If everything is the default, we can just clear the attributes. */
  289. if (mem_attrs_eq_p (attrs, mode_mem_attrs[(int) GET_MODE (mem)]))
  290. {
  291. MEM_ATTRS (mem) = 0;
  292. return;
  293. }
  294. if (!MEM_ATTRS (mem)
  295. || !mem_attrs_eq_p (attrs, MEM_ATTRS (mem)))
  296. {
  297. MEM_ATTRS (mem) = ggc_alloc<mem_attrs> ();
  298. memcpy (MEM_ATTRS (mem), attrs, sizeof (mem_attrs));
  299. }
  300. }
  301. /* Returns a hash code for X (which is a really a reg_attrs *). */
  302. hashval_t
  303. reg_attr_hasher::hash (reg_attrs *x)
  304. {
  305. const reg_attrs *const p = x;
  306. return ((p->offset * 1000) ^ (intptr_t) p->decl);
  307. }
  308. /* Returns nonzero if the value represented by X is the same as that given by
  309. Y. */
  310. bool
  311. reg_attr_hasher::equal (reg_attrs *x, reg_attrs *y)
  312. {
  313. const reg_attrs *const p = x;
  314. const reg_attrs *const q = y;
  315. return (p->decl == q->decl && p->offset == q->offset);
  316. }
  317. /* Allocate a new reg_attrs structure and insert it into the hash table if
  318. one identical to it is not already in the table. We are doing this for
  319. MEM of mode MODE. */
  320. static reg_attrs *
  321. get_reg_attrs (tree decl, int offset)
  322. {
  323. reg_attrs attrs;
  324. /* If everything is the default, we can just return zero. */
  325. if (decl == 0 && offset == 0)
  326. return 0;
  327. attrs.decl = decl;
  328. attrs.offset = offset;
  329. reg_attrs **slot = reg_attrs_htab->find_slot (&attrs, INSERT);
  330. if (*slot == 0)
  331. {
  332. *slot = ggc_alloc<reg_attrs> ();
  333. memcpy (*slot, &attrs, sizeof (reg_attrs));
  334. }
  335. return *slot;
  336. }
  337. #if !HAVE_blockage
  338. /* Generate an empty ASM_INPUT, which is used to block attempts to schedule,
  339. and to block register equivalences to be seen across this insn. */
  340. rtx
  341. gen_blockage (void)
  342. {
  343. rtx x = gen_rtx_ASM_INPUT (VOIDmode, "");
  344. MEM_VOLATILE_P (x) = true;
  345. return x;
  346. }
  347. #endif
  348. /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
  349. don't attempt to share with the various global pieces of rtl (such as
  350. frame_pointer_rtx). */
  351. rtx
  352. gen_raw_REG (machine_mode mode, int regno)
  353. {
  354. rtx x = gen_rtx_raw_REG (mode, regno);
  355. ORIGINAL_REGNO (x) = regno;
  356. return x;
  357. }
  358. /* There are some RTL codes that require special attention; the generation
  359. functions do the raw handling. If you add to this list, modify
  360. special_rtx in gengenrtl.c as well. */
  361. rtx_expr_list *
  362. gen_rtx_EXPR_LIST (machine_mode mode, rtx expr, rtx expr_list)
  363. {
  364. return as_a <rtx_expr_list *> (gen_rtx_fmt_ee (EXPR_LIST, mode, expr,
  365. expr_list));
  366. }
  367. rtx_insn_list *
  368. gen_rtx_INSN_LIST (machine_mode mode, rtx insn, rtx insn_list)
  369. {
  370. return as_a <rtx_insn_list *> (gen_rtx_fmt_ue (INSN_LIST, mode, insn,
  371. insn_list));
  372. }
  373. rtx_insn *
  374. gen_rtx_INSN (machine_mode mode, rtx_insn *prev_insn, rtx_insn *next_insn,
  375. basic_block bb, rtx pattern, int location, int code,
  376. rtx reg_notes)
  377. {
  378. return as_a <rtx_insn *> (gen_rtx_fmt_uuBeiie (INSN, mode,
  379. prev_insn, next_insn,
  380. bb, pattern, location, code,
  381. reg_notes));
  382. }
  383. rtx
  384. gen_rtx_CONST_INT (machine_mode mode ATTRIBUTE_UNUSED, HOST_WIDE_INT arg)
  385. {
  386. if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
  387. return const_int_rtx[arg + MAX_SAVED_CONST_INT];
  388. #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
  389. if (const_true_rtx && arg == STORE_FLAG_VALUE)
  390. return const_true_rtx;
  391. #endif
  392. /* Look up the CONST_INT in the hash table. */
  393. rtx *slot = const_int_htab->find_slot_with_hash (arg, (hashval_t) arg,
  394. INSERT);
  395. if (*slot == 0)
  396. *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
  397. return *slot;
  398. }
  399. rtx
  400. gen_int_mode (HOST_WIDE_INT c, machine_mode mode)
  401. {
  402. return GEN_INT (trunc_int_for_mode (c, mode));
  403. }
  404. /* CONST_DOUBLEs might be created from pairs of integers, or from
  405. REAL_VALUE_TYPEs. Also, their length is known only at run time,
  406. so we cannot use gen_rtx_raw_CONST_DOUBLE. */
  407. /* Determine whether REAL, a CONST_DOUBLE, already exists in the
  408. hash table. If so, return its counterpart; otherwise add it
  409. to the hash table and return it. */
  410. static rtx
  411. lookup_const_double (rtx real)
  412. {
  413. rtx *slot = const_double_htab->find_slot (real, INSERT);
  414. if (*slot == 0)
  415. *slot = real;
  416. return *slot;
  417. }
  418. /* Return a CONST_DOUBLE rtx for a floating-point value specified by
  419. VALUE in mode MODE. */
  420. rtx
  421. const_double_from_real_value (REAL_VALUE_TYPE value, machine_mode mode)
  422. {
  423. rtx real = rtx_alloc (CONST_DOUBLE);
  424. PUT_MODE (real, mode);
  425. real->u.rv = value;
  426. return lookup_const_double (real);
  427. }
  428. /* Determine whether FIXED, a CONST_FIXED, already exists in the
  429. hash table. If so, return its counterpart; otherwise add it
  430. to the hash table and return it. */
  431. static rtx
  432. lookup_const_fixed (rtx fixed)
  433. {
  434. rtx *slot = const_fixed_htab->find_slot (fixed, INSERT);
  435. if (*slot == 0)
  436. *slot = fixed;
  437. return *slot;
  438. }
  439. /* Return a CONST_FIXED rtx for a fixed-point value specified by
  440. VALUE in mode MODE. */
  441. rtx
  442. const_fixed_from_fixed_value (FIXED_VALUE_TYPE value, machine_mode mode)
  443. {
  444. rtx fixed = rtx_alloc (CONST_FIXED);
  445. PUT_MODE (fixed, mode);
  446. fixed->u.fv = value;
  447. return lookup_const_fixed (fixed);
  448. }
  449. #if TARGET_SUPPORTS_WIDE_INT == 0
  450. /* Constructs double_int from rtx CST. */
  451. double_int
  452. rtx_to_double_int (const_rtx cst)
  453. {
  454. double_int r;
  455. if (CONST_INT_P (cst))
  456. r = double_int::from_shwi (INTVAL (cst));
  457. else if (CONST_DOUBLE_AS_INT_P (cst))
  458. {
  459. r.low = CONST_DOUBLE_LOW (cst);
  460. r.high = CONST_DOUBLE_HIGH (cst);
  461. }
  462. else
  463. gcc_unreachable ();
  464. return r;
  465. }
  466. #endif
  467. #if TARGET_SUPPORTS_WIDE_INT
  468. /* Determine whether CONST_WIDE_INT WINT already exists in the hash table.
  469. If so, return its counterpart; otherwise add it to the hash table and
  470. return it. */
  471. static rtx
  472. lookup_const_wide_int (rtx wint)
  473. {
  474. rtx *slot = const_wide_int_htab->find_slot (wint, INSERT);
  475. if (*slot == 0)
  476. *slot = wint;
  477. return *slot;
  478. }
  479. #endif
  480. /* Return an rtx constant for V, given that the constant has mode MODE.
  481. The returned rtx will be a CONST_INT if V fits, otherwise it will be
  482. a CONST_DOUBLE (if !TARGET_SUPPORTS_WIDE_INT) or a CONST_WIDE_INT
  483. (if TARGET_SUPPORTS_WIDE_INT). */
  484. rtx
  485. immed_wide_int_const (const wide_int_ref &v, machine_mode mode)
  486. {
  487. unsigned int len = v.get_len ();
  488. unsigned int prec = GET_MODE_PRECISION (mode);
  489. /* Allow truncation but not extension since we do not know if the
  490. number is signed or unsigned. */
  491. gcc_assert (prec <= v.get_precision ());
  492. if (len < 2 || prec <= HOST_BITS_PER_WIDE_INT)
  493. return gen_int_mode (v.elt (0), mode);
  494. #if TARGET_SUPPORTS_WIDE_INT
  495. {
  496. unsigned int i;
  497. rtx value;
  498. unsigned int blocks_needed
  499. = (prec + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT;
  500. if (len > blocks_needed)
  501. len = blocks_needed;
  502. value = const_wide_int_alloc (len);
  503. /* It is so tempting to just put the mode in here. Must control
  504. myself ... */
  505. PUT_MODE (value, VOIDmode);
  506. CWI_PUT_NUM_ELEM (value, len);
  507. for (i = 0; i < len; i++)
  508. CONST_WIDE_INT_ELT (value, i) = v.elt (i);
  509. return lookup_const_wide_int (value);
  510. }
  511. #else
  512. return immed_double_const (v.elt (0), v.elt (1), mode);
  513. #endif
  514. }
  515. #if TARGET_SUPPORTS_WIDE_INT == 0
  516. /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair
  517. of ints: I0 is the low-order word and I1 is the high-order word.
  518. For values that are larger than HOST_BITS_PER_DOUBLE_INT, the
  519. implied upper bits are copies of the high bit of i1. The value
  520. itself is neither signed nor unsigned. Do not use this routine for
  521. non-integer modes; convert to REAL_VALUE_TYPE and use
  522. CONST_DOUBLE_FROM_REAL_VALUE. */
  523. rtx
  524. immed_double_const (HOST_WIDE_INT i0, HOST_WIDE_INT i1, machine_mode mode)
  525. {
  526. rtx value;
  527. unsigned int i;
  528. /* There are the following cases (note that there are no modes with
  529. HOST_BITS_PER_WIDE_INT < GET_MODE_BITSIZE (mode) < HOST_BITS_PER_DOUBLE_INT):
  530. 1) If GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT, then we use
  531. gen_int_mode.
  532. 2) If the value of the integer fits into HOST_WIDE_INT anyway
  533. (i.e., i1 consists only from copies of the sign bit, and sign
  534. of i0 and i1 are the same), then we return a CONST_INT for i0.
  535. 3) Otherwise, we create a CONST_DOUBLE for i0 and i1. */
  536. if (mode != VOIDmode)
  537. {
  538. gcc_assert (GET_MODE_CLASS (mode) == MODE_INT
  539. || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT
  540. /* We can get a 0 for an error mark. */
  541. || GET_MODE_CLASS (mode) == MODE_VECTOR_INT
  542. || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
  543. || GET_MODE_CLASS (mode) == MODE_POINTER_BOUNDS);
  544. if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  545. return gen_int_mode (i0, mode);
  546. }
  547. /* If this integer fits in one word, return a CONST_INT. */
  548. if ((i1 == 0 && i0 >= 0) || (i1 == ~0 && i0 < 0))
  549. return GEN_INT (i0);
  550. /* We use VOIDmode for integers. */
  551. value = rtx_alloc (CONST_DOUBLE);
  552. PUT_MODE (value, VOIDmode);
  553. CONST_DOUBLE_LOW (value) = i0;
  554. CONST_DOUBLE_HIGH (value) = i1;
  555. for (i = 2; i < (sizeof CONST_DOUBLE_FORMAT - 1); i++)
  556. XWINT (value, i) = 0;
  557. return lookup_const_double (value);
  558. }
  559. #endif
  560. rtx
  561. gen_rtx_REG (machine_mode mode, unsigned int regno)
  562. {
  563. /* In case the MD file explicitly references the frame pointer, have
  564. all such references point to the same frame pointer. This is
  565. used during frame pointer elimination to distinguish the explicit
  566. references to these registers from pseudos that happened to be
  567. assigned to them.
  568. If we have eliminated the frame pointer or arg pointer, we will
  569. be using it as a normal register, for example as a spill
  570. register. In such cases, we might be accessing it in a mode that
  571. is not Pmode and therefore cannot use the pre-allocated rtx.
  572. Also don't do this when we are making new REGs in reload, since
  573. we don't want to get confused with the real pointers. */
  574. if (mode == Pmode && !reload_in_progress && !lra_in_progress)
  575. {
  576. if (regno == FRAME_POINTER_REGNUM
  577. && (!reload_completed || frame_pointer_needed))
  578. return frame_pointer_rtx;
  579. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  580. if (regno == HARD_FRAME_POINTER_REGNUM
  581. && (!reload_completed || frame_pointer_needed))
  582. return hard_frame_pointer_rtx;
  583. #endif
  584. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && !HARD_FRAME_POINTER_IS_ARG_POINTER
  585. if (regno == ARG_POINTER_REGNUM)
  586. return arg_pointer_rtx;
  587. #endif
  588. #ifdef RETURN_ADDRESS_POINTER_REGNUM
  589. if (regno == RETURN_ADDRESS_POINTER_REGNUM)
  590. return return_address_pointer_rtx;
  591. #endif
  592. if (regno == (unsigned) PIC_OFFSET_TABLE_REGNUM
  593. && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
  594. && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
  595. return pic_offset_table_rtx;
  596. if (regno == STACK_POINTER_REGNUM)
  597. return stack_pointer_rtx;
  598. }
  599. #if 0
  600. /* If the per-function register table has been set up, try to re-use
  601. an existing entry in that table to avoid useless generation of RTL.
  602. This code is disabled for now until we can fix the various backends
  603. which depend on having non-shared hard registers in some cases. Long
  604. term we want to re-enable this code as it can significantly cut down
  605. on the amount of useless RTL that gets generated.
  606. We'll also need to fix some code that runs after reload that wants to
  607. set ORIGINAL_REGNO. */
  608. if (cfun
  609. && cfun->emit
  610. && regno_reg_rtx
  611. && regno < FIRST_PSEUDO_REGISTER
  612. && reg_raw_mode[regno] == mode)
  613. return regno_reg_rtx[regno];
  614. #endif
  615. return gen_raw_REG (mode, regno);
  616. }
  617. rtx
  618. gen_rtx_MEM (machine_mode mode, rtx addr)
  619. {
  620. rtx rt = gen_rtx_raw_MEM (mode, addr);
  621. /* This field is not cleared by the mere allocation of the rtx, so
  622. we clear it here. */
  623. MEM_ATTRS (rt) = 0;
  624. return rt;
  625. }
  626. /* Generate a memory referring to non-trapping constant memory. */
  627. rtx
  628. gen_const_mem (machine_mode mode, rtx addr)
  629. {
  630. rtx mem = gen_rtx_MEM (mode, addr);
  631. MEM_READONLY_P (mem) = 1;
  632. MEM_NOTRAP_P (mem) = 1;
  633. return mem;
  634. }
  635. /* Generate a MEM referring to fixed portions of the frame, e.g., register
  636. save areas. */
  637. rtx
  638. gen_frame_mem (machine_mode mode, rtx addr)
  639. {
  640. rtx mem = gen_rtx_MEM (mode, addr);
  641. MEM_NOTRAP_P (mem) = 1;
  642. set_mem_alias_set (mem, get_frame_alias_set ());
  643. return mem;
  644. }
  645. /* Generate a MEM referring to a temporary use of the stack, not part
  646. of the fixed stack frame. For example, something which is pushed
  647. by a target splitter. */
  648. rtx
  649. gen_tmp_stack_mem (machine_mode mode, rtx addr)
  650. {
  651. rtx mem = gen_rtx_MEM (mode, addr);
  652. MEM_NOTRAP_P (mem) = 1;
  653. if (!cfun->calls_alloca)
  654. set_mem_alias_set (mem, get_frame_alias_set ());
  655. return mem;
  656. }
  657. /* We want to create (subreg:OMODE (obj:IMODE) OFFSET). Return true if
  658. this construct would be valid, and false otherwise. */
  659. bool
  660. validate_subreg (machine_mode omode, machine_mode imode,
  661. const_rtx reg, unsigned int offset)
  662. {
  663. unsigned int isize = GET_MODE_SIZE (imode);
  664. unsigned int osize = GET_MODE_SIZE (omode);
  665. /* All subregs must be aligned. */
  666. if (offset % osize != 0)
  667. return false;
  668. /* The subreg offset cannot be outside the inner object. */
  669. if (offset >= isize)
  670. return false;
  671. /* ??? This should not be here. Temporarily continue to allow word_mode
  672. subregs of anything. The most common offender is (subreg:SI (reg:DF)).
  673. Generally, backends are doing something sketchy but it'll take time to
  674. fix them all. */
  675. if (omode == word_mode)
  676. ;
  677. /* ??? Similarly, e.g. with (subreg:DF (reg:TI)). Though store_bit_field
  678. is the culprit here, and not the backends. */
  679. else if (osize >= UNITS_PER_WORD && isize >= osize)
  680. ;
  681. /* Allow component subregs of complex and vector. Though given the below
  682. extraction rules, it's not always clear what that means. */
  683. else if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode))
  684. && GET_MODE_INNER (imode) == omode)
  685. ;
  686. /* ??? x86 sse code makes heavy use of *paradoxical* vector subregs,
  687. i.e. (subreg:V4SF (reg:SF) 0). This surely isn't the cleanest way to
  688. represent this. It's questionable if this ought to be represented at
  689. all -- why can't this all be hidden in post-reload splitters that make
  690. arbitrarily mode changes to the registers themselves. */
  691. else if (VECTOR_MODE_P (omode) && GET_MODE_INNER (omode) == imode)
  692. ;
  693. /* Subregs involving floating point modes are not allowed to
  694. change size. Therefore (subreg:DI (reg:DF) 0) is fine, but
  695. (subreg:SI (reg:DF) 0) isn't. */
  696. else if (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode))
  697. {
  698. if (! (isize == osize
  699. /* LRA can use subreg to store a floating point value in
  700. an integer mode. Although the floating point and the
  701. integer modes need the same number of hard registers,
  702. the size of floating point mode can be less than the
  703. integer mode. LRA also uses subregs for a register
  704. should be used in different mode in on insn. */
  705. || lra_in_progress))
  706. return false;
  707. }
  708. /* Paradoxical subregs must have offset zero. */
  709. if (osize > isize)
  710. return offset == 0;
  711. /* This is a normal subreg. Verify that the offset is representable. */
  712. /* For hard registers, we already have most of these rules collected in
  713. subreg_offset_representable_p. */
  714. if (reg && REG_P (reg) && HARD_REGISTER_P (reg))
  715. {
  716. unsigned int regno = REGNO (reg);
  717. #ifdef CANNOT_CHANGE_MODE_CLASS
  718. if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode))
  719. && GET_MODE_INNER (imode) == omode)
  720. ;
  721. else if (REG_CANNOT_CHANGE_MODE_P (regno, imode, omode))
  722. return false;
  723. #endif
  724. return subreg_offset_representable_p (regno, imode, offset, omode);
  725. }
  726. /* For pseudo registers, we want most of the same checks. Namely:
  727. If the register no larger than a word, the subreg must be lowpart.
  728. If the register is larger than a word, the subreg must be the lowpart
  729. of a subword. A subreg does *not* perform arbitrary bit extraction.
  730. Given that we've already checked mode/offset alignment, we only have
  731. to check subword subregs here. */
  732. if (osize < UNITS_PER_WORD
  733. && ! (lra_in_progress && (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode))))
  734. {
  735. machine_mode wmode = isize > UNITS_PER_WORD ? word_mode : imode;
  736. unsigned int low_off = subreg_lowpart_offset (omode, wmode);
  737. if (offset % UNITS_PER_WORD != low_off)
  738. return false;
  739. }
  740. return true;
  741. }
  742. rtx
  743. gen_rtx_SUBREG (machine_mode mode, rtx reg, int offset)
  744. {
  745. gcc_assert (validate_subreg (mode, GET_MODE (reg), reg, offset));
  746. return gen_rtx_raw_SUBREG (mode, reg, offset);
  747. }
  748. /* Generate a SUBREG representing the least-significant part of REG if MODE
  749. is smaller than mode of REG, otherwise paradoxical SUBREG. */
  750. rtx
  751. gen_lowpart_SUBREG (machine_mode mode, rtx reg)
  752. {
  753. machine_mode inmode;
  754. inmode = GET_MODE (reg);
  755. if (inmode == VOIDmode)
  756. inmode = mode;
  757. return gen_rtx_SUBREG (mode, reg,
  758. subreg_lowpart_offset (mode, inmode));
  759. }
  760. rtx
  761. gen_rtx_VAR_LOCATION (machine_mode mode, tree decl, rtx loc,
  762. enum var_init_status status)
  763. {
  764. rtx x = gen_rtx_fmt_te (VAR_LOCATION, mode, decl, loc);
  765. PAT_VAR_LOCATION_STATUS (x) = status;
  766. return x;
  767. }
  768. /* Create an rtvec and stores within it the RTXen passed in the arguments. */
  769. rtvec
  770. gen_rtvec (int n, ...)
  771. {
  772. int i;
  773. rtvec rt_val;
  774. va_list p;
  775. va_start (p, n);
  776. /* Don't allocate an empty rtvec... */
  777. if (n == 0)
  778. {
  779. va_end (p);
  780. return NULL_RTVEC;
  781. }
  782. rt_val = rtvec_alloc (n);
  783. for (i = 0; i < n; i++)
  784. rt_val->elem[i] = va_arg (p, rtx);
  785. va_end (p);
  786. return rt_val;
  787. }
  788. rtvec
  789. gen_rtvec_v (int n, rtx *argp)
  790. {
  791. int i;
  792. rtvec rt_val;
  793. /* Don't allocate an empty rtvec... */
  794. if (n == 0)
  795. return NULL_RTVEC;
  796. rt_val = rtvec_alloc (n);
  797. for (i = 0; i < n; i++)
  798. rt_val->elem[i] = *argp++;
  799. return rt_val;
  800. }
  801. rtvec
  802. gen_rtvec_v (int n, rtx_insn **argp)
  803. {
  804. int i;
  805. rtvec rt_val;
  806. /* Don't allocate an empty rtvec... */
  807. if (n == 0)
  808. return NULL_RTVEC;
  809. rt_val = rtvec_alloc (n);
  810. for (i = 0; i < n; i++)
  811. rt_val->elem[i] = *argp++;
  812. return rt_val;
  813. }
  814. /* Return the number of bytes between the start of an OUTER_MODE
  815. in-memory value and the start of an INNER_MODE in-memory value,
  816. given that the former is a lowpart of the latter. It may be a
  817. paradoxical lowpart, in which case the offset will be negative
  818. on big-endian targets. */
  819. int
  820. byte_lowpart_offset (machine_mode outer_mode,
  821. machine_mode inner_mode)
  822. {
  823. if (GET_MODE_SIZE (outer_mode) < GET_MODE_SIZE (inner_mode))
  824. return subreg_lowpart_offset (outer_mode, inner_mode);
  825. else
  826. return -subreg_lowpart_offset (inner_mode, outer_mode);
  827. }
  828. /* Generate a REG rtx for a new pseudo register of mode MODE.
  829. This pseudo is assigned the next sequential register number. */
  830. rtx
  831. gen_reg_rtx (machine_mode mode)
  832. {
  833. rtx val;
  834. unsigned int align = GET_MODE_ALIGNMENT (mode);
  835. gcc_assert (can_create_pseudo_p ());
  836. /* If a virtual register with bigger mode alignment is generated,
  837. increase stack alignment estimation because it might be spilled
  838. to stack later. */
  839. if (SUPPORTS_STACK_ALIGNMENT
  840. && crtl->stack_alignment_estimated < align
  841. && !crtl->stack_realign_processed)
  842. {
  843. unsigned int min_align = MINIMUM_ALIGNMENT (NULL, mode, align);
  844. if (crtl->stack_alignment_estimated < min_align)
  845. crtl->stack_alignment_estimated = min_align;
  846. }
  847. if (generating_concat_p
  848. && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
  849. || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
  850. {
  851. /* For complex modes, don't make a single pseudo.
  852. Instead, make a CONCAT of two pseudos.
  853. This allows noncontiguous allocation of the real and imaginary parts,
  854. which makes much better code. Besides, allocating DCmode
  855. pseudos overstrains reload on some machines like the 386. */
  856. rtx realpart, imagpart;
  857. machine_mode partmode = GET_MODE_INNER (mode);
  858. realpart = gen_reg_rtx (partmode);
  859. imagpart = gen_reg_rtx (partmode);
  860. return gen_rtx_CONCAT (mode, realpart, imagpart);
  861. }
  862. /* Do not call gen_reg_rtx with uninitialized crtl. */
  863. gcc_assert (crtl->emit.regno_pointer_align_length);
  864. /* Make sure regno_pointer_align, and regno_reg_rtx are large
  865. enough to have an element for this pseudo reg number. */
  866. if (reg_rtx_no == crtl->emit.regno_pointer_align_length)
  867. {
  868. int old_size = crtl->emit.regno_pointer_align_length;
  869. char *tmp;
  870. rtx *new1;
  871. tmp = XRESIZEVEC (char, crtl->emit.regno_pointer_align, old_size * 2);
  872. memset (tmp + old_size, 0, old_size);
  873. crtl->emit.regno_pointer_align = (unsigned char *) tmp;
  874. new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, old_size * 2);
  875. memset (new1 + old_size, 0, old_size * sizeof (rtx));
  876. regno_reg_rtx = new1;
  877. crtl->emit.regno_pointer_align_length = old_size * 2;
  878. }
  879. val = gen_raw_REG (mode, reg_rtx_no);
  880. regno_reg_rtx[reg_rtx_no++] = val;
  881. return val;
  882. }
  883. /* Return TRUE if REG is a PARM_DECL, FALSE otherwise. */
  884. bool
  885. reg_is_parm_p (rtx reg)
  886. {
  887. tree decl;
  888. gcc_assert (REG_P (reg));
  889. decl = REG_EXPR (reg);
  890. return (decl && TREE_CODE (decl) == PARM_DECL);
  891. }
  892. /* Update NEW with the same attributes as REG, but with OFFSET added
  893. to the REG_OFFSET. */
  894. static void
  895. update_reg_offset (rtx new_rtx, rtx reg, int offset)
  896. {
  897. REG_ATTRS (new_rtx) = get_reg_attrs (REG_EXPR (reg),
  898. REG_OFFSET (reg) + offset);
  899. }
  900. /* Generate a register with same attributes as REG, but with OFFSET
  901. added to the REG_OFFSET. */
  902. rtx
  903. gen_rtx_REG_offset (rtx reg, machine_mode mode, unsigned int regno,
  904. int offset)
  905. {
  906. rtx new_rtx = gen_rtx_REG (mode, regno);
  907. update_reg_offset (new_rtx, reg, offset);
  908. return new_rtx;
  909. }
  910. /* Generate a new pseudo-register with the same attributes as REG, but
  911. with OFFSET added to the REG_OFFSET. */
  912. rtx
  913. gen_reg_rtx_offset (rtx reg, machine_mode mode, int offset)
  914. {
  915. rtx new_rtx = gen_reg_rtx (mode);
  916. update_reg_offset (new_rtx, reg, offset);
  917. return new_rtx;
  918. }
  919. /* Adjust REG in-place so that it has mode MODE. It is assumed that the
  920. new register is a (possibly paradoxical) lowpart of the old one. */
  921. void
  922. adjust_reg_mode (rtx reg, machine_mode mode)
  923. {
  924. update_reg_offset (reg, reg, byte_lowpart_offset (mode, GET_MODE (reg)));
  925. PUT_MODE (reg, mode);
  926. }
  927. /* Copy REG's attributes from X, if X has any attributes. If REG and X
  928. have different modes, REG is a (possibly paradoxical) lowpart of X. */
  929. void
  930. set_reg_attrs_from_value (rtx reg, rtx x)
  931. {
  932. int offset;
  933. bool can_be_reg_pointer = true;
  934. /* Don't call mark_reg_pointer for incompatible pointer sign
  935. extension. */
  936. while (GET_CODE (x) == SIGN_EXTEND
  937. || GET_CODE (x) == ZERO_EXTEND
  938. || GET_CODE (x) == TRUNCATE
  939. || (GET_CODE (x) == SUBREG && subreg_lowpart_p (x)))
  940. {
  941. #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
  942. if ((GET_CODE (x) == SIGN_EXTEND && POINTERS_EXTEND_UNSIGNED)
  943. || (GET_CODE (x) != SIGN_EXTEND && ! POINTERS_EXTEND_UNSIGNED))
  944. can_be_reg_pointer = false;
  945. #endif
  946. x = XEXP (x, 0);
  947. }
  948. /* Hard registers can be reused for multiple purposes within the same
  949. function, so setting REG_ATTRS, REG_POINTER and REG_POINTER_ALIGN
  950. on them is wrong. */
  951. if (HARD_REGISTER_P (reg))
  952. return;
  953. offset = byte_lowpart_offset (GET_MODE (reg), GET_MODE (x));
  954. if (MEM_P (x))
  955. {
  956. if (MEM_OFFSET_KNOWN_P (x))
  957. REG_ATTRS (reg) = get_reg_attrs (MEM_EXPR (x),
  958. MEM_OFFSET (x) + offset);
  959. if (can_be_reg_pointer && MEM_POINTER (x))
  960. mark_reg_pointer (reg, 0);
  961. }
  962. else if (REG_P (x))
  963. {
  964. if (REG_ATTRS (x))
  965. update_reg_offset (reg, x, offset);
  966. if (can_be_reg_pointer && REG_POINTER (x))
  967. mark_reg_pointer (reg, REGNO_POINTER_ALIGN (REGNO (x)));
  968. }
  969. }
  970. /* Generate a REG rtx for a new pseudo register, copying the mode
  971. and attributes from X. */
  972. rtx
  973. gen_reg_rtx_and_attrs (rtx x)
  974. {
  975. rtx reg = gen_reg_rtx (GET_MODE (x));
  976. set_reg_attrs_from_value (reg, x);
  977. return reg;
  978. }
  979. /* Set the register attributes for registers contained in PARM_RTX.
  980. Use needed values from memory attributes of MEM. */
  981. void
  982. set_reg_attrs_for_parm (rtx parm_rtx, rtx mem)
  983. {
  984. if (REG_P (parm_rtx))
  985. set_reg_attrs_from_value (parm_rtx, mem);
  986. else if (GET_CODE (parm_rtx) == PARALLEL)
  987. {
  988. /* Check for a NULL entry in the first slot, used to indicate that the
  989. parameter goes both on the stack and in registers. */
  990. int i = XEXP (XVECEXP (parm_rtx, 0, 0), 0) ? 0 : 1;
  991. for (; i < XVECLEN (parm_rtx, 0); i++)
  992. {
  993. rtx x = XVECEXP (parm_rtx, 0, i);
  994. if (REG_P (XEXP (x, 0)))
  995. REG_ATTRS (XEXP (x, 0))
  996. = get_reg_attrs (MEM_EXPR (mem),
  997. INTVAL (XEXP (x, 1)));
  998. }
  999. }
  1000. }
  1001. /* Set the REG_ATTRS for registers in value X, given that X represents
  1002. decl T. */
  1003. void
  1004. set_reg_attrs_for_decl_rtl (tree t, rtx x)
  1005. {
  1006. if (GET_CODE (x) == SUBREG)
  1007. {
  1008. gcc_assert (subreg_lowpart_p (x));
  1009. x = SUBREG_REG (x);
  1010. }
  1011. if (REG_P (x))
  1012. REG_ATTRS (x)
  1013. = get_reg_attrs (t, byte_lowpart_offset (GET_MODE (x),
  1014. DECL_MODE (t)));
  1015. if (GET_CODE (x) == CONCAT)
  1016. {
  1017. if (REG_P (XEXP (x, 0)))
  1018. REG_ATTRS (XEXP (x, 0)) = get_reg_attrs (t, 0);
  1019. if (REG_P (XEXP (x, 1)))
  1020. REG_ATTRS (XEXP (x, 1))
  1021. = get_reg_attrs (t, GET_MODE_UNIT_SIZE (GET_MODE (XEXP (x, 0))));
  1022. }
  1023. if (GET_CODE (x) == PARALLEL)
  1024. {
  1025. int i, start;
  1026. /* Check for a NULL entry, used to indicate that the parameter goes
  1027. both on the stack and in registers. */
  1028. if (XEXP (XVECEXP (x, 0, 0), 0))
  1029. start = 0;
  1030. else
  1031. start = 1;
  1032. for (i = start; i < XVECLEN (x, 0); i++)
  1033. {
  1034. rtx y = XVECEXP (x, 0, i);
  1035. if (REG_P (XEXP (y, 0)))
  1036. REG_ATTRS (XEXP (y, 0)) = get_reg_attrs (t, INTVAL (XEXP (y, 1)));
  1037. }
  1038. }
  1039. }
  1040. /* Assign the RTX X to declaration T. */
  1041. void
  1042. set_decl_rtl (tree t, rtx x)
  1043. {
  1044. DECL_WRTL_CHECK (t)->decl_with_rtl.rtl = x;
  1045. if (x)
  1046. set_reg_attrs_for_decl_rtl (t, x);
  1047. }
  1048. /* Assign the RTX X to parameter declaration T. BY_REFERENCE_P is true
  1049. if the ABI requires the parameter to be passed by reference. */
  1050. void
  1051. set_decl_incoming_rtl (tree t, rtx x, bool by_reference_p)
  1052. {
  1053. DECL_INCOMING_RTL (t) = x;
  1054. if (x && !by_reference_p)
  1055. set_reg_attrs_for_decl_rtl (t, x);
  1056. }
  1057. /* Identify REG (which may be a CONCAT) as a user register. */
  1058. void
  1059. mark_user_reg (rtx reg)
  1060. {
  1061. if (GET_CODE (reg) == CONCAT)
  1062. {
  1063. REG_USERVAR_P (XEXP (reg, 0)) = 1;
  1064. REG_USERVAR_P (XEXP (reg, 1)) = 1;
  1065. }
  1066. else
  1067. {
  1068. gcc_assert (REG_P (reg));
  1069. REG_USERVAR_P (reg) = 1;
  1070. }
  1071. }
  1072. /* Identify REG as a probable pointer register and show its alignment
  1073. as ALIGN, if nonzero. */
  1074. void
  1075. mark_reg_pointer (rtx reg, int align)
  1076. {
  1077. if (! REG_POINTER (reg))
  1078. {
  1079. REG_POINTER (reg) = 1;
  1080. if (align)
  1081. REGNO_POINTER_ALIGN (REGNO (reg)) = align;
  1082. }
  1083. else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
  1084. /* We can no-longer be sure just how aligned this pointer is. */
  1085. REGNO_POINTER_ALIGN (REGNO (reg)) = align;
  1086. }
  1087. /* Return 1 plus largest pseudo reg number used in the current function. */
  1088. int
  1089. max_reg_num (void)
  1090. {
  1091. return reg_rtx_no;
  1092. }
  1093. /* Return 1 + the largest label number used so far in the current function. */
  1094. int
  1095. max_label_num (void)
  1096. {
  1097. return label_num;
  1098. }
  1099. /* Return first label number used in this function (if any were used). */
  1100. int
  1101. get_first_label_num (void)
  1102. {
  1103. return first_label_num;
  1104. }
  1105. /* If the rtx for label was created during the expansion of a nested
  1106. function, then first_label_num won't include this label number.
  1107. Fix this now so that array indices work later. */
  1108. void
  1109. maybe_set_first_label_num (rtx x)
  1110. {
  1111. if (CODE_LABEL_NUMBER (x) < first_label_num)
  1112. first_label_num = CODE_LABEL_NUMBER (x);
  1113. }
  1114. /* Return a value representing some low-order bits of X, where the number
  1115. of low-order bits is given by MODE. Note that no conversion is done
  1116. between floating-point and fixed-point values, rather, the bit
  1117. representation is returned.
  1118. This function handles the cases in common between gen_lowpart, below,
  1119. and two variants in cse.c and combine.c. These are the cases that can
  1120. be safely handled at all points in the compilation.
  1121. If this is not a case we can handle, return 0. */
  1122. rtx
  1123. gen_lowpart_common (machine_mode mode, rtx x)
  1124. {
  1125. int msize = GET_MODE_SIZE (mode);
  1126. int xsize;
  1127. int offset = 0;
  1128. machine_mode innermode;
  1129. /* Unfortunately, this routine doesn't take a parameter for the mode of X,
  1130. so we have to make one up. Yuk. */
  1131. innermode = GET_MODE (x);
  1132. if (CONST_INT_P (x)
  1133. && msize * BITS_PER_UNIT <= HOST_BITS_PER_WIDE_INT)
  1134. innermode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0);
  1135. else if (innermode == VOIDmode)
  1136. innermode = mode_for_size (HOST_BITS_PER_DOUBLE_INT, MODE_INT, 0);
  1137. xsize = GET_MODE_SIZE (innermode);
  1138. gcc_assert (innermode != VOIDmode && innermode != BLKmode);
  1139. if (innermode == mode)
  1140. return x;
  1141. /* MODE must occupy no more words than the mode of X. */
  1142. if ((msize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
  1143. > ((xsize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))
  1144. return 0;
  1145. /* Don't allow generating paradoxical FLOAT_MODE subregs. */
  1146. if (SCALAR_FLOAT_MODE_P (mode) && msize > xsize)
  1147. return 0;
  1148. offset = subreg_lowpart_offset (mode, innermode);
  1149. if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
  1150. && (GET_MODE_CLASS (mode) == MODE_INT
  1151. || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
  1152. {
  1153. /* If we are getting the low-order part of something that has been
  1154. sign- or zero-extended, we can either just use the object being
  1155. extended or make a narrower extension. If we want an even smaller
  1156. piece than the size of the object being extended, call ourselves
  1157. recursively.
  1158. This case is used mostly by combine and cse. */
  1159. if (GET_MODE (XEXP (x, 0)) == mode)
  1160. return XEXP (x, 0);
  1161. else if (msize < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
  1162. return gen_lowpart_common (mode, XEXP (x, 0));
  1163. else if (msize < xsize)
  1164. return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
  1165. }
  1166. else if (GET_CODE (x) == SUBREG || REG_P (x)
  1167. || GET_CODE (x) == CONCAT || GET_CODE (x) == CONST_VECTOR
  1168. || CONST_DOUBLE_AS_FLOAT_P (x) || CONST_SCALAR_INT_P (x))
  1169. return simplify_gen_subreg (mode, x, innermode, offset);
  1170. /* Otherwise, we can't do this. */
  1171. return 0;
  1172. }
  1173. rtx
  1174. gen_highpart (machine_mode mode, rtx x)
  1175. {
  1176. unsigned int msize = GET_MODE_SIZE (mode);
  1177. rtx result;
  1178. /* This case loses if X is a subreg. To catch bugs early,
  1179. complain if an invalid MODE is used even in other cases. */
  1180. gcc_assert (msize <= UNITS_PER_WORD
  1181. || msize == (unsigned int) GET_MODE_UNIT_SIZE (GET_MODE (x)));
  1182. result = simplify_gen_subreg (mode, x, GET_MODE (x),
  1183. subreg_highpart_offset (mode, GET_MODE (x)));
  1184. gcc_assert (result);
  1185. /* simplify_gen_subreg is not guaranteed to return a valid operand for
  1186. the target if we have a MEM. gen_highpart must return a valid operand,
  1187. emitting code if necessary to do so. */
  1188. if (MEM_P (result))
  1189. {
  1190. result = validize_mem (result);
  1191. gcc_assert (result);
  1192. }
  1193. return result;
  1194. }
  1195. /* Like gen_highpart, but accept mode of EXP operand in case EXP can
  1196. be VOIDmode constant. */
  1197. rtx
  1198. gen_highpart_mode (machine_mode outermode, machine_mode innermode, rtx exp)
  1199. {
  1200. if (GET_MODE (exp) != VOIDmode)
  1201. {
  1202. gcc_assert (GET_MODE (exp) == innermode);
  1203. return gen_highpart (outermode, exp);
  1204. }
  1205. return simplify_gen_subreg (outermode, exp, innermode,
  1206. subreg_highpart_offset (outermode, innermode));
  1207. }
  1208. /* Return the SUBREG_BYTE for an OUTERMODE lowpart of an INNERMODE value. */
  1209. unsigned int
  1210. subreg_lowpart_offset (machine_mode outermode, machine_mode innermode)
  1211. {
  1212. unsigned int offset = 0;
  1213. int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
  1214. if (difference > 0)
  1215. {
  1216. if (WORDS_BIG_ENDIAN)
  1217. offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
  1218. if (BYTES_BIG_ENDIAN)
  1219. offset += difference % UNITS_PER_WORD;
  1220. }
  1221. return offset;
  1222. }
  1223. /* Return offset in bytes to get OUTERMODE high part
  1224. of the value in mode INNERMODE stored in memory in target format. */
  1225. unsigned int
  1226. subreg_highpart_offset (machine_mode outermode, machine_mode innermode)
  1227. {
  1228. unsigned int offset = 0;
  1229. int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
  1230. gcc_assert (GET_MODE_SIZE (innermode) >= GET_MODE_SIZE (outermode));
  1231. if (difference > 0)
  1232. {
  1233. if (! WORDS_BIG_ENDIAN)
  1234. offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
  1235. if (! BYTES_BIG_ENDIAN)
  1236. offset += difference % UNITS_PER_WORD;
  1237. }
  1238. return offset;
  1239. }
  1240. /* Return 1 iff X, assumed to be a SUBREG,
  1241. refers to the least significant part of its containing reg.
  1242. If X is not a SUBREG, always return 1 (it is its own low part!). */
  1243. int
  1244. subreg_lowpart_p (const_rtx x)
  1245. {
  1246. if (GET_CODE (x) != SUBREG)
  1247. return 1;
  1248. else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
  1249. return 0;
  1250. return (subreg_lowpart_offset (GET_MODE (x), GET_MODE (SUBREG_REG (x)))
  1251. == SUBREG_BYTE (x));
  1252. }
  1253. /* Return true if X is a paradoxical subreg, false otherwise. */
  1254. bool
  1255. paradoxical_subreg_p (const_rtx x)
  1256. {
  1257. if (GET_CODE (x) != SUBREG)
  1258. return false;
  1259. return (GET_MODE_PRECISION (GET_MODE (x))
  1260. > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (x))));
  1261. }
  1262. /* Return subword OFFSET of operand OP.
  1263. The word number, OFFSET, is interpreted as the word number starting
  1264. at the low-order address. OFFSET 0 is the low-order word if not
  1265. WORDS_BIG_ENDIAN, otherwise it is the high-order word.
  1266. If we cannot extract the required word, we return zero. Otherwise,
  1267. an rtx corresponding to the requested word will be returned.
  1268. VALIDATE_ADDRESS is nonzero if the address should be validated. Before
  1269. reload has completed, a valid address will always be returned. After
  1270. reload, if a valid address cannot be returned, we return zero.
  1271. If VALIDATE_ADDRESS is zero, we simply form the required address; validating
  1272. it is the responsibility of the caller.
  1273. MODE is the mode of OP in case it is a CONST_INT.
  1274. ??? This is still rather broken for some cases. The problem for the
  1275. moment is that all callers of this thing provide no 'goal mode' to
  1276. tell us to work with. This exists because all callers were written
  1277. in a word based SUBREG world.
  1278. Now use of this function can be deprecated by simplify_subreg in most
  1279. cases.
  1280. */
  1281. rtx
  1282. operand_subword (rtx op, unsigned int offset, int validate_address, machine_mode mode)
  1283. {
  1284. if (mode == VOIDmode)
  1285. mode = GET_MODE (op);
  1286. gcc_assert (mode != VOIDmode);
  1287. /* If OP is narrower than a word, fail. */
  1288. if (mode != BLKmode
  1289. && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
  1290. return 0;
  1291. /* If we want a word outside OP, return zero. */
  1292. if (mode != BLKmode
  1293. && (offset + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
  1294. return const0_rtx;
  1295. /* Form a new MEM at the requested address. */
  1296. if (MEM_P (op))
  1297. {
  1298. rtx new_rtx = adjust_address_nv (op, word_mode, offset * UNITS_PER_WORD);
  1299. if (! validate_address)
  1300. return new_rtx;
  1301. else if (reload_completed)
  1302. {
  1303. if (! strict_memory_address_addr_space_p (word_mode,
  1304. XEXP (new_rtx, 0),
  1305. MEM_ADDR_SPACE (op)))
  1306. return 0;
  1307. }
  1308. else
  1309. return replace_equiv_address (new_rtx, XEXP (new_rtx, 0));
  1310. }
  1311. /* Rest can be handled by simplify_subreg. */
  1312. return simplify_gen_subreg (word_mode, op, mode, (offset * UNITS_PER_WORD));
  1313. }
  1314. /* Similar to `operand_subword', but never return 0. If we can't
  1315. extract the required subword, put OP into a register and try again.
  1316. The second attempt must succeed. We always validate the address in
  1317. this case.
  1318. MODE is the mode of OP, in case it is CONST_INT. */
  1319. rtx
  1320. operand_subword_force (rtx op, unsigned int offset, machine_mode mode)
  1321. {
  1322. rtx result = operand_subword (op, offset, 1, mode);
  1323. if (result)
  1324. return result;
  1325. if (mode != BLKmode && mode != VOIDmode)
  1326. {
  1327. /* If this is a register which can not be accessed by words, copy it
  1328. to a pseudo register. */
  1329. if (REG_P (op))
  1330. op = copy_to_reg (op);
  1331. else
  1332. op = force_reg (mode, op);
  1333. }
  1334. result = operand_subword (op, offset, 1, mode);
  1335. gcc_assert (result);
  1336. return result;
  1337. }
  1338. /* Returns 1 if both MEM_EXPR can be considered equal
  1339. and 0 otherwise. */
  1340. int
  1341. mem_expr_equal_p (const_tree expr1, const_tree expr2)
  1342. {
  1343. if (expr1 == expr2)
  1344. return 1;
  1345. if (! expr1 || ! expr2)
  1346. return 0;
  1347. if (TREE_CODE (expr1) != TREE_CODE (expr2))
  1348. return 0;
  1349. return operand_equal_p (expr1, expr2, 0);
  1350. }
  1351. /* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN
  1352. bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or
  1353. -1 if not known. */
  1354. int
  1355. get_mem_align_offset (rtx mem, unsigned int align)
  1356. {
  1357. tree expr;
  1358. unsigned HOST_WIDE_INT offset;
  1359. /* This function can't use
  1360. if (!MEM_EXPR (mem) || !MEM_OFFSET_KNOWN_P (mem)
  1361. || (MAX (MEM_ALIGN (mem),
  1362. MAX (align, get_object_alignment (MEM_EXPR (mem))))
  1363. < align))
  1364. return -1;
  1365. else
  1366. return (- MEM_OFFSET (mem)) & (align / BITS_PER_UNIT - 1);
  1367. for two reasons:
  1368. - COMPONENT_REFs in MEM_EXPR can have NULL first operand,
  1369. for <variable>. get_inner_reference doesn't handle it and
  1370. even if it did, the alignment in that case needs to be determined
  1371. from DECL_FIELD_CONTEXT's TYPE_ALIGN.
  1372. - it would do suboptimal job for COMPONENT_REFs, even if MEM_EXPR
  1373. isn't sufficiently aligned, the object it is in might be. */
  1374. gcc_assert (MEM_P (mem));
  1375. expr = MEM_EXPR (mem);
  1376. if (expr == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
  1377. return -1;
  1378. offset = MEM_OFFSET (mem);
  1379. if (DECL_P (expr))
  1380. {
  1381. if (DECL_ALIGN (expr) < align)
  1382. return -1;
  1383. }
  1384. else if (INDIRECT_REF_P (expr))
  1385. {
  1386. if (TYPE_ALIGN (TREE_TYPE (expr)) < (unsigned int) align)
  1387. return -1;
  1388. }
  1389. else if (TREE_CODE (expr) == COMPONENT_REF)
  1390. {
  1391. while (1)
  1392. {
  1393. tree inner = TREE_OPERAND (expr, 0);
  1394. tree field = TREE_OPERAND (expr, 1);
  1395. tree byte_offset = component_ref_field_offset (expr);
  1396. tree bit_offset = DECL_FIELD_BIT_OFFSET (field);
  1397. if (!byte_offset
  1398. || !tree_fits_uhwi_p (byte_offset)
  1399. || !tree_fits_uhwi_p (bit_offset))
  1400. return -1;
  1401. offset += tree_to_uhwi (byte_offset);
  1402. offset += tree_to_uhwi (bit_offset) / BITS_PER_UNIT;
  1403. if (inner == NULL_TREE)
  1404. {
  1405. if (TYPE_ALIGN (DECL_FIELD_CONTEXT (field))
  1406. < (unsigned int) align)
  1407. return -1;
  1408. break;
  1409. }
  1410. else if (DECL_P (inner))
  1411. {
  1412. if (DECL_ALIGN (inner) < align)
  1413. return -1;
  1414. break;
  1415. }
  1416. else if (TREE_CODE (inner) != COMPONENT_REF)
  1417. return -1;
  1418. expr = inner;
  1419. }
  1420. }
  1421. else
  1422. return -1;
  1423. return offset & ((align / BITS_PER_UNIT) - 1);
  1424. }
  1425. /* Given REF (a MEM) and T, either the type of X or the expression
  1426. corresponding to REF, set the memory attributes. OBJECTP is nonzero
  1427. if we are making a new object of this type. BITPOS is nonzero if
  1428. there is an offset outstanding on T that will be applied later. */
  1429. void
  1430. set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp,
  1431. HOST_WIDE_INT bitpos)
  1432. {
  1433. HOST_WIDE_INT apply_bitpos = 0;
  1434. tree type;
  1435. struct mem_attrs attrs, *defattrs, *refattrs;
  1436. addr_space_t as;
  1437. /* It can happen that type_for_mode was given a mode for which there
  1438. is no language-level type. In which case it returns NULL, which
  1439. we can see here. */
  1440. if (t == NULL_TREE)
  1441. return;
  1442. type = TYPE_P (t) ? t : TREE_TYPE (t);
  1443. if (type == error_mark_node)
  1444. return;
  1445. /* If we have already set DECL_RTL = ref, get_alias_set will get the
  1446. wrong answer, as it assumes that DECL_RTL already has the right alias
  1447. info. Callers should not set DECL_RTL until after the call to
  1448. set_mem_attributes. */
  1449. gcc_assert (!DECL_P (t) || ref != DECL_RTL_IF_SET (t));
  1450. memset (&attrs, 0, sizeof (attrs));
  1451. /* Get the alias set from the expression or type (perhaps using a
  1452. front-end routine) and use it. */
  1453. attrs.alias = get_alias_set (t);
  1454. MEM_VOLATILE_P (ref) |= TYPE_VOLATILE (type);
  1455. MEM_POINTER (ref) = POINTER_TYPE_P (type);
  1456. /* Default values from pre-existing memory attributes if present. */
  1457. refattrs = MEM_ATTRS (ref);
  1458. if (refattrs)
  1459. {
  1460. /* ??? Can this ever happen? Calling this routine on a MEM that
  1461. already carries memory attributes should probably be invalid. */
  1462. attrs.expr = refattrs->expr;
  1463. attrs.offset_known_p = refattrs->offset_known_p;
  1464. attrs.offset = refattrs->offset;
  1465. attrs.size_known_p = refattrs->size_known_p;
  1466. attrs.size = refattrs->size;
  1467. attrs.align = refattrs->align;
  1468. }
  1469. /* Otherwise, default values from the mode of the MEM reference. */
  1470. else
  1471. {
  1472. defattrs = mode_mem_attrs[(int) GET_MODE (ref)];
  1473. gcc_assert (!defattrs->expr);
  1474. gcc_assert (!defattrs->offset_known_p);
  1475. /* Respect mode size. */
  1476. attrs.size_known_p = defattrs->size_known_p;
  1477. attrs.size = defattrs->size;
  1478. /* ??? Is this really necessary? We probably should always get
  1479. the size from the type below. */
  1480. /* Respect mode alignment for STRICT_ALIGNMENT targets if T is a type;
  1481. if T is an object, always compute the object alignment below. */
  1482. if (TYPE_P (t))
  1483. attrs.align = defattrs->align;
  1484. else
  1485. attrs.align = BITS_PER_UNIT;
  1486. /* ??? If T is a type, respecting mode alignment may *also* be wrong
  1487. e.g. if the type carries an alignment attribute. Should we be
  1488. able to simply always use TYPE_ALIGN? */
  1489. }
  1490. /* We can set the alignment from the type if we are making an object,
  1491. this is an INDIRECT_REF, or if TYPE_ALIGN_OK. */
  1492. if (objectp || TREE_CODE (t) == INDIRECT_REF || TYPE_ALIGN_OK (type))
  1493. attrs.align = MAX (attrs.align, TYPE_ALIGN (type));
  1494. /* If the size is known, we can set that. */
  1495. tree new_size = TYPE_SIZE_UNIT (type);
  1496. /* The address-space is that of the type. */
  1497. as = TYPE_ADDR_SPACE (type);
  1498. /* If T is not a type, we may be able to deduce some more information about
  1499. the expression. */
  1500. if (! TYPE_P (t))
  1501. {
  1502. tree base;
  1503. if (TREE_THIS_VOLATILE (t))
  1504. MEM_VOLATILE_P (ref) = 1;
  1505. /* Now remove any conversions: they don't change what the underlying
  1506. object is. Likewise for SAVE_EXPR. */
  1507. while (CONVERT_EXPR_P (t)
  1508. || TREE_CODE (t) == VIEW_CONVERT_EXPR
  1509. || TREE_CODE (t) == SAVE_EXPR)
  1510. t = TREE_OPERAND (t, 0);
  1511. /* Note whether this expression can trap. */
  1512. MEM_NOTRAP_P (ref) = !tree_could_trap_p (t);
  1513. base = get_base_address (t);
  1514. if (base)
  1515. {
  1516. if (DECL_P (base)
  1517. && TREE_READONLY (base)
  1518. && (TREE_STATIC (base) || DECL_EXTERNAL (base))
  1519. && !TREE_THIS_VOLATILE (base))
  1520. MEM_READONLY_P (ref) = 1;
  1521. /* Mark static const strings readonly as well. */
  1522. if (TREE_CODE (base) == STRING_CST
  1523. && TREE_READONLY (base)
  1524. && TREE_STATIC (base))
  1525. MEM_READONLY_P (ref) = 1;
  1526. /* Address-space information is on the base object. */
  1527. if (TREE_CODE (base) == MEM_REF
  1528. || TREE_CODE (base) == TARGET_MEM_REF)
  1529. as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (base,
  1530. 0))));
  1531. else
  1532. as = TYPE_ADDR_SPACE (TREE_TYPE (base));
  1533. }
  1534. /* If this expression uses it's parent's alias set, mark it such
  1535. that we won't change it. */
  1536. if (component_uses_parent_alias_set_from (t) != NULL_TREE)
  1537. MEM_KEEP_ALIAS_SET_P (ref) = 1;
  1538. /* If this is a decl, set the attributes of the MEM from it. */
  1539. if (DECL_P (t))
  1540. {
  1541. attrs.expr = t;
  1542. attrs.offset_known_p = true;
  1543. attrs.offset = 0;
  1544. apply_bitpos = bitpos;
  1545. new_size = DECL_SIZE_UNIT (t);
  1546. }
  1547. /* ??? If we end up with a constant here do record a MEM_EXPR. */
  1548. else if (CONSTANT_CLASS_P (t))
  1549. ;
  1550. /* If this is a field reference, record it. */
  1551. else if (TREE_CODE (t) == COMPONENT_REF)
  1552. {
  1553. attrs.expr = t;
  1554. attrs.offset_known_p = true;
  1555. attrs.offset = 0;
  1556. apply_bitpos = bitpos;
  1557. if (DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
  1558. new_size = DECL_SIZE_UNIT (TREE_OPERAND (t, 1));
  1559. }
  1560. /* If this is an array reference, look for an outer field reference. */
  1561. else if (TREE_CODE (t) == ARRAY_REF)
  1562. {
  1563. tree off_tree = size_zero_node;
  1564. /* We can't modify t, because we use it at the end of the
  1565. function. */
  1566. tree t2 = t;
  1567. do
  1568. {
  1569. tree index = TREE_OPERAND (t2, 1);
  1570. tree low_bound = array_ref_low_bound (t2);
  1571. tree unit_size = array_ref_element_size (t2);
  1572. /* We assume all arrays have sizes that are a multiple of a byte.
  1573. First subtract the lower bound, if any, in the type of the
  1574. index, then convert to sizetype and multiply by the size of
  1575. the array element. */
  1576. if (! integer_zerop (low_bound))
  1577. index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
  1578. index, low_bound);
  1579. off_tree = size_binop (PLUS_EXPR,
  1580. size_binop (MULT_EXPR,
  1581. fold_convert (sizetype,
  1582. index),
  1583. unit_size),
  1584. off_tree);
  1585. t2 = TREE_OPERAND (t2, 0);
  1586. }
  1587. while (TREE_CODE (t2) == ARRAY_REF);
  1588. if (DECL_P (t2)
  1589. || TREE_CODE (t2) == COMPONENT_REF)
  1590. {
  1591. attrs.expr = t2;
  1592. attrs.offset_known_p = false;
  1593. if (tree_fits_uhwi_p (off_tree))
  1594. {
  1595. attrs.offset_known_p = true;
  1596. attrs.offset = tree_to_uhwi (off_tree);
  1597. apply_bitpos = bitpos;
  1598. }
  1599. }
  1600. /* Else do not record a MEM_EXPR. */
  1601. }
  1602. /* If this is an indirect reference, record it. */
  1603. else if (TREE_CODE (t) == MEM_REF
  1604. || TREE_CODE (t) == TARGET_MEM_REF)
  1605. {
  1606. attrs.expr = t;
  1607. attrs.offset_known_p = true;
  1608. attrs.offset = 0;
  1609. apply_bitpos = bitpos;
  1610. }
  1611. /* Compute the alignment. */
  1612. unsigned int obj_align;
  1613. unsigned HOST_WIDE_INT obj_bitpos;
  1614. get_object_alignment_1 (t, &obj_align, &obj_bitpos);
  1615. obj_bitpos = (obj_bitpos - bitpos) & (obj_align - 1);
  1616. if (obj_bitpos != 0)
  1617. obj_align = (obj_bitpos & -obj_bitpos);
  1618. attrs.align = MAX (attrs.align, obj_align);
  1619. }
  1620. if (tree_fits_uhwi_p (new_size))
  1621. {
  1622. attrs.size_known_p = true;
  1623. attrs.size = tree_to_uhwi (new_size);
  1624. }
  1625. /* If we modified OFFSET based on T, then subtract the outstanding
  1626. bit position offset. Similarly, increase the size of the accessed
  1627. object to contain the negative offset. */
  1628. if (apply_bitpos)
  1629. {
  1630. gcc_assert (attrs.offset_known_p);
  1631. attrs.offset -= apply_bitpos / BITS_PER_UNIT;
  1632. if (attrs.size_known_p)
  1633. attrs.size += apply_bitpos / BITS_PER_UNIT;
  1634. }
  1635. /* Now set the attributes we computed above. */
  1636. attrs.addrspace = as;
  1637. set_mem_attrs (ref, &attrs);
  1638. }
  1639. void
  1640. set_mem_attributes (rtx ref, tree t, int objectp)
  1641. {
  1642. set_mem_attributes_minus_bitpos (ref, t, objectp, 0);
  1643. }
  1644. /* Set the alias set of MEM to SET. */
  1645. void
  1646. set_mem_alias_set (rtx mem, alias_set_type set)
  1647. {
  1648. struct mem_attrs attrs;
  1649. /* If the new and old alias sets don't conflict, something is wrong. */
  1650. gcc_checking_assert (alias_sets_conflict_p (set, MEM_ALIAS_SET (mem)));
  1651. attrs = *get_mem_attrs (mem);
  1652. attrs.alias = set;
  1653. set_mem_attrs (mem, &attrs);
  1654. }
  1655. /* Set the address space of MEM to ADDRSPACE (target-defined). */
  1656. void
  1657. set_mem_addr_space (rtx mem, addr_space_t addrspace)
  1658. {
  1659. struct mem_attrs attrs;
  1660. attrs = *get_mem_attrs (mem);
  1661. attrs.addrspace = addrspace;
  1662. set_mem_attrs (mem, &attrs);
  1663. }
  1664. /* Set the alignment of MEM to ALIGN bits. */
  1665. void
  1666. set_mem_align (rtx mem, unsigned int align)
  1667. {
  1668. struct mem_attrs attrs;
  1669. attrs = *get_mem_attrs (mem);
  1670. attrs.align = align;
  1671. set_mem_attrs (mem, &attrs);
  1672. }
  1673. /* Set the expr for MEM to EXPR. */
  1674. void
  1675. set_mem_expr (rtx mem, tree expr)
  1676. {
  1677. struct mem_attrs attrs;
  1678. attrs = *get_mem_attrs (mem);
  1679. attrs.expr = expr;
  1680. set_mem_attrs (mem, &attrs);
  1681. }
  1682. /* Set the offset of MEM to OFFSET. */
  1683. void
  1684. set_mem_offset (rtx mem, HOST_WIDE_INT offset)
  1685. {
  1686. struct mem_attrs attrs;
  1687. attrs = *get_mem_attrs (mem);
  1688. attrs.offset_known_p = true;
  1689. attrs.offset = offset;
  1690. set_mem_attrs (mem, &attrs);
  1691. }
  1692. /* Clear the offset of MEM. */
  1693. void
  1694. clear_mem_offset (rtx mem)
  1695. {
  1696. struct mem_attrs attrs;
  1697. attrs = *get_mem_attrs (mem);
  1698. attrs.offset_known_p = false;
  1699. set_mem_attrs (mem, &attrs);
  1700. }
  1701. /* Set the size of MEM to SIZE. */
  1702. void
  1703. set_mem_size (rtx mem, HOST_WIDE_INT size)
  1704. {
  1705. struct mem_attrs attrs;
  1706. attrs = *get_mem_attrs (mem);
  1707. attrs.size_known_p = true;
  1708. attrs.size = size;
  1709. set_mem_attrs (mem, &attrs);
  1710. }
  1711. /* Clear the size of MEM. */
  1712. void
  1713. clear_mem_size (rtx mem)
  1714. {
  1715. struct mem_attrs attrs;
  1716. attrs = *get_mem_attrs (mem);
  1717. attrs.size_known_p = false;
  1718. set_mem_attrs (mem, &attrs);
  1719. }
  1720. /* Return a memory reference like MEMREF, but with its mode changed to MODE
  1721. and its address changed to ADDR. (VOIDmode means don't change the mode.
  1722. NULL for ADDR means don't change the address.) VALIDATE is nonzero if the
  1723. returned memory location is required to be valid. INPLACE is true if any
  1724. changes can be made directly to MEMREF or false if MEMREF must be treated
  1725. as immutable.
  1726. The memory attributes are not changed. */
  1727. static rtx
  1728. change_address_1 (rtx memref, machine_mode mode, rtx addr, int validate,
  1729. bool inplace)
  1730. {
  1731. addr_space_t as;
  1732. rtx new_rtx;
  1733. gcc_assert (MEM_P (memref));
  1734. as = MEM_ADDR_SPACE (memref);
  1735. if (mode == VOIDmode)
  1736. mode = GET_MODE (memref);
  1737. if (addr == 0)
  1738. addr = XEXP (memref, 0);
  1739. if (mode == GET_MODE (memref) && addr == XEXP (memref, 0)
  1740. && (!validate || memory_address_addr_space_p (mode, addr, as)))
  1741. return memref;
  1742. /* Don't validate address for LRA. LRA can make the address valid
  1743. by itself in most efficient way. */
  1744. if (validate && !lra_in_progress)
  1745. {
  1746. if (reload_in_progress || reload_completed)
  1747. gcc_assert (memory_address_addr_space_p (mode, addr, as));
  1748. else
  1749. addr = memory_address_addr_space (mode, addr, as);
  1750. }
  1751. if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
  1752. return memref;
  1753. if (inplace)
  1754. {
  1755. XEXP (memref, 0) = addr;
  1756. return memref;
  1757. }
  1758. new_rtx = gen_rtx_MEM (mode, addr);
  1759. MEM_COPY_ATTRIBUTES (new_rtx, memref);
  1760. return new_rtx;
  1761. }
  1762. /* Like change_address_1 with VALIDATE nonzero, but we are not saying in what
  1763. way we are changing MEMREF, so we only preserve the alias set. */
  1764. rtx
  1765. change_address (rtx memref, machine_mode mode, rtx addr)
  1766. {
  1767. rtx new_rtx = change_address_1 (memref, mode, addr, 1, false);
  1768. machine_mode mmode = GET_MODE (new_rtx);
  1769. struct mem_attrs attrs, *defattrs;
  1770. attrs = *get_mem_attrs (memref);
  1771. defattrs = mode_mem_attrs[(int) mmode];
  1772. attrs.expr = NULL_TREE;
  1773. attrs.offset_known_p = false;
  1774. attrs.size_known_p = defattrs->size_known_p;
  1775. attrs.size = defattrs->size;
  1776. attrs.align = defattrs->align;
  1777. /* If there are no changes, just return the original memory reference. */
  1778. if (new_rtx == memref)
  1779. {
  1780. if (mem_attrs_eq_p (get_mem_attrs (memref), &attrs))
  1781. return new_rtx;
  1782. new_rtx = gen_rtx_MEM (mmode, XEXP (memref, 0));
  1783. MEM_COPY_ATTRIBUTES (new_rtx, memref);
  1784. }
  1785. set_mem_attrs (new_rtx, &attrs);
  1786. return new_rtx;
  1787. }
  1788. /* Return a memory reference like MEMREF, but with its mode changed
  1789. to MODE and its address offset by OFFSET bytes. If VALIDATE is
  1790. nonzero, the memory address is forced to be valid.
  1791. If ADJUST_ADDRESS is zero, OFFSET is only used to update MEM_ATTRS
  1792. and the caller is responsible for adjusting MEMREF base register.
  1793. If ADJUST_OBJECT is zero, the underlying object associated with the
  1794. memory reference is left unchanged and the caller is responsible for
  1795. dealing with it. Otherwise, if the new memory reference is outside
  1796. the underlying object, even partially, then the object is dropped.
  1797. SIZE, if nonzero, is the size of an access in cases where MODE
  1798. has no inherent size. */
  1799. rtx
  1800. adjust_address_1 (rtx memref, machine_mode mode, HOST_WIDE_INT offset,
  1801. int validate, int adjust_address, int adjust_object,
  1802. HOST_WIDE_INT size)
  1803. {
  1804. rtx addr = XEXP (memref, 0);
  1805. rtx new_rtx;
  1806. machine_mode address_mode;
  1807. int pbits;
  1808. struct mem_attrs attrs = *get_mem_attrs (memref), *defattrs;
  1809. unsigned HOST_WIDE_INT max_align;
  1810. #ifdef POINTERS_EXTEND_UNSIGNED
  1811. machine_mode pointer_mode
  1812. = targetm.addr_space.pointer_mode (attrs.addrspace);
  1813. #endif
  1814. /* VOIDmode means no mode change for change_address_1. */
  1815. if (mode == VOIDmode)
  1816. mode = GET_MODE (memref);
  1817. /* Take the size of non-BLKmode accesses from the mode. */
  1818. defattrs = mode_mem_attrs[(int) mode];
  1819. if (defattrs->size_known_p)
  1820. size = defattrs->size;
  1821. /* If there are no changes, just return the original memory reference. */
  1822. if (mode == GET_MODE (memref) && !offset
  1823. && (size == 0 || (attrs.size_known_p && attrs.size == size))
  1824. && (!validate || memory_address_addr_space_p (mode, addr,
  1825. attrs.addrspace)))
  1826. return memref;
  1827. /* ??? Prefer to create garbage instead of creating shared rtl.
  1828. This may happen even if offset is nonzero -- consider
  1829. (plus (plus reg reg) const_int) -- so do this always. */
  1830. addr = copy_rtx (addr);
  1831. /* Convert a possibly large offset to a signed value within the
  1832. range of the target address space. */
  1833. address_mode = get_address_mode (memref);
  1834. pbits = GET_MODE_BITSIZE (address_mode);
  1835. if (HOST_BITS_PER_WIDE_INT > pbits)
  1836. {
  1837. int shift = HOST_BITS_PER_WIDE_INT - pbits;
  1838. offset = (((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) offset << shift))
  1839. >> shift);
  1840. }
  1841. if (adjust_address)
  1842. {
  1843. /* If MEMREF is a LO_SUM and the offset is within the alignment of the
  1844. object, we can merge it into the LO_SUM. */
  1845. if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
  1846. && offset >= 0
  1847. && (unsigned HOST_WIDE_INT) offset
  1848. < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
  1849. addr = gen_rtx_LO_SUM (address_mode, XEXP (addr, 0),
  1850. plus_constant (address_mode,
  1851. XEXP (addr, 1), offset));
  1852. #ifdef POINTERS_EXTEND_UNSIGNED
  1853. /* If MEMREF is a ZERO_EXTEND from pointer_mode and the offset is valid
  1854. in that mode, we merge it into the ZERO_EXTEND. We take advantage of
  1855. the fact that pointers are not allowed to overflow. */
  1856. else if (POINTERS_EXTEND_UNSIGNED > 0
  1857. && GET_CODE (addr) == ZERO_EXTEND
  1858. && GET_MODE (XEXP (addr, 0)) == pointer_mode
  1859. && trunc_int_for_mode (offset, pointer_mode) == offset)
  1860. addr = gen_rtx_ZERO_EXTEND (address_mode,
  1861. plus_constant (pointer_mode,
  1862. XEXP (addr, 0), offset));
  1863. #endif
  1864. else
  1865. addr = plus_constant (address_mode, addr, offset);
  1866. }
  1867. new_rtx = change_address_1 (memref, mode, addr, validate, false);
  1868. /* If the address is a REG, change_address_1 rightfully returns memref,
  1869. but this would destroy memref's MEM_ATTRS. */
  1870. if (new_rtx == memref && offset != 0)
  1871. new_rtx = copy_rtx (new_rtx);
  1872. /* Conservatively drop the object if we don't know where we start from. */
  1873. if (adjust_object && (!attrs.offset_known_p || !attrs.size_known_p))
  1874. {
  1875. attrs.expr = NULL_TREE;
  1876. attrs.alias = 0;
  1877. }
  1878. /* Compute the new values of the memory attributes due to this adjustment.
  1879. We add the offsets and update the alignment. */
  1880. if (attrs.offset_known_p)
  1881. {
  1882. attrs.offset += offset;
  1883. /* Drop the object if the new left end is not within its bounds. */
  1884. if (adjust_object && attrs.offset < 0)
  1885. {
  1886. attrs.expr = NULL_TREE;
  1887. attrs.alias = 0;
  1888. }
  1889. }
  1890. /* Compute the new alignment by taking the MIN of the alignment and the
  1891. lowest-order set bit in OFFSET, but don't change the alignment if OFFSET
  1892. if zero. */
  1893. if (offset != 0)
  1894. {
  1895. max_align = (offset & -offset) * BITS_PER_UNIT;
  1896. attrs.align = MIN (attrs.align, max_align);
  1897. }
  1898. if (size)
  1899. {
  1900. /* Drop the object if the new right end is not within its bounds. */
  1901. if (adjust_object && (offset + size) > attrs.size)
  1902. {
  1903. attrs.expr = NULL_TREE;
  1904. attrs.alias = 0;
  1905. }
  1906. attrs.size_known_p = true;
  1907. attrs.size = size;
  1908. }
  1909. else if (attrs.size_known_p)
  1910. {
  1911. gcc_assert (!adjust_object);
  1912. attrs.size -= offset;
  1913. /* ??? The store_by_pieces machinery generates negative sizes,
  1914. so don't assert for that here. */
  1915. }
  1916. set_mem_attrs (new_rtx, &attrs);
  1917. return new_rtx;
  1918. }
  1919. /* Return a memory reference like MEMREF, but with its mode changed
  1920. to MODE and its address changed to ADDR, which is assumed to be
  1921. MEMREF offset by OFFSET bytes. If VALIDATE is
  1922. nonzero, the memory address is forced to be valid. */
  1923. rtx
  1924. adjust_automodify_address_1 (rtx memref, machine_mode mode, rtx addr,
  1925. HOST_WIDE_INT offset, int validate)
  1926. {
  1927. memref = change_address_1 (memref, VOIDmode, addr, validate, false);
  1928. return adjust_address_1 (memref, mode, offset, validate, 0, 0, 0);
  1929. }
  1930. /* Return a memory reference like MEMREF, but whose address is changed by
  1931. adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
  1932. known to be in OFFSET (possibly 1). */
  1933. rtx
  1934. offset_address (rtx memref, rtx offset, unsigned HOST_WIDE_INT pow2)
  1935. {
  1936. rtx new_rtx, addr = XEXP (memref, 0);
  1937. machine_mode address_mode;
  1938. struct mem_attrs attrs, *defattrs;
  1939. attrs = *get_mem_attrs (memref);
  1940. address_mode = get_address_mode (memref);
  1941. new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset);
  1942. /* At this point we don't know _why_ the address is invalid. It
  1943. could have secondary memory references, multiplies or anything.
  1944. However, if we did go and rearrange things, we can wind up not
  1945. being able to recognize the magic around pic_offset_table_rtx.
  1946. This stuff is fragile, and is yet another example of why it is
  1947. bad to expose PIC machinery too early. */
  1948. if (! memory_address_addr_space_p (GET_MODE (memref), new_rtx,
  1949. attrs.addrspace)
  1950. && GET_CODE (addr) == PLUS
  1951. && XEXP (addr, 0) == pic_offset_table_rtx)
  1952. {
  1953. addr = force_reg (GET_MODE (addr), addr);
  1954. new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset);
  1955. }
  1956. update_temp_slot_address (XEXP (memref, 0), new_rtx);
  1957. new_rtx = change_address_1 (memref, VOIDmode, new_rtx, 1, false);
  1958. /* If there are no changes, just return the original memory reference. */
  1959. if (new_rtx == memref)
  1960. return new_rtx;
  1961. /* Update the alignment to reflect the offset. Reset the offset, which
  1962. we don't know. */
  1963. defattrs = mode_mem_attrs[(int) GET_MODE (new_rtx)];
  1964. attrs.offset_known_p = false;
  1965. attrs.size_known_p = defattrs->size_known_p;
  1966. attrs.size = defattrs->size;
  1967. attrs.align = MIN (attrs.align, pow2 * BITS_PER_UNIT);
  1968. set_mem_attrs (new_rtx, &attrs);
  1969. return new_rtx;
  1970. }
  1971. /* Return a memory reference like MEMREF, but with its address changed to
  1972. ADDR. The caller is asserting that the actual piece of memory pointed
  1973. to is the same, just the form of the address is being changed, such as
  1974. by putting something into a register. INPLACE is true if any changes
  1975. can be made directly to MEMREF or false if MEMREF must be treated as
  1976. immutable. */
  1977. rtx
  1978. replace_equiv_address (rtx memref, rtx addr, bool inplace)
  1979. {
  1980. /* change_address_1 copies the memory attribute structure without change
  1981. and that's exactly what we want here. */
  1982. update_temp_slot_address (XEXP (memref, 0), addr);
  1983. return change_address_1 (memref, VOIDmode, addr, 1, inplace);
  1984. }
  1985. /* Likewise, but the reference is not required to be valid. */
  1986. rtx
  1987. replace_equiv_address_nv (rtx memref, rtx addr, bool inplace)
  1988. {
  1989. return change_address_1 (memref, VOIDmode, addr, 0, inplace);
  1990. }
  1991. /* Return a memory reference like MEMREF, but with its mode widened to
  1992. MODE and offset by OFFSET. This would be used by targets that e.g.
  1993. cannot issue QImode memory operations and have to use SImode memory
  1994. operations plus masking logic. */
  1995. rtx
  1996. widen_memory_access (rtx memref, machine_mode mode, HOST_WIDE_INT offset)
  1997. {
  1998. rtx new_rtx = adjust_address_1 (memref, mode, offset, 1, 1, 0, 0);
  1999. struct mem_attrs attrs;
  2000. unsigned int size = GET_MODE_SIZE (mode);
  2001. /* If there are no changes, just return the original memory reference. */
  2002. if (new_rtx == memref)
  2003. return new_rtx;
  2004. attrs = *get_mem_attrs (new_rtx);
  2005. /* If we don't know what offset we were at within the expression, then
  2006. we can't know if we've overstepped the bounds. */
  2007. if (! attrs.offset_known_p)
  2008. attrs.expr = NULL_TREE;
  2009. while (attrs.expr)
  2010. {
  2011. if (TREE_CODE (attrs.expr) == COMPONENT_REF)
  2012. {
  2013. tree field = TREE_OPERAND (attrs.expr, 1);
  2014. tree offset = component_ref_field_offset (attrs.expr);
  2015. if (! DECL_SIZE_UNIT (field))
  2016. {
  2017. attrs.expr = NULL_TREE;
  2018. break;
  2019. }
  2020. /* Is the field at least as large as the access? If so, ok,
  2021. otherwise strip back to the containing structure. */
  2022. if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST
  2023. && compare_tree_int (DECL_SIZE_UNIT (field), size) >= 0
  2024. && attrs.offset >= 0)
  2025. break;
  2026. if (! tree_fits_uhwi_p (offset))
  2027. {
  2028. attrs.expr = NULL_TREE;
  2029. break;
  2030. }
  2031. attrs.expr = TREE_OPERAND (attrs.expr, 0);
  2032. attrs.offset += tree_to_uhwi (offset);
  2033. attrs.offset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
  2034. / BITS_PER_UNIT);
  2035. }
  2036. /* Similarly for the decl. */
  2037. else if (DECL_P (attrs.expr)
  2038. && DECL_SIZE_UNIT (attrs.expr)
  2039. && TREE_CODE (DECL_SIZE_UNIT (attrs.expr)) == INTEGER_CST
  2040. && compare_tree_int (DECL_SIZE_UNIT (attrs.expr), size) >= 0
  2041. && (! attrs.offset_known_p || attrs.offset >= 0))
  2042. break;
  2043. else
  2044. {
  2045. /* The widened memory access overflows the expression, which means
  2046. that it could alias another expression. Zap it. */
  2047. attrs.expr = NULL_TREE;
  2048. break;
  2049. }
  2050. }
  2051. if (! attrs.expr)
  2052. attrs.offset_known_p = false;
  2053. /* The widened memory may alias other stuff, so zap the alias set. */
  2054. /* ??? Maybe use get_alias_set on any remaining expression. */
  2055. attrs.alias = 0;
  2056. attrs.size_known_p = true;
  2057. attrs.size = size;
  2058. set_mem_attrs (new_rtx, &attrs);
  2059. return new_rtx;
  2060. }
  2061. /* A fake decl that is used as the MEM_EXPR of spill slots. */
  2062. static GTY(()) tree spill_slot_decl;
  2063. tree
  2064. get_spill_slot_decl (bool force_build_p)
  2065. {
  2066. tree d = spill_slot_decl;
  2067. rtx rd;
  2068. struct mem_attrs attrs;
  2069. if (d || !force_build_p)
  2070. return d;
  2071. d = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
  2072. VAR_DECL, get_identifier ("%sfp"), void_type_node);
  2073. DECL_ARTIFICIAL (d) = 1;
  2074. DECL_IGNORED_P (d) = 1;
  2075. TREE_USED (d) = 1;
  2076. spill_slot_decl = d;
  2077. rd = gen_rtx_MEM (BLKmode, frame_pointer_rtx);
  2078. MEM_NOTRAP_P (rd) = 1;
  2079. attrs = *mode_mem_attrs[(int) BLKmode];
  2080. attrs.alias = new_alias_set ();
  2081. attrs.expr = d;
  2082. set_mem_attrs (rd, &attrs);
  2083. SET_DECL_RTL (d, rd);
  2084. return d;
  2085. }
  2086. /* Given MEM, a result from assign_stack_local, fill in the memory
  2087. attributes as appropriate for a register allocator spill slot.
  2088. These slots are not aliasable by other memory. We arrange for
  2089. them all to use a single MEM_EXPR, so that the aliasing code can
  2090. work properly in the case of shared spill slots. */
  2091. void
  2092. set_mem_attrs_for_spill (rtx mem)
  2093. {
  2094. struct mem_attrs attrs;
  2095. rtx addr;
  2096. attrs = *get_mem_attrs (mem);
  2097. attrs.expr = get_spill_slot_decl (true);
  2098. attrs.alias = MEM_ALIAS_SET (DECL_RTL (attrs.expr));
  2099. attrs.addrspace = ADDR_SPACE_GENERIC;
  2100. /* We expect the incoming memory to be of the form:
  2101. (mem:MODE (plus (reg sfp) (const_int offset)))
  2102. with perhaps the plus missing for offset = 0. */
  2103. addr = XEXP (mem, 0);
  2104. attrs.offset_known_p = true;
  2105. attrs.offset = 0;
  2106. if (GET_CODE (addr) == PLUS
  2107. && CONST_INT_P (XEXP (addr, 1)))
  2108. attrs.offset = INTVAL (XEXP (addr, 1));
  2109. set_mem_attrs (mem, &attrs);
  2110. MEM_NOTRAP_P (mem) = 1;
  2111. }
  2112. /* Return a newly created CODE_LABEL rtx with a unique label number. */
  2113. rtx_code_label *
  2114. gen_label_rtx (void)
  2115. {
  2116. return as_a <rtx_code_label *> (
  2117. gen_rtx_CODE_LABEL (VOIDmode, NULL_RTX, NULL_RTX,
  2118. NULL, label_num++, NULL));
  2119. }
  2120. /* For procedure integration. */
  2121. /* Install new pointers to the first and last insns in the chain.
  2122. Also, set cur_insn_uid to one higher than the last in use.
  2123. Used for an inline-procedure after copying the insn chain. */
  2124. void
  2125. set_new_first_and_last_insn (rtx_insn *first, rtx_insn *last)
  2126. {
  2127. rtx_insn *insn;
  2128. set_first_insn (first);
  2129. set_last_insn (last);
  2130. cur_insn_uid = 0;
  2131. if (MIN_NONDEBUG_INSN_UID || MAY_HAVE_DEBUG_INSNS)
  2132. {
  2133. int debug_count = 0;
  2134. cur_insn_uid = MIN_NONDEBUG_INSN_UID - 1;
  2135. cur_debug_insn_uid = 0;
  2136. for (insn = first; insn; insn = NEXT_INSN (insn))
  2137. if (INSN_UID (insn) < MIN_NONDEBUG_INSN_UID)
  2138. cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn));
  2139. else
  2140. {
  2141. cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
  2142. if (DEBUG_INSN_P (insn))
  2143. debug_count++;
  2144. }
  2145. if (debug_count)
  2146. cur_debug_insn_uid = MIN_NONDEBUG_INSN_UID + debug_count;
  2147. else
  2148. cur_debug_insn_uid++;
  2149. }
  2150. else
  2151. for (insn = first; insn; insn = NEXT_INSN (insn))
  2152. cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
  2153. cur_insn_uid++;
  2154. }
  2155. /* Go through all the RTL insn bodies and copy any invalid shared
  2156. structure. This routine should only be called once. */
  2157. static void
  2158. unshare_all_rtl_1 (rtx_insn *insn)
  2159. {
  2160. /* Unshare just about everything else. */
  2161. unshare_all_rtl_in_chain (insn);
  2162. /* Make sure the addresses of stack slots found outside the insn chain
  2163. (such as, in DECL_RTL of a variable) are not shared
  2164. with the insn chain.
  2165. This special care is necessary when the stack slot MEM does not
  2166. actually appear in the insn chain. If it does appear, its address
  2167. is unshared from all else at that point. */
  2168. stack_slot_list = safe_as_a <rtx_expr_list *> (
  2169. copy_rtx_if_shared (stack_slot_list));
  2170. }
  2171. /* Go through all the RTL insn bodies and copy any invalid shared
  2172. structure, again. This is a fairly expensive thing to do so it
  2173. should be done sparingly. */
  2174. void
  2175. unshare_all_rtl_again (rtx_insn *insn)
  2176. {
  2177. rtx_insn *p;
  2178. tree decl;
  2179. for (p = insn; p; p = NEXT_INSN (p))
  2180. if (INSN_P (p))
  2181. {
  2182. reset_used_flags (PATTERN (p));
  2183. reset_used_flags (REG_NOTES (p));
  2184. if (CALL_P (p))
  2185. reset_used_flags (CALL_INSN_FUNCTION_USAGE (p));
  2186. }
  2187. /* Make sure that virtual stack slots are not shared. */
  2188. set_used_decls (DECL_INITIAL (cfun->decl));
  2189. /* Make sure that virtual parameters are not shared. */
  2190. for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = DECL_CHAIN (decl))
  2191. set_used_flags (DECL_RTL (decl));
  2192. reset_used_flags (stack_slot_list);
  2193. unshare_all_rtl_1 (insn);
  2194. }
  2195. unsigned int
  2196. unshare_all_rtl (void)
  2197. {
  2198. unshare_all_rtl_1 (get_insns ());
  2199. return 0;
  2200. }
  2201. /* Check that ORIG is not marked when it should not be and mark ORIG as in use,
  2202. Recursively does the same for subexpressions. */
  2203. static void
  2204. verify_rtx_sharing (rtx orig, rtx insn)
  2205. {
  2206. rtx x = orig;
  2207. int i;
  2208. enum rtx_code code;
  2209. const char *format_ptr;
  2210. if (x == 0)
  2211. return;
  2212. code = GET_CODE (x);
  2213. /* These types may be freely shared. */
  2214. switch (code)
  2215. {
  2216. case REG:
  2217. case DEBUG_EXPR:
  2218. case VALUE:
  2219. CASE_CONST_ANY:
  2220. case SYMBOL_REF:
  2221. case LABEL_REF:
  2222. case CODE_LABEL:
  2223. case PC:
  2224. case CC0:
  2225. case RETURN:
  2226. case SIMPLE_RETURN:
  2227. case SCRATCH:
  2228. /* SCRATCH must be shared because they represent distinct values. */
  2229. return;
  2230. case CLOBBER:
  2231. /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
  2232. clobbers or clobbers of hard registers that originated as pseudos.
  2233. This is needed to allow safe register renaming. */
  2234. if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  2235. && ORIGINAL_REGNO (XEXP (x, 0)) == REGNO (XEXP (x, 0)))
  2236. return;
  2237. break;
  2238. case CONST:
  2239. if (shared_const_p (orig))
  2240. return;
  2241. break;
  2242. case MEM:
  2243. /* A MEM is allowed to be shared if its address is constant. */
  2244. if (CONSTANT_ADDRESS_P (XEXP (x, 0))
  2245. || reload_completed || reload_in_progress)
  2246. return;
  2247. break;
  2248. default:
  2249. break;
  2250. }
  2251. /* This rtx may not be shared. If it has already been seen,
  2252. replace it with a copy of itself. */
  2253. #ifdef ENABLE_CHECKING
  2254. if (RTX_FLAG (x, used))
  2255. {
  2256. error ("invalid rtl sharing found in the insn");
  2257. debug_rtx (insn);
  2258. error ("shared rtx");
  2259. debug_rtx (x);
  2260. internal_error ("internal consistency failure");
  2261. }
  2262. #endif
  2263. gcc_assert (!RTX_FLAG (x, used));
  2264. RTX_FLAG (x, used) = 1;
  2265. /* Now scan the subexpressions recursively. */
  2266. format_ptr = GET_RTX_FORMAT (code);
  2267. for (i = 0; i < GET_RTX_LENGTH (code); i++)
  2268. {
  2269. switch (*format_ptr++)
  2270. {
  2271. case 'e':
  2272. verify_rtx_sharing (XEXP (x, i), insn);
  2273. break;
  2274. case 'E':
  2275. if (XVEC (x, i) != NULL)
  2276. {
  2277. int j;
  2278. int len = XVECLEN (x, i);
  2279. for (j = 0; j < len; j++)
  2280. {
  2281. /* We allow sharing of ASM_OPERANDS inside single
  2282. instruction. */
  2283. if (j && GET_CODE (XVECEXP (x, i, j)) == SET
  2284. && (GET_CODE (SET_SRC (XVECEXP (x, i, j)))
  2285. == ASM_OPERANDS))
  2286. verify_rtx_sharing (SET_DEST (XVECEXP (x, i, j)), insn);
  2287. else
  2288. verify_rtx_sharing (XVECEXP (x, i, j), insn);
  2289. }
  2290. }
  2291. break;
  2292. }
  2293. }
  2294. return;
  2295. }
  2296. /* Reset used-flags for INSN. */
  2297. static void
  2298. reset_insn_used_flags (rtx insn)
  2299. {
  2300. gcc_assert (INSN_P (insn));
  2301. reset_used_flags (PATTERN (insn));
  2302. reset_used_flags (REG_NOTES (insn));
  2303. if (CALL_P (insn))
  2304. reset_used_flags (CALL_INSN_FUNCTION_USAGE (insn));
  2305. }
  2306. /* Go through all the RTL insn bodies and clear all the USED bits. */
  2307. static void
  2308. reset_all_used_flags (void)
  2309. {
  2310. rtx_insn *p;
  2311. for (p = get_insns (); p; p = NEXT_INSN (p))
  2312. if (INSN_P (p))
  2313. {
  2314. rtx pat = PATTERN (p);
  2315. if (GET_CODE (pat) != SEQUENCE)
  2316. reset_insn_used_flags (p);
  2317. else
  2318. {
  2319. gcc_assert (REG_NOTES (p) == NULL);
  2320. for (int i = 0; i < XVECLEN (pat, 0); i++)
  2321. {
  2322. rtx insn = XVECEXP (pat, 0, i);
  2323. if (INSN_P (insn))
  2324. reset_insn_used_flags (insn);
  2325. }
  2326. }
  2327. }
  2328. }
  2329. /* Verify sharing in INSN. */
  2330. static void
  2331. verify_insn_sharing (rtx insn)
  2332. {
  2333. gcc_assert (INSN_P (insn));
  2334. reset_used_flags (PATTERN (insn));
  2335. reset_used_flags (REG_NOTES (insn));
  2336. if (CALL_P (insn))
  2337. reset_used_flags (CALL_INSN_FUNCTION_USAGE (insn));
  2338. }
  2339. /* Go through all the RTL insn bodies and check that there is no unexpected
  2340. sharing in between the subexpressions. */
  2341. DEBUG_FUNCTION void
  2342. verify_rtl_sharing (void)
  2343. {
  2344. rtx_insn *p;
  2345. timevar_push (TV_VERIFY_RTL_SHARING);
  2346. reset_all_used_flags ();
  2347. for (p = get_insns (); p; p = NEXT_INSN (p))
  2348. if (INSN_P (p))
  2349. {
  2350. rtx pat = PATTERN (p);
  2351. if (GET_CODE (pat) != SEQUENCE)
  2352. verify_insn_sharing (p);
  2353. else
  2354. for (int i = 0; i < XVECLEN (pat, 0); i++)
  2355. {
  2356. rtx insn = XVECEXP (pat, 0, i);
  2357. if (INSN_P (insn))
  2358. verify_insn_sharing (insn);
  2359. }
  2360. }
  2361. reset_all_used_flags ();
  2362. timevar_pop (TV_VERIFY_RTL_SHARING);
  2363. }
  2364. /* Go through all the RTL insn bodies and copy any invalid shared structure.
  2365. Assumes the mark bits are cleared at entry. */
  2366. void
  2367. unshare_all_rtl_in_chain (rtx_insn *insn)
  2368. {
  2369. for (; insn; insn = NEXT_INSN (insn))
  2370. if (INSN_P (insn))
  2371. {
  2372. PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
  2373. REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
  2374. if (CALL_P (insn))
  2375. CALL_INSN_FUNCTION_USAGE (insn)
  2376. = copy_rtx_if_shared (CALL_INSN_FUNCTION_USAGE (insn));
  2377. }
  2378. }
  2379. /* Go through all virtual stack slots of a function and mark them as
  2380. shared. We never replace the DECL_RTLs themselves with a copy,
  2381. but expressions mentioned into a DECL_RTL cannot be shared with
  2382. expressions in the instruction stream.
  2383. Note that reload may convert pseudo registers into memories in-place.
  2384. Pseudo registers are always shared, but MEMs never are. Thus if we
  2385. reset the used flags on MEMs in the instruction stream, we must set
  2386. them again on MEMs that appear in DECL_RTLs. */
  2387. static void
  2388. set_used_decls (tree blk)
  2389. {
  2390. tree t;
  2391. /* Mark decls. */
  2392. for (t = BLOCK_VARS (blk); t; t = DECL_CHAIN (t))
  2393. if (DECL_RTL_SET_P (t))
  2394. set_used_flags (DECL_RTL (t));
  2395. /* Now process sub-blocks. */
  2396. for (t = BLOCK_SUBBLOCKS (blk); t; t = BLOCK_CHAIN (t))
  2397. set_used_decls (t);
  2398. }
  2399. /* Mark ORIG as in use, and return a copy of it if it was already in use.
  2400. Recursively does the same for subexpressions. Uses
  2401. copy_rtx_if_shared_1 to reduce stack space. */
  2402. rtx
  2403. copy_rtx_if_shared (rtx orig)
  2404. {
  2405. copy_rtx_if_shared_1 (&orig);
  2406. return orig;
  2407. }
  2408. /* Mark *ORIG1 as in use, and set it to a copy of it if it was already in
  2409. use. Recursively does the same for subexpressions. */
  2410. static void
  2411. copy_rtx_if_shared_1 (rtx *orig1)
  2412. {
  2413. rtx x;
  2414. int i;
  2415. enum rtx_code code;
  2416. rtx *last_ptr;
  2417. const char *format_ptr;
  2418. int copied = 0;
  2419. int length;
  2420. /* Repeat is used to turn tail-recursion into iteration. */
  2421. repeat:
  2422. x = *orig1;
  2423. if (x == 0)
  2424. return;
  2425. code = GET_CODE (x);
  2426. /* These types may be freely shared. */
  2427. switch (code)
  2428. {
  2429. case REG:
  2430. case DEBUG_EXPR:
  2431. case VALUE:
  2432. CASE_CONST_ANY:
  2433. case SYMBOL_REF:
  2434. case LABEL_REF:
  2435. case CODE_LABEL:
  2436. case PC:
  2437. case CC0:
  2438. case RETURN:
  2439. case SIMPLE_RETURN:
  2440. case SCRATCH:
  2441. /* SCRATCH must be shared because they represent distinct values. */
  2442. return;
  2443. case CLOBBER:
  2444. /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
  2445. clobbers or clobbers of hard registers that originated as pseudos.
  2446. This is needed to allow safe register renaming. */
  2447. if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  2448. && ORIGINAL_REGNO (XEXP (x, 0)) == REGNO (XEXP (x, 0)))
  2449. return;
  2450. break;
  2451. case CONST:
  2452. if (shared_const_p (x))
  2453. return;
  2454. break;
  2455. case DEBUG_INSN:
  2456. case INSN:
  2457. case JUMP_INSN:
  2458. case CALL_INSN:
  2459. case NOTE:
  2460. case BARRIER:
  2461. /* The chain of insns is not being copied. */
  2462. return;
  2463. default:
  2464. break;
  2465. }
  2466. /* This rtx may not be shared. If it has already been seen,
  2467. replace it with a copy of itself. */
  2468. if (RTX_FLAG (x, used))
  2469. {
  2470. x = shallow_copy_rtx (x);
  2471. copied = 1;
  2472. }
  2473. RTX_FLAG (x, used) = 1;
  2474. /* Now scan the subexpressions recursively.
  2475. We can store any replaced subexpressions directly into X
  2476. since we know X is not shared! Any vectors in X
  2477. must be copied if X was copied. */
  2478. format_ptr = GET_RTX_FORMAT (code);
  2479. length = GET_RTX_LENGTH (code);
  2480. last_ptr = NULL;
  2481. for (i = 0; i < length; i++)
  2482. {
  2483. switch (*format_ptr++)
  2484. {
  2485. case 'e':
  2486. if (last_ptr)
  2487. copy_rtx_if_shared_1 (last_ptr);
  2488. last_ptr = &XEXP (x, i);
  2489. break;
  2490. case 'E':
  2491. if (XVEC (x, i) != NULL)
  2492. {
  2493. int j;
  2494. int len = XVECLEN (x, i);
  2495. /* Copy the vector iff I copied the rtx and the length
  2496. is nonzero. */
  2497. if (copied && len > 0)
  2498. XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
  2499. /* Call recursively on all inside the vector. */
  2500. for (j = 0; j < len; j++)
  2501. {
  2502. if (last_ptr)
  2503. copy_rtx_if_shared_1 (last_ptr);
  2504. last_ptr = &XVECEXP (x, i, j);
  2505. }
  2506. }
  2507. break;
  2508. }
  2509. }
  2510. *orig1 = x;
  2511. if (last_ptr)
  2512. {
  2513. orig1 = last_ptr;
  2514. goto repeat;
  2515. }
  2516. return;
  2517. }
  2518. /* Set the USED bit in X and its non-shareable subparts to FLAG. */
  2519. static void
  2520. mark_used_flags (rtx x, int flag)
  2521. {
  2522. int i, j;
  2523. enum rtx_code code;
  2524. const char *format_ptr;
  2525. int length;
  2526. /* Repeat is used to turn tail-recursion into iteration. */
  2527. repeat:
  2528. if (x == 0)
  2529. return;
  2530. code = GET_CODE (x);
  2531. /* These types may be freely shared so we needn't do any resetting
  2532. for them. */
  2533. switch (code)
  2534. {
  2535. case REG:
  2536. case DEBUG_EXPR:
  2537. case VALUE:
  2538. CASE_CONST_ANY:
  2539. case SYMBOL_REF:
  2540. case CODE_LABEL:
  2541. case PC:
  2542. case CC0:
  2543. case RETURN:
  2544. case SIMPLE_RETURN:
  2545. return;
  2546. case DEBUG_INSN:
  2547. case INSN:
  2548. case JUMP_INSN:
  2549. case CALL_INSN:
  2550. case NOTE:
  2551. case LABEL_REF:
  2552. case BARRIER:
  2553. /* The chain of insns is not being copied. */
  2554. return;
  2555. default:
  2556. break;
  2557. }
  2558. RTX_FLAG (x, used) = flag;
  2559. format_ptr = GET_RTX_FORMAT (code);
  2560. length = GET_RTX_LENGTH (code);
  2561. for (i = 0; i < length; i++)
  2562. {
  2563. switch (*format_ptr++)
  2564. {
  2565. case 'e':
  2566. if (i == length-1)
  2567. {
  2568. x = XEXP (x, i);
  2569. goto repeat;
  2570. }
  2571. mark_used_flags (XEXP (x, i), flag);
  2572. break;
  2573. case 'E':
  2574. for (j = 0; j < XVECLEN (x, i); j++)
  2575. mark_used_flags (XVECEXP (x, i, j), flag);
  2576. break;
  2577. }
  2578. }
  2579. }
  2580. /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
  2581. to look for shared sub-parts. */
  2582. void
  2583. reset_used_flags (rtx x)
  2584. {
  2585. mark_used_flags (x, 0);
  2586. }
  2587. /* Set all the USED bits in X to allow copy_rtx_if_shared to be used
  2588. to look for shared sub-parts. */
  2589. void
  2590. set_used_flags (rtx x)
  2591. {
  2592. mark_used_flags (x, 1);
  2593. }
  2594. /* Copy X if necessary so that it won't be altered by changes in OTHER.
  2595. Return X or the rtx for the pseudo reg the value of X was copied into.
  2596. OTHER must be valid as a SET_DEST. */
  2597. rtx
  2598. make_safe_from (rtx x, rtx other)
  2599. {
  2600. while (1)
  2601. switch (GET_CODE (other))
  2602. {
  2603. case SUBREG:
  2604. other = SUBREG_REG (other);
  2605. break;
  2606. case STRICT_LOW_PART:
  2607. case SIGN_EXTEND:
  2608. case ZERO_EXTEND:
  2609. other = XEXP (other, 0);
  2610. break;
  2611. default:
  2612. goto done;
  2613. }
  2614. done:
  2615. if ((MEM_P (other)
  2616. && ! CONSTANT_P (x)
  2617. && !REG_P (x)
  2618. && GET_CODE (x) != SUBREG)
  2619. || (REG_P (other)
  2620. && (REGNO (other) < FIRST_PSEUDO_REGISTER
  2621. || reg_mentioned_p (other, x))))
  2622. {
  2623. rtx temp = gen_reg_rtx (GET_MODE (x));
  2624. emit_move_insn (temp, x);
  2625. return temp;
  2626. }
  2627. return x;
  2628. }
  2629. /* Emission of insns (adding them to the doubly-linked list). */
  2630. /* Return the last insn emitted, even if it is in a sequence now pushed. */
  2631. rtx_insn *
  2632. get_last_insn_anywhere (void)
  2633. {
  2634. struct sequence_stack *stack;
  2635. if (get_last_insn ())
  2636. return get_last_insn ();
  2637. for (stack = seq_stack; stack; stack = stack->next)
  2638. if (stack->last != 0)
  2639. return stack->last;
  2640. return 0;
  2641. }
  2642. /* Return the first nonnote insn emitted in current sequence or current
  2643. function. This routine looks inside SEQUENCEs. */
  2644. rtx_insn *
  2645. get_first_nonnote_insn (void)
  2646. {
  2647. rtx_insn *insn = get_insns ();
  2648. if (insn)
  2649. {
  2650. if (NOTE_P (insn))
  2651. for (insn = next_insn (insn);
  2652. insn && NOTE_P (insn);
  2653. insn = next_insn (insn))
  2654. continue;
  2655. else
  2656. {
  2657. if (NONJUMP_INSN_P (insn)
  2658. && GET_CODE (PATTERN (insn)) == SEQUENCE)
  2659. insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0);
  2660. }
  2661. }
  2662. return insn;
  2663. }
  2664. /* Return the last nonnote insn emitted in current sequence or current
  2665. function. This routine looks inside SEQUENCEs. */
  2666. rtx_insn *
  2667. get_last_nonnote_insn (void)
  2668. {
  2669. rtx_insn *insn = get_last_insn ();
  2670. if (insn)
  2671. {
  2672. if (NOTE_P (insn))
  2673. for (insn = previous_insn (insn);
  2674. insn && NOTE_P (insn);
  2675. insn = previous_insn (insn))
  2676. continue;
  2677. else
  2678. {
  2679. if (NONJUMP_INSN_P (insn))
  2680. if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
  2681. insn = seq->insn (seq->len () - 1);
  2682. }
  2683. }
  2684. return insn;
  2685. }
  2686. /* Return the number of actual (non-debug) insns emitted in this
  2687. function. */
  2688. int
  2689. get_max_insn_count (void)
  2690. {
  2691. int n = cur_insn_uid;
  2692. /* The table size must be stable across -g, to avoid codegen
  2693. differences due to debug insns, and not be affected by
  2694. -fmin-insn-uid, to avoid excessive table size and to simplify
  2695. debugging of -fcompare-debug failures. */
  2696. if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID)
  2697. n -= cur_debug_insn_uid;
  2698. else
  2699. n -= MIN_NONDEBUG_INSN_UID;
  2700. return n;
  2701. }
  2702. /* Return the next insn. If it is a SEQUENCE, return the first insn
  2703. of the sequence. */
  2704. rtx_insn *
  2705. next_insn (rtx_insn *insn)
  2706. {
  2707. if (insn)
  2708. {
  2709. insn = NEXT_INSN (insn);
  2710. if (insn && NONJUMP_INSN_P (insn)
  2711. && GET_CODE (PATTERN (insn)) == SEQUENCE)
  2712. insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0);
  2713. }
  2714. return insn;
  2715. }
  2716. /* Return the previous insn. If it is a SEQUENCE, return the last insn
  2717. of the sequence. */
  2718. rtx_insn *
  2719. previous_insn (rtx_insn *insn)
  2720. {
  2721. if (insn)
  2722. {
  2723. insn = PREV_INSN (insn);
  2724. if (insn && NONJUMP_INSN_P (insn))
  2725. if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
  2726. insn = seq->insn (seq->len () - 1);
  2727. }
  2728. return insn;
  2729. }
  2730. /* Return the next insn after INSN that is not a NOTE. This routine does not
  2731. look inside SEQUENCEs. */
  2732. rtx_insn *
  2733. next_nonnote_insn (rtx uncast_insn)
  2734. {
  2735. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2736. while (insn)
  2737. {
  2738. insn = NEXT_INSN (insn);
  2739. if (insn == 0 || !NOTE_P (insn))
  2740. break;
  2741. }
  2742. return insn;
  2743. }
  2744. /* Return the next insn after INSN that is not a NOTE, but stop the
  2745. search before we enter another basic block. This routine does not
  2746. look inside SEQUENCEs. */
  2747. rtx_insn *
  2748. next_nonnote_insn_bb (rtx_insn *insn)
  2749. {
  2750. while (insn)
  2751. {
  2752. insn = NEXT_INSN (insn);
  2753. if (insn == 0 || !NOTE_P (insn))
  2754. break;
  2755. if (NOTE_INSN_BASIC_BLOCK_P (insn))
  2756. return NULL;
  2757. }
  2758. return insn;
  2759. }
  2760. /* Return the previous insn before INSN that is not a NOTE. This routine does
  2761. not look inside SEQUENCEs. */
  2762. rtx_insn *
  2763. prev_nonnote_insn (rtx uncast_insn)
  2764. {
  2765. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2766. while (insn)
  2767. {
  2768. insn = PREV_INSN (insn);
  2769. if (insn == 0 || !NOTE_P (insn))
  2770. break;
  2771. }
  2772. return insn;
  2773. }
  2774. /* Return the previous insn before INSN that is not a NOTE, but stop
  2775. the search before we enter another basic block. This routine does
  2776. not look inside SEQUENCEs. */
  2777. rtx_insn *
  2778. prev_nonnote_insn_bb (rtx uncast_insn)
  2779. {
  2780. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2781. while (insn)
  2782. {
  2783. insn = PREV_INSN (insn);
  2784. if (insn == 0 || !NOTE_P (insn))
  2785. break;
  2786. if (NOTE_INSN_BASIC_BLOCK_P (insn))
  2787. return NULL;
  2788. }
  2789. return insn;
  2790. }
  2791. /* Return the next insn after INSN that is not a DEBUG_INSN. This
  2792. routine does not look inside SEQUENCEs. */
  2793. rtx_insn *
  2794. next_nondebug_insn (rtx uncast_insn)
  2795. {
  2796. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2797. while (insn)
  2798. {
  2799. insn = NEXT_INSN (insn);
  2800. if (insn == 0 || !DEBUG_INSN_P (insn))
  2801. break;
  2802. }
  2803. return insn;
  2804. }
  2805. /* Return the previous insn before INSN that is not a DEBUG_INSN.
  2806. This routine does not look inside SEQUENCEs. */
  2807. rtx_insn *
  2808. prev_nondebug_insn (rtx uncast_insn)
  2809. {
  2810. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2811. while (insn)
  2812. {
  2813. insn = PREV_INSN (insn);
  2814. if (insn == 0 || !DEBUG_INSN_P (insn))
  2815. break;
  2816. }
  2817. return insn;
  2818. }
  2819. /* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
  2820. This routine does not look inside SEQUENCEs. */
  2821. rtx_insn *
  2822. next_nonnote_nondebug_insn (rtx uncast_insn)
  2823. {
  2824. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2825. while (insn)
  2826. {
  2827. insn = NEXT_INSN (insn);
  2828. if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
  2829. break;
  2830. }
  2831. return insn;
  2832. }
  2833. /* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
  2834. This routine does not look inside SEQUENCEs. */
  2835. rtx_insn *
  2836. prev_nonnote_nondebug_insn (rtx uncast_insn)
  2837. {
  2838. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2839. while (insn)
  2840. {
  2841. insn = PREV_INSN (insn);
  2842. if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
  2843. break;
  2844. }
  2845. return insn;
  2846. }
  2847. /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
  2848. or 0, if there is none. This routine does not look inside
  2849. SEQUENCEs. */
  2850. rtx_insn *
  2851. next_real_insn (rtx uncast_insn)
  2852. {
  2853. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2854. while (insn)
  2855. {
  2856. insn = NEXT_INSN (insn);
  2857. if (insn == 0 || INSN_P (insn))
  2858. break;
  2859. }
  2860. return insn;
  2861. }
  2862. /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
  2863. or 0, if there is none. This routine does not look inside
  2864. SEQUENCEs. */
  2865. rtx_insn *
  2866. prev_real_insn (rtx uncast_insn)
  2867. {
  2868. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2869. while (insn)
  2870. {
  2871. insn = PREV_INSN (insn);
  2872. if (insn == 0 || INSN_P (insn))
  2873. break;
  2874. }
  2875. return insn;
  2876. }
  2877. /* Return the last CALL_INSN in the current list, or 0 if there is none.
  2878. This routine does not look inside SEQUENCEs. */
  2879. rtx_call_insn *
  2880. last_call_insn (void)
  2881. {
  2882. rtx_insn *insn;
  2883. for (insn = get_last_insn ();
  2884. insn && !CALL_P (insn);
  2885. insn = PREV_INSN (insn))
  2886. ;
  2887. return safe_as_a <rtx_call_insn *> (insn);
  2888. }
  2889. /* Find the next insn after INSN that really does something. This routine
  2890. does not look inside SEQUENCEs. After reload this also skips over
  2891. standalone USE and CLOBBER insn. */
  2892. int
  2893. active_insn_p (const_rtx insn)
  2894. {
  2895. return (CALL_P (insn) || JUMP_P (insn)
  2896. || JUMP_TABLE_DATA_P (insn) /* FIXME */
  2897. || (NONJUMP_INSN_P (insn)
  2898. && (! reload_completed
  2899. || (GET_CODE (PATTERN (insn)) != USE
  2900. && GET_CODE (PATTERN (insn)) != CLOBBER))));
  2901. }
  2902. rtx_insn *
  2903. next_active_insn (rtx uncast_insn)
  2904. {
  2905. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2906. while (insn)
  2907. {
  2908. insn = NEXT_INSN (insn);
  2909. if (insn == 0 || active_insn_p (insn))
  2910. break;
  2911. }
  2912. return insn;
  2913. }
  2914. /* Find the last insn before INSN that really does something. This routine
  2915. does not look inside SEQUENCEs. After reload this also skips over
  2916. standalone USE and CLOBBER insn. */
  2917. rtx_insn *
  2918. prev_active_insn (rtx uncast_insn)
  2919. {
  2920. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2921. while (insn)
  2922. {
  2923. insn = PREV_INSN (insn);
  2924. if (insn == 0 || active_insn_p (insn))
  2925. break;
  2926. }
  2927. return insn;
  2928. }
  2929. #ifdef HAVE_cc0
  2930. /* Return the next insn that uses CC0 after INSN, which is assumed to
  2931. set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
  2932. applied to the result of this function should yield INSN).
  2933. Normally, this is simply the next insn. However, if a REG_CC_USER note
  2934. is present, it contains the insn that uses CC0.
  2935. Return 0 if we can't find the insn. */
  2936. rtx_insn *
  2937. next_cc0_user (rtx uncast_insn)
  2938. {
  2939. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2940. rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
  2941. if (note)
  2942. return safe_as_a <rtx_insn *> (XEXP (note, 0));
  2943. insn = next_nonnote_insn (insn);
  2944. if (insn && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
  2945. insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0);
  2946. if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
  2947. return insn;
  2948. return 0;
  2949. }
  2950. /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
  2951. note, it is the previous insn. */
  2952. rtx_insn *
  2953. prev_cc0_setter (rtx uncast_insn)
  2954. {
  2955. rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
  2956. rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
  2957. if (note)
  2958. return safe_as_a <rtx_insn *> (XEXP (note, 0));
  2959. insn = prev_nonnote_insn (insn);
  2960. gcc_assert (sets_cc0_p (PATTERN (insn)));
  2961. return insn;
  2962. }
  2963. #endif
  2964. #ifdef AUTO_INC_DEC
  2965. /* Find a RTX_AUTOINC class rtx which matches DATA. */
  2966. static int
  2967. find_auto_inc (const_rtx x, const_rtx reg)
  2968. {
  2969. subrtx_iterator::array_type array;
  2970. FOR_EACH_SUBRTX (iter, array, x, NONCONST)
  2971. {
  2972. const_rtx x = *iter;
  2973. if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC
  2974. && rtx_equal_p (reg, XEXP (x, 0)))
  2975. return true;
  2976. }
  2977. return false;
  2978. }
  2979. #endif
  2980. /* Increment the label uses for all labels present in rtx. */
  2981. static void
  2982. mark_label_nuses (rtx x)
  2983. {
  2984. enum rtx_code code;
  2985. int i, j;
  2986. const char *fmt;
  2987. code = GET_CODE (x);
  2988. if (code == LABEL_REF && LABEL_P (LABEL_REF_LABEL (x)))
  2989. LABEL_NUSES (LABEL_REF_LABEL (x))++;
  2990. fmt = GET_RTX_FORMAT (code);
  2991. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2992. {
  2993. if (fmt[i] == 'e')
  2994. mark_label_nuses (XEXP (x, i));
  2995. else if (fmt[i] == 'E')
  2996. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2997. mark_label_nuses (XVECEXP (x, i, j));
  2998. }
  2999. }
  3000. /* Try splitting insns that can be split for better scheduling.
  3001. PAT is the pattern which might split.
  3002. TRIAL is the insn providing PAT.
  3003. LAST is nonzero if we should return the last insn of the sequence produced.
  3004. If this routine succeeds in splitting, it returns the first or last
  3005. replacement insn depending on the value of LAST. Otherwise, it
  3006. returns TRIAL. If the insn to be returned can be split, it will be. */
  3007. rtx_insn *
  3008. try_split (rtx pat, rtx uncast_trial, int last)
  3009. {
  3010. rtx_insn *trial = as_a <rtx_insn *> (uncast_trial);
  3011. rtx_insn *before = PREV_INSN (trial);
  3012. rtx_insn *after = NEXT_INSN (trial);
  3013. rtx note;
  3014. rtx_insn *seq, *tem;
  3015. int probability;
  3016. rtx_insn *insn_last, *insn;
  3017. int njumps = 0;
  3018. rtx call_insn = NULL_RTX;
  3019. /* We're not good at redistributing frame information. */
  3020. if (RTX_FRAME_RELATED_P (trial))
  3021. return trial;
  3022. if (any_condjump_p (trial)
  3023. && (note = find_reg_note (trial, REG_BR_PROB, 0)))
  3024. split_branch_probability = XINT (note, 0);
  3025. probability = split_branch_probability;
  3026. seq = safe_as_a <rtx_insn *> (split_insns (pat, trial));
  3027. split_branch_probability = -1;
  3028. if (!seq)
  3029. return trial;
  3030. /* Avoid infinite loop if any insn of the result matches
  3031. the original pattern. */
  3032. insn_last = seq;
  3033. while (1)
  3034. {
  3035. if (INSN_P (insn_last)
  3036. && rtx_equal_p (PATTERN (insn_last), pat))
  3037. return trial;
  3038. if (!NEXT_INSN (insn_last))
  3039. break;
  3040. insn_last = NEXT_INSN (insn_last);
  3041. }
  3042. /* We will be adding the new sequence to the function. The splitters
  3043. may have introduced invalid RTL sharing, so unshare the sequence now. */
  3044. unshare_all_rtl_in_chain (seq);
  3045. /* Mark labels and copy flags. */
  3046. for (insn = insn_last; insn ; insn = PREV_INSN (insn))
  3047. {
  3048. if (JUMP_P (insn))
  3049. {
  3050. if (JUMP_P (trial))
  3051. CROSSING_JUMP_P (insn) = CROSSING_JUMP_P (trial);
  3052. mark_jump_label (PATTERN (insn), insn, 0);
  3053. njumps++;
  3054. if (probability != -1
  3055. && any_condjump_p (insn)
  3056. && !find_reg_note (insn, REG_BR_PROB, 0))
  3057. {
  3058. /* We can preserve the REG_BR_PROB notes only if exactly
  3059. one jump is created, otherwise the machine description
  3060. is responsible for this step using
  3061. split_branch_probability variable. */
  3062. gcc_assert (njumps == 1);
  3063. add_int_reg_note (insn, REG_BR_PROB, probability);
  3064. }
  3065. }
  3066. }
  3067. /* If we are splitting a CALL_INSN, look for the CALL_INSN
  3068. in SEQ and copy any additional information across. */
  3069. if (CALL_P (trial))
  3070. {
  3071. for (insn = insn_last; insn ; insn = PREV_INSN (insn))
  3072. if (CALL_P (insn))
  3073. {
  3074. rtx_insn *next;
  3075. rtx *p;
  3076. gcc_assert (call_insn == NULL_RTX);
  3077. call_insn = insn;
  3078. /* Add the old CALL_INSN_FUNCTION_USAGE to whatever the
  3079. target may have explicitly specified. */
  3080. p = &CALL_INSN_FUNCTION_USAGE (insn);
  3081. while (*p)
  3082. p = &XEXP (*p, 1);
  3083. *p = CALL_INSN_FUNCTION_USAGE (trial);
  3084. /* If the old call was a sibling call, the new one must
  3085. be too. */
  3086. SIBLING_CALL_P (insn) = SIBLING_CALL_P (trial);
  3087. /* If the new call is the last instruction in the sequence,
  3088. it will effectively replace the old call in-situ. Otherwise
  3089. we must move any following NOTE_INSN_CALL_ARG_LOCATION note
  3090. so that it comes immediately after the new call. */
  3091. if (NEXT_INSN (insn))
  3092. for (next = NEXT_INSN (trial);
  3093. next && NOTE_P (next);
  3094. next = NEXT_INSN (next))
  3095. if (NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION)
  3096. {
  3097. remove_insn (next);
  3098. add_insn_after (next, insn, NULL);
  3099. break;
  3100. }
  3101. }
  3102. }
  3103. /* Copy notes, particularly those related to the CFG. */
  3104. for (note = REG_NOTES (trial); note; note = XEXP (note, 1))
  3105. {
  3106. switch (REG_NOTE_KIND (note))
  3107. {
  3108. case REG_EH_REGION:
  3109. copy_reg_eh_region_note_backward (note, insn_last, NULL);
  3110. break;
  3111. case REG_NORETURN:
  3112. case REG_SETJMP:
  3113. case REG_TM:
  3114. for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
  3115. {
  3116. if (CALL_P (insn))
  3117. add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
  3118. }
  3119. break;
  3120. case REG_NON_LOCAL_GOTO:
  3121. for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
  3122. {
  3123. if (JUMP_P (insn))
  3124. add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
  3125. }
  3126. break;
  3127. #ifdef AUTO_INC_DEC
  3128. case REG_INC:
  3129. for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
  3130. {
  3131. rtx reg = XEXP (note, 0);
  3132. if (!FIND_REG_INC_NOTE (insn, reg)
  3133. && find_auto_inc (PATTERN (insn), reg))
  3134. add_reg_note (insn, REG_INC, reg);
  3135. }
  3136. break;
  3137. #endif
  3138. case REG_ARGS_SIZE:
  3139. fixup_args_size_notes (NULL, insn_last, INTVAL (XEXP (note, 0)));
  3140. break;
  3141. case REG_CALL_DECL:
  3142. gcc_assert (call_insn != NULL_RTX);
  3143. add_reg_note (call_insn, REG_NOTE_KIND (note), XEXP (note, 0));
  3144. break;
  3145. default:
  3146. break;
  3147. }
  3148. }
  3149. /* If there are LABELS inside the split insns increment the
  3150. usage count so we don't delete the label. */
  3151. if (INSN_P (trial))
  3152. {
  3153. insn = insn_last;
  3154. while (insn != NULL_RTX)
  3155. {
  3156. /* JUMP_P insns have already been "marked" above. */
  3157. if (NONJUMP_INSN_P (insn))
  3158. mark_label_nuses (PATTERN (insn));
  3159. insn = PREV_INSN (insn);
  3160. }
  3161. }
  3162. tem = emit_insn_after_setloc (seq, trial, INSN_LOCATION (trial));
  3163. delete_insn (trial);
  3164. /* Recursively call try_split for each new insn created; by the
  3165. time control returns here that insn will be fully split, so
  3166. set LAST and continue from the insn after the one returned.
  3167. We can't use next_active_insn here since AFTER may be a note.
  3168. Ignore deleted insns, which can be occur if not optimizing. */
  3169. for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
  3170. if (! tem->deleted () && INSN_P (tem))
  3171. tem = try_split (PATTERN (tem), tem, 1);
  3172. /* Return either the first or the last insn, depending on which was
  3173. requested. */
  3174. return last
  3175. ? (after ? PREV_INSN (after) : get_last_insn ())
  3176. : NEXT_INSN (before);
  3177. }
  3178. /* Make and return an INSN rtx, initializing all its slots.
  3179. Store PATTERN in the pattern slots. */
  3180. rtx_insn *
  3181. make_insn_raw (rtx pattern)
  3182. {
  3183. rtx_insn *insn;
  3184. insn = as_a <rtx_insn *> (rtx_alloc (INSN));
  3185. INSN_UID (insn) = cur_insn_uid++;
  3186. PATTERN (insn) = pattern;
  3187. INSN_CODE (insn) = -1;
  3188. REG_NOTES (insn) = NULL;
  3189. INSN_LOCATION (insn) = curr_insn_location ();
  3190. BLOCK_FOR_INSN (insn) = NULL;
  3191. #ifdef ENABLE_RTL_CHECKING
  3192. if (insn
  3193. && INSN_P (insn)
  3194. && (returnjump_p (insn)
  3195. || (GET_CODE (insn) == SET
  3196. && SET_DEST (insn) == pc_rtx)))
  3197. {
  3198. warning (0, "ICE: emit_insn used where emit_jump_insn needed:\n");
  3199. debug_rtx (insn);
  3200. }
  3201. #endif
  3202. return insn;
  3203. }
  3204. /* Like `make_insn_raw' but make a DEBUG_INSN instead of an insn. */
  3205. static rtx_insn *
  3206. make_debug_insn_raw (rtx pattern)
  3207. {
  3208. rtx_debug_insn *insn;
  3209. insn = as_a <rtx_debug_insn *> (rtx_alloc (DEBUG_INSN));
  3210. INSN_UID (insn) = cur_debug_insn_uid++;
  3211. if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID)
  3212. INSN_UID (insn) = cur_insn_uid++;
  3213. PATTERN (insn) = pattern;
  3214. INSN_CODE (insn) = -1;
  3215. REG_NOTES (insn) = NULL;
  3216. INSN_LOCATION (insn) = curr_insn_location ();
  3217. BLOCK_FOR_INSN (insn) = NULL;
  3218. return insn;
  3219. }
  3220. /* Like `make_insn_raw' but make a JUMP_INSN instead of an insn. */
  3221. static rtx_insn *
  3222. make_jump_insn_raw (rtx pattern)
  3223. {
  3224. rtx_jump_insn *insn;
  3225. insn = as_a <rtx_jump_insn *> (rtx_alloc (JUMP_INSN));
  3226. INSN_UID (insn) = cur_insn_uid++;
  3227. PATTERN (insn) = pattern;
  3228. INSN_CODE (insn) = -1;
  3229. REG_NOTES (insn) = NULL;
  3230. JUMP_LABEL (insn) = NULL;
  3231. INSN_LOCATION (insn) = curr_insn_location ();
  3232. BLOCK_FOR_INSN (insn) = NULL;
  3233. return insn;
  3234. }
  3235. /* Like `make_insn_raw' but make a CALL_INSN instead of an insn. */
  3236. static rtx_insn *
  3237. make_call_insn_raw (rtx pattern)
  3238. {
  3239. rtx_call_insn *insn;
  3240. insn = as_a <rtx_call_insn *> (rtx_alloc (CALL_INSN));
  3241. INSN_UID (insn) = cur_insn_uid++;
  3242. PATTERN (insn) = pattern;
  3243. INSN_CODE (insn) = -1;
  3244. REG_NOTES (insn) = NULL;
  3245. CALL_INSN_FUNCTION_USAGE (insn) = NULL;
  3246. INSN_LOCATION (insn) = curr_insn_location ();
  3247. BLOCK_FOR_INSN (insn) = NULL;
  3248. return insn;
  3249. }
  3250. /* Like `make_insn_raw' but make a NOTE instead of an insn. */
  3251. static rtx_note *
  3252. make_note_raw (enum insn_note subtype)
  3253. {
  3254. /* Some notes are never created this way at all. These notes are
  3255. only created by patching out insns. */
  3256. gcc_assert (subtype != NOTE_INSN_DELETED_LABEL
  3257. && subtype != NOTE_INSN_DELETED_DEBUG_LABEL);
  3258. rtx_note *note = as_a <rtx_note *> (rtx_alloc (NOTE));
  3259. INSN_UID (note) = cur_insn_uid++;
  3260. NOTE_KIND (note) = subtype;
  3261. BLOCK_FOR_INSN (note) = NULL;
  3262. memset (&NOTE_DATA (note), 0, sizeof (NOTE_DATA (note)));
  3263. return note;
  3264. }
  3265. /* Add INSN to the end of the doubly-linked list, between PREV and NEXT.
  3266. INSN may be any object that can appear in the chain: INSN_P and NOTE_P objects,
  3267. but also BARRIERs and JUMP_TABLE_DATAs. PREV and NEXT may be NULL. */
  3268. static inline void
  3269. link_insn_into_chain (rtx_insn *insn, rtx_insn *prev, rtx_insn *next)
  3270. {
  3271. SET_PREV_INSN (insn) = prev;
  3272. SET_NEXT_INSN (insn) = next;
  3273. if (prev != NULL)
  3274. {
  3275. SET_NEXT_INSN (prev) = insn;
  3276. if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
  3277. {
  3278. rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev));
  3279. SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = insn;
  3280. }
  3281. }
  3282. if (next != NULL)
  3283. {
  3284. SET_PREV_INSN (next) = insn;
  3285. if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
  3286. {
  3287. rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next));
  3288. SET_PREV_INSN (sequence->insn (0)) = insn;
  3289. }
  3290. }
  3291. if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
  3292. {
  3293. rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (insn));
  3294. SET_PREV_INSN (sequence->insn (0)) = prev;
  3295. SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next;
  3296. }
  3297. }
  3298. /* Add INSN to the end of the doubly-linked list.
  3299. INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
  3300. void
  3301. add_insn (rtx_insn *insn)
  3302. {
  3303. rtx_insn *prev = get_last_insn ();
  3304. link_insn_into_chain (insn, prev, NULL);
  3305. if (NULL == get_insns ())
  3306. set_first_insn (insn);
  3307. set_last_insn (insn);
  3308. }
  3309. /* Add INSN into the doubly-linked list after insn AFTER. */
  3310. static void
  3311. add_insn_after_nobb (rtx_insn *insn, rtx_insn *after)
  3312. {
  3313. rtx_insn *next = NEXT_INSN (after);
  3314. gcc_assert (!optimize || !after->deleted ());
  3315. link_insn_into_chain (insn, after, next);
  3316. if (next == NULL)
  3317. {
  3318. if (get_last_insn () == after)
  3319. set_last_insn (insn);
  3320. else
  3321. {
  3322. struct sequence_stack *stack = seq_stack;
  3323. /* Scan all pending sequences too. */
  3324. for (; stack; stack = stack->next)
  3325. if (after == stack->last)
  3326. {
  3327. stack->last = insn;
  3328. break;
  3329. }
  3330. }
  3331. }
  3332. }
  3333. /* Add INSN into the doubly-linked list before insn BEFORE. */
  3334. static void
  3335. add_insn_before_nobb (rtx_insn *insn, rtx_insn *before)
  3336. {
  3337. rtx_insn *prev = PREV_INSN (before);
  3338. gcc_assert (!optimize || !before->deleted ());
  3339. link_insn_into_chain (insn, prev, before);
  3340. if (prev == NULL)
  3341. {
  3342. if (get_insns () == before)
  3343. set_first_insn (insn);
  3344. else
  3345. {
  3346. struct sequence_stack *stack = seq_stack;
  3347. /* Scan all pending sequences too. */
  3348. for (; stack; stack = stack->next)
  3349. if (before == stack->first)
  3350. {
  3351. stack->first = insn;
  3352. break;
  3353. }
  3354. gcc_assert (stack);
  3355. }
  3356. }
  3357. }
  3358. /* Like add_insn_after_nobb, but try to set BLOCK_FOR_INSN.
  3359. If BB is NULL, an attempt is made to infer the bb from before.
  3360. This and the next function should be the only functions called
  3361. to insert an insn once delay slots have been filled since only
  3362. they know how to update a SEQUENCE. */
  3363. void
  3364. add_insn_after (rtx uncast_insn, rtx uncast_after, basic_block bb)
  3365. {
  3366. rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
  3367. rtx_insn *after = as_a <rtx_insn *> (uncast_after);
  3368. add_insn_after_nobb (insn, after);
  3369. if (!BARRIER_P (after)
  3370. && !BARRIER_P (insn)
  3371. && (bb = BLOCK_FOR_INSN (after)))
  3372. {
  3373. set_block_for_insn (insn, bb);
  3374. if (INSN_P (insn))
  3375. df_insn_rescan (insn);
  3376. /* Should not happen as first in the BB is always
  3377. either NOTE or LABEL. */
  3378. if (BB_END (bb) == after
  3379. /* Avoid clobbering of structure when creating new BB. */
  3380. && !BARRIER_P (insn)
  3381. && !NOTE_INSN_BASIC_BLOCK_P (insn))
  3382. BB_END (bb) = insn;
  3383. }
  3384. }
  3385. /* Like add_insn_before_nobb, but try to set BLOCK_FOR_INSN.
  3386. If BB is NULL, an attempt is made to infer the bb from before.
  3387. This and the previous function should be the only functions called
  3388. to insert an insn once delay slots have been filled since only
  3389. they know how to update a SEQUENCE. */
  3390. void
  3391. add_insn_before (rtx uncast_insn, rtx uncast_before, basic_block bb)
  3392. {
  3393. rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
  3394. rtx_insn *before = as_a <rtx_insn *> (uncast_before);
  3395. add_insn_before_nobb (insn, before);
  3396. if (!bb
  3397. && !BARRIER_P (before)
  3398. && !BARRIER_P (insn))
  3399. bb = BLOCK_FOR_INSN (before);
  3400. if (bb)
  3401. {
  3402. set_block_for_insn (insn, bb);
  3403. if (INSN_P (insn))
  3404. df_insn_rescan (insn);
  3405. /* Should not happen as first in the BB is always either NOTE or
  3406. LABEL. */
  3407. gcc_assert (BB_HEAD (bb) != insn
  3408. /* Avoid clobbering of structure when creating new BB. */
  3409. || BARRIER_P (insn)
  3410. || NOTE_INSN_BASIC_BLOCK_P (insn));
  3411. }
  3412. }
  3413. /* Replace insn with an deleted instruction note. */
  3414. void
  3415. set_insn_deleted (rtx insn)
  3416. {
  3417. if (INSN_P (insn))
  3418. df_insn_delete (as_a <rtx_insn *> (insn));
  3419. PUT_CODE (insn, NOTE);
  3420. NOTE_KIND (insn) = NOTE_INSN_DELETED;
  3421. }
  3422. /* Unlink INSN from the insn chain.
  3423. This function knows how to handle sequences.
  3424. This function does not invalidate data flow information associated with
  3425. INSN (i.e. does not call df_insn_delete). That makes this function
  3426. usable for only disconnecting an insn from the chain, and re-emit it
  3427. elsewhere later.
  3428. To later insert INSN elsewhere in the insn chain via add_insn and
  3429. similar functions, PREV_INSN and NEXT_INSN must be nullified by
  3430. the caller. Nullifying them here breaks many insn chain walks.
  3431. To really delete an insn and related DF information, use delete_insn. */
  3432. void
  3433. remove_insn (rtx uncast_insn)
  3434. {
  3435. rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
  3436. rtx_insn *next = NEXT_INSN (insn);
  3437. rtx_insn *prev = PREV_INSN (insn);
  3438. basic_block bb;
  3439. if (prev)
  3440. {
  3441. SET_NEXT_INSN (prev) = next;
  3442. if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
  3443. {
  3444. rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev));
  3445. SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next;
  3446. }
  3447. }
  3448. else if (get_insns () == insn)
  3449. {
  3450. if (next)
  3451. SET_PREV_INSN (next) = NULL;
  3452. set_first_insn (next);
  3453. }
  3454. else
  3455. {
  3456. struct sequence_stack *stack = seq_stack;
  3457. /* Scan all pending sequences too. */
  3458. for (; stack; stack = stack->next)
  3459. if (insn == stack->first)
  3460. {
  3461. stack->first = next;
  3462. break;
  3463. }
  3464. gcc_assert (stack);
  3465. }
  3466. if (next)
  3467. {
  3468. SET_PREV_INSN (next) = prev;
  3469. if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
  3470. {
  3471. rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next));
  3472. SET_PREV_INSN (sequence->insn (0)) = prev;
  3473. }
  3474. }
  3475. else if (get_last_insn () == insn)
  3476. set_last_insn (prev);
  3477. else
  3478. {
  3479. struct sequence_stack *stack = seq_stack;
  3480. /* Scan all pending sequences too. */
  3481. for (; stack; stack = stack->next)
  3482. if (insn == stack->last)
  3483. {
  3484. stack->last = prev;
  3485. break;
  3486. }
  3487. gcc_assert (stack);
  3488. }
  3489. /* Fix up basic block boundaries, if necessary. */
  3490. if (!BARRIER_P (insn)
  3491. && (bb = BLOCK_FOR_INSN (insn)))
  3492. {
  3493. if (BB_HEAD (bb) == insn)
  3494. {
  3495. /* Never ever delete the basic block note without deleting whole
  3496. basic block. */
  3497. gcc_assert (!NOTE_P (insn));
  3498. BB_HEAD (bb) = next;
  3499. }
  3500. if (BB_END (bb) == insn)
  3501. BB_END (bb) = prev;
  3502. }
  3503. }
  3504. /* Append CALL_FUSAGE to the CALL_INSN_FUNCTION_USAGE for CALL_INSN. */
  3505. void
  3506. add_function_usage_to (rtx call_insn, rtx call_fusage)
  3507. {
  3508. gcc_assert (call_insn && CALL_P (call_insn));
  3509. /* Put the register usage information on the CALL. If there is already
  3510. some usage information, put ours at the end. */
  3511. if (CALL_INSN_FUNCTION_USAGE (call_insn))
  3512. {
  3513. rtx link;
  3514. for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
  3515. link = XEXP (link, 1))
  3516. ;
  3517. XEXP (link, 1) = call_fusage;
  3518. }
  3519. else
  3520. CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
  3521. }
  3522. /* Delete all insns made since FROM.
  3523. FROM becomes the new last instruction. */
  3524. void
  3525. delete_insns_since (rtx_insn *from)
  3526. {
  3527. if (from == 0)
  3528. set_first_insn (0);
  3529. else
  3530. SET_NEXT_INSN (from) = 0;
  3531. set_last_insn (from);
  3532. }
  3533. /* This function is deprecated, please use sequences instead.
  3534. Move a consecutive bunch of insns to a different place in the chain.
  3535. The insns to be moved are those between FROM and TO.
  3536. They are moved to a new position after the insn AFTER.
  3537. AFTER must not be FROM or TO or any insn in between.
  3538. This function does not know about SEQUENCEs and hence should not be
  3539. called after delay-slot filling has been done. */
  3540. void
  3541. reorder_insns_nobb (rtx_insn *from, rtx_insn *to, rtx_insn *after)
  3542. {
  3543. #ifdef ENABLE_CHECKING
  3544. rtx_insn *x;
  3545. for (x = from; x != to; x = NEXT_INSN (x))
  3546. gcc_assert (after != x);
  3547. gcc_assert (after != to);
  3548. #endif
  3549. /* Splice this bunch out of where it is now. */
  3550. if (PREV_INSN (from))
  3551. SET_NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
  3552. if (NEXT_INSN (to))
  3553. SET_PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
  3554. if (get_last_insn () == to)
  3555. set_last_insn (PREV_INSN (from));
  3556. if (get_insns () == from)
  3557. set_first_insn (NEXT_INSN (to));
  3558. /* Make the new neighbors point to it and it to them. */
  3559. if (NEXT_INSN (after))
  3560. SET_PREV_INSN (NEXT_INSN (after)) = to;
  3561. SET_NEXT_INSN (to) = NEXT_INSN (after);
  3562. SET_PREV_INSN (from) = after;
  3563. SET_NEXT_INSN (after) = from;
  3564. if (after == get_last_insn ())
  3565. set_last_insn (to);
  3566. }
  3567. /* Same as function above, but take care to update BB boundaries. */
  3568. void
  3569. reorder_insns (rtx_insn *from, rtx_insn *to, rtx_insn *after)
  3570. {
  3571. rtx_insn *prev = PREV_INSN (from);
  3572. basic_block bb, bb2;
  3573. reorder_insns_nobb (from, to, after);
  3574. if (!BARRIER_P (after)
  3575. && (bb = BLOCK_FOR_INSN (after)))
  3576. {
  3577. rtx_insn *x;
  3578. df_set_bb_dirty (bb);
  3579. if (!BARRIER_P (from)
  3580. && (bb2 = BLOCK_FOR_INSN (from)))
  3581. {
  3582. if (BB_END (bb2) == to)
  3583. BB_END (bb2) = prev;
  3584. df_set_bb_dirty (bb2);
  3585. }
  3586. if (BB_END (bb) == after)
  3587. BB_END (bb) = to;
  3588. for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
  3589. if (!BARRIER_P (x))
  3590. df_insn_change_bb (x, bb);
  3591. }
  3592. }
  3593. /* Emit insn(s) of given code and pattern
  3594. at a specified place within the doubly-linked list.
  3595. All of the emit_foo global entry points accept an object
  3596. X which is either an insn list or a PATTERN of a single
  3597. instruction.
  3598. There are thus a few canonical ways to generate code and
  3599. emit it at a specific place in the instruction stream. For
  3600. example, consider the instruction named SPOT and the fact that
  3601. we would like to emit some instructions before SPOT. We might
  3602. do it like this:
  3603. start_sequence ();
  3604. ... emit the new instructions ...
  3605. insns_head = get_insns ();
  3606. end_sequence ();
  3607. emit_insn_before (insns_head, SPOT);
  3608. It used to be common to generate SEQUENCE rtl instead, but that
  3609. is a relic of the past which no longer occurs. The reason is that
  3610. SEQUENCE rtl results in much fragmented RTL memory since the SEQUENCE
  3611. generated would almost certainly die right after it was created. */
  3612. static rtx_insn *
  3613. emit_pattern_before_noloc (rtx x, rtx before, rtx last, basic_block bb,
  3614. rtx_insn *(*make_raw) (rtx))
  3615. {
  3616. rtx_insn *insn;
  3617. gcc_assert (before);
  3618. if (x == NULL_RTX)
  3619. return safe_as_a <rtx_insn *> (last);
  3620. switch (GET_CODE (x))
  3621. {
  3622. case DEBUG_INSN:
  3623. case INSN:
  3624. case JUMP_INSN:
  3625. case CALL_INSN:
  3626. case CODE_LABEL:
  3627. case BARRIER:
  3628. case NOTE:
  3629. insn = as_a <rtx_insn *> (x);
  3630. while (insn)
  3631. {
  3632. rtx_insn *next = NEXT_INSN (insn);
  3633. add_insn_before (insn, before, bb);
  3634. last = insn;
  3635. insn = next;
  3636. }
  3637. break;
  3638. #ifdef ENABLE_RTL_CHECKING
  3639. case SEQUENCE:
  3640. gcc_unreachable ();
  3641. break;
  3642. #endif
  3643. default:
  3644. last = (*make_raw) (x);
  3645. add_insn_before (last, before, bb);
  3646. break;
  3647. }
  3648. return safe_as_a <rtx_insn *> (last);
  3649. }
  3650. /* Make X be output before the instruction BEFORE. */
  3651. rtx_insn *
  3652. emit_insn_before_noloc (rtx x, rtx_insn *before, basic_block bb)
  3653. {
  3654. return emit_pattern_before_noloc (x, before, before, bb, make_insn_raw);
  3655. }
  3656. /* Make an instruction with body X and code JUMP_INSN
  3657. and output it before the instruction BEFORE. */
  3658. rtx_insn *
  3659. emit_jump_insn_before_noloc (rtx x, rtx_insn *before)
  3660. {
  3661. return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
  3662. make_jump_insn_raw);
  3663. }
  3664. /* Make an instruction with body X and code CALL_INSN
  3665. and output it before the instruction BEFORE. */
  3666. rtx_insn *
  3667. emit_call_insn_before_noloc (rtx x, rtx_insn *before)
  3668. {
  3669. return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
  3670. make_call_insn_raw);
  3671. }
  3672. /* Make an instruction with body X and code DEBUG_INSN
  3673. and output it before the instruction BEFORE. */
  3674. rtx_insn *
  3675. emit_debug_insn_before_noloc (rtx x, rtx before)
  3676. {
  3677. return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
  3678. make_debug_insn_raw);
  3679. }
  3680. /* Make an insn of code BARRIER
  3681. and output it before the insn BEFORE. */
  3682. rtx_barrier *
  3683. emit_barrier_before (rtx before)
  3684. {
  3685. rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
  3686. INSN_UID (insn) = cur_insn_uid++;
  3687. add_insn_before (insn, before, NULL);
  3688. return insn;
  3689. }
  3690. /* Emit the label LABEL before the insn BEFORE. */
  3691. rtx_insn *
  3692. emit_label_before (rtx label, rtx_insn *before)
  3693. {
  3694. gcc_checking_assert (INSN_UID (label) == 0);
  3695. INSN_UID (label) = cur_insn_uid++;
  3696. add_insn_before (label, before, NULL);
  3697. return as_a <rtx_insn *> (label);
  3698. }
  3699. /* Helper for emit_insn_after, handles lists of instructions
  3700. efficiently. */
  3701. static rtx_insn *
  3702. emit_insn_after_1 (rtx_insn *first, rtx uncast_after, basic_block bb)
  3703. {
  3704. rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
  3705. rtx_insn *last;
  3706. rtx_insn *after_after;
  3707. if (!bb && !BARRIER_P (after))
  3708. bb = BLOCK_FOR_INSN (after);
  3709. if (bb)
  3710. {
  3711. df_set_bb_dirty (bb);
  3712. for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
  3713. if (!BARRIER_P (last))
  3714. {
  3715. set_block_for_insn (last, bb);
  3716. df_insn_rescan (last);
  3717. }
  3718. if (!BARRIER_P (last))
  3719. {
  3720. set_block_for_insn (last, bb);
  3721. df_insn_rescan (last);
  3722. }
  3723. if (BB_END (bb) == after)
  3724. BB_END (bb) = last;
  3725. }
  3726. else
  3727. for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
  3728. continue;
  3729. after_after = NEXT_INSN (after);
  3730. SET_NEXT_INSN (after) = first;
  3731. SET_PREV_INSN (first) = after;
  3732. SET_NEXT_INSN (last) = after_after;
  3733. if (after_after)
  3734. SET_PREV_INSN (after_after) = last;
  3735. if (after == get_last_insn ())
  3736. set_last_insn (last);
  3737. return last;
  3738. }
  3739. static rtx_insn *
  3740. emit_pattern_after_noloc (rtx x, rtx uncast_after, basic_block bb,
  3741. rtx_insn *(*make_raw)(rtx))
  3742. {
  3743. rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
  3744. rtx_insn *last = after;
  3745. gcc_assert (after);
  3746. if (x == NULL_RTX)
  3747. return last;
  3748. switch (GET_CODE (x))
  3749. {
  3750. case DEBUG_INSN:
  3751. case INSN:
  3752. case JUMP_INSN:
  3753. case CALL_INSN:
  3754. case CODE_LABEL:
  3755. case BARRIER:
  3756. case NOTE:
  3757. last = emit_insn_after_1 (as_a <rtx_insn *> (x), after, bb);
  3758. break;
  3759. #ifdef ENABLE_RTL_CHECKING
  3760. case SEQUENCE:
  3761. gcc_unreachable ();
  3762. break;
  3763. #endif
  3764. default:
  3765. last = (*make_raw) (x);
  3766. add_insn_after (last, after, bb);
  3767. break;
  3768. }
  3769. return last;
  3770. }
  3771. /* Make X be output after the insn AFTER and set the BB of insn. If
  3772. BB is NULL, an attempt is made to infer the BB from AFTER. */
  3773. rtx_insn *
  3774. emit_insn_after_noloc (rtx x, rtx after, basic_block bb)
  3775. {
  3776. return emit_pattern_after_noloc (x, after, bb, make_insn_raw);
  3777. }
  3778. /* Make an insn of code JUMP_INSN with body X
  3779. and output it after the insn AFTER. */
  3780. rtx_insn *
  3781. emit_jump_insn_after_noloc (rtx x, rtx after)
  3782. {
  3783. return emit_pattern_after_noloc (x, after, NULL, make_jump_insn_raw);
  3784. }
  3785. /* Make an instruction with body X and code CALL_INSN
  3786. and output it after the instruction AFTER. */
  3787. rtx_insn *
  3788. emit_call_insn_after_noloc (rtx x, rtx after)
  3789. {
  3790. return emit_pattern_after_noloc (x, after, NULL, make_call_insn_raw);
  3791. }
  3792. /* Make an instruction with body X and code CALL_INSN
  3793. and output it after the instruction AFTER. */
  3794. rtx_insn *
  3795. emit_debug_insn_after_noloc (rtx x, rtx after)
  3796. {
  3797. return emit_pattern_after_noloc (x, after, NULL, make_debug_insn_raw);
  3798. }
  3799. /* Make an insn of code BARRIER
  3800. and output it after the insn AFTER. */
  3801. rtx_barrier *
  3802. emit_barrier_after (rtx after)
  3803. {
  3804. rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
  3805. INSN_UID (insn) = cur_insn_uid++;
  3806. add_insn_after (insn, after, NULL);
  3807. return insn;
  3808. }
  3809. /* Emit the label LABEL after the insn AFTER. */
  3810. rtx_insn *
  3811. emit_label_after (rtx label, rtx_insn *after)
  3812. {
  3813. gcc_checking_assert (INSN_UID (label) == 0);
  3814. INSN_UID (label) = cur_insn_uid++;
  3815. add_insn_after (label, after, NULL);
  3816. return as_a <rtx_insn *> (label);
  3817. }
  3818. /* Notes require a bit of special handling: Some notes need to have their
  3819. BLOCK_FOR_INSN set, others should never have it set, and some should
  3820. have it set or clear depending on the context. */
  3821. /* Return true iff a note of kind SUBTYPE should be emitted with routines
  3822. that never set BLOCK_FOR_INSN on NOTE. BB_BOUNDARY is true if the
  3823. caller is asked to emit a note before BB_HEAD, or after BB_END. */
  3824. static bool
  3825. note_outside_basic_block_p (enum insn_note subtype, bool on_bb_boundary_p)
  3826. {
  3827. switch (subtype)
  3828. {
  3829. /* NOTE_INSN_SWITCH_TEXT_SECTIONS only appears between basic blocks. */
  3830. case NOTE_INSN_SWITCH_TEXT_SECTIONS:
  3831. return true;
  3832. /* Notes for var tracking and EH region markers can appear between or
  3833. inside basic blocks. If the caller is emitting on the basic block
  3834. boundary, do not set BLOCK_FOR_INSN on the new note. */
  3835. case NOTE_INSN_VAR_LOCATION:
  3836. case NOTE_INSN_CALL_ARG_LOCATION:
  3837. case NOTE_INSN_EH_REGION_BEG:
  3838. case NOTE_INSN_EH_REGION_END:
  3839. return on_bb_boundary_p;
  3840. /* Otherwise, BLOCK_FOR_INSN must be set. */
  3841. default:
  3842. return false;
  3843. }
  3844. }
  3845. /* Emit a note of subtype SUBTYPE after the insn AFTER. */
  3846. rtx_note *
  3847. emit_note_after (enum insn_note subtype, rtx uncast_after)
  3848. {
  3849. rtx_insn *after = as_a <rtx_insn *> (uncast_after);
  3850. rtx_note *note = make_note_raw (subtype);
  3851. basic_block bb = BARRIER_P (after) ? NULL : BLOCK_FOR_INSN (after);
  3852. bool on_bb_boundary_p = (bb != NULL && BB_END (bb) == after);
  3853. if (note_outside_basic_block_p (subtype, on_bb_boundary_p))
  3854. add_insn_after_nobb (note, after);
  3855. else
  3856. add_insn_after (note, after, bb);
  3857. return note;
  3858. }
  3859. /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
  3860. rtx_note *
  3861. emit_note_before (enum insn_note subtype, rtx uncast_before)
  3862. {
  3863. rtx_insn *before = as_a <rtx_insn *> (uncast_before);
  3864. rtx_note *note = make_note_raw (subtype);
  3865. basic_block bb = BARRIER_P (before) ? NULL : BLOCK_FOR_INSN (before);
  3866. bool on_bb_boundary_p = (bb != NULL && BB_HEAD (bb) == before);
  3867. if (note_outside_basic_block_p (subtype, on_bb_boundary_p))
  3868. add_insn_before_nobb (note, before);
  3869. else
  3870. add_insn_before (note, before, bb);
  3871. return note;
  3872. }
  3873. /* Insert PATTERN after AFTER, setting its INSN_LOCATION to LOC.
  3874. MAKE_RAW indicates how to turn PATTERN into a real insn. */
  3875. static rtx_insn *
  3876. emit_pattern_after_setloc (rtx pattern, rtx uncast_after, int loc,
  3877. rtx_insn *(*make_raw) (rtx))
  3878. {
  3879. rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
  3880. rtx last = emit_pattern_after_noloc (pattern, after, NULL, make_raw);
  3881. if (pattern == NULL_RTX || !loc)
  3882. return safe_as_a <rtx_insn *> (last);
  3883. after = NEXT_INSN (after);
  3884. while (1)
  3885. {
  3886. if (active_insn_p (after) && !INSN_LOCATION (after))
  3887. INSN_LOCATION (after) = loc;
  3888. if (after == last)
  3889. break;
  3890. after = NEXT_INSN (after);
  3891. }
  3892. return safe_as_a <rtx_insn *> (last);
  3893. }
  3894. /* Insert PATTERN after AFTER. MAKE_RAW indicates how to turn PATTERN
  3895. into a real insn. SKIP_DEBUG_INSNS indicates whether to insert after
  3896. any DEBUG_INSNs. */
  3897. static rtx_insn *
  3898. emit_pattern_after (rtx pattern, rtx uncast_after, bool skip_debug_insns,
  3899. rtx_insn *(*make_raw) (rtx))
  3900. {
  3901. rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
  3902. rtx_insn *prev = after;
  3903. if (skip_debug_insns)
  3904. while (DEBUG_INSN_P (prev))
  3905. prev = PREV_INSN (prev);
  3906. if (INSN_P (prev))
  3907. return emit_pattern_after_setloc (pattern, after, INSN_LOCATION (prev),
  3908. make_raw);
  3909. else
  3910. return emit_pattern_after_noloc (pattern, after, NULL, make_raw);
  3911. }
  3912. /* Like emit_insn_after_noloc, but set INSN_LOCATION according to LOC. */
  3913. rtx_insn *
  3914. emit_insn_after_setloc (rtx pattern, rtx after, int loc)
  3915. {
  3916. return emit_pattern_after_setloc (pattern, after, loc, make_insn_raw);
  3917. }
  3918. /* Like emit_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
  3919. rtx_insn *
  3920. emit_insn_after (rtx pattern, rtx after)
  3921. {
  3922. return emit_pattern_after (pattern, after, true, make_insn_raw);
  3923. }
  3924. /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to LOC. */
  3925. rtx_insn *
  3926. emit_jump_insn_after_setloc (rtx pattern, rtx after, int loc)
  3927. {
  3928. return emit_pattern_after_setloc (pattern, after, loc, make_jump_insn_raw);
  3929. }
  3930. /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
  3931. rtx_insn *
  3932. emit_jump_insn_after (rtx pattern, rtx after)
  3933. {
  3934. return emit_pattern_after (pattern, after, true, make_jump_insn_raw);
  3935. }
  3936. /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to LOC. */
  3937. rtx_insn *
  3938. emit_call_insn_after_setloc (rtx pattern, rtx after, int loc)
  3939. {
  3940. return emit_pattern_after_setloc (pattern, after, loc, make_call_insn_raw);
  3941. }
  3942. /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
  3943. rtx_insn *
  3944. emit_call_insn_after (rtx pattern, rtx after)
  3945. {
  3946. return emit_pattern_after (pattern, after, true, make_call_insn_raw);
  3947. }
  3948. /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to LOC. */
  3949. rtx_insn *
  3950. emit_debug_insn_after_setloc (rtx pattern, rtx after, int loc)
  3951. {
  3952. return emit_pattern_after_setloc (pattern, after, loc, make_debug_insn_raw);
  3953. }
  3954. /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
  3955. rtx_insn *
  3956. emit_debug_insn_after (rtx pattern, rtx after)
  3957. {
  3958. return emit_pattern_after (pattern, after, false, make_debug_insn_raw);
  3959. }
  3960. /* Insert PATTERN before BEFORE, setting its INSN_LOCATION to LOC.
  3961. MAKE_RAW indicates how to turn PATTERN into a real insn. INSNP
  3962. indicates if PATTERN is meant for an INSN as opposed to a JUMP_INSN,
  3963. CALL_INSN, etc. */
  3964. static rtx_insn *
  3965. emit_pattern_before_setloc (rtx pattern, rtx uncast_before, int loc, bool insnp,
  3966. rtx_insn *(*make_raw) (rtx))
  3967. {
  3968. rtx_insn *before = as_a <rtx_insn *> (uncast_before);
  3969. rtx_insn *first = PREV_INSN (before);
  3970. rtx_insn *last = emit_pattern_before_noloc (pattern, before,
  3971. insnp ? before : NULL_RTX,
  3972. NULL, make_raw);
  3973. if (pattern == NULL_RTX || !loc)
  3974. return last;
  3975. if (!first)
  3976. first = get_insns ();
  3977. else
  3978. first = NEXT_INSN (first);
  3979. while (1)
  3980. {
  3981. if (active_insn_p (first) && !INSN_LOCATION (first))
  3982. INSN_LOCATION (first) = loc;
  3983. if (first == last)
  3984. break;
  3985. first = NEXT_INSN (first);
  3986. }
  3987. return last;
  3988. }
  3989. /* Insert PATTERN before BEFORE. MAKE_RAW indicates how to turn PATTERN
  3990. into a real insn. SKIP_DEBUG_INSNS indicates whether to insert
  3991. before any DEBUG_INSNs. INSNP indicates if PATTERN is meant for an
  3992. INSN as opposed to a JUMP_INSN, CALL_INSN, etc. */
  3993. static rtx_insn *
  3994. emit_pattern_before (rtx pattern, rtx uncast_before, bool skip_debug_insns,
  3995. bool insnp, rtx_insn *(*make_raw) (rtx))
  3996. {
  3997. rtx_insn *before = safe_as_a <rtx_insn *> (uncast_before);
  3998. rtx_insn *next = before;
  3999. if (skip_debug_insns)
  4000. while (DEBUG_INSN_P (next))
  4001. next = PREV_INSN (next);
  4002. if (INSN_P (next))
  4003. return emit_pattern_before_setloc (pattern, before, INSN_LOCATION (next),
  4004. insnp, make_raw);
  4005. else
  4006. return emit_pattern_before_noloc (pattern, before,
  4007. insnp ? before : NULL_RTX,
  4008. NULL, make_raw);
  4009. }
  4010. /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
  4011. rtx_insn *
  4012. emit_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
  4013. {
  4014. return emit_pattern_before_setloc (pattern, before, loc, true,
  4015. make_insn_raw);
  4016. }
  4017. /* Like emit_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */
  4018. rtx_insn *
  4019. emit_insn_before (rtx pattern, rtx before)
  4020. {
  4021. return emit_pattern_before (pattern, before, true, true, make_insn_raw);
  4022. }
  4023. /* like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
  4024. rtx_insn *
  4025. emit_jump_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
  4026. {
  4027. return emit_pattern_before_setloc (pattern, before, loc, false,
  4028. make_jump_insn_raw);
  4029. }
  4030. /* Like emit_jump_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */
  4031. rtx_insn *
  4032. emit_jump_insn_before (rtx pattern, rtx before)
  4033. {
  4034. return emit_pattern_before (pattern, before, true, false,
  4035. make_jump_insn_raw);
  4036. }
  4037. /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
  4038. rtx_insn *
  4039. emit_call_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
  4040. {
  4041. return emit_pattern_before_setloc (pattern, before, loc, false,
  4042. make_call_insn_raw);
  4043. }
  4044. /* Like emit_call_insn_before_noloc,
  4045. but set insn_location according to BEFORE. */
  4046. rtx_insn *
  4047. emit_call_insn_before (rtx pattern, rtx_insn *before)
  4048. {
  4049. return emit_pattern_before (pattern, before, true, false,
  4050. make_call_insn_raw);
  4051. }
  4052. /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
  4053. rtx_insn *
  4054. emit_debug_insn_before_setloc (rtx pattern, rtx before, int loc)
  4055. {
  4056. return emit_pattern_before_setloc (pattern, before, loc, false,
  4057. make_debug_insn_raw);
  4058. }
  4059. /* Like emit_debug_insn_before_noloc,
  4060. but set insn_location according to BEFORE. */
  4061. rtx_insn *
  4062. emit_debug_insn_before (rtx pattern, rtx before)
  4063. {
  4064. return emit_pattern_before (pattern, before, false, false,
  4065. make_debug_insn_raw);
  4066. }
  4067. /* Take X and emit it at the end of the doubly-linked
  4068. INSN list.
  4069. Returns the last insn emitted. */
  4070. rtx_insn *
  4071. emit_insn (rtx x)
  4072. {
  4073. rtx_insn *last = get_last_insn ();
  4074. rtx_insn *insn;
  4075. if (x == NULL_RTX)
  4076. return last;
  4077. switch (GET_CODE (x))
  4078. {
  4079. case DEBUG_INSN:
  4080. case INSN:
  4081. case JUMP_INSN:
  4082. case CALL_INSN:
  4083. case CODE_LABEL:
  4084. case BARRIER:
  4085. case NOTE:
  4086. insn = as_a <rtx_insn *> (x);
  4087. while (insn)
  4088. {
  4089. rtx_insn *next = NEXT_INSN (insn);
  4090. add_insn (insn);
  4091. last = insn;
  4092. insn = next;
  4093. }
  4094. break;
  4095. #ifdef ENABLE_RTL_CHECKING
  4096. case JUMP_TABLE_DATA:
  4097. case SEQUENCE:
  4098. gcc_unreachable ();
  4099. break;
  4100. #endif
  4101. default:
  4102. last = make_insn_raw (x);
  4103. add_insn (last);
  4104. break;
  4105. }
  4106. return last;
  4107. }
  4108. /* Make an insn of code DEBUG_INSN with pattern X
  4109. and add it to the end of the doubly-linked list. */
  4110. rtx_insn *
  4111. emit_debug_insn (rtx x)
  4112. {
  4113. rtx_insn *last = get_last_insn ();
  4114. rtx_insn *insn;
  4115. if (x == NULL_RTX)
  4116. return last;
  4117. switch (GET_CODE (x))
  4118. {
  4119. case DEBUG_INSN:
  4120. case INSN:
  4121. case JUMP_INSN:
  4122. case CALL_INSN:
  4123. case CODE_LABEL:
  4124. case BARRIER:
  4125. case NOTE:
  4126. insn = as_a <rtx_insn *> (x);
  4127. while (insn)
  4128. {
  4129. rtx_insn *next = NEXT_INSN (insn);
  4130. add_insn (insn);
  4131. last = insn;
  4132. insn = next;
  4133. }
  4134. break;
  4135. #ifdef ENABLE_RTL_CHECKING
  4136. case JUMP_TABLE_DATA:
  4137. case SEQUENCE:
  4138. gcc_unreachable ();
  4139. break;
  4140. #endif
  4141. default:
  4142. last = make_debug_insn_raw (x);
  4143. add_insn (last);
  4144. break;
  4145. }
  4146. return last;
  4147. }
  4148. /* Make an insn of code JUMP_INSN with pattern X
  4149. and add it to the end of the doubly-linked list. */
  4150. rtx_insn *
  4151. emit_jump_insn (rtx x)
  4152. {
  4153. rtx_insn *last = NULL;
  4154. rtx_insn *insn;
  4155. switch (GET_CODE (x))
  4156. {
  4157. case DEBUG_INSN:
  4158. case INSN:
  4159. case JUMP_INSN:
  4160. case CALL_INSN:
  4161. case CODE_LABEL:
  4162. case BARRIER:
  4163. case NOTE:
  4164. insn = as_a <rtx_insn *> (x);
  4165. while (insn)
  4166. {
  4167. rtx_insn *next = NEXT_INSN (insn);
  4168. add_insn (insn);
  4169. last = insn;
  4170. insn = next;
  4171. }
  4172. break;
  4173. #ifdef ENABLE_RTL_CHECKING
  4174. case JUMP_TABLE_DATA:
  4175. case SEQUENCE:
  4176. gcc_unreachable ();
  4177. break;
  4178. #endif
  4179. default:
  4180. last = make_jump_insn_raw (x);
  4181. add_insn (last);
  4182. break;
  4183. }
  4184. return last;
  4185. }
  4186. /* Make an insn of code CALL_INSN with pattern X
  4187. and add it to the end of the doubly-linked list. */
  4188. rtx_insn *
  4189. emit_call_insn (rtx x)
  4190. {
  4191. rtx_insn *insn;
  4192. switch (GET_CODE (x))
  4193. {
  4194. case DEBUG_INSN:
  4195. case INSN:
  4196. case JUMP_INSN:
  4197. case CALL_INSN:
  4198. case CODE_LABEL:
  4199. case BARRIER:
  4200. case NOTE:
  4201. insn = emit_insn (x);
  4202. break;
  4203. #ifdef ENABLE_RTL_CHECKING
  4204. case SEQUENCE:
  4205. case JUMP_TABLE_DATA:
  4206. gcc_unreachable ();
  4207. break;
  4208. #endif
  4209. default:
  4210. insn = make_call_insn_raw (x);
  4211. add_insn (insn);
  4212. break;
  4213. }
  4214. return insn;
  4215. }
  4216. /* Add the label LABEL to the end of the doubly-linked list. */
  4217. rtx_insn *
  4218. emit_label (rtx label)
  4219. {
  4220. gcc_checking_assert (INSN_UID (label) == 0);
  4221. INSN_UID (label) = cur_insn_uid++;
  4222. add_insn (as_a <rtx_insn *> (label));
  4223. return as_a <rtx_insn *> (label);
  4224. }
  4225. /* Make an insn of code JUMP_TABLE_DATA
  4226. and add it to the end of the doubly-linked list. */
  4227. rtx_jump_table_data *
  4228. emit_jump_table_data (rtx table)
  4229. {
  4230. rtx_jump_table_data *jump_table_data =
  4231. as_a <rtx_jump_table_data *> (rtx_alloc (JUMP_TABLE_DATA));
  4232. INSN_UID (jump_table_data) = cur_insn_uid++;
  4233. PATTERN (jump_table_data) = table;
  4234. BLOCK_FOR_INSN (jump_table_data) = NULL;
  4235. add_insn (jump_table_data);
  4236. return jump_table_data;
  4237. }
  4238. /* Make an insn of code BARRIER
  4239. and add it to the end of the doubly-linked list. */
  4240. rtx_barrier *
  4241. emit_barrier (void)
  4242. {
  4243. rtx_barrier *barrier = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
  4244. INSN_UID (barrier) = cur_insn_uid++;
  4245. add_insn (barrier);
  4246. return barrier;
  4247. }
  4248. /* Emit a copy of note ORIG. */
  4249. rtx_note *
  4250. emit_note_copy (rtx_note *orig)
  4251. {
  4252. enum insn_note kind = (enum insn_note) NOTE_KIND (orig);
  4253. rtx_note *note = make_note_raw (kind);
  4254. NOTE_DATA (note) = NOTE_DATA (orig);
  4255. add_insn (note);
  4256. return note;
  4257. }
  4258. /* Make an insn of code NOTE or type NOTE_NO
  4259. and add it to the end of the doubly-linked list. */
  4260. rtx_note *
  4261. emit_note (enum insn_note kind)
  4262. {
  4263. rtx_note *note = make_note_raw (kind);
  4264. add_insn (note);
  4265. return note;
  4266. }
  4267. /* Emit a clobber of lvalue X. */
  4268. rtx_insn *
  4269. emit_clobber (rtx x)
  4270. {
  4271. /* CONCATs should not appear in the insn stream. */
  4272. if (GET_CODE (x) == CONCAT)
  4273. {
  4274. emit_clobber (XEXP (x, 0));
  4275. return emit_clobber (XEXP (x, 1));
  4276. }
  4277. return emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
  4278. }
  4279. /* Return a sequence of insns to clobber lvalue X. */
  4280. rtx_insn *
  4281. gen_clobber (rtx x)
  4282. {
  4283. rtx_insn *seq;
  4284. start_sequence ();
  4285. emit_clobber (x);
  4286. seq = get_insns ();
  4287. end_sequence ();
  4288. return seq;
  4289. }
  4290. /* Emit a use of rvalue X. */
  4291. rtx_insn *
  4292. emit_use (rtx x)
  4293. {
  4294. /* CONCATs should not appear in the insn stream. */
  4295. if (GET_CODE (x) == CONCAT)
  4296. {
  4297. emit_use (XEXP (x, 0));
  4298. return emit_use (XEXP (x, 1));
  4299. }
  4300. return emit_insn (gen_rtx_USE (VOIDmode, x));
  4301. }
  4302. /* Return a sequence of insns to use rvalue X. */
  4303. rtx_insn *
  4304. gen_use (rtx x)
  4305. {
  4306. rtx_insn *seq;
  4307. start_sequence ();
  4308. emit_use (x);
  4309. seq = get_insns ();
  4310. end_sequence ();
  4311. return seq;
  4312. }
  4313. /* Notes like REG_EQUAL and REG_EQUIV refer to a set in an instruction.
  4314. Return the set in INSN that such notes describe, or NULL if the notes
  4315. have no meaning for INSN. */
  4316. rtx
  4317. set_for_reg_notes (rtx insn)
  4318. {
  4319. rtx pat, reg;
  4320. if (!INSN_P (insn))
  4321. return NULL_RTX;
  4322. pat = PATTERN (insn);
  4323. if (GET_CODE (pat) == PARALLEL)
  4324. {
  4325. /* We do not use single_set because that ignores SETs of unused
  4326. registers. REG_EQUAL and REG_EQUIV notes really do require the
  4327. PARALLEL to have a single SET. */
  4328. if (multiple_sets (insn))
  4329. return NULL_RTX;
  4330. pat = XVECEXP (pat, 0, 0);
  4331. }
  4332. if (GET_CODE (pat) != SET)
  4333. return NULL_RTX;
  4334. reg = SET_DEST (pat);
  4335. /* Notes apply to the contents of a STRICT_LOW_PART. */
  4336. if (GET_CODE (reg) == STRICT_LOW_PART)
  4337. reg = XEXP (reg, 0);
  4338. /* Check that we have a register. */
  4339. if (!(REG_P (reg) || GET_CODE (reg) == SUBREG))
  4340. return NULL_RTX;
  4341. return pat;
  4342. }
  4343. /* Place a note of KIND on insn INSN with DATUM as the datum. If a
  4344. note of this type already exists, remove it first. */
  4345. rtx
  4346. set_unique_reg_note (rtx insn, enum reg_note kind, rtx datum)
  4347. {
  4348. rtx note = find_reg_note (insn, kind, NULL_RTX);
  4349. switch (kind)
  4350. {
  4351. case REG_EQUAL:
  4352. case REG_EQUIV:
  4353. if (!set_for_reg_notes (insn))
  4354. return NULL_RTX;
  4355. /* Don't add ASM_OPERAND REG_EQUAL/REG_EQUIV notes.
  4356. It serves no useful purpose and breaks eliminate_regs. */
  4357. if (GET_CODE (datum) == ASM_OPERANDS)
  4358. return NULL_RTX;
  4359. /* Notes with side effects are dangerous. Even if the side-effect
  4360. initially mirrors one in PATTERN (INSN), later optimizations
  4361. might alter the way that the final register value is calculated
  4362. and so move or alter the side-effect in some way. The note would
  4363. then no longer be a valid substitution for SET_SRC. */
  4364. if (side_effects_p (datum))
  4365. return NULL_RTX;
  4366. break;
  4367. default:
  4368. break;
  4369. }
  4370. if (note)
  4371. XEXP (note, 0) = datum;
  4372. else
  4373. {
  4374. add_reg_note (insn, kind, datum);
  4375. note = REG_NOTES (insn);
  4376. }
  4377. switch (kind)
  4378. {
  4379. case REG_EQUAL:
  4380. case REG_EQUIV:
  4381. df_notes_rescan (as_a <rtx_insn *> (insn));
  4382. break;
  4383. default:
  4384. break;
  4385. }
  4386. return note;
  4387. }
  4388. /* Like set_unique_reg_note, but don't do anything unless INSN sets DST. */
  4389. rtx
  4390. set_dst_reg_note (rtx insn, enum reg_note kind, rtx datum, rtx dst)
  4391. {
  4392. rtx set = set_for_reg_notes (insn);
  4393. if (set && SET_DEST (set) == dst)
  4394. return set_unique_reg_note (insn, kind, datum);
  4395. return NULL_RTX;
  4396. }
  4397. /* Return an indication of which type of insn should have X as a body.
  4398. The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
  4399. static enum rtx_code
  4400. classify_insn (rtx x)
  4401. {
  4402. if (LABEL_P (x))
  4403. return CODE_LABEL;
  4404. if (GET_CODE (x) == CALL)
  4405. return CALL_INSN;
  4406. if (ANY_RETURN_P (x))
  4407. return JUMP_INSN;
  4408. if (GET_CODE (x) == SET)
  4409. {
  4410. if (SET_DEST (x) == pc_rtx)
  4411. return JUMP_INSN;
  4412. else if (GET_CODE (SET_SRC (x)) == CALL)
  4413. return CALL_INSN;
  4414. else
  4415. return INSN;
  4416. }
  4417. if (GET_CODE (x) == PARALLEL)
  4418. {
  4419. int j;
  4420. for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
  4421. if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
  4422. return CALL_INSN;
  4423. else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  4424. && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
  4425. return JUMP_INSN;
  4426. else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  4427. && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
  4428. return CALL_INSN;
  4429. }
  4430. return INSN;
  4431. }
  4432. /* Emit the rtl pattern X as an appropriate kind of insn.
  4433. If X is a label, it is simply added into the insn chain. */
  4434. rtx_insn *
  4435. emit (rtx x)
  4436. {
  4437. enum rtx_code code = classify_insn (x);
  4438. switch (code)
  4439. {
  4440. case CODE_LABEL:
  4441. return emit_label (x);
  4442. case INSN:
  4443. return emit_insn (x);
  4444. case JUMP_INSN:
  4445. {
  4446. rtx_insn *insn = emit_jump_insn (x);
  4447. if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
  4448. return emit_barrier ();
  4449. return insn;
  4450. }
  4451. case CALL_INSN:
  4452. return emit_call_insn (x);
  4453. case DEBUG_INSN:
  4454. return emit_debug_insn (x);
  4455. default:
  4456. gcc_unreachable ();
  4457. }
  4458. }
  4459. /* Space for free sequence stack entries. */
  4460. static GTY ((deletable)) struct sequence_stack *free_sequence_stack;
  4461. /* Begin emitting insns to a sequence. If this sequence will contain
  4462. something that might cause the compiler to pop arguments to function
  4463. calls (because those pops have previously been deferred; see
  4464. INHIBIT_DEFER_POP for more details), use do_pending_stack_adjust
  4465. before calling this function. That will ensure that the deferred
  4466. pops are not accidentally emitted in the middle of this sequence. */
  4467. void
  4468. start_sequence (void)
  4469. {
  4470. struct sequence_stack *tem;
  4471. if (free_sequence_stack != NULL)
  4472. {
  4473. tem = free_sequence_stack;
  4474. free_sequence_stack = tem->next;
  4475. }
  4476. else
  4477. tem = ggc_alloc<sequence_stack> ();
  4478. tem->next = seq_stack;
  4479. tem->first = get_insns ();
  4480. tem->last = get_last_insn ();
  4481. seq_stack = tem;
  4482. set_first_insn (0);
  4483. set_last_insn (0);
  4484. }
  4485. /* Set up the insn chain starting with FIRST as the current sequence,
  4486. saving the previously current one. See the documentation for
  4487. start_sequence for more information about how to use this function. */
  4488. void
  4489. push_to_sequence (rtx_insn *first)
  4490. {
  4491. rtx_insn *last;
  4492. start_sequence ();
  4493. for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last))
  4494. ;
  4495. set_first_insn (first);
  4496. set_last_insn (last);
  4497. }
  4498. /* Like push_to_sequence, but take the last insn as an argument to avoid
  4499. looping through the list. */
  4500. void
  4501. push_to_sequence2 (rtx_insn *first, rtx_insn *last)
  4502. {
  4503. start_sequence ();
  4504. set_first_insn (first);
  4505. set_last_insn (last);
  4506. }
  4507. /* Set up the outer-level insn chain
  4508. as the current sequence, saving the previously current one. */
  4509. void
  4510. push_topmost_sequence (void)
  4511. {
  4512. struct sequence_stack *stack, *top = NULL;
  4513. start_sequence ();
  4514. for (stack = seq_stack; stack; stack = stack->next)
  4515. top = stack;
  4516. set_first_insn (top->first);
  4517. set_last_insn (top->last);
  4518. }
  4519. /* After emitting to the outer-level insn chain, update the outer-level
  4520. insn chain, and restore the previous saved state. */
  4521. void
  4522. pop_topmost_sequence (void)
  4523. {
  4524. struct sequence_stack *stack, *top = NULL;
  4525. for (stack = seq_stack; stack; stack = stack->next)
  4526. top = stack;
  4527. top->first = get_insns ();
  4528. top->last = get_last_insn ();
  4529. end_sequence ();
  4530. }
  4531. /* After emitting to a sequence, restore previous saved state.
  4532. To get the contents of the sequence just made, you must call
  4533. `get_insns' *before* calling here.
  4534. If the compiler might have deferred popping arguments while
  4535. generating this sequence, and this sequence will not be immediately
  4536. inserted into the instruction stream, use do_pending_stack_adjust
  4537. before calling get_insns. That will ensure that the deferred
  4538. pops are inserted into this sequence, and not into some random
  4539. location in the instruction stream. See INHIBIT_DEFER_POP for more
  4540. information about deferred popping of arguments. */
  4541. void
  4542. end_sequence (void)
  4543. {
  4544. struct sequence_stack *tem = seq_stack;
  4545. set_first_insn (tem->first);
  4546. set_last_insn (tem->last);
  4547. seq_stack = tem->next;
  4548. memset (tem, 0, sizeof (*tem));
  4549. tem->next = free_sequence_stack;
  4550. free_sequence_stack = tem;
  4551. }
  4552. /* Return 1 if currently emitting into a sequence. */
  4553. int
  4554. in_sequence_p (void)
  4555. {
  4556. return seq_stack != 0;
  4557. }
  4558. /* Put the various virtual registers into REGNO_REG_RTX. */
  4559. static void
  4560. init_virtual_regs (void)
  4561. {
  4562. regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
  4563. regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
  4564. regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
  4565. regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
  4566. regno_reg_rtx[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
  4567. regno_reg_rtx[VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM]
  4568. = virtual_preferred_stack_boundary_rtx;
  4569. }
  4570. /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
  4571. static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
  4572. static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
  4573. static int copy_insn_n_scratches;
  4574. /* When an insn is being copied by copy_insn_1, this is nonzero if we have
  4575. copied an ASM_OPERANDS.
  4576. In that case, it is the original input-operand vector. */
  4577. static rtvec orig_asm_operands_vector;
  4578. /* When an insn is being copied by copy_insn_1, this is nonzero if we have
  4579. copied an ASM_OPERANDS.
  4580. In that case, it is the copied input-operand vector. */
  4581. static rtvec copy_asm_operands_vector;
  4582. /* Likewise for the constraints vector. */
  4583. static rtvec orig_asm_constraints_vector;
  4584. static rtvec copy_asm_constraints_vector;
  4585. /* Recursively create a new copy of an rtx for copy_insn.
  4586. This function differs from copy_rtx in that it handles SCRATCHes and
  4587. ASM_OPERANDs properly.
  4588. Normally, this function is not used directly; use copy_insn as front end.
  4589. However, you could first copy an insn pattern with copy_insn and then use
  4590. this function afterwards to properly copy any REG_NOTEs containing
  4591. SCRATCHes. */
  4592. rtx
  4593. copy_insn_1 (rtx orig)
  4594. {
  4595. rtx copy;
  4596. int i, j;
  4597. RTX_CODE code;
  4598. const char *format_ptr;
  4599. if (orig == NULL)
  4600. return NULL;
  4601. code = GET_CODE (orig);
  4602. switch (code)
  4603. {
  4604. case REG:
  4605. case DEBUG_EXPR:
  4606. CASE_CONST_ANY:
  4607. case SYMBOL_REF:
  4608. case CODE_LABEL:
  4609. case PC:
  4610. case CC0:
  4611. case RETURN:
  4612. case SIMPLE_RETURN:
  4613. return orig;
  4614. case CLOBBER:
  4615. /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
  4616. clobbers or clobbers of hard registers that originated as pseudos.
  4617. This is needed to allow safe register renaming. */
  4618. if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
  4619. && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
  4620. return orig;
  4621. break;
  4622. case SCRATCH:
  4623. for (i = 0; i < copy_insn_n_scratches; i++)
  4624. if (copy_insn_scratch_in[i] == orig)
  4625. return copy_insn_scratch_out[i];
  4626. break;
  4627. case CONST:
  4628. if (shared_const_p (orig))
  4629. return orig;
  4630. break;
  4631. /* A MEM with a constant address is not sharable. The problem is that
  4632. the constant address may need to be reloaded. If the mem is shared,
  4633. then reloading one copy of this mem will cause all copies to appear
  4634. to have been reloaded. */
  4635. default:
  4636. break;
  4637. }
  4638. /* Copy the various flags, fields, and other information. We assume
  4639. that all fields need copying, and then clear the fields that should
  4640. not be copied. That is the sensible default behavior, and forces
  4641. us to explicitly document why we are *not* copying a flag. */
  4642. copy = shallow_copy_rtx (orig);
  4643. /* We do not copy the USED flag, which is used as a mark bit during
  4644. walks over the RTL. */
  4645. RTX_FLAG (copy, used) = 0;
  4646. /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
  4647. if (INSN_P (orig))
  4648. {
  4649. RTX_FLAG (copy, jump) = 0;
  4650. RTX_FLAG (copy, call) = 0;
  4651. RTX_FLAG (copy, frame_related) = 0;
  4652. }
  4653. format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  4654. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  4655. switch (*format_ptr++)
  4656. {
  4657. case 'e':
  4658. if (XEXP (orig, i) != NULL)
  4659. XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
  4660. break;
  4661. case 'E':
  4662. case 'V':
  4663. if (XVEC (orig, i) == orig_asm_constraints_vector)
  4664. XVEC (copy, i) = copy_asm_constraints_vector;
  4665. else if (XVEC (orig, i) == orig_asm_operands_vector)
  4666. XVEC (copy, i) = copy_asm_operands_vector;
  4667. else if (XVEC (orig, i) != NULL)
  4668. {
  4669. XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  4670. for (j = 0; j < XVECLEN (copy, i); j++)
  4671. XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
  4672. }
  4673. break;
  4674. case 't':
  4675. case 'w':
  4676. case 'i':
  4677. case 's':
  4678. case 'S':
  4679. case 'u':
  4680. case '0':
  4681. /* These are left unchanged. */
  4682. break;
  4683. default:
  4684. gcc_unreachable ();
  4685. }
  4686. if (code == SCRATCH)
  4687. {
  4688. i = copy_insn_n_scratches++;
  4689. gcc_assert (i < MAX_RECOG_OPERANDS);
  4690. copy_insn_scratch_in[i] = orig;
  4691. copy_insn_scratch_out[i] = copy;
  4692. }
  4693. else if (code == ASM_OPERANDS)
  4694. {
  4695. orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
  4696. copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
  4697. orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
  4698. copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
  4699. }
  4700. return copy;
  4701. }
  4702. /* Create a new copy of an rtx.
  4703. This function differs from copy_rtx in that it handles SCRATCHes and
  4704. ASM_OPERANDs properly.
  4705. INSN doesn't really have to be a full INSN; it could be just the
  4706. pattern. */
  4707. rtx
  4708. copy_insn (rtx insn)
  4709. {
  4710. copy_insn_n_scratches = 0;
  4711. orig_asm_operands_vector = 0;
  4712. orig_asm_constraints_vector = 0;
  4713. copy_asm_operands_vector = 0;
  4714. copy_asm_constraints_vector = 0;
  4715. return copy_insn_1 (insn);
  4716. }
  4717. /* Return a copy of INSN that can be used in a SEQUENCE delay slot,
  4718. on that assumption that INSN itself remains in its original place. */
  4719. rtx_insn *
  4720. copy_delay_slot_insn (rtx_insn *insn)
  4721. {
  4722. /* Copy INSN with its rtx_code, all its notes, location etc. */
  4723. insn = as_a <rtx_insn *> (copy_rtx (insn));
  4724. INSN_UID (insn) = cur_insn_uid++;
  4725. return insn;
  4726. }
  4727. /* Initialize data structures and variables in this file
  4728. before generating rtl for each function. */
  4729. void
  4730. init_emit (void)
  4731. {
  4732. set_first_insn (NULL);
  4733. set_last_insn (NULL);
  4734. if (MIN_NONDEBUG_INSN_UID)
  4735. cur_insn_uid = MIN_NONDEBUG_INSN_UID;
  4736. else
  4737. cur_insn_uid = 1;
  4738. cur_debug_insn_uid = 1;
  4739. reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
  4740. first_label_num = label_num;
  4741. seq_stack = NULL;
  4742. /* Init the tables that describe all the pseudo regs. */
  4743. crtl->emit.regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
  4744. crtl->emit.regno_pointer_align
  4745. = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);
  4746. regno_reg_rtx = ggc_vec_alloc<rtx> (crtl->emit.regno_pointer_align_length);
  4747. /* Put copies of all the hard registers into regno_reg_rtx. */
  4748. memcpy (regno_reg_rtx,
  4749. initial_regno_reg_rtx,
  4750. FIRST_PSEUDO_REGISTER * sizeof (rtx));
  4751. /* Put copies of all the virtual register rtx into regno_reg_rtx. */
  4752. init_virtual_regs ();
  4753. /* Indicate that the virtual registers and stack locations are
  4754. all pointers. */
  4755. REG_POINTER (stack_pointer_rtx) = 1;
  4756. REG_POINTER (frame_pointer_rtx) = 1;
  4757. REG_POINTER (hard_frame_pointer_rtx) = 1;
  4758. REG_POINTER (arg_pointer_rtx) = 1;
  4759. REG_POINTER (virtual_incoming_args_rtx) = 1;
  4760. REG_POINTER (virtual_stack_vars_rtx) = 1;
  4761. REG_POINTER (virtual_stack_dynamic_rtx) = 1;
  4762. REG_POINTER (virtual_outgoing_args_rtx) = 1;
  4763. REG_POINTER (virtual_cfa_rtx) = 1;
  4764. #ifdef STACK_BOUNDARY
  4765. REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
  4766. REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
  4767. REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
  4768. REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
  4769. REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
  4770. REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
  4771. REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
  4772. REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
  4773. REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
  4774. #endif
  4775. #ifdef INIT_EXPANDERS
  4776. INIT_EXPANDERS;
  4777. #endif
  4778. }
  4779. /* Generate a vector constant for mode MODE and constant value CONSTANT. */
  4780. static rtx
  4781. gen_const_vector (machine_mode mode, int constant)
  4782. {
  4783. rtx tem;
  4784. rtvec v;
  4785. int units, i;
  4786. machine_mode inner;
  4787. units = GET_MODE_NUNITS (mode);
  4788. inner = GET_MODE_INNER (mode);
  4789. gcc_assert (!DECIMAL_FLOAT_MODE_P (inner));
  4790. v = rtvec_alloc (units);
  4791. /* We need to call this function after we set the scalar const_tiny_rtx
  4792. entries. */
  4793. gcc_assert (const_tiny_rtx[constant][(int) inner]);
  4794. for (i = 0; i < units; ++i)
  4795. RTVEC_ELT (v, i) = const_tiny_rtx[constant][(int) inner];
  4796. tem = gen_rtx_raw_CONST_VECTOR (mode, v);
  4797. return tem;
  4798. }
  4799. /* Generate a vector like gen_rtx_raw_CONST_VEC, but use the zero vector when
  4800. all elements are zero, and the one vector when all elements are one. */
  4801. rtx
  4802. gen_rtx_CONST_VECTOR (machine_mode mode, rtvec v)
  4803. {
  4804. machine_mode inner = GET_MODE_INNER (mode);
  4805. int nunits = GET_MODE_NUNITS (mode);
  4806. rtx x;
  4807. int i;
  4808. /* Check to see if all of the elements have the same value. */
  4809. x = RTVEC_ELT (v, nunits - 1);
  4810. for (i = nunits - 2; i >= 0; i--)
  4811. if (RTVEC_ELT (v, i) != x)
  4812. break;
  4813. /* If the values are all the same, check to see if we can use one of the
  4814. standard constant vectors. */
  4815. if (i == -1)
  4816. {
  4817. if (x == CONST0_RTX (inner))
  4818. return CONST0_RTX (mode);
  4819. else if (x == CONST1_RTX (inner))
  4820. return CONST1_RTX (mode);
  4821. else if (x == CONSTM1_RTX (inner))
  4822. return CONSTM1_RTX (mode);
  4823. }
  4824. return gen_rtx_raw_CONST_VECTOR (mode, v);
  4825. }
  4826. /* Initialise global register information required by all functions. */
  4827. void
  4828. init_emit_regs (void)
  4829. {
  4830. int i;
  4831. machine_mode mode;
  4832. mem_attrs *attrs;
  4833. /* Reset register attributes */
  4834. reg_attrs_htab->empty ();
  4835. /* We need reg_raw_mode, so initialize the modes now. */
  4836. init_reg_modes_target ();
  4837. /* Assign register numbers to the globally defined register rtx. */
  4838. stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
  4839. frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
  4840. hard_frame_pointer_rtx = gen_raw_REG (Pmode, HARD_FRAME_POINTER_REGNUM);
  4841. arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
  4842. virtual_incoming_args_rtx =
  4843. gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
  4844. virtual_stack_vars_rtx =
  4845. gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
  4846. virtual_stack_dynamic_rtx =
  4847. gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
  4848. virtual_outgoing_args_rtx =
  4849. gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
  4850. virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
  4851. virtual_preferred_stack_boundary_rtx =
  4852. gen_raw_REG (Pmode, VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM);
  4853. /* Initialize RTL for commonly used hard registers. These are
  4854. copied into regno_reg_rtx as we begin to compile each function. */
  4855. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  4856. initial_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i);
  4857. #ifdef RETURN_ADDRESS_POINTER_REGNUM
  4858. return_address_pointer_rtx
  4859. = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
  4860. #endif
  4861. pic_offset_table_rtx = NULL_RTX;
  4862. if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
  4863. pic_offset_table_rtx = gen_raw_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
  4864. for (i = 0; i < (int) MAX_MACHINE_MODE; i++)
  4865. {
  4866. mode = (machine_mode) i;
  4867. attrs = ggc_cleared_alloc<mem_attrs> ();
  4868. attrs->align = BITS_PER_UNIT;
  4869. attrs->addrspace = ADDR_SPACE_GENERIC;
  4870. if (mode != BLKmode)
  4871. {
  4872. attrs->size_known_p = true;
  4873. attrs->size = GET_MODE_SIZE (mode);
  4874. if (STRICT_ALIGNMENT)
  4875. attrs->align = GET_MODE_ALIGNMENT (mode);
  4876. }
  4877. mode_mem_attrs[i] = attrs;
  4878. }
  4879. }
  4880. /* Initialize global machine_mode variables. */
  4881. void
  4882. init_derived_machine_modes (void)
  4883. {
  4884. byte_mode = VOIDmode;
  4885. word_mode = VOIDmode;
  4886. for (machine_mode mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  4887. mode != VOIDmode;
  4888. mode = GET_MODE_WIDER_MODE (mode))
  4889. {
  4890. if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
  4891. && byte_mode == VOIDmode)
  4892. byte_mode = mode;
  4893. if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
  4894. && word_mode == VOIDmode)
  4895. word_mode = mode;
  4896. }
  4897. ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
  4898. }
  4899. /* Create some permanent unique rtl objects shared between all functions. */
  4900. void
  4901. init_emit_once (void)
  4902. {
  4903. int i;
  4904. machine_mode mode;
  4905. machine_mode double_mode;
  4906. /* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE,
  4907. CONST_FIXED, and memory attribute hash tables. */
  4908. const_int_htab = hash_table<const_int_hasher>::create_ggc (37);
  4909. #if TARGET_SUPPORTS_WIDE_INT
  4910. const_wide_int_htab = hash_table<const_wide_int_hasher>::create_ggc (37);
  4911. #endif
  4912. const_double_htab = hash_table<const_double_hasher>::create_ggc (37);
  4913. const_fixed_htab = hash_table<const_fixed_hasher>::create_ggc (37);
  4914. reg_attrs_htab = hash_table<reg_attr_hasher>::create_ggc (37);
  4915. #ifdef INIT_EXPANDERS
  4916. /* This is to initialize {init|mark|free}_machine_status before the first
  4917. call to push_function_context_to. This is needed by the Chill front
  4918. end which calls push_function_context_to before the first call to
  4919. init_function_start. */
  4920. INIT_EXPANDERS;
  4921. #endif
  4922. /* Create the unique rtx's for certain rtx codes and operand values. */
  4923. /* Don't use gen_rtx_CONST_INT here since gen_rtx_CONST_INT in this case
  4924. tries to use these variables. */
  4925. for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
  4926. const_int_rtx[i + MAX_SAVED_CONST_INT] =
  4927. gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i);
  4928. if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
  4929. && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
  4930. const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
  4931. else
  4932. const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
  4933. double_mode = mode_for_size (DOUBLE_TYPE_SIZE, MODE_FLOAT, 0);
  4934. real_from_integer (&dconst0, double_mode, 0, SIGNED);
  4935. real_from_integer (&dconst1, double_mode, 1, SIGNED);
  4936. real_from_integer (&dconst2, double_mode, 2, SIGNED);
  4937. dconstm1 = dconst1;
  4938. dconstm1.sign = 1;
  4939. dconsthalf = dconst1;
  4940. SET_REAL_EXP (&dconsthalf, REAL_EXP (&dconsthalf) - 1);
  4941. for (i = 0; i < 3; i++)
  4942. {
  4943. const REAL_VALUE_TYPE *const r =
  4944. (i == 0 ? &dconst0 : i == 1 ? &dconst1 : &dconst2);
  4945. for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
  4946. mode != VOIDmode;
  4947. mode = GET_MODE_WIDER_MODE (mode))
  4948. const_tiny_rtx[i][(int) mode] =
  4949. CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
  4950. for (mode = GET_CLASS_NARROWEST_MODE (MODE_DECIMAL_FLOAT);
  4951. mode != VOIDmode;
  4952. mode = GET_MODE_WIDER_MODE (mode))
  4953. const_tiny_rtx[i][(int) mode] =
  4954. CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
  4955. const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
  4956. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  4957. mode != VOIDmode;
  4958. mode = GET_MODE_WIDER_MODE (mode))
  4959. const_tiny_rtx[i][(int) mode] = GEN_INT (i);
  4960. for (mode = MIN_MODE_PARTIAL_INT;
  4961. mode <= MAX_MODE_PARTIAL_INT;
  4962. mode = (machine_mode)((int)(mode) + 1))
  4963. const_tiny_rtx[i][(int) mode] = GEN_INT (i);
  4964. }
  4965. const_tiny_rtx[3][(int) VOIDmode] = constm1_rtx;
  4966. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  4967. mode != VOIDmode;
  4968. mode = GET_MODE_WIDER_MODE (mode))
  4969. const_tiny_rtx[3][(int) mode] = constm1_rtx;
  4970. for (mode = MIN_MODE_PARTIAL_INT;
  4971. mode <= MAX_MODE_PARTIAL_INT;
  4972. mode = (machine_mode)((int)(mode) + 1))
  4973. const_tiny_rtx[3][(int) mode] = constm1_rtx;
  4974. for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_INT);
  4975. mode != VOIDmode;
  4976. mode = GET_MODE_WIDER_MODE (mode))
  4977. {
  4978. rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
  4979. const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
  4980. }
  4981. for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
  4982. mode != VOIDmode;
  4983. mode = GET_MODE_WIDER_MODE (mode))
  4984. {
  4985. rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
  4986. const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
  4987. }
  4988. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
  4989. mode != VOIDmode;
  4990. mode = GET_MODE_WIDER_MODE (mode))
  4991. {
  4992. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  4993. const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
  4994. const_tiny_rtx[3][(int) mode] = gen_const_vector (mode, 3);
  4995. }
  4996. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
  4997. mode != VOIDmode;
  4998. mode = GET_MODE_WIDER_MODE (mode))
  4999. {
  5000. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  5001. const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
  5002. }
  5003. for (mode = GET_CLASS_NARROWEST_MODE (MODE_FRACT);
  5004. mode != VOIDmode;
  5005. mode = GET_MODE_WIDER_MODE (mode))
  5006. {
  5007. FCONST0 (mode).data.high = 0;
  5008. FCONST0 (mode).data.low = 0;
  5009. FCONST0 (mode).mode = mode;
  5010. const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5011. FCONST0 (mode), mode);
  5012. }
  5013. for (mode = GET_CLASS_NARROWEST_MODE (MODE_UFRACT);
  5014. mode != VOIDmode;
  5015. mode = GET_MODE_WIDER_MODE (mode))
  5016. {
  5017. FCONST0 (mode).data.high = 0;
  5018. FCONST0 (mode).data.low = 0;
  5019. FCONST0 (mode).mode = mode;
  5020. const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5021. FCONST0 (mode), mode);
  5022. }
  5023. for (mode = GET_CLASS_NARROWEST_MODE (MODE_ACCUM);
  5024. mode != VOIDmode;
  5025. mode = GET_MODE_WIDER_MODE (mode))
  5026. {
  5027. FCONST0 (mode).data.high = 0;
  5028. FCONST0 (mode).data.low = 0;
  5029. FCONST0 (mode).mode = mode;
  5030. const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5031. FCONST0 (mode), mode);
  5032. /* We store the value 1. */
  5033. FCONST1 (mode).data.high = 0;
  5034. FCONST1 (mode).data.low = 0;
  5035. FCONST1 (mode).mode = mode;
  5036. FCONST1 (mode).data
  5037. = double_int_one.lshift (GET_MODE_FBIT (mode),
  5038. HOST_BITS_PER_DOUBLE_INT,
  5039. SIGNED_FIXED_POINT_MODE_P (mode));
  5040. const_tiny_rtx[1][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5041. FCONST1 (mode), mode);
  5042. }
  5043. for (mode = GET_CLASS_NARROWEST_MODE (MODE_UACCUM);
  5044. mode != VOIDmode;
  5045. mode = GET_MODE_WIDER_MODE (mode))
  5046. {
  5047. FCONST0 (mode).data.high = 0;
  5048. FCONST0 (mode).data.low = 0;
  5049. FCONST0 (mode).mode = mode;
  5050. const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5051. FCONST0 (mode), mode);
  5052. /* We store the value 1. */
  5053. FCONST1 (mode).data.high = 0;
  5054. FCONST1 (mode).data.low = 0;
  5055. FCONST1 (mode).mode = mode;
  5056. FCONST1 (mode).data
  5057. = double_int_one.lshift (GET_MODE_FBIT (mode),
  5058. HOST_BITS_PER_DOUBLE_INT,
  5059. SIGNED_FIXED_POINT_MODE_P (mode));
  5060. const_tiny_rtx[1][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
  5061. FCONST1 (mode), mode);
  5062. }
  5063. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FRACT);
  5064. mode != VOIDmode;
  5065. mode = GET_MODE_WIDER_MODE (mode))
  5066. {
  5067. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  5068. }
  5069. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UFRACT);
  5070. mode != VOIDmode;
  5071. mode = GET_MODE_WIDER_MODE (mode))
  5072. {
  5073. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  5074. }
  5075. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_ACCUM);
  5076. mode != VOIDmode;
  5077. mode = GET_MODE_WIDER_MODE (mode))
  5078. {
  5079. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  5080. const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
  5081. }
  5082. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UACCUM);
  5083. mode != VOIDmode;
  5084. mode = GET_MODE_WIDER_MODE (mode))
  5085. {
  5086. const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
  5087. const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
  5088. }
  5089. for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
  5090. if (GET_MODE_CLASS ((machine_mode) i) == MODE_CC)
  5091. const_tiny_rtx[0][i] = const0_rtx;
  5092. const_tiny_rtx[0][(int) BImode] = const0_rtx;
  5093. if (STORE_FLAG_VALUE == 1)
  5094. const_tiny_rtx[1][(int) BImode] = const1_rtx;
  5095. for (mode = GET_CLASS_NARROWEST_MODE (MODE_POINTER_BOUNDS);
  5096. mode != VOIDmode;
  5097. mode = GET_MODE_WIDER_MODE (mode))
  5098. {
  5099. wide_int wi_zero = wi::zero (GET_MODE_PRECISION (mode));
  5100. const_tiny_rtx[0][mode] = immed_wide_int_const (wi_zero, mode);
  5101. }
  5102. pc_rtx = gen_rtx_fmt_ (PC, VOIDmode);
  5103. ret_rtx = gen_rtx_fmt_ (RETURN, VOIDmode);
  5104. simple_return_rtx = gen_rtx_fmt_ (SIMPLE_RETURN, VOIDmode);
  5105. cc0_rtx = gen_rtx_fmt_ (CC0, VOIDmode);
  5106. }
  5107. /* Produce exact duplicate of insn INSN after AFTER.
  5108. Care updating of libcall regions if present. */
  5109. rtx_insn *
  5110. emit_copy_of_insn_after (rtx_insn *insn, rtx_insn *after)
  5111. {
  5112. rtx_insn *new_rtx;
  5113. rtx link;
  5114. switch (GET_CODE (insn))
  5115. {
  5116. case INSN:
  5117. new_rtx = emit_insn_after (copy_insn (PATTERN (insn)), after);
  5118. break;
  5119. case JUMP_INSN:
  5120. new_rtx = emit_jump_insn_after (copy_insn (PATTERN (insn)), after);
  5121. CROSSING_JUMP_P (new_rtx) = CROSSING_JUMP_P (insn);
  5122. break;
  5123. case DEBUG_INSN:
  5124. new_rtx = emit_debug_insn_after (copy_insn (PATTERN (insn)), after);
  5125. break;
  5126. case CALL_INSN:
  5127. new_rtx = emit_call_insn_after (copy_insn (PATTERN (insn)), after);
  5128. if (CALL_INSN_FUNCTION_USAGE (insn))
  5129. CALL_INSN_FUNCTION_USAGE (new_rtx)
  5130. = copy_insn (CALL_INSN_FUNCTION_USAGE (insn));
  5131. SIBLING_CALL_P (new_rtx) = SIBLING_CALL_P (insn);
  5132. RTL_CONST_CALL_P (new_rtx) = RTL_CONST_CALL_P (insn);
  5133. RTL_PURE_CALL_P (new_rtx) = RTL_PURE_CALL_P (insn);
  5134. RTL_LOOPING_CONST_OR_PURE_CALL_P (new_rtx)
  5135. = RTL_LOOPING_CONST_OR_PURE_CALL_P (insn);
  5136. break;
  5137. default:
  5138. gcc_unreachable ();
  5139. }
  5140. /* Update LABEL_NUSES. */
  5141. mark_jump_label (PATTERN (new_rtx), new_rtx, 0);
  5142. INSN_LOCATION (new_rtx) = INSN_LOCATION (insn);
  5143. /* If the old insn is frame related, then so is the new one. This is
  5144. primarily needed for IA-64 unwind info which marks epilogue insns,
  5145. which may be duplicated by the basic block reordering code. */
  5146. RTX_FRAME_RELATED_P (new_rtx) = RTX_FRAME_RELATED_P (insn);
  5147. /* Copy all REG_NOTES except REG_LABEL_OPERAND since mark_jump_label
  5148. will make them. REG_LABEL_TARGETs are created there too, but are
  5149. supposed to be sticky, so we copy them. */
  5150. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  5151. if (REG_NOTE_KIND (link) != REG_LABEL_OPERAND)
  5152. {
  5153. if (GET_CODE (link) == EXPR_LIST)
  5154. add_reg_note (new_rtx, REG_NOTE_KIND (link),
  5155. copy_insn_1 (XEXP (link, 0)));
  5156. else
  5157. add_shallow_copy_of_reg_note (new_rtx, link);
  5158. }
  5159. INSN_CODE (new_rtx) = INSN_CODE (insn);
  5160. return new_rtx;
  5161. }
  5162. static GTY((deletable)) rtx hard_reg_clobbers [NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
  5163. rtx
  5164. gen_hard_reg_clobber (machine_mode mode, unsigned int regno)
  5165. {
  5166. if (hard_reg_clobbers[mode][regno])
  5167. return hard_reg_clobbers[mode][regno];
  5168. else
  5169. return (hard_reg_clobbers[mode][regno] =
  5170. gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, regno)));
  5171. }
  5172. location_t prologue_location;
  5173. location_t epilogue_location;
  5174. /* Hold current location information and last location information, so the
  5175. datastructures are built lazily only when some instructions in given
  5176. place are needed. */
  5177. static location_t curr_location;
  5178. /* Allocate insn location datastructure. */
  5179. void
  5180. insn_locations_init (void)
  5181. {
  5182. prologue_location = epilogue_location = 0;
  5183. curr_location = UNKNOWN_LOCATION;
  5184. }
  5185. /* At the end of emit stage, clear current location. */
  5186. void
  5187. insn_locations_finalize (void)
  5188. {
  5189. epilogue_location = curr_location;
  5190. curr_location = UNKNOWN_LOCATION;
  5191. }
  5192. /* Set current location. */
  5193. void
  5194. set_curr_insn_location (location_t location)
  5195. {
  5196. curr_location = location;
  5197. }
  5198. /* Get current location. */
  5199. location_t
  5200. curr_insn_location (void)
  5201. {
  5202. return curr_location;
  5203. }
  5204. /* Return lexical scope block insn belongs to. */
  5205. tree
  5206. insn_scope (const rtx_insn *insn)
  5207. {
  5208. return LOCATION_BLOCK (INSN_LOCATION (insn));
  5209. }
  5210. /* Return line number of the statement that produced this insn. */
  5211. int
  5212. insn_line (const rtx_insn *insn)
  5213. {
  5214. return LOCATION_LINE (INSN_LOCATION (insn));
  5215. }
  5216. /* Return source file of the statement that produced this insn. */
  5217. const char *
  5218. insn_file (const rtx_insn *insn)
  5219. {
  5220. return LOCATION_FILE (INSN_LOCATION (insn));
  5221. }
  5222. /* Return expanded location of the statement that produced this insn. */
  5223. expanded_location
  5224. insn_location (const rtx_insn *insn)
  5225. {
  5226. return expand_location (INSN_LOCATION (insn));
  5227. }
  5228. /* Return true if memory model MODEL requires a pre-operation (release-style)
  5229. barrier or a post-operation (acquire-style) barrier. While not universal,
  5230. this function matches behavior of several targets. */
  5231. bool
  5232. need_atomic_barrier_p (enum memmodel model, bool pre)
  5233. {
  5234. switch (model & MEMMODEL_MASK)
  5235. {
  5236. case MEMMODEL_RELAXED:
  5237. case MEMMODEL_CONSUME:
  5238. return false;
  5239. case MEMMODEL_RELEASE:
  5240. return pre;
  5241. case MEMMODEL_ACQUIRE:
  5242. return !pre;
  5243. case MEMMODEL_ACQ_REL:
  5244. case MEMMODEL_SEQ_CST:
  5245. return true;
  5246. default:
  5247. gcc_unreachable ();
  5248. }
  5249. }
  5250. #include "gt-emit-rtl.h"