m68k.c 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552
  1. /* Subroutines for insn-output.c for Motorola 68000 family.
  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
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License 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. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "tm.h"
  19. #include "hash-set.h"
  20. #include "machmode.h"
  21. #include "vec.h"
  22. #include "double-int.h"
  23. #include "input.h"
  24. #include "alias.h"
  25. #include "symtab.h"
  26. #include "wide-int.h"
  27. #include "inchash.h"
  28. #include "tree.h"
  29. #include "fold-const.h"
  30. #include "calls.h"
  31. #include "stor-layout.h"
  32. #include "varasm.h"
  33. #include "rtl.h"
  34. #include "hard-reg-set.h"
  35. #include "function.h"
  36. #include "regs.h"
  37. #include "insn-config.h"
  38. #include "conditions.h"
  39. #include "output.h"
  40. #include "insn-attr.h"
  41. #include "recog.h"
  42. #include "diagnostic-core.h"
  43. #include "hashtab.h"
  44. #include "flags.h"
  45. #include "statistics.h"
  46. #include "real.h"
  47. #include "fixed-value.h"
  48. #include "expmed.h"
  49. #include "dojump.h"
  50. #include "explow.h"
  51. #include "emit-rtl.h"
  52. #include "stmt.h"
  53. #include "expr.h"
  54. #include "reload.h"
  55. #include "tm_p.h"
  56. #include "target.h"
  57. #include "target-def.h"
  58. #include "debug.h"
  59. #include "dominance.h"
  60. #include "cfg.h"
  61. #include "cfgrtl.h"
  62. #include "cfganal.h"
  63. #include "lcm.h"
  64. #include "cfgbuild.h"
  65. #include "cfgcleanup.h"
  66. #include "predict.h"
  67. #include "basic-block.h"
  68. #include "df.h"
  69. /* ??? Need to add a dependency between m68k.o and sched-int.h. */
  70. #include "sched-int.h"
  71. #include "insn-codes.h"
  72. #include "ggc.h"
  73. #include "opts.h"
  74. #include "optabs.h"
  75. #include "builtins.h"
  76. #include "rtl-iter.h"
  77. enum reg_class regno_reg_class[] =
  78. {
  79. DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
  80. DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
  81. ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
  82. ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
  83. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  84. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  85. ADDR_REGS
  86. };
  87. /* The minimum number of integer registers that we want to save with the
  88. movem instruction. Using two movel instructions instead of a single
  89. moveml is about 15% faster for the 68020 and 68030 at no expense in
  90. code size. */
  91. #define MIN_MOVEM_REGS 3
  92. /* The minimum number of floating point registers that we want to save
  93. with the fmovem instruction. */
  94. #define MIN_FMOVEM_REGS 1
  95. /* Structure describing stack frame layout. */
  96. struct m68k_frame
  97. {
  98. /* Stack pointer to frame pointer offset. */
  99. HOST_WIDE_INT offset;
  100. /* Offset of FPU registers. */
  101. HOST_WIDE_INT foffset;
  102. /* Frame size in bytes (rounded up). */
  103. HOST_WIDE_INT size;
  104. /* Data and address register. */
  105. int reg_no;
  106. unsigned int reg_mask;
  107. /* FPU registers. */
  108. int fpu_no;
  109. unsigned int fpu_mask;
  110. /* Offsets relative to ARG_POINTER. */
  111. HOST_WIDE_INT frame_pointer_offset;
  112. HOST_WIDE_INT stack_pointer_offset;
  113. /* Function which the above information refers to. */
  114. int funcdef_no;
  115. };
  116. /* Current frame information calculated by m68k_compute_frame_layout(). */
  117. static struct m68k_frame current_frame;
  118. /* Structure describing an m68k address.
  119. If CODE is UNKNOWN, the address is BASE + INDEX * SCALE + OFFSET,
  120. with null fields evaluating to 0. Here:
  121. - BASE satisfies m68k_legitimate_base_reg_p
  122. - INDEX satisfies m68k_legitimate_index_reg_p
  123. - OFFSET satisfies m68k_legitimate_constant_address_p
  124. INDEX is either HImode or SImode. The other fields are SImode.
  125. If CODE is PRE_DEC, the address is -(BASE). If CODE is POST_INC,
  126. the address is (BASE)+. */
  127. struct m68k_address {
  128. enum rtx_code code;
  129. rtx base;
  130. rtx index;
  131. rtx offset;
  132. int scale;
  133. };
  134. static int m68k_sched_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);
  135. static int m68k_sched_issue_rate (void);
  136. static int m68k_sched_variable_issue (FILE *, int, rtx_insn *, int);
  137. static void m68k_sched_md_init_global (FILE *, int, int);
  138. static void m68k_sched_md_finish_global (FILE *, int);
  139. static void m68k_sched_md_init (FILE *, int, int);
  140. static void m68k_sched_dfa_pre_advance_cycle (void);
  141. static void m68k_sched_dfa_post_advance_cycle (void);
  142. static int m68k_sched_first_cycle_multipass_dfa_lookahead (void);
  143. static bool m68k_can_eliminate (const int, const int);
  144. static void m68k_conditional_register_usage (void);
  145. static bool m68k_legitimate_address_p (machine_mode, rtx, bool);
  146. static void m68k_option_override (void);
  147. static void m68k_override_options_after_change (void);
  148. static rtx find_addr_reg (rtx);
  149. static const char *singlemove_string (rtx *);
  150. static void m68k_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
  151. HOST_WIDE_INT, tree);
  152. static rtx m68k_struct_value_rtx (tree, int);
  153. static tree m68k_handle_fndecl_attribute (tree *node, tree name,
  154. tree args, int flags,
  155. bool *no_add_attrs);
  156. static void m68k_compute_frame_layout (void);
  157. static bool m68k_save_reg (unsigned int regno, bool interrupt_handler);
  158. static bool m68k_ok_for_sibcall_p (tree, tree);
  159. static bool m68k_tls_symbol_p (rtx);
  160. static rtx m68k_legitimize_address (rtx, rtx, machine_mode);
  161. static bool m68k_rtx_costs (rtx, int, int, int, int *, bool);
  162. #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
  163. static bool m68k_return_in_memory (const_tree, const_tree);
  164. #endif
  165. static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
  166. static void m68k_trampoline_init (rtx, tree, rtx);
  167. static int m68k_return_pops_args (tree, tree, int);
  168. static rtx m68k_delegitimize_address (rtx);
  169. static void m68k_function_arg_advance (cumulative_args_t, machine_mode,
  170. const_tree, bool);
  171. static rtx m68k_function_arg (cumulative_args_t, machine_mode,
  172. const_tree, bool);
  173. static bool m68k_cannot_force_const_mem (machine_mode mode, rtx x);
  174. static bool m68k_output_addr_const_extra (FILE *, rtx);
  175. static void m68k_init_sync_libfuncs (void) ATTRIBUTE_UNUSED;
  176. /* Initialize the GCC target structure. */
  177. #if INT_OP_GROUP == INT_OP_DOT_WORD
  178. #undef TARGET_ASM_ALIGNED_HI_OP
  179. #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
  180. #endif
  181. #if INT_OP_GROUP == INT_OP_NO_DOT
  182. #undef TARGET_ASM_BYTE_OP
  183. #define TARGET_ASM_BYTE_OP "\tbyte\t"
  184. #undef TARGET_ASM_ALIGNED_HI_OP
  185. #define TARGET_ASM_ALIGNED_HI_OP "\tshort\t"
  186. #undef TARGET_ASM_ALIGNED_SI_OP
  187. #define TARGET_ASM_ALIGNED_SI_OP "\tlong\t"
  188. #endif
  189. #if INT_OP_GROUP == INT_OP_DC
  190. #undef TARGET_ASM_BYTE_OP
  191. #define TARGET_ASM_BYTE_OP "\tdc.b\t"
  192. #undef TARGET_ASM_ALIGNED_HI_OP
  193. #define TARGET_ASM_ALIGNED_HI_OP "\tdc.w\t"
  194. #undef TARGET_ASM_ALIGNED_SI_OP
  195. #define TARGET_ASM_ALIGNED_SI_OP "\tdc.l\t"
  196. #endif
  197. #undef TARGET_ASM_UNALIGNED_HI_OP
  198. #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
  199. #undef TARGET_ASM_UNALIGNED_SI_OP
  200. #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
  201. #undef TARGET_ASM_OUTPUT_MI_THUNK
  202. #define TARGET_ASM_OUTPUT_MI_THUNK m68k_output_mi_thunk
  203. #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
  204. #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
  205. #undef TARGET_ASM_FILE_START_APP_OFF
  206. #define TARGET_ASM_FILE_START_APP_OFF true
  207. #undef TARGET_LEGITIMIZE_ADDRESS
  208. #define TARGET_LEGITIMIZE_ADDRESS m68k_legitimize_address
  209. #undef TARGET_SCHED_ADJUST_COST
  210. #define TARGET_SCHED_ADJUST_COST m68k_sched_adjust_cost
  211. #undef TARGET_SCHED_ISSUE_RATE
  212. #define TARGET_SCHED_ISSUE_RATE m68k_sched_issue_rate
  213. #undef TARGET_SCHED_VARIABLE_ISSUE
  214. #define TARGET_SCHED_VARIABLE_ISSUE m68k_sched_variable_issue
  215. #undef TARGET_SCHED_INIT_GLOBAL
  216. #define TARGET_SCHED_INIT_GLOBAL m68k_sched_md_init_global
  217. #undef TARGET_SCHED_FINISH_GLOBAL
  218. #define TARGET_SCHED_FINISH_GLOBAL m68k_sched_md_finish_global
  219. #undef TARGET_SCHED_INIT
  220. #define TARGET_SCHED_INIT m68k_sched_md_init
  221. #undef TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE
  222. #define TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE m68k_sched_dfa_pre_advance_cycle
  223. #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE
  224. #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE m68k_sched_dfa_post_advance_cycle
  225. #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
  226. #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
  227. m68k_sched_first_cycle_multipass_dfa_lookahead
  228. #undef TARGET_OPTION_OVERRIDE
  229. #define TARGET_OPTION_OVERRIDE m68k_option_override
  230. #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
  231. #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE m68k_override_options_after_change
  232. #undef TARGET_RTX_COSTS
  233. #define TARGET_RTX_COSTS m68k_rtx_costs
  234. #undef TARGET_ATTRIBUTE_TABLE
  235. #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table
  236. #undef TARGET_PROMOTE_PROTOTYPES
  237. #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
  238. #undef TARGET_STRUCT_VALUE_RTX
  239. #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx
  240. #undef TARGET_CANNOT_FORCE_CONST_MEM
  241. #define TARGET_CANNOT_FORCE_CONST_MEM m68k_cannot_force_const_mem
  242. #undef TARGET_FUNCTION_OK_FOR_SIBCALL
  243. #define TARGET_FUNCTION_OK_FOR_SIBCALL m68k_ok_for_sibcall_p
  244. #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
  245. #undef TARGET_RETURN_IN_MEMORY
  246. #define TARGET_RETURN_IN_MEMORY m68k_return_in_memory
  247. #endif
  248. #ifdef HAVE_AS_TLS
  249. #undef TARGET_HAVE_TLS
  250. #define TARGET_HAVE_TLS (true)
  251. #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
  252. #define TARGET_ASM_OUTPUT_DWARF_DTPREL m68k_output_dwarf_dtprel
  253. #endif
  254. #undef TARGET_LEGITIMATE_ADDRESS_P
  255. #define TARGET_LEGITIMATE_ADDRESS_P m68k_legitimate_address_p
  256. #undef TARGET_CAN_ELIMINATE
  257. #define TARGET_CAN_ELIMINATE m68k_can_eliminate
  258. #undef TARGET_CONDITIONAL_REGISTER_USAGE
  259. #define TARGET_CONDITIONAL_REGISTER_USAGE m68k_conditional_register_usage
  260. #undef TARGET_TRAMPOLINE_INIT
  261. #define TARGET_TRAMPOLINE_INIT m68k_trampoline_init
  262. #undef TARGET_RETURN_POPS_ARGS
  263. #define TARGET_RETURN_POPS_ARGS m68k_return_pops_args
  264. #undef TARGET_DELEGITIMIZE_ADDRESS
  265. #define TARGET_DELEGITIMIZE_ADDRESS m68k_delegitimize_address
  266. #undef TARGET_FUNCTION_ARG
  267. #define TARGET_FUNCTION_ARG m68k_function_arg
  268. #undef TARGET_FUNCTION_ARG_ADVANCE
  269. #define TARGET_FUNCTION_ARG_ADVANCE m68k_function_arg_advance
  270. #undef TARGET_LEGITIMATE_CONSTANT_P
  271. #define TARGET_LEGITIMATE_CONSTANT_P m68k_legitimate_constant_p
  272. #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
  273. #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA m68k_output_addr_const_extra
  274. /* The value stored by TAS. */
  275. #undef TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
  276. #define TARGET_ATOMIC_TEST_AND_SET_TRUEVAL 128
  277. static const struct attribute_spec m68k_attribute_table[] =
  278. {
  279. /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
  280. affects_type_identity } */
  281. { "interrupt", 0, 0, true, false, false, m68k_handle_fndecl_attribute,
  282. false },
  283. { "interrupt_handler", 0, 0, true, false, false,
  284. m68k_handle_fndecl_attribute, false },
  285. { "interrupt_thread", 0, 0, true, false, false,
  286. m68k_handle_fndecl_attribute, false },
  287. { NULL, 0, 0, false, false, false, NULL, false }
  288. };
  289. struct gcc_target targetm = TARGET_INITIALIZER;
  290. /* Base flags for 68k ISAs. */
  291. #define FL_FOR_isa_00 FL_ISA_68000
  292. #define FL_FOR_isa_10 (FL_FOR_isa_00 | FL_ISA_68010)
  293. /* FL_68881 controls the default setting of -m68881. gcc has traditionally
  294. generated 68881 code for 68020 and 68030 targets unless explicitly told
  295. not to. */
  296. #define FL_FOR_isa_20 (FL_FOR_isa_10 | FL_ISA_68020 \
  297. | FL_BITFIELD | FL_68881 | FL_CAS)
  298. #define FL_FOR_isa_40 (FL_FOR_isa_20 | FL_ISA_68040)
  299. #define FL_FOR_isa_cpu32 (FL_FOR_isa_10 | FL_ISA_68020)
  300. /* Base flags for ColdFire ISAs. */
  301. #define FL_FOR_isa_a (FL_COLDFIRE | FL_ISA_A)
  302. #define FL_FOR_isa_aplus (FL_FOR_isa_a | FL_ISA_APLUS | FL_CF_USP)
  303. /* Note ISA_B doesn't necessarily include USP (user stack pointer) support. */
  304. #define FL_FOR_isa_b (FL_FOR_isa_a | FL_ISA_B | FL_CF_HWDIV)
  305. /* ISA_C is not upwardly compatible with ISA_B. */
  306. #define FL_FOR_isa_c (FL_FOR_isa_a | FL_ISA_C | FL_CF_USP)
  307. enum m68k_isa
  308. {
  309. /* Traditional 68000 instruction sets. */
  310. isa_00,
  311. isa_10,
  312. isa_20,
  313. isa_40,
  314. isa_cpu32,
  315. /* ColdFire instruction set variants. */
  316. isa_a,
  317. isa_aplus,
  318. isa_b,
  319. isa_c,
  320. isa_max
  321. };
  322. /* Information about one of the -march, -mcpu or -mtune arguments. */
  323. struct m68k_target_selection
  324. {
  325. /* The argument being described. */
  326. const char *name;
  327. /* For -mcpu, this is the device selected by the option.
  328. For -mtune and -march, it is a representative device
  329. for the microarchitecture or ISA respectively. */
  330. enum target_device device;
  331. /* The M68K_DEVICE fields associated with DEVICE. See the comment
  332. in m68k-devices.def for details. FAMILY is only valid for -mcpu. */
  333. const char *family;
  334. enum uarch_type microarch;
  335. enum m68k_isa isa;
  336. unsigned long flags;
  337. };
  338. /* A list of all devices in m68k-devices.def. Used for -mcpu selection. */
  339. static const struct m68k_target_selection all_devices[] =
  340. {
  341. #define M68K_DEVICE(NAME,ENUM_VALUE,FAMILY,MULTILIB,MICROARCH,ISA,FLAGS) \
  342. { NAME, ENUM_VALUE, FAMILY, u##MICROARCH, ISA, FLAGS | FL_FOR_##ISA },
  343. #include "m68k-devices.def"
  344. #undef M68K_DEVICE
  345. { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
  346. };
  347. /* A list of all ISAs, mapping each one to a representative device.
  348. Used for -march selection. */
  349. static const struct m68k_target_selection all_isas[] =
  350. {
  351. #define M68K_ISA(NAME,DEVICE,MICROARCH,ISA,FLAGS) \
  352. { NAME, DEVICE, NULL, u##MICROARCH, ISA, FLAGS },
  353. #include "m68k-isas.def"
  354. #undef M68K_ISA
  355. { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
  356. };
  357. /* A list of all microarchitectures, mapping each one to a representative
  358. device. Used for -mtune selection. */
  359. static const struct m68k_target_selection all_microarchs[] =
  360. {
  361. #define M68K_MICROARCH(NAME,DEVICE,MICROARCH,ISA,FLAGS) \
  362. { NAME, DEVICE, NULL, u##MICROARCH, ISA, FLAGS },
  363. #include "m68k-microarchs.def"
  364. #undef M68K_MICROARCH
  365. { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
  366. };
  367. /* The entries associated with the -mcpu, -march and -mtune settings,
  368. or null for options that have not been used. */
  369. const struct m68k_target_selection *m68k_cpu_entry;
  370. const struct m68k_target_selection *m68k_arch_entry;
  371. const struct m68k_target_selection *m68k_tune_entry;
  372. /* Which CPU we are generating code for. */
  373. enum target_device m68k_cpu;
  374. /* Which microarchitecture to tune for. */
  375. enum uarch_type m68k_tune;
  376. /* Which FPU to use. */
  377. enum fpu_type m68k_fpu;
  378. /* The set of FL_* flags that apply to the target processor. */
  379. unsigned int m68k_cpu_flags;
  380. /* The set of FL_* flags that apply to the processor to be tuned for. */
  381. unsigned int m68k_tune_flags;
  382. /* Asm templates for calling or jumping to an arbitrary symbolic address,
  383. or NULL if such calls or jumps are not supported. The address is held
  384. in operand 0. */
  385. const char *m68k_symbolic_call;
  386. const char *m68k_symbolic_jump;
  387. /* Enum variable that corresponds to m68k_symbolic_call values. */
  388. enum M68K_SYMBOLIC_CALL m68k_symbolic_call_var;
  389. /* Implement TARGET_OPTION_OVERRIDE. */
  390. static void
  391. m68k_option_override (void)
  392. {
  393. const struct m68k_target_selection *entry;
  394. unsigned long target_mask;
  395. if (global_options_set.x_m68k_arch_option)
  396. m68k_arch_entry = &all_isas[m68k_arch_option];
  397. if (global_options_set.x_m68k_cpu_option)
  398. m68k_cpu_entry = &all_devices[(int) m68k_cpu_option];
  399. if (global_options_set.x_m68k_tune_option)
  400. m68k_tune_entry = &all_microarchs[(int) m68k_tune_option];
  401. /* User can choose:
  402. -mcpu=
  403. -march=
  404. -mtune=
  405. -march=ARCH should generate code that runs any processor
  406. implementing architecture ARCH. -mcpu=CPU should override -march
  407. and should generate code that runs on processor CPU, making free
  408. use of any instructions that CPU understands. -mtune=UARCH applies
  409. on top of -mcpu or -march and optimizes the code for UARCH. It does
  410. not change the target architecture. */
  411. if (m68k_cpu_entry)
  412. {
  413. /* Complain if the -march setting is for a different microarchitecture,
  414. or includes flags that the -mcpu setting doesn't. */
  415. if (m68k_arch_entry
  416. && (m68k_arch_entry->microarch != m68k_cpu_entry->microarch
  417. || (m68k_arch_entry->flags & ~m68k_cpu_entry->flags) != 0))
  418. warning (0, "-mcpu=%s conflicts with -march=%s",
  419. m68k_cpu_entry->name, m68k_arch_entry->name);
  420. entry = m68k_cpu_entry;
  421. }
  422. else
  423. entry = m68k_arch_entry;
  424. if (!entry)
  425. entry = all_devices + TARGET_CPU_DEFAULT;
  426. m68k_cpu_flags = entry->flags;
  427. /* Use the architecture setting to derive default values for
  428. certain flags. */
  429. target_mask = 0;
  430. /* ColdFire is lenient about alignment. */
  431. if (!TARGET_COLDFIRE)
  432. target_mask |= MASK_STRICT_ALIGNMENT;
  433. if ((m68k_cpu_flags & FL_BITFIELD) != 0)
  434. target_mask |= MASK_BITFIELD;
  435. if ((m68k_cpu_flags & FL_CF_HWDIV) != 0)
  436. target_mask |= MASK_CF_HWDIV;
  437. if ((m68k_cpu_flags & (FL_68881 | FL_CF_FPU)) != 0)
  438. target_mask |= MASK_HARD_FLOAT;
  439. target_flags |= target_mask & ~target_flags_explicit;
  440. /* Set the directly-usable versions of the -mcpu and -mtune settings. */
  441. m68k_cpu = entry->device;
  442. if (m68k_tune_entry)
  443. {
  444. m68k_tune = m68k_tune_entry->microarch;
  445. m68k_tune_flags = m68k_tune_entry->flags;
  446. }
  447. #ifdef M68K_DEFAULT_TUNE
  448. else if (!m68k_cpu_entry && !m68k_arch_entry)
  449. {
  450. enum target_device dev;
  451. dev = all_microarchs[M68K_DEFAULT_TUNE].device;
  452. m68k_tune_flags = all_devices[dev].flags;
  453. }
  454. #endif
  455. else
  456. {
  457. m68k_tune = entry->microarch;
  458. m68k_tune_flags = entry->flags;
  459. }
  460. /* Set the type of FPU. */
  461. m68k_fpu = (!TARGET_HARD_FLOAT ? FPUTYPE_NONE
  462. : (m68k_cpu_flags & FL_COLDFIRE) != 0 ? FPUTYPE_COLDFIRE
  463. : FPUTYPE_68881);
  464. /* Sanity check to ensure that msep-data and mid-sahred-library are not
  465. * both specified together. Doing so simply doesn't make sense.
  466. */
  467. if (TARGET_SEP_DATA && TARGET_ID_SHARED_LIBRARY)
  468. error ("cannot specify both -msep-data and -mid-shared-library");
  469. /* If we're generating code for a separate A5 relative data segment,
  470. * we've got to enable -fPIC as well. This might be relaxable to
  471. * -fpic but it hasn't been tested properly.
  472. */
  473. if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY)
  474. flag_pic = 2;
  475. /* -mpcrel -fPIC uses 32-bit pc-relative displacements. Raise an
  476. error if the target does not support them. */
  477. if (TARGET_PCREL && !TARGET_68020 && flag_pic == 2)
  478. error ("-mpcrel -fPIC is not currently supported on selected cpu");
  479. /* ??? A historic way of turning on pic, or is this intended to
  480. be an embedded thing that doesn't have the same name binding
  481. significance that it does on hosted ELF systems? */
  482. if (TARGET_PCREL && flag_pic == 0)
  483. flag_pic = 1;
  484. if (!flag_pic)
  485. {
  486. m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_JSR;
  487. m68k_symbolic_jump = "jra %a0";
  488. }
  489. else if (TARGET_ID_SHARED_LIBRARY)
  490. /* All addresses must be loaded from the GOT. */
  491. ;
  492. else if (TARGET_68020 || TARGET_ISAB || TARGET_ISAC)
  493. {
  494. if (TARGET_PCREL)
  495. m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_C;
  496. else
  497. m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_P;
  498. if (TARGET_ISAC)
  499. /* No unconditional long branch */;
  500. else if (TARGET_PCREL)
  501. m68k_symbolic_jump = "bra%.l %c0";
  502. else
  503. m68k_symbolic_jump = "bra%.l %p0";
  504. /* Turn off function cse if we are doing PIC. We always want
  505. function call to be done as `bsr foo@PLTPC'. */
  506. /* ??? It's traditional to do this for -mpcrel too, but it isn't
  507. clear how intentional that is. */
  508. flag_no_function_cse = 1;
  509. }
  510. switch (m68k_symbolic_call_var)
  511. {
  512. case M68K_SYMBOLIC_CALL_JSR:
  513. m68k_symbolic_call = "jsr %a0";
  514. break;
  515. case M68K_SYMBOLIC_CALL_BSR_C:
  516. m68k_symbolic_call = "bsr%.l %c0";
  517. break;
  518. case M68K_SYMBOLIC_CALL_BSR_P:
  519. m68k_symbolic_call = "bsr%.l %p0";
  520. break;
  521. case M68K_SYMBOLIC_CALL_NONE:
  522. gcc_assert (m68k_symbolic_call == NULL);
  523. break;
  524. default:
  525. gcc_unreachable ();
  526. }
  527. #ifndef ASM_OUTPUT_ALIGN_WITH_NOP
  528. if (align_labels > 2)
  529. {
  530. warning (0, "-falign-labels=%d is not supported", align_labels);
  531. align_labels = 0;
  532. }
  533. if (align_loops > 2)
  534. {
  535. warning (0, "-falign-loops=%d is not supported", align_loops);
  536. align_loops = 0;
  537. }
  538. #endif
  539. if (stack_limit_rtx != NULL_RTX && !TARGET_68020)
  540. {
  541. warning (0, "-fstack-limit- options are not supported on this cpu");
  542. stack_limit_rtx = NULL_RTX;
  543. }
  544. SUBTARGET_OVERRIDE_OPTIONS;
  545. /* Setup scheduling options. */
  546. if (TUNE_CFV1)
  547. m68k_sched_cpu = CPU_CFV1;
  548. else if (TUNE_CFV2)
  549. m68k_sched_cpu = CPU_CFV2;
  550. else if (TUNE_CFV3)
  551. m68k_sched_cpu = CPU_CFV3;
  552. else if (TUNE_CFV4)
  553. m68k_sched_cpu = CPU_CFV4;
  554. else
  555. {
  556. m68k_sched_cpu = CPU_UNKNOWN;
  557. flag_schedule_insns = 0;
  558. flag_schedule_insns_after_reload = 0;
  559. flag_modulo_sched = 0;
  560. flag_live_range_shrinkage = 0;
  561. }
  562. if (m68k_sched_cpu != CPU_UNKNOWN)
  563. {
  564. if ((m68k_cpu_flags & (FL_CF_EMAC | FL_CF_EMAC_B)) != 0)
  565. m68k_sched_mac = MAC_CF_EMAC;
  566. else if ((m68k_cpu_flags & FL_CF_MAC) != 0)
  567. m68k_sched_mac = MAC_CF_MAC;
  568. else
  569. m68k_sched_mac = MAC_NO;
  570. }
  571. }
  572. /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE. */
  573. static void
  574. m68k_override_options_after_change (void)
  575. {
  576. if (m68k_sched_cpu == CPU_UNKNOWN)
  577. {
  578. flag_schedule_insns = 0;
  579. flag_schedule_insns_after_reload = 0;
  580. flag_modulo_sched = 0;
  581. flag_live_range_shrinkage = 0;
  582. }
  583. }
  584. /* Generate a macro of the form __mPREFIX_cpu_NAME, where PREFIX is the
  585. given argument and NAME is the argument passed to -mcpu. Return NULL
  586. if -mcpu was not passed. */
  587. const char *
  588. m68k_cpp_cpu_ident (const char *prefix)
  589. {
  590. if (!m68k_cpu_entry)
  591. return NULL;
  592. return concat ("__m", prefix, "_cpu_", m68k_cpu_entry->name, NULL);
  593. }
  594. /* Generate a macro of the form __mPREFIX_family_NAME, where PREFIX is the
  595. given argument and NAME is the name of the representative device for
  596. the -mcpu argument's family. Return NULL if -mcpu was not passed. */
  597. const char *
  598. m68k_cpp_cpu_family (const char *prefix)
  599. {
  600. if (!m68k_cpu_entry)
  601. return NULL;
  602. return concat ("__m", prefix, "_family_", m68k_cpu_entry->family, NULL);
  603. }
  604. /* Return m68k_fk_interrupt_handler if FUNC has an "interrupt" or
  605. "interrupt_handler" attribute and interrupt_thread if FUNC has an
  606. "interrupt_thread" attribute. Otherwise, return
  607. m68k_fk_normal_function. */
  608. enum m68k_function_kind
  609. m68k_get_function_kind (tree func)
  610. {
  611. tree a;
  612. gcc_assert (TREE_CODE (func) == FUNCTION_DECL);
  613. a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
  614. if (a != NULL_TREE)
  615. return m68k_fk_interrupt_handler;
  616. a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
  617. if (a != NULL_TREE)
  618. return m68k_fk_interrupt_handler;
  619. a = lookup_attribute ("interrupt_thread", DECL_ATTRIBUTES (func));
  620. if (a != NULL_TREE)
  621. return m68k_fk_interrupt_thread;
  622. return m68k_fk_normal_function;
  623. }
  624. /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
  625. struct attribute_spec.handler. */
  626. static tree
  627. m68k_handle_fndecl_attribute (tree *node, tree name,
  628. tree args ATTRIBUTE_UNUSED,
  629. int flags ATTRIBUTE_UNUSED,
  630. bool *no_add_attrs)
  631. {
  632. if (TREE_CODE (*node) != FUNCTION_DECL)
  633. {
  634. warning (OPT_Wattributes, "%qE attribute only applies to functions",
  635. name);
  636. *no_add_attrs = true;
  637. }
  638. if (m68k_get_function_kind (*node) != m68k_fk_normal_function)
  639. {
  640. error ("multiple interrupt attributes not allowed");
  641. *no_add_attrs = true;
  642. }
  643. if (!TARGET_FIDOA
  644. && !strcmp (IDENTIFIER_POINTER (name), "interrupt_thread"))
  645. {
  646. error ("interrupt_thread is available only on fido");
  647. *no_add_attrs = true;
  648. }
  649. return NULL_TREE;
  650. }
  651. static void
  652. m68k_compute_frame_layout (void)
  653. {
  654. int regno, saved;
  655. unsigned int mask;
  656. enum m68k_function_kind func_kind =
  657. m68k_get_function_kind (current_function_decl);
  658. bool interrupt_handler = func_kind == m68k_fk_interrupt_handler;
  659. bool interrupt_thread = func_kind == m68k_fk_interrupt_thread;
  660. /* Only compute the frame once per function.
  661. Don't cache information until reload has been completed. */
  662. if (current_frame.funcdef_no == current_function_funcdef_no
  663. && reload_completed)
  664. return;
  665. current_frame.size = (get_frame_size () + 3) & -4;
  666. mask = saved = 0;
  667. /* Interrupt thread does not need to save any register. */
  668. if (!interrupt_thread)
  669. for (regno = 0; regno < 16; regno++)
  670. if (m68k_save_reg (regno, interrupt_handler))
  671. {
  672. mask |= 1 << (regno - D0_REG);
  673. saved++;
  674. }
  675. current_frame.offset = saved * 4;
  676. current_frame.reg_no = saved;
  677. current_frame.reg_mask = mask;
  678. current_frame.foffset = 0;
  679. mask = saved = 0;
  680. if (TARGET_HARD_FLOAT)
  681. {
  682. /* Interrupt thread does not need to save any register. */
  683. if (!interrupt_thread)
  684. for (regno = 16; regno < 24; regno++)
  685. if (m68k_save_reg (regno, interrupt_handler))
  686. {
  687. mask |= 1 << (regno - FP0_REG);
  688. saved++;
  689. }
  690. current_frame.foffset = saved * TARGET_FP_REG_SIZE;
  691. current_frame.offset += current_frame.foffset;
  692. }
  693. current_frame.fpu_no = saved;
  694. current_frame.fpu_mask = mask;
  695. /* Remember what function this frame refers to. */
  696. current_frame.funcdef_no = current_function_funcdef_no;
  697. }
  698. /* Worker function for TARGET_CAN_ELIMINATE. */
  699. bool
  700. m68k_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
  701. {
  702. return (to == STACK_POINTER_REGNUM ? ! frame_pointer_needed : true);
  703. }
  704. HOST_WIDE_INT
  705. m68k_initial_elimination_offset (int from, int to)
  706. {
  707. int argptr_offset;
  708. /* The arg pointer points 8 bytes before the start of the arguments,
  709. as defined by FIRST_PARM_OFFSET. This makes it coincident with the
  710. frame pointer in most frames. */
  711. argptr_offset = frame_pointer_needed ? 0 : UNITS_PER_WORD;
  712. if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
  713. return argptr_offset;
  714. m68k_compute_frame_layout ();
  715. gcc_assert (to == STACK_POINTER_REGNUM);
  716. switch (from)
  717. {
  718. case ARG_POINTER_REGNUM:
  719. return current_frame.offset + current_frame.size - argptr_offset;
  720. case FRAME_POINTER_REGNUM:
  721. return current_frame.offset + current_frame.size;
  722. default:
  723. gcc_unreachable ();
  724. }
  725. }
  726. /* Refer to the array `regs_ever_live' to determine which registers
  727. to save; `regs_ever_live[I]' is nonzero if register number I
  728. is ever used in the function. This function is responsible for
  729. knowing which registers should not be saved even if used.
  730. Return true if we need to save REGNO. */
  731. static bool
  732. m68k_save_reg (unsigned int regno, bool interrupt_handler)
  733. {
  734. if (flag_pic && regno == PIC_REG)
  735. {
  736. if (crtl->saves_all_registers)
  737. return true;
  738. if (crtl->uses_pic_offset_table)
  739. return true;
  740. /* Reload may introduce constant pool references into a function
  741. that thitherto didn't need a PIC register. Note that the test
  742. above will not catch that case because we will only set
  743. crtl->uses_pic_offset_table when emitting
  744. the address reloads. */
  745. if (crtl->uses_const_pool)
  746. return true;
  747. }
  748. if (crtl->calls_eh_return)
  749. {
  750. unsigned int i;
  751. for (i = 0; ; i++)
  752. {
  753. unsigned int test = EH_RETURN_DATA_REGNO (i);
  754. if (test == INVALID_REGNUM)
  755. break;
  756. if (test == regno)
  757. return true;
  758. }
  759. }
  760. /* Fixed regs we never touch. */
  761. if (fixed_regs[regno])
  762. return false;
  763. /* The frame pointer (if it is such) is handled specially. */
  764. if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)
  765. return false;
  766. /* Interrupt handlers must also save call_used_regs
  767. if they are live or when calling nested functions. */
  768. if (interrupt_handler)
  769. {
  770. if (df_regs_ever_live_p (regno))
  771. return true;
  772. if (!crtl->is_leaf && call_used_regs[regno])
  773. return true;
  774. }
  775. /* Never need to save registers that aren't touched. */
  776. if (!df_regs_ever_live_p (regno))
  777. return false;
  778. /* Otherwise save everything that isn't call-clobbered. */
  779. return !call_used_regs[regno];
  780. }
  781. /* Emit RTL for a MOVEM or FMOVEM instruction. BASE + OFFSET represents
  782. the lowest memory address. COUNT is the number of registers to be
  783. moved, with register REGNO + I being moved if bit I of MASK is set.
  784. STORE_P specifies the direction of the move and ADJUST_STACK_P says
  785. whether or not this is pre-decrement (if STORE_P) or post-increment
  786. (if !STORE_P) operation. */
  787. static rtx_insn *
  788. m68k_emit_movem (rtx base, HOST_WIDE_INT offset,
  789. unsigned int count, unsigned int regno,
  790. unsigned int mask, bool store_p, bool adjust_stack_p)
  791. {
  792. int i;
  793. rtx body, addr, src, operands[2];
  794. machine_mode mode;
  795. body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (adjust_stack_p + count));
  796. mode = reg_raw_mode[regno];
  797. i = 0;
  798. if (adjust_stack_p)
  799. {
  800. src = plus_constant (Pmode, base,
  801. (count
  802. * GET_MODE_SIZE (mode)
  803. * (HOST_WIDE_INT) (store_p ? -1 : 1)));
  804. XVECEXP (body, 0, i++) = gen_rtx_SET (VOIDmode, base, src);
  805. }
  806. for (; mask != 0; mask >>= 1, regno++)
  807. if (mask & 1)
  808. {
  809. addr = plus_constant (Pmode, base, offset);
  810. operands[!store_p] = gen_frame_mem (mode, addr);
  811. operands[store_p] = gen_rtx_REG (mode, regno);
  812. XVECEXP (body, 0, i++)
  813. = gen_rtx_SET (VOIDmode, operands[0], operands[1]);
  814. offset += GET_MODE_SIZE (mode);
  815. }
  816. gcc_assert (i == XVECLEN (body, 0));
  817. return emit_insn (body);
  818. }
  819. /* Make INSN a frame-related instruction. */
  820. static void
  821. m68k_set_frame_related (rtx_insn *insn)
  822. {
  823. rtx body;
  824. int i;
  825. RTX_FRAME_RELATED_P (insn) = 1;
  826. body = PATTERN (insn);
  827. if (GET_CODE (body) == PARALLEL)
  828. for (i = 0; i < XVECLEN (body, 0); i++)
  829. RTX_FRAME_RELATED_P (XVECEXP (body, 0, i)) = 1;
  830. }
  831. /* Emit RTL for the "prologue" define_expand. */
  832. void
  833. m68k_expand_prologue (void)
  834. {
  835. HOST_WIDE_INT fsize_with_regs;
  836. rtx limit, src, dest;
  837. m68k_compute_frame_layout ();
  838. if (flag_stack_usage_info)
  839. current_function_static_stack_size
  840. = current_frame.size + current_frame.offset;
  841. /* If the stack limit is a symbol, we can check it here,
  842. before actually allocating the space. */
  843. if (crtl->limit_stack
  844. && GET_CODE (stack_limit_rtx) == SYMBOL_REF)
  845. {
  846. limit = plus_constant (Pmode, stack_limit_rtx, current_frame.size + 4);
  847. if (!m68k_legitimate_constant_p (Pmode, limit))
  848. {
  849. emit_move_insn (gen_rtx_REG (Pmode, D0_REG), limit);
  850. limit = gen_rtx_REG (Pmode, D0_REG);
  851. }
  852. emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode,
  853. stack_pointer_rtx, limit),
  854. stack_pointer_rtx, limit,
  855. const1_rtx));
  856. }
  857. fsize_with_regs = current_frame.size;
  858. if (TARGET_COLDFIRE)
  859. {
  860. /* ColdFire's move multiple instructions do not allow pre-decrement
  861. addressing. Add the size of movem saves to the initial stack
  862. allocation instead. */
  863. if (current_frame.reg_no >= MIN_MOVEM_REGS)
  864. fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode);
  865. if (current_frame.fpu_no >= MIN_FMOVEM_REGS)
  866. fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode);
  867. }
  868. if (frame_pointer_needed)
  869. {
  870. if (fsize_with_regs == 0 && TUNE_68040)
  871. {
  872. /* On the 68040, two separate moves are faster than link.w 0. */
  873. dest = gen_frame_mem (Pmode,
  874. gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
  875. m68k_set_frame_related (emit_move_insn (dest, frame_pointer_rtx));
  876. m68k_set_frame_related (emit_move_insn (frame_pointer_rtx,
  877. stack_pointer_rtx));
  878. }
  879. else if (fsize_with_regs < 0x8000 || TARGET_68020)
  880. m68k_set_frame_related
  881. (emit_insn (gen_link (frame_pointer_rtx,
  882. GEN_INT (-4 - fsize_with_regs))));
  883. else
  884. {
  885. m68k_set_frame_related
  886. (emit_insn (gen_link (frame_pointer_rtx, GEN_INT (-4))));
  887. m68k_set_frame_related
  888. (emit_insn (gen_addsi3 (stack_pointer_rtx,
  889. stack_pointer_rtx,
  890. GEN_INT (-fsize_with_regs))));
  891. }
  892. /* If the frame pointer is needed, emit a special barrier that
  893. will prevent the scheduler from moving stores to the frame
  894. before the stack adjustment. */
  895. emit_insn (gen_stack_tie (stack_pointer_rtx, frame_pointer_rtx));
  896. }
  897. else if (fsize_with_regs != 0)
  898. m68k_set_frame_related
  899. (emit_insn (gen_addsi3 (stack_pointer_rtx,
  900. stack_pointer_rtx,
  901. GEN_INT (-fsize_with_regs))));
  902. if (current_frame.fpu_mask)
  903. {
  904. gcc_assert (current_frame.fpu_no >= MIN_FMOVEM_REGS);
  905. if (TARGET_68881)
  906. m68k_set_frame_related
  907. (m68k_emit_movem (stack_pointer_rtx,
  908. current_frame.fpu_no * -GET_MODE_SIZE (XFmode),
  909. current_frame.fpu_no, FP0_REG,
  910. current_frame.fpu_mask, true, true));
  911. else
  912. {
  913. int offset;
  914. /* If we're using moveml to save the integer registers,
  915. the stack pointer will point to the bottom of the moveml
  916. save area. Find the stack offset of the first FP register. */
  917. if (current_frame.reg_no < MIN_MOVEM_REGS)
  918. offset = 0;
  919. else
  920. offset = current_frame.reg_no * GET_MODE_SIZE (SImode);
  921. m68k_set_frame_related
  922. (m68k_emit_movem (stack_pointer_rtx, offset,
  923. current_frame.fpu_no, FP0_REG,
  924. current_frame.fpu_mask, true, false));
  925. }
  926. }
  927. /* If the stack limit is not a symbol, check it here.
  928. This has the disadvantage that it may be too late... */
  929. if (crtl->limit_stack)
  930. {
  931. if (REG_P (stack_limit_rtx))
  932. emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode, stack_pointer_rtx,
  933. stack_limit_rtx),
  934. stack_pointer_rtx, stack_limit_rtx,
  935. const1_rtx));
  936. else if (GET_CODE (stack_limit_rtx) != SYMBOL_REF)
  937. warning (0, "stack limit expression is not supported");
  938. }
  939. if (current_frame.reg_no < MIN_MOVEM_REGS)
  940. {
  941. /* Store each register separately in the same order moveml does. */
  942. int i;
  943. for (i = 16; i-- > 0; )
  944. if (current_frame.reg_mask & (1 << i))
  945. {
  946. src = gen_rtx_REG (SImode, D0_REG + i);
  947. dest = gen_frame_mem (SImode,
  948. gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
  949. m68k_set_frame_related (emit_insn (gen_movsi (dest, src)));
  950. }
  951. }
  952. else
  953. {
  954. if (TARGET_COLDFIRE)
  955. /* The required register save space has already been allocated.
  956. The first register should be stored at (%sp). */
  957. m68k_set_frame_related
  958. (m68k_emit_movem (stack_pointer_rtx, 0,
  959. current_frame.reg_no, D0_REG,
  960. current_frame.reg_mask, true, false));
  961. else
  962. m68k_set_frame_related
  963. (m68k_emit_movem (stack_pointer_rtx,
  964. current_frame.reg_no * -GET_MODE_SIZE (SImode),
  965. current_frame.reg_no, D0_REG,
  966. current_frame.reg_mask, true, true));
  967. }
  968. if (!TARGET_SEP_DATA
  969. && crtl->uses_pic_offset_table)
  970. emit_insn (gen_load_got (pic_offset_table_rtx));
  971. }
  972. /* Return true if a simple (return) instruction is sufficient for this
  973. instruction (i.e. if no epilogue is needed). */
  974. bool
  975. m68k_use_return_insn (void)
  976. {
  977. if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
  978. return false;
  979. m68k_compute_frame_layout ();
  980. return current_frame.offset == 0;
  981. }
  982. /* Emit RTL for the "epilogue" or "sibcall_epilogue" define_expand;
  983. SIBCALL_P says which.
  984. The function epilogue should not depend on the current stack pointer!
  985. It should use the frame pointer only, if there is a frame pointer.
  986. This is mandatory because of alloca; we also take advantage of it to
  987. omit stack adjustments before returning. */
  988. void
  989. m68k_expand_epilogue (bool sibcall_p)
  990. {
  991. HOST_WIDE_INT fsize, fsize_with_regs;
  992. bool big, restore_from_sp;
  993. m68k_compute_frame_layout ();
  994. fsize = current_frame.size;
  995. big = false;
  996. restore_from_sp = false;
  997. /* FIXME : crtl->is_leaf below is too strong.
  998. What we really need to know there is if there could be pending
  999. stack adjustment needed at that point. */
  1000. restore_from_sp = (!frame_pointer_needed
  1001. || (!cfun->calls_alloca && crtl->is_leaf));
  1002. /* fsize_with_regs is the size we need to adjust the sp when
  1003. popping the frame. */
  1004. fsize_with_regs = fsize;
  1005. if (TARGET_COLDFIRE && restore_from_sp)
  1006. {
  1007. /* ColdFire's move multiple instructions do not allow post-increment
  1008. addressing. Add the size of movem loads to the final deallocation
  1009. instead. */
  1010. if (current_frame.reg_no >= MIN_MOVEM_REGS)
  1011. fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode);
  1012. if (current_frame.fpu_no >= MIN_FMOVEM_REGS)
  1013. fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode);
  1014. }
  1015. if (current_frame.offset + fsize >= 0x8000
  1016. && !restore_from_sp
  1017. && (current_frame.reg_mask || current_frame.fpu_mask))
  1018. {
  1019. if (TARGET_COLDFIRE
  1020. && (current_frame.reg_no >= MIN_MOVEM_REGS
  1021. || current_frame.fpu_no >= MIN_FMOVEM_REGS))
  1022. {
  1023. /* ColdFire's move multiple instructions do not support the
  1024. (d8,Ax,Xi) addressing mode, so we're as well using a normal
  1025. stack-based restore. */
  1026. emit_move_insn (gen_rtx_REG (Pmode, A1_REG),
  1027. GEN_INT (-(current_frame.offset + fsize)));
  1028. emit_insn (gen_addsi3 (stack_pointer_rtx,
  1029. gen_rtx_REG (Pmode, A1_REG),
  1030. frame_pointer_rtx));
  1031. restore_from_sp = true;
  1032. }
  1033. else
  1034. {
  1035. emit_move_insn (gen_rtx_REG (Pmode, A1_REG), GEN_INT (-fsize));
  1036. fsize = 0;
  1037. big = true;
  1038. }
  1039. }
  1040. if (current_frame.reg_no < MIN_MOVEM_REGS)
  1041. {
  1042. /* Restore each register separately in the same order moveml does. */
  1043. int i;
  1044. HOST_WIDE_INT offset;
  1045. offset = current_frame.offset + fsize;
  1046. for (i = 0; i < 16; i++)
  1047. if (current_frame.reg_mask & (1 << i))
  1048. {
  1049. rtx addr;
  1050. if (big)
  1051. {
  1052. /* Generate the address -OFFSET(%fp,%a1.l). */
  1053. addr = gen_rtx_REG (Pmode, A1_REG);
  1054. addr = gen_rtx_PLUS (Pmode, addr, frame_pointer_rtx);
  1055. addr = plus_constant (Pmode, addr, -offset);
  1056. }
  1057. else if (restore_from_sp)
  1058. addr = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
  1059. else
  1060. addr = plus_constant (Pmode, frame_pointer_rtx, -offset);
  1061. emit_move_insn (gen_rtx_REG (SImode, D0_REG + i),
  1062. gen_frame_mem (SImode, addr));
  1063. offset -= GET_MODE_SIZE (SImode);
  1064. }
  1065. }
  1066. else if (current_frame.reg_mask)
  1067. {
  1068. if (big)
  1069. m68k_emit_movem (gen_rtx_PLUS (Pmode,
  1070. gen_rtx_REG (Pmode, A1_REG),
  1071. frame_pointer_rtx),
  1072. -(current_frame.offset + fsize),
  1073. current_frame.reg_no, D0_REG,
  1074. current_frame.reg_mask, false, false);
  1075. else if (restore_from_sp)
  1076. m68k_emit_movem (stack_pointer_rtx, 0,
  1077. current_frame.reg_no, D0_REG,
  1078. current_frame.reg_mask, false,
  1079. !TARGET_COLDFIRE);
  1080. else
  1081. m68k_emit_movem (frame_pointer_rtx,
  1082. -(current_frame.offset + fsize),
  1083. current_frame.reg_no, D0_REG,
  1084. current_frame.reg_mask, false, false);
  1085. }
  1086. if (current_frame.fpu_no > 0)
  1087. {
  1088. if (big)
  1089. m68k_emit_movem (gen_rtx_PLUS (Pmode,
  1090. gen_rtx_REG (Pmode, A1_REG),
  1091. frame_pointer_rtx),
  1092. -(current_frame.foffset + fsize),
  1093. current_frame.fpu_no, FP0_REG,
  1094. current_frame.fpu_mask, false, false);
  1095. else if (restore_from_sp)
  1096. {
  1097. if (TARGET_COLDFIRE)
  1098. {
  1099. int offset;
  1100. /* If we used moveml to restore the integer registers, the
  1101. stack pointer will still point to the bottom of the moveml
  1102. save area. Find the stack offset of the first FP
  1103. register. */
  1104. if (current_frame.reg_no < MIN_MOVEM_REGS)
  1105. offset = 0;
  1106. else
  1107. offset = current_frame.reg_no * GET_MODE_SIZE (SImode);
  1108. m68k_emit_movem (stack_pointer_rtx, offset,
  1109. current_frame.fpu_no, FP0_REG,
  1110. current_frame.fpu_mask, false, false);
  1111. }
  1112. else
  1113. m68k_emit_movem (stack_pointer_rtx, 0,
  1114. current_frame.fpu_no, FP0_REG,
  1115. current_frame.fpu_mask, false, true);
  1116. }
  1117. else
  1118. m68k_emit_movem (frame_pointer_rtx,
  1119. -(current_frame.foffset + fsize),
  1120. current_frame.fpu_no, FP0_REG,
  1121. current_frame.fpu_mask, false, false);
  1122. }
  1123. if (frame_pointer_needed)
  1124. emit_insn (gen_unlink (frame_pointer_rtx));
  1125. else if (fsize_with_regs)
  1126. emit_insn (gen_addsi3 (stack_pointer_rtx,
  1127. stack_pointer_rtx,
  1128. GEN_INT (fsize_with_regs)));
  1129. if (crtl->calls_eh_return)
  1130. emit_insn (gen_addsi3 (stack_pointer_rtx,
  1131. stack_pointer_rtx,
  1132. EH_RETURN_STACKADJ_RTX));
  1133. if (!sibcall_p)
  1134. emit_jump_insn (ret_rtx);
  1135. }
  1136. /* Return true if X is a valid comparison operator for the dbcc
  1137. instruction.
  1138. Note it rejects floating point comparison operators.
  1139. (In the future we could use Fdbcc).
  1140. It also rejects some comparisons when CC_NO_OVERFLOW is set. */
  1141. int
  1142. valid_dbcc_comparison_p_2 (rtx x, machine_mode mode ATTRIBUTE_UNUSED)
  1143. {
  1144. switch (GET_CODE (x))
  1145. {
  1146. case EQ: case NE: case GTU: case LTU:
  1147. case GEU: case LEU:
  1148. return 1;
  1149. /* Reject some when CC_NO_OVERFLOW is set. This may be over
  1150. conservative */
  1151. case GT: case LT: case GE: case LE:
  1152. return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
  1153. default:
  1154. return 0;
  1155. }
  1156. }
  1157. /* Return nonzero if flags are currently in the 68881 flag register. */
  1158. int
  1159. flags_in_68881 (void)
  1160. {
  1161. /* We could add support for these in the future */
  1162. return cc_status.flags & CC_IN_68881;
  1163. }
  1164. /* Return true if PARALLEL contains register REGNO. */
  1165. static bool
  1166. m68k_reg_present_p (const_rtx parallel, unsigned int regno)
  1167. {
  1168. int i;
  1169. if (REG_P (parallel) && REGNO (parallel) == regno)
  1170. return true;
  1171. if (GET_CODE (parallel) != PARALLEL)
  1172. return false;
  1173. for (i = 0; i < XVECLEN (parallel, 0); ++i)
  1174. {
  1175. const_rtx x;
  1176. x = XEXP (XVECEXP (parallel, 0, i), 0);
  1177. if (REG_P (x) && REGNO (x) == regno)
  1178. return true;
  1179. }
  1180. return false;
  1181. }
  1182. /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P. */
  1183. static bool
  1184. m68k_ok_for_sibcall_p (tree decl, tree exp)
  1185. {
  1186. enum m68k_function_kind kind;
  1187. /* We cannot use sibcalls for nested functions because we use the
  1188. static chain register for indirect calls. */
  1189. if (CALL_EXPR_STATIC_CHAIN (exp))
  1190. return false;
  1191. if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
  1192. {
  1193. /* Check that the return value locations are the same. For
  1194. example that we aren't returning a value from the sibling in
  1195. a D0 register but then need to transfer it to a A0 register. */
  1196. rtx cfun_value;
  1197. rtx call_value;
  1198. cfun_value = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (cfun->decl)),
  1199. cfun->decl);
  1200. call_value = FUNCTION_VALUE (TREE_TYPE (exp), decl);
  1201. /* Check that the values are equal or that the result the callee
  1202. function returns is superset of what the current function returns. */
  1203. if (!(rtx_equal_p (cfun_value, call_value)
  1204. || (REG_P (cfun_value)
  1205. && m68k_reg_present_p (call_value, REGNO (cfun_value)))))
  1206. return false;
  1207. }
  1208. kind = m68k_get_function_kind (current_function_decl);
  1209. if (kind == m68k_fk_normal_function)
  1210. /* We can always sibcall from a normal function, because it's
  1211. undefined if it is calling an interrupt function. */
  1212. return true;
  1213. /* Otherwise we can only sibcall if the function kind is known to be
  1214. the same. */
  1215. if (decl && m68k_get_function_kind (decl) == kind)
  1216. return true;
  1217. return false;
  1218. }
  1219. /* On the m68k all args are always pushed. */
  1220. static rtx
  1221. m68k_function_arg (cumulative_args_t cum ATTRIBUTE_UNUSED,
  1222. machine_mode mode ATTRIBUTE_UNUSED,
  1223. const_tree type ATTRIBUTE_UNUSED,
  1224. bool named ATTRIBUTE_UNUSED)
  1225. {
  1226. return NULL_RTX;
  1227. }
  1228. static void
  1229. m68k_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
  1230. const_tree type, bool named ATTRIBUTE_UNUSED)
  1231. {
  1232. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  1233. *cum += (mode != BLKmode
  1234. ? (GET_MODE_SIZE (mode) + 3) & ~3
  1235. : (int_size_in_bytes (type) + 3) & ~3);
  1236. }
  1237. /* Convert X to a legitimate function call memory reference and return the
  1238. result. */
  1239. rtx
  1240. m68k_legitimize_call_address (rtx x)
  1241. {
  1242. gcc_assert (MEM_P (x));
  1243. if (call_operand (XEXP (x, 0), VOIDmode))
  1244. return x;
  1245. return replace_equiv_address (x, force_reg (Pmode, XEXP (x, 0)));
  1246. }
  1247. /* Likewise for sibling calls. */
  1248. rtx
  1249. m68k_legitimize_sibcall_address (rtx x)
  1250. {
  1251. gcc_assert (MEM_P (x));
  1252. if (sibcall_operand (XEXP (x, 0), VOIDmode))
  1253. return x;
  1254. emit_move_insn (gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM), XEXP (x, 0));
  1255. return replace_equiv_address (x, gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM));
  1256. }
  1257. /* Convert X to a legitimate address and return it if successful. Otherwise
  1258. return X.
  1259. For the 68000, we handle X+REG by loading X into a register R and
  1260. using R+REG. R will go in an address reg and indexing will be used.
  1261. However, if REG is a broken-out memory address or multiplication,
  1262. nothing needs to be done because REG can certainly go in an address reg. */
  1263. static rtx
  1264. m68k_legitimize_address (rtx x, rtx oldx, machine_mode mode)
  1265. {
  1266. if (m68k_tls_symbol_p (x))
  1267. return m68k_legitimize_tls_address (x);
  1268. if (GET_CODE (x) == PLUS)
  1269. {
  1270. int ch = (x) != (oldx);
  1271. int copied = 0;
  1272. #define COPY_ONCE(Y) if (!copied) { Y = copy_rtx (Y); copied = ch = 1; }
  1273. if (GET_CODE (XEXP (x, 0)) == MULT)
  1274. {
  1275. COPY_ONCE (x);
  1276. XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
  1277. }
  1278. if (GET_CODE (XEXP (x, 1)) == MULT)
  1279. {
  1280. COPY_ONCE (x);
  1281. XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
  1282. }
  1283. if (ch)
  1284. {
  1285. if (GET_CODE (XEXP (x, 1)) == REG
  1286. && GET_CODE (XEXP (x, 0)) == REG)
  1287. {
  1288. if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT)
  1289. {
  1290. COPY_ONCE (x);
  1291. x = force_operand (x, 0);
  1292. }
  1293. return x;
  1294. }
  1295. if (memory_address_p (mode, x))
  1296. return x;
  1297. }
  1298. if (GET_CODE (XEXP (x, 0)) == REG
  1299. || (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
  1300. && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  1301. && GET_MODE (XEXP (XEXP (x, 0), 0)) == HImode))
  1302. {
  1303. rtx temp = gen_reg_rtx (Pmode);
  1304. rtx val = force_operand (XEXP (x, 1), 0);
  1305. emit_move_insn (temp, val);
  1306. COPY_ONCE (x);
  1307. XEXP (x, 1) = temp;
  1308. if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT
  1309. && GET_CODE (XEXP (x, 0)) == REG)
  1310. x = force_operand (x, 0);
  1311. }
  1312. else if (GET_CODE (XEXP (x, 1)) == REG
  1313. || (GET_CODE (XEXP (x, 1)) == SIGN_EXTEND
  1314. && GET_CODE (XEXP (XEXP (x, 1), 0)) == REG
  1315. && GET_MODE (XEXP (XEXP (x, 1), 0)) == HImode))
  1316. {
  1317. rtx temp = gen_reg_rtx (Pmode);
  1318. rtx val = force_operand (XEXP (x, 0), 0);
  1319. emit_move_insn (temp, val);
  1320. COPY_ONCE (x);
  1321. XEXP (x, 0) = temp;
  1322. if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT
  1323. && GET_CODE (XEXP (x, 1)) == REG)
  1324. x = force_operand (x, 0);
  1325. }
  1326. }
  1327. return x;
  1328. }
  1329. /* Output a dbCC; jCC sequence. Note we do not handle the
  1330. floating point version of this sequence (Fdbcc). We also
  1331. do not handle alternative conditions when CC_NO_OVERFLOW is
  1332. set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
  1333. kick those out before we get here. */
  1334. void
  1335. output_dbcc_and_branch (rtx *operands)
  1336. {
  1337. switch (GET_CODE (operands[3]))
  1338. {
  1339. case EQ:
  1340. output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands);
  1341. break;
  1342. case NE:
  1343. output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands);
  1344. break;
  1345. case GT:
  1346. output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands);
  1347. break;
  1348. case GTU:
  1349. output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands);
  1350. break;
  1351. case LT:
  1352. output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands);
  1353. break;
  1354. case LTU:
  1355. output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands);
  1356. break;
  1357. case GE:
  1358. output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands);
  1359. break;
  1360. case GEU:
  1361. output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands);
  1362. break;
  1363. case LE:
  1364. output_asm_insn ("dble %0,%l1\n\tjle %l2", operands);
  1365. break;
  1366. case LEU:
  1367. output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands);
  1368. break;
  1369. default:
  1370. gcc_unreachable ();
  1371. }
  1372. /* If the decrement is to be done in SImode, then we have
  1373. to compensate for the fact that dbcc decrements in HImode. */
  1374. switch (GET_MODE (operands[0]))
  1375. {
  1376. case SImode:
  1377. output_asm_insn ("clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1", operands);
  1378. break;
  1379. case HImode:
  1380. break;
  1381. default:
  1382. gcc_unreachable ();
  1383. }
  1384. }
  1385. const char *
  1386. output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest)
  1387. {
  1388. rtx loperands[7];
  1389. enum rtx_code op_code = GET_CODE (op);
  1390. /* This does not produce a useful cc. */
  1391. CC_STATUS_INIT;
  1392. /* The m68k cmp.l instruction requires operand1 to be a reg as used
  1393. below. Swap the operands and change the op if these requirements
  1394. are not fulfilled. */
  1395. if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG)
  1396. {
  1397. rtx tmp = operand1;
  1398. operand1 = operand2;
  1399. operand2 = tmp;
  1400. op_code = swap_condition (op_code);
  1401. }
  1402. loperands[0] = operand1;
  1403. if (GET_CODE (operand1) == REG)
  1404. loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1);
  1405. else
  1406. loperands[1] = adjust_address (operand1, SImode, 4);
  1407. if (operand2 != const0_rtx)
  1408. {
  1409. loperands[2] = operand2;
  1410. if (GET_CODE (operand2) == REG)
  1411. loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1);
  1412. else
  1413. loperands[3] = adjust_address (operand2, SImode, 4);
  1414. }
  1415. loperands[4] = gen_label_rtx ();
  1416. if (operand2 != const0_rtx)
  1417. output_asm_insn ("cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1", loperands);
  1418. else
  1419. {
  1420. if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0]))
  1421. output_asm_insn ("tst%.l %0", loperands);
  1422. else
  1423. output_asm_insn ("cmp%.w #0,%0", loperands);
  1424. output_asm_insn ("jne %l4", loperands);
  1425. if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1]))
  1426. output_asm_insn ("tst%.l %1", loperands);
  1427. else
  1428. output_asm_insn ("cmp%.w #0,%1", loperands);
  1429. }
  1430. loperands[5] = dest;
  1431. switch (op_code)
  1432. {
  1433. case EQ:
  1434. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1435. CODE_LABEL_NUMBER (loperands[4]));
  1436. output_asm_insn ("seq %5", loperands);
  1437. break;
  1438. case NE:
  1439. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1440. CODE_LABEL_NUMBER (loperands[4]));
  1441. output_asm_insn ("sne %5", loperands);
  1442. break;
  1443. case GT:
  1444. loperands[6] = gen_label_rtx ();
  1445. output_asm_insn ("shi %5\n\tjra %l6", loperands);
  1446. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1447. CODE_LABEL_NUMBER (loperands[4]));
  1448. output_asm_insn ("sgt %5", loperands);
  1449. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1450. CODE_LABEL_NUMBER (loperands[6]));
  1451. break;
  1452. case GTU:
  1453. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1454. CODE_LABEL_NUMBER (loperands[4]));
  1455. output_asm_insn ("shi %5", loperands);
  1456. break;
  1457. case LT:
  1458. loperands[6] = gen_label_rtx ();
  1459. output_asm_insn ("scs %5\n\tjra %l6", loperands);
  1460. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1461. CODE_LABEL_NUMBER (loperands[4]));
  1462. output_asm_insn ("slt %5", loperands);
  1463. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1464. CODE_LABEL_NUMBER (loperands[6]));
  1465. break;
  1466. case LTU:
  1467. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1468. CODE_LABEL_NUMBER (loperands[4]));
  1469. output_asm_insn ("scs %5", loperands);
  1470. break;
  1471. case GE:
  1472. loperands[6] = gen_label_rtx ();
  1473. output_asm_insn ("scc %5\n\tjra %l6", loperands);
  1474. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1475. CODE_LABEL_NUMBER (loperands[4]));
  1476. output_asm_insn ("sge %5", loperands);
  1477. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1478. CODE_LABEL_NUMBER (loperands[6]));
  1479. break;
  1480. case GEU:
  1481. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1482. CODE_LABEL_NUMBER (loperands[4]));
  1483. output_asm_insn ("scc %5", loperands);
  1484. break;
  1485. case LE:
  1486. loperands[6] = gen_label_rtx ();
  1487. output_asm_insn ("sls %5\n\tjra %l6", loperands);
  1488. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1489. CODE_LABEL_NUMBER (loperands[4]));
  1490. output_asm_insn ("sle %5", loperands);
  1491. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1492. CODE_LABEL_NUMBER (loperands[6]));
  1493. break;
  1494. case LEU:
  1495. (*targetm.asm_out.internal_label) (asm_out_file, "L",
  1496. CODE_LABEL_NUMBER (loperands[4]));
  1497. output_asm_insn ("sls %5", loperands);
  1498. break;
  1499. default:
  1500. gcc_unreachable ();
  1501. }
  1502. return "";
  1503. }
  1504. const char *
  1505. output_btst (rtx *operands, rtx countop, rtx dataop, rtx_insn *insn, int signpos)
  1506. {
  1507. operands[0] = countop;
  1508. operands[1] = dataop;
  1509. if (GET_CODE (countop) == CONST_INT)
  1510. {
  1511. register int count = INTVAL (countop);
  1512. /* If COUNT is bigger than size of storage unit in use,
  1513. advance to the containing unit of same size. */
  1514. if (count > signpos)
  1515. {
  1516. int offset = (count & ~signpos) / 8;
  1517. count = count & signpos;
  1518. operands[1] = dataop = adjust_address (dataop, QImode, offset);
  1519. }
  1520. if (count == signpos)
  1521. cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
  1522. else
  1523. cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
  1524. /* These three statements used to use next_insns_test_no...
  1525. but it appears that this should do the same job. */
  1526. if (count == 31
  1527. && next_insn_tests_no_inequality (insn))
  1528. return "tst%.l %1";
  1529. if (count == 15
  1530. && next_insn_tests_no_inequality (insn))
  1531. return "tst%.w %1";
  1532. if (count == 7
  1533. && next_insn_tests_no_inequality (insn))
  1534. return "tst%.b %1";
  1535. /* Try to use `movew to ccr' followed by the appropriate branch insn.
  1536. On some m68k variants unfortunately that's slower than btst.
  1537. On 68000 and higher, that should also work for all HImode operands. */
  1538. if (TUNE_CPU32 || TARGET_COLDFIRE || optimize_size)
  1539. {
  1540. if (count == 3 && DATA_REG_P (operands[1])
  1541. && next_insn_tests_no_inequality (insn))
  1542. {
  1543. cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N | CC_NO_OVERFLOW;
  1544. return "move%.w %1,%%ccr";
  1545. }
  1546. if (count == 2 && DATA_REG_P (operands[1])
  1547. && next_insn_tests_no_inequality (insn))
  1548. {
  1549. cc_status.flags = CC_NOT_NEGATIVE | CC_INVERTED | CC_NO_OVERFLOW;
  1550. return "move%.w %1,%%ccr";
  1551. }
  1552. /* count == 1 followed by bvc/bvs and
  1553. count == 0 followed by bcc/bcs are also possible, but need
  1554. m68k-specific CC_Z_IN_NOT_V and CC_Z_IN_NOT_C flags. */
  1555. }
  1556. cc_status.flags = CC_NOT_NEGATIVE;
  1557. }
  1558. return "btst %0,%1";
  1559. }
  1560. /* Return true if X is a legitimate base register. STRICT_P says
  1561. whether we need strict checking. */
  1562. bool
  1563. m68k_legitimate_base_reg_p (rtx x, bool strict_p)
  1564. {
  1565. /* Allow SUBREG everywhere we allow REG. This results in better code. */
  1566. if (!strict_p && GET_CODE (x) == SUBREG)
  1567. x = SUBREG_REG (x);
  1568. return (REG_P (x)
  1569. && (strict_p
  1570. ? REGNO_OK_FOR_BASE_P (REGNO (x))
  1571. : REGNO_OK_FOR_BASE_NONSTRICT_P (REGNO (x))));
  1572. }
  1573. /* Return true if X is a legitimate index register. STRICT_P says
  1574. whether we need strict checking. */
  1575. bool
  1576. m68k_legitimate_index_reg_p (rtx x, bool strict_p)
  1577. {
  1578. if (!strict_p && GET_CODE (x) == SUBREG)
  1579. x = SUBREG_REG (x);
  1580. return (REG_P (x)
  1581. && (strict_p
  1582. ? REGNO_OK_FOR_INDEX_P (REGNO (x))
  1583. : REGNO_OK_FOR_INDEX_NONSTRICT_P (REGNO (x))));
  1584. }
  1585. /* Return true if X is a legitimate index expression for a (d8,An,Xn) or
  1586. (bd,An,Xn) addressing mode. Fill in the INDEX and SCALE fields of
  1587. ADDRESS if so. STRICT_P says whether we need strict checking. */
  1588. static bool
  1589. m68k_decompose_index (rtx x, bool strict_p, struct m68k_address *address)
  1590. {
  1591. int scale;
  1592. /* Check for a scale factor. */
  1593. scale = 1;
  1594. if ((TARGET_68020 || TARGET_COLDFIRE)
  1595. && GET_CODE (x) == MULT
  1596. && GET_CODE (XEXP (x, 1)) == CONST_INT
  1597. && (INTVAL (XEXP (x, 1)) == 2
  1598. || INTVAL (XEXP (x, 1)) == 4
  1599. || (INTVAL (XEXP (x, 1)) == 8
  1600. && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE))))
  1601. {
  1602. scale = INTVAL (XEXP (x, 1));
  1603. x = XEXP (x, 0);
  1604. }
  1605. /* Check for a word extension. */
  1606. if (!TARGET_COLDFIRE
  1607. && GET_CODE (x) == SIGN_EXTEND
  1608. && GET_MODE (XEXP (x, 0)) == HImode)
  1609. x = XEXP (x, 0);
  1610. if (m68k_legitimate_index_reg_p (x, strict_p))
  1611. {
  1612. address->scale = scale;
  1613. address->index = x;
  1614. return true;
  1615. }
  1616. return false;
  1617. }
  1618. /* Return true if X is an illegitimate symbolic constant. */
  1619. bool
  1620. m68k_illegitimate_symbolic_constant_p (rtx x)
  1621. {
  1622. rtx base, offset;
  1623. if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
  1624. {
  1625. split_const (x, &base, &offset);
  1626. if (GET_CODE (base) == SYMBOL_REF
  1627. && !offset_within_block_p (base, INTVAL (offset)))
  1628. return true;
  1629. }
  1630. return m68k_tls_reference_p (x, false);
  1631. }
  1632. /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
  1633. static bool
  1634. m68k_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
  1635. {
  1636. return m68k_illegitimate_symbolic_constant_p (x);
  1637. }
  1638. /* Return true if X is a legitimate constant address that can reach
  1639. bytes in the range [X, X + REACH). STRICT_P says whether we need
  1640. strict checking. */
  1641. static bool
  1642. m68k_legitimate_constant_address_p (rtx x, unsigned int reach, bool strict_p)
  1643. {
  1644. rtx base, offset;
  1645. if (!CONSTANT_ADDRESS_P (x))
  1646. return false;
  1647. if (flag_pic
  1648. && !(strict_p && TARGET_PCREL)
  1649. && symbolic_operand (x, VOIDmode))
  1650. return false;
  1651. if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P && reach > 1)
  1652. {
  1653. split_const (x, &base, &offset);
  1654. if (GET_CODE (base) == SYMBOL_REF
  1655. && !offset_within_block_p (base, INTVAL (offset) + reach - 1))
  1656. return false;
  1657. }
  1658. return !m68k_tls_reference_p (x, false);
  1659. }
  1660. /* Return true if X is a LABEL_REF for a jump table. Assume that unplaced
  1661. labels will become jump tables. */
  1662. static bool
  1663. m68k_jump_table_ref_p (rtx x)
  1664. {
  1665. if (GET_CODE (x) != LABEL_REF)
  1666. return false;
  1667. rtx_insn *insn = as_a <rtx_insn *> (XEXP (x, 0));
  1668. if (!NEXT_INSN (insn) && !PREV_INSN (insn))
  1669. return true;
  1670. insn = next_nonnote_insn (insn);
  1671. return insn && JUMP_TABLE_DATA_P (insn);
  1672. }
  1673. /* Return true if X is a legitimate address for values of mode MODE.
  1674. STRICT_P says whether strict checking is needed. If the address
  1675. is valid, describe its components in *ADDRESS. */
  1676. static bool
  1677. m68k_decompose_address (machine_mode mode, rtx x,
  1678. bool strict_p, struct m68k_address *address)
  1679. {
  1680. unsigned int reach;
  1681. memset (address, 0, sizeof (*address));
  1682. if (mode == BLKmode)
  1683. reach = 1;
  1684. else
  1685. reach = GET_MODE_SIZE (mode);
  1686. /* Check for (An) (mode 2). */
  1687. if (m68k_legitimate_base_reg_p (x, strict_p))
  1688. {
  1689. address->base = x;
  1690. return true;
  1691. }
  1692. /* Check for -(An) and (An)+ (modes 3 and 4). */
  1693. if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC)
  1694. && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p))
  1695. {
  1696. address->code = GET_CODE (x);
  1697. address->base = XEXP (x, 0);
  1698. return true;
  1699. }
  1700. /* Check for (d16,An) (mode 5). */
  1701. if (GET_CODE (x) == PLUS
  1702. && GET_CODE (XEXP (x, 1)) == CONST_INT
  1703. && IN_RANGE (INTVAL (XEXP (x, 1)), -0x8000, 0x8000 - reach)
  1704. && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p))
  1705. {
  1706. address->base = XEXP (x, 0);
  1707. address->offset = XEXP (x, 1);
  1708. return true;
  1709. }
  1710. /* Check for GOT loads. These are (bd,An,Xn) addresses if
  1711. TARGET_68020 && flag_pic == 2, otherwise they are (d16,An)
  1712. addresses. */
  1713. if (GET_CODE (x) == PLUS
  1714. && XEXP (x, 0) == pic_offset_table_rtx)
  1715. {
  1716. /* As we are processing a PLUS, do not unwrap RELOC32 symbols --
  1717. they are invalid in this context. */
  1718. if (m68k_unwrap_symbol (XEXP (x, 1), false) != XEXP (x, 1))
  1719. {
  1720. address->base = XEXP (x, 0);
  1721. address->offset = XEXP (x, 1);
  1722. return true;
  1723. }
  1724. }
  1725. /* The ColdFire FPU only accepts addressing modes 2-5. */
  1726. if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT)
  1727. return false;
  1728. /* Check for (xxx).w and (xxx).l. Also, in the TARGET_PCREL case,
  1729. check for (d16,PC) or (bd,PC,Xn) with a suppressed index register.
  1730. All these modes are variations of mode 7. */
  1731. if (m68k_legitimate_constant_address_p (x, reach, strict_p))
  1732. {
  1733. address->offset = x;
  1734. return true;
  1735. }
  1736. /* Check for (d8,PC,Xn), a mode 7 form. This case is needed for
  1737. tablejumps.
  1738. ??? do_tablejump creates these addresses before placing the target
  1739. label, so we have to assume that unplaced labels are jump table
  1740. references. It seems unlikely that we would ever generate indexed
  1741. accesses to unplaced labels in other cases. */
  1742. if (GET_CODE (x) == PLUS
  1743. && m68k_jump_table_ref_p (XEXP (x, 1))
  1744. && m68k_decompose_index (XEXP (x, 0), strict_p, address))
  1745. {
  1746. address->offset = XEXP (x, 1);
  1747. return true;
  1748. }
  1749. /* Everything hereafter deals with (d8,An,Xn.SIZE*SCALE) or
  1750. (bd,An,Xn.SIZE*SCALE) addresses. */
  1751. if (TARGET_68020)
  1752. {
  1753. /* Check for a nonzero base displacement. */
  1754. if (GET_CODE (x) == PLUS
  1755. && m68k_legitimate_constant_address_p (XEXP (x, 1), reach, strict_p))
  1756. {
  1757. address->offset = XEXP (x, 1);
  1758. x = XEXP (x, 0);
  1759. }
  1760. /* Check for a suppressed index register. */
  1761. if (m68k_legitimate_base_reg_p (x, strict_p))
  1762. {
  1763. address->base = x;
  1764. return true;
  1765. }
  1766. /* Check for a suppressed base register. Do not allow this case
  1767. for non-symbolic offsets as it effectively gives gcc freedom
  1768. to treat data registers as base registers, which can generate
  1769. worse code. */
  1770. if (address->offset
  1771. && symbolic_operand (address->offset, VOIDmode)
  1772. && m68k_decompose_index (x, strict_p, address))
  1773. return true;
  1774. }
  1775. else
  1776. {
  1777. /* Check for a nonzero base displacement. */
  1778. if (GET_CODE (x) == PLUS
  1779. && GET_CODE (XEXP (x, 1)) == CONST_INT
  1780. && IN_RANGE (INTVAL (XEXP (x, 1)), -0x80, 0x80 - reach))
  1781. {
  1782. address->offset = XEXP (x, 1);
  1783. x = XEXP (x, 0);
  1784. }
  1785. }
  1786. /* We now expect the sum of a base and an index. */
  1787. if (GET_CODE (x) == PLUS)
  1788. {
  1789. if (m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p)
  1790. && m68k_decompose_index (XEXP (x, 1), strict_p, address))
  1791. {
  1792. address->base = XEXP (x, 0);
  1793. return true;
  1794. }
  1795. if (m68k_legitimate_base_reg_p (XEXP (x, 1), strict_p)
  1796. && m68k_decompose_index (XEXP (x, 0), strict_p, address))
  1797. {
  1798. address->base = XEXP (x, 1);
  1799. return true;
  1800. }
  1801. }
  1802. return false;
  1803. }
  1804. /* Return true if X is a legitimate address for values of mode MODE.
  1805. STRICT_P says whether strict checking is needed. */
  1806. bool
  1807. m68k_legitimate_address_p (machine_mode mode, rtx x, bool strict_p)
  1808. {
  1809. struct m68k_address address;
  1810. return m68k_decompose_address (mode, x, strict_p, &address);
  1811. }
  1812. /* Return true if X is a memory, describing its address in ADDRESS if so.
  1813. Apply strict checking if called during or after reload. */
  1814. static bool
  1815. m68k_legitimate_mem_p (rtx x, struct m68k_address *address)
  1816. {
  1817. return (MEM_P (x)
  1818. && m68k_decompose_address (GET_MODE (x), XEXP (x, 0),
  1819. reload_in_progress || reload_completed,
  1820. address));
  1821. }
  1822. /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
  1823. bool
  1824. m68k_legitimate_constant_p (machine_mode mode, rtx x)
  1825. {
  1826. return mode != XFmode && !m68k_illegitimate_symbolic_constant_p (x);
  1827. }
  1828. /* Return true if X matches the 'Q' constraint. It must be a memory
  1829. with a base address and no constant offset or index. */
  1830. bool
  1831. m68k_matches_q_p (rtx x)
  1832. {
  1833. struct m68k_address address;
  1834. return (m68k_legitimate_mem_p (x, &address)
  1835. && address.code == UNKNOWN
  1836. && address.base
  1837. && !address.offset
  1838. && !address.index);
  1839. }
  1840. /* Return true if X matches the 'U' constraint. It must be a base address
  1841. with a constant offset and no index. */
  1842. bool
  1843. m68k_matches_u_p (rtx x)
  1844. {
  1845. struct m68k_address address;
  1846. return (m68k_legitimate_mem_p (x, &address)
  1847. && address.code == UNKNOWN
  1848. && address.base
  1849. && address.offset
  1850. && !address.index);
  1851. }
  1852. /* Return GOT pointer. */
  1853. static rtx
  1854. m68k_get_gp (void)
  1855. {
  1856. if (pic_offset_table_rtx == NULL_RTX)
  1857. pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_REG);
  1858. crtl->uses_pic_offset_table = 1;
  1859. return pic_offset_table_rtx;
  1860. }
  1861. /* M68K relocations, used to distinguish GOT and TLS relocations in UNSPEC
  1862. wrappers. */
  1863. enum m68k_reloc { RELOC_GOT, RELOC_TLSGD, RELOC_TLSLDM, RELOC_TLSLDO,
  1864. RELOC_TLSIE, RELOC_TLSLE };
  1865. #define TLS_RELOC_P(RELOC) ((RELOC) != RELOC_GOT)
  1866. /* Wrap symbol X into unspec representing relocation RELOC.
  1867. BASE_REG - register that should be added to the result.
  1868. TEMP_REG - if non-null, temporary register. */
  1869. static rtx
  1870. m68k_wrap_symbol (rtx x, enum m68k_reloc reloc, rtx base_reg, rtx temp_reg)
  1871. {
  1872. bool use_x_p;
  1873. use_x_p = (base_reg == pic_offset_table_rtx) ? TARGET_XGOT : TARGET_XTLS;
  1874. if (TARGET_COLDFIRE && use_x_p)
  1875. /* When compiling with -mx{got, tls} switch the code will look like this:
  1876. move.l <X>@<RELOC>,<TEMP_REG>
  1877. add.l <BASE_REG>,<TEMP_REG> */
  1878. {
  1879. /* Wrap X in UNSPEC_??? to tip m68k_output_addr_const_extra
  1880. to put @RELOC after reference. */
  1881. x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)),
  1882. UNSPEC_RELOC32);
  1883. x = gen_rtx_CONST (Pmode, x);
  1884. if (temp_reg == NULL)
  1885. {
  1886. gcc_assert (can_create_pseudo_p ());
  1887. temp_reg = gen_reg_rtx (Pmode);
  1888. }
  1889. emit_move_insn (temp_reg, x);
  1890. emit_insn (gen_addsi3 (temp_reg, temp_reg, base_reg));
  1891. x = temp_reg;
  1892. }
  1893. else
  1894. {
  1895. x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)),
  1896. UNSPEC_RELOC16);
  1897. x = gen_rtx_CONST (Pmode, x);
  1898. x = gen_rtx_PLUS (Pmode, base_reg, x);
  1899. }
  1900. return x;
  1901. }
  1902. /* Helper for m68k_unwrap_symbol.
  1903. Also, if unwrapping was successful (that is if (ORIG != <return value>)),
  1904. sets *RELOC_PTR to relocation type for the symbol. */
  1905. static rtx
  1906. m68k_unwrap_symbol_1 (rtx orig, bool unwrap_reloc32_p,
  1907. enum m68k_reloc *reloc_ptr)
  1908. {
  1909. if (GET_CODE (orig) == CONST)
  1910. {
  1911. rtx x;
  1912. enum m68k_reloc dummy;
  1913. x = XEXP (orig, 0);
  1914. if (reloc_ptr == NULL)
  1915. reloc_ptr = &dummy;
  1916. /* Handle an addend. */
  1917. if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
  1918. && CONST_INT_P (XEXP (x, 1)))
  1919. x = XEXP (x, 0);
  1920. if (GET_CODE (x) == UNSPEC)
  1921. {
  1922. switch (XINT (x, 1))
  1923. {
  1924. case UNSPEC_RELOC16:
  1925. orig = XVECEXP (x, 0, 0);
  1926. *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1));
  1927. break;
  1928. case UNSPEC_RELOC32:
  1929. if (unwrap_reloc32_p)
  1930. {
  1931. orig = XVECEXP (x, 0, 0);
  1932. *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1));
  1933. }
  1934. break;
  1935. default:
  1936. break;
  1937. }
  1938. }
  1939. }
  1940. return orig;
  1941. }
  1942. /* Unwrap symbol from UNSPEC_RELOC16 and, if unwrap_reloc32_p,
  1943. UNSPEC_RELOC32 wrappers. */
  1944. rtx
  1945. m68k_unwrap_symbol (rtx orig, bool unwrap_reloc32_p)
  1946. {
  1947. return m68k_unwrap_symbol_1 (orig, unwrap_reloc32_p, NULL);
  1948. }
  1949. /* Prescan insn before outputing assembler for it. */
  1950. void
  1951. m68k_final_prescan_insn (rtx_insn *insn ATTRIBUTE_UNUSED,
  1952. rtx *operands, int n_operands)
  1953. {
  1954. int i;
  1955. /* Combine and, possibly, other optimizations may do good job
  1956. converting
  1957. (const (unspec [(symbol)]))
  1958. into
  1959. (const (plus (unspec [(symbol)])
  1960. (const_int N))).
  1961. The problem with this is emitting @TLS or @GOT decorations.
  1962. The decoration is emitted when processing (unspec), so the
  1963. result would be "#symbol@TLSLE+N" instead of "#symbol+N@TLSLE".
  1964. It seems that the easiest solution to this is to convert such
  1965. operands to
  1966. (const (unspec [(plus (symbol)
  1967. (const_int N))])).
  1968. Note, that the top level of operand remains intact, so we don't have
  1969. to patch up anything outside of the operand. */
  1970. subrtx_var_iterator::array_type array;
  1971. for (i = 0; i < n_operands; ++i)
  1972. {
  1973. rtx op;
  1974. op = operands[i];
  1975. FOR_EACH_SUBRTX_VAR (iter, array, op, ALL)
  1976. {
  1977. rtx x = *iter;
  1978. if (m68k_unwrap_symbol (x, true) != x)
  1979. {
  1980. rtx plus;
  1981. gcc_assert (GET_CODE (x) == CONST);
  1982. plus = XEXP (x, 0);
  1983. if (GET_CODE (plus) == PLUS || GET_CODE (plus) == MINUS)
  1984. {
  1985. rtx unspec;
  1986. rtx addend;
  1987. unspec = XEXP (plus, 0);
  1988. gcc_assert (GET_CODE (unspec) == UNSPEC);
  1989. addend = XEXP (plus, 1);
  1990. gcc_assert (CONST_INT_P (addend));
  1991. /* We now have all the pieces, rearrange them. */
  1992. /* Move symbol to plus. */
  1993. XEXP (plus, 0) = XVECEXP (unspec, 0, 0);
  1994. /* Move plus inside unspec. */
  1995. XVECEXP (unspec, 0, 0) = plus;
  1996. /* Move unspec to top level of const. */
  1997. XEXP (x, 0) = unspec;
  1998. }
  1999. iter.skip_subrtxes ();
  2000. }
  2001. }
  2002. }
  2003. }
  2004. /* Move X to a register and add REG_EQUAL note pointing to ORIG.
  2005. If REG is non-null, use it; generate new pseudo otherwise. */
  2006. static rtx
  2007. m68k_move_to_reg (rtx x, rtx orig, rtx reg)
  2008. {
  2009. rtx_insn *insn;
  2010. if (reg == NULL_RTX)
  2011. {
  2012. gcc_assert (can_create_pseudo_p ());
  2013. reg = gen_reg_rtx (Pmode);
  2014. }
  2015. insn = emit_move_insn (reg, x);
  2016. /* Put a REG_EQUAL note on this insn, so that it can be optimized
  2017. by loop. */
  2018. set_unique_reg_note (insn, REG_EQUAL, orig);
  2019. return reg;
  2020. }
  2021. /* Does the same as m68k_wrap_symbol, but returns a memory reference to
  2022. GOT slot. */
  2023. static rtx
  2024. m68k_wrap_symbol_into_got_ref (rtx x, enum m68k_reloc reloc, rtx temp_reg)
  2025. {
  2026. x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), temp_reg);
  2027. x = gen_rtx_MEM (Pmode, x);
  2028. MEM_READONLY_P (x) = 1;
  2029. return x;
  2030. }
  2031. /* Legitimize PIC addresses. If the address is already
  2032. position-independent, we return ORIG. Newly generated
  2033. position-independent addresses go to REG. If we need more
  2034. than one register, we lose.
  2035. An address is legitimized by making an indirect reference
  2036. through the Global Offset Table with the name of the symbol
  2037. used as an offset.
  2038. The assembler and linker are responsible for placing the
  2039. address of the symbol in the GOT. The function prologue
  2040. is responsible for initializing a5 to the starting address
  2041. of the GOT.
  2042. The assembler is also responsible for translating a symbol name
  2043. into a constant displacement from the start of the GOT.
  2044. A quick example may make things a little clearer:
  2045. When not generating PIC code to store the value 12345 into _foo
  2046. we would generate the following code:
  2047. movel #12345, _foo
  2048. When generating PIC two transformations are made. First, the compiler
  2049. loads the address of foo into a register. So the first transformation makes:
  2050. lea _foo, a0
  2051. movel #12345, a0@
  2052. The code in movsi will intercept the lea instruction and call this
  2053. routine which will transform the instructions into:
  2054. movel a5@(_foo:w), a0
  2055. movel #12345, a0@
  2056. That (in a nutshell) is how *all* symbol and label references are
  2057. handled. */
  2058. rtx
  2059. legitimize_pic_address (rtx orig, machine_mode mode ATTRIBUTE_UNUSED,
  2060. rtx reg)
  2061. {
  2062. rtx pic_ref = orig;
  2063. /* First handle a simple SYMBOL_REF or LABEL_REF */
  2064. if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
  2065. {
  2066. gcc_assert (reg);
  2067. pic_ref = m68k_wrap_symbol_into_got_ref (orig, RELOC_GOT, reg);
  2068. pic_ref = m68k_move_to_reg (pic_ref, orig, reg);
  2069. }
  2070. else if (GET_CODE (orig) == CONST)
  2071. {
  2072. rtx base;
  2073. /* Make sure this has not already been legitimized. */
  2074. if (m68k_unwrap_symbol (orig, true) != orig)
  2075. return orig;
  2076. gcc_assert (reg);
  2077. /* legitimize both operands of the PLUS */
  2078. gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
  2079. base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
  2080. orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
  2081. base == reg ? 0 : reg);
  2082. if (GET_CODE (orig) == CONST_INT)
  2083. pic_ref = plus_constant (Pmode, base, INTVAL (orig));
  2084. else
  2085. pic_ref = gen_rtx_PLUS (Pmode, base, orig);
  2086. }
  2087. return pic_ref;
  2088. }
  2089. /* The __tls_get_addr symbol. */
  2090. static GTY(()) rtx m68k_tls_get_addr;
  2091. /* Return SYMBOL_REF for __tls_get_addr. */
  2092. static rtx
  2093. m68k_get_tls_get_addr (void)
  2094. {
  2095. if (m68k_tls_get_addr == NULL_RTX)
  2096. m68k_tls_get_addr = init_one_libfunc ("__tls_get_addr");
  2097. return m68k_tls_get_addr;
  2098. }
  2099. /* Return libcall result in A0 instead of usual D0. */
  2100. static bool m68k_libcall_value_in_a0_p = false;
  2101. /* Emit instruction sequence that calls __tls_get_addr. X is
  2102. the TLS symbol we are referencing and RELOC is the symbol type to use
  2103. (either TLSGD or TLSLDM). EQV is the REG_EQUAL note for the sequence
  2104. emitted. A pseudo register with result of __tls_get_addr call is
  2105. returned. */
  2106. static rtx
  2107. m68k_call_tls_get_addr (rtx x, rtx eqv, enum m68k_reloc reloc)
  2108. {
  2109. rtx a0;
  2110. rtx_insn *insns;
  2111. rtx dest;
  2112. /* Emit the call sequence. */
  2113. start_sequence ();
  2114. /* FIXME: Unfortunately, emit_library_call_value does not
  2115. consider (plus (%a5) (const (unspec))) to be a good enough
  2116. operand for push, so it forces it into a register. The bad
  2117. thing about this is that combiner, due to copy propagation and other
  2118. optimizations, sometimes can not later fix this. As a consequence,
  2119. additional register may be allocated resulting in a spill.
  2120. For reference, see args processing loops in
  2121. calls.c:emit_library_call_value_1.
  2122. For testcase, see gcc.target/m68k/tls-{gd, ld}.c */
  2123. x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), NULL_RTX);
  2124. /* __tls_get_addr() is not a libcall, but emitting a libcall_value
  2125. is the simpliest way of generating a call. The difference between
  2126. __tls_get_addr() and libcall is that the result is returned in D0
  2127. instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
  2128. which temporarily switches returning the result to A0. */
  2129. m68k_libcall_value_in_a0_p = true;
  2130. a0 = emit_library_call_value (m68k_get_tls_get_addr (), NULL_RTX, LCT_PURE,
  2131. Pmode, 1, x, Pmode);
  2132. m68k_libcall_value_in_a0_p = false;
  2133. insns = get_insns ();
  2134. end_sequence ();
  2135. gcc_assert (can_create_pseudo_p ());
  2136. dest = gen_reg_rtx (Pmode);
  2137. emit_libcall_block (insns, dest, a0, eqv);
  2138. return dest;
  2139. }
  2140. /* The __tls_get_addr symbol. */
  2141. static GTY(()) rtx m68k_read_tp;
  2142. /* Return SYMBOL_REF for __m68k_read_tp. */
  2143. static rtx
  2144. m68k_get_m68k_read_tp (void)
  2145. {
  2146. if (m68k_read_tp == NULL_RTX)
  2147. m68k_read_tp = init_one_libfunc ("__m68k_read_tp");
  2148. return m68k_read_tp;
  2149. }
  2150. /* Emit instruction sequence that calls __m68k_read_tp.
  2151. A pseudo register with result of __m68k_read_tp call is returned. */
  2152. static rtx
  2153. m68k_call_m68k_read_tp (void)
  2154. {
  2155. rtx a0;
  2156. rtx eqv;
  2157. rtx_insn *insns;
  2158. rtx dest;
  2159. start_sequence ();
  2160. /* __m68k_read_tp() is not a libcall, but emitting a libcall_value
  2161. is the simpliest way of generating a call. The difference between
  2162. __m68k_read_tp() and libcall is that the result is returned in D0
  2163. instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
  2164. which temporarily switches returning the result to A0. */
  2165. /* Emit the call sequence. */
  2166. m68k_libcall_value_in_a0_p = true;
  2167. a0 = emit_library_call_value (m68k_get_m68k_read_tp (), NULL_RTX, LCT_PURE,
  2168. Pmode, 0);
  2169. m68k_libcall_value_in_a0_p = false;
  2170. insns = get_insns ();
  2171. end_sequence ();
  2172. /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
  2173. share the m68k_read_tp result with other IE/LE model accesses. */
  2174. eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), UNSPEC_RELOC32);
  2175. gcc_assert (can_create_pseudo_p ());
  2176. dest = gen_reg_rtx (Pmode);
  2177. emit_libcall_block (insns, dest, a0, eqv);
  2178. return dest;
  2179. }
  2180. /* Return a legitimized address for accessing TLS SYMBOL_REF X.
  2181. For explanations on instructions sequences see TLS/NPTL ABI for m68k and
  2182. ColdFire. */
  2183. rtx
  2184. m68k_legitimize_tls_address (rtx orig)
  2185. {
  2186. switch (SYMBOL_REF_TLS_MODEL (orig))
  2187. {
  2188. case TLS_MODEL_GLOBAL_DYNAMIC:
  2189. orig = m68k_call_tls_get_addr (orig, orig, RELOC_TLSGD);
  2190. break;
  2191. case TLS_MODEL_LOCAL_DYNAMIC:
  2192. {
  2193. rtx eqv;
  2194. rtx a0;
  2195. rtx x;
  2196. /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
  2197. share the LDM result with other LD model accesses. */
  2198. eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
  2199. UNSPEC_RELOC32);
  2200. a0 = m68k_call_tls_get_addr (orig, eqv, RELOC_TLSLDM);
  2201. x = m68k_wrap_symbol (orig, RELOC_TLSLDO, a0, NULL_RTX);
  2202. if (can_create_pseudo_p ())
  2203. x = m68k_move_to_reg (x, orig, NULL_RTX);
  2204. orig = x;
  2205. break;
  2206. }
  2207. case TLS_MODEL_INITIAL_EXEC:
  2208. {
  2209. rtx a0;
  2210. rtx x;
  2211. a0 = m68k_call_m68k_read_tp ();
  2212. x = m68k_wrap_symbol_into_got_ref (orig, RELOC_TLSIE, NULL_RTX);
  2213. x = gen_rtx_PLUS (Pmode, x, a0);
  2214. if (can_create_pseudo_p ())
  2215. x = m68k_move_to_reg (x, orig, NULL_RTX);
  2216. orig = x;
  2217. break;
  2218. }
  2219. case TLS_MODEL_LOCAL_EXEC:
  2220. {
  2221. rtx a0;
  2222. rtx x;
  2223. a0 = m68k_call_m68k_read_tp ();
  2224. x = m68k_wrap_symbol (orig, RELOC_TLSLE, a0, NULL_RTX);
  2225. if (can_create_pseudo_p ())
  2226. x = m68k_move_to_reg (x, orig, NULL_RTX);
  2227. orig = x;
  2228. break;
  2229. }
  2230. default:
  2231. gcc_unreachable ();
  2232. }
  2233. return orig;
  2234. }
  2235. /* Return true if X is a TLS symbol. */
  2236. static bool
  2237. m68k_tls_symbol_p (rtx x)
  2238. {
  2239. if (!TARGET_HAVE_TLS)
  2240. return false;
  2241. if (GET_CODE (x) != SYMBOL_REF)
  2242. return false;
  2243. return SYMBOL_REF_TLS_MODEL (x) != 0;
  2244. }
  2245. /* If !LEGITIMATE_P, return true if X is a TLS symbol reference,
  2246. though illegitimate one.
  2247. If LEGITIMATE_P, return true if X is a legitimate TLS symbol reference. */
  2248. bool
  2249. m68k_tls_reference_p (rtx x, bool legitimate_p)
  2250. {
  2251. if (!TARGET_HAVE_TLS)
  2252. return false;
  2253. if (!legitimate_p)
  2254. {
  2255. subrtx_var_iterator::array_type array;
  2256. FOR_EACH_SUBRTX_VAR (iter, array, x, ALL)
  2257. {
  2258. rtx x = *iter;
  2259. /* Note: this is not the same as m68k_tls_symbol_p. */
  2260. if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
  2261. return true;
  2262. /* Don't recurse into legitimate TLS references. */
  2263. if (m68k_tls_reference_p (x, true))
  2264. iter.skip_subrtxes ();
  2265. }
  2266. return false;
  2267. }
  2268. else
  2269. {
  2270. enum m68k_reloc reloc = RELOC_GOT;
  2271. return (m68k_unwrap_symbol_1 (x, true, &reloc) != x
  2272. && TLS_RELOC_P (reloc));
  2273. }
  2274. }
  2275. #define USE_MOVQ(i) ((unsigned) ((i) + 128) <= 255)
  2276. /* Return the type of move that should be used for integer I. */
  2277. M68K_CONST_METHOD
  2278. m68k_const_method (HOST_WIDE_INT i)
  2279. {
  2280. unsigned u;
  2281. if (USE_MOVQ (i))
  2282. return MOVQ;
  2283. /* The ColdFire doesn't have byte or word operations. */
  2284. /* FIXME: This may not be useful for the m68060 either. */
  2285. if (!TARGET_COLDFIRE)
  2286. {
  2287. /* if -256 < N < 256 but N is not in range for a moveq
  2288. N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */
  2289. if (USE_MOVQ (i ^ 0xff))
  2290. return NOTB;
  2291. /* Likewise, try with not.w */
  2292. if (USE_MOVQ (i ^ 0xffff))
  2293. return NOTW;
  2294. /* This is the only value where neg.w is useful */
  2295. if (i == -65408)
  2296. return NEGW;
  2297. }
  2298. /* Try also with swap. */
  2299. u = i;
  2300. if (USE_MOVQ ((u >> 16) | (u << 16)))
  2301. return SWAP;
  2302. if (TARGET_ISAB)
  2303. {
  2304. /* Try using MVZ/MVS with an immediate value to load constants. */
  2305. if (i >= 0 && i <= 65535)
  2306. return MVZ;
  2307. if (i >= -32768 && i <= 32767)
  2308. return MVS;
  2309. }
  2310. /* Otherwise, use move.l */
  2311. return MOVL;
  2312. }
  2313. /* Return the cost of moving constant I into a data register. */
  2314. static int
  2315. const_int_cost (HOST_WIDE_INT i)
  2316. {
  2317. switch (m68k_const_method (i))
  2318. {
  2319. case MOVQ:
  2320. /* Constants between -128 and 127 are cheap due to moveq. */
  2321. return 0;
  2322. case MVZ:
  2323. case MVS:
  2324. case NOTB:
  2325. case NOTW:
  2326. case NEGW:
  2327. case SWAP:
  2328. /* Constants easily generated by moveq + not.b/not.w/neg.w/swap. */
  2329. return 1;
  2330. case MOVL:
  2331. return 2;
  2332. default:
  2333. gcc_unreachable ();
  2334. }
  2335. }
  2336. static bool
  2337. m68k_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
  2338. int *total, bool speed ATTRIBUTE_UNUSED)
  2339. {
  2340. switch (code)
  2341. {
  2342. case CONST_INT:
  2343. /* Constant zero is super cheap due to clr instruction. */
  2344. if (x == const0_rtx)
  2345. *total = 0;
  2346. else
  2347. *total = const_int_cost (INTVAL (x));
  2348. return true;
  2349. case CONST:
  2350. case LABEL_REF:
  2351. case SYMBOL_REF:
  2352. *total = 3;
  2353. return true;
  2354. case CONST_DOUBLE:
  2355. /* Make 0.0 cheaper than other floating constants to
  2356. encourage creating tstsf and tstdf insns. */
  2357. if (outer_code == COMPARE
  2358. && (x == CONST0_RTX (SFmode) || x == CONST0_RTX (DFmode)))
  2359. *total = 4;
  2360. else
  2361. *total = 5;
  2362. return true;
  2363. /* These are vaguely right for a 68020. */
  2364. /* The costs for long multiply have been adjusted to work properly
  2365. in synth_mult on the 68020, relative to an average of the time
  2366. for add and the time for shift, taking away a little more because
  2367. sometimes move insns are needed. */
  2368. /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS
  2369. terms. */
  2370. #define MULL_COST \
  2371. (TUNE_68060 ? 2 \
  2372. : TUNE_68040 ? 5 \
  2373. : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
  2374. : (TUNE_CFV2 && TUNE_MAC) ? 4 \
  2375. : TUNE_CFV2 ? 8 \
  2376. : TARGET_COLDFIRE ? 3 : 13)
  2377. #define MULW_COST \
  2378. (TUNE_68060 ? 2 \
  2379. : TUNE_68040 ? 3 \
  2380. : TUNE_68000_10 ? 5 \
  2381. : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
  2382. : (TUNE_CFV2 && TUNE_MAC) ? 2 \
  2383. : TUNE_CFV2 ? 8 \
  2384. : TARGET_COLDFIRE ? 2 : 8)
  2385. #define DIVW_COST \
  2386. (TARGET_CF_HWDIV ? 11 \
  2387. : TUNE_68000_10 || TARGET_COLDFIRE ? 12 : 27)
  2388. case PLUS:
  2389. /* An lea costs about three times as much as a simple add. */
  2390. if (GET_MODE (x) == SImode
  2391. && GET_CODE (XEXP (x, 1)) == REG
  2392. && GET_CODE (XEXP (x, 0)) == MULT
  2393. && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  2394. && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2395. && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2
  2396. || INTVAL (XEXP (XEXP (x, 0), 1)) == 4
  2397. || INTVAL (XEXP (XEXP (x, 0), 1)) == 8))
  2398. {
  2399. /* lea an@(dx:l:i),am */
  2400. *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);
  2401. return true;
  2402. }
  2403. return false;
  2404. case ASHIFT:
  2405. case ASHIFTRT:
  2406. case LSHIFTRT:
  2407. if (TUNE_68060)
  2408. {
  2409. *total = COSTS_N_INSNS(1);
  2410. return true;
  2411. }
  2412. if (TUNE_68000_10)
  2413. {
  2414. if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  2415. {
  2416. if (INTVAL (XEXP (x, 1)) < 16)
  2417. *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2;
  2418. else
  2419. /* We're using clrw + swap for these cases. */
  2420. *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2;
  2421. }
  2422. else
  2423. *total = COSTS_N_INSNS (10); /* Worst case. */
  2424. return true;
  2425. }
  2426. /* A shift by a big integer takes an extra instruction. */
  2427. if (GET_CODE (XEXP (x, 1)) == CONST_INT
  2428. && (INTVAL (XEXP (x, 1)) == 16))
  2429. {
  2430. *total = COSTS_N_INSNS (2); /* clrw;swap */
  2431. return true;
  2432. }
  2433. if (GET_CODE (XEXP (x, 1)) == CONST_INT
  2434. && !(INTVAL (XEXP (x, 1)) > 0
  2435. && INTVAL (XEXP (x, 1)) <= 8))
  2436. {
  2437. *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */
  2438. return true;
  2439. }
  2440. return false;
  2441. case MULT:
  2442. if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
  2443. || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
  2444. && GET_MODE (x) == SImode)
  2445. *total = COSTS_N_INSNS (MULW_COST);
  2446. else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
  2447. *total = COSTS_N_INSNS (MULW_COST);
  2448. else
  2449. *total = COSTS_N_INSNS (MULL_COST);
  2450. return true;
  2451. case DIV:
  2452. case UDIV:
  2453. case MOD:
  2454. case UMOD:
  2455. if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
  2456. *total = COSTS_N_INSNS (DIVW_COST); /* div.w */
  2457. else if (TARGET_CF_HWDIV)
  2458. *total = COSTS_N_INSNS (18);
  2459. else
  2460. *total = COSTS_N_INSNS (43); /* div.l */
  2461. return true;
  2462. case ZERO_EXTRACT:
  2463. if (outer_code == COMPARE)
  2464. *total = 0;
  2465. return false;
  2466. default:
  2467. return false;
  2468. }
  2469. }
  2470. /* Return an instruction to move CONST_INT OPERANDS[1] into data register
  2471. OPERANDS[0]. */
  2472. static const char *
  2473. output_move_const_into_data_reg (rtx *operands)
  2474. {
  2475. HOST_WIDE_INT i;
  2476. i = INTVAL (operands[1]);
  2477. switch (m68k_const_method (i))
  2478. {
  2479. case MVZ:
  2480. return "mvzw %1,%0";
  2481. case MVS:
  2482. return "mvsw %1,%0";
  2483. case MOVQ:
  2484. return "moveq %1,%0";
  2485. case NOTB:
  2486. CC_STATUS_INIT;
  2487. operands[1] = GEN_INT (i ^ 0xff);
  2488. return "moveq %1,%0\n\tnot%.b %0";
  2489. case NOTW:
  2490. CC_STATUS_INIT;
  2491. operands[1] = GEN_INT (i ^ 0xffff);
  2492. return "moveq %1,%0\n\tnot%.w %0";
  2493. case NEGW:
  2494. CC_STATUS_INIT;
  2495. return "moveq #-128,%0\n\tneg%.w %0";
  2496. case SWAP:
  2497. {
  2498. unsigned u = i;
  2499. operands[1] = GEN_INT ((u << 16) | (u >> 16));
  2500. return "moveq %1,%0\n\tswap %0";
  2501. }
  2502. case MOVL:
  2503. return "move%.l %1,%0";
  2504. default:
  2505. gcc_unreachable ();
  2506. }
  2507. }
  2508. /* Return true if I can be handled by ISA B's mov3q instruction. */
  2509. bool
  2510. valid_mov3q_const (HOST_WIDE_INT i)
  2511. {
  2512. return TARGET_ISAB && (i == -1 || IN_RANGE (i, 1, 7));
  2513. }
  2514. /* Return an instruction to move CONST_INT OPERANDS[1] into OPERANDS[0].
  2515. I is the value of OPERANDS[1]. */
  2516. static const char *
  2517. output_move_simode_const (rtx *operands)
  2518. {
  2519. rtx dest;
  2520. HOST_WIDE_INT src;
  2521. dest = operands[0];
  2522. src = INTVAL (operands[1]);
  2523. if (src == 0
  2524. && (DATA_REG_P (dest) || MEM_P (dest))
  2525. /* clr insns on 68000 read before writing. */
  2526. && ((TARGET_68010 || TARGET_COLDFIRE)
  2527. || !(MEM_P (dest) && MEM_VOLATILE_P (dest))))
  2528. return "clr%.l %0";
  2529. else if (GET_MODE (dest) == SImode && valid_mov3q_const (src))
  2530. return "mov3q%.l %1,%0";
  2531. else if (src == 0 && ADDRESS_REG_P (dest))
  2532. return "sub%.l %0,%0";
  2533. else if (DATA_REG_P (dest))
  2534. return output_move_const_into_data_reg (operands);
  2535. else if (ADDRESS_REG_P (dest) && IN_RANGE (src, -0x8000, 0x7fff))
  2536. {
  2537. if (valid_mov3q_const (src))
  2538. return "mov3q%.l %1,%0";
  2539. return "move%.w %1,%0";
  2540. }
  2541. else if (MEM_P (dest)
  2542. && GET_CODE (XEXP (dest, 0)) == PRE_DEC
  2543. && REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
  2544. && IN_RANGE (src, -0x8000, 0x7fff))
  2545. {
  2546. if (valid_mov3q_const (src))
  2547. return "mov3q%.l %1,%-";
  2548. return "pea %a1";
  2549. }
  2550. return "move%.l %1,%0";
  2551. }
  2552. const char *
  2553. output_move_simode (rtx *operands)
  2554. {
  2555. if (GET_CODE (operands[1]) == CONST_INT)
  2556. return output_move_simode_const (operands);
  2557. else if ((GET_CODE (operands[1]) == SYMBOL_REF
  2558. || GET_CODE (operands[1]) == CONST)
  2559. && push_operand (operands[0], SImode))
  2560. return "pea %a1";
  2561. else if ((GET_CODE (operands[1]) == SYMBOL_REF
  2562. || GET_CODE (operands[1]) == CONST)
  2563. && ADDRESS_REG_P (operands[0]))
  2564. return "lea %a1,%0";
  2565. return "move%.l %1,%0";
  2566. }
  2567. const char *
  2568. output_move_himode (rtx *operands)
  2569. {
  2570. if (GET_CODE (operands[1]) == CONST_INT)
  2571. {
  2572. if (operands[1] == const0_rtx
  2573. && (DATA_REG_P (operands[0])
  2574. || GET_CODE (operands[0]) == MEM)
  2575. /* clr insns on 68000 read before writing. */
  2576. && ((TARGET_68010 || TARGET_COLDFIRE)
  2577. || !(GET_CODE (operands[0]) == MEM
  2578. && MEM_VOLATILE_P (operands[0]))))
  2579. return "clr%.w %0";
  2580. else if (operands[1] == const0_rtx
  2581. && ADDRESS_REG_P (operands[0]))
  2582. return "sub%.l %0,%0";
  2583. else if (DATA_REG_P (operands[0])
  2584. && INTVAL (operands[1]) < 128
  2585. && INTVAL (operands[1]) >= -128)
  2586. return "moveq %1,%0";
  2587. else if (INTVAL (operands[1]) < 0x8000
  2588. && INTVAL (operands[1]) >= -0x8000)
  2589. return "move%.w %1,%0";
  2590. }
  2591. else if (CONSTANT_P (operands[1]))
  2592. return "move%.l %1,%0";
  2593. return "move%.w %1,%0";
  2594. }
  2595. const char *
  2596. output_move_qimode (rtx *operands)
  2597. {
  2598. /* 68k family always modifies the stack pointer by at least 2, even for
  2599. byte pushes. The 5200 (ColdFire) does not do this. */
  2600. /* This case is generated by pushqi1 pattern now. */
  2601. gcc_assert (!(GET_CODE (operands[0]) == MEM
  2602. && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
  2603. && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx
  2604. && ! ADDRESS_REG_P (operands[1])
  2605. && ! TARGET_COLDFIRE));
  2606. /* clr and st insns on 68000 read before writing. */
  2607. if (!ADDRESS_REG_P (operands[0])
  2608. && ((TARGET_68010 || TARGET_COLDFIRE)
  2609. || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
  2610. {
  2611. if (operands[1] == const0_rtx)
  2612. return "clr%.b %0";
  2613. if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0]))
  2614. && GET_CODE (operands[1]) == CONST_INT
  2615. && (INTVAL (operands[1]) & 255) == 255)
  2616. {
  2617. CC_STATUS_INIT;
  2618. return "st %0";
  2619. }
  2620. }
  2621. if (GET_CODE (operands[1]) == CONST_INT
  2622. && DATA_REG_P (operands[0])
  2623. && INTVAL (operands[1]) < 128
  2624. && INTVAL (operands[1]) >= -128)
  2625. return "moveq %1,%0";
  2626. if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0]))
  2627. return "sub%.l %0,%0";
  2628. if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1]))
  2629. return "move%.l %1,%0";
  2630. /* 68k family (including the 5200 ColdFire) does not support byte moves to
  2631. from address registers. */
  2632. if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1]))
  2633. return "move%.w %1,%0";
  2634. return "move%.b %1,%0";
  2635. }
  2636. const char *
  2637. output_move_stricthi (rtx *operands)
  2638. {
  2639. if (operands[1] == const0_rtx
  2640. /* clr insns on 68000 read before writing. */
  2641. && ((TARGET_68010 || TARGET_COLDFIRE)
  2642. || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
  2643. return "clr%.w %0";
  2644. return "move%.w %1,%0";
  2645. }
  2646. const char *
  2647. output_move_strictqi (rtx *operands)
  2648. {
  2649. if (operands[1] == const0_rtx
  2650. /* clr insns on 68000 read before writing. */
  2651. && ((TARGET_68010 || TARGET_COLDFIRE)
  2652. || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
  2653. return "clr%.b %0";
  2654. return "move%.b %1,%0";
  2655. }
  2656. /* Return the best assembler insn template
  2657. for moving operands[1] into operands[0] as a fullword. */
  2658. static const char *
  2659. singlemove_string (rtx *operands)
  2660. {
  2661. if (GET_CODE (operands[1]) == CONST_INT)
  2662. return output_move_simode_const (operands);
  2663. return "move%.l %1,%0";
  2664. }
  2665. /* Output assembler or rtl code to perform a doubleword move insn
  2666. with operands OPERANDS.
  2667. Pointers to 3 helper functions should be specified:
  2668. HANDLE_REG_ADJUST to adjust a register by a small value,
  2669. HANDLE_COMPADR to compute an address and
  2670. HANDLE_MOVSI to move 4 bytes. */
  2671. static void
  2672. handle_move_double (rtx operands[2],
  2673. void (*handle_reg_adjust) (rtx, int),
  2674. void (*handle_compadr) (rtx [2]),
  2675. void (*handle_movsi) (rtx [2]))
  2676. {
  2677. enum
  2678. {
  2679. REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
  2680. } optype0, optype1;
  2681. rtx latehalf[2];
  2682. rtx middlehalf[2];
  2683. rtx xops[2];
  2684. rtx addreg0 = 0, addreg1 = 0;
  2685. int dest_overlapped_low = 0;
  2686. int size = GET_MODE_SIZE (GET_MODE (operands[0]));
  2687. middlehalf[0] = 0;
  2688. middlehalf[1] = 0;
  2689. /* First classify both operands. */
  2690. if (REG_P (operands[0]))
  2691. optype0 = REGOP;
  2692. else if (offsettable_memref_p (operands[0]))
  2693. optype0 = OFFSOP;
  2694. else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  2695. optype0 = POPOP;
  2696. else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  2697. optype0 = PUSHOP;
  2698. else if (GET_CODE (operands[0]) == MEM)
  2699. optype0 = MEMOP;
  2700. else
  2701. optype0 = RNDOP;
  2702. if (REG_P (operands[1]))
  2703. optype1 = REGOP;
  2704. else if (CONSTANT_P (operands[1]))
  2705. optype1 = CNSTOP;
  2706. else if (offsettable_memref_p (operands[1]))
  2707. optype1 = OFFSOP;
  2708. else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  2709. optype1 = POPOP;
  2710. else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  2711. optype1 = PUSHOP;
  2712. else if (GET_CODE (operands[1]) == MEM)
  2713. optype1 = MEMOP;
  2714. else
  2715. optype1 = RNDOP;
  2716. /* Check for the cases that the operand constraints are not supposed
  2717. to allow to happen. Generating code for these cases is
  2718. painful. */
  2719. gcc_assert (optype0 != RNDOP && optype1 != RNDOP);
  2720. /* If one operand is decrementing and one is incrementing
  2721. decrement the former register explicitly
  2722. and change that operand into ordinary indexing. */
  2723. if (optype0 == PUSHOP && optype1 == POPOP)
  2724. {
  2725. operands[0] = XEXP (XEXP (operands[0], 0), 0);
  2726. handle_reg_adjust (operands[0], -size);
  2727. if (GET_MODE (operands[1]) == XFmode)
  2728. operands[0] = gen_rtx_MEM (XFmode, operands[0]);
  2729. else if (GET_MODE (operands[0]) == DFmode)
  2730. operands[0] = gen_rtx_MEM (DFmode, operands[0]);
  2731. else
  2732. operands[0] = gen_rtx_MEM (DImode, operands[0]);
  2733. optype0 = OFFSOP;
  2734. }
  2735. if (optype0 == POPOP && optype1 == PUSHOP)
  2736. {
  2737. operands[1] = XEXP (XEXP (operands[1], 0), 0);
  2738. handle_reg_adjust (operands[1], -size);
  2739. if (GET_MODE (operands[1]) == XFmode)
  2740. operands[1] = gen_rtx_MEM (XFmode, operands[1]);
  2741. else if (GET_MODE (operands[1]) == DFmode)
  2742. operands[1] = gen_rtx_MEM (DFmode, operands[1]);
  2743. else
  2744. operands[1] = gen_rtx_MEM (DImode, operands[1]);
  2745. optype1 = OFFSOP;
  2746. }
  2747. /* If an operand is an unoffsettable memory ref, find a register
  2748. we can increment temporarily to make it refer to the second word. */
  2749. if (optype0 == MEMOP)
  2750. addreg0 = find_addr_reg (XEXP (operands[0], 0));
  2751. if (optype1 == MEMOP)
  2752. addreg1 = find_addr_reg (XEXP (operands[1], 0));
  2753. /* Ok, we can do one word at a time.
  2754. Normally we do the low-numbered word first,
  2755. but if either operand is autodecrementing then we
  2756. do the high-numbered word first.
  2757. In either case, set up in LATEHALF the operands to use
  2758. for the high-numbered word and in some cases alter the
  2759. operands in OPERANDS to be suitable for the low-numbered word. */
  2760. if (size == 12)
  2761. {
  2762. if (optype0 == REGOP)
  2763. {
  2764. latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
  2765. middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
  2766. }
  2767. else if (optype0 == OFFSOP)
  2768. {
  2769. middlehalf[0] = adjust_address (operands[0], SImode, 4);
  2770. latehalf[0] = adjust_address (operands[0], SImode, size - 4);
  2771. }
  2772. else
  2773. {
  2774. middlehalf[0] = adjust_address (operands[0], SImode, 0);
  2775. latehalf[0] = adjust_address (operands[0], SImode, 0);
  2776. }
  2777. if (optype1 == REGOP)
  2778. {
  2779. latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
  2780. middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
  2781. }
  2782. else if (optype1 == OFFSOP)
  2783. {
  2784. middlehalf[1] = adjust_address (operands[1], SImode, 4);
  2785. latehalf[1] = adjust_address (operands[1], SImode, size - 4);
  2786. }
  2787. else if (optype1 == CNSTOP)
  2788. {
  2789. if (GET_CODE (operands[1]) == CONST_DOUBLE)
  2790. {
  2791. REAL_VALUE_TYPE r;
  2792. long l[3];
  2793. REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  2794. REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  2795. operands[1] = GEN_INT (l[0]);
  2796. middlehalf[1] = GEN_INT (l[1]);
  2797. latehalf[1] = GEN_INT (l[2]);
  2798. }
  2799. else
  2800. {
  2801. /* No non-CONST_DOUBLE constant should ever appear
  2802. here. */
  2803. gcc_assert (!CONSTANT_P (operands[1]));
  2804. }
  2805. }
  2806. else
  2807. {
  2808. middlehalf[1] = adjust_address (operands[1], SImode, 0);
  2809. latehalf[1] = adjust_address (operands[1], SImode, 0);
  2810. }
  2811. }
  2812. else
  2813. /* size is not 12: */
  2814. {
  2815. if (optype0 == REGOP)
  2816. latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
  2817. else if (optype0 == OFFSOP)
  2818. latehalf[0] = adjust_address (operands[0], SImode, size - 4);
  2819. else
  2820. latehalf[0] = adjust_address (operands[0], SImode, 0);
  2821. if (optype1 == REGOP)
  2822. latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
  2823. else if (optype1 == OFFSOP)
  2824. latehalf[1] = adjust_address (operands[1], SImode, size - 4);
  2825. else if (optype1 == CNSTOP)
  2826. split_double (operands[1], &operands[1], &latehalf[1]);
  2827. else
  2828. latehalf[1] = adjust_address (operands[1], SImode, 0);
  2829. }
  2830. /* If insn is effectively movd N(REG),-(REG) then we will do the high
  2831. word first. We should use the adjusted operand 1 (which is N+4(REG))
  2832. for the low word as well, to compensate for the first decrement of
  2833. REG. */
  2834. if (optype0 == PUSHOP
  2835. && reg_overlap_mentioned_p (XEXP (XEXP (operands[0], 0), 0), operands[1]))
  2836. operands[1] = middlehalf[1] = latehalf[1];
  2837. /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
  2838. if the upper part of reg N does not appear in the MEM, arrange to
  2839. emit the move late-half first. Otherwise, compute the MEM address
  2840. into the upper part of N and use that as a pointer to the memory
  2841. operand. */
  2842. if (optype0 == REGOP
  2843. && (optype1 == OFFSOP || optype1 == MEMOP))
  2844. {
  2845. rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0]));
  2846. if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
  2847. && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  2848. {
  2849. /* If both halves of dest are used in the src memory address,
  2850. compute the address into latehalf of dest.
  2851. Note that this can't happen if the dest is two data regs. */
  2852. compadr:
  2853. xops[0] = latehalf[0];
  2854. xops[1] = XEXP (operands[1], 0);
  2855. handle_compadr (xops);
  2856. if (GET_MODE (operands[1]) == XFmode)
  2857. {
  2858. operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
  2859. middlehalf[1] = adjust_address (operands[1], DImode, size - 8);
  2860. latehalf[1] = adjust_address (operands[1], DImode, size - 4);
  2861. }
  2862. else
  2863. {
  2864. operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
  2865. latehalf[1] = adjust_address (operands[1], DImode, size - 4);
  2866. }
  2867. }
  2868. else if (size == 12
  2869. && reg_overlap_mentioned_p (middlehalf[0],
  2870. XEXP (operands[1], 0)))
  2871. {
  2872. /* Check for two regs used by both source and dest.
  2873. Note that this can't happen if the dest is all data regs.
  2874. It can happen if the dest is d6, d7, a0.
  2875. But in that case, latehalf is an addr reg, so
  2876. the code at compadr does ok. */
  2877. if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
  2878. || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  2879. goto compadr;
  2880. /* JRV says this can't happen: */
  2881. gcc_assert (!addreg0 && !addreg1);
  2882. /* Only the middle reg conflicts; simply put it last. */
  2883. handle_movsi (operands);
  2884. handle_movsi (latehalf);
  2885. handle_movsi (middlehalf);
  2886. return;
  2887. }
  2888. else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
  2889. /* If the low half of dest is mentioned in the source memory
  2890. address, the arrange to emit the move late half first. */
  2891. dest_overlapped_low = 1;
  2892. }
  2893. /* If one or both operands autodecrementing,
  2894. do the two words, high-numbered first. */
  2895. /* Likewise, the first move would clobber the source of the second one,
  2896. do them in the other order. This happens only for registers;
  2897. such overlap can't happen in memory unless the user explicitly
  2898. sets it up, and that is an undefined circumstance. */
  2899. if (optype0 == PUSHOP || optype1 == PUSHOP
  2900. || (optype0 == REGOP && optype1 == REGOP
  2901. && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
  2902. || REGNO (operands[0]) == REGNO (latehalf[1])))
  2903. || dest_overlapped_low)
  2904. {
  2905. /* Make any unoffsettable addresses point at high-numbered word. */
  2906. if (addreg0)
  2907. handle_reg_adjust (addreg0, size - 4);
  2908. if (addreg1)
  2909. handle_reg_adjust (addreg1, size - 4);
  2910. /* Do that word. */
  2911. handle_movsi (latehalf);
  2912. /* Undo the adds we just did. */
  2913. if (addreg0)
  2914. handle_reg_adjust (addreg0, -4);
  2915. if (addreg1)
  2916. handle_reg_adjust (addreg1, -4);
  2917. if (size == 12)
  2918. {
  2919. handle_movsi (middlehalf);
  2920. if (addreg0)
  2921. handle_reg_adjust (addreg0, -4);
  2922. if (addreg1)
  2923. handle_reg_adjust (addreg1, -4);
  2924. }
  2925. /* Do low-numbered word. */
  2926. handle_movsi (operands);
  2927. return;
  2928. }
  2929. /* Normal case: do the two words, low-numbered first. */
  2930. m68k_final_prescan_insn (NULL, operands, 2);
  2931. handle_movsi (operands);
  2932. /* Do the middle one of the three words for long double */
  2933. if (size == 12)
  2934. {
  2935. if (addreg0)
  2936. handle_reg_adjust (addreg0, 4);
  2937. if (addreg1)
  2938. handle_reg_adjust (addreg1, 4);
  2939. m68k_final_prescan_insn (NULL, middlehalf, 2);
  2940. handle_movsi (middlehalf);
  2941. }
  2942. /* Make any unoffsettable addresses point at high-numbered word. */
  2943. if (addreg0)
  2944. handle_reg_adjust (addreg0, 4);
  2945. if (addreg1)
  2946. handle_reg_adjust (addreg1, 4);
  2947. /* Do that word. */
  2948. m68k_final_prescan_insn (NULL, latehalf, 2);
  2949. handle_movsi (latehalf);
  2950. /* Undo the adds we just did. */
  2951. if (addreg0)
  2952. handle_reg_adjust (addreg0, -(size - 4));
  2953. if (addreg1)
  2954. handle_reg_adjust (addreg1, -(size - 4));
  2955. return;
  2956. }
  2957. /* Output assembler code to adjust REG by N. */
  2958. static void
  2959. output_reg_adjust (rtx reg, int n)
  2960. {
  2961. const char *s;
  2962. gcc_assert (GET_MODE (reg) == SImode
  2963. && -12 <= n && n != 0 && n <= 12);
  2964. switch (n)
  2965. {
  2966. case 12:
  2967. s = "add%.l #12,%0";
  2968. break;
  2969. case 8:
  2970. s = "addq%.l #8,%0";
  2971. break;
  2972. case 4:
  2973. s = "addq%.l #4,%0";
  2974. break;
  2975. case -12:
  2976. s = "sub%.l #12,%0";
  2977. break;
  2978. case -8:
  2979. s = "subq%.l #8,%0";
  2980. break;
  2981. case -4:
  2982. s = "subq%.l #4,%0";
  2983. break;
  2984. default:
  2985. gcc_unreachable ();
  2986. s = NULL;
  2987. }
  2988. output_asm_insn (s, &reg);
  2989. }
  2990. /* Emit rtl code to adjust REG by N. */
  2991. static void
  2992. emit_reg_adjust (rtx reg1, int n)
  2993. {
  2994. rtx reg2;
  2995. gcc_assert (GET_MODE (reg1) == SImode
  2996. && -12 <= n && n != 0 && n <= 12);
  2997. reg1 = copy_rtx (reg1);
  2998. reg2 = copy_rtx (reg1);
  2999. if (n < 0)
  3000. emit_insn (gen_subsi3 (reg1, reg2, GEN_INT (-n)));
  3001. else if (n > 0)
  3002. emit_insn (gen_addsi3 (reg1, reg2, GEN_INT (n)));
  3003. else
  3004. gcc_unreachable ();
  3005. }
  3006. /* Output assembler to load address OPERANDS[0] to register OPERANDS[1]. */
  3007. static void
  3008. output_compadr (rtx operands[2])
  3009. {
  3010. output_asm_insn ("lea %a1,%0", operands);
  3011. }
  3012. /* Output the best assembler insn for moving operands[1] into operands[0]
  3013. as a fullword. */
  3014. static void
  3015. output_movsi (rtx operands[2])
  3016. {
  3017. output_asm_insn (singlemove_string (operands), operands);
  3018. }
  3019. /* Copy OP and change its mode to MODE. */
  3020. static rtx
  3021. copy_operand (rtx op, machine_mode mode)
  3022. {
  3023. /* ??? This looks really ugly. There must be a better way
  3024. to change a mode on the operand. */
  3025. if (GET_MODE (op) != VOIDmode)
  3026. {
  3027. if (REG_P (op))
  3028. op = gen_rtx_REG (mode, REGNO (op));
  3029. else
  3030. {
  3031. op = copy_rtx (op);
  3032. PUT_MODE (op, mode);
  3033. }
  3034. }
  3035. return op;
  3036. }
  3037. /* Emit rtl code for moving operands[1] into operands[0] as a fullword. */
  3038. static void
  3039. emit_movsi (rtx operands[2])
  3040. {
  3041. operands[0] = copy_operand (operands[0], SImode);
  3042. operands[1] = copy_operand (operands[1], SImode);
  3043. emit_insn (gen_movsi (operands[0], operands[1]));
  3044. }
  3045. /* Output assembler code to perform a doubleword move insn
  3046. with operands OPERANDS. */
  3047. const char *
  3048. output_move_double (rtx *operands)
  3049. {
  3050. handle_move_double (operands,
  3051. output_reg_adjust, output_compadr, output_movsi);
  3052. return "";
  3053. }
  3054. /* Output rtl code to perform a doubleword move insn
  3055. with operands OPERANDS. */
  3056. void
  3057. m68k_emit_move_double (rtx operands[2])
  3058. {
  3059. handle_move_double (operands, emit_reg_adjust, emit_movsi, emit_movsi);
  3060. }
  3061. /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
  3062. new rtx with the correct mode. */
  3063. static rtx
  3064. force_mode (machine_mode mode, rtx orig)
  3065. {
  3066. if (mode == GET_MODE (orig))
  3067. return orig;
  3068. if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
  3069. abort ();
  3070. return gen_rtx_REG (mode, REGNO (orig));
  3071. }
  3072. static int
  3073. fp_reg_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
  3074. {
  3075. return reg_renumber && FP_REG_P (op);
  3076. }
  3077. /* Emit insns to move operands[1] into operands[0].
  3078. Return 1 if we have written out everything that needs to be done to
  3079. do the move. Otherwise, return 0 and the caller will emit the move
  3080. normally.
  3081. Note SCRATCH_REG may not be in the proper mode depending on how it
  3082. will be used. This routine is responsible for creating a new copy
  3083. of SCRATCH_REG in the proper mode. */
  3084. int
  3085. emit_move_sequence (rtx *operands, machine_mode mode, rtx scratch_reg)
  3086. {
  3087. register rtx operand0 = operands[0];
  3088. register rtx operand1 = operands[1];
  3089. register rtx tem;
  3090. if (scratch_reg
  3091. && reload_in_progress && GET_CODE (operand0) == REG
  3092. && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
  3093. operand0 = reg_equiv_mem (REGNO (operand0));
  3094. else if (scratch_reg
  3095. && reload_in_progress && GET_CODE (operand0) == SUBREG
  3096. && GET_CODE (SUBREG_REG (operand0)) == REG
  3097. && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
  3098. {
  3099. /* We must not alter SUBREG_BYTE (operand0) since that would confuse
  3100. the code which tracks sets/uses for delete_output_reload. */
  3101. rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
  3102. reg_equiv_mem (REGNO (SUBREG_REG (operand0))),
  3103. SUBREG_BYTE (operand0));
  3104. operand0 = alter_subreg (&temp, true);
  3105. }
  3106. if (scratch_reg
  3107. && reload_in_progress && GET_CODE (operand1) == REG
  3108. && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
  3109. operand1 = reg_equiv_mem (REGNO (operand1));
  3110. else if (scratch_reg
  3111. && reload_in_progress && GET_CODE (operand1) == SUBREG
  3112. && GET_CODE (SUBREG_REG (operand1)) == REG
  3113. && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
  3114. {
  3115. /* We must not alter SUBREG_BYTE (operand0) since that would confuse
  3116. the code which tracks sets/uses for delete_output_reload. */
  3117. rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
  3118. reg_equiv_mem (REGNO (SUBREG_REG (operand1))),
  3119. SUBREG_BYTE (operand1));
  3120. operand1 = alter_subreg (&temp, true);
  3121. }
  3122. if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
  3123. && ((tem = find_replacement (&XEXP (operand0, 0)))
  3124. != XEXP (operand0, 0)))
  3125. operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
  3126. if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
  3127. && ((tem = find_replacement (&XEXP (operand1, 0)))
  3128. != XEXP (operand1, 0)))
  3129. operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
  3130. /* Handle secondary reloads for loads/stores of FP registers where
  3131. the address is symbolic by using the scratch register */
  3132. if (fp_reg_operand (operand0, mode)
  3133. && ((GET_CODE (operand1) == MEM
  3134. && ! memory_address_p (DFmode, XEXP (operand1, 0)))
  3135. || ((GET_CODE (operand1) == SUBREG
  3136. && GET_CODE (XEXP (operand1, 0)) == MEM
  3137. && !memory_address_p (DFmode, XEXP (XEXP (operand1, 0), 0)))))
  3138. && scratch_reg)
  3139. {
  3140. if (GET_CODE (operand1) == SUBREG)
  3141. operand1 = XEXP (operand1, 0);
  3142. /* SCRATCH_REG will hold an address. We want
  3143. it in SImode regardless of what mode it was originally given
  3144. to us. */
  3145. scratch_reg = force_mode (SImode, scratch_reg);
  3146. /* D might not fit in 14 bits either; for such cases load D into
  3147. scratch reg. */
  3148. if (!memory_address_p (Pmode, XEXP (operand1, 0)))
  3149. {
  3150. emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
  3151. emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
  3152. Pmode,
  3153. XEXP (XEXP (operand1, 0), 0),
  3154. scratch_reg));
  3155. }
  3156. else
  3157. emit_move_insn (scratch_reg, XEXP (operand1, 0));
  3158. emit_insn (gen_rtx_SET (VOIDmode, operand0,
  3159. gen_rtx_MEM (mode, scratch_reg)));
  3160. return 1;
  3161. }
  3162. else if (fp_reg_operand (operand1, mode)
  3163. && ((GET_CODE (operand0) == MEM
  3164. && ! memory_address_p (DFmode, XEXP (operand0, 0)))
  3165. || ((GET_CODE (operand0) == SUBREG)
  3166. && GET_CODE (XEXP (operand0, 0)) == MEM
  3167. && !memory_address_p (DFmode, XEXP (XEXP (operand0, 0), 0))))
  3168. && scratch_reg)
  3169. {
  3170. if (GET_CODE (operand0) == SUBREG)
  3171. operand0 = XEXP (operand0, 0);
  3172. /* SCRATCH_REG will hold an address and maybe the actual data. We want
  3173. it in SIMODE regardless of what mode it was originally given
  3174. to us. */
  3175. scratch_reg = force_mode (SImode, scratch_reg);
  3176. /* D might not fit in 14 bits either; for such cases load D into
  3177. scratch reg. */
  3178. if (!memory_address_p (Pmode, XEXP (operand0, 0)))
  3179. {
  3180. emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
  3181. emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
  3182. 0)),
  3183. Pmode,
  3184. XEXP (XEXP (operand0, 0),
  3185. 0),
  3186. scratch_reg));
  3187. }
  3188. else
  3189. emit_move_insn (scratch_reg, XEXP (operand0, 0));
  3190. emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
  3191. operand1));
  3192. return 1;
  3193. }
  3194. /* Handle secondary reloads for loads of FP registers from constant
  3195. expressions by forcing the constant into memory.
  3196. use scratch_reg to hold the address of the memory location.
  3197. The proper fix is to change PREFERRED_RELOAD_CLASS to return
  3198. NO_REGS when presented with a const_int and an register class
  3199. containing only FP registers. Doing so unfortunately creates
  3200. more problems than it solves. Fix this for 2.5. */
  3201. else if (fp_reg_operand (operand0, mode)
  3202. && CONSTANT_P (operand1)
  3203. && scratch_reg)
  3204. {
  3205. rtx xoperands[2];
  3206. /* SCRATCH_REG will hold an address and maybe the actual data. We want
  3207. it in SIMODE regardless of what mode it was originally given
  3208. to us. */
  3209. scratch_reg = force_mode (SImode, scratch_reg);
  3210. /* Force the constant into memory and put the address of the
  3211. memory location into scratch_reg. */
  3212. xoperands[0] = scratch_reg;
  3213. xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
  3214. emit_insn (gen_rtx_SET (mode, scratch_reg, xoperands[1]));
  3215. /* Now load the destination register. */
  3216. emit_insn (gen_rtx_SET (mode, operand0,
  3217. gen_rtx_MEM (mode, scratch_reg)));
  3218. return 1;
  3219. }
  3220. /* Now have insn-emit do whatever it normally does. */
  3221. return 0;
  3222. }
  3223. /* Split one or more DImode RTL references into pairs of SImode
  3224. references. The RTL can be REG, offsettable MEM, integer constant, or
  3225. CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to
  3226. split and "num" is its length. lo_half and hi_half are output arrays
  3227. that parallel "operands". */
  3228. void
  3229. split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
  3230. {
  3231. while (num--)
  3232. {
  3233. rtx op = operands[num];
  3234. /* simplify_subreg refuses to split volatile memory addresses,
  3235. but we still have to handle it. */
  3236. if (GET_CODE (op) == MEM)
  3237. {
  3238. lo_half[num] = adjust_address (op, SImode, 4);
  3239. hi_half[num] = adjust_address (op, SImode, 0);
  3240. }
  3241. else
  3242. {
  3243. lo_half[num] = simplify_gen_subreg (SImode, op,
  3244. GET_MODE (op) == VOIDmode
  3245. ? DImode : GET_MODE (op), 4);
  3246. hi_half[num] = simplify_gen_subreg (SImode, op,
  3247. GET_MODE (op) == VOIDmode
  3248. ? DImode : GET_MODE (op), 0);
  3249. }
  3250. }
  3251. }
  3252. /* Split X into a base and a constant offset, storing them in *BASE
  3253. and *OFFSET respectively. */
  3254. static void
  3255. m68k_split_offset (rtx x, rtx *base, HOST_WIDE_INT *offset)
  3256. {
  3257. *offset = 0;
  3258. if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
  3259. {
  3260. *offset += INTVAL (XEXP (x, 1));
  3261. x = XEXP (x, 0);
  3262. }
  3263. *base = x;
  3264. }
  3265. /* Return true if PATTERN is a PARALLEL suitable for a movem or fmovem
  3266. instruction. STORE_P says whether the move is a load or store.
  3267. If the instruction uses post-increment or pre-decrement addressing,
  3268. AUTOMOD_BASE is the base register and AUTOMOD_OFFSET is the total
  3269. adjustment. This adjustment will be made by the first element of
  3270. PARALLEL, with the loads or stores starting at element 1. If the
  3271. instruction does not use post-increment or pre-decrement addressing,
  3272. AUTOMOD_BASE is null, AUTOMOD_OFFSET is 0, and the loads or stores
  3273. start at element 0. */
  3274. bool
  3275. m68k_movem_pattern_p (rtx pattern, rtx automod_base,
  3276. HOST_WIDE_INT automod_offset, bool store_p)
  3277. {
  3278. rtx base, mem_base, set, mem, reg, last_reg;
  3279. HOST_WIDE_INT offset, mem_offset;
  3280. int i, first, len;
  3281. enum reg_class rclass;
  3282. len = XVECLEN (pattern, 0);
  3283. first = (automod_base != NULL);
  3284. if (automod_base)
  3285. {
  3286. /* Stores must be pre-decrement and loads must be post-increment. */
  3287. if (store_p != (automod_offset < 0))
  3288. return false;
  3289. /* Work out the base and offset for lowest memory location. */
  3290. base = automod_base;
  3291. offset = (automod_offset < 0 ? automod_offset : 0);
  3292. }
  3293. else
  3294. {
  3295. /* Allow any valid base and offset in the first access. */
  3296. base = NULL;
  3297. offset = 0;
  3298. }
  3299. last_reg = NULL;
  3300. rclass = NO_REGS;
  3301. for (i = first; i < len; i++)
  3302. {
  3303. /* We need a plain SET. */
  3304. set = XVECEXP (pattern, 0, i);
  3305. if (GET_CODE (set) != SET)
  3306. return false;
  3307. /* Check that we have a memory location... */
  3308. mem = XEXP (set, !store_p);
  3309. if (!MEM_P (mem) || !memory_operand (mem, VOIDmode))
  3310. return false;
  3311. /* ...with the right address. */
  3312. if (base == NULL)
  3313. {
  3314. m68k_split_offset (XEXP (mem, 0), &base, &offset);
  3315. /* The ColdFire instruction only allows (An) and (d16,An) modes.
  3316. There are no mode restrictions for 680x0 besides the
  3317. automodification rules enforced above. */
  3318. if (TARGET_COLDFIRE
  3319. && !m68k_legitimate_base_reg_p (base, reload_completed))
  3320. return false;
  3321. }
  3322. else
  3323. {
  3324. m68k_split_offset (XEXP (mem, 0), &mem_base, &mem_offset);
  3325. if (!rtx_equal_p (base, mem_base) || offset != mem_offset)
  3326. return false;
  3327. }
  3328. /* Check that we have a register of the required mode and class. */
  3329. reg = XEXP (set, store_p);
  3330. if (!REG_P (reg)
  3331. || !HARD_REGISTER_P (reg)
  3332. || GET_MODE (reg) != reg_raw_mode[REGNO (reg)])
  3333. return false;
  3334. if (last_reg)
  3335. {
  3336. /* The register must belong to RCLASS and have a higher number
  3337. than the register in the previous SET. */
  3338. if (!TEST_HARD_REG_BIT (reg_class_contents[rclass], REGNO (reg))
  3339. || REGNO (last_reg) >= REGNO (reg))
  3340. return false;
  3341. }
  3342. else
  3343. {
  3344. /* Work out which register class we need. */
  3345. if (INT_REGNO_P (REGNO (reg)))
  3346. rclass = GENERAL_REGS;
  3347. else if (FP_REGNO_P (REGNO (reg)))
  3348. rclass = FP_REGS;
  3349. else
  3350. return false;
  3351. }
  3352. last_reg = reg;
  3353. offset += GET_MODE_SIZE (GET_MODE (reg));
  3354. }
  3355. /* If we have an automodification, check whether the final offset is OK. */
  3356. if (automod_base && offset != (automod_offset < 0 ? 0 : automod_offset))
  3357. return false;
  3358. /* Reject unprofitable cases. */
  3359. if (len < first + (rclass == FP_REGS ? MIN_FMOVEM_REGS : MIN_MOVEM_REGS))
  3360. return false;
  3361. return true;
  3362. }
  3363. /* Return the assembly code template for a movem or fmovem instruction
  3364. whose pattern is given by PATTERN. Store the template's operands
  3365. in OPERANDS.
  3366. If the instruction uses post-increment or pre-decrement addressing,
  3367. AUTOMOD_OFFSET is the total adjustment, otherwise it is 0. STORE_P
  3368. is true if this is a store instruction. */
  3369. const char *
  3370. m68k_output_movem (rtx *operands, rtx pattern,
  3371. HOST_WIDE_INT automod_offset, bool store_p)
  3372. {
  3373. unsigned int mask;
  3374. int i, first;
  3375. gcc_assert (GET_CODE (pattern) == PARALLEL);
  3376. mask = 0;
  3377. first = (automod_offset != 0);
  3378. for (i = first; i < XVECLEN (pattern, 0); i++)
  3379. {
  3380. /* When using movem with pre-decrement addressing, register X + D0_REG
  3381. is controlled by bit 15 - X. For all other addressing modes,
  3382. register X + D0_REG is controlled by bit X. Confusingly, the
  3383. register mask for fmovem is in the opposite order to that for
  3384. movem. */
  3385. unsigned int regno;
  3386. gcc_assert (MEM_P (XEXP (XVECEXP (pattern, 0, i), !store_p)));
  3387. gcc_assert (REG_P (XEXP (XVECEXP (pattern, 0, i), store_p)));
  3388. regno = REGNO (XEXP (XVECEXP (pattern, 0, i), store_p));
  3389. if (automod_offset < 0)
  3390. {
  3391. if (FP_REGNO_P (regno))
  3392. mask |= 1 << (regno - FP0_REG);
  3393. else
  3394. mask |= 1 << (15 - (regno - D0_REG));
  3395. }
  3396. else
  3397. {
  3398. if (FP_REGNO_P (regno))
  3399. mask |= 1 << (7 - (regno - FP0_REG));
  3400. else
  3401. mask |= 1 << (regno - D0_REG);
  3402. }
  3403. }
  3404. CC_STATUS_INIT;
  3405. if (automod_offset == 0)
  3406. operands[0] = XEXP (XEXP (XVECEXP (pattern, 0, first), !store_p), 0);
  3407. else if (automod_offset < 0)
  3408. operands[0] = gen_rtx_PRE_DEC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0)));
  3409. else
  3410. operands[0] = gen_rtx_POST_INC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0)));
  3411. operands[1] = GEN_INT (mask);
  3412. if (FP_REGNO_P (REGNO (XEXP (XVECEXP (pattern, 0, first), store_p))))
  3413. {
  3414. if (store_p)
  3415. return "fmovem %1,%a0";
  3416. else
  3417. return "fmovem %a0,%1";
  3418. }
  3419. else
  3420. {
  3421. if (store_p)
  3422. return "movem%.l %1,%a0";
  3423. else
  3424. return "movem%.l %a0,%1";
  3425. }
  3426. }
  3427. /* Return a REG that occurs in ADDR with coefficient 1.
  3428. ADDR can be effectively incremented by incrementing REG. */
  3429. static rtx
  3430. find_addr_reg (rtx addr)
  3431. {
  3432. while (GET_CODE (addr) == PLUS)
  3433. {
  3434. if (GET_CODE (XEXP (addr, 0)) == REG)
  3435. addr = XEXP (addr, 0);
  3436. else if (GET_CODE (XEXP (addr, 1)) == REG)
  3437. addr = XEXP (addr, 1);
  3438. else if (CONSTANT_P (XEXP (addr, 0)))
  3439. addr = XEXP (addr, 1);
  3440. else if (CONSTANT_P (XEXP (addr, 1)))
  3441. addr = XEXP (addr, 0);
  3442. else
  3443. gcc_unreachable ();
  3444. }
  3445. gcc_assert (GET_CODE (addr) == REG);
  3446. return addr;
  3447. }
  3448. /* Output assembler code to perform a 32-bit 3-operand add. */
  3449. const char *
  3450. output_addsi3 (rtx *operands)
  3451. {
  3452. if (! operands_match_p (operands[0], operands[1]))
  3453. {
  3454. if (!ADDRESS_REG_P (operands[1]))
  3455. {
  3456. rtx tmp = operands[1];
  3457. operands[1] = operands[2];
  3458. operands[2] = tmp;
  3459. }
  3460. /* These insns can result from reloads to access
  3461. stack slots over 64k from the frame pointer. */
  3462. if (GET_CODE (operands[2]) == CONST_INT
  3463. && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767))
  3464. return "move%.l %2,%0\n\tadd%.l %1,%0";
  3465. if (GET_CODE (operands[2]) == REG)
  3466. return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
  3467. return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
  3468. }
  3469. if (GET_CODE (operands[2]) == CONST_INT)
  3470. {
  3471. if (INTVAL (operands[2]) > 0
  3472. && INTVAL (operands[2]) <= 8)
  3473. return "addq%.l %2,%0";
  3474. if (INTVAL (operands[2]) < 0
  3475. && INTVAL (operands[2]) >= -8)
  3476. {
  3477. operands[2] = GEN_INT (- INTVAL (operands[2]));
  3478. return "subq%.l %2,%0";
  3479. }
  3480. /* On the CPU32 it is faster to use two addql instructions to
  3481. add a small integer (8 < N <= 16) to a register.
  3482. Likewise for subql. */
  3483. if (TUNE_CPU32 && REG_P (operands[0]))
  3484. {
  3485. if (INTVAL (operands[2]) > 8
  3486. && INTVAL (operands[2]) <= 16)
  3487. {
  3488. operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
  3489. return "addq%.l #8,%0\n\taddq%.l %2,%0";
  3490. }
  3491. if (INTVAL (operands[2]) < -8
  3492. && INTVAL (operands[2]) >= -16)
  3493. {
  3494. operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
  3495. return "subq%.l #8,%0\n\tsubq%.l %2,%0";
  3496. }
  3497. }
  3498. if (ADDRESS_REG_P (operands[0])
  3499. && INTVAL (operands[2]) >= -0x8000
  3500. && INTVAL (operands[2]) < 0x8000)
  3501. {
  3502. if (TUNE_68040)
  3503. return "add%.w %2,%0";
  3504. else
  3505. return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
  3506. }
  3507. }
  3508. return "add%.l %2,%0";
  3509. }
  3510. /* Store in cc_status the expressions that the condition codes will
  3511. describe after execution of an instruction whose pattern is EXP.
  3512. Do not alter them if the instruction would not alter the cc's. */
  3513. /* On the 68000, all the insns to store in an address register fail to
  3514. set the cc's. However, in some cases these instructions can make it
  3515. possibly invalid to use the saved cc's. In those cases we clear out
  3516. some or all of the saved cc's so they won't be used. */
  3517. void
  3518. notice_update_cc (rtx exp, rtx insn)
  3519. {
  3520. if (GET_CODE (exp) == SET)
  3521. {
  3522. if (GET_CODE (SET_SRC (exp)) == CALL)
  3523. CC_STATUS_INIT;
  3524. else if (ADDRESS_REG_P (SET_DEST (exp)))
  3525. {
  3526. if (cc_status.value1 && modified_in_p (cc_status.value1, insn))
  3527. cc_status.value1 = 0;
  3528. if (cc_status.value2 && modified_in_p (cc_status.value2, insn))
  3529. cc_status.value2 = 0;
  3530. }
  3531. /* fmoves to memory or data registers do not set the condition
  3532. codes. Normal moves _do_ set the condition codes, but not in
  3533. a way that is appropriate for comparison with 0, because -0.0
  3534. would be treated as a negative nonzero number. Note that it
  3535. isn't appropriate to conditionalize this restriction on
  3536. HONOR_SIGNED_ZEROS because that macro merely indicates whether
  3537. we care about the difference between -0.0 and +0.0. */
  3538. else if (!FP_REG_P (SET_DEST (exp))
  3539. && SET_DEST (exp) != cc0_rtx
  3540. && (FP_REG_P (SET_SRC (exp))
  3541. || GET_CODE (SET_SRC (exp)) == FIX
  3542. || FLOAT_MODE_P (GET_MODE (SET_DEST (exp)))))
  3543. CC_STATUS_INIT;
  3544. /* A pair of move insns doesn't produce a useful overall cc. */
  3545. else if (!FP_REG_P (SET_DEST (exp))
  3546. && !FP_REG_P (SET_SRC (exp))
  3547. && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
  3548. && (GET_CODE (SET_SRC (exp)) == REG
  3549. || GET_CODE (SET_SRC (exp)) == MEM
  3550. || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
  3551. CC_STATUS_INIT;
  3552. else if (SET_DEST (exp) != pc_rtx)
  3553. {
  3554. cc_status.flags = 0;
  3555. cc_status.value1 = SET_DEST (exp);
  3556. cc_status.value2 = SET_SRC (exp);
  3557. }
  3558. }
  3559. else if (GET_CODE (exp) == PARALLEL
  3560. && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
  3561. {
  3562. rtx dest = SET_DEST (XVECEXP (exp, 0, 0));
  3563. rtx src = SET_SRC (XVECEXP (exp, 0, 0));
  3564. if (ADDRESS_REG_P (dest))
  3565. CC_STATUS_INIT;
  3566. else if (dest != pc_rtx)
  3567. {
  3568. cc_status.flags = 0;
  3569. cc_status.value1 = dest;
  3570. cc_status.value2 = src;
  3571. }
  3572. }
  3573. else
  3574. CC_STATUS_INIT;
  3575. if (cc_status.value2 != 0
  3576. && ADDRESS_REG_P (cc_status.value2)
  3577. && GET_MODE (cc_status.value2) == QImode)
  3578. CC_STATUS_INIT;
  3579. if (cc_status.value2 != 0)
  3580. switch (GET_CODE (cc_status.value2))
  3581. {
  3582. case ASHIFT: case ASHIFTRT: case LSHIFTRT:
  3583. case ROTATE: case ROTATERT:
  3584. /* These instructions always clear the overflow bit, and set
  3585. the carry to the bit shifted out. */
  3586. cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
  3587. break;
  3588. case PLUS: case MINUS: case MULT:
  3589. case DIV: case UDIV: case MOD: case UMOD: case NEG:
  3590. if (GET_MODE (cc_status.value2) != VOIDmode)
  3591. cc_status.flags |= CC_NO_OVERFLOW;
  3592. break;
  3593. case ZERO_EXTEND:
  3594. /* (SET r1 (ZERO_EXTEND r2)) on this machine
  3595. ends with a move insn moving r2 in r2's mode.
  3596. Thus, the cc's are set for r2.
  3597. This can set N bit spuriously. */
  3598. cc_status.flags |= CC_NOT_NEGATIVE;
  3599. default:
  3600. break;
  3601. }
  3602. if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
  3603. && cc_status.value2
  3604. && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
  3605. cc_status.value2 = 0;
  3606. /* Check for PRE_DEC in dest modifying a register used in src. */
  3607. if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM
  3608. && GET_CODE (XEXP (cc_status.value1, 0)) == PRE_DEC
  3609. && cc_status.value2
  3610. && reg_overlap_mentioned_p (XEXP (XEXP (cc_status.value1, 0), 0),
  3611. cc_status.value2))
  3612. cc_status.value2 = 0;
  3613. if (((cc_status.value1 && FP_REG_P (cc_status.value1))
  3614. || (cc_status.value2 && FP_REG_P (cc_status.value2))))
  3615. cc_status.flags = CC_IN_68881;
  3616. if (cc_status.value2 && GET_CODE (cc_status.value2) == COMPARE
  3617. && GET_MODE_CLASS (GET_MODE (XEXP (cc_status.value2, 0))) == MODE_FLOAT)
  3618. {
  3619. cc_status.flags = CC_IN_68881;
  3620. if (!FP_REG_P (XEXP (cc_status.value2, 0))
  3621. && FP_REG_P (XEXP (cc_status.value2, 1)))
  3622. cc_status.flags |= CC_REVERSED;
  3623. }
  3624. }
  3625. const char *
  3626. output_move_const_double (rtx *operands)
  3627. {
  3628. int code = standard_68881_constant_p (operands[1]);
  3629. if (code != 0)
  3630. {
  3631. static char buf[40];
  3632. sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
  3633. return buf;
  3634. }
  3635. return "fmove%.d %1,%0";
  3636. }
  3637. const char *
  3638. output_move_const_single (rtx *operands)
  3639. {
  3640. int code = standard_68881_constant_p (operands[1]);
  3641. if (code != 0)
  3642. {
  3643. static char buf[40];
  3644. sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
  3645. return buf;
  3646. }
  3647. return "fmove%.s %f1,%0";
  3648. }
  3649. /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
  3650. from the "fmovecr" instruction.
  3651. The value, anded with 0xff, gives the code to use in fmovecr
  3652. to get the desired constant. */
  3653. /* This code has been fixed for cross-compilation. */
  3654. static int inited_68881_table = 0;
  3655. static const char *const strings_68881[7] = {
  3656. "0.0",
  3657. "1.0",
  3658. "10.0",
  3659. "100.0",
  3660. "10000.0",
  3661. "1e8",
  3662. "1e16"
  3663. };
  3664. static const int codes_68881[7] = {
  3665. 0x0f,
  3666. 0x32,
  3667. 0x33,
  3668. 0x34,
  3669. 0x35,
  3670. 0x36,
  3671. 0x37
  3672. };
  3673. REAL_VALUE_TYPE values_68881[7];
  3674. /* Set up values_68881 array by converting the decimal values
  3675. strings_68881 to binary. */
  3676. void
  3677. init_68881_table (void)
  3678. {
  3679. int i;
  3680. REAL_VALUE_TYPE r;
  3681. machine_mode mode;
  3682. mode = SFmode;
  3683. for (i = 0; i < 7; i++)
  3684. {
  3685. if (i == 6)
  3686. mode = DFmode;
  3687. r = REAL_VALUE_ATOF (strings_68881[i], mode);
  3688. values_68881[i] = r;
  3689. }
  3690. inited_68881_table = 1;
  3691. }
  3692. int
  3693. standard_68881_constant_p (rtx x)
  3694. {
  3695. REAL_VALUE_TYPE r;
  3696. int i;
  3697. /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be
  3698. used at all on those chips. */
  3699. if (TUNE_68040_60)
  3700. return 0;
  3701. if (! inited_68881_table)
  3702. init_68881_table ();
  3703. REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  3704. /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0
  3705. is rejected. */
  3706. for (i = 0; i < 6; i++)
  3707. {
  3708. if (REAL_VALUES_IDENTICAL (r, values_68881[i]))
  3709. return (codes_68881[i]);
  3710. }
  3711. if (GET_MODE (x) == SFmode)
  3712. return 0;
  3713. if (REAL_VALUES_EQUAL (r, values_68881[6]))
  3714. return (codes_68881[6]);
  3715. /* larger powers of ten in the constants ram are not used
  3716. because they are not equal to a `double' C constant. */
  3717. return 0;
  3718. }
  3719. /* If X is a floating-point constant, return the logarithm of X base 2,
  3720. or 0 if X is not a power of 2. */
  3721. int
  3722. floating_exact_log2 (rtx x)
  3723. {
  3724. REAL_VALUE_TYPE r, r1;
  3725. int exp;
  3726. REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  3727. if (REAL_VALUES_LESS (r, dconst1))
  3728. return 0;
  3729. exp = real_exponent (&r);
  3730. real_2expN (&r1, exp, DFmode);
  3731. if (REAL_VALUES_EQUAL (r1, r))
  3732. return exp;
  3733. return 0;
  3734. }
  3735. /* A C compound statement to output to stdio stream STREAM the
  3736. assembler syntax for an instruction operand X. X is an RTL
  3737. expression.
  3738. CODE is a value that can be used to specify one of several ways
  3739. of printing the operand. It is used when identical operands
  3740. must be printed differently depending on the context. CODE
  3741. comes from the `%' specification that was used to request
  3742. printing of the operand. If the specification was just `%DIGIT'
  3743. then CODE is 0; if the specification was `%LTR DIGIT' then CODE
  3744. is the ASCII code for LTR.
  3745. If X is a register, this macro should print the register's name.
  3746. The names can be found in an array `reg_names' whose type is
  3747. `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
  3748. When the machine description has a specification `%PUNCT' (a `%'
  3749. followed by a punctuation character), this macro is called with
  3750. a null pointer for X and the punctuation character for CODE.
  3751. The m68k specific codes are:
  3752. '.' for dot needed in Motorola-style opcode names.
  3753. '-' for an operand pushing on the stack:
  3754. sp@-, -(sp) or -(%sp) depending on the style of syntax.
  3755. '+' for an operand pushing on the stack:
  3756. sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
  3757. '@' for a reference to the top word on the stack:
  3758. sp@, (sp) or (%sp) depending on the style of syntax.
  3759. '#' for an immediate operand prefix (# in MIT and Motorola syntax
  3760. but & in SGS syntax).
  3761. '!' for the cc register (used in an `and to cc' insn).
  3762. '$' for the letter `s' in an op code, but only on the 68040.
  3763. '&' for the letter `d' in an op code, but only on the 68040.
  3764. '/' for register prefix needed by longlong.h.
  3765. '?' for m68k_library_id_string
  3766. 'b' for byte insn (no effect, on the Sun; this is for the ISI).
  3767. 'd' to force memory addressing to be absolute, not relative.
  3768. 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
  3769. 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
  3770. or print pair of registers as rx:ry.
  3771. 'p' print an address with @PLTPC attached, but only if the operand
  3772. is not locally-bound. */
  3773. void
  3774. print_operand (FILE *file, rtx op, int letter)
  3775. {
  3776. if (letter == '.')
  3777. {
  3778. if (MOTOROLA)
  3779. fprintf (file, ".");
  3780. }
  3781. else if (letter == '#')
  3782. asm_fprintf (file, "%I");
  3783. else if (letter == '-')
  3784. asm_fprintf (file, MOTOROLA ? "-(%Rsp)" : "%Rsp@-");
  3785. else if (letter == '+')
  3786. asm_fprintf (file, MOTOROLA ? "(%Rsp)+" : "%Rsp@+");
  3787. else if (letter == '@')
  3788. asm_fprintf (file, MOTOROLA ? "(%Rsp)" : "%Rsp@");
  3789. else if (letter == '!')
  3790. asm_fprintf (file, "%Rfpcr");
  3791. else if (letter == '$')
  3792. {
  3793. if (TARGET_68040)
  3794. fprintf (file, "s");
  3795. }
  3796. else if (letter == '&')
  3797. {
  3798. if (TARGET_68040)
  3799. fprintf (file, "d");
  3800. }
  3801. else if (letter == '/')
  3802. asm_fprintf (file, "%R");
  3803. else if (letter == '?')
  3804. asm_fprintf (file, m68k_library_id_string);
  3805. else if (letter == 'p')
  3806. {
  3807. output_addr_const (file, op);
  3808. if (!(GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (op)))
  3809. fprintf (file, "@PLTPC");
  3810. }
  3811. else if (GET_CODE (op) == REG)
  3812. {
  3813. if (letter == 'R')
  3814. /* Print out the second register name of a register pair.
  3815. I.e., R (6) => 7. */
  3816. fputs (M68K_REGNAME(REGNO (op) + 1), file);
  3817. else
  3818. fputs (M68K_REGNAME(REGNO (op)), file);
  3819. }
  3820. else if (GET_CODE (op) == MEM)
  3821. {
  3822. output_address (XEXP (op, 0));
  3823. if (letter == 'd' && ! TARGET_68020
  3824. && CONSTANT_ADDRESS_P (XEXP (op, 0))
  3825. && !(GET_CODE (XEXP (op, 0)) == CONST_INT
  3826. && INTVAL (XEXP (op, 0)) < 0x8000
  3827. && INTVAL (XEXP (op, 0)) >= -0x8000))
  3828. fprintf (file, MOTOROLA ? ".l" : ":l");
  3829. }
  3830. else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
  3831. {
  3832. REAL_VALUE_TYPE r;
  3833. long l;
  3834. REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  3835. REAL_VALUE_TO_TARGET_SINGLE (r, l);
  3836. asm_fprintf (file, "%I0x%lx", l & 0xFFFFFFFF);
  3837. }
  3838. else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode)
  3839. {
  3840. REAL_VALUE_TYPE r;
  3841. long l[3];
  3842. REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  3843. REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  3844. asm_fprintf (file, "%I0x%lx%08lx%08lx", l[0] & 0xFFFFFFFF,
  3845. l[1] & 0xFFFFFFFF, l[2] & 0xFFFFFFFF);
  3846. }
  3847. else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode)
  3848. {
  3849. REAL_VALUE_TYPE r;
  3850. long l[2];
  3851. REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  3852. REAL_VALUE_TO_TARGET_DOUBLE (r, l);
  3853. asm_fprintf (file, "%I0x%lx%08lx", l[0] & 0xFFFFFFFF, l[1] & 0xFFFFFFFF);
  3854. }
  3855. else
  3856. {
  3857. /* Use `print_operand_address' instead of `output_addr_const'
  3858. to ensure that we print relevant PIC stuff. */
  3859. asm_fprintf (file, "%I");
  3860. if (TARGET_PCREL
  3861. && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST))
  3862. print_operand_address (file, op);
  3863. else
  3864. output_addr_const (file, op);
  3865. }
  3866. }
  3867. /* Return string for TLS relocation RELOC. */
  3868. static const char *
  3869. m68k_get_reloc_decoration (enum m68k_reloc reloc)
  3870. {
  3871. /* To my knowledge, !MOTOROLA assemblers don't support TLS. */
  3872. gcc_assert (MOTOROLA || reloc == RELOC_GOT);
  3873. switch (reloc)
  3874. {
  3875. case RELOC_GOT:
  3876. if (MOTOROLA)
  3877. {
  3878. if (flag_pic == 1 && TARGET_68020)
  3879. return "@GOT.w";
  3880. else
  3881. return "@GOT";
  3882. }
  3883. else
  3884. {
  3885. if (TARGET_68020)
  3886. {
  3887. switch (flag_pic)
  3888. {
  3889. case 1:
  3890. return ":w";
  3891. case 2:
  3892. return ":l";
  3893. default:
  3894. return "";
  3895. }
  3896. }
  3897. }
  3898. case RELOC_TLSGD:
  3899. return "@TLSGD";
  3900. case RELOC_TLSLDM:
  3901. return "@TLSLDM";
  3902. case RELOC_TLSLDO:
  3903. return "@TLSLDO";
  3904. case RELOC_TLSIE:
  3905. return "@TLSIE";
  3906. case RELOC_TLSLE:
  3907. return "@TLSLE";
  3908. default:
  3909. gcc_unreachable ();
  3910. }
  3911. }
  3912. /* m68k implementation of TARGET_OUTPUT_ADDR_CONST_EXTRA. */
  3913. static bool
  3914. m68k_output_addr_const_extra (FILE *file, rtx x)
  3915. {
  3916. if (GET_CODE (x) == UNSPEC)
  3917. {
  3918. switch (XINT (x, 1))
  3919. {
  3920. case UNSPEC_RELOC16:
  3921. case UNSPEC_RELOC32:
  3922. output_addr_const (file, XVECEXP (x, 0, 0));
  3923. fputs (m68k_get_reloc_decoration
  3924. ((enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1))), file);
  3925. return true;
  3926. default:
  3927. break;
  3928. }
  3929. }
  3930. return false;
  3931. }
  3932. /* M68K implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */
  3933. static void
  3934. m68k_output_dwarf_dtprel (FILE *file, int size, rtx x)
  3935. {
  3936. gcc_assert (size == 4);
  3937. fputs ("\t.long\t", file);
  3938. output_addr_const (file, x);
  3939. fputs ("@TLSLDO+0x8000", file);
  3940. }
  3941. /* In the name of slightly smaller debug output, and to cater to
  3942. general assembler lossage, recognize various UNSPEC sequences
  3943. and turn them back into a direct symbol reference. */
  3944. static rtx
  3945. m68k_delegitimize_address (rtx orig_x)
  3946. {
  3947. rtx x;
  3948. struct m68k_address addr;
  3949. rtx unspec;
  3950. orig_x = delegitimize_mem_from_attrs (orig_x);
  3951. x = orig_x;
  3952. if (MEM_P (x))
  3953. x = XEXP (x, 0);
  3954. if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
  3955. return orig_x;
  3956. if (!m68k_decompose_address (GET_MODE (x), x, false, &addr)
  3957. || addr.offset == NULL_RTX
  3958. || GET_CODE (addr.offset) != CONST)
  3959. return orig_x;
  3960. unspec = XEXP (addr.offset, 0);
  3961. if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
  3962. unspec = XEXP (unspec, 0);
  3963. if (GET_CODE (unspec) != UNSPEC
  3964. || (XINT (unspec, 1) != UNSPEC_RELOC16
  3965. && XINT (unspec, 1) != UNSPEC_RELOC32))
  3966. return orig_x;
  3967. x = XVECEXP (unspec, 0, 0);
  3968. gcc_assert (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF);
  3969. if (unspec != XEXP (addr.offset, 0))
  3970. x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.offset, 0), 1));
  3971. if (addr.index)
  3972. {
  3973. rtx idx = addr.index;
  3974. if (addr.scale != 1)
  3975. idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
  3976. x = gen_rtx_PLUS (Pmode, idx, x);
  3977. }
  3978. if (addr.base)
  3979. x = gen_rtx_PLUS (Pmode, addr.base, x);
  3980. if (MEM_P (orig_x))
  3981. x = replace_equiv_address_nv (orig_x, x);
  3982. return x;
  3983. }
  3984. /* A C compound statement to output to stdio stream STREAM the
  3985. assembler syntax for an instruction operand that is a memory
  3986. reference whose address is ADDR. ADDR is an RTL expression.
  3987. Note that this contains a kludge that knows that the only reason
  3988. we have an address (plus (label_ref...) (reg...)) when not generating
  3989. PIC code is in the insn before a tablejump, and we know that m68k.md
  3990. generates a label LInnn: on such an insn.
  3991. It is possible for PIC to generate a (plus (label_ref...) (reg...))
  3992. and we handle that just like we would a (plus (symbol_ref...) (reg...)).
  3993. This routine is responsible for distinguishing between -fpic and -fPIC
  3994. style relocations in an address. When generating -fpic code the
  3995. offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating
  3996. -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */
  3997. void
  3998. print_operand_address (FILE *file, rtx addr)
  3999. {
  4000. struct m68k_address address;
  4001. if (!m68k_decompose_address (QImode, addr, true, &address))
  4002. gcc_unreachable ();
  4003. if (address.code == PRE_DEC)
  4004. fprintf (file, MOTOROLA ? "-(%s)" : "%s@-",
  4005. M68K_REGNAME (REGNO (address.base)));
  4006. else if (address.code == POST_INC)
  4007. fprintf (file, MOTOROLA ? "(%s)+" : "%s@+",
  4008. M68K_REGNAME (REGNO (address.base)));
  4009. else if (!address.base && !address.index)
  4010. {
  4011. /* A constant address. */
  4012. gcc_assert (address.offset == addr);
  4013. if (GET_CODE (addr) == CONST_INT)
  4014. {
  4015. /* (xxx).w or (xxx).l. */
  4016. if (IN_RANGE (INTVAL (addr), -0x8000, 0x7fff))
  4017. fprintf (file, MOTOROLA ? "%d.w" : "%d:w", (int) INTVAL (addr));
  4018. else
  4019. fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr));
  4020. }
  4021. else if (TARGET_PCREL)
  4022. {
  4023. /* (d16,PC) or (bd,PC,Xn) (with suppressed index register). */
  4024. fputc ('(', file);
  4025. output_addr_const (file, addr);
  4026. asm_fprintf (file, flag_pic == 1 ? ":w,%Rpc)" : ":l,%Rpc)");
  4027. }
  4028. else
  4029. {
  4030. /* (xxx).l. We need a special case for SYMBOL_REF if the symbol
  4031. name ends in `.<letter>', as the last 2 characters can be
  4032. mistaken as a size suffix. Put the name in parentheses. */
  4033. if (GET_CODE (addr) == SYMBOL_REF
  4034. && strlen (XSTR (addr, 0)) > 2
  4035. && XSTR (addr, 0)[strlen (XSTR (addr, 0)) - 2] == '.')
  4036. {
  4037. putc ('(', file);
  4038. output_addr_const (file, addr);
  4039. putc (')', file);
  4040. }
  4041. else
  4042. output_addr_const (file, addr);
  4043. }
  4044. }
  4045. else
  4046. {
  4047. int labelno;
  4048. /* If ADDR is a (d8,pc,Xn) address, this is the number of the
  4049. label being accessed, otherwise it is -1. */
  4050. labelno = (address.offset
  4051. && !address.base
  4052. && GET_CODE (address.offset) == LABEL_REF
  4053. ? CODE_LABEL_NUMBER (XEXP (address.offset, 0))
  4054. : -1);
  4055. if (MOTOROLA)
  4056. {
  4057. /* Print the "offset(base" component. */
  4058. if (labelno >= 0)
  4059. asm_fprintf (file, "%LL%d(%Rpc,", labelno);
  4060. else
  4061. {
  4062. if (address.offset)
  4063. output_addr_const (file, address.offset);
  4064. putc ('(', file);
  4065. if (address.base)
  4066. fputs (M68K_REGNAME (REGNO (address.base)), file);
  4067. }
  4068. /* Print the ",index" component, if any. */
  4069. if (address.index)
  4070. {
  4071. if (address.base)
  4072. putc (',', file);
  4073. fprintf (file, "%s.%c",
  4074. M68K_REGNAME (REGNO (address.index)),
  4075. GET_MODE (address.index) == HImode ? 'w' : 'l');
  4076. if (address.scale != 1)
  4077. fprintf (file, "*%d", address.scale);
  4078. }
  4079. putc (')', file);
  4080. }
  4081. else /* !MOTOROLA */
  4082. {
  4083. if (!address.offset && !address.index)
  4084. fprintf (file, "%s@", M68K_REGNAME (REGNO (address.base)));
  4085. else
  4086. {
  4087. /* Print the "base@(offset" component. */
  4088. if (labelno >= 0)
  4089. asm_fprintf (file, "%Rpc@(%LL%d", labelno);
  4090. else
  4091. {
  4092. if (address.base)
  4093. fputs (M68K_REGNAME (REGNO (address.base)), file);
  4094. fprintf (file, "@(");
  4095. if (address.offset)
  4096. output_addr_const (file, address.offset);
  4097. }
  4098. /* Print the ",index" component, if any. */
  4099. if (address.index)
  4100. {
  4101. fprintf (file, ",%s:%c",
  4102. M68K_REGNAME (REGNO (address.index)),
  4103. GET_MODE (address.index) == HImode ? 'w' : 'l');
  4104. if (address.scale != 1)
  4105. fprintf (file, ":%d", address.scale);
  4106. }
  4107. putc (')', file);
  4108. }
  4109. }
  4110. }
  4111. }
  4112. /* Check for cases where a clr insns can be omitted from code using
  4113. strict_low_part sets. For example, the second clrl here is not needed:
  4114. clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
  4115. MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear
  4116. insn we are checking for redundancy. TARGET is the register set by the
  4117. clear insn. */
  4118. bool
  4119. strict_low_part_peephole_ok (machine_mode mode, rtx_insn *first_insn,
  4120. rtx target)
  4121. {
  4122. rtx_insn *p = first_insn;
  4123. while ((p = PREV_INSN (p)))
  4124. {
  4125. if (NOTE_INSN_BASIC_BLOCK_P (p))
  4126. return false;
  4127. if (NOTE_P (p))
  4128. continue;
  4129. /* If it isn't an insn, then give up. */
  4130. if (!INSN_P (p))
  4131. return false;
  4132. if (reg_set_p (target, p))
  4133. {
  4134. rtx set = single_set (p);
  4135. rtx dest;
  4136. /* If it isn't an easy to recognize insn, then give up. */
  4137. if (! set)
  4138. return false;
  4139. dest = SET_DEST (set);
  4140. /* If this sets the entire target register to zero, then our
  4141. first_insn is redundant. */
  4142. if (rtx_equal_p (dest, target)
  4143. && SET_SRC (set) == const0_rtx)
  4144. return true;
  4145. else if (GET_CODE (dest) == STRICT_LOW_PART
  4146. && GET_CODE (XEXP (dest, 0)) == REG
  4147. && REGNO (XEXP (dest, 0)) == REGNO (target)
  4148. && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0)))
  4149. <= GET_MODE_SIZE (mode)))
  4150. /* This is a strict low part set which modifies less than
  4151. we are using, so it is safe. */
  4152. ;
  4153. else
  4154. return false;
  4155. }
  4156. }
  4157. return false;
  4158. }
  4159. /* Operand predicates for implementing asymmetric pc-relative addressing
  4160. on m68k. The m68k supports pc-relative addressing (mode 7, register 2)
  4161. when used as a source operand, but not as a destination operand.
  4162. We model this by restricting the meaning of the basic predicates
  4163. (general_operand, memory_operand, etc) to forbid the use of this
  4164. addressing mode, and then define the following predicates that permit
  4165. this addressing mode. These predicates can then be used for the
  4166. source operands of the appropriate instructions.
  4167. n.b. While it is theoretically possible to change all machine patterns
  4168. to use this addressing more where permitted by the architecture,
  4169. it has only been implemented for "common" cases: SImode, HImode, and
  4170. QImode operands, and only for the principle operations that would
  4171. require this addressing mode: data movement and simple integer operations.
  4172. In parallel with these new predicates, two new constraint letters
  4173. were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'.
  4174. 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case.
  4175. In the pcrel case 's' is only valid in combination with 'a' registers.
  4176. See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding
  4177. of how these constraints are used.
  4178. The use of these predicates is strictly optional, though patterns that
  4179. don't will cause an extra reload register to be allocated where one
  4180. was not necessary:
  4181. lea (abc:w,%pc),%a0 ; need to reload address
  4182. moveq &1,%d1 ; since write to pc-relative space
  4183. movel %d1,%a0@ ; is not allowed
  4184. ...
  4185. lea (abc:w,%pc),%a1 ; no need to reload address here
  4186. movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok
  4187. For more info, consult tiemann@cygnus.com.
  4188. All of the ugliness with predicates and constraints is due to the
  4189. simple fact that the m68k does not allow a pc-relative addressing
  4190. mode as a destination. gcc does not distinguish between source and
  4191. destination addresses. Hence, if we claim that pc-relative address
  4192. modes are valid, e.g. TARGET_LEGITIMATE_ADDRESS_P accepts them, then we
  4193. end up with invalid code. To get around this problem, we left
  4194. pc-relative modes as invalid addresses, and then added special
  4195. predicates and constraints to accept them.
  4196. A cleaner way to handle this is to modify gcc to distinguish
  4197. between source and destination addresses. We can then say that
  4198. pc-relative is a valid source address but not a valid destination
  4199. address, and hopefully avoid a lot of the predicate and constraint
  4200. hackery. Unfortunately, this would be a pretty big change. It would
  4201. be a useful change for a number of ports, but there aren't any current
  4202. plans to undertake this.
  4203. ***************************************************************************/
  4204. const char *
  4205. output_andsi3 (rtx *operands)
  4206. {
  4207. int logval;
  4208. if (GET_CODE (operands[2]) == CONST_INT
  4209. && (INTVAL (operands[2]) | 0xffff) == -1
  4210. && (DATA_REG_P (operands[0])
  4211. || offsettable_memref_p (operands[0]))
  4212. && !TARGET_COLDFIRE)
  4213. {
  4214. if (GET_CODE (operands[0]) != REG)
  4215. operands[0] = adjust_address (operands[0], HImode, 2);
  4216. operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff);
  4217. /* Do not delete a following tstl %0 insn; that would be incorrect. */
  4218. CC_STATUS_INIT;
  4219. if (operands[2] == const0_rtx)
  4220. return "clr%.w %0";
  4221. return "and%.w %2,%0";
  4222. }
  4223. if (GET_CODE (operands[2]) == CONST_INT
  4224. && (logval = exact_log2 (~ INTVAL (operands[2]) & 0xffffffff)) >= 0
  4225. && (DATA_REG_P (operands[0])
  4226. || offsettable_memref_p (operands[0])))
  4227. {
  4228. if (DATA_REG_P (operands[0]))
  4229. operands[1] = GEN_INT (logval);
  4230. else
  4231. {
  4232. operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
  4233. operands[1] = GEN_INT (logval % 8);
  4234. }
  4235. /* This does not set condition codes in a standard way. */
  4236. CC_STATUS_INIT;
  4237. return "bclr %1,%0";
  4238. }
  4239. return "and%.l %2,%0";
  4240. }
  4241. const char *
  4242. output_iorsi3 (rtx *operands)
  4243. {
  4244. register int logval;
  4245. if (GET_CODE (operands[2]) == CONST_INT
  4246. && INTVAL (operands[2]) >> 16 == 0
  4247. && (DATA_REG_P (operands[0])
  4248. || offsettable_memref_p (operands[0]))
  4249. && !TARGET_COLDFIRE)
  4250. {
  4251. if (GET_CODE (operands[0]) != REG)
  4252. operands[0] = adjust_address (operands[0], HImode, 2);
  4253. /* Do not delete a following tstl %0 insn; that would be incorrect. */
  4254. CC_STATUS_INIT;
  4255. if (INTVAL (operands[2]) == 0xffff)
  4256. return "mov%.w %2,%0";
  4257. return "or%.w %2,%0";
  4258. }
  4259. if (GET_CODE (operands[2]) == CONST_INT
  4260. && (logval = exact_log2 (INTVAL (operands[2]) & 0xffffffff)) >= 0
  4261. && (DATA_REG_P (operands[0])
  4262. || offsettable_memref_p (operands[0])))
  4263. {
  4264. if (DATA_REG_P (operands[0]))
  4265. operands[1] = GEN_INT (logval);
  4266. else
  4267. {
  4268. operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
  4269. operands[1] = GEN_INT (logval % 8);
  4270. }
  4271. CC_STATUS_INIT;
  4272. return "bset %1,%0";
  4273. }
  4274. return "or%.l %2,%0";
  4275. }
  4276. const char *
  4277. output_xorsi3 (rtx *operands)
  4278. {
  4279. register int logval;
  4280. if (GET_CODE (operands[2]) == CONST_INT
  4281. && INTVAL (operands[2]) >> 16 == 0
  4282. && (offsettable_memref_p (operands[0]) || DATA_REG_P (operands[0]))
  4283. && !TARGET_COLDFIRE)
  4284. {
  4285. if (! DATA_REG_P (operands[0]))
  4286. operands[0] = adjust_address (operands[0], HImode, 2);
  4287. /* Do not delete a following tstl %0 insn; that would be incorrect. */
  4288. CC_STATUS_INIT;
  4289. if (INTVAL (operands[2]) == 0xffff)
  4290. return "not%.w %0";
  4291. return "eor%.w %2,%0";
  4292. }
  4293. if (GET_CODE (operands[2]) == CONST_INT
  4294. && (logval = exact_log2 (INTVAL (operands[2]) & 0xffffffff)) >= 0
  4295. && (DATA_REG_P (operands[0])
  4296. || offsettable_memref_p (operands[0])))
  4297. {
  4298. if (DATA_REG_P (operands[0]))
  4299. operands[1] = GEN_INT (logval);
  4300. else
  4301. {
  4302. operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
  4303. operands[1] = GEN_INT (logval % 8);
  4304. }
  4305. CC_STATUS_INIT;
  4306. return "bchg %1,%0";
  4307. }
  4308. return "eor%.l %2,%0";
  4309. }
  4310. /* Return the instruction that should be used for a call to address X,
  4311. which is known to be in operand 0. */
  4312. const char *
  4313. output_call (rtx x)
  4314. {
  4315. if (symbolic_operand (x, VOIDmode))
  4316. return m68k_symbolic_call;
  4317. else
  4318. return "jsr %a0";
  4319. }
  4320. /* Likewise sibling calls. */
  4321. const char *
  4322. output_sibcall (rtx x)
  4323. {
  4324. if (symbolic_operand (x, VOIDmode))
  4325. return m68k_symbolic_jump;
  4326. else
  4327. return "jmp %a0";
  4328. }
  4329. static void
  4330. m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
  4331. HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
  4332. tree function)
  4333. {
  4334. rtx this_slot, offset, addr, mem, tmp;
  4335. rtx_insn *insn;
  4336. /* Avoid clobbering the struct value reg by using the
  4337. static chain reg as a temporary. */
  4338. tmp = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
  4339. /* Pretend to be a post-reload pass while generating rtl. */
  4340. reload_completed = 1;
  4341. /* The "this" pointer is stored at 4(%sp). */
  4342. this_slot = gen_rtx_MEM (Pmode, plus_constant (Pmode,
  4343. stack_pointer_rtx, 4));
  4344. /* Add DELTA to THIS. */
  4345. if (delta != 0)
  4346. {
  4347. /* Make the offset a legitimate operand for memory addition. */
  4348. offset = GEN_INT (delta);
  4349. if ((delta < -8 || delta > 8)
  4350. && (TARGET_COLDFIRE || USE_MOVQ (delta)))
  4351. {
  4352. emit_move_insn (gen_rtx_REG (Pmode, D0_REG), offset);
  4353. offset = gen_rtx_REG (Pmode, D0_REG);
  4354. }
  4355. emit_insn (gen_add3_insn (copy_rtx (this_slot),
  4356. copy_rtx (this_slot), offset));
  4357. }
  4358. /* If needed, add *(*THIS + VCALL_OFFSET) to THIS. */
  4359. if (vcall_offset != 0)
  4360. {
  4361. /* Set the static chain register to *THIS. */
  4362. emit_move_insn (tmp, this_slot);
  4363. emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
  4364. /* Set ADDR to a legitimate address for *THIS + VCALL_OFFSET. */
  4365. addr = plus_constant (Pmode, tmp, vcall_offset);
  4366. if (!m68k_legitimate_address_p (Pmode, addr, true))
  4367. {
  4368. emit_insn (gen_rtx_SET (VOIDmode, tmp, addr));
  4369. addr = tmp;
  4370. }
  4371. /* Load the offset into %d0 and add it to THIS. */
  4372. emit_move_insn (gen_rtx_REG (Pmode, D0_REG),
  4373. gen_rtx_MEM (Pmode, addr));
  4374. emit_insn (gen_add3_insn (copy_rtx (this_slot),
  4375. copy_rtx (this_slot),
  4376. gen_rtx_REG (Pmode, D0_REG)));
  4377. }
  4378. /* Jump to the target function. Use a sibcall if direct jumps are
  4379. allowed, otherwise load the address into a register first. */
  4380. mem = DECL_RTL (function);
  4381. if (!sibcall_operand (XEXP (mem, 0), VOIDmode))
  4382. {
  4383. gcc_assert (flag_pic);
  4384. if (!TARGET_SEP_DATA)
  4385. {
  4386. /* Use the static chain register as a temporary (call-clobbered)
  4387. GOT pointer for this function. We can use the static chain
  4388. register because it isn't live on entry to the thunk. */
  4389. SET_REGNO (pic_offset_table_rtx, STATIC_CHAIN_REGNUM);
  4390. emit_insn (gen_load_got (pic_offset_table_rtx));
  4391. }
  4392. legitimize_pic_address (XEXP (mem, 0), Pmode, tmp);
  4393. mem = replace_equiv_address (mem, tmp);
  4394. }
  4395. insn = emit_call_insn (gen_sibcall (mem, const0_rtx));
  4396. SIBLING_CALL_P (insn) = 1;
  4397. /* Run just enough of rest_of_compilation. */
  4398. insn = get_insns ();
  4399. split_all_insns_noflow ();
  4400. final_start_function (insn, file, 1);
  4401. final (insn, file, 1);
  4402. final_end_function ();
  4403. /* Clean up the vars set above. */
  4404. reload_completed = 0;
  4405. /* Restore the original PIC register. */
  4406. if (flag_pic)
  4407. SET_REGNO (pic_offset_table_rtx, PIC_REG);
  4408. }
  4409. /* Worker function for TARGET_STRUCT_VALUE_RTX. */
  4410. static rtx
  4411. m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
  4412. int incoming ATTRIBUTE_UNUSED)
  4413. {
  4414. return gen_rtx_REG (Pmode, M68K_STRUCT_VALUE_REGNUM);
  4415. }
  4416. /* Return nonzero if register old_reg can be renamed to register new_reg. */
  4417. int
  4418. m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
  4419. unsigned int new_reg)
  4420. {
  4421. /* Interrupt functions can only use registers that have already been
  4422. saved by the prologue, even if they would normally be
  4423. call-clobbered. */
  4424. if ((m68k_get_function_kind (current_function_decl)
  4425. == m68k_fk_interrupt_handler)
  4426. && !df_regs_ever_live_p (new_reg))
  4427. return 0;
  4428. return 1;
  4429. }
  4430. /* Value is true if hard register REGNO can hold a value of machine-mode
  4431. MODE. On the 68000, we let the cpu registers can hold any mode, but
  4432. restrict the 68881 registers to floating-point modes. */
  4433. bool
  4434. m68k_regno_mode_ok (int regno, machine_mode mode)
  4435. {
  4436. if (DATA_REGNO_P (regno))
  4437. {
  4438. /* Data Registers, can hold aggregate if fits in. */
  4439. if (regno + GET_MODE_SIZE (mode) / 4 <= 8)
  4440. return true;
  4441. }
  4442. else if (ADDRESS_REGNO_P (regno))
  4443. {
  4444. if (regno + GET_MODE_SIZE (mode) / 4 <= 16)
  4445. return true;
  4446. }
  4447. else if (FP_REGNO_P (regno))
  4448. {
  4449. /* FPU registers, hold float or complex float of long double or
  4450. smaller. */
  4451. if ((GET_MODE_CLASS (mode) == MODE_FLOAT
  4452. || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  4453. && GET_MODE_UNIT_SIZE (mode) <= TARGET_FP_REG_SIZE)
  4454. return true;
  4455. }
  4456. return false;
  4457. }
  4458. /* Implement SECONDARY_RELOAD_CLASS. */
  4459. enum reg_class
  4460. m68k_secondary_reload_class (enum reg_class rclass,
  4461. machine_mode mode, rtx x)
  4462. {
  4463. int regno;
  4464. regno = true_regnum (x);
  4465. /* If one operand of a movqi is an address register, the other
  4466. operand must be a general register or constant. Other types
  4467. of operand must be reloaded through a data register. */
  4468. if (GET_MODE_SIZE (mode) == 1
  4469. && reg_classes_intersect_p (rclass, ADDR_REGS)
  4470. && !(INT_REGNO_P (regno) || CONSTANT_P (x)))
  4471. return DATA_REGS;
  4472. /* PC-relative addresses must be loaded into an address register first. */
  4473. if (TARGET_PCREL
  4474. && !reg_class_subset_p (rclass, ADDR_REGS)
  4475. && symbolic_operand (x, VOIDmode))
  4476. return ADDR_REGS;
  4477. return NO_REGS;
  4478. }
  4479. /* Implement PREFERRED_RELOAD_CLASS. */
  4480. enum reg_class
  4481. m68k_preferred_reload_class (rtx x, enum reg_class rclass)
  4482. {
  4483. enum reg_class secondary_class;
  4484. /* If RCLASS might need a secondary reload, try restricting it to
  4485. a class that doesn't. */
  4486. secondary_class = m68k_secondary_reload_class (rclass, GET_MODE (x), x);
  4487. if (secondary_class != NO_REGS
  4488. && reg_class_subset_p (secondary_class, rclass))
  4489. return secondary_class;
  4490. /* Prefer to use moveq for in-range constants. */
  4491. if (GET_CODE (x) == CONST_INT
  4492. && reg_class_subset_p (DATA_REGS, rclass)
  4493. && IN_RANGE (INTVAL (x), -0x80, 0x7f))
  4494. return DATA_REGS;
  4495. /* ??? Do we really need this now? */
  4496. if (GET_CODE (x) == CONST_DOUBLE
  4497. && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  4498. {
  4499. if (TARGET_HARD_FLOAT && reg_class_subset_p (FP_REGS, rclass))
  4500. return FP_REGS;
  4501. return NO_REGS;
  4502. }
  4503. return rclass;
  4504. }
  4505. /* Return floating point values in a 68881 register. This makes 68881 code
  4506. a little bit faster. It also makes -msoft-float code incompatible with
  4507. hard-float code, so people have to be careful not to mix the two.
  4508. For ColdFire it was decided the ABI incompatibility is undesirable.
  4509. If there is need for a hard-float ABI it is probably worth doing it
  4510. properly and also passing function arguments in FP registers. */
  4511. rtx
  4512. m68k_libcall_value (machine_mode mode)
  4513. {
  4514. switch (mode) {
  4515. case SFmode:
  4516. case DFmode:
  4517. case XFmode:
  4518. if (TARGET_68881)
  4519. return gen_rtx_REG (mode, FP0_REG);
  4520. break;
  4521. default:
  4522. break;
  4523. }
  4524. return gen_rtx_REG (mode, m68k_libcall_value_in_a0_p ? A0_REG : D0_REG);
  4525. }
  4526. /* Location in which function value is returned.
  4527. NOTE: Due to differences in ABIs, don't call this function directly,
  4528. use FUNCTION_VALUE instead. */
  4529. rtx
  4530. m68k_function_value (const_tree valtype, const_tree func ATTRIBUTE_UNUSED)
  4531. {
  4532. machine_mode mode;
  4533. mode = TYPE_MODE (valtype);
  4534. switch (mode) {
  4535. case SFmode:
  4536. case DFmode:
  4537. case XFmode:
  4538. if (TARGET_68881)
  4539. return gen_rtx_REG (mode, FP0_REG);
  4540. break;
  4541. default:
  4542. break;
  4543. }
  4544. /* If the function returns a pointer, push that into %a0. */
  4545. if (func && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (func))))
  4546. /* For compatibility with the large body of existing code which
  4547. does not always properly declare external functions returning
  4548. pointer types, the m68k/SVR4 convention is to copy the value
  4549. returned for pointer functions from a0 to d0 in the function
  4550. epilogue, so that callers that have neglected to properly
  4551. declare the callee can still find the correct return value in
  4552. d0. */
  4553. return gen_rtx_PARALLEL
  4554. (mode,
  4555. gen_rtvec (2,
  4556. gen_rtx_EXPR_LIST (VOIDmode,
  4557. gen_rtx_REG (mode, A0_REG),
  4558. const0_rtx),
  4559. gen_rtx_EXPR_LIST (VOIDmode,
  4560. gen_rtx_REG (mode, D0_REG),
  4561. const0_rtx)));
  4562. else if (POINTER_TYPE_P (valtype))
  4563. return gen_rtx_REG (mode, A0_REG);
  4564. else
  4565. return gen_rtx_REG (mode, D0_REG);
  4566. }
  4567. /* Worker function for TARGET_RETURN_IN_MEMORY. */
  4568. #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
  4569. static bool
  4570. m68k_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
  4571. {
  4572. machine_mode mode = TYPE_MODE (type);
  4573. if (mode == BLKmode)
  4574. return true;
  4575. /* If TYPE's known alignment is less than the alignment of MODE that
  4576. would contain the structure, then return in memory. We need to
  4577. do so to maintain the compatibility between code compiled with
  4578. -mstrict-align and that compiled with -mno-strict-align. */
  4579. if (AGGREGATE_TYPE_P (type)
  4580. && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (mode))
  4581. return true;
  4582. return false;
  4583. }
  4584. #endif
  4585. /* CPU to schedule the program for. */
  4586. enum attr_cpu m68k_sched_cpu;
  4587. /* MAC to schedule the program for. */
  4588. enum attr_mac m68k_sched_mac;
  4589. /* Operand type. */
  4590. enum attr_op_type
  4591. {
  4592. /* No operand. */
  4593. OP_TYPE_NONE,
  4594. /* Integer register. */
  4595. OP_TYPE_RN,
  4596. /* FP register. */
  4597. OP_TYPE_FPN,
  4598. /* Implicit mem reference (e.g. stack). */
  4599. OP_TYPE_MEM1,
  4600. /* Memory without offset or indexing. EA modes 2, 3 and 4. */
  4601. OP_TYPE_MEM234,
  4602. /* Memory with offset but without indexing. EA mode 5. */
  4603. OP_TYPE_MEM5,
  4604. /* Memory with indexing. EA mode 6. */
  4605. OP_TYPE_MEM6,
  4606. /* Memory referenced by absolute address. EA mode 7. */
  4607. OP_TYPE_MEM7,
  4608. /* Immediate operand that doesn't require extension word. */
  4609. OP_TYPE_IMM_Q,
  4610. /* Immediate 16 bit operand. */
  4611. OP_TYPE_IMM_W,
  4612. /* Immediate 32 bit operand. */
  4613. OP_TYPE_IMM_L
  4614. };
  4615. /* Return type of memory ADDR_RTX refers to. */
  4616. static enum attr_op_type
  4617. sched_address_type (machine_mode mode, rtx addr_rtx)
  4618. {
  4619. struct m68k_address address;
  4620. if (symbolic_operand (addr_rtx, VOIDmode))
  4621. return OP_TYPE_MEM7;
  4622. if (!m68k_decompose_address (mode, addr_rtx,
  4623. reload_completed, &address))
  4624. {
  4625. gcc_assert (!reload_completed);
  4626. /* Reload will likely fix the address to be in the register. */
  4627. return OP_TYPE_MEM234;
  4628. }
  4629. if (address.scale != 0)
  4630. return OP_TYPE_MEM6;
  4631. if (address.base != NULL_RTX)
  4632. {
  4633. if (address.offset == NULL_RTX)
  4634. return OP_TYPE_MEM234;
  4635. return OP_TYPE_MEM5;
  4636. }
  4637. gcc_assert (address.offset != NULL_RTX);
  4638. return OP_TYPE_MEM7;
  4639. }
  4640. /* Return X or Y (depending on OPX_P) operand of INSN. */
  4641. static rtx
  4642. sched_get_operand (rtx_insn *insn, bool opx_p)
  4643. {
  4644. int i;
  4645. if (recog_memoized (insn) < 0)
  4646. gcc_unreachable ();
  4647. extract_constrain_insn_cached (insn);
  4648. if (opx_p)
  4649. i = get_attr_opx (insn);
  4650. else
  4651. i = get_attr_opy (insn);
  4652. if (i >= recog_data.n_operands)
  4653. return NULL;
  4654. return recog_data.operand[i];
  4655. }
  4656. /* Return type of INSN's operand X (if OPX_P) or operand Y (if !OPX_P).
  4657. If ADDRESS_P is true, return type of memory location operand refers to. */
  4658. static enum attr_op_type
  4659. sched_attr_op_type (rtx_insn *insn, bool opx_p, bool address_p)
  4660. {
  4661. rtx op;
  4662. op = sched_get_operand (insn, opx_p);
  4663. if (op == NULL)
  4664. {
  4665. gcc_assert (!reload_completed);
  4666. return OP_TYPE_RN;
  4667. }
  4668. if (address_p)
  4669. return sched_address_type (QImode, op);
  4670. if (memory_operand (op, VOIDmode))
  4671. return sched_address_type (GET_MODE (op), XEXP (op, 0));
  4672. if (register_operand (op, VOIDmode))
  4673. {
  4674. if ((!reload_completed && FLOAT_MODE_P (GET_MODE (op)))
  4675. || (reload_completed && FP_REG_P (op)))
  4676. return OP_TYPE_FPN;
  4677. return OP_TYPE_RN;
  4678. }
  4679. if (GET_CODE (op) == CONST_INT)
  4680. {
  4681. int ival;
  4682. ival = INTVAL (op);
  4683. /* Check for quick constants. */
  4684. switch (get_attr_type (insn))
  4685. {
  4686. case TYPE_ALUQ_L:
  4687. if (IN_RANGE (ival, 1, 8) || IN_RANGE (ival, -8, -1))
  4688. return OP_TYPE_IMM_Q;
  4689. gcc_assert (!reload_completed);
  4690. break;
  4691. case TYPE_MOVEQ_L:
  4692. if (USE_MOVQ (ival))
  4693. return OP_TYPE_IMM_Q;
  4694. gcc_assert (!reload_completed);
  4695. break;
  4696. case TYPE_MOV3Q_L:
  4697. if (valid_mov3q_const (ival))
  4698. return OP_TYPE_IMM_Q;
  4699. gcc_assert (!reload_completed);
  4700. break;
  4701. default:
  4702. break;
  4703. }
  4704. if (IN_RANGE (ival, -0x8000, 0x7fff))
  4705. return OP_TYPE_IMM_W;
  4706. return OP_TYPE_IMM_L;
  4707. }
  4708. if (GET_CODE (op) == CONST_DOUBLE)
  4709. {
  4710. switch (GET_MODE (op))
  4711. {
  4712. case SFmode:
  4713. return OP_TYPE_IMM_W;
  4714. case VOIDmode:
  4715. case DFmode:
  4716. return OP_TYPE_IMM_L;
  4717. default:
  4718. gcc_unreachable ();
  4719. }
  4720. }
  4721. if (GET_CODE (op) == CONST
  4722. || symbolic_operand (op, VOIDmode)
  4723. || LABEL_P (op))
  4724. {
  4725. switch (GET_MODE (op))
  4726. {
  4727. case QImode:
  4728. return OP_TYPE_IMM_Q;
  4729. case HImode:
  4730. return OP_TYPE_IMM_W;
  4731. case SImode:
  4732. return OP_TYPE_IMM_L;
  4733. default:
  4734. if (symbolic_operand (m68k_unwrap_symbol (op, false), VOIDmode))
  4735. /* Just a guess. */
  4736. return OP_TYPE_IMM_W;
  4737. return OP_TYPE_IMM_L;
  4738. }
  4739. }
  4740. gcc_assert (!reload_completed);
  4741. if (FLOAT_MODE_P (GET_MODE (op)))
  4742. return OP_TYPE_FPN;
  4743. return OP_TYPE_RN;
  4744. }
  4745. /* Implement opx_type attribute.
  4746. Return type of INSN's operand X.
  4747. If ADDRESS_P is true, return type of memory location operand refers to. */
  4748. enum attr_opx_type
  4749. m68k_sched_attr_opx_type (rtx_insn *insn, int address_p)
  4750. {
  4751. switch (sched_attr_op_type (insn, true, address_p != 0))
  4752. {
  4753. case OP_TYPE_RN:
  4754. return OPX_TYPE_RN;
  4755. case OP_TYPE_FPN:
  4756. return OPX_TYPE_FPN;
  4757. case OP_TYPE_MEM1:
  4758. return OPX_TYPE_MEM1;
  4759. case OP_TYPE_MEM234:
  4760. return OPX_TYPE_MEM234;
  4761. case OP_TYPE_MEM5:
  4762. return OPX_TYPE_MEM5;
  4763. case OP_TYPE_MEM6:
  4764. return OPX_TYPE_MEM6;
  4765. case OP_TYPE_MEM7:
  4766. return OPX_TYPE_MEM7;
  4767. case OP_TYPE_IMM_Q:
  4768. return OPX_TYPE_IMM_Q;
  4769. case OP_TYPE_IMM_W:
  4770. return OPX_TYPE_IMM_W;
  4771. case OP_TYPE_IMM_L:
  4772. return OPX_TYPE_IMM_L;
  4773. default:
  4774. gcc_unreachable ();
  4775. }
  4776. }
  4777. /* Implement opy_type attribute.
  4778. Return type of INSN's operand Y.
  4779. If ADDRESS_P is true, return type of memory location operand refers to. */
  4780. enum attr_opy_type
  4781. m68k_sched_attr_opy_type (rtx_insn *insn, int address_p)
  4782. {
  4783. switch (sched_attr_op_type (insn, false, address_p != 0))
  4784. {
  4785. case OP_TYPE_RN:
  4786. return OPY_TYPE_RN;
  4787. case OP_TYPE_FPN:
  4788. return OPY_TYPE_FPN;
  4789. case OP_TYPE_MEM1:
  4790. return OPY_TYPE_MEM1;
  4791. case OP_TYPE_MEM234:
  4792. return OPY_TYPE_MEM234;
  4793. case OP_TYPE_MEM5:
  4794. return OPY_TYPE_MEM5;
  4795. case OP_TYPE_MEM6:
  4796. return OPY_TYPE_MEM6;
  4797. case OP_TYPE_MEM7:
  4798. return OPY_TYPE_MEM7;
  4799. case OP_TYPE_IMM_Q:
  4800. return OPY_TYPE_IMM_Q;
  4801. case OP_TYPE_IMM_W:
  4802. return OPY_TYPE_IMM_W;
  4803. case OP_TYPE_IMM_L:
  4804. return OPY_TYPE_IMM_L;
  4805. default:
  4806. gcc_unreachable ();
  4807. }
  4808. }
  4809. /* Return size of INSN as int. */
  4810. static int
  4811. sched_get_attr_size_int (rtx_insn *insn)
  4812. {
  4813. int size;
  4814. switch (get_attr_type (insn))
  4815. {
  4816. case TYPE_IGNORE:
  4817. /* There should be no references to m68k_sched_attr_size for 'ignore'
  4818. instructions. */
  4819. gcc_unreachable ();
  4820. return 0;
  4821. case TYPE_MUL_L:
  4822. size = 2;
  4823. break;
  4824. default:
  4825. size = 1;
  4826. break;
  4827. }
  4828. switch (get_attr_opx_type (insn))
  4829. {
  4830. case OPX_TYPE_NONE:
  4831. case OPX_TYPE_RN:
  4832. case OPX_TYPE_FPN:
  4833. case OPX_TYPE_MEM1:
  4834. case OPX_TYPE_MEM234:
  4835. case OPY_TYPE_IMM_Q:
  4836. break;
  4837. case OPX_TYPE_MEM5:
  4838. case OPX_TYPE_MEM6:
  4839. /* Here we assume that most absolute references are short. */
  4840. case OPX_TYPE_MEM7:
  4841. case OPY_TYPE_IMM_W:
  4842. ++size;
  4843. break;
  4844. case OPY_TYPE_IMM_L:
  4845. size += 2;
  4846. break;
  4847. default:
  4848. gcc_unreachable ();
  4849. }
  4850. switch (get_attr_opy_type (insn))
  4851. {
  4852. case OPY_TYPE_NONE:
  4853. case OPY_TYPE_RN:
  4854. case OPY_TYPE_FPN:
  4855. case OPY_TYPE_MEM1:
  4856. case OPY_TYPE_MEM234:
  4857. case OPY_TYPE_IMM_Q:
  4858. break;
  4859. case OPY_TYPE_MEM5:
  4860. case OPY_TYPE_MEM6:
  4861. /* Here we assume that most absolute references are short. */
  4862. case OPY_TYPE_MEM7:
  4863. case OPY_TYPE_IMM_W:
  4864. ++size;
  4865. break;
  4866. case OPY_TYPE_IMM_L:
  4867. size += 2;
  4868. break;
  4869. default:
  4870. gcc_unreachable ();
  4871. }
  4872. if (size > 3)
  4873. {
  4874. gcc_assert (!reload_completed);
  4875. size = 3;
  4876. }
  4877. return size;
  4878. }
  4879. /* Return size of INSN as attribute enum value. */
  4880. enum attr_size
  4881. m68k_sched_attr_size (rtx_insn *insn)
  4882. {
  4883. switch (sched_get_attr_size_int (insn))
  4884. {
  4885. case 1:
  4886. return SIZE_1;
  4887. case 2:
  4888. return SIZE_2;
  4889. case 3:
  4890. return SIZE_3;
  4891. default:
  4892. gcc_unreachable ();
  4893. }
  4894. }
  4895. /* Return operand X or Y (depending on OPX_P) of INSN,
  4896. if it is a MEM, or NULL overwise. */
  4897. static enum attr_op_type
  4898. sched_get_opxy_mem_type (rtx_insn *insn, bool opx_p)
  4899. {
  4900. if (opx_p)
  4901. {
  4902. switch (get_attr_opx_type (insn))
  4903. {
  4904. case OPX_TYPE_NONE:
  4905. case OPX_TYPE_RN:
  4906. case OPX_TYPE_FPN:
  4907. case OPX_TYPE_IMM_Q:
  4908. case OPX_TYPE_IMM_W:
  4909. case OPX_TYPE_IMM_L:
  4910. return OP_TYPE_RN;
  4911. case OPX_TYPE_MEM1:
  4912. case OPX_TYPE_MEM234:
  4913. case OPX_TYPE_MEM5:
  4914. case OPX_TYPE_MEM7:
  4915. return OP_TYPE_MEM1;
  4916. case OPX_TYPE_MEM6:
  4917. return OP_TYPE_MEM6;
  4918. default:
  4919. gcc_unreachable ();
  4920. }
  4921. }
  4922. else
  4923. {
  4924. switch (get_attr_opy_type (insn))
  4925. {
  4926. case OPY_TYPE_NONE:
  4927. case OPY_TYPE_RN:
  4928. case OPY_TYPE_FPN:
  4929. case OPY_TYPE_IMM_Q:
  4930. case OPY_TYPE_IMM_W:
  4931. case OPY_TYPE_IMM_L:
  4932. return OP_TYPE_RN;
  4933. case OPY_TYPE_MEM1:
  4934. case OPY_TYPE_MEM234:
  4935. case OPY_TYPE_MEM5:
  4936. case OPY_TYPE_MEM7:
  4937. return OP_TYPE_MEM1;
  4938. case OPY_TYPE_MEM6:
  4939. return OP_TYPE_MEM6;
  4940. default:
  4941. gcc_unreachable ();
  4942. }
  4943. }
  4944. }
  4945. /* Implement op_mem attribute. */
  4946. enum attr_op_mem
  4947. m68k_sched_attr_op_mem (rtx_insn *insn)
  4948. {
  4949. enum attr_op_type opx;
  4950. enum attr_op_type opy;
  4951. opx = sched_get_opxy_mem_type (insn, true);
  4952. opy = sched_get_opxy_mem_type (insn, false);
  4953. if (opy == OP_TYPE_RN && opx == OP_TYPE_RN)
  4954. return OP_MEM_00;
  4955. if (opy == OP_TYPE_RN && opx == OP_TYPE_MEM1)
  4956. {
  4957. switch (get_attr_opx_access (insn))
  4958. {
  4959. case OPX_ACCESS_R:
  4960. return OP_MEM_10;
  4961. case OPX_ACCESS_W:
  4962. return OP_MEM_01;
  4963. case OPX_ACCESS_RW:
  4964. return OP_MEM_11;
  4965. default:
  4966. gcc_unreachable ();
  4967. }
  4968. }
  4969. if (opy == OP_TYPE_RN && opx == OP_TYPE_MEM6)
  4970. {
  4971. switch (get_attr_opx_access (insn))
  4972. {
  4973. case OPX_ACCESS_R:
  4974. return OP_MEM_I0;
  4975. case OPX_ACCESS_W:
  4976. return OP_MEM_0I;
  4977. case OPX_ACCESS_RW:
  4978. return OP_MEM_I1;
  4979. default:
  4980. gcc_unreachable ();
  4981. }
  4982. }
  4983. if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_RN)
  4984. return OP_MEM_10;
  4985. if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_MEM1)
  4986. {
  4987. switch (get_attr_opx_access (insn))
  4988. {
  4989. case OPX_ACCESS_W:
  4990. return OP_MEM_11;
  4991. default:
  4992. gcc_assert (!reload_completed);
  4993. return OP_MEM_11;
  4994. }
  4995. }
  4996. if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_MEM6)
  4997. {
  4998. switch (get_attr_opx_access (insn))
  4999. {
  5000. case OPX_ACCESS_W:
  5001. return OP_MEM_1I;
  5002. default:
  5003. gcc_assert (!reload_completed);
  5004. return OP_MEM_1I;
  5005. }
  5006. }
  5007. if (opy == OP_TYPE_MEM6 && opx == OP_TYPE_RN)
  5008. return OP_MEM_I0;
  5009. if (opy == OP_TYPE_MEM6 && opx == OP_TYPE_MEM1)
  5010. {
  5011. switch (get_attr_opx_access (insn))
  5012. {
  5013. case OPX_ACCESS_W:
  5014. return OP_MEM_I1;
  5015. default:
  5016. gcc_assert (!reload_completed);
  5017. return OP_MEM_I1;
  5018. }
  5019. }
  5020. gcc_assert (opy == OP_TYPE_MEM6 && opx == OP_TYPE_MEM6);
  5021. gcc_assert (!reload_completed);
  5022. return OP_MEM_I1;
  5023. }
  5024. /* Data for ColdFire V4 index bypass.
  5025. Producer modifies register that is used as index in consumer with
  5026. specified scale. */
  5027. static struct
  5028. {
  5029. /* Producer instruction. */
  5030. rtx pro;
  5031. /* Consumer instruction. */
  5032. rtx con;
  5033. /* Scale of indexed memory access within consumer.
  5034. Or zero if bypass should not be effective at the moment. */
  5035. int scale;
  5036. } sched_cfv4_bypass_data;
  5037. /* An empty state that is used in m68k_sched_adjust_cost. */
  5038. static state_t sched_adjust_cost_state;
  5039. /* Implement adjust_cost scheduler hook.
  5040. Return adjusted COST of dependency LINK between DEF_INSN and INSN. */
  5041. static int
  5042. m68k_sched_adjust_cost (rtx_insn *insn, rtx link ATTRIBUTE_UNUSED,
  5043. rtx_insn *def_insn, int cost)
  5044. {
  5045. int delay;
  5046. if (recog_memoized (def_insn) < 0
  5047. || recog_memoized (insn) < 0)
  5048. return cost;
  5049. if (sched_cfv4_bypass_data.scale == 1)
  5050. /* Handle ColdFire V4 bypass for indexed address with 1x scale. */
  5051. {
  5052. /* haifa-sched.c: insn_cost () calls bypass_p () just before
  5053. targetm.sched.adjust_cost (). Hence, we can be relatively sure
  5054. that the data in sched_cfv4_bypass_data is up to date. */
  5055. gcc_assert (sched_cfv4_bypass_data.pro == def_insn
  5056. && sched_cfv4_bypass_data.con == insn);
  5057. if (cost < 3)
  5058. cost = 3;
  5059. sched_cfv4_bypass_data.pro = NULL;
  5060. sched_cfv4_bypass_data.con = NULL;
  5061. sched_cfv4_bypass_data.scale = 0;
  5062. }
  5063. else
  5064. gcc_assert (sched_cfv4_bypass_data.pro == NULL
  5065. && sched_cfv4_bypass_data.con == NULL
  5066. && sched_cfv4_bypass_data.scale == 0);
  5067. /* Don't try to issue INSN earlier than DFA permits.
  5068. This is especially useful for instructions that write to memory,
  5069. as their true dependence (default) latency is better to be set to 0
  5070. to workaround alias analysis limitations.
  5071. This is, in fact, a machine independent tweak, so, probably,
  5072. it should be moved to haifa-sched.c: insn_cost (). */
  5073. delay = min_insn_conflict_delay (sched_adjust_cost_state, def_insn, insn);
  5074. if (delay > cost)
  5075. cost = delay;
  5076. return cost;
  5077. }
  5078. /* Return maximal number of insns that can be scheduled on a single cycle. */
  5079. static int
  5080. m68k_sched_issue_rate (void)
  5081. {
  5082. switch (m68k_sched_cpu)
  5083. {
  5084. case CPU_CFV1:
  5085. case CPU_CFV2:
  5086. case CPU_CFV3:
  5087. return 1;
  5088. case CPU_CFV4:
  5089. return 2;
  5090. default:
  5091. gcc_unreachable ();
  5092. return 0;
  5093. }
  5094. }
  5095. /* Maximal length of instruction for current CPU.
  5096. E.g. it is 3 for any ColdFire core. */
  5097. static int max_insn_size;
  5098. /* Data to model instruction buffer of CPU. */
  5099. struct _sched_ib
  5100. {
  5101. /* True if instruction buffer model is modeled for current CPU. */
  5102. bool enabled_p;
  5103. /* Size of the instruction buffer in words. */
  5104. int size;
  5105. /* Number of filled words in the instruction buffer. */
  5106. int filled;
  5107. /* Additional information about instruction buffer for CPUs that have
  5108. a buffer of instruction records, rather then a plain buffer
  5109. of instruction words. */
  5110. struct _sched_ib_records
  5111. {
  5112. /* Size of buffer in records. */
  5113. int n_insns;
  5114. /* Array to hold data on adjustements made to the size of the buffer. */
  5115. int *adjust;
  5116. /* Index of the above array. */
  5117. int adjust_index;
  5118. } records;
  5119. /* An insn that reserves (marks empty) one word in the instruction buffer. */
  5120. rtx insn;
  5121. };
  5122. static struct _sched_ib sched_ib;
  5123. /* ID of memory unit. */
  5124. static int sched_mem_unit_code;
  5125. /* Implementation of the targetm.sched.variable_issue () hook.
  5126. It is called after INSN was issued. It returns the number of insns
  5127. that can possibly get scheduled on the current cycle.
  5128. It is used here to determine the effect of INSN on the instruction
  5129. buffer. */
  5130. static int
  5131. m68k_sched_variable_issue (FILE *sched_dump ATTRIBUTE_UNUSED,
  5132. int sched_verbose ATTRIBUTE_UNUSED,
  5133. rtx_insn *insn, int can_issue_more)
  5134. {
  5135. int insn_size;
  5136. if (recog_memoized (insn) >= 0 && get_attr_type (insn) != TYPE_IGNORE)
  5137. {
  5138. switch (m68k_sched_cpu)
  5139. {
  5140. case CPU_CFV1:
  5141. case CPU_CFV2:
  5142. insn_size = sched_get_attr_size_int (insn);
  5143. break;
  5144. case CPU_CFV3:
  5145. insn_size = sched_get_attr_size_int (insn);
  5146. /* ColdFire V3 and V4 cores have instruction buffers that can
  5147. accumulate up to 8 instructions regardless of instructions'
  5148. sizes. So we should take care not to "prefetch" 24 one-word
  5149. or 12 two-words instructions.
  5150. To model this behavior we temporarily decrease size of the
  5151. buffer by (max_insn_size - insn_size) for next 7 instructions. */
  5152. {
  5153. int adjust;
  5154. adjust = max_insn_size - insn_size;
  5155. sched_ib.size -= adjust;
  5156. if (sched_ib.filled > sched_ib.size)
  5157. sched_ib.filled = sched_ib.size;
  5158. sched_ib.records.adjust[sched_ib.records.adjust_index] = adjust;
  5159. }
  5160. ++sched_ib.records.adjust_index;
  5161. if (sched_ib.records.adjust_index == sched_ib.records.n_insns)
  5162. sched_ib.records.adjust_index = 0;
  5163. /* Undo adjustement we did 7 instructions ago. */
  5164. sched_ib.size
  5165. += sched_ib.records.adjust[sched_ib.records.adjust_index];
  5166. break;
  5167. case CPU_CFV4:
  5168. gcc_assert (!sched_ib.enabled_p);
  5169. insn_size = 0;
  5170. break;
  5171. default:
  5172. gcc_unreachable ();
  5173. }
  5174. if (insn_size > sched_ib.filled)
  5175. /* Scheduling for register pressure does not always take DFA into
  5176. account. Workaround instruction buffer not being filled enough. */
  5177. {
  5178. gcc_assert (sched_pressure == SCHED_PRESSURE_WEIGHTED);
  5179. insn_size = sched_ib.filled;
  5180. }
  5181. --can_issue_more;
  5182. }
  5183. else if (GET_CODE (PATTERN (insn)) == ASM_INPUT
  5184. || asm_noperands (PATTERN (insn)) >= 0)
  5185. insn_size = sched_ib.filled;
  5186. else
  5187. insn_size = 0;
  5188. sched_ib.filled -= insn_size;
  5189. return can_issue_more;
  5190. }
  5191. /* Return how many instructions should scheduler lookahead to choose the
  5192. best one. */
  5193. static int
  5194. m68k_sched_first_cycle_multipass_dfa_lookahead (void)
  5195. {
  5196. return m68k_sched_issue_rate () - 1;
  5197. }
  5198. /* Implementation of targetm.sched.init_global () hook.
  5199. It is invoked once per scheduling pass and is used here
  5200. to initialize scheduler constants. */
  5201. static void
  5202. m68k_sched_md_init_global (FILE *sched_dump ATTRIBUTE_UNUSED,
  5203. int sched_verbose ATTRIBUTE_UNUSED,
  5204. int n_insns ATTRIBUTE_UNUSED)
  5205. {
  5206. #ifdef ENABLE_CHECKING
  5207. /* Check that all instructions have DFA reservations and
  5208. that all instructions can be issued from a clean state. */
  5209. {
  5210. rtx_insn *insn;
  5211. state_t state;
  5212. state = alloca (state_size ());
  5213. for (insn = get_insns (); insn != NULL; insn = NEXT_INSN (insn))
  5214. {
  5215. if (INSN_P (insn) && recog_memoized (insn) >= 0)
  5216. {
  5217. gcc_assert (insn_has_dfa_reservation_p (insn));
  5218. state_reset (state);
  5219. if (state_transition (state, insn) >= 0)
  5220. gcc_unreachable ();
  5221. }
  5222. }
  5223. }
  5224. #endif
  5225. /* Setup target cpu. */
  5226. /* ColdFire V4 has a set of features to keep its instruction buffer full
  5227. (e.g., a separate memory bus for instructions) and, hence, we do not model
  5228. buffer for this CPU. */
  5229. sched_ib.enabled_p = (m68k_sched_cpu != CPU_CFV4);
  5230. switch (m68k_sched_cpu)
  5231. {
  5232. case CPU_CFV4:
  5233. sched_ib.filled = 0;
  5234. /* FALLTHRU */
  5235. case CPU_CFV1:
  5236. case CPU_CFV2:
  5237. max_insn_size = 3;
  5238. sched_ib.records.n_insns = 0;
  5239. sched_ib.records.adjust = NULL;
  5240. break;
  5241. case CPU_CFV3:
  5242. max_insn_size = 3;
  5243. sched_ib.records.n_insns = 8;
  5244. sched_ib.records.adjust = XNEWVEC (int, sched_ib.records.n_insns);
  5245. break;
  5246. default:
  5247. gcc_unreachable ();
  5248. }
  5249. sched_mem_unit_code = get_cpu_unit_code ("cf_mem1");
  5250. sched_adjust_cost_state = xmalloc (state_size ());
  5251. state_reset (sched_adjust_cost_state);
  5252. start_sequence ();
  5253. emit_insn (gen_ib ());
  5254. sched_ib.insn = get_insns ();
  5255. end_sequence ();
  5256. }
  5257. /* Scheduling pass is now finished. Free/reset static variables. */
  5258. static void
  5259. m68k_sched_md_finish_global (FILE *dump ATTRIBUTE_UNUSED,
  5260. int verbose ATTRIBUTE_UNUSED)
  5261. {
  5262. sched_ib.insn = NULL;
  5263. free (sched_adjust_cost_state);
  5264. sched_adjust_cost_state = NULL;
  5265. sched_mem_unit_code = 0;
  5266. free (sched_ib.records.adjust);
  5267. sched_ib.records.adjust = NULL;
  5268. sched_ib.records.n_insns = 0;
  5269. max_insn_size = 0;
  5270. }
  5271. /* Implementation of targetm.sched.init () hook.
  5272. It is invoked each time scheduler starts on the new block (basic block or
  5273. extended basic block). */
  5274. static void
  5275. m68k_sched_md_init (FILE *sched_dump ATTRIBUTE_UNUSED,
  5276. int sched_verbose ATTRIBUTE_UNUSED,
  5277. int n_insns ATTRIBUTE_UNUSED)
  5278. {
  5279. switch (m68k_sched_cpu)
  5280. {
  5281. case CPU_CFV1:
  5282. case CPU_CFV2:
  5283. sched_ib.size = 6;
  5284. break;
  5285. case CPU_CFV3:
  5286. sched_ib.size = sched_ib.records.n_insns * max_insn_size;
  5287. memset (sched_ib.records.adjust, 0,
  5288. sched_ib.records.n_insns * sizeof (*sched_ib.records.adjust));
  5289. sched_ib.records.adjust_index = 0;
  5290. break;
  5291. case CPU_CFV4:
  5292. gcc_assert (!sched_ib.enabled_p);
  5293. sched_ib.size = 0;
  5294. break;
  5295. default:
  5296. gcc_unreachable ();
  5297. }
  5298. if (sched_ib.enabled_p)
  5299. /* haifa-sched.c: schedule_block () calls advance_cycle () just before
  5300. the first cycle. Workaround that. */
  5301. sched_ib.filled = -2;
  5302. }
  5303. /* Implementation of targetm.sched.dfa_pre_advance_cycle () hook.
  5304. It is invoked just before current cycle finishes and is used here
  5305. to track if instruction buffer got its two words this cycle. */
  5306. static void
  5307. m68k_sched_dfa_pre_advance_cycle (void)
  5308. {
  5309. if (!sched_ib.enabled_p)
  5310. return;
  5311. if (!cpu_unit_reservation_p (curr_state, sched_mem_unit_code))
  5312. {
  5313. sched_ib.filled += 2;
  5314. if (sched_ib.filled > sched_ib.size)
  5315. sched_ib.filled = sched_ib.size;
  5316. }
  5317. }
  5318. /* Implementation of targetm.sched.dfa_post_advance_cycle () hook.
  5319. It is invoked just after new cycle begins and is used here
  5320. to setup number of filled words in the instruction buffer so that
  5321. instructions which won't have all their words prefetched would be
  5322. stalled for a cycle. */
  5323. static void
  5324. m68k_sched_dfa_post_advance_cycle (void)
  5325. {
  5326. int i;
  5327. if (!sched_ib.enabled_p)
  5328. return;
  5329. /* Setup number of prefetched instruction words in the instruction
  5330. buffer. */
  5331. i = max_insn_size - sched_ib.filled;
  5332. while (--i >= 0)
  5333. {
  5334. if (state_transition (curr_state, sched_ib.insn) >= 0)
  5335. /* Pick up scheduler state. */
  5336. ++sched_ib.filled;
  5337. }
  5338. }
  5339. /* Return X or Y (depending on OPX_P) operand of INSN,
  5340. if it is an integer register, or NULL overwise. */
  5341. static rtx
  5342. sched_get_reg_operand (rtx_insn *insn, bool opx_p)
  5343. {
  5344. rtx op = NULL;
  5345. if (opx_p)
  5346. {
  5347. if (get_attr_opx_type (insn) == OPX_TYPE_RN)
  5348. {
  5349. op = sched_get_operand (insn, true);
  5350. gcc_assert (op != NULL);
  5351. if (!reload_completed && !REG_P (op))
  5352. return NULL;
  5353. }
  5354. }
  5355. else
  5356. {
  5357. if (get_attr_opy_type (insn) == OPY_TYPE_RN)
  5358. {
  5359. op = sched_get_operand (insn, false);
  5360. gcc_assert (op != NULL);
  5361. if (!reload_completed && !REG_P (op))
  5362. return NULL;
  5363. }
  5364. }
  5365. return op;
  5366. }
  5367. /* Return true, if X or Y (depending on OPX_P) operand of INSN
  5368. is a MEM. */
  5369. static bool
  5370. sched_mem_operand_p (rtx_insn *insn, bool opx_p)
  5371. {
  5372. switch (sched_get_opxy_mem_type (insn, opx_p))
  5373. {
  5374. case OP_TYPE_MEM1:
  5375. case OP_TYPE_MEM6:
  5376. return true;
  5377. default:
  5378. return false;
  5379. }
  5380. }
  5381. /* Return X or Y (depending on OPX_P) operand of INSN,
  5382. if it is a MEM, or NULL overwise. */
  5383. static rtx
  5384. sched_get_mem_operand (rtx_insn *insn, bool must_read_p, bool must_write_p)
  5385. {
  5386. bool opx_p;
  5387. bool opy_p;
  5388. opx_p = false;
  5389. opy_p = false;
  5390. if (must_read_p)
  5391. {
  5392. opx_p = true;
  5393. opy_p = true;
  5394. }
  5395. if (must_write_p)
  5396. {
  5397. opx_p = true;
  5398. opy_p = false;
  5399. }
  5400. if (opy_p && sched_mem_operand_p (insn, false))
  5401. return sched_get_operand (insn, false);
  5402. if (opx_p && sched_mem_operand_p (insn, true))
  5403. return sched_get_operand (insn, true);
  5404. gcc_unreachable ();
  5405. return NULL;
  5406. }
  5407. /* Return non-zero if PRO modifies register used as part of
  5408. address in CON. */
  5409. int
  5410. m68k_sched_address_bypass_p (rtx_insn *pro, rtx_insn *con)
  5411. {
  5412. rtx pro_x;
  5413. rtx con_mem_read;
  5414. pro_x = sched_get_reg_operand (pro, true);
  5415. if (pro_x == NULL)
  5416. return 0;
  5417. con_mem_read = sched_get_mem_operand (con, true, false);
  5418. gcc_assert (con_mem_read != NULL);
  5419. if (reg_mentioned_p (pro_x, con_mem_read))
  5420. return 1;
  5421. return 0;
  5422. }
  5423. /* Helper function for m68k_sched_indexed_address_bypass_p.
  5424. if PRO modifies register used as index in CON,
  5425. return scale of indexed memory access in CON. Return zero overwise. */
  5426. static int
  5427. sched_get_indexed_address_scale (rtx_insn *pro, rtx_insn *con)
  5428. {
  5429. rtx reg;
  5430. rtx mem;
  5431. struct m68k_address address;
  5432. reg = sched_get_reg_operand (pro, true);
  5433. if (reg == NULL)
  5434. return 0;
  5435. mem = sched_get_mem_operand (con, true, false);
  5436. gcc_assert (mem != NULL && MEM_P (mem));
  5437. if (!m68k_decompose_address (GET_MODE (mem), XEXP (mem, 0), reload_completed,
  5438. &address))
  5439. gcc_unreachable ();
  5440. if (REGNO (reg) == REGNO (address.index))
  5441. {
  5442. gcc_assert (address.scale != 0);
  5443. return address.scale;
  5444. }
  5445. return 0;
  5446. }
  5447. /* Return non-zero if PRO modifies register used
  5448. as index with scale 2 or 4 in CON. */
  5449. int
  5450. m68k_sched_indexed_address_bypass_p (rtx_insn *pro, rtx_insn *con)
  5451. {
  5452. gcc_assert (sched_cfv4_bypass_data.pro == NULL
  5453. && sched_cfv4_bypass_data.con == NULL
  5454. && sched_cfv4_bypass_data.scale == 0);
  5455. switch (sched_get_indexed_address_scale (pro, con))
  5456. {
  5457. case 1:
  5458. /* We can't have a variable latency bypass, so
  5459. remember to adjust the insn cost in adjust_cost hook. */
  5460. sched_cfv4_bypass_data.pro = pro;
  5461. sched_cfv4_bypass_data.con = con;
  5462. sched_cfv4_bypass_data.scale = 1;
  5463. return 0;
  5464. case 2:
  5465. case 4:
  5466. return 1;
  5467. default:
  5468. return 0;
  5469. }
  5470. }
  5471. /* We generate a two-instructions program at M_TRAMP :
  5472. movea.l &CHAIN_VALUE,%a0
  5473. jmp FNADDR
  5474. where %a0 can be modified by changing STATIC_CHAIN_REGNUM. */
  5475. static void
  5476. m68k_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
  5477. {
  5478. rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
  5479. rtx mem;
  5480. gcc_assert (ADDRESS_REGNO_P (STATIC_CHAIN_REGNUM));
  5481. mem = adjust_address (m_tramp, HImode, 0);
  5482. emit_move_insn (mem, GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9)));
  5483. mem = adjust_address (m_tramp, SImode, 2);
  5484. emit_move_insn (mem, chain_value);
  5485. mem = adjust_address (m_tramp, HImode, 6);
  5486. emit_move_insn (mem, GEN_INT(0x4EF9));
  5487. mem = adjust_address (m_tramp, SImode, 8);
  5488. emit_move_insn (mem, fnaddr);
  5489. FINALIZE_TRAMPOLINE (XEXP (m_tramp, 0));
  5490. }
  5491. /* On the 68000, the RTS insn cannot pop anything.
  5492. On the 68010, the RTD insn may be used to pop them if the number
  5493. of args is fixed, but if the number is variable then the caller
  5494. must pop them all. RTD can't be used for library calls now
  5495. because the library is compiled with the Unix compiler.
  5496. Use of RTD is a selectable option, since it is incompatible with
  5497. standard Unix calling sequences. If the option is not selected,
  5498. the caller must always pop the args. */
  5499. static int
  5500. m68k_return_pops_args (tree fundecl, tree funtype, int size)
  5501. {
  5502. return ((TARGET_RTD
  5503. && (!fundecl
  5504. || TREE_CODE (fundecl) != IDENTIFIER_NODE)
  5505. && (!stdarg_p (funtype)))
  5506. ? size : 0);
  5507. }
  5508. /* Make sure everything's fine if we *don't* have a given processor.
  5509. This assumes that putting a register in fixed_regs will keep the
  5510. compiler's mitts completely off it. We don't bother to zero it out
  5511. of register classes. */
  5512. static void
  5513. m68k_conditional_register_usage (void)
  5514. {
  5515. int i;
  5516. HARD_REG_SET x;
  5517. if (!TARGET_HARD_FLOAT)
  5518. {
  5519. COPY_HARD_REG_SET (x, reg_class_contents[(int)FP_REGS]);
  5520. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  5521. if (TEST_HARD_REG_BIT (x, i))
  5522. fixed_regs[i] = call_used_regs[i] = 1;
  5523. }
  5524. if (flag_pic)
  5525. fixed_regs[PIC_REG] = call_used_regs[PIC_REG] = 1;
  5526. }
  5527. static void
  5528. m68k_init_sync_libfuncs (void)
  5529. {
  5530. init_sync_libfuncs (UNITS_PER_WORD);
  5531. }
  5532. /* Implements EPILOGUE_USES. All registers are live on exit from an
  5533. interrupt routine. */
  5534. bool
  5535. m68k_epilogue_uses (int regno ATTRIBUTE_UNUSED)
  5536. {
  5537. return (reload_completed
  5538. && (m68k_get_function_kind (current_function_decl)
  5539. == m68k_fk_interrupt_handler));
  5540. }
  5541. #include "gt-m68k.h"