calls.c 160 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076
  1. /* Convert function calls to rtl insns, for GNU C compiler.
  2. Copyright (C) 1989-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "tm.h"
  19. #include "rtl.h"
  20. #include "hash-set.h"
  21. #include "machmode.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "fold-const.h"
  31. #include "stor-layout.h"
  32. #include "varasm.h"
  33. #include "stringpool.h"
  34. #include "attribs.h"
  35. #include "predict.h"
  36. #include "hashtab.h"
  37. #include "hard-reg-set.h"
  38. #include "function.h"
  39. #include "basic-block.h"
  40. #include "tree-ssa-alias.h"
  41. #include "internal-fn.h"
  42. #include "gimple-expr.h"
  43. #include "is-a.h"
  44. #include "gimple.h"
  45. #include "flags.h"
  46. #include "statistics.h"
  47. #include "real.h"
  48. #include "fixed-value.h"
  49. #include "insn-config.h"
  50. #include "expmed.h"
  51. #include "dojump.h"
  52. #include "explow.h"
  53. #include "calls.h"
  54. #include "emit-rtl.h"
  55. #include "stmt.h"
  56. #include "expr.h"
  57. #include "insn-codes.h"
  58. #include "optabs.h"
  59. #include "libfuncs.h"
  60. #include "regs.h"
  61. #include "diagnostic-core.h"
  62. #include "output.h"
  63. #include "tm_p.h"
  64. #include "timevar.h"
  65. #include "sbitmap.h"
  66. #include "bitmap.h"
  67. #include "langhooks.h"
  68. #include "target.h"
  69. #include "hash-map.h"
  70. #include "plugin-api.h"
  71. #include "ipa-ref.h"
  72. #include "cgraph.h"
  73. #include "except.h"
  74. #include "dbgcnt.h"
  75. #include "rtl-iter.h"
  76. #include "tree-chkp.h"
  77. #include "rtl-chkp.h"
  78. /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
  79. #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
  80. /* Data structure and subroutines used within expand_call. */
  81. struct arg_data
  82. {
  83. /* Tree node for this argument. */
  84. tree tree_value;
  85. /* Mode for value; TYPE_MODE unless promoted. */
  86. machine_mode mode;
  87. /* Current RTL value for argument, or 0 if it isn't precomputed. */
  88. rtx value;
  89. /* Initially-compute RTL value for argument; only for const functions. */
  90. rtx initial_value;
  91. /* Register to pass this argument in, 0 if passed on stack, or an
  92. PARALLEL if the arg is to be copied into multiple non-contiguous
  93. registers. */
  94. rtx reg;
  95. /* Register to pass this argument in when generating tail call sequence.
  96. This is not the same register as for normal calls on machines with
  97. register windows. */
  98. rtx tail_call_reg;
  99. /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
  100. form for emit_group_move. */
  101. rtx parallel_value;
  102. /* If value is passed in neither reg nor stack, this field holds a number
  103. of a special slot to be used. */
  104. rtx special_slot;
  105. /* For pointer bounds hold an index of parm bounds are bound to. -1 if
  106. there is no such pointer. */
  107. int pointer_arg;
  108. /* If pointer_arg refers a structure, then pointer_offset holds an offset
  109. of a pointer in this structure. */
  110. int pointer_offset;
  111. /* If REG was promoted from the actual mode of the argument expression,
  112. indicates whether the promotion is sign- or zero-extended. */
  113. int unsignedp;
  114. /* Number of bytes to put in registers. 0 means put the whole arg
  115. in registers. Also 0 if not passed in registers. */
  116. int partial;
  117. /* Nonzero if argument must be passed on stack.
  118. Note that some arguments may be passed on the stack
  119. even though pass_on_stack is zero, just because FUNCTION_ARG says so.
  120. pass_on_stack identifies arguments that *cannot* go in registers. */
  121. int pass_on_stack;
  122. /* Some fields packaged up for locate_and_pad_parm. */
  123. struct locate_and_pad_arg_data locate;
  124. /* Location on the stack at which parameter should be stored. The store
  125. has already been done if STACK == VALUE. */
  126. rtx stack;
  127. /* Location on the stack of the start of this argument slot. This can
  128. differ from STACK if this arg pads downward. This location is known
  129. to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
  130. rtx stack_slot;
  131. /* Place that this stack area has been saved, if needed. */
  132. rtx save_area;
  133. /* If an argument's alignment does not permit direct copying into registers,
  134. copy in smaller-sized pieces into pseudos. These are stored in a
  135. block pointed to by this field. The next field says how many
  136. word-sized pseudos we made. */
  137. rtx *aligned_regs;
  138. int n_aligned_regs;
  139. };
  140. /* A vector of one char per byte of stack space. A byte if nonzero if
  141. the corresponding stack location has been used.
  142. This vector is used to prevent a function call within an argument from
  143. clobbering any stack already set up. */
  144. static char *stack_usage_map;
  145. /* Size of STACK_USAGE_MAP. */
  146. static int highest_outgoing_arg_in_use;
  147. /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
  148. stack location's tail call argument has been already stored into the stack.
  149. This bitmap is used to prevent sibling call optimization if function tries
  150. to use parent's incoming argument slots when they have been already
  151. overwritten with tail call arguments. */
  152. static sbitmap stored_args_map;
  153. /* stack_arg_under_construction is nonzero when an argument may be
  154. initialized with a constructor call (including a C function that
  155. returns a BLKmode struct) and expand_call must take special action
  156. to make sure the object being constructed does not overlap the
  157. argument list for the constructor call. */
  158. static int stack_arg_under_construction;
  159. static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
  160. HOST_WIDE_INT, rtx, rtx, int, rtx, int,
  161. cumulative_args_t);
  162. static void precompute_register_parameters (int, struct arg_data *, int *);
  163. static void store_bounds (struct arg_data *, struct arg_data *);
  164. static int store_one_arg (struct arg_data *, rtx, int, int, int);
  165. static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
  166. static int finalize_must_preallocate (int, int, struct arg_data *,
  167. struct args_size *);
  168. static void precompute_arguments (int, struct arg_data *);
  169. static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
  170. static void initialize_argument_information (int, struct arg_data *,
  171. struct args_size *, int,
  172. tree, tree,
  173. tree, tree, cumulative_args_t, int,
  174. rtx *, int *, int *, int *,
  175. bool *, bool);
  176. static void compute_argument_addresses (struct arg_data *, rtx, int);
  177. static rtx rtx_for_function_call (tree, tree);
  178. static void load_register_parameters (struct arg_data *, int, rtx *, int,
  179. int, int *);
  180. static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
  181. machine_mode, int, va_list);
  182. static int special_function_p (const_tree, int);
  183. static int check_sibcall_argument_overlap_1 (rtx);
  184. static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
  185. static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
  186. unsigned int);
  187. static tree split_complex_types (tree);
  188. #ifdef REG_PARM_STACK_SPACE
  189. static rtx save_fixed_argument_area (int, rtx, int *, int *);
  190. static void restore_fixed_argument_area (rtx, rtx, int, int);
  191. #endif
  192. /* Force FUNEXP into a form suitable for the address of a CALL,
  193. and return that as an rtx. Also load the static chain register
  194. if FNDECL is a nested function.
  195. CALL_FUSAGE points to a variable holding the prospective
  196. CALL_INSN_FUNCTION_USAGE information. */
  197. rtx
  198. prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value,
  199. rtx *call_fusage, int reg_parm_seen, int sibcallp)
  200. {
  201. /* Make a valid memory address and copy constants through pseudo-regs,
  202. but not for a constant address if -fno-function-cse. */
  203. if (GET_CODE (funexp) != SYMBOL_REF)
  204. /* If we are using registers for parameters, force the
  205. function address into a register now. */
  206. funexp = ((reg_parm_seen
  207. && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
  208. ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
  209. : memory_address (FUNCTION_MODE, funexp));
  210. else if (! sibcallp)
  211. {
  212. #ifndef NO_FUNCTION_CSE
  213. if (optimize && ! flag_no_function_cse)
  214. funexp = force_reg (Pmode, funexp);
  215. #endif
  216. }
  217. if (static_chain_value != 0
  218. && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
  219. || DECL_STATIC_CHAIN (fndecl_or_type)))
  220. {
  221. rtx chain;
  222. chain = targetm.calls.static_chain (fndecl_or_type, false);
  223. static_chain_value = convert_memory_address (Pmode, static_chain_value);
  224. emit_move_insn (chain, static_chain_value);
  225. if (REG_P (chain))
  226. use_reg (call_fusage, chain);
  227. }
  228. return funexp;
  229. }
  230. /* Generate instructions to call function FUNEXP,
  231. and optionally pop the results.
  232. The CALL_INSN is the first insn generated.
  233. FNDECL is the declaration node of the function. This is given to the
  234. hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
  235. its own args.
  236. FUNTYPE is the data type of the function. This is given to the hook
  237. TARGET_RETURN_POPS_ARGS to determine whether this function pops its
  238. own args. We used to allow an identifier for library functions, but
  239. that doesn't work when the return type is an aggregate type and the
  240. calling convention says that the pointer to this aggregate is to be
  241. popped by the callee.
  242. STACK_SIZE is the number of bytes of arguments on the stack,
  243. ROUNDED_STACK_SIZE is that number rounded up to
  244. PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
  245. both to put into the call insn and to generate explicit popping
  246. code if necessary.
  247. STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
  248. It is zero if this call doesn't want a structure value.
  249. NEXT_ARG_REG is the rtx that results from executing
  250. targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
  251. just after all the args have had their registers assigned.
  252. This could be whatever you like, but normally it is the first
  253. arg-register beyond those used for args in this call,
  254. or 0 if all the arg-registers are used in this call.
  255. It is passed on to `gen_call' so you can put this info in the call insn.
  256. VALREG is a hard register in which a value is returned,
  257. or 0 if the call does not return a value.
  258. OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
  259. the args to this call were processed.
  260. We restore `inhibit_defer_pop' to that value.
  261. CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
  262. denote registers used by the called function. */
  263. static void
  264. emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
  265. tree funtype ATTRIBUTE_UNUSED,
  266. HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
  267. HOST_WIDE_INT rounded_stack_size,
  268. HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
  269. rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
  270. int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
  271. cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
  272. {
  273. rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
  274. rtx_insn *call_insn;
  275. rtx call, funmem;
  276. int already_popped = 0;
  277. HOST_WIDE_INT n_popped
  278. = targetm.calls.return_pops_args (fndecl, funtype, stack_size);
  279. #ifdef CALL_POPS_ARGS
  280. n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
  281. #endif
  282. /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
  283. and we don't want to load it into a register as an optimization,
  284. because prepare_call_address already did it if it should be done. */
  285. if (GET_CODE (funexp) != SYMBOL_REF)
  286. funexp = memory_address (FUNCTION_MODE, funexp);
  287. funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
  288. if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
  289. {
  290. tree t = fndecl;
  291. /* Although a built-in FUNCTION_DECL and its non-__builtin
  292. counterpart compare equal and get a shared mem_attrs, they
  293. produce different dump output in compare-debug compilations,
  294. if an entry gets garbage collected in one compilation, then
  295. adds a different (but equivalent) entry, while the other
  296. doesn't run the garbage collector at the same spot and then
  297. shares the mem_attr with the equivalent entry. */
  298. if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
  299. {
  300. tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
  301. if (t2)
  302. t = t2;
  303. }
  304. set_mem_expr (funmem, t);
  305. }
  306. else if (fntree)
  307. set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
  308. #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
  309. if ((ecf_flags & ECF_SIBCALL)
  310. && HAVE_sibcall_pop && HAVE_sibcall_value_pop
  311. && (n_popped > 0 || stack_size == 0))
  312. {
  313. rtx n_pop = GEN_INT (n_popped);
  314. rtx pat;
  315. /* If this subroutine pops its own args, record that in the call insn
  316. if possible, for the sake of frame pointer elimination. */
  317. if (valreg)
  318. pat = GEN_SIBCALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
  319. next_arg_reg, n_pop);
  320. else
  321. pat = GEN_SIBCALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
  322. n_pop);
  323. emit_call_insn (pat);
  324. already_popped = 1;
  325. }
  326. else
  327. #endif
  328. #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
  329. /* If the target has "call" or "call_value" insns, then prefer them
  330. if no arguments are actually popped. If the target does not have
  331. "call" or "call_value" insns, then we must use the popping versions
  332. even if the call has no arguments to pop. */
  333. #if defined (HAVE_call) && defined (HAVE_call_value)
  334. if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
  335. && n_popped > 0)
  336. #else
  337. if (HAVE_call_pop && HAVE_call_value_pop)
  338. #endif
  339. {
  340. rtx n_pop = GEN_INT (n_popped);
  341. rtx pat;
  342. /* If this subroutine pops its own args, record that in the call insn
  343. if possible, for the sake of frame pointer elimination. */
  344. if (valreg)
  345. pat = GEN_CALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
  346. next_arg_reg, n_pop);
  347. else
  348. pat = GEN_CALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
  349. n_pop);
  350. emit_call_insn (pat);
  351. already_popped = 1;
  352. }
  353. else
  354. #endif
  355. #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
  356. if ((ecf_flags & ECF_SIBCALL)
  357. && HAVE_sibcall && HAVE_sibcall_value)
  358. {
  359. if (valreg)
  360. emit_call_insn (GEN_SIBCALL_VALUE (valreg, funmem,
  361. rounded_stack_size_rtx,
  362. next_arg_reg, NULL_RTX));
  363. else
  364. emit_call_insn (GEN_SIBCALL (funmem, rounded_stack_size_rtx,
  365. next_arg_reg,
  366. GEN_INT (struct_value_size)));
  367. }
  368. else
  369. #endif
  370. #if defined (HAVE_call) && defined (HAVE_call_value)
  371. if (HAVE_call && HAVE_call_value)
  372. {
  373. if (valreg)
  374. emit_call_insn (GEN_CALL_VALUE (valreg, funmem, rounded_stack_size_rtx,
  375. next_arg_reg, NULL_RTX));
  376. else
  377. emit_call_insn (GEN_CALL (funmem, rounded_stack_size_rtx, next_arg_reg,
  378. GEN_INT (struct_value_size)));
  379. }
  380. else
  381. #endif
  382. gcc_unreachable ();
  383. /* Find the call we just emitted. */
  384. call_insn = last_call_insn ();
  385. /* Some target create a fresh MEM instead of reusing the one provided
  386. above. Set its MEM_EXPR. */
  387. call = get_call_rtx_from (call_insn);
  388. if (call
  389. && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
  390. && MEM_EXPR (funmem) != NULL_TREE)
  391. set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
  392. /* Mark instrumented calls. */
  393. if (call && fntree)
  394. CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
  395. /* Put the register usage information there. */
  396. add_function_usage_to (call_insn, call_fusage);
  397. /* If this is a const call, then set the insn's unchanging bit. */
  398. if (ecf_flags & ECF_CONST)
  399. RTL_CONST_CALL_P (call_insn) = 1;
  400. /* If this is a pure call, then set the insn's unchanging bit. */
  401. if (ecf_flags & ECF_PURE)
  402. RTL_PURE_CALL_P (call_insn) = 1;
  403. /* If this is a const call, then set the insn's unchanging bit. */
  404. if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
  405. RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
  406. /* Create a nothrow REG_EH_REGION note, if needed. */
  407. make_reg_eh_region_note (call_insn, ecf_flags, 0);
  408. if (ecf_flags & ECF_NORETURN)
  409. add_reg_note (call_insn, REG_NORETURN, const0_rtx);
  410. if (ecf_flags & ECF_RETURNS_TWICE)
  411. {
  412. add_reg_note (call_insn, REG_SETJMP, const0_rtx);
  413. cfun->calls_setjmp = 1;
  414. }
  415. SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
  416. /* Restore this now, so that we do defer pops for this call's args
  417. if the context of the call as a whole permits. */
  418. inhibit_defer_pop = old_inhibit_defer_pop;
  419. if (n_popped > 0)
  420. {
  421. if (!already_popped)
  422. CALL_INSN_FUNCTION_USAGE (call_insn)
  423. = gen_rtx_EXPR_LIST (VOIDmode,
  424. gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
  425. CALL_INSN_FUNCTION_USAGE (call_insn));
  426. rounded_stack_size -= n_popped;
  427. rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
  428. stack_pointer_delta -= n_popped;
  429. add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
  430. /* If popup is needed, stack realign must use DRAP */
  431. if (SUPPORTS_STACK_ALIGNMENT)
  432. crtl->need_drap = true;
  433. }
  434. /* For noreturn calls when not accumulating outgoing args force
  435. REG_ARGS_SIZE note to prevent crossjumping of calls with different
  436. args sizes. */
  437. else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
  438. add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
  439. if (!ACCUMULATE_OUTGOING_ARGS)
  440. {
  441. /* If returning from the subroutine does not automatically pop the args,
  442. we need an instruction to pop them sooner or later.
  443. Perhaps do it now; perhaps just record how much space to pop later.
  444. If returning from the subroutine does pop the args, indicate that the
  445. stack pointer will be changed. */
  446. if (rounded_stack_size != 0)
  447. {
  448. if (ecf_flags & ECF_NORETURN)
  449. /* Just pretend we did the pop. */
  450. stack_pointer_delta -= rounded_stack_size;
  451. else if (flag_defer_pop && inhibit_defer_pop == 0
  452. && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
  453. pending_stack_adjust += rounded_stack_size;
  454. else
  455. adjust_stack (rounded_stack_size_rtx);
  456. }
  457. }
  458. /* When we accumulate outgoing args, we must avoid any stack manipulations.
  459. Restore the stack pointer to its original value now. Usually
  460. ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
  461. On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
  462. popping variants of functions exist as well.
  463. ??? We may optimize similar to defer_pop above, but it is
  464. probably not worthwhile.
  465. ??? It will be worthwhile to enable combine_stack_adjustments even for
  466. such machines. */
  467. else if (n_popped)
  468. anti_adjust_stack (GEN_INT (n_popped));
  469. }
  470. /* Determine if the function identified by NAME and FNDECL is one with
  471. special properties we wish to know about.
  472. For example, if the function might return more than one time (setjmp), then
  473. set RETURNS_TWICE to a nonzero value.
  474. Similarly set NORETURN if the function is in the longjmp family.
  475. Set MAY_BE_ALLOCA for any memory allocation function that might allocate
  476. space from the stack such as alloca. */
  477. static int
  478. special_function_p (const_tree fndecl, int flags)
  479. {
  480. tree name_decl = DECL_NAME (fndecl);
  481. /* For instrumentation clones we want to derive flags
  482. from the original name. */
  483. if (cgraph_node::get (fndecl)
  484. && cgraph_node::get (fndecl)->instrumentation_clone)
  485. name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
  486. if (fndecl && name_decl
  487. && IDENTIFIER_LENGTH (name_decl) <= 17
  488. /* Exclude functions not at the file scope, or not `extern',
  489. since they are not the magic functions we would otherwise
  490. think they are.
  491. FIXME: this should be handled with attributes, not with this
  492. hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
  493. because you can declare fork() inside a function if you
  494. wish. */
  495. && (DECL_CONTEXT (fndecl) == NULL_TREE
  496. || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
  497. && TREE_PUBLIC (fndecl))
  498. {
  499. const char *name = IDENTIFIER_POINTER (name_decl);
  500. const char *tname = name;
  501. /* We assume that alloca will always be called by name. It
  502. makes no sense to pass it as a pointer-to-function to
  503. anything that does not understand its behavior. */
  504. if (((IDENTIFIER_LENGTH (name_decl) == 6
  505. && name[0] == 'a'
  506. && ! strcmp (name, "alloca"))
  507. || (IDENTIFIER_LENGTH (name_decl) == 16
  508. && name[0] == '_'
  509. && ! strcmp (name, "__builtin_alloca"))))
  510. flags |= ECF_MAY_BE_ALLOCA;
  511. /* Disregard prefix _, __, __x or __builtin_. */
  512. if (name[0] == '_')
  513. {
  514. if (name[1] == '_'
  515. && name[2] == 'b'
  516. && !strncmp (name + 3, "uiltin_", 7))
  517. tname += 10;
  518. else if (name[1] == '_' && name[2] == 'x')
  519. tname += 3;
  520. else if (name[1] == '_')
  521. tname += 2;
  522. else
  523. tname += 1;
  524. }
  525. if (tname[0] == 's')
  526. {
  527. if ((tname[1] == 'e'
  528. && (! strcmp (tname, "setjmp")
  529. || ! strcmp (tname, "setjmp_syscall")))
  530. || (tname[1] == 'i'
  531. && ! strcmp (tname, "sigsetjmp"))
  532. || (tname[1] == 'a'
  533. && ! strcmp (tname, "savectx")))
  534. flags |= ECF_RETURNS_TWICE | ECF_LEAF;
  535. if (tname[1] == 'i'
  536. && ! strcmp (tname, "siglongjmp"))
  537. flags |= ECF_NORETURN;
  538. }
  539. else if ((tname[0] == 'q' && tname[1] == 's'
  540. && ! strcmp (tname, "qsetjmp"))
  541. || (tname[0] == 'v' && tname[1] == 'f'
  542. && ! strcmp (tname, "vfork"))
  543. || (tname[0] == 'g' && tname[1] == 'e'
  544. && !strcmp (tname, "getcontext")))
  545. flags |= ECF_RETURNS_TWICE | ECF_LEAF;
  546. else if (tname[0] == 'l' && tname[1] == 'o'
  547. && ! strcmp (tname, "longjmp"))
  548. flags |= ECF_NORETURN;
  549. }
  550. return flags;
  551. }
  552. /* Similar to special_function_p; return a set of ERF_ flags for the
  553. function FNDECL. */
  554. static int
  555. decl_return_flags (tree fndecl)
  556. {
  557. tree attr;
  558. tree type = TREE_TYPE (fndecl);
  559. if (!type)
  560. return 0;
  561. attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
  562. if (!attr)
  563. return 0;
  564. attr = TREE_VALUE (TREE_VALUE (attr));
  565. if (!attr || TREE_STRING_LENGTH (attr) < 1)
  566. return 0;
  567. switch (TREE_STRING_POINTER (attr)[0])
  568. {
  569. case '1':
  570. case '2':
  571. case '3':
  572. case '4':
  573. return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
  574. case 'm':
  575. return ERF_NOALIAS;
  576. case '.':
  577. default:
  578. return 0;
  579. }
  580. }
  581. /* Return nonzero when FNDECL represents a call to setjmp. */
  582. int
  583. setjmp_call_p (const_tree fndecl)
  584. {
  585. if (DECL_IS_RETURNS_TWICE (fndecl))
  586. return ECF_RETURNS_TWICE;
  587. return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
  588. }
  589. /* Return true if STMT is an alloca call. */
  590. bool
  591. gimple_alloca_call_p (const_gimple stmt)
  592. {
  593. tree fndecl;
  594. if (!is_gimple_call (stmt))
  595. return false;
  596. fndecl = gimple_call_fndecl (stmt);
  597. if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
  598. return true;
  599. return false;
  600. }
  601. /* Return true when exp contains alloca call. */
  602. bool
  603. alloca_call_p (const_tree exp)
  604. {
  605. tree fndecl;
  606. if (TREE_CODE (exp) == CALL_EXPR
  607. && (fndecl = get_callee_fndecl (exp))
  608. && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
  609. return true;
  610. return false;
  611. }
  612. /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
  613. function. Return FALSE otherwise. */
  614. static bool
  615. is_tm_builtin (const_tree fndecl)
  616. {
  617. if (fndecl == NULL)
  618. return false;
  619. if (decl_is_tm_clone (fndecl))
  620. return true;
  621. if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
  622. {
  623. switch (DECL_FUNCTION_CODE (fndecl))
  624. {
  625. case BUILT_IN_TM_COMMIT:
  626. case BUILT_IN_TM_COMMIT_EH:
  627. case BUILT_IN_TM_ABORT:
  628. case BUILT_IN_TM_IRREVOCABLE:
  629. case BUILT_IN_TM_GETTMCLONE_IRR:
  630. case BUILT_IN_TM_MEMCPY:
  631. case BUILT_IN_TM_MEMMOVE:
  632. case BUILT_IN_TM_MEMSET:
  633. CASE_BUILT_IN_TM_STORE (1):
  634. CASE_BUILT_IN_TM_STORE (2):
  635. CASE_BUILT_IN_TM_STORE (4):
  636. CASE_BUILT_IN_TM_STORE (8):
  637. CASE_BUILT_IN_TM_STORE (FLOAT):
  638. CASE_BUILT_IN_TM_STORE (DOUBLE):
  639. CASE_BUILT_IN_TM_STORE (LDOUBLE):
  640. CASE_BUILT_IN_TM_STORE (M64):
  641. CASE_BUILT_IN_TM_STORE (M128):
  642. CASE_BUILT_IN_TM_STORE (M256):
  643. CASE_BUILT_IN_TM_LOAD (1):
  644. CASE_BUILT_IN_TM_LOAD (2):
  645. CASE_BUILT_IN_TM_LOAD (4):
  646. CASE_BUILT_IN_TM_LOAD (8):
  647. CASE_BUILT_IN_TM_LOAD (FLOAT):
  648. CASE_BUILT_IN_TM_LOAD (DOUBLE):
  649. CASE_BUILT_IN_TM_LOAD (LDOUBLE):
  650. CASE_BUILT_IN_TM_LOAD (M64):
  651. CASE_BUILT_IN_TM_LOAD (M128):
  652. CASE_BUILT_IN_TM_LOAD (M256):
  653. case BUILT_IN_TM_LOG:
  654. case BUILT_IN_TM_LOG_1:
  655. case BUILT_IN_TM_LOG_2:
  656. case BUILT_IN_TM_LOG_4:
  657. case BUILT_IN_TM_LOG_8:
  658. case BUILT_IN_TM_LOG_FLOAT:
  659. case BUILT_IN_TM_LOG_DOUBLE:
  660. case BUILT_IN_TM_LOG_LDOUBLE:
  661. case BUILT_IN_TM_LOG_M64:
  662. case BUILT_IN_TM_LOG_M128:
  663. case BUILT_IN_TM_LOG_M256:
  664. return true;
  665. default:
  666. break;
  667. }
  668. }
  669. return false;
  670. }
  671. /* Detect flags (function attributes) from the function decl or type node. */
  672. int
  673. flags_from_decl_or_type (const_tree exp)
  674. {
  675. int flags = 0;
  676. if (DECL_P (exp))
  677. {
  678. /* The function exp may have the `malloc' attribute. */
  679. if (DECL_IS_MALLOC (exp))
  680. flags |= ECF_MALLOC;
  681. /* The function exp may have the `returns_twice' attribute. */
  682. if (DECL_IS_RETURNS_TWICE (exp))
  683. flags |= ECF_RETURNS_TWICE;
  684. /* Process the pure and const attributes. */
  685. if (TREE_READONLY (exp))
  686. flags |= ECF_CONST;
  687. if (DECL_PURE_P (exp))
  688. flags |= ECF_PURE;
  689. if (DECL_LOOPING_CONST_OR_PURE_P (exp))
  690. flags |= ECF_LOOPING_CONST_OR_PURE;
  691. if (DECL_IS_NOVOPS (exp))
  692. flags |= ECF_NOVOPS;
  693. if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
  694. flags |= ECF_LEAF;
  695. if (TREE_NOTHROW (exp))
  696. flags |= ECF_NOTHROW;
  697. if (flag_tm)
  698. {
  699. if (is_tm_builtin (exp))
  700. flags |= ECF_TM_BUILTIN;
  701. else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
  702. || lookup_attribute ("transaction_pure",
  703. TYPE_ATTRIBUTES (TREE_TYPE (exp))))
  704. flags |= ECF_TM_PURE;
  705. }
  706. flags = special_function_p (exp, flags);
  707. }
  708. else if (TYPE_P (exp))
  709. {
  710. if (TYPE_READONLY (exp))
  711. flags |= ECF_CONST;
  712. if (flag_tm
  713. && ((flags & ECF_CONST) != 0
  714. || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
  715. flags |= ECF_TM_PURE;
  716. }
  717. else
  718. gcc_unreachable ();
  719. if (TREE_THIS_VOLATILE (exp))
  720. {
  721. flags |= ECF_NORETURN;
  722. if (flags & (ECF_CONST|ECF_PURE))
  723. flags |= ECF_LOOPING_CONST_OR_PURE;
  724. }
  725. return flags;
  726. }
  727. /* Detect flags from a CALL_EXPR. */
  728. int
  729. call_expr_flags (const_tree t)
  730. {
  731. int flags;
  732. tree decl = get_callee_fndecl (t);
  733. if (decl)
  734. flags = flags_from_decl_or_type (decl);
  735. else
  736. {
  737. t = TREE_TYPE (CALL_EXPR_FN (t));
  738. if (t && TREE_CODE (t) == POINTER_TYPE)
  739. flags = flags_from_decl_or_type (TREE_TYPE (t));
  740. else
  741. flags = 0;
  742. }
  743. return flags;
  744. }
  745. /* Precompute all register parameters as described by ARGS, storing values
  746. into fields within the ARGS array.
  747. NUM_ACTUALS indicates the total number elements in the ARGS array.
  748. Set REG_PARM_SEEN if we encounter a register parameter. */
  749. static void
  750. precompute_register_parameters (int num_actuals, struct arg_data *args,
  751. int *reg_parm_seen)
  752. {
  753. int i;
  754. *reg_parm_seen = 0;
  755. for (i = 0; i < num_actuals; i++)
  756. if (args[i].reg != 0 && ! args[i].pass_on_stack)
  757. {
  758. *reg_parm_seen = 1;
  759. if (args[i].value == 0)
  760. {
  761. push_temp_slots ();
  762. args[i].value = expand_normal (args[i].tree_value);
  763. preserve_temp_slots (args[i].value);
  764. pop_temp_slots ();
  765. }
  766. /* If we are to promote the function arg to a wider mode,
  767. do it now. */
  768. if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
  769. args[i].value
  770. = convert_modes (args[i].mode,
  771. TYPE_MODE (TREE_TYPE (args[i].tree_value)),
  772. args[i].value, args[i].unsignedp);
  773. /* If the value is a non-legitimate constant, force it into a
  774. pseudo now. TLS symbols sometimes need a call to resolve. */
  775. if (CONSTANT_P (args[i].value)
  776. && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
  777. args[i].value = force_reg (args[i].mode, args[i].value);
  778. /* If we're going to have to load the value by parts, pull the
  779. parts into pseudos. The part extraction process can involve
  780. non-trivial computation. */
  781. if (GET_CODE (args[i].reg) == PARALLEL)
  782. {
  783. tree type = TREE_TYPE (args[i].tree_value);
  784. args[i].parallel_value
  785. = emit_group_load_into_temps (args[i].reg, args[i].value,
  786. type, int_size_in_bytes (type));
  787. }
  788. /* If the value is expensive, and we are inside an appropriately
  789. short loop, put the value into a pseudo and then put the pseudo
  790. into the hard reg.
  791. For small register classes, also do this if this call uses
  792. register parameters. This is to avoid reload conflicts while
  793. loading the parameters registers. */
  794. else if ((! (REG_P (args[i].value)
  795. || (GET_CODE (args[i].value) == SUBREG
  796. && REG_P (SUBREG_REG (args[i].value)))))
  797. && args[i].mode != BLKmode
  798. && set_src_cost (args[i].value, optimize_insn_for_speed_p ())
  799. > COSTS_N_INSNS (1)
  800. && ((*reg_parm_seen
  801. && targetm.small_register_classes_for_mode_p (args[i].mode))
  802. || optimize))
  803. args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
  804. }
  805. }
  806. #ifdef REG_PARM_STACK_SPACE
  807. /* The argument list is the property of the called routine and it
  808. may clobber it. If the fixed area has been used for previous
  809. parameters, we must save and restore it. */
  810. static rtx
  811. save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
  812. {
  813. int low;
  814. int high;
  815. /* Compute the boundary of the area that needs to be saved, if any. */
  816. high = reg_parm_stack_space;
  817. #ifdef ARGS_GROW_DOWNWARD
  818. high += 1;
  819. #endif
  820. if (high > highest_outgoing_arg_in_use)
  821. high = highest_outgoing_arg_in_use;
  822. for (low = 0; low < high; low++)
  823. if (stack_usage_map[low] != 0)
  824. {
  825. int num_to_save;
  826. machine_mode save_mode;
  827. int delta;
  828. rtx addr;
  829. rtx stack_area;
  830. rtx save_area;
  831. while (stack_usage_map[--high] == 0)
  832. ;
  833. *low_to_save = low;
  834. *high_to_save = high;
  835. num_to_save = high - low + 1;
  836. save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
  837. /* If we don't have the required alignment, must do this
  838. in BLKmode. */
  839. if ((low & (MIN (GET_MODE_SIZE (save_mode),
  840. BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
  841. save_mode = BLKmode;
  842. #ifdef ARGS_GROW_DOWNWARD
  843. delta = -high;
  844. #else
  845. delta = low;
  846. #endif
  847. addr = plus_constant (Pmode, argblock, delta);
  848. stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
  849. set_mem_align (stack_area, PARM_BOUNDARY);
  850. if (save_mode == BLKmode)
  851. {
  852. save_area = assign_stack_temp (BLKmode, num_to_save);
  853. emit_block_move (validize_mem (save_area), stack_area,
  854. GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
  855. }
  856. else
  857. {
  858. save_area = gen_reg_rtx (save_mode);
  859. emit_move_insn (save_area, stack_area);
  860. }
  861. return save_area;
  862. }
  863. return NULL_RTX;
  864. }
  865. static void
  866. restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
  867. {
  868. machine_mode save_mode = GET_MODE (save_area);
  869. int delta;
  870. rtx addr, stack_area;
  871. #ifdef ARGS_GROW_DOWNWARD
  872. delta = -high_to_save;
  873. #else
  874. delta = low_to_save;
  875. #endif
  876. addr = plus_constant (Pmode, argblock, delta);
  877. stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
  878. set_mem_align (stack_area, PARM_BOUNDARY);
  879. if (save_mode != BLKmode)
  880. emit_move_insn (stack_area, save_area);
  881. else
  882. emit_block_move (stack_area, validize_mem (save_area),
  883. GEN_INT (high_to_save - low_to_save + 1),
  884. BLOCK_OP_CALL_PARM);
  885. }
  886. #endif /* REG_PARM_STACK_SPACE */
  887. /* If any elements in ARGS refer to parameters that are to be passed in
  888. registers, but not in memory, and whose alignment does not permit a
  889. direct copy into registers. Copy the values into a group of pseudos
  890. which we will later copy into the appropriate hard registers.
  891. Pseudos for each unaligned argument will be stored into the array
  892. args[argnum].aligned_regs. The caller is responsible for deallocating
  893. the aligned_regs array if it is nonzero. */
  894. static void
  895. store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
  896. {
  897. int i, j;
  898. for (i = 0; i < num_actuals; i++)
  899. if (args[i].reg != 0 && ! args[i].pass_on_stack
  900. && GET_CODE (args[i].reg) != PARALLEL
  901. && args[i].mode == BLKmode
  902. && MEM_P (args[i].value)
  903. && (MEM_ALIGN (args[i].value)
  904. < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
  905. {
  906. int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
  907. int endian_correction = 0;
  908. if (args[i].partial)
  909. {
  910. gcc_assert (args[i].partial % UNITS_PER_WORD == 0);
  911. args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD;
  912. }
  913. else
  914. {
  915. args[i].n_aligned_regs
  916. = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  917. }
  918. args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs);
  919. /* Structures smaller than a word are normally aligned to the
  920. least significant byte. On a BYTES_BIG_ENDIAN machine,
  921. this means we must skip the empty high order bytes when
  922. calculating the bit offset. */
  923. if (bytes < UNITS_PER_WORD
  924. #ifdef BLOCK_REG_PADDING
  925. && (BLOCK_REG_PADDING (args[i].mode,
  926. TREE_TYPE (args[i].tree_value), 1)
  927. == downward)
  928. #else
  929. && BYTES_BIG_ENDIAN
  930. #endif
  931. )
  932. endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
  933. for (j = 0; j < args[i].n_aligned_regs; j++)
  934. {
  935. rtx reg = gen_reg_rtx (word_mode);
  936. rtx word = operand_subword_force (args[i].value, j, BLKmode);
  937. int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
  938. args[i].aligned_regs[j] = reg;
  939. word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
  940. word_mode, word_mode);
  941. /* There is no need to restrict this code to loading items
  942. in TYPE_ALIGN sized hunks. The bitfield instructions can
  943. load up entire word sized registers efficiently.
  944. ??? This may not be needed anymore.
  945. We use to emit a clobber here but that doesn't let later
  946. passes optimize the instructions we emit. By storing 0 into
  947. the register later passes know the first AND to zero out the
  948. bitfield being set in the register is unnecessary. The store
  949. of 0 will be deleted as will at least the first AND. */
  950. emit_move_insn (reg, const0_rtx);
  951. bytes -= bitsize / BITS_PER_UNIT;
  952. store_bit_field (reg, bitsize, endian_correction, 0, 0,
  953. word_mode, word);
  954. }
  955. }
  956. }
  957. /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
  958. CALL_EXPR EXP.
  959. NUM_ACTUALS is the total number of parameters.
  960. N_NAMED_ARGS is the total number of named arguments.
  961. STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
  962. value, or null.
  963. FNDECL is the tree code for the target of this call (if known)
  964. ARGS_SO_FAR holds state needed by the target to know where to place
  965. the next argument.
  966. REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
  967. for arguments which are passed in registers.
  968. OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
  969. and may be modified by this routine.
  970. OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
  971. flags which may may be modified by this routine.
  972. MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
  973. that requires allocation of stack space.
  974. CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
  975. the thunked-to function. */
  976. static void
  977. initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
  978. struct arg_data *args,
  979. struct args_size *args_size,
  980. int n_named_args ATTRIBUTE_UNUSED,
  981. tree exp, tree struct_value_addr_value,
  982. tree fndecl, tree fntype,
  983. cumulative_args_t args_so_far,
  984. int reg_parm_stack_space,
  985. rtx *old_stack_level, int *old_pending_adj,
  986. int *must_preallocate, int *ecf_flags,
  987. bool *may_tailcall, bool call_from_thunk_p)
  988. {
  989. CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
  990. location_t loc = EXPR_LOCATION (exp);
  991. /* Count arg position in order args appear. */
  992. int argpos;
  993. int i;
  994. args_size->constant = 0;
  995. args_size->var = 0;
  996. bitmap_obstack_initialize (NULL);
  997. /* In this loop, we consider args in the order they are written.
  998. We fill up ARGS from the back. */
  999. i = num_actuals - 1;
  1000. {
  1001. int j = i, ptr_arg = -1;
  1002. call_expr_arg_iterator iter;
  1003. tree arg;
  1004. bitmap slots = NULL;
  1005. if (struct_value_addr_value)
  1006. {
  1007. args[j].tree_value = struct_value_addr_value;
  1008. j--;
  1009. /* If we pass structure address then we need to
  1010. create bounds for it. Since created bounds is
  1011. a call statement, we expand it right here to avoid
  1012. fixing all other places where it may be expanded. */
  1013. if (CALL_WITH_BOUNDS_P (exp))
  1014. {
  1015. args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ());
  1016. args[j].tree_value
  1017. = chkp_make_bounds_for_struct_addr (struct_value_addr_value);
  1018. expand_expr_real (args[j].tree_value, args[j].value, VOIDmode,
  1019. EXPAND_NORMAL, 0, false);
  1020. args[j].pointer_arg = j + 1;
  1021. j--;
  1022. }
  1023. }
  1024. FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
  1025. {
  1026. tree argtype = TREE_TYPE (arg);
  1027. /* Remember last param with pointer and associate it
  1028. with following pointer bounds. */
  1029. if (CALL_WITH_BOUNDS_P (exp)
  1030. && chkp_type_has_pointer (argtype))
  1031. {
  1032. if (slots)
  1033. BITMAP_FREE (slots);
  1034. ptr_arg = j;
  1035. if (!BOUNDED_TYPE_P (argtype))
  1036. {
  1037. slots = BITMAP_ALLOC (NULL);
  1038. chkp_find_bound_slots (argtype, slots);
  1039. }
  1040. }
  1041. else if (POINTER_BOUNDS_TYPE_P (argtype))
  1042. {
  1043. /* We expect bounds in instrumented calls only.
  1044. Otherwise it is a sign we lost flag due to some optimization
  1045. and may emit call args incorrectly. */
  1046. gcc_assert (CALL_WITH_BOUNDS_P (exp));
  1047. /* For structures look for the next available pointer. */
  1048. if (ptr_arg != -1 && slots)
  1049. {
  1050. unsigned bnd_no = bitmap_first_set_bit (slots);
  1051. args[j].pointer_offset =
  1052. bnd_no * POINTER_SIZE / BITS_PER_UNIT;
  1053. bitmap_clear_bit (slots, bnd_no);
  1054. /* Check we have no more pointers in the structure. */
  1055. if (bitmap_empty_p (slots))
  1056. BITMAP_FREE (slots);
  1057. }
  1058. args[j].pointer_arg = ptr_arg;
  1059. /* Check we covered all pointers in the previous
  1060. non bounds arg. */
  1061. if (!slots)
  1062. ptr_arg = -1;
  1063. }
  1064. else
  1065. ptr_arg = -1;
  1066. if (targetm.calls.split_complex_arg
  1067. && argtype
  1068. && TREE_CODE (argtype) == COMPLEX_TYPE
  1069. && targetm.calls.split_complex_arg (argtype))
  1070. {
  1071. tree subtype = TREE_TYPE (argtype);
  1072. args[j].tree_value = build1 (REALPART_EXPR, subtype, arg);
  1073. j--;
  1074. args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg);
  1075. }
  1076. else
  1077. args[j].tree_value = arg;
  1078. j--;
  1079. }
  1080. if (slots)
  1081. BITMAP_FREE (slots);
  1082. }
  1083. bitmap_obstack_release (NULL);
  1084. /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
  1085. for (argpos = 0; argpos < num_actuals; i--, argpos++)
  1086. {
  1087. tree type = TREE_TYPE (args[i].tree_value);
  1088. int unsignedp;
  1089. machine_mode mode;
  1090. /* Replace erroneous argument with constant zero. */
  1091. if (type == error_mark_node || !COMPLETE_TYPE_P (type))
  1092. args[i].tree_value = integer_zero_node, type = integer_type_node;
  1093. /* If TYPE is a transparent union or record, pass things the way
  1094. we would pass the first field of the union or record. We have
  1095. already verified that the modes are the same. */
  1096. if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE)
  1097. && TYPE_TRANSPARENT_AGGR (type))
  1098. type = TREE_TYPE (first_field (type));
  1099. /* Decide where to pass this arg.
  1100. args[i].reg is nonzero if all or part is passed in registers.
  1101. args[i].partial is nonzero if part but not all is passed in registers,
  1102. and the exact value says how many bytes are passed in registers.
  1103. args[i].pass_on_stack is nonzero if the argument must at least be
  1104. computed on the stack. It may then be loaded back into registers
  1105. if args[i].reg is nonzero.
  1106. These decisions are driven by the FUNCTION_... macros and must agree
  1107. with those made by function.c. */
  1108. /* See if this argument should be passed by invisible reference. */
  1109. if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type),
  1110. type, argpos < n_named_args))
  1111. {
  1112. bool callee_copies;
  1113. tree base = NULL_TREE;
  1114. callee_copies
  1115. = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type),
  1116. type, argpos < n_named_args);
  1117. /* If we're compiling a thunk, pass through invisible references
  1118. instead of making a copy. */
  1119. if (call_from_thunk_p
  1120. || (callee_copies
  1121. && !TREE_ADDRESSABLE (type)
  1122. && (base = get_base_address (args[i].tree_value))
  1123. && TREE_CODE (base) != SSA_NAME
  1124. && (!DECL_P (base) || MEM_P (DECL_RTL (base)))))
  1125. {
  1126. /* We may have turned the parameter value into an SSA name.
  1127. Go back to the original parameter so we can take the
  1128. address. */
  1129. if (TREE_CODE (args[i].tree_value) == SSA_NAME)
  1130. {
  1131. gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value));
  1132. args[i].tree_value = SSA_NAME_VAR (args[i].tree_value);
  1133. gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL);
  1134. }
  1135. /* Argument setup code may have copied the value to register. We
  1136. revert that optimization now because the tail call code must
  1137. use the original location. */
  1138. if (TREE_CODE (args[i].tree_value) == PARM_DECL
  1139. && !MEM_P (DECL_RTL (args[i].tree_value))
  1140. && DECL_INCOMING_RTL (args[i].tree_value)
  1141. && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
  1142. set_decl_rtl (args[i].tree_value,
  1143. DECL_INCOMING_RTL (args[i].tree_value));
  1144. mark_addressable (args[i].tree_value);
  1145. /* We can't use sibcalls if a callee-copied argument is
  1146. stored in the current function's frame. */
  1147. if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
  1148. *may_tailcall = false;
  1149. args[i].tree_value = build_fold_addr_expr_loc (loc,
  1150. args[i].tree_value);
  1151. type = TREE_TYPE (args[i].tree_value);
  1152. if (*ecf_flags & ECF_CONST)
  1153. *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
  1154. }
  1155. else
  1156. {
  1157. /* We make a copy of the object and pass the address to the
  1158. function being called. */
  1159. rtx copy;
  1160. if (!COMPLETE_TYPE_P (type)
  1161. || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
  1162. || (flag_stack_check == GENERIC_STACK_CHECK
  1163. && compare_tree_int (TYPE_SIZE_UNIT (type),
  1164. STACK_CHECK_MAX_VAR_SIZE) > 0))
  1165. {
  1166. /* This is a variable-sized object. Make space on the stack
  1167. for it. */
  1168. rtx size_rtx = expr_size (args[i].tree_value);
  1169. if (*old_stack_level == 0)
  1170. {
  1171. emit_stack_save (SAVE_BLOCK, old_stack_level);
  1172. *old_pending_adj = pending_stack_adjust;
  1173. pending_stack_adjust = 0;
  1174. }
  1175. /* We can pass TRUE as the 4th argument because we just
  1176. saved the stack pointer and will restore it right after
  1177. the call. */
  1178. copy = allocate_dynamic_stack_space (size_rtx,
  1179. TYPE_ALIGN (type),
  1180. TYPE_ALIGN (type),
  1181. true);
  1182. copy = gen_rtx_MEM (BLKmode, copy);
  1183. set_mem_attributes (copy, type, 1);
  1184. }
  1185. else
  1186. copy = assign_temp (type, 1, 0);
  1187. store_expr (args[i].tree_value, copy, 0, false);
  1188. /* Just change the const function to pure and then let
  1189. the next test clear the pure based on
  1190. callee_copies. */
  1191. if (*ecf_flags & ECF_CONST)
  1192. {
  1193. *ecf_flags &= ~ECF_CONST;
  1194. *ecf_flags |= ECF_PURE;
  1195. }
  1196. if (!callee_copies && *ecf_flags & ECF_PURE)
  1197. *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
  1198. args[i].tree_value
  1199. = build_fold_addr_expr_loc (loc, make_tree (type, copy));
  1200. type = TREE_TYPE (args[i].tree_value);
  1201. *may_tailcall = false;
  1202. }
  1203. }
  1204. unsignedp = TYPE_UNSIGNED (type);
  1205. mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
  1206. fndecl ? TREE_TYPE (fndecl) : fntype, 0);
  1207. args[i].unsignedp = unsignedp;
  1208. args[i].mode = mode;
  1209. args[i].reg = targetm.calls.function_arg (args_so_far, mode, type,
  1210. argpos < n_named_args);
  1211. if (args[i].reg && CONST_INT_P (args[i].reg))
  1212. {
  1213. args[i].special_slot = args[i].reg;
  1214. args[i].reg = NULL;
  1215. }
  1216. /* If this is a sibling call and the machine has register windows, the
  1217. register window has to be unwinded before calling the routine, so
  1218. arguments have to go into the incoming registers. */
  1219. if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
  1220. args[i].tail_call_reg
  1221. = targetm.calls.function_incoming_arg (args_so_far, mode, type,
  1222. argpos < n_named_args);
  1223. else
  1224. args[i].tail_call_reg = args[i].reg;
  1225. if (args[i].reg)
  1226. args[i].partial
  1227. = targetm.calls.arg_partial_bytes (args_so_far, mode, type,
  1228. argpos < n_named_args);
  1229. args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
  1230. /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
  1231. it means that we are to pass this arg in the register(s) designated
  1232. by the PARALLEL, but also to pass it in the stack. */
  1233. if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
  1234. && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
  1235. args[i].pass_on_stack = 1;
  1236. /* If this is an addressable type, we must preallocate the stack
  1237. since we must evaluate the object into its final location.
  1238. If this is to be passed in both registers and the stack, it is simpler
  1239. to preallocate. */
  1240. if (TREE_ADDRESSABLE (type)
  1241. || (args[i].pass_on_stack && args[i].reg != 0))
  1242. *must_preallocate = 1;
  1243. /* No stack allocation and padding for bounds. */
  1244. if (POINTER_BOUNDS_P (args[i].tree_value))
  1245. ;
  1246. /* Compute the stack-size of this argument. */
  1247. else if (args[i].reg == 0 || args[i].partial != 0
  1248. || reg_parm_stack_space > 0
  1249. || args[i].pass_on_stack)
  1250. locate_and_pad_parm (mode, type,
  1251. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  1252. 1,
  1253. #else
  1254. args[i].reg != 0,
  1255. #endif
  1256. reg_parm_stack_space,
  1257. args[i].pass_on_stack ? 0 : args[i].partial,
  1258. fndecl, args_size, &args[i].locate);
  1259. #ifdef BLOCK_REG_PADDING
  1260. else
  1261. /* The argument is passed entirely in registers. See at which
  1262. end it should be padded. */
  1263. args[i].locate.where_pad =
  1264. BLOCK_REG_PADDING (mode, type,
  1265. int_size_in_bytes (type) <= UNITS_PER_WORD);
  1266. #endif
  1267. /* Update ARGS_SIZE, the total stack space for args so far. */
  1268. args_size->constant += args[i].locate.size.constant;
  1269. if (args[i].locate.size.var)
  1270. ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
  1271. /* Increment ARGS_SO_FAR, which has info about which arg-registers
  1272. have been used, etc. */
  1273. targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type),
  1274. type, argpos < n_named_args);
  1275. }
  1276. }
  1277. /* Update ARGS_SIZE to contain the total size for the argument block.
  1278. Return the original constant component of the argument block's size.
  1279. REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
  1280. for arguments passed in registers. */
  1281. static int
  1282. compute_argument_block_size (int reg_parm_stack_space,
  1283. struct args_size *args_size,
  1284. tree fndecl ATTRIBUTE_UNUSED,
  1285. tree fntype ATTRIBUTE_UNUSED,
  1286. int preferred_stack_boundary ATTRIBUTE_UNUSED)
  1287. {
  1288. int unadjusted_args_size = args_size->constant;
  1289. /* For accumulate outgoing args mode we don't need to align, since the frame
  1290. will be already aligned. Align to STACK_BOUNDARY in order to prevent
  1291. backends from generating misaligned frame sizes. */
  1292. if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
  1293. preferred_stack_boundary = STACK_BOUNDARY;
  1294. /* Compute the actual size of the argument block required. The variable
  1295. and constant sizes must be combined, the size may have to be rounded,
  1296. and there may be a minimum required size. */
  1297. if (args_size->var)
  1298. {
  1299. args_size->var = ARGS_SIZE_TREE (*args_size);
  1300. args_size->constant = 0;
  1301. preferred_stack_boundary /= BITS_PER_UNIT;
  1302. if (preferred_stack_boundary > 1)
  1303. {
  1304. /* We don't handle this case yet. To handle it correctly we have
  1305. to add the delta, round and subtract the delta.
  1306. Currently no machine description requires this support. */
  1307. gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
  1308. args_size->var = round_up (args_size->var, preferred_stack_boundary);
  1309. }
  1310. if (reg_parm_stack_space > 0)
  1311. {
  1312. args_size->var
  1313. = size_binop (MAX_EXPR, args_size->var,
  1314. ssize_int (reg_parm_stack_space));
  1315. /* The area corresponding to register parameters is not to count in
  1316. the size of the block we need. So make the adjustment. */
  1317. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
  1318. args_size->var
  1319. = size_binop (MINUS_EXPR, args_size->var,
  1320. ssize_int (reg_parm_stack_space));
  1321. }
  1322. }
  1323. else
  1324. {
  1325. preferred_stack_boundary /= BITS_PER_UNIT;
  1326. if (preferred_stack_boundary < 1)
  1327. preferred_stack_boundary = 1;
  1328. args_size->constant = (((args_size->constant
  1329. + stack_pointer_delta
  1330. + preferred_stack_boundary - 1)
  1331. / preferred_stack_boundary
  1332. * preferred_stack_boundary)
  1333. - stack_pointer_delta);
  1334. args_size->constant = MAX (args_size->constant,
  1335. reg_parm_stack_space);
  1336. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
  1337. args_size->constant -= reg_parm_stack_space;
  1338. }
  1339. return unadjusted_args_size;
  1340. }
  1341. /* Precompute parameters as needed for a function call.
  1342. FLAGS is mask of ECF_* constants.
  1343. NUM_ACTUALS is the number of arguments.
  1344. ARGS is an array containing information for each argument; this
  1345. routine fills in the INITIAL_VALUE and VALUE fields for each
  1346. precomputed argument. */
  1347. static void
  1348. precompute_arguments (int num_actuals, struct arg_data *args)
  1349. {
  1350. int i;
  1351. /* If this is a libcall, then precompute all arguments so that we do not
  1352. get extraneous instructions emitted as part of the libcall sequence. */
  1353. /* If we preallocated the stack space, and some arguments must be passed
  1354. on the stack, then we must precompute any parameter which contains a
  1355. function call which will store arguments on the stack.
  1356. Otherwise, evaluating the parameter may clobber previous parameters
  1357. which have already been stored into the stack. (we have code to avoid
  1358. such case by saving the outgoing stack arguments, but it results in
  1359. worse code) */
  1360. if (!ACCUMULATE_OUTGOING_ARGS)
  1361. return;
  1362. for (i = 0; i < num_actuals; i++)
  1363. {
  1364. tree type;
  1365. machine_mode mode;
  1366. if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
  1367. continue;
  1368. /* If this is an addressable type, we cannot pre-evaluate it. */
  1369. type = TREE_TYPE (args[i].tree_value);
  1370. gcc_assert (!TREE_ADDRESSABLE (type));
  1371. args[i].initial_value = args[i].value
  1372. = expand_normal (args[i].tree_value);
  1373. mode = TYPE_MODE (type);
  1374. if (mode != args[i].mode)
  1375. {
  1376. int unsignedp = args[i].unsignedp;
  1377. args[i].value
  1378. = convert_modes (args[i].mode, mode,
  1379. args[i].value, args[i].unsignedp);
  1380. /* CSE will replace this only if it contains args[i].value
  1381. pseudo, so convert it down to the declared mode using
  1382. a SUBREG. */
  1383. if (REG_P (args[i].value)
  1384. && GET_MODE_CLASS (args[i].mode) == MODE_INT
  1385. && promote_mode (type, mode, &unsignedp) != args[i].mode)
  1386. {
  1387. args[i].initial_value
  1388. = gen_lowpart_SUBREG (mode, args[i].value);
  1389. SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
  1390. SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
  1391. }
  1392. }
  1393. }
  1394. }
  1395. /* Given the current state of MUST_PREALLOCATE and information about
  1396. arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
  1397. compute and return the final value for MUST_PREALLOCATE. */
  1398. static int
  1399. finalize_must_preallocate (int must_preallocate, int num_actuals,
  1400. struct arg_data *args, struct args_size *args_size)
  1401. {
  1402. /* See if we have or want to preallocate stack space.
  1403. If we would have to push a partially-in-regs parm
  1404. before other stack parms, preallocate stack space instead.
  1405. If the size of some parm is not a multiple of the required stack
  1406. alignment, we must preallocate.
  1407. If the total size of arguments that would otherwise create a copy in
  1408. a temporary (such as a CALL) is more than half the total argument list
  1409. size, preallocation is faster.
  1410. Another reason to preallocate is if we have a machine (like the m88k)
  1411. where stack alignment is required to be maintained between every
  1412. pair of insns, not just when the call is made. However, we assume here
  1413. that such machines either do not have push insns (and hence preallocation
  1414. would occur anyway) or the problem is taken care of with
  1415. PUSH_ROUNDING. */
  1416. if (! must_preallocate)
  1417. {
  1418. int partial_seen = 0;
  1419. int copy_to_evaluate_size = 0;
  1420. int i;
  1421. for (i = 0; i < num_actuals && ! must_preallocate; i++)
  1422. {
  1423. if (args[i].partial > 0 && ! args[i].pass_on_stack)
  1424. partial_seen = 1;
  1425. else if (partial_seen && args[i].reg == 0)
  1426. must_preallocate = 1;
  1427. /* We preallocate in case there are bounds passed
  1428. in the bounds table to have precomputed address
  1429. for bounds association. */
  1430. else if (POINTER_BOUNDS_P (args[i].tree_value)
  1431. && !args[i].reg)
  1432. must_preallocate = 1;
  1433. if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
  1434. && (TREE_CODE (args[i].tree_value) == CALL_EXPR
  1435. || TREE_CODE (args[i].tree_value) == TARGET_EXPR
  1436. || TREE_CODE (args[i].tree_value) == COND_EXPR
  1437. || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
  1438. copy_to_evaluate_size
  1439. += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
  1440. }
  1441. if (copy_to_evaluate_size * 2 >= args_size->constant
  1442. && args_size->constant > 0)
  1443. must_preallocate = 1;
  1444. }
  1445. return must_preallocate;
  1446. }
  1447. /* If we preallocated stack space, compute the address of each argument
  1448. and store it into the ARGS array.
  1449. We need not ensure it is a valid memory address here; it will be
  1450. validized when it is used.
  1451. ARGBLOCK is an rtx for the address of the outgoing arguments. */
  1452. static void
  1453. compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
  1454. {
  1455. if (argblock)
  1456. {
  1457. rtx arg_reg = argblock;
  1458. int i, arg_offset = 0;
  1459. if (GET_CODE (argblock) == PLUS)
  1460. arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
  1461. for (i = 0; i < num_actuals; i++)
  1462. {
  1463. rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
  1464. rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
  1465. rtx addr;
  1466. unsigned int align, boundary;
  1467. unsigned int units_on_stack = 0;
  1468. machine_mode partial_mode = VOIDmode;
  1469. /* Skip this parm if it will not be passed on the stack. */
  1470. if (! args[i].pass_on_stack
  1471. && args[i].reg != 0
  1472. && args[i].partial == 0)
  1473. continue;
  1474. /* Pointer Bounds are never passed on the stack. */
  1475. if (POINTER_BOUNDS_P (args[i].tree_value))
  1476. continue;
  1477. if (CONST_INT_P (offset))
  1478. addr = plus_constant (Pmode, arg_reg, INTVAL (offset));
  1479. else
  1480. addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
  1481. addr = plus_constant (Pmode, addr, arg_offset);
  1482. if (args[i].partial != 0)
  1483. {
  1484. /* Only part of the parameter is being passed on the stack.
  1485. Generate a simple memory reference of the correct size. */
  1486. units_on_stack = args[i].locate.size.constant;
  1487. partial_mode = mode_for_size (units_on_stack * BITS_PER_UNIT,
  1488. MODE_INT, 1);
  1489. args[i].stack = gen_rtx_MEM (partial_mode, addr);
  1490. set_mem_size (args[i].stack, units_on_stack);
  1491. }
  1492. else
  1493. {
  1494. args[i].stack = gen_rtx_MEM (args[i].mode, addr);
  1495. set_mem_attributes (args[i].stack,
  1496. TREE_TYPE (args[i].tree_value), 1);
  1497. }
  1498. align = BITS_PER_UNIT;
  1499. boundary = args[i].locate.boundary;
  1500. if (args[i].locate.where_pad != downward)
  1501. align = boundary;
  1502. else if (CONST_INT_P (offset))
  1503. {
  1504. align = INTVAL (offset) * BITS_PER_UNIT | boundary;
  1505. align = align & -align;
  1506. }
  1507. set_mem_align (args[i].stack, align);
  1508. if (CONST_INT_P (slot_offset))
  1509. addr = plus_constant (Pmode, arg_reg, INTVAL (slot_offset));
  1510. else
  1511. addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
  1512. addr = plus_constant (Pmode, addr, arg_offset);
  1513. if (args[i].partial != 0)
  1514. {
  1515. /* Only part of the parameter is being passed on the stack.
  1516. Generate a simple memory reference of the correct size.
  1517. */
  1518. args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
  1519. set_mem_size (args[i].stack_slot, units_on_stack);
  1520. }
  1521. else
  1522. {
  1523. args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
  1524. set_mem_attributes (args[i].stack_slot,
  1525. TREE_TYPE (args[i].tree_value), 1);
  1526. }
  1527. set_mem_align (args[i].stack_slot, args[i].locate.boundary);
  1528. /* Function incoming arguments may overlap with sibling call
  1529. outgoing arguments and we cannot allow reordering of reads
  1530. from function arguments with stores to outgoing arguments
  1531. of sibling calls. */
  1532. set_mem_alias_set (args[i].stack, 0);
  1533. set_mem_alias_set (args[i].stack_slot, 0);
  1534. }
  1535. }
  1536. }
  1537. /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
  1538. in a call instruction.
  1539. FNDECL is the tree node for the target function. For an indirect call
  1540. FNDECL will be NULL_TREE.
  1541. ADDR is the operand 0 of CALL_EXPR for this call. */
  1542. static rtx
  1543. rtx_for_function_call (tree fndecl, tree addr)
  1544. {
  1545. rtx funexp;
  1546. /* Get the function to call, in the form of RTL. */
  1547. if (fndecl)
  1548. {
  1549. if (!TREE_USED (fndecl) && fndecl != current_function_decl)
  1550. TREE_USED (fndecl) = 1;
  1551. /* Get a SYMBOL_REF rtx for the function address. */
  1552. funexp = XEXP (DECL_RTL (fndecl), 0);
  1553. }
  1554. else
  1555. /* Generate an rtx (probably a pseudo-register) for the address. */
  1556. {
  1557. push_temp_slots ();
  1558. funexp = expand_normal (addr);
  1559. pop_temp_slots (); /* FUNEXP can't be BLKmode. */
  1560. }
  1561. return funexp;
  1562. }
  1563. /* Internal state for internal_arg_pointer_based_exp and its helpers. */
  1564. static struct
  1565. {
  1566. /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
  1567. or NULL_RTX if none has been scanned yet. */
  1568. rtx_insn *scan_start;
  1569. /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
  1570. based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
  1571. pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
  1572. with fixed offset, or PC if this is with variable or unknown offset. */
  1573. vec<rtx> cache;
  1574. } internal_arg_pointer_exp_state;
  1575. static rtx internal_arg_pointer_based_exp (const_rtx, bool);
  1576. /* Helper function for internal_arg_pointer_based_exp. Scan insns in
  1577. the tail call sequence, starting with first insn that hasn't been
  1578. scanned yet, and note for each pseudo on the LHS whether it is based
  1579. on crtl->args.internal_arg_pointer or not, and what offset from that
  1580. that pointer it has. */
  1581. static void
  1582. internal_arg_pointer_based_exp_scan (void)
  1583. {
  1584. rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
  1585. if (scan_start == NULL_RTX)
  1586. insn = get_insns ();
  1587. else
  1588. insn = NEXT_INSN (scan_start);
  1589. while (insn)
  1590. {
  1591. rtx set = single_set (insn);
  1592. if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
  1593. {
  1594. rtx val = NULL_RTX;
  1595. unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
  1596. /* Punt on pseudos set multiple times. */
  1597. if (idx < internal_arg_pointer_exp_state.cache.length ()
  1598. && (internal_arg_pointer_exp_state.cache[idx]
  1599. != NULL_RTX))
  1600. val = pc_rtx;
  1601. else
  1602. val = internal_arg_pointer_based_exp (SET_SRC (set), false);
  1603. if (val != NULL_RTX)
  1604. {
  1605. if (idx >= internal_arg_pointer_exp_state.cache.length ())
  1606. internal_arg_pointer_exp_state.cache
  1607. .safe_grow_cleared (idx + 1);
  1608. internal_arg_pointer_exp_state.cache[idx] = val;
  1609. }
  1610. }
  1611. if (NEXT_INSN (insn) == NULL_RTX)
  1612. scan_start = insn;
  1613. insn = NEXT_INSN (insn);
  1614. }
  1615. internal_arg_pointer_exp_state.scan_start = scan_start;
  1616. }
  1617. /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
  1618. NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
  1619. it with fixed offset, or PC if this is with variable or unknown offset.
  1620. TOPLEVEL is true if the function is invoked at the topmost level. */
  1621. static rtx
  1622. internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
  1623. {
  1624. if (CONSTANT_P (rtl))
  1625. return NULL_RTX;
  1626. if (rtl == crtl->args.internal_arg_pointer)
  1627. return const0_rtx;
  1628. if (REG_P (rtl) && HARD_REGISTER_P (rtl))
  1629. return NULL_RTX;
  1630. if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
  1631. {
  1632. rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
  1633. if (val == NULL_RTX || val == pc_rtx)
  1634. return val;
  1635. return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
  1636. }
  1637. /* When called at the topmost level, scan pseudo assignments in between the
  1638. last scanned instruction in the tail call sequence and the latest insn
  1639. in that sequence. */
  1640. if (toplevel)
  1641. internal_arg_pointer_based_exp_scan ();
  1642. if (REG_P (rtl))
  1643. {
  1644. unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
  1645. if (idx < internal_arg_pointer_exp_state.cache.length ())
  1646. return internal_arg_pointer_exp_state.cache[idx];
  1647. return NULL_RTX;
  1648. }
  1649. subrtx_iterator::array_type array;
  1650. FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
  1651. {
  1652. const_rtx x = *iter;
  1653. if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
  1654. return pc_rtx;
  1655. if (MEM_P (x))
  1656. iter.skip_subrtxes ();
  1657. }
  1658. return NULL_RTX;
  1659. }
  1660. /* Return true if and only if SIZE storage units (usually bytes)
  1661. starting from address ADDR overlap with already clobbered argument
  1662. area. This function is used to determine if we should give up a
  1663. sibcall. */
  1664. static bool
  1665. mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
  1666. {
  1667. HOST_WIDE_INT i;
  1668. rtx val;
  1669. if (bitmap_empty_p (stored_args_map))
  1670. return false;
  1671. val = internal_arg_pointer_based_exp (addr, true);
  1672. if (val == NULL_RTX)
  1673. return false;
  1674. else if (val == pc_rtx)
  1675. return true;
  1676. else
  1677. i = INTVAL (val);
  1678. #ifdef STACK_GROWS_DOWNWARD
  1679. i -= crtl->args.pretend_args_size;
  1680. #else
  1681. i += crtl->args.pretend_args_size;
  1682. #endif
  1683. #ifdef ARGS_GROW_DOWNWARD
  1684. i = -i - size;
  1685. #endif
  1686. if (size > 0)
  1687. {
  1688. unsigned HOST_WIDE_INT k;
  1689. for (k = 0; k < size; k++)
  1690. if (i + k < SBITMAP_SIZE (stored_args_map)
  1691. && bitmap_bit_p (stored_args_map, i + k))
  1692. return true;
  1693. }
  1694. return false;
  1695. }
  1696. /* Do the register loads required for any wholly-register parms or any
  1697. parms which are passed both on the stack and in a register. Their
  1698. expressions were already evaluated.
  1699. Mark all register-parms as living through the call, putting these USE
  1700. insns in the CALL_INSN_FUNCTION_USAGE field.
  1701. When IS_SIBCALL, perform the check_sibcall_argument_overlap
  1702. checking, setting *SIBCALL_FAILURE if appropriate. */
  1703. static void
  1704. load_register_parameters (struct arg_data *args, int num_actuals,
  1705. rtx *call_fusage, int flags, int is_sibcall,
  1706. int *sibcall_failure)
  1707. {
  1708. int i, j;
  1709. for (i = 0; i < num_actuals; i++)
  1710. {
  1711. rtx reg = ((flags & ECF_SIBCALL)
  1712. ? args[i].tail_call_reg : args[i].reg);
  1713. if (reg)
  1714. {
  1715. int partial = args[i].partial;
  1716. int nregs;
  1717. int size = 0;
  1718. rtx_insn *before_arg = get_last_insn ();
  1719. /* Set non-negative if we must move a word at a time, even if
  1720. just one word (e.g, partial == 4 && mode == DFmode). Set
  1721. to -1 if we just use a normal move insn. This value can be
  1722. zero if the argument is a zero size structure. */
  1723. nregs = -1;
  1724. if (GET_CODE (reg) == PARALLEL)
  1725. ;
  1726. else if (partial)
  1727. {
  1728. gcc_assert (partial % UNITS_PER_WORD == 0);
  1729. nregs = partial / UNITS_PER_WORD;
  1730. }
  1731. else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
  1732. {
  1733. size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
  1734. nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
  1735. }
  1736. else
  1737. size = GET_MODE_SIZE (args[i].mode);
  1738. /* Handle calls that pass values in multiple non-contiguous
  1739. locations. The Irix 6 ABI has examples of this. */
  1740. if (GET_CODE (reg) == PARALLEL)
  1741. emit_group_move (reg, args[i].parallel_value);
  1742. /* If simple case, just do move. If normal partial, store_one_arg
  1743. has already loaded the register for us. In all other cases,
  1744. load the register(s) from memory. */
  1745. else if (nregs == -1)
  1746. {
  1747. emit_move_insn (reg, args[i].value);
  1748. #ifdef BLOCK_REG_PADDING
  1749. /* Handle case where we have a value that needs shifting
  1750. up to the msb. eg. a QImode value and we're padding
  1751. upward on a BYTES_BIG_ENDIAN machine. */
  1752. if (size < UNITS_PER_WORD
  1753. && (args[i].locate.where_pad
  1754. == (BYTES_BIG_ENDIAN ? upward : downward)))
  1755. {
  1756. rtx x;
  1757. int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
  1758. /* Assigning REG here rather than a temp makes CALL_FUSAGE
  1759. report the whole reg as used. Strictly speaking, the
  1760. call only uses SIZE bytes at the msb end, but it doesn't
  1761. seem worth generating rtl to say that. */
  1762. reg = gen_rtx_REG (word_mode, REGNO (reg));
  1763. x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
  1764. if (x != reg)
  1765. emit_move_insn (reg, x);
  1766. }
  1767. #endif
  1768. }
  1769. /* If we have pre-computed the values to put in the registers in
  1770. the case of non-aligned structures, copy them in now. */
  1771. else if (args[i].n_aligned_regs != 0)
  1772. for (j = 0; j < args[i].n_aligned_regs; j++)
  1773. emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
  1774. args[i].aligned_regs[j]);
  1775. else if (partial == 0 || args[i].pass_on_stack)
  1776. {
  1777. rtx mem = validize_mem (copy_rtx (args[i].value));
  1778. /* Check for overlap with already clobbered argument area,
  1779. providing that this has non-zero size. */
  1780. if (is_sibcall
  1781. && (size == 0
  1782. || mem_overlaps_already_clobbered_arg_p
  1783. (XEXP (args[i].value, 0), size)))
  1784. *sibcall_failure = 1;
  1785. if (size % UNITS_PER_WORD == 0
  1786. || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
  1787. move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
  1788. else
  1789. {
  1790. if (nregs > 1)
  1791. move_block_to_reg (REGNO (reg), mem, nregs - 1,
  1792. args[i].mode);
  1793. rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
  1794. unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
  1795. unsigned int bitsize = size * BITS_PER_UNIT - bitoff;
  1796. rtx x = extract_bit_field (mem, bitsize, bitoff, 1,
  1797. dest, word_mode, word_mode);
  1798. if (BYTES_BIG_ENDIAN)
  1799. x = expand_shift (LSHIFT_EXPR, word_mode, x,
  1800. BITS_PER_WORD - bitsize, dest, 1);
  1801. if (x != dest)
  1802. emit_move_insn (dest, x);
  1803. }
  1804. /* Handle a BLKmode that needs shifting. */
  1805. if (nregs == 1 && size < UNITS_PER_WORD
  1806. #ifdef BLOCK_REG_PADDING
  1807. && args[i].locate.where_pad == downward
  1808. #else
  1809. && BYTES_BIG_ENDIAN
  1810. #endif
  1811. )
  1812. {
  1813. rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
  1814. int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
  1815. enum tree_code dir = (BYTES_BIG_ENDIAN
  1816. ? RSHIFT_EXPR : LSHIFT_EXPR);
  1817. rtx x;
  1818. x = expand_shift (dir, word_mode, dest, shift, dest, 1);
  1819. if (x != dest)
  1820. emit_move_insn (dest, x);
  1821. }
  1822. }
  1823. /* When a parameter is a block, and perhaps in other cases, it is
  1824. possible that it did a load from an argument slot that was
  1825. already clobbered. */
  1826. if (is_sibcall
  1827. && check_sibcall_argument_overlap (before_arg, &args[i], 0))
  1828. *sibcall_failure = 1;
  1829. /* Handle calls that pass values in multiple non-contiguous
  1830. locations. The Irix 6 ABI has examples of this. */
  1831. if (GET_CODE (reg) == PARALLEL)
  1832. use_group_regs (call_fusage, reg);
  1833. else if (nregs == -1)
  1834. use_reg_mode (call_fusage, reg,
  1835. TYPE_MODE (TREE_TYPE (args[i].tree_value)));
  1836. else if (nregs > 0)
  1837. use_regs (call_fusage, REGNO (reg), nregs);
  1838. }
  1839. }
  1840. }
  1841. /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
  1842. wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
  1843. bytes, then we would need to push some additional bytes to pad the
  1844. arguments. So, we compute an adjust to the stack pointer for an
  1845. amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
  1846. bytes. Then, when the arguments are pushed the stack will be perfectly
  1847. aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
  1848. be popped after the call. Returns the adjustment. */
  1849. static int
  1850. combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
  1851. struct args_size *args_size,
  1852. unsigned int preferred_unit_stack_boundary)
  1853. {
  1854. /* The number of bytes to pop so that the stack will be
  1855. under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
  1856. HOST_WIDE_INT adjustment;
  1857. /* The alignment of the stack after the arguments are pushed, if we
  1858. just pushed the arguments without adjust the stack here. */
  1859. unsigned HOST_WIDE_INT unadjusted_alignment;
  1860. unadjusted_alignment
  1861. = ((stack_pointer_delta + unadjusted_args_size)
  1862. % preferred_unit_stack_boundary);
  1863. /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
  1864. as possible -- leaving just enough left to cancel out the
  1865. UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
  1866. PENDING_STACK_ADJUST is non-negative, and congruent to
  1867. -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
  1868. /* Begin by trying to pop all the bytes. */
  1869. unadjusted_alignment
  1870. = (unadjusted_alignment
  1871. - (pending_stack_adjust % preferred_unit_stack_boundary));
  1872. adjustment = pending_stack_adjust;
  1873. /* Push enough additional bytes that the stack will be aligned
  1874. after the arguments are pushed. */
  1875. if (preferred_unit_stack_boundary > 1)
  1876. {
  1877. if (unadjusted_alignment > 0)
  1878. adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
  1879. else
  1880. adjustment += unadjusted_alignment;
  1881. }
  1882. /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
  1883. bytes after the call. The right number is the entire
  1884. PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
  1885. by the arguments in the first place. */
  1886. args_size->constant
  1887. = pending_stack_adjust - adjustment + unadjusted_args_size;
  1888. return adjustment;
  1889. }
  1890. /* Scan X expression if it does not dereference any argument slots
  1891. we already clobbered by tail call arguments (as noted in stored_args_map
  1892. bitmap).
  1893. Return nonzero if X expression dereferences such argument slots,
  1894. zero otherwise. */
  1895. static int
  1896. check_sibcall_argument_overlap_1 (rtx x)
  1897. {
  1898. RTX_CODE code;
  1899. int i, j;
  1900. const char *fmt;
  1901. if (x == NULL_RTX)
  1902. return 0;
  1903. code = GET_CODE (x);
  1904. /* We need not check the operands of the CALL expression itself. */
  1905. if (code == CALL)
  1906. return 0;
  1907. if (code == MEM)
  1908. return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
  1909. GET_MODE_SIZE (GET_MODE (x)));
  1910. /* Scan all subexpressions. */
  1911. fmt = GET_RTX_FORMAT (code);
  1912. for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  1913. {
  1914. if (*fmt == 'e')
  1915. {
  1916. if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
  1917. return 1;
  1918. }
  1919. else if (*fmt == 'E')
  1920. {
  1921. for (j = 0; j < XVECLEN (x, i); j++)
  1922. if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
  1923. return 1;
  1924. }
  1925. }
  1926. return 0;
  1927. }
  1928. /* Scan sequence after INSN if it does not dereference any argument slots
  1929. we already clobbered by tail call arguments (as noted in stored_args_map
  1930. bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
  1931. stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
  1932. should be 0). Return nonzero if sequence after INSN dereferences such argument
  1933. slots, zero otherwise. */
  1934. static int
  1935. check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
  1936. int mark_stored_args_map)
  1937. {
  1938. int low, high;
  1939. if (insn == NULL_RTX)
  1940. insn = get_insns ();
  1941. else
  1942. insn = NEXT_INSN (insn);
  1943. for (; insn; insn = NEXT_INSN (insn))
  1944. if (INSN_P (insn)
  1945. && check_sibcall_argument_overlap_1 (PATTERN (insn)))
  1946. break;
  1947. if (mark_stored_args_map)
  1948. {
  1949. #ifdef ARGS_GROW_DOWNWARD
  1950. low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
  1951. #else
  1952. low = arg->locate.slot_offset.constant;
  1953. #endif
  1954. for (high = low + arg->locate.size.constant; low < high; low++)
  1955. bitmap_set_bit (stored_args_map, low);
  1956. }
  1957. return insn != NULL_RTX;
  1958. }
  1959. /* Given that a function returns a value of mode MODE at the most
  1960. significant end of hard register VALUE, shift VALUE left or right
  1961. as specified by LEFT_P. Return true if some action was needed. */
  1962. bool
  1963. shift_return_value (machine_mode mode, bool left_p, rtx value)
  1964. {
  1965. HOST_WIDE_INT shift;
  1966. gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
  1967. shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode);
  1968. if (shift == 0)
  1969. return false;
  1970. /* Use ashr rather than lshr for right shifts. This is for the benefit
  1971. of the MIPS port, which requires SImode values to be sign-extended
  1972. when stored in 64-bit registers. */
  1973. if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab,
  1974. value, GEN_INT (shift), value, 1, OPTAB_WIDEN))
  1975. gcc_unreachable ();
  1976. return true;
  1977. }
  1978. /* If X is a likely-spilled register value, copy it to a pseudo
  1979. register and return that register. Return X otherwise. */
  1980. static rtx
  1981. avoid_likely_spilled_reg (rtx x)
  1982. {
  1983. rtx new_rtx;
  1984. if (REG_P (x)
  1985. && HARD_REGISTER_P (x)
  1986. && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
  1987. {
  1988. /* Make sure that we generate a REG rather than a CONCAT.
  1989. Moves into CONCATs can need nontrivial instructions,
  1990. and the whole point of this function is to avoid
  1991. using the hard register directly in such a situation. */
  1992. generating_concat_p = 0;
  1993. new_rtx = gen_reg_rtx (GET_MODE (x));
  1994. generating_concat_p = 1;
  1995. emit_move_insn (new_rtx, x);
  1996. return new_rtx;
  1997. }
  1998. return x;
  1999. }
  2000. /* Generate all the code for a CALL_EXPR exp
  2001. and return an rtx for its value.
  2002. Store the value in TARGET (specified as an rtx) if convenient.
  2003. If the value is stored in TARGET then TARGET is returned.
  2004. If IGNORE is nonzero, then we ignore the value of the function call. */
  2005. rtx
  2006. expand_call (tree exp, rtx target, int ignore)
  2007. {
  2008. /* Nonzero if we are currently expanding a call. */
  2009. static int currently_expanding_call = 0;
  2010. /* RTX for the function to be called. */
  2011. rtx funexp;
  2012. /* Sequence of insns to perform a normal "call". */
  2013. rtx_insn *normal_call_insns = NULL;
  2014. /* Sequence of insns to perform a tail "call". */
  2015. rtx_insn *tail_call_insns = NULL;
  2016. /* Data type of the function. */
  2017. tree funtype;
  2018. tree type_arg_types;
  2019. tree rettype;
  2020. /* Declaration of the function being called,
  2021. or 0 if the function is computed (not known by name). */
  2022. tree fndecl = 0;
  2023. /* The type of the function being called. */
  2024. tree fntype;
  2025. bool try_tail_call = CALL_EXPR_TAILCALL (exp);
  2026. int pass;
  2027. /* Register in which non-BLKmode value will be returned,
  2028. or 0 if no value or if value is BLKmode. */
  2029. rtx valreg;
  2030. /* Register(s) in which bounds are returned. */
  2031. rtx valbnd = NULL;
  2032. /* Address where we should return a BLKmode value;
  2033. 0 if value not BLKmode. */
  2034. rtx structure_value_addr = 0;
  2035. /* Nonzero if that address is being passed by treating it as
  2036. an extra, implicit first parameter. Otherwise,
  2037. it is passed by being copied directly into struct_value_rtx. */
  2038. int structure_value_addr_parm = 0;
  2039. /* Holds the value of implicit argument for the struct value. */
  2040. tree structure_value_addr_value = NULL_TREE;
  2041. /* Size of aggregate value wanted, or zero if none wanted
  2042. or if we are using the non-reentrant PCC calling convention
  2043. or expecting the value in registers. */
  2044. HOST_WIDE_INT struct_value_size = 0;
  2045. /* Nonzero if called function returns an aggregate in memory PCC style,
  2046. by returning the address of where to find it. */
  2047. int pcc_struct_value = 0;
  2048. rtx struct_value = 0;
  2049. /* Number of actual parameters in this call, including struct value addr. */
  2050. int num_actuals;
  2051. /* Number of named args. Args after this are anonymous ones
  2052. and they must all go on the stack. */
  2053. int n_named_args;
  2054. /* Number of complex actual arguments that need to be split. */
  2055. int num_complex_actuals = 0;
  2056. /* Vector of information about each argument.
  2057. Arguments are numbered in the order they will be pushed,
  2058. not the order they are written. */
  2059. struct arg_data *args;
  2060. /* Total size in bytes of all the stack-parms scanned so far. */
  2061. struct args_size args_size;
  2062. struct args_size adjusted_args_size;
  2063. /* Size of arguments before any adjustments (such as rounding). */
  2064. int unadjusted_args_size;
  2065. /* Data on reg parms scanned so far. */
  2066. CUMULATIVE_ARGS args_so_far_v;
  2067. cumulative_args_t args_so_far;
  2068. /* Nonzero if a reg parm has been scanned. */
  2069. int reg_parm_seen;
  2070. /* Nonzero if this is an indirect function call. */
  2071. /* Nonzero if we must avoid push-insns in the args for this call.
  2072. If stack space is allocated for register parameters, but not by the
  2073. caller, then it is preallocated in the fixed part of the stack frame.
  2074. So the entire argument block must then be preallocated (i.e., we
  2075. ignore PUSH_ROUNDING in that case). */
  2076. int must_preallocate = !PUSH_ARGS;
  2077. /* Size of the stack reserved for parameter registers. */
  2078. int reg_parm_stack_space = 0;
  2079. /* Address of space preallocated for stack parms
  2080. (on machines that lack push insns), or 0 if space not preallocated. */
  2081. rtx argblock = 0;
  2082. /* Mask of ECF_ and ERF_ flags. */
  2083. int flags = 0;
  2084. int return_flags = 0;
  2085. #ifdef REG_PARM_STACK_SPACE
  2086. /* Define the boundary of the register parm stack space that needs to be
  2087. saved, if any. */
  2088. int low_to_save, high_to_save;
  2089. rtx save_area = 0; /* Place that it is saved */
  2090. #endif
  2091. int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
  2092. char *initial_stack_usage_map = stack_usage_map;
  2093. char *stack_usage_map_buf = NULL;
  2094. int old_stack_allocated;
  2095. /* State variables to track stack modifications. */
  2096. rtx old_stack_level = 0;
  2097. int old_stack_arg_under_construction = 0;
  2098. int old_pending_adj = 0;
  2099. int old_inhibit_defer_pop = inhibit_defer_pop;
  2100. /* Some stack pointer alterations we make are performed via
  2101. allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
  2102. which we then also need to save/restore along the way. */
  2103. int old_stack_pointer_delta = 0;
  2104. rtx call_fusage;
  2105. tree addr = CALL_EXPR_FN (exp);
  2106. int i;
  2107. /* The alignment of the stack, in bits. */
  2108. unsigned HOST_WIDE_INT preferred_stack_boundary;
  2109. /* The alignment of the stack, in bytes. */
  2110. unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
  2111. /* The static chain value to use for this call. */
  2112. rtx static_chain_value;
  2113. /* See if this is "nothrow" function call. */
  2114. if (TREE_NOTHROW (exp))
  2115. flags |= ECF_NOTHROW;
  2116. /* See if we can find a DECL-node for the actual function, and get the
  2117. function attributes (flags) from the function decl or type node. */
  2118. fndecl = get_callee_fndecl (exp);
  2119. if (fndecl)
  2120. {
  2121. fntype = TREE_TYPE (fndecl);
  2122. flags |= flags_from_decl_or_type (fndecl);
  2123. return_flags |= decl_return_flags (fndecl);
  2124. }
  2125. else
  2126. {
  2127. fntype = TREE_TYPE (TREE_TYPE (addr));
  2128. flags |= flags_from_decl_or_type (fntype);
  2129. }
  2130. rettype = TREE_TYPE (exp);
  2131. struct_value = targetm.calls.struct_value_rtx (fntype, 0);
  2132. /* Warn if this value is an aggregate type,
  2133. regardless of which calling convention we are using for it. */
  2134. if (AGGREGATE_TYPE_P (rettype))
  2135. warning (OPT_Waggregate_return, "function call has aggregate value");
  2136. /* If the result of a non looping pure or const function call is
  2137. ignored (or void), and none of its arguments are volatile, we can
  2138. avoid expanding the call and just evaluate the arguments for
  2139. side-effects. */
  2140. if ((flags & (ECF_CONST | ECF_PURE))
  2141. && (!(flags & ECF_LOOPING_CONST_OR_PURE))
  2142. && (ignore || target == const0_rtx
  2143. || TYPE_MODE (rettype) == VOIDmode))
  2144. {
  2145. bool volatilep = false;
  2146. tree arg;
  2147. call_expr_arg_iterator iter;
  2148. FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
  2149. if (TREE_THIS_VOLATILE (arg))
  2150. {
  2151. volatilep = true;
  2152. break;
  2153. }
  2154. if (! volatilep)
  2155. {
  2156. FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
  2157. expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
  2158. return const0_rtx;
  2159. }
  2160. }
  2161. #ifdef REG_PARM_STACK_SPACE
  2162. reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
  2163. #endif
  2164. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
  2165. && reg_parm_stack_space > 0 && PUSH_ARGS)
  2166. must_preallocate = 1;
  2167. /* Set up a place to return a structure. */
  2168. /* Cater to broken compilers. */
  2169. if (aggregate_value_p (exp, fntype))
  2170. {
  2171. /* This call returns a big structure. */
  2172. flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
  2173. #ifdef PCC_STATIC_STRUCT_RETURN
  2174. {
  2175. pcc_struct_value = 1;
  2176. }
  2177. #else /* not PCC_STATIC_STRUCT_RETURN */
  2178. {
  2179. struct_value_size = int_size_in_bytes (rettype);
  2180. /* Even if it is semantically safe to use the target as the return
  2181. slot, it may be not sufficiently aligned for the return type. */
  2182. if (CALL_EXPR_RETURN_SLOT_OPT (exp)
  2183. && target
  2184. && MEM_P (target)
  2185. && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
  2186. && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype),
  2187. MEM_ALIGN (target))))
  2188. structure_value_addr = XEXP (target, 0);
  2189. else
  2190. {
  2191. /* For variable-sized objects, we must be called with a target
  2192. specified. If we were to allocate space on the stack here,
  2193. we would have no way of knowing when to free it. */
  2194. rtx d = assign_temp (rettype, 1, 1);
  2195. structure_value_addr = XEXP (d, 0);
  2196. target = 0;
  2197. }
  2198. }
  2199. #endif /* not PCC_STATIC_STRUCT_RETURN */
  2200. }
  2201. /* Figure out the amount to which the stack should be aligned. */
  2202. preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
  2203. if (fndecl)
  2204. {
  2205. struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
  2206. /* Without automatic stack alignment, we can't increase preferred
  2207. stack boundary. With automatic stack alignment, it is
  2208. unnecessary since unless we can guarantee that all callers will
  2209. align the outgoing stack properly, callee has to align its
  2210. stack anyway. */
  2211. if (i
  2212. && i->preferred_incoming_stack_boundary
  2213. && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
  2214. preferred_stack_boundary = i->preferred_incoming_stack_boundary;
  2215. }
  2216. /* Operand 0 is a pointer-to-function; get the type of the function. */
  2217. funtype = TREE_TYPE (addr);
  2218. gcc_assert (POINTER_TYPE_P (funtype));
  2219. funtype = TREE_TYPE (funtype);
  2220. /* Count whether there are actual complex arguments that need to be split
  2221. into their real and imaginary parts. Munge the type_arg_types
  2222. appropriately here as well. */
  2223. if (targetm.calls.split_complex_arg)
  2224. {
  2225. call_expr_arg_iterator iter;
  2226. tree arg;
  2227. FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
  2228. {
  2229. tree type = TREE_TYPE (arg);
  2230. if (type && TREE_CODE (type) == COMPLEX_TYPE
  2231. && targetm.calls.split_complex_arg (type))
  2232. num_complex_actuals++;
  2233. }
  2234. type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
  2235. }
  2236. else
  2237. type_arg_types = TYPE_ARG_TYPES (funtype);
  2238. if (flags & ECF_MAY_BE_ALLOCA)
  2239. cfun->calls_alloca = 1;
  2240. /* If struct_value_rtx is 0, it means pass the address
  2241. as if it were an extra parameter. Put the argument expression
  2242. in structure_value_addr_value. */
  2243. if (structure_value_addr && struct_value == 0)
  2244. {
  2245. /* If structure_value_addr is a REG other than
  2246. virtual_outgoing_args_rtx, we can use always use it. If it
  2247. is not a REG, we must always copy it into a register.
  2248. If it is virtual_outgoing_args_rtx, we must copy it to another
  2249. register in some cases. */
  2250. rtx temp = (!REG_P (structure_value_addr)
  2251. || (ACCUMULATE_OUTGOING_ARGS
  2252. && stack_arg_under_construction
  2253. && structure_value_addr == virtual_outgoing_args_rtx)
  2254. ? copy_addr_to_reg (convert_memory_address
  2255. (Pmode, structure_value_addr))
  2256. : structure_value_addr);
  2257. structure_value_addr_value =
  2258. make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
  2259. structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1;
  2260. }
  2261. /* Count the arguments and set NUM_ACTUALS. */
  2262. num_actuals =
  2263. call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
  2264. /* Compute number of named args.
  2265. First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
  2266. if (type_arg_types != 0)
  2267. n_named_args
  2268. = (list_length (type_arg_types)
  2269. /* Count the struct value address, if it is passed as a parm. */
  2270. + structure_value_addr_parm);
  2271. else
  2272. /* If we know nothing, treat all args as named. */
  2273. n_named_args = num_actuals;
  2274. /* Start updating where the next arg would go.
  2275. On some machines (such as the PA) indirect calls have a different
  2276. calling convention than normal calls. The fourth argument in
  2277. INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
  2278. or not. */
  2279. INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
  2280. args_so_far = pack_cumulative_args (&args_so_far_v);
  2281. /* Now possibly adjust the number of named args.
  2282. Normally, don't include the last named arg if anonymous args follow.
  2283. We do include the last named arg if
  2284. targetm.calls.strict_argument_naming() returns nonzero.
  2285. (If no anonymous args follow, the result of list_length is actually
  2286. one too large. This is harmless.)
  2287. If targetm.calls.pretend_outgoing_varargs_named() returns
  2288. nonzero, and targetm.calls.strict_argument_naming() returns zero,
  2289. this machine will be able to place unnamed args that were passed
  2290. in registers into the stack. So treat all args as named. This
  2291. allows the insns emitting for a specific argument list to be
  2292. independent of the function declaration.
  2293. If targetm.calls.pretend_outgoing_varargs_named() returns zero,
  2294. we do not have any reliable way to pass unnamed args in
  2295. registers, so we must force them into memory. */
  2296. if (type_arg_types != 0
  2297. && targetm.calls.strict_argument_naming (args_so_far))
  2298. ;
  2299. else if (type_arg_types != 0
  2300. && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
  2301. /* Don't include the last named arg. */
  2302. --n_named_args;
  2303. else
  2304. /* Treat all args as named. */
  2305. n_named_args = num_actuals;
  2306. /* Make a vector to hold all the information about each arg. */
  2307. args = XALLOCAVEC (struct arg_data, num_actuals);
  2308. memset (args, 0, num_actuals * sizeof (struct arg_data));
  2309. /* Build up entries in the ARGS array, compute the size of the
  2310. arguments into ARGS_SIZE, etc. */
  2311. initialize_argument_information (num_actuals, args, &args_size,
  2312. n_named_args, exp,
  2313. structure_value_addr_value, fndecl, fntype,
  2314. args_so_far, reg_parm_stack_space,
  2315. &old_stack_level, &old_pending_adj,
  2316. &must_preallocate, &flags,
  2317. &try_tail_call, CALL_FROM_THUNK_P (exp));
  2318. if (args_size.var)
  2319. must_preallocate = 1;
  2320. /* Now make final decision about preallocating stack space. */
  2321. must_preallocate = finalize_must_preallocate (must_preallocate,
  2322. num_actuals, args,
  2323. &args_size);
  2324. /* If the structure value address will reference the stack pointer, we
  2325. must stabilize it. We don't need to do this if we know that we are
  2326. not going to adjust the stack pointer in processing this call. */
  2327. if (structure_value_addr
  2328. && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
  2329. || reg_mentioned_p (virtual_outgoing_args_rtx,
  2330. structure_value_addr))
  2331. && (args_size.var
  2332. || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
  2333. structure_value_addr = copy_to_reg (structure_value_addr);
  2334. /* Tail calls can make things harder to debug, and we've traditionally
  2335. pushed these optimizations into -O2. Don't try if we're already
  2336. expanding a call, as that means we're an argument. Don't try if
  2337. there's cleanups, as we know there's code to follow the call. */
  2338. if (currently_expanding_call++ != 0
  2339. || !flag_optimize_sibling_calls
  2340. || args_size.var
  2341. || dbg_cnt (tail_call) == false)
  2342. try_tail_call = 0;
  2343. /* Rest of purposes for tail call optimizations to fail. */
  2344. if (
  2345. #ifdef HAVE_sibcall_epilogue
  2346. !HAVE_sibcall_epilogue
  2347. #else
  2348. 1
  2349. #endif
  2350. || !try_tail_call
  2351. /* Doing sibling call optimization needs some work, since
  2352. structure_value_addr can be allocated on the stack.
  2353. It does not seem worth the effort since few optimizable
  2354. sibling calls will return a structure. */
  2355. || structure_value_addr != NULL_RTX
  2356. #ifdef REG_PARM_STACK_SPACE
  2357. /* If outgoing reg parm stack space changes, we can not do sibcall. */
  2358. || (OUTGOING_REG_PARM_STACK_SPACE (funtype)
  2359. != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
  2360. || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))
  2361. #endif
  2362. /* Check whether the target is able to optimize the call
  2363. into a sibcall. */
  2364. || !targetm.function_ok_for_sibcall (fndecl, exp)
  2365. /* Functions that do not return exactly once may not be sibcall
  2366. optimized. */
  2367. || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN))
  2368. || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
  2369. /* If the called function is nested in the current one, it might access
  2370. some of the caller's arguments, but could clobber them beforehand if
  2371. the argument areas are shared. */
  2372. || (fndecl && decl_function_context (fndecl) == current_function_decl)
  2373. /* If this function requires more stack slots than the current
  2374. function, we cannot change it into a sibling call.
  2375. crtl->args.pretend_args_size is not part of the
  2376. stack allocated by our caller. */
  2377. || args_size.constant > (crtl->args.size
  2378. - crtl->args.pretend_args_size)
  2379. /* If the callee pops its own arguments, then it must pop exactly
  2380. the same number of arguments as the current function. */
  2381. || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
  2382. != targetm.calls.return_pops_args (current_function_decl,
  2383. TREE_TYPE (current_function_decl),
  2384. crtl->args.size))
  2385. || !lang_hooks.decls.ok_for_sibcall (fndecl))
  2386. try_tail_call = 0;
  2387. /* Check if caller and callee disagree in promotion of function
  2388. return value. */
  2389. if (try_tail_call)
  2390. {
  2391. machine_mode caller_mode, caller_promoted_mode;
  2392. machine_mode callee_mode, callee_promoted_mode;
  2393. int caller_unsignedp, callee_unsignedp;
  2394. tree caller_res = DECL_RESULT (current_function_decl);
  2395. caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
  2396. caller_mode = DECL_MODE (caller_res);
  2397. callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
  2398. callee_mode = TYPE_MODE (TREE_TYPE (funtype));
  2399. caller_promoted_mode
  2400. = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
  2401. &caller_unsignedp,
  2402. TREE_TYPE (current_function_decl), 1);
  2403. callee_promoted_mode
  2404. = promote_function_mode (TREE_TYPE (funtype), callee_mode,
  2405. &callee_unsignedp,
  2406. funtype, 1);
  2407. if (caller_mode != VOIDmode
  2408. && (caller_promoted_mode != callee_promoted_mode
  2409. || ((caller_mode != caller_promoted_mode
  2410. || callee_mode != callee_promoted_mode)
  2411. && (caller_unsignedp != callee_unsignedp
  2412. || GET_MODE_BITSIZE (caller_mode)
  2413. < GET_MODE_BITSIZE (callee_mode)))))
  2414. try_tail_call = 0;
  2415. }
  2416. /* Ensure current function's preferred stack boundary is at least
  2417. what we need. Stack alignment may also increase preferred stack
  2418. boundary. */
  2419. if (crtl->preferred_stack_boundary < preferred_stack_boundary)
  2420. crtl->preferred_stack_boundary = preferred_stack_boundary;
  2421. else
  2422. preferred_stack_boundary = crtl->preferred_stack_boundary;
  2423. preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
  2424. /* We want to make two insn chains; one for a sibling call, the other
  2425. for a normal call. We will select one of the two chains after
  2426. initial RTL generation is complete. */
  2427. for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
  2428. {
  2429. int sibcall_failure = 0;
  2430. /* We want to emit any pending stack adjustments before the tail
  2431. recursion "call". That way we know any adjustment after the tail
  2432. recursion call can be ignored if we indeed use the tail
  2433. call expansion. */
  2434. saved_pending_stack_adjust save;
  2435. rtx_insn *insns, *before_call, *after_args;
  2436. rtx next_arg_reg;
  2437. if (pass == 0)
  2438. {
  2439. /* State variables we need to save and restore between
  2440. iterations. */
  2441. save_pending_stack_adjust (&save);
  2442. }
  2443. if (pass)
  2444. flags &= ~ECF_SIBCALL;
  2445. else
  2446. flags |= ECF_SIBCALL;
  2447. /* Other state variables that we must reinitialize each time
  2448. through the loop (that are not initialized by the loop itself). */
  2449. argblock = 0;
  2450. call_fusage = 0;
  2451. /* Start a new sequence for the normal call case.
  2452. From this point on, if the sibling call fails, we want to set
  2453. sibcall_failure instead of continuing the loop. */
  2454. start_sequence ();
  2455. /* Don't let pending stack adjusts add up to too much.
  2456. Also, do all pending adjustments now if there is any chance
  2457. this might be a call to alloca or if we are expanding a sibling
  2458. call sequence.
  2459. Also do the adjustments before a throwing call, otherwise
  2460. exception handling can fail; PR 19225. */
  2461. if (pending_stack_adjust >= 32
  2462. || (pending_stack_adjust > 0
  2463. && (flags & ECF_MAY_BE_ALLOCA))
  2464. || (pending_stack_adjust > 0
  2465. && flag_exceptions && !(flags & ECF_NOTHROW))
  2466. || pass == 0)
  2467. do_pending_stack_adjust ();
  2468. /* Precompute any arguments as needed. */
  2469. if (pass)
  2470. precompute_arguments (num_actuals, args);
  2471. /* Now we are about to start emitting insns that can be deleted
  2472. if a libcall is deleted. */
  2473. if (pass && (flags & ECF_MALLOC))
  2474. start_sequence ();
  2475. if (pass == 0 && crtl->stack_protect_guard)
  2476. stack_protect_epilogue ();
  2477. adjusted_args_size = args_size;
  2478. /* Compute the actual size of the argument block required. The variable
  2479. and constant sizes must be combined, the size may have to be rounded,
  2480. and there may be a minimum required size. When generating a sibcall
  2481. pattern, do not round up, since we'll be re-using whatever space our
  2482. caller provided. */
  2483. unadjusted_args_size
  2484. = compute_argument_block_size (reg_parm_stack_space,
  2485. &adjusted_args_size,
  2486. fndecl, fntype,
  2487. (pass == 0 ? 0
  2488. : preferred_stack_boundary));
  2489. old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
  2490. /* The argument block when performing a sibling call is the
  2491. incoming argument block. */
  2492. if (pass == 0)
  2493. {
  2494. argblock = crtl->args.internal_arg_pointer;
  2495. argblock
  2496. #ifdef STACK_GROWS_DOWNWARD
  2497. = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
  2498. #else
  2499. = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
  2500. #endif
  2501. stored_args_map = sbitmap_alloc (args_size.constant);
  2502. bitmap_clear (stored_args_map);
  2503. }
  2504. /* If we have no actual push instructions, or shouldn't use them,
  2505. make space for all args right now. */
  2506. else if (adjusted_args_size.var != 0)
  2507. {
  2508. if (old_stack_level == 0)
  2509. {
  2510. emit_stack_save (SAVE_BLOCK, &old_stack_level);
  2511. old_stack_pointer_delta = stack_pointer_delta;
  2512. old_pending_adj = pending_stack_adjust;
  2513. pending_stack_adjust = 0;
  2514. /* stack_arg_under_construction says whether a stack arg is
  2515. being constructed at the old stack level. Pushing the stack
  2516. gets a clean outgoing argument block. */
  2517. old_stack_arg_under_construction = stack_arg_under_construction;
  2518. stack_arg_under_construction = 0;
  2519. }
  2520. argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
  2521. if (flag_stack_usage_info)
  2522. current_function_has_unbounded_dynamic_stack_size = 1;
  2523. }
  2524. else
  2525. {
  2526. /* Note that we must go through the motions of allocating an argument
  2527. block even if the size is zero because we may be storing args
  2528. in the area reserved for register arguments, which may be part of
  2529. the stack frame. */
  2530. int needed = adjusted_args_size.constant;
  2531. /* Store the maximum argument space used. It will be pushed by
  2532. the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
  2533. checking). */
  2534. if (needed > crtl->outgoing_args_size)
  2535. crtl->outgoing_args_size = needed;
  2536. if (must_preallocate)
  2537. {
  2538. if (ACCUMULATE_OUTGOING_ARGS)
  2539. {
  2540. /* Since the stack pointer will never be pushed, it is
  2541. possible for the evaluation of a parm to clobber
  2542. something we have already written to the stack.
  2543. Since most function calls on RISC machines do not use
  2544. the stack, this is uncommon, but must work correctly.
  2545. Therefore, we save any area of the stack that was already
  2546. written and that we are using. Here we set up to do this
  2547. by making a new stack usage map from the old one. The
  2548. actual save will be done by store_one_arg.
  2549. Another approach might be to try to reorder the argument
  2550. evaluations to avoid this conflicting stack usage. */
  2551. /* Since we will be writing into the entire argument area,
  2552. the map must be allocated for its entire size, not just
  2553. the part that is the responsibility of the caller. */
  2554. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
  2555. needed += reg_parm_stack_space;
  2556. #ifdef ARGS_GROW_DOWNWARD
  2557. highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
  2558. needed + 1);
  2559. #else
  2560. highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
  2561. needed);
  2562. #endif
  2563. free (stack_usage_map_buf);
  2564. stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
  2565. stack_usage_map = stack_usage_map_buf;
  2566. if (initial_highest_arg_in_use)
  2567. memcpy (stack_usage_map, initial_stack_usage_map,
  2568. initial_highest_arg_in_use);
  2569. if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
  2570. memset (&stack_usage_map[initial_highest_arg_in_use], 0,
  2571. (highest_outgoing_arg_in_use
  2572. - initial_highest_arg_in_use));
  2573. needed = 0;
  2574. /* The address of the outgoing argument list must not be
  2575. copied to a register here, because argblock would be left
  2576. pointing to the wrong place after the call to
  2577. allocate_dynamic_stack_space below. */
  2578. argblock = virtual_outgoing_args_rtx;
  2579. }
  2580. else
  2581. {
  2582. if (inhibit_defer_pop == 0)
  2583. {
  2584. /* Try to reuse some or all of the pending_stack_adjust
  2585. to get this space. */
  2586. needed
  2587. = (combine_pending_stack_adjustment_and_call
  2588. (unadjusted_args_size,
  2589. &adjusted_args_size,
  2590. preferred_unit_stack_boundary));
  2591. /* combine_pending_stack_adjustment_and_call computes
  2592. an adjustment before the arguments are allocated.
  2593. Account for them and see whether or not the stack
  2594. needs to go up or down. */
  2595. needed = unadjusted_args_size - needed;
  2596. if (needed < 0)
  2597. {
  2598. /* We're releasing stack space. */
  2599. /* ??? We can avoid any adjustment at all if we're
  2600. already aligned. FIXME. */
  2601. pending_stack_adjust = -needed;
  2602. do_pending_stack_adjust ();
  2603. needed = 0;
  2604. }
  2605. else
  2606. /* We need to allocate space. We'll do that in
  2607. push_block below. */
  2608. pending_stack_adjust = 0;
  2609. }
  2610. /* Special case this because overhead of `push_block' in
  2611. this case is non-trivial. */
  2612. if (needed == 0)
  2613. argblock = virtual_outgoing_args_rtx;
  2614. else
  2615. {
  2616. argblock = push_block (GEN_INT (needed), 0, 0);
  2617. #ifdef ARGS_GROW_DOWNWARD
  2618. argblock = plus_constant (Pmode, argblock, needed);
  2619. #endif
  2620. }
  2621. /* We only really need to call `copy_to_reg' in the case
  2622. where push insns are going to be used to pass ARGBLOCK
  2623. to a function call in ARGS. In that case, the stack
  2624. pointer changes value from the allocation point to the
  2625. call point, and hence the value of
  2626. VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
  2627. as well always do it. */
  2628. argblock = copy_to_reg (argblock);
  2629. }
  2630. }
  2631. }
  2632. if (ACCUMULATE_OUTGOING_ARGS)
  2633. {
  2634. /* The save/restore code in store_one_arg handles all
  2635. cases except one: a constructor call (including a C
  2636. function returning a BLKmode struct) to initialize
  2637. an argument. */
  2638. if (stack_arg_under_construction)
  2639. {
  2640. rtx push_size
  2641. = GEN_INT (adjusted_args_size.constant
  2642. + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
  2643. : TREE_TYPE (fndecl))) ? 0
  2644. : reg_parm_stack_space));
  2645. if (old_stack_level == 0)
  2646. {
  2647. emit_stack_save (SAVE_BLOCK, &old_stack_level);
  2648. old_stack_pointer_delta = stack_pointer_delta;
  2649. old_pending_adj = pending_stack_adjust;
  2650. pending_stack_adjust = 0;
  2651. /* stack_arg_under_construction says whether a stack
  2652. arg is being constructed at the old stack level.
  2653. Pushing the stack gets a clean outgoing argument
  2654. block. */
  2655. old_stack_arg_under_construction
  2656. = stack_arg_under_construction;
  2657. stack_arg_under_construction = 0;
  2658. /* Make a new map for the new argument list. */
  2659. free (stack_usage_map_buf);
  2660. stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
  2661. stack_usage_map = stack_usage_map_buf;
  2662. highest_outgoing_arg_in_use = 0;
  2663. }
  2664. /* We can pass TRUE as the 4th argument because we just
  2665. saved the stack pointer and will restore it right after
  2666. the call. */
  2667. allocate_dynamic_stack_space (push_size, 0,
  2668. BIGGEST_ALIGNMENT, true);
  2669. }
  2670. /* If argument evaluation might modify the stack pointer,
  2671. copy the address of the argument list to a register. */
  2672. for (i = 0; i < num_actuals; i++)
  2673. if (args[i].pass_on_stack)
  2674. {
  2675. argblock = copy_addr_to_reg (argblock);
  2676. break;
  2677. }
  2678. }
  2679. compute_argument_addresses (args, argblock, num_actuals);
  2680. /* Perform stack alignment before the first push (the last arg). */
  2681. if (argblock == 0
  2682. && adjusted_args_size.constant > reg_parm_stack_space
  2683. && adjusted_args_size.constant != unadjusted_args_size)
  2684. {
  2685. /* When the stack adjustment is pending, we get better code
  2686. by combining the adjustments. */
  2687. if (pending_stack_adjust
  2688. && ! inhibit_defer_pop)
  2689. {
  2690. pending_stack_adjust
  2691. = (combine_pending_stack_adjustment_and_call
  2692. (unadjusted_args_size,
  2693. &adjusted_args_size,
  2694. preferred_unit_stack_boundary));
  2695. do_pending_stack_adjust ();
  2696. }
  2697. else if (argblock == 0)
  2698. anti_adjust_stack (GEN_INT (adjusted_args_size.constant
  2699. - unadjusted_args_size));
  2700. }
  2701. /* Now that the stack is properly aligned, pops can't safely
  2702. be deferred during the evaluation of the arguments. */
  2703. NO_DEFER_POP;
  2704. /* Record the maximum pushed stack space size. We need to delay
  2705. doing it this far to take into account the optimization done
  2706. by combine_pending_stack_adjustment_and_call. */
  2707. if (flag_stack_usage_info
  2708. && !ACCUMULATE_OUTGOING_ARGS
  2709. && pass
  2710. && adjusted_args_size.var == 0)
  2711. {
  2712. int pushed = adjusted_args_size.constant + pending_stack_adjust;
  2713. if (pushed > current_function_pushed_stack_size)
  2714. current_function_pushed_stack_size = pushed;
  2715. }
  2716. funexp = rtx_for_function_call (fndecl, addr);
  2717. /* Precompute all register parameters. It isn't safe to compute anything
  2718. once we have started filling any specific hard regs. */
  2719. precompute_register_parameters (num_actuals, args, &reg_parm_seen);
  2720. if (CALL_EXPR_STATIC_CHAIN (exp))
  2721. static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
  2722. else
  2723. static_chain_value = 0;
  2724. #ifdef REG_PARM_STACK_SPACE
  2725. /* Save the fixed argument area if it's part of the caller's frame and
  2726. is clobbered by argument setup for this call. */
  2727. if (ACCUMULATE_OUTGOING_ARGS && pass)
  2728. save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
  2729. &low_to_save, &high_to_save);
  2730. #endif
  2731. /* Now store (and compute if necessary) all non-register parms.
  2732. These come before register parms, since they can require block-moves,
  2733. which could clobber the registers used for register parms.
  2734. Parms which have partial registers are not stored here,
  2735. but we do preallocate space here if they want that. */
  2736. for (i = 0; i < num_actuals; i++)
  2737. {
  2738. /* Delay bounds until all other args are stored. */
  2739. if (POINTER_BOUNDS_P (args[i].tree_value))
  2740. continue;
  2741. else if (args[i].reg == 0 || args[i].pass_on_stack)
  2742. {
  2743. rtx_insn *before_arg = get_last_insn ();
  2744. /* We don't allow passing huge (> 2^30 B) arguments
  2745. by value. It would cause an overflow later on. */
  2746. if (adjusted_args_size.constant
  2747. >= (1 << (HOST_BITS_PER_INT - 2)))
  2748. {
  2749. sorry ("passing too large argument on stack");
  2750. continue;
  2751. }
  2752. if (store_one_arg (&args[i], argblock, flags,
  2753. adjusted_args_size.var != 0,
  2754. reg_parm_stack_space)
  2755. || (pass == 0
  2756. && check_sibcall_argument_overlap (before_arg,
  2757. &args[i], 1)))
  2758. sibcall_failure = 1;
  2759. }
  2760. if (args[i].stack)
  2761. call_fusage
  2762. = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
  2763. gen_rtx_USE (VOIDmode, args[i].stack),
  2764. call_fusage);
  2765. }
  2766. /* If we have a parm that is passed in registers but not in memory
  2767. and whose alignment does not permit a direct copy into registers,
  2768. make a group of pseudos that correspond to each register that we
  2769. will later fill. */
  2770. if (STRICT_ALIGNMENT)
  2771. store_unaligned_arguments_into_pseudos (args, num_actuals);
  2772. /* Now store any partially-in-registers parm.
  2773. This is the last place a block-move can happen. */
  2774. if (reg_parm_seen)
  2775. for (i = 0; i < num_actuals; i++)
  2776. if (args[i].partial != 0 && ! args[i].pass_on_stack)
  2777. {
  2778. rtx_insn *before_arg = get_last_insn ();
  2779. if (store_one_arg (&args[i], argblock, flags,
  2780. adjusted_args_size.var != 0,
  2781. reg_parm_stack_space)
  2782. || (pass == 0
  2783. && check_sibcall_argument_overlap (before_arg,
  2784. &args[i], 1)))
  2785. sibcall_failure = 1;
  2786. }
  2787. bool any_regs = false;
  2788. for (i = 0; i < num_actuals; i++)
  2789. if (args[i].reg != NULL_RTX)
  2790. {
  2791. any_regs = true;
  2792. targetm.calls.call_args (args[i].reg, funtype);
  2793. }
  2794. if (!any_regs)
  2795. targetm.calls.call_args (pc_rtx, funtype);
  2796. /* Figure out the register where the value, if any, will come back. */
  2797. valreg = 0;
  2798. valbnd = 0;
  2799. if (TYPE_MODE (rettype) != VOIDmode
  2800. && ! structure_value_addr)
  2801. {
  2802. if (pcc_struct_value)
  2803. {
  2804. valreg = hard_function_value (build_pointer_type (rettype),
  2805. fndecl, NULL, (pass == 0));
  2806. if (CALL_WITH_BOUNDS_P (exp))
  2807. valbnd = targetm.calls.
  2808. chkp_function_value_bounds (build_pointer_type (rettype),
  2809. fndecl, (pass == 0));
  2810. }
  2811. else
  2812. {
  2813. valreg = hard_function_value (rettype, fndecl, fntype,
  2814. (pass == 0));
  2815. if (CALL_WITH_BOUNDS_P (exp))
  2816. valbnd = targetm.calls.chkp_function_value_bounds (rettype,
  2817. fndecl,
  2818. (pass == 0));
  2819. }
  2820. /* If VALREG is a PARALLEL whose first member has a zero
  2821. offset, use that. This is for targets such as m68k that
  2822. return the same value in multiple places. */
  2823. if (GET_CODE (valreg) == PARALLEL)
  2824. {
  2825. rtx elem = XVECEXP (valreg, 0, 0);
  2826. rtx where = XEXP (elem, 0);
  2827. rtx offset = XEXP (elem, 1);
  2828. if (offset == const0_rtx
  2829. && GET_MODE (where) == GET_MODE (valreg))
  2830. valreg = where;
  2831. }
  2832. }
  2833. /* Store all bounds not passed in registers. */
  2834. for (i = 0; i < num_actuals; i++)
  2835. {
  2836. if (POINTER_BOUNDS_P (args[i].tree_value)
  2837. && !args[i].reg)
  2838. store_bounds (&args[i],
  2839. args[i].pointer_arg == -1
  2840. ? NULL
  2841. : &args[args[i].pointer_arg]);
  2842. }
  2843. /* If register arguments require space on the stack and stack space
  2844. was not preallocated, allocate stack space here for arguments
  2845. passed in registers. */
  2846. if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
  2847. && !ACCUMULATE_OUTGOING_ARGS
  2848. && must_preallocate == 0 && reg_parm_stack_space > 0)
  2849. anti_adjust_stack (GEN_INT (reg_parm_stack_space));
  2850. /* Pass the function the address in which to return a
  2851. structure value. */
  2852. if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
  2853. {
  2854. structure_value_addr
  2855. = convert_memory_address (Pmode, structure_value_addr);
  2856. emit_move_insn (struct_value,
  2857. force_reg (Pmode,
  2858. force_operand (structure_value_addr,
  2859. NULL_RTX)));
  2860. if (REG_P (struct_value))
  2861. use_reg (&call_fusage, struct_value);
  2862. }
  2863. after_args = get_last_insn ();
  2864. funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
  2865. static_chain_value, &call_fusage,
  2866. reg_parm_seen, pass == 0);
  2867. load_register_parameters (args, num_actuals, &call_fusage, flags,
  2868. pass == 0, &sibcall_failure);
  2869. /* Save a pointer to the last insn before the call, so that we can
  2870. later safely search backwards to find the CALL_INSN. */
  2871. before_call = get_last_insn ();
  2872. /* Set up next argument register. For sibling calls on machines
  2873. with register windows this should be the incoming register. */
  2874. if (pass == 0)
  2875. next_arg_reg = targetm.calls.function_incoming_arg (args_so_far,
  2876. VOIDmode,
  2877. void_type_node,
  2878. true);
  2879. else
  2880. next_arg_reg = targetm.calls.function_arg (args_so_far,
  2881. VOIDmode, void_type_node,
  2882. true);
  2883. if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
  2884. {
  2885. int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
  2886. arg_nr = num_actuals - arg_nr - 1;
  2887. if (arg_nr >= 0
  2888. && arg_nr < num_actuals
  2889. && args[arg_nr].reg
  2890. && valreg
  2891. && REG_P (valreg)
  2892. && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
  2893. call_fusage
  2894. = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
  2895. gen_rtx_SET (VOIDmode, valreg, args[arg_nr].reg),
  2896. call_fusage);
  2897. }
  2898. /* All arguments and registers used for the call must be set up by
  2899. now! */
  2900. /* Stack must be properly aligned now. */
  2901. gcc_assert (!pass
  2902. || !(stack_pointer_delta % preferred_unit_stack_boundary));
  2903. /* Generate the actual call instruction. */
  2904. emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
  2905. adjusted_args_size.constant, struct_value_size,
  2906. next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
  2907. flags, args_so_far);
  2908. if (flag_ipa_ra)
  2909. {
  2910. rtx_call_insn *last;
  2911. rtx datum = NULL_RTX;
  2912. if (fndecl != NULL_TREE)
  2913. {
  2914. datum = XEXP (DECL_RTL (fndecl), 0);
  2915. gcc_assert (datum != NULL_RTX
  2916. && GET_CODE (datum) == SYMBOL_REF);
  2917. }
  2918. last = last_call_insn ();
  2919. add_reg_note (last, REG_CALL_DECL, datum);
  2920. }
  2921. /* If the call setup or the call itself overlaps with anything
  2922. of the argument setup we probably clobbered our call address.
  2923. In that case we can't do sibcalls. */
  2924. if (pass == 0
  2925. && check_sibcall_argument_overlap (after_args, 0, 0))
  2926. sibcall_failure = 1;
  2927. /* If a non-BLKmode value is returned at the most significant end
  2928. of a register, shift the register right by the appropriate amount
  2929. and update VALREG accordingly. BLKmode values are handled by the
  2930. group load/store machinery below. */
  2931. if (!structure_value_addr
  2932. && !pcc_struct_value
  2933. && TYPE_MODE (rettype) != VOIDmode
  2934. && TYPE_MODE (rettype) != BLKmode
  2935. && REG_P (valreg)
  2936. && targetm.calls.return_in_msb (rettype))
  2937. {
  2938. if (shift_return_value (TYPE_MODE (rettype), false, valreg))
  2939. sibcall_failure = 1;
  2940. valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
  2941. }
  2942. if (pass && (flags & ECF_MALLOC))
  2943. {
  2944. rtx temp = gen_reg_rtx (GET_MODE (valreg));
  2945. rtx_insn *last, *insns;
  2946. /* The return value from a malloc-like function is a pointer. */
  2947. if (TREE_CODE (rettype) == POINTER_TYPE)
  2948. mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
  2949. emit_move_insn (temp, valreg);
  2950. /* The return value from a malloc-like function can not alias
  2951. anything else. */
  2952. last = get_last_insn ();
  2953. add_reg_note (last, REG_NOALIAS, temp);
  2954. /* Write out the sequence. */
  2955. insns = get_insns ();
  2956. end_sequence ();
  2957. emit_insn (insns);
  2958. valreg = temp;
  2959. }
  2960. /* For calls to `setjmp', etc., inform
  2961. function.c:setjmp_warnings that it should complain if
  2962. nonvolatile values are live. For functions that cannot
  2963. return, inform flow that control does not fall through. */
  2964. if ((flags & ECF_NORETURN) || pass == 0)
  2965. {
  2966. /* The barrier must be emitted
  2967. immediately after the CALL_INSN. Some ports emit more
  2968. than just a CALL_INSN above, so we must search for it here. */
  2969. rtx_insn *last = get_last_insn ();
  2970. while (!CALL_P (last))
  2971. {
  2972. last = PREV_INSN (last);
  2973. /* There was no CALL_INSN? */
  2974. gcc_assert (last != before_call);
  2975. }
  2976. emit_barrier_after (last);
  2977. /* Stack adjustments after a noreturn call are dead code.
  2978. However when NO_DEFER_POP is in effect, we must preserve
  2979. stack_pointer_delta. */
  2980. if (inhibit_defer_pop == 0)
  2981. {
  2982. stack_pointer_delta = old_stack_allocated;
  2983. pending_stack_adjust = 0;
  2984. }
  2985. }
  2986. /* If value type not void, return an rtx for the value. */
  2987. if (TYPE_MODE (rettype) == VOIDmode
  2988. || ignore)
  2989. target = const0_rtx;
  2990. else if (structure_value_addr)
  2991. {
  2992. if (target == 0 || !MEM_P (target))
  2993. {
  2994. target
  2995. = gen_rtx_MEM (TYPE_MODE (rettype),
  2996. memory_address (TYPE_MODE (rettype),
  2997. structure_value_addr));
  2998. set_mem_attributes (target, rettype, 1);
  2999. }
  3000. }
  3001. else if (pcc_struct_value)
  3002. {
  3003. /* This is the special C++ case where we need to
  3004. know what the true target was. We take care to
  3005. never use this value more than once in one expression. */
  3006. target = gen_rtx_MEM (TYPE_MODE (rettype),
  3007. copy_to_reg (valreg));
  3008. set_mem_attributes (target, rettype, 1);
  3009. }
  3010. /* Handle calls that return values in multiple non-contiguous locations.
  3011. The Irix 6 ABI has examples of this. */
  3012. else if (GET_CODE (valreg) == PARALLEL)
  3013. {
  3014. if (target == 0)
  3015. target = emit_group_move_into_temps (valreg);
  3016. else if (rtx_equal_p (target, valreg))
  3017. ;
  3018. else if (GET_CODE (target) == PARALLEL)
  3019. /* Handle the result of a emit_group_move_into_temps
  3020. call in the previous pass. */
  3021. emit_group_move (target, valreg);
  3022. else
  3023. emit_group_store (target, valreg, rettype,
  3024. int_size_in_bytes (rettype));
  3025. }
  3026. else if (target
  3027. && GET_MODE (target) == TYPE_MODE (rettype)
  3028. && GET_MODE (target) == GET_MODE (valreg))
  3029. {
  3030. bool may_overlap = false;
  3031. /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
  3032. reg to a plain register. */
  3033. if (!REG_P (target) || HARD_REGISTER_P (target))
  3034. valreg = avoid_likely_spilled_reg (valreg);
  3035. /* If TARGET is a MEM in the argument area, and we have
  3036. saved part of the argument area, then we can't store
  3037. directly into TARGET as it may get overwritten when we
  3038. restore the argument save area below. Don't work too
  3039. hard though and simply force TARGET to a register if it
  3040. is a MEM; the optimizer is quite likely to sort it out. */
  3041. if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
  3042. for (i = 0; i < num_actuals; i++)
  3043. if (args[i].save_area)
  3044. {
  3045. may_overlap = true;
  3046. break;
  3047. }
  3048. if (may_overlap)
  3049. target = copy_to_reg (valreg);
  3050. else
  3051. {
  3052. /* TARGET and VALREG cannot be equal at this point
  3053. because the latter would not have
  3054. REG_FUNCTION_VALUE_P true, while the former would if
  3055. it were referring to the same register.
  3056. If they refer to the same register, this move will be
  3057. a no-op, except when function inlining is being
  3058. done. */
  3059. emit_move_insn (target, valreg);
  3060. /* If we are setting a MEM, this code must be executed.
  3061. Since it is emitted after the call insn, sibcall
  3062. optimization cannot be performed in that case. */
  3063. if (MEM_P (target))
  3064. sibcall_failure = 1;
  3065. }
  3066. }
  3067. else
  3068. target = copy_to_reg (avoid_likely_spilled_reg (valreg));
  3069. /* If we promoted this return value, make the proper SUBREG.
  3070. TARGET might be const0_rtx here, so be careful. */
  3071. if (REG_P (target)
  3072. && TYPE_MODE (rettype) != BLKmode
  3073. && GET_MODE (target) != TYPE_MODE (rettype))
  3074. {
  3075. tree type = rettype;
  3076. int unsignedp = TYPE_UNSIGNED (type);
  3077. int offset = 0;
  3078. machine_mode pmode;
  3079. /* Ensure we promote as expected, and get the new unsignedness. */
  3080. pmode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
  3081. funtype, 1);
  3082. gcc_assert (GET_MODE (target) == pmode);
  3083. if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
  3084. && (GET_MODE_SIZE (GET_MODE (target))
  3085. > GET_MODE_SIZE (TYPE_MODE (type))))
  3086. {
  3087. offset = GET_MODE_SIZE (GET_MODE (target))
  3088. - GET_MODE_SIZE (TYPE_MODE (type));
  3089. if (! BYTES_BIG_ENDIAN)
  3090. offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
  3091. else if (! WORDS_BIG_ENDIAN)
  3092. offset %= UNITS_PER_WORD;
  3093. }
  3094. target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
  3095. SUBREG_PROMOTED_VAR_P (target) = 1;
  3096. SUBREG_PROMOTED_SET (target, unsignedp);
  3097. }
  3098. /* If size of args is variable or this was a constructor call for a stack
  3099. argument, restore saved stack-pointer value. */
  3100. if (old_stack_level)
  3101. {
  3102. rtx_insn *prev = get_last_insn ();
  3103. emit_stack_restore (SAVE_BLOCK, old_stack_level);
  3104. stack_pointer_delta = old_stack_pointer_delta;
  3105. fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
  3106. pending_stack_adjust = old_pending_adj;
  3107. old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
  3108. stack_arg_under_construction = old_stack_arg_under_construction;
  3109. highest_outgoing_arg_in_use = initial_highest_arg_in_use;
  3110. stack_usage_map = initial_stack_usage_map;
  3111. sibcall_failure = 1;
  3112. }
  3113. else if (ACCUMULATE_OUTGOING_ARGS && pass)
  3114. {
  3115. #ifdef REG_PARM_STACK_SPACE
  3116. if (save_area)
  3117. restore_fixed_argument_area (save_area, argblock,
  3118. high_to_save, low_to_save);
  3119. #endif
  3120. /* If we saved any argument areas, restore them. */
  3121. for (i = 0; i < num_actuals; i++)
  3122. if (args[i].save_area)
  3123. {
  3124. machine_mode save_mode = GET_MODE (args[i].save_area);
  3125. rtx stack_area
  3126. = gen_rtx_MEM (save_mode,
  3127. memory_address (save_mode,
  3128. XEXP (args[i].stack_slot, 0)));
  3129. if (save_mode != BLKmode)
  3130. emit_move_insn (stack_area, args[i].save_area);
  3131. else
  3132. emit_block_move (stack_area, args[i].save_area,
  3133. GEN_INT (args[i].locate.size.constant),
  3134. BLOCK_OP_CALL_PARM);
  3135. }
  3136. highest_outgoing_arg_in_use = initial_highest_arg_in_use;
  3137. stack_usage_map = initial_stack_usage_map;
  3138. }
  3139. /* If this was alloca, record the new stack level for nonlocal gotos.
  3140. Check for the handler slots since we might not have a save area
  3141. for non-local gotos. */
  3142. if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
  3143. update_nonlocal_goto_save_area ();
  3144. /* Free up storage we no longer need. */
  3145. for (i = 0; i < num_actuals; ++i)
  3146. free (args[i].aligned_regs);
  3147. targetm.calls.end_call_args ();
  3148. insns = get_insns ();
  3149. end_sequence ();
  3150. if (pass == 0)
  3151. {
  3152. tail_call_insns = insns;
  3153. /* Restore the pending stack adjustment now that we have
  3154. finished generating the sibling call sequence. */
  3155. restore_pending_stack_adjust (&save);
  3156. /* Prepare arg structure for next iteration. */
  3157. for (i = 0; i < num_actuals; i++)
  3158. {
  3159. args[i].value = 0;
  3160. args[i].aligned_regs = 0;
  3161. args[i].stack = 0;
  3162. }
  3163. sbitmap_free (stored_args_map);
  3164. internal_arg_pointer_exp_state.scan_start = NULL;
  3165. internal_arg_pointer_exp_state.cache.release ();
  3166. }
  3167. else
  3168. {
  3169. normal_call_insns = insns;
  3170. /* Verify that we've deallocated all the stack we used. */
  3171. gcc_assert ((flags & ECF_NORETURN)
  3172. || (old_stack_allocated
  3173. == stack_pointer_delta - pending_stack_adjust));
  3174. }
  3175. /* If something prevents making this a sibling call,
  3176. zero out the sequence. */
  3177. if (sibcall_failure)
  3178. tail_call_insns = NULL;
  3179. else
  3180. break;
  3181. }
  3182. /* If tail call production succeeded, we need to remove REG_EQUIV notes on
  3183. arguments too, as argument area is now clobbered by the call. */
  3184. if (tail_call_insns)
  3185. {
  3186. emit_insn (tail_call_insns);
  3187. crtl->tail_call_emit = true;
  3188. }
  3189. else
  3190. emit_insn (normal_call_insns);
  3191. currently_expanding_call--;
  3192. free (stack_usage_map_buf);
  3193. /* Join result with returned bounds so caller may use them if needed. */
  3194. target = chkp_join_splitted_slot (target, valbnd);
  3195. return target;
  3196. }
  3197. /* A sibling call sequence invalidates any REG_EQUIV notes made for
  3198. this function's incoming arguments.
  3199. At the start of RTL generation we know the only REG_EQUIV notes
  3200. in the rtl chain are those for incoming arguments, so we can look
  3201. for REG_EQUIV notes between the start of the function and the
  3202. NOTE_INSN_FUNCTION_BEG.
  3203. This is (slight) overkill. We could keep track of the highest
  3204. argument we clobber and be more selective in removing notes, but it
  3205. does not seem to be worth the effort. */
  3206. void
  3207. fixup_tail_calls (void)
  3208. {
  3209. rtx_insn *insn;
  3210. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  3211. {
  3212. rtx note;
  3213. /* There are never REG_EQUIV notes for the incoming arguments
  3214. after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
  3215. if (NOTE_P (insn)
  3216. && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
  3217. break;
  3218. note = find_reg_note (insn, REG_EQUIV, 0);
  3219. if (note)
  3220. remove_note (insn, note);
  3221. note = find_reg_note (insn, REG_EQUIV, 0);
  3222. gcc_assert (!note);
  3223. }
  3224. }
  3225. /* Traverse a list of TYPES and expand all complex types into their
  3226. components. */
  3227. static tree
  3228. split_complex_types (tree types)
  3229. {
  3230. tree p;
  3231. /* Before allocating memory, check for the common case of no complex. */
  3232. for (p = types; p; p = TREE_CHAIN (p))
  3233. {
  3234. tree type = TREE_VALUE (p);
  3235. if (TREE_CODE (type) == COMPLEX_TYPE
  3236. && targetm.calls.split_complex_arg (type))
  3237. goto found;
  3238. }
  3239. return types;
  3240. found:
  3241. types = copy_list (types);
  3242. for (p = types; p; p = TREE_CHAIN (p))
  3243. {
  3244. tree complex_type = TREE_VALUE (p);
  3245. if (TREE_CODE (complex_type) == COMPLEX_TYPE
  3246. && targetm.calls.split_complex_arg (complex_type))
  3247. {
  3248. tree next, imag;
  3249. /* Rewrite complex type with component type. */
  3250. TREE_VALUE (p) = TREE_TYPE (complex_type);
  3251. next = TREE_CHAIN (p);
  3252. /* Add another component type for the imaginary part. */
  3253. imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
  3254. TREE_CHAIN (p) = imag;
  3255. TREE_CHAIN (imag) = next;
  3256. /* Skip the newly created node. */
  3257. p = TREE_CHAIN (p);
  3258. }
  3259. }
  3260. return types;
  3261. }
  3262. /* Output a library call to function FUN (a SYMBOL_REF rtx).
  3263. The RETVAL parameter specifies whether return value needs to be saved, other
  3264. parameters are documented in the emit_library_call function below. */
  3265. static rtx
  3266. emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
  3267. enum libcall_type fn_type,
  3268. machine_mode outmode, int nargs, va_list p)
  3269. {
  3270. /* Total size in bytes of all the stack-parms scanned so far. */
  3271. struct args_size args_size;
  3272. /* Size of arguments before any adjustments (such as rounding). */
  3273. struct args_size original_args_size;
  3274. int argnum;
  3275. rtx fun;
  3276. /* Todo, choose the correct decl type of orgfun. Sadly this information
  3277. isn't present here, so we default to native calling abi here. */
  3278. tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
  3279. tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
  3280. int count;
  3281. rtx argblock = 0;
  3282. CUMULATIVE_ARGS args_so_far_v;
  3283. cumulative_args_t args_so_far;
  3284. struct arg
  3285. {
  3286. rtx value;
  3287. machine_mode mode;
  3288. rtx reg;
  3289. int partial;
  3290. struct locate_and_pad_arg_data locate;
  3291. rtx save_area;
  3292. };
  3293. struct arg *argvec;
  3294. int old_inhibit_defer_pop = inhibit_defer_pop;
  3295. rtx call_fusage = 0;
  3296. rtx mem_value = 0;
  3297. rtx valreg;
  3298. int pcc_struct_value = 0;
  3299. int struct_value_size = 0;
  3300. int flags;
  3301. int reg_parm_stack_space = 0;
  3302. int needed;
  3303. rtx_insn *before_call;
  3304. bool have_push_fusage;
  3305. tree tfom; /* type_for_mode (outmode, 0) */
  3306. #ifdef REG_PARM_STACK_SPACE
  3307. /* Define the boundary of the register parm stack space that needs to be
  3308. save, if any. */
  3309. int low_to_save = 0, high_to_save = 0;
  3310. rtx save_area = 0; /* Place that it is saved. */
  3311. #endif
  3312. /* Size of the stack reserved for parameter registers. */
  3313. int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
  3314. char *initial_stack_usage_map = stack_usage_map;
  3315. char *stack_usage_map_buf = NULL;
  3316. rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
  3317. #ifdef REG_PARM_STACK_SPACE
  3318. reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
  3319. #endif
  3320. /* By default, library functions can not throw. */
  3321. flags = ECF_NOTHROW;
  3322. switch (fn_type)
  3323. {
  3324. case LCT_NORMAL:
  3325. break;
  3326. case LCT_CONST:
  3327. flags |= ECF_CONST;
  3328. break;
  3329. case LCT_PURE:
  3330. flags |= ECF_PURE;
  3331. break;
  3332. case LCT_NORETURN:
  3333. flags |= ECF_NORETURN;
  3334. break;
  3335. case LCT_THROW:
  3336. flags = ECF_NORETURN;
  3337. break;
  3338. case LCT_RETURNS_TWICE:
  3339. flags = ECF_RETURNS_TWICE;
  3340. break;
  3341. }
  3342. fun = orgfun;
  3343. /* Ensure current function's preferred stack boundary is at least
  3344. what we need. */
  3345. if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
  3346. crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
  3347. /* If this kind of value comes back in memory,
  3348. decide where in memory it should come back. */
  3349. if (outmode != VOIDmode)
  3350. {
  3351. tfom = lang_hooks.types.type_for_mode (outmode, 0);
  3352. if (aggregate_value_p (tfom, 0))
  3353. {
  3354. #ifdef PCC_STATIC_STRUCT_RETURN
  3355. rtx pointer_reg
  3356. = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
  3357. mem_value = gen_rtx_MEM (outmode, pointer_reg);
  3358. pcc_struct_value = 1;
  3359. if (value == 0)
  3360. value = gen_reg_rtx (outmode);
  3361. #else /* not PCC_STATIC_STRUCT_RETURN */
  3362. struct_value_size = GET_MODE_SIZE (outmode);
  3363. if (value != 0 && MEM_P (value))
  3364. mem_value = value;
  3365. else
  3366. mem_value = assign_temp (tfom, 1, 1);
  3367. #endif
  3368. /* This call returns a big structure. */
  3369. flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
  3370. }
  3371. }
  3372. else
  3373. tfom = void_type_node;
  3374. /* ??? Unfinished: must pass the memory address as an argument. */
  3375. /* Copy all the libcall-arguments out of the varargs data
  3376. and into a vector ARGVEC.
  3377. Compute how to pass each argument. We only support a very small subset
  3378. of the full argument passing conventions to limit complexity here since
  3379. library functions shouldn't have many args. */
  3380. argvec = XALLOCAVEC (struct arg, nargs + 1);
  3381. memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
  3382. #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
  3383. INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
  3384. #else
  3385. INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
  3386. #endif
  3387. args_so_far = pack_cumulative_args (&args_so_far_v);
  3388. args_size.constant = 0;
  3389. args_size.var = 0;
  3390. count = 0;
  3391. push_temp_slots ();
  3392. /* If there's a structure value address to be passed,
  3393. either pass it in the special place, or pass it as an extra argument. */
  3394. if (mem_value && struct_value == 0 && ! pcc_struct_value)
  3395. {
  3396. rtx addr = XEXP (mem_value, 0);
  3397. nargs++;
  3398. /* Make sure it is a reasonable operand for a move or push insn. */
  3399. if (!REG_P (addr) && !MEM_P (addr)
  3400. && !(CONSTANT_P (addr)
  3401. && targetm.legitimate_constant_p (Pmode, addr)))
  3402. addr = force_operand (addr, NULL_RTX);
  3403. argvec[count].value = addr;
  3404. argvec[count].mode = Pmode;
  3405. argvec[count].partial = 0;
  3406. argvec[count].reg = targetm.calls.function_arg (args_so_far,
  3407. Pmode, NULL_TREE, true);
  3408. gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode,
  3409. NULL_TREE, 1) == 0);
  3410. locate_and_pad_parm (Pmode, NULL_TREE,
  3411. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  3412. 1,
  3413. #else
  3414. argvec[count].reg != 0,
  3415. #endif
  3416. reg_parm_stack_space, 0,
  3417. NULL_TREE, &args_size, &argvec[count].locate);
  3418. if (argvec[count].reg == 0 || argvec[count].partial != 0
  3419. || reg_parm_stack_space > 0)
  3420. args_size.constant += argvec[count].locate.size.constant;
  3421. targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true);
  3422. count++;
  3423. }
  3424. for (; count < nargs; count++)
  3425. {
  3426. rtx val = va_arg (p, rtx);
  3427. machine_mode mode = (machine_mode) va_arg (p, int);
  3428. int unsigned_p = 0;
  3429. /* We cannot convert the arg value to the mode the library wants here;
  3430. must do it earlier where we know the signedness of the arg. */
  3431. gcc_assert (mode != BLKmode
  3432. && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
  3433. /* Make sure it is a reasonable operand for a move or push insn. */
  3434. if (!REG_P (val) && !MEM_P (val)
  3435. && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val)))
  3436. val = force_operand (val, NULL_RTX);
  3437. if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1))
  3438. {
  3439. rtx slot;
  3440. int must_copy
  3441. = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1);
  3442. /* If this was a CONST function, it is now PURE since it now
  3443. reads memory. */
  3444. if (flags & ECF_CONST)
  3445. {
  3446. flags &= ~ECF_CONST;
  3447. flags |= ECF_PURE;
  3448. }
  3449. if (MEM_P (val) && !must_copy)
  3450. {
  3451. tree val_expr = MEM_EXPR (val);
  3452. if (val_expr)
  3453. mark_addressable (val_expr);
  3454. slot = val;
  3455. }
  3456. else
  3457. {
  3458. slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
  3459. 1, 1);
  3460. emit_move_insn (slot, val);
  3461. }
  3462. call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
  3463. gen_rtx_USE (VOIDmode, slot),
  3464. call_fusage);
  3465. if (must_copy)
  3466. call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
  3467. gen_rtx_CLOBBER (VOIDmode,
  3468. slot),
  3469. call_fusage);
  3470. mode = Pmode;
  3471. val = force_operand (XEXP (slot, 0), NULL_RTX);
  3472. }
  3473. mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
  3474. argvec[count].mode = mode;
  3475. argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p);
  3476. argvec[count].reg = targetm.calls.function_arg (args_so_far, mode,
  3477. NULL_TREE, true);
  3478. argvec[count].partial
  3479. = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1);
  3480. if (argvec[count].reg == 0
  3481. || argvec[count].partial != 0
  3482. || reg_parm_stack_space > 0)
  3483. {
  3484. locate_and_pad_parm (mode, NULL_TREE,
  3485. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  3486. 1,
  3487. #else
  3488. argvec[count].reg != 0,
  3489. #endif
  3490. reg_parm_stack_space, argvec[count].partial,
  3491. NULL_TREE, &args_size, &argvec[count].locate);
  3492. args_size.constant += argvec[count].locate.size.constant;
  3493. gcc_assert (!argvec[count].locate.size.var);
  3494. }
  3495. #ifdef BLOCK_REG_PADDING
  3496. else
  3497. /* The argument is passed entirely in registers. See at which
  3498. end it should be padded. */
  3499. argvec[count].locate.where_pad =
  3500. BLOCK_REG_PADDING (mode, NULL_TREE,
  3501. GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
  3502. #endif
  3503. targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
  3504. }
  3505. /* If this machine requires an external definition for library
  3506. functions, write one out. */
  3507. assemble_external_libcall (fun);
  3508. original_args_size = args_size;
  3509. args_size.constant = (((args_size.constant
  3510. + stack_pointer_delta
  3511. + STACK_BYTES - 1)
  3512. / STACK_BYTES
  3513. * STACK_BYTES)
  3514. - stack_pointer_delta);
  3515. args_size.constant = MAX (args_size.constant,
  3516. reg_parm_stack_space);
  3517. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
  3518. args_size.constant -= reg_parm_stack_space;
  3519. if (args_size.constant > crtl->outgoing_args_size)
  3520. crtl->outgoing_args_size = args_size.constant;
  3521. if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
  3522. {
  3523. int pushed = args_size.constant + pending_stack_adjust;
  3524. if (pushed > current_function_pushed_stack_size)
  3525. current_function_pushed_stack_size = pushed;
  3526. }
  3527. if (ACCUMULATE_OUTGOING_ARGS)
  3528. {
  3529. /* Since the stack pointer will never be pushed, it is possible for
  3530. the evaluation of a parm to clobber something we have already
  3531. written to the stack. Since most function calls on RISC machines
  3532. do not use the stack, this is uncommon, but must work correctly.
  3533. Therefore, we save any area of the stack that was already written
  3534. and that we are using. Here we set up to do this by making a new
  3535. stack usage map from the old one.
  3536. Another approach might be to try to reorder the argument
  3537. evaluations to avoid this conflicting stack usage. */
  3538. needed = args_size.constant;
  3539. /* Since we will be writing into the entire argument area, the
  3540. map must be allocated for its entire size, not just the part that
  3541. is the responsibility of the caller. */
  3542. if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
  3543. needed += reg_parm_stack_space;
  3544. #ifdef ARGS_GROW_DOWNWARD
  3545. highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
  3546. needed + 1);
  3547. #else
  3548. highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
  3549. needed);
  3550. #endif
  3551. stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
  3552. stack_usage_map = stack_usage_map_buf;
  3553. if (initial_highest_arg_in_use)
  3554. memcpy (stack_usage_map, initial_stack_usage_map,
  3555. initial_highest_arg_in_use);
  3556. if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
  3557. memset (&stack_usage_map[initial_highest_arg_in_use], 0,
  3558. highest_outgoing_arg_in_use - initial_highest_arg_in_use);
  3559. needed = 0;
  3560. /* We must be careful to use virtual regs before they're instantiated,
  3561. and real regs afterwards. Loop optimization, for example, can create
  3562. new libcalls after we've instantiated the virtual regs, and if we
  3563. use virtuals anyway, they won't match the rtl patterns. */
  3564. if (virtuals_instantiated)
  3565. argblock = plus_constant (Pmode, stack_pointer_rtx,
  3566. STACK_POINTER_OFFSET);
  3567. else
  3568. argblock = virtual_outgoing_args_rtx;
  3569. }
  3570. else
  3571. {
  3572. if (!PUSH_ARGS)
  3573. argblock = push_block (GEN_INT (args_size.constant), 0, 0);
  3574. }
  3575. /* We push args individually in reverse order, perform stack alignment
  3576. before the first push (the last arg). */
  3577. if (argblock == 0)
  3578. anti_adjust_stack (GEN_INT (args_size.constant
  3579. - original_args_size.constant));
  3580. argnum = nargs - 1;
  3581. #ifdef REG_PARM_STACK_SPACE
  3582. if (ACCUMULATE_OUTGOING_ARGS)
  3583. {
  3584. /* The argument list is the property of the called routine and it
  3585. may clobber it. If the fixed area has been used for previous
  3586. parameters, we must save and restore it. */
  3587. save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
  3588. &low_to_save, &high_to_save);
  3589. }
  3590. #endif
  3591. /* When expanding a normal call, args are stored in push order,
  3592. which is the reverse of what we have here. */
  3593. bool any_regs = false;
  3594. for (int i = nargs; i-- > 0; )
  3595. if (argvec[i].reg != NULL_RTX)
  3596. {
  3597. targetm.calls.call_args (argvec[i].reg, NULL_TREE);
  3598. any_regs = true;
  3599. }
  3600. if (!any_regs)
  3601. targetm.calls.call_args (pc_rtx, NULL_TREE);
  3602. /* Push the args that need to be pushed. */
  3603. have_push_fusage = false;
  3604. /* ARGNUM indexes the ARGVEC array in the order in which the arguments
  3605. are to be pushed. */
  3606. for (count = 0; count < nargs; count++, argnum--)
  3607. {
  3608. machine_mode mode = argvec[argnum].mode;
  3609. rtx val = argvec[argnum].value;
  3610. rtx reg = argvec[argnum].reg;
  3611. int partial = argvec[argnum].partial;
  3612. unsigned int parm_align = argvec[argnum].locate.boundary;
  3613. int lower_bound = 0, upper_bound = 0, i;
  3614. if (! (reg != 0 && partial == 0))
  3615. {
  3616. rtx use;
  3617. if (ACCUMULATE_OUTGOING_ARGS)
  3618. {
  3619. /* If this is being stored into a pre-allocated, fixed-size,
  3620. stack area, save any previous data at that location. */
  3621. #ifdef ARGS_GROW_DOWNWARD
  3622. /* stack_slot is negative, but we want to index stack_usage_map
  3623. with positive values. */
  3624. upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
  3625. lower_bound = upper_bound - argvec[argnum].locate.size.constant;
  3626. #else
  3627. lower_bound = argvec[argnum].locate.slot_offset.constant;
  3628. upper_bound = lower_bound + argvec[argnum].locate.size.constant;
  3629. #endif
  3630. i = lower_bound;
  3631. /* Don't worry about things in the fixed argument area;
  3632. it has already been saved. */
  3633. if (i < reg_parm_stack_space)
  3634. i = reg_parm_stack_space;
  3635. while (i < upper_bound && stack_usage_map[i] == 0)
  3636. i++;
  3637. if (i < upper_bound)
  3638. {
  3639. /* We need to make a save area. */
  3640. unsigned int size
  3641. = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
  3642. machine_mode save_mode
  3643. = mode_for_size (size, MODE_INT, 1);
  3644. rtx adr
  3645. = plus_constant (Pmode, argblock,
  3646. argvec[argnum].locate.offset.constant);
  3647. rtx stack_area
  3648. = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
  3649. if (save_mode == BLKmode)
  3650. {
  3651. argvec[argnum].save_area
  3652. = assign_stack_temp (BLKmode,
  3653. argvec[argnum].locate.size.constant
  3654. );
  3655. emit_block_move (validize_mem
  3656. (copy_rtx (argvec[argnum].save_area)),
  3657. stack_area,
  3658. GEN_INT (argvec[argnum].locate.size.constant),
  3659. BLOCK_OP_CALL_PARM);
  3660. }
  3661. else
  3662. {
  3663. argvec[argnum].save_area = gen_reg_rtx (save_mode);
  3664. emit_move_insn (argvec[argnum].save_area, stack_area);
  3665. }
  3666. }
  3667. }
  3668. emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
  3669. partial, reg, 0, argblock,
  3670. GEN_INT (argvec[argnum].locate.offset.constant),
  3671. reg_parm_stack_space,
  3672. ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
  3673. /* Now mark the segment we just used. */
  3674. if (ACCUMULATE_OUTGOING_ARGS)
  3675. for (i = lower_bound; i < upper_bound; i++)
  3676. stack_usage_map[i] = 1;
  3677. NO_DEFER_POP;
  3678. /* Indicate argument access so that alias.c knows that these
  3679. values are live. */
  3680. if (argblock)
  3681. use = plus_constant (Pmode, argblock,
  3682. argvec[argnum].locate.offset.constant);
  3683. else if (have_push_fusage)
  3684. continue;
  3685. else
  3686. {
  3687. /* When arguments are pushed, trying to tell alias.c where
  3688. exactly this argument is won't work, because the
  3689. auto-increment causes confusion. So we merely indicate
  3690. that we access something with a known mode somewhere on
  3691. the stack. */
  3692. use = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
  3693. gen_rtx_SCRATCH (Pmode));
  3694. have_push_fusage = true;
  3695. }
  3696. use = gen_rtx_MEM (argvec[argnum].mode, use);
  3697. use = gen_rtx_USE (VOIDmode, use);
  3698. call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
  3699. }
  3700. }
  3701. argnum = nargs - 1;
  3702. fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
  3703. /* Now load any reg parms into their regs. */
  3704. /* ARGNUM indexes the ARGVEC array in the order in which the arguments
  3705. are to be pushed. */
  3706. for (count = 0; count < nargs; count++, argnum--)
  3707. {
  3708. machine_mode mode = argvec[argnum].mode;
  3709. rtx val = argvec[argnum].value;
  3710. rtx reg = argvec[argnum].reg;
  3711. int partial = argvec[argnum].partial;
  3712. #ifdef BLOCK_REG_PADDING
  3713. int size = 0;
  3714. #endif
  3715. /* Handle calls that pass values in multiple non-contiguous
  3716. locations. The PA64 has examples of this for library calls. */
  3717. if (reg != 0 && GET_CODE (reg) == PARALLEL)
  3718. emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
  3719. else if (reg != 0 && partial == 0)
  3720. {
  3721. emit_move_insn (reg, val);
  3722. #ifdef BLOCK_REG_PADDING
  3723. size = GET_MODE_SIZE (argvec[argnum].mode);
  3724. /* Copied from load_register_parameters. */
  3725. /* Handle case where we have a value that needs shifting
  3726. up to the msb. eg. a QImode value and we're padding
  3727. upward on a BYTES_BIG_ENDIAN machine. */
  3728. if (size < UNITS_PER_WORD
  3729. && (argvec[argnum].locate.where_pad
  3730. == (BYTES_BIG_ENDIAN ? upward : downward)))
  3731. {
  3732. rtx x;
  3733. int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
  3734. /* Assigning REG here rather than a temp makes CALL_FUSAGE
  3735. report the whole reg as used. Strictly speaking, the
  3736. call only uses SIZE bytes at the msb end, but it doesn't
  3737. seem worth generating rtl to say that. */
  3738. reg = gen_rtx_REG (word_mode, REGNO (reg));
  3739. x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
  3740. if (x != reg)
  3741. emit_move_insn (reg, x);
  3742. }
  3743. #endif
  3744. }
  3745. NO_DEFER_POP;
  3746. }
  3747. /* Any regs containing parms remain in use through the call. */
  3748. for (count = 0; count < nargs; count++)
  3749. {
  3750. rtx reg = argvec[count].reg;
  3751. if (reg != 0 && GET_CODE (reg) == PARALLEL)
  3752. use_group_regs (&call_fusage, reg);
  3753. else if (reg != 0)
  3754. {
  3755. int partial = argvec[count].partial;
  3756. if (partial)
  3757. {
  3758. int nregs;
  3759. gcc_assert (partial % UNITS_PER_WORD == 0);
  3760. nregs = partial / UNITS_PER_WORD;
  3761. use_regs (&call_fusage, REGNO (reg), nregs);
  3762. }
  3763. else
  3764. use_reg (&call_fusage, reg);
  3765. }
  3766. }
  3767. /* Pass the function the address in which to return a structure value. */
  3768. if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
  3769. {
  3770. emit_move_insn (struct_value,
  3771. force_reg (Pmode,
  3772. force_operand (XEXP (mem_value, 0),
  3773. NULL_RTX)));
  3774. if (REG_P (struct_value))
  3775. use_reg (&call_fusage, struct_value);
  3776. }
  3777. /* Don't allow popping to be deferred, since then
  3778. cse'ing of library calls could delete a call and leave the pop. */
  3779. NO_DEFER_POP;
  3780. valreg = (mem_value == 0 && outmode != VOIDmode
  3781. ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
  3782. /* Stack must be properly aligned now. */
  3783. gcc_assert (!(stack_pointer_delta
  3784. & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
  3785. before_call = get_last_insn ();
  3786. /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
  3787. will set inhibit_defer_pop to that value. */
  3788. /* The return type is needed to decide how many bytes the function pops.
  3789. Signedness plays no role in that, so for simplicity, we pretend it's
  3790. always signed. We also assume that the list of arguments passed has
  3791. no impact, so we pretend it is unknown. */
  3792. emit_call_1 (fun, NULL,
  3793. get_identifier (XSTR (orgfun, 0)),
  3794. build_function_type (tfom, NULL_TREE),
  3795. original_args_size.constant, args_size.constant,
  3796. struct_value_size,
  3797. targetm.calls.function_arg (args_so_far,
  3798. VOIDmode, void_type_node, true),
  3799. valreg,
  3800. old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
  3801. if (flag_ipa_ra)
  3802. {
  3803. rtx last, datum = orgfun;
  3804. gcc_assert (GET_CODE (datum) == SYMBOL_REF);
  3805. last = last_call_insn ();
  3806. add_reg_note (last, REG_CALL_DECL, datum);
  3807. }
  3808. /* Right-shift returned value if necessary. */
  3809. if (!pcc_struct_value
  3810. && TYPE_MODE (tfom) != BLKmode
  3811. && targetm.calls.return_in_msb (tfom))
  3812. {
  3813. shift_return_value (TYPE_MODE (tfom), false, valreg);
  3814. valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
  3815. }
  3816. targetm.calls.end_call_args ();
  3817. /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
  3818. that it should complain if nonvolatile values are live. For
  3819. functions that cannot return, inform flow that control does not
  3820. fall through. */
  3821. if (flags & ECF_NORETURN)
  3822. {
  3823. /* The barrier note must be emitted
  3824. immediately after the CALL_INSN. Some ports emit more than
  3825. just a CALL_INSN above, so we must search for it here. */
  3826. rtx_insn *last = get_last_insn ();
  3827. while (!CALL_P (last))
  3828. {
  3829. last = PREV_INSN (last);
  3830. /* There was no CALL_INSN? */
  3831. gcc_assert (last != before_call);
  3832. }
  3833. emit_barrier_after (last);
  3834. }
  3835. /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
  3836. and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
  3837. if (flags & ECF_NOTHROW)
  3838. {
  3839. rtx_insn *last = get_last_insn ();
  3840. while (!CALL_P (last))
  3841. {
  3842. last = PREV_INSN (last);
  3843. /* There was no CALL_INSN? */
  3844. gcc_assert (last != before_call);
  3845. }
  3846. make_reg_eh_region_note_nothrow_nononlocal (last);
  3847. }
  3848. /* Now restore inhibit_defer_pop to its actual original value. */
  3849. OK_DEFER_POP;
  3850. pop_temp_slots ();
  3851. /* Copy the value to the right place. */
  3852. if (outmode != VOIDmode && retval)
  3853. {
  3854. if (mem_value)
  3855. {
  3856. if (value == 0)
  3857. value = mem_value;
  3858. if (value != mem_value)
  3859. emit_move_insn (value, mem_value);
  3860. }
  3861. else if (GET_CODE (valreg) == PARALLEL)
  3862. {
  3863. if (value == 0)
  3864. value = gen_reg_rtx (outmode);
  3865. emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
  3866. }
  3867. else
  3868. {
  3869. /* Convert to the proper mode if a promotion has been active. */
  3870. if (GET_MODE (valreg) != outmode)
  3871. {
  3872. int unsignedp = TYPE_UNSIGNED (tfom);
  3873. gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
  3874. fndecl ? TREE_TYPE (fndecl) : fntype, 1)
  3875. == GET_MODE (valreg));
  3876. valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
  3877. }
  3878. if (value != 0)
  3879. emit_move_insn (value, valreg);
  3880. else
  3881. value = valreg;
  3882. }
  3883. }
  3884. if (ACCUMULATE_OUTGOING_ARGS)
  3885. {
  3886. #ifdef REG_PARM_STACK_SPACE
  3887. if (save_area)
  3888. restore_fixed_argument_area (save_area, argblock,
  3889. high_to_save, low_to_save);
  3890. #endif
  3891. /* If we saved any argument areas, restore them. */
  3892. for (count = 0; count < nargs; count++)
  3893. if (argvec[count].save_area)
  3894. {
  3895. machine_mode save_mode = GET_MODE (argvec[count].save_area);
  3896. rtx adr = plus_constant (Pmode, argblock,
  3897. argvec[count].locate.offset.constant);
  3898. rtx stack_area = gen_rtx_MEM (save_mode,
  3899. memory_address (save_mode, adr));
  3900. if (save_mode == BLKmode)
  3901. emit_block_move (stack_area,
  3902. validize_mem
  3903. (copy_rtx (argvec[count].save_area)),
  3904. GEN_INT (argvec[count].locate.size.constant),
  3905. BLOCK_OP_CALL_PARM);
  3906. else
  3907. emit_move_insn (stack_area, argvec[count].save_area);
  3908. }
  3909. highest_outgoing_arg_in_use = initial_highest_arg_in_use;
  3910. stack_usage_map = initial_stack_usage_map;
  3911. }
  3912. free (stack_usage_map_buf);
  3913. return value;
  3914. }
  3915. /* Output a library call to function FUN (a SYMBOL_REF rtx)
  3916. (emitting the queue unless NO_QUEUE is nonzero),
  3917. for a value of mode OUTMODE,
  3918. with NARGS different arguments, passed as alternating rtx values
  3919. and machine_modes to convert them to.
  3920. FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
  3921. `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
  3922. other types of library calls. */
  3923. void
  3924. emit_library_call (rtx orgfun, enum libcall_type fn_type,
  3925. machine_mode outmode, int nargs, ...)
  3926. {
  3927. va_list p;
  3928. va_start (p, nargs);
  3929. emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
  3930. va_end (p);
  3931. }
  3932. /* Like emit_library_call except that an extra argument, VALUE,
  3933. comes second and says where to store the result.
  3934. (If VALUE is zero, this function chooses a convenient way
  3935. to return the value.
  3936. This function returns an rtx for where the value is to be found.
  3937. If VALUE is nonzero, VALUE is returned. */
  3938. rtx
  3939. emit_library_call_value (rtx orgfun, rtx value,
  3940. enum libcall_type fn_type,
  3941. machine_mode outmode, int nargs, ...)
  3942. {
  3943. rtx result;
  3944. va_list p;
  3945. va_start (p, nargs);
  3946. result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
  3947. nargs, p);
  3948. va_end (p);
  3949. return result;
  3950. }
  3951. /* Store pointer bounds argument ARG into Bounds Table entry
  3952. associated with PARM. */
  3953. static void
  3954. store_bounds (struct arg_data *arg, struct arg_data *parm)
  3955. {
  3956. rtx slot = NULL, ptr = NULL, addr = NULL;
  3957. /* We may pass bounds not associated with any pointer. */
  3958. if (!parm)
  3959. {
  3960. gcc_assert (arg->special_slot);
  3961. slot = arg->special_slot;
  3962. ptr = const0_rtx;
  3963. }
  3964. /* Find pointer associated with bounds and where it is
  3965. passed. */
  3966. else
  3967. {
  3968. if (!parm->reg)
  3969. {
  3970. gcc_assert (!arg->special_slot);
  3971. addr = adjust_address (parm->stack, Pmode, arg->pointer_offset);
  3972. }
  3973. else if (REG_P (parm->reg))
  3974. {
  3975. gcc_assert (arg->special_slot);
  3976. slot = arg->special_slot;
  3977. if (MEM_P (parm->value))
  3978. addr = adjust_address (parm->value, Pmode, arg->pointer_offset);
  3979. else if (REG_P (parm->value))
  3980. ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset);
  3981. else
  3982. {
  3983. gcc_assert (!arg->pointer_offset);
  3984. ptr = parm->value;
  3985. }
  3986. }
  3987. else
  3988. {
  3989. gcc_assert (GET_CODE (parm->reg) == PARALLEL);
  3990. gcc_assert (arg->special_slot);
  3991. slot = arg->special_slot;
  3992. if (parm->parallel_value)
  3993. ptr = chkp_get_value_with_offs (parm->parallel_value,
  3994. GEN_INT (arg->pointer_offset));
  3995. else
  3996. gcc_unreachable ();
  3997. }
  3998. }
  3999. /* Expand bounds. */
  4000. if (!arg->value)
  4001. arg->value = expand_normal (arg->tree_value);
  4002. targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot);
  4003. }
  4004. /* Store a single argument for a function call
  4005. into the register or memory area where it must be passed.
  4006. *ARG describes the argument value and where to pass it.
  4007. ARGBLOCK is the address of the stack-block for all the arguments,
  4008. or 0 on a machine where arguments are pushed individually.
  4009. MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
  4010. so must be careful about how the stack is used.
  4011. VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
  4012. argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
  4013. that we need not worry about saving and restoring the stack.
  4014. FNDECL is the declaration of the function we are calling.
  4015. Return nonzero if this arg should cause sibcall failure,
  4016. zero otherwise. */
  4017. static int
  4018. store_one_arg (struct arg_data *arg, rtx argblock, int flags,
  4019. int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
  4020. {
  4021. tree pval = arg->tree_value;
  4022. rtx reg = 0;
  4023. int partial = 0;
  4024. int used = 0;
  4025. int i, lower_bound = 0, upper_bound = 0;
  4026. int sibcall_failure = 0;
  4027. if (TREE_CODE (pval) == ERROR_MARK)
  4028. return 1;
  4029. /* Push a new temporary level for any temporaries we make for
  4030. this argument. */
  4031. push_temp_slots ();
  4032. if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
  4033. {
  4034. /* If this is being stored into a pre-allocated, fixed-size, stack area,
  4035. save any previous data at that location. */
  4036. if (argblock && ! variable_size && arg->stack)
  4037. {
  4038. #ifdef ARGS_GROW_DOWNWARD
  4039. /* stack_slot is negative, but we want to index stack_usage_map
  4040. with positive values. */
  4041. if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
  4042. upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
  4043. else
  4044. upper_bound = 0;
  4045. lower_bound = upper_bound - arg->locate.size.constant;
  4046. #else
  4047. if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
  4048. lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
  4049. else
  4050. lower_bound = 0;
  4051. upper_bound = lower_bound + arg->locate.size.constant;
  4052. #endif
  4053. i = lower_bound;
  4054. /* Don't worry about things in the fixed argument area;
  4055. it has already been saved. */
  4056. if (i < reg_parm_stack_space)
  4057. i = reg_parm_stack_space;
  4058. while (i < upper_bound && stack_usage_map[i] == 0)
  4059. i++;
  4060. if (i < upper_bound)
  4061. {
  4062. /* We need to make a save area. */
  4063. unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
  4064. machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
  4065. rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
  4066. rtx stack_area = gen_rtx_MEM (save_mode, adr);
  4067. if (save_mode == BLKmode)
  4068. {
  4069. arg->save_area
  4070. = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
  4071. preserve_temp_slots (arg->save_area);
  4072. emit_block_move (validize_mem (copy_rtx (arg->save_area)),
  4073. stack_area,
  4074. GEN_INT (arg->locate.size.constant),
  4075. BLOCK_OP_CALL_PARM);
  4076. }
  4077. else
  4078. {
  4079. arg->save_area = gen_reg_rtx (save_mode);
  4080. emit_move_insn (arg->save_area, stack_area);
  4081. }
  4082. }
  4083. }
  4084. }
  4085. /* If this isn't going to be placed on both the stack and in registers,
  4086. set up the register and number of words. */
  4087. if (! arg->pass_on_stack)
  4088. {
  4089. if (flags & ECF_SIBCALL)
  4090. reg = arg->tail_call_reg;
  4091. else
  4092. reg = arg->reg;
  4093. partial = arg->partial;
  4094. }
  4095. /* Being passed entirely in a register. We shouldn't be called in
  4096. this case. */
  4097. gcc_assert (reg == 0 || partial != 0);
  4098. /* If this arg needs special alignment, don't load the registers
  4099. here. */
  4100. if (arg->n_aligned_regs != 0)
  4101. reg = 0;
  4102. /* If this is being passed partially in a register, we can't evaluate
  4103. it directly into its stack slot. Otherwise, we can. */
  4104. if (arg->value == 0)
  4105. {
  4106. /* stack_arg_under_construction is nonzero if a function argument is
  4107. being evaluated directly into the outgoing argument list and
  4108. expand_call must take special action to preserve the argument list
  4109. if it is called recursively.
  4110. For scalar function arguments stack_usage_map is sufficient to
  4111. determine which stack slots must be saved and restored. Scalar
  4112. arguments in general have pass_on_stack == 0.
  4113. If this argument is initialized by a function which takes the
  4114. address of the argument (a C++ constructor or a C function
  4115. returning a BLKmode structure), then stack_usage_map is
  4116. insufficient and expand_call must push the stack around the
  4117. function call. Such arguments have pass_on_stack == 1.
  4118. Note that it is always safe to set stack_arg_under_construction,
  4119. but this generates suboptimal code if set when not needed. */
  4120. if (arg->pass_on_stack)
  4121. stack_arg_under_construction++;
  4122. arg->value = expand_expr (pval,
  4123. (partial
  4124. || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
  4125. ? NULL_RTX : arg->stack,
  4126. VOIDmode, EXPAND_STACK_PARM);
  4127. /* If we are promoting object (or for any other reason) the mode
  4128. doesn't agree, convert the mode. */
  4129. if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
  4130. arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
  4131. arg->value, arg->unsignedp);
  4132. if (arg->pass_on_stack)
  4133. stack_arg_under_construction--;
  4134. }
  4135. /* Check for overlap with already clobbered argument area. */
  4136. if ((flags & ECF_SIBCALL)
  4137. && MEM_P (arg->value)
  4138. && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
  4139. arg->locate.size.constant))
  4140. sibcall_failure = 1;
  4141. /* Don't allow anything left on stack from computation
  4142. of argument to alloca. */
  4143. if (flags & ECF_MAY_BE_ALLOCA)
  4144. do_pending_stack_adjust ();
  4145. if (arg->value == arg->stack)
  4146. /* If the value is already in the stack slot, we are done. */
  4147. ;
  4148. else if (arg->mode != BLKmode)
  4149. {
  4150. int size;
  4151. unsigned int parm_align;
  4152. /* Argument is a scalar, not entirely passed in registers.
  4153. (If part is passed in registers, arg->partial says how much
  4154. and emit_push_insn will take care of putting it there.)
  4155. Push it, and if its size is less than the
  4156. amount of space allocated to it,
  4157. also bump stack pointer by the additional space.
  4158. Note that in C the default argument promotions
  4159. will prevent such mismatches. */
  4160. size = GET_MODE_SIZE (arg->mode);
  4161. /* Compute how much space the push instruction will push.
  4162. On many machines, pushing a byte will advance the stack
  4163. pointer by a halfword. */
  4164. #ifdef PUSH_ROUNDING
  4165. size = PUSH_ROUNDING (size);
  4166. #endif
  4167. used = size;
  4168. /* Compute how much space the argument should get:
  4169. round up to a multiple of the alignment for arguments. */
  4170. if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
  4171. used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
  4172. / (PARM_BOUNDARY / BITS_PER_UNIT))
  4173. * (PARM_BOUNDARY / BITS_PER_UNIT));
  4174. /* Compute the alignment of the pushed argument. */
  4175. parm_align = arg->locate.boundary;
  4176. if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
  4177. {
  4178. int pad = used - size;
  4179. if (pad)
  4180. {
  4181. unsigned int pad_align = (pad & -pad) * BITS_PER_UNIT;
  4182. parm_align = MIN (parm_align, pad_align);
  4183. }
  4184. }
  4185. /* This isn't already where we want it on the stack, so put it there.
  4186. This can either be done with push or copy insns. */
  4187. emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
  4188. parm_align, partial, reg, used - size, argblock,
  4189. ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
  4190. ARGS_SIZE_RTX (arg->locate.alignment_pad));
  4191. /* Unless this is a partially-in-register argument, the argument is now
  4192. in the stack. */
  4193. if (partial == 0)
  4194. arg->value = arg->stack;
  4195. }
  4196. else
  4197. {
  4198. /* BLKmode, at least partly to be pushed. */
  4199. unsigned int parm_align;
  4200. int excess;
  4201. rtx size_rtx;
  4202. /* Pushing a nonscalar.
  4203. If part is passed in registers, PARTIAL says how much
  4204. and emit_push_insn will take care of putting it there. */
  4205. /* Round its size up to a multiple
  4206. of the allocation unit for arguments. */
  4207. if (arg->locate.size.var != 0)
  4208. {
  4209. excess = 0;
  4210. size_rtx = ARGS_SIZE_RTX (arg->locate.size);
  4211. }
  4212. else
  4213. {
  4214. /* PUSH_ROUNDING has no effect on us, because emit_push_insn
  4215. for BLKmode is careful to avoid it. */
  4216. excess = (arg->locate.size.constant
  4217. - int_size_in_bytes (TREE_TYPE (pval))
  4218. + partial);
  4219. size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
  4220. NULL_RTX, TYPE_MODE (sizetype),
  4221. EXPAND_NORMAL);
  4222. }
  4223. parm_align = arg->locate.boundary;
  4224. /* When an argument is padded down, the block is aligned to
  4225. PARM_BOUNDARY, but the actual argument isn't. */
  4226. if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
  4227. {
  4228. if (arg->locate.size.var)
  4229. parm_align = BITS_PER_UNIT;
  4230. else if (excess)
  4231. {
  4232. unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
  4233. parm_align = MIN (parm_align, excess_align);
  4234. }
  4235. }
  4236. if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
  4237. {
  4238. /* emit_push_insn might not work properly if arg->value and
  4239. argblock + arg->locate.offset areas overlap. */
  4240. rtx x = arg->value;
  4241. int i = 0;
  4242. if (XEXP (x, 0) == crtl->args.internal_arg_pointer
  4243. || (GET_CODE (XEXP (x, 0)) == PLUS
  4244. && XEXP (XEXP (x, 0), 0) ==
  4245. crtl->args.internal_arg_pointer
  4246. && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
  4247. {
  4248. if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
  4249. i = INTVAL (XEXP (XEXP (x, 0), 1));
  4250. /* expand_call should ensure this. */
  4251. gcc_assert (!arg->locate.offset.var
  4252. && arg->locate.size.var == 0
  4253. && CONST_INT_P (size_rtx));
  4254. if (arg->locate.offset.constant > i)
  4255. {
  4256. if (arg->locate.offset.constant < i + INTVAL (size_rtx))
  4257. sibcall_failure = 1;
  4258. }
  4259. else if (arg->locate.offset.constant < i)
  4260. {
  4261. /* Use arg->locate.size.constant instead of size_rtx
  4262. because we only care about the part of the argument
  4263. on the stack. */
  4264. if (i < (arg->locate.offset.constant
  4265. + arg->locate.size.constant))
  4266. sibcall_failure = 1;
  4267. }
  4268. else
  4269. {
  4270. /* Even though they appear to be at the same location,
  4271. if part of the outgoing argument is in registers,
  4272. they aren't really at the same location. Check for
  4273. this by making sure that the incoming size is the
  4274. same as the outgoing size. */
  4275. if (arg->locate.size.constant != INTVAL (size_rtx))
  4276. sibcall_failure = 1;
  4277. }
  4278. }
  4279. }
  4280. emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
  4281. parm_align, partial, reg, excess, argblock,
  4282. ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
  4283. ARGS_SIZE_RTX (arg->locate.alignment_pad));
  4284. /* Unless this is a partially-in-register argument, the argument is now
  4285. in the stack.
  4286. ??? Unlike the case above, in which we want the actual
  4287. address of the data, so that we can load it directly into a
  4288. register, here we want the address of the stack slot, so that
  4289. it's properly aligned for word-by-word copying or something
  4290. like that. It's not clear that this is always correct. */
  4291. if (partial == 0)
  4292. arg->value = arg->stack_slot;
  4293. }
  4294. if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
  4295. {
  4296. tree type = TREE_TYPE (arg->tree_value);
  4297. arg->parallel_value
  4298. = emit_group_load_into_temps (arg->reg, arg->value, type,
  4299. int_size_in_bytes (type));
  4300. }
  4301. /* Mark all slots this store used. */
  4302. if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
  4303. && argblock && ! variable_size && arg->stack)
  4304. for (i = lower_bound; i < upper_bound; i++)
  4305. stack_usage_map[i] = 1;
  4306. /* Once we have pushed something, pops can't safely
  4307. be deferred during the rest of the arguments. */
  4308. NO_DEFER_POP;
  4309. /* Free any temporary slots made in processing this argument. */
  4310. pop_temp_slots ();
  4311. return sibcall_failure;
  4312. }
  4313. /* Nonzero if we do not know how to pass TYPE solely in registers. */
  4314. bool
  4315. must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED,
  4316. const_tree type)
  4317. {
  4318. if (!type)
  4319. return false;
  4320. /* If the type has variable size... */
  4321. if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4322. return true;
  4323. /* If the type is marked as addressable (it is required
  4324. to be constructed into the stack)... */
  4325. if (TREE_ADDRESSABLE (type))
  4326. return true;
  4327. return false;
  4328. }
  4329. /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
  4330. takes trailing padding of a structure into account. */
  4331. /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
  4332. bool
  4333. must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type)
  4334. {
  4335. if (!type)
  4336. return false;
  4337. /* If the type has variable size... */
  4338. if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4339. return true;
  4340. /* If the type is marked as addressable (it is required
  4341. to be constructed into the stack)... */
  4342. if (TREE_ADDRESSABLE (type))
  4343. return true;
  4344. /* If the padding and mode of the type is such that a copy into
  4345. a register would put it into the wrong part of the register. */
  4346. if (mode == BLKmode
  4347. && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
  4348. && (FUNCTION_ARG_PADDING (mode, type)
  4349. == (BYTES_BIG_ENDIAN ? upward : downward)))
  4350. return true;
  4351. return false;
  4352. }