expr.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204
  1. /* Convert tree expression to rtl instructions, for GNU compiler.
  2. Copyright (C) 1988 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the GNU CC General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. GNU CC, but only under the conditions described in the
  12. GNU CC General Public License. A copy of this license is
  13. supposed to have been given to you along with GNU CC so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. #include "config.h"
  18. #include "rtl.h"
  19. #include "tree.h"
  20. #include "flags.h"
  21. #include "insn-flags.h"
  22. #include "insn-codes.h"
  23. #include "expr.h"
  24. #include "insn-config.h"
  25. #include "recog.h"
  26. #include "varargs.h"
  27. /* Decide whether a function's arguments should be processed
  28. from first to last or from last to first. */
  29. #ifdef STACK_GROWS_DOWNWARD
  30. #ifdef PUSH_ROUNDING
  31. #define PUSH_ARGS_REVERSED /* If it's last to first */
  32. #endif
  33. #endif
  34. /* Like STACK_BOUNDARY but in units of bytes, not bits. */
  35. #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
  36. /* If this is nonzero, we do not bother generating VOLATILE
  37. around volatile memory references, and we are willing to
  38. output indirect addresses. If cse is to follow, we reject
  39. indirect addresses so a useful potential cse is generated;
  40. if it is used only once, instruction combination will produce
  41. the same indirect address eventually. */
  42. int cse_not_expected;
  43. /* Nonzero to generate code for all the subroutines within an
  44. expression before generating the upper levels of the expression.
  45. Nowadays this is never zero. */
  46. int do_preexpand_calls = 1;
  47. /* Number of units that we should eventually pop off the stack.
  48. These are the arguments to function calls that have already returned. */
  49. int pending_stack_adjust;
  50. /* Total size of arguments already pushed for function calls that
  51. have not happened yet. Also counts 1 for each level of conditional
  52. expression that we are inside. When this is nonzero,
  53. args passed to function calls must be popped right away
  54. to ensure contiguity of argument lists for future calls. */
  55. static int current_args_size;
  56. /* Nonzero means current function may call alloca. */
  57. int may_call_alloca;
  58. rtx store_expr ();
  59. static void store_constructor ();
  60. static rtx store_field ();
  61. static rtx expand_call ();
  62. static void emit_call_1 ();
  63. static rtx prepare_call_address ();
  64. static rtx expand_builtin ();
  65. static rtx compare ();
  66. static rtx compare_constants ();
  67. static rtx compare1 ();
  68. static rtx do_store_flag ();
  69. static void preexpand_calls ();
  70. static rtx expand_increment ();
  71. static void move_by_pieces_1 ();
  72. static void init_queue ();
  73. void do_pending_stack_adjust ();
  74. /* MOVE_RATIO is the number of move instructions that is better than
  75. a block move. */
  76. #if defined (HAVE_movstrhi) || defined (HAVE_movstrsi)
  77. #define MOVE_RATIO 2
  78. #else
  79. #define MOVE_RATIO 6
  80. #endif
  81. /* Table indexed by tree code giving 1 if the code is for a
  82. comparison operation, or anything that is most easily
  83. computed with a conditional branch.
  84. We include tree.def to give it the proper length.
  85. The contents thus created are irrelevant.
  86. The real contents are initialized in init_comparisons. */
  87. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) 0,
  88. static char comparison_code[] = {
  89. #include "tree.def"
  90. };
  91. #undef DEFTREECODE
  92. /* This is run once per compilation. */
  93. void
  94. init_comparisons ()
  95. {
  96. comparison_code[(int) EQ_EXPR] = 1;
  97. comparison_code[(int) NE_EXPR] = 1;
  98. comparison_code[(int) LT_EXPR] = 1;
  99. comparison_code[(int) GT_EXPR] = 1;
  100. comparison_code[(int) LE_EXPR] = 1;
  101. comparison_code[(int) GE_EXPR] = 1;
  102. }
  103. /* This is run at the start of compiling a function. */
  104. void
  105. init_expr ()
  106. {
  107. init_queue ();
  108. may_call_alloca = 0;
  109. }
  110. /* Manage the queue of increment instructions to be output
  111. for POSTINCREMENT_EXPR expressions, etc. */
  112. static rtx pending_chain;
  113. /* Queue up to increment (or change) VAR later. BODY says how:
  114. BODY should be the same thing you would pass to emit_insn
  115. to increment right away. It will go to emit_insn later on.
  116. The value is a QUEUED expression to be used in place of VAR
  117. where you want to guarantee the pre-incrementation value of VAR. */
  118. static rtx
  119. enqueue_insn (var, body)
  120. rtx var, body;
  121. {
  122. pending_chain = gen_rtx (QUEUED, GET_MODE (var),
  123. var, 0, 0, body, pending_chain);
  124. return pending_chain;
  125. }
  126. /* Use protect_from_queue to convert a QUEUED expression
  127. into something that you can put immediately into an instruction.
  128. If the queued incrementation has not happened yet,
  129. protect_from_queue returns the variable itself.
  130. If the incrementation has happened, protect_from_queue returns a temp
  131. that contains a copy of the old value of the variable.
  132. Any time an rtx which might possibly be a QUEUED is to be put
  133. into an instruction, it must be passed through protect_from_queue first.
  134. QUEUED expressions are not meaningful in instructions.
  135. Do not pass a value through protect_from_queue and then hold
  136. on to it for a while before putting it in an instruction!
  137. If the queue is flushed in between, incorrect code will result. */
  138. rtx
  139. protect_from_queue (x, modify)
  140. register rtx x;
  141. int modify;
  142. {
  143. register RTX_CODE code = GET_CODE (x);
  144. if (code != QUEUED)
  145. {
  146. /* A special hack for read access to (MEM (QUEUED ...))
  147. to facilitate use of autoincrement.
  148. Make a copy of the contents of the memory location
  149. rather than a copy of the address. */
  150. if (code == MEM && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
  151. {
  152. register rtx y = XEXP (x, 0);
  153. XEXP (x, 0) = QUEUED_VAR (y);
  154. if (QUEUED_INSN (y))
  155. {
  156. register rtx temp = gen_reg_rtx (GET_MODE (x));
  157. emit_insn_before (gen_move_insn (temp, x),
  158. QUEUED_INSN (y));
  159. return temp;
  160. }
  161. return x;
  162. }
  163. /* Otherwise, recursively protect the subexpressions of all
  164. the kinds of rtx's that can contain a QUEUED. */
  165. if (code == MEM)
  166. XEXP (x, 0) = protect_from_queue (XEXP (x, 0), 0);
  167. else if (code == PLUS || code == MULT)
  168. {
  169. XEXP (x, 0) = protect_from_queue (XEXP (x, 0), 0);
  170. XEXP (x, 1) = protect_from_queue (XEXP (x, 1), 0);
  171. }
  172. return x;
  173. }
  174. /* If the increment has not happened, use the variable itself. */
  175. if (QUEUED_INSN (x) == 0)
  176. return QUEUED_VAR (x);
  177. /* If the increment has happened and a pre-increment copy exists,
  178. use that copy. */
  179. if (QUEUED_COPY (x) != 0)
  180. return QUEUED_COPY (x);
  181. /* The increment has happened but we haven't set up a pre-increment copy.
  182. Set one up now, and use it. */
  183. QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
  184. emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
  185. QUEUED_INSN (x));
  186. return QUEUED_COPY (x);
  187. }
  188. /* Return nonzero if X contains a QUEUED expression:
  189. if it contains anything that will be altered by a queued increment. */
  190. static int
  191. queued_subexp_p (x)
  192. rtx x;
  193. {
  194. register enum rtx_code code = GET_CODE (x);
  195. switch (code)
  196. {
  197. case QUEUED:
  198. return 1;
  199. case MEM:
  200. return queued_subexp_p (XEXP (x, 0));
  201. case MULT:
  202. case PLUS:
  203. case MINUS:
  204. return queued_subexp_p (XEXP (x, 0))
  205. || queued_subexp_p (XEXP (x, 1));
  206. }
  207. return 0;
  208. }
  209. /* Perform all the pending incrementations. */
  210. void
  211. emit_queue ()
  212. {
  213. register rtx p;
  214. while (p = pending_chain)
  215. {
  216. QUEUED_INSN (p) = emit_insn (QUEUED_BODY (p));
  217. pending_chain = QUEUED_NEXT (p);
  218. }
  219. }
  220. static void
  221. init_queue ()
  222. {
  223. if (pending_chain)
  224. abort ();
  225. }
  226. /* Copy data from FROM to TO, where the machine modes are not the same.
  227. Both modes may be integer, or both may be floating.
  228. UNSIGNEDP should be nonzero if FROM is an unsigned type.
  229. This causes zero-extension instead of sign-extension. */
  230. void
  231. convert_move (to, from, unsignedp)
  232. register rtx to, from;
  233. int unsignedp;
  234. {
  235. enum machine_mode to_mode = GET_MODE (to);
  236. enum machine_mode from_mode = GET_MODE (from);
  237. int to_real = to_mode == SFmode || to_mode == DFmode;
  238. int from_real = from_mode == SFmode || from_mode == DFmode;
  239. int extending = (int) to_mode > (int) from_mode;
  240. to = protect_from_queue (to, 1);
  241. from = protect_from_queue (from, 0);
  242. if (to_real != from_real)
  243. abort ();
  244. if (to_mode == from_mode
  245. || (from_mode == VOIDmode && CONSTANT_P (from)))
  246. {
  247. emit_move_insn (to, from);
  248. return;
  249. }
  250. if (to_real)
  251. {
  252. #ifdef HAVE_extendsfdf2
  253. if (HAVE_extendsfdf2 && extending)
  254. {
  255. emit_unop_insn (CODE_FOR_extendsfdf2, to, from, UNKNOWN);
  256. return;
  257. }
  258. #endif
  259. #ifdef HAVE_truncdfsf2
  260. if (HAVE_truncdfsf2 && ! extending)
  261. {
  262. emit_unop_insn (CODE_FOR_truncdfsf2, to, from, UNKNOWN);
  263. return;
  264. }
  265. #endif
  266. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, (extending
  267. ? "_extendsfdf2"
  268. : "_truncdfsf2")),
  269. GET_MODE (to), 1,
  270. from, (extending ? SFmode : DFmode));
  271. emit_move_insn (to, hard_libcall_value (GET_MODE (to)));
  272. return;
  273. }
  274. /* Now both modes are integers. */
  275. if (to_mode == DImode)
  276. {
  277. emit_insn (gen_rtx (CLOBBER, VOIDmode, to));
  278. if (unsignedp)
  279. {
  280. convert_move (gen_lowpart (SImode, to), from, unsignedp);
  281. emit_clr_insn (gen_highpart (SImode, to));
  282. }
  283. #ifdef HAVE_slt
  284. else if (HAVE_slt && insn_operand_mode[(int) CODE_FOR_slt][0] == SImode)
  285. {
  286. convert_move (gen_lowpart (SImode, to), from, unsignedp);
  287. emit_insn (gen_slt (gen_highpart (SImode, to)));
  288. }
  289. #endif
  290. else
  291. {
  292. register rtx label = gen_label_rtx ();
  293. emit_clr_insn (gen_highpart (SImode, to));
  294. convert_move (gen_lowpart (SImode, to), from, unsignedp);
  295. emit_cmp_insn (gen_lowpart (SImode, to),
  296. gen_rtx (CONST_INT, VOIDmode, 0),
  297. 0, 0);
  298. emit_jump_insn (gen_bge (label));
  299. expand_unop (SImode, one_cmpl_optab,
  300. gen_highpart (SImode, to), gen_highpart (SImode, to),
  301. 1);
  302. emit_label (label);
  303. }
  304. return;
  305. }
  306. if (from_mode == DImode)
  307. {
  308. convert_move (to, gen_lowpart (SImode, from), 0);
  309. return;
  310. }
  311. /* Now follow all the conversions between integers
  312. no more than a word long. */
  313. /* For truncation, usually we can just refer to FROM in a narrower mode. */
  314. if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
  315. && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
  316. GET_MODE_BITSIZE (from_mode))
  317. && ((GET_CODE (from) == MEM
  318. && ! mode_dependent_address_p (XEXP (from, 0)))
  319. || GET_CODE (from) == REG))
  320. {
  321. emit_move_insn (to, gen_lowpart (to_mode, from));
  322. return;
  323. }
  324. if (to_mode == SImode && from_mode == HImode)
  325. {
  326. if (unsignedp)
  327. {
  328. #ifdef HAVE_zero_extendhisi2
  329. if (HAVE_zero_extendhisi2)
  330. emit_unop_insn (CODE_FOR_zero_extendhisi2, to, from, ZERO_EXTEND);
  331. else
  332. #endif
  333. abort ();
  334. }
  335. else
  336. {
  337. #ifdef HAVE_extendhisi2
  338. if (HAVE_extendhisi2)
  339. emit_unop_insn (CODE_FOR_extendhisi2, to, from, SIGN_EXTEND);
  340. else
  341. #endif
  342. abort ();
  343. }
  344. return;
  345. }
  346. if (to_mode == SImode && from_mode == QImode)
  347. {
  348. if (unsignedp)
  349. {
  350. #ifdef HAVE_zero_extendqisi2
  351. if (HAVE_zero_extendqisi2)
  352. {
  353. emit_unop_insn (CODE_FOR_zero_extendqisi2, to, from, ZERO_EXTEND);
  354. return;
  355. }
  356. #endif
  357. #if defined (HAVE_zero_extendqihi2) && defined (HAVE_extendhisi2)
  358. if (HAVE_zero_extendqihi2 && HAVE_extendhisi2)
  359. {
  360. register rtx temp = gen_reg_rtx (HImode);
  361. emit_unop_insn (CODE_FOR_zero_extendqihi2, temp, from, ZERO_EXTEND);
  362. emit_unop_insn (CODE_FOR_extendhisi2, to, temp, SIGN_EXTEND);
  363. return;
  364. }
  365. #endif
  366. }
  367. else
  368. {
  369. #ifdef HAVE_extendqisi2
  370. if (HAVE_extendqisi2)
  371. {
  372. emit_unop_insn (CODE_FOR_extendqisi2, to, from, SIGN_EXTEND);
  373. return;
  374. }
  375. #endif
  376. #if defined (HAVE_extendqihi2) && defined (HAVE_extendhisi2)
  377. if (HAVE_extendqihi2 && HAVE_extendhisi2)
  378. {
  379. register rtx temp = gen_reg_rtx (HImode);
  380. emit_unop_insn (CODE_FOR_extendqihi2, temp, from, SIGN_EXTEND);
  381. emit_unop_insn (CODE_FOR_extendhisi2, to, temp, SIGN_EXTEND);
  382. return;
  383. }
  384. #endif
  385. }
  386. abort ();
  387. }
  388. if (to_mode == HImode && from_mode == QImode)
  389. {
  390. if (unsignedp)
  391. {
  392. #ifdef HAVE_zero_extendqihi2
  393. if (HAVE_zero_extendqihi2)
  394. {
  395. emit_unop_insn (CODE_FOR_zero_extendqihi2, to, from, ZERO_EXTEND);
  396. return;
  397. }
  398. #endif
  399. }
  400. else
  401. {
  402. #ifdef HAVE_extendqihi2
  403. if (HAVE_extendqihi2)
  404. {
  405. emit_unop_insn (CODE_FOR_extendqihi2, to, from, SIGN_EXTEND);
  406. return;
  407. }
  408. #endif
  409. }
  410. abort ();
  411. }
  412. /* Now we are truncating an integer to a smaller one.
  413. If the result is a temporary, we might as well just copy it,
  414. since only the low-order part of the result needs to be valid
  415. and it is valid with no change. */
  416. if (GET_CODE (to) == REG)
  417. {
  418. if (GET_CODE (from) == REG)
  419. {
  420. emit_move_insn (to, gen_lowpart (GET_MODE (to), from));
  421. return;
  422. }
  423. else if (GET_CODE (from) == SUBREG)
  424. {
  425. from = copy_rtx (from);
  426. /* This is safe since FROM is not more than one word. */
  427. PUT_MODE (from, GET_MODE (to));
  428. emit_move_insn (to, from);
  429. return;
  430. }
  431. #ifndef BYTES_BIG_ENDIAN
  432. else if (GET_CODE (from) == MEM)
  433. {
  434. register rtx addr = XEXP (from, 0);
  435. if (memory_address_p (GET_MODE (to), addr))
  436. {
  437. emit_move_insn (to, gen_rtx (MEM, GET_MODE (to), addr));
  438. return;
  439. }
  440. }
  441. #endif /* not BYTES_BIG_ENDIAN */
  442. }
  443. if (from_mode == SImode && to_mode == HImode)
  444. {
  445. #ifdef HAVE_truncsihi2
  446. if (HAVE_truncsihi2)
  447. {
  448. emit_unop_insn (CODE_FOR_truncsihi2, to, from, UNKNOWN);
  449. return;
  450. }
  451. #endif
  452. abort ();
  453. }
  454. if (from_mode == SImode && to_mode == QImode)
  455. {
  456. #ifdef HAVE_truncsiqi2
  457. if (HAVE_truncsiqi2)
  458. {
  459. emit_unop_insn (CODE_FOR_truncsiqi2, to, from, UNKNOWN);
  460. return;
  461. }
  462. #endif
  463. abort ();
  464. }
  465. if (from_mode == HImode && to_mode == QImode)
  466. {
  467. #ifdef HAVE_trunchiqi2
  468. if (HAVE_trunchiqi2)
  469. {
  470. emit_unop_insn (CODE_FOR_trunchiqi2, to, from, UNKNOWN);
  471. return;
  472. }
  473. #endif
  474. abort ();
  475. }
  476. /* Mode combination is not recognized. */
  477. abort ();
  478. }
  479. /* Return an rtx for a value that would result
  480. from converting X to mode MODE.
  481. Both X and MODE may be floating, or both integer.
  482. UNSIGNEDP is nonzero if X is an unsigned value.
  483. This can be done by referring to a part of X in place
  484. or by copying to a new temporary with conversion. */
  485. rtx
  486. convert_to_mode (mode, x, unsignedp)
  487. enum machine_mode mode;
  488. rtx x;
  489. int unsignedp;
  490. {
  491. register rtx temp;
  492. if (mode == GET_MODE (x))
  493. return x;
  494. if (integer_mode_p (mode)
  495. && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (x)))
  496. return gen_lowpart (mode, x);
  497. temp = gen_reg_rtx (mode);
  498. convert_move (temp, x, unsignedp);
  499. return temp;
  500. }
  501. int
  502. integer_mode_p (mode)
  503. enum machine_mode mode;
  504. {
  505. return (int) mode > (int) VOIDmode && (int) mode <= (int) TImode;
  506. }
  507. /* Generate several move instructions to copy LEN bytes
  508. from block FROM to block TO. (These are MEM rtx's with BLKmode).
  509. The caller must pass FROM and TO
  510. through protect_from_queue before calling.
  511. ALIGN (in bytes) is maximum alignment we can assume. */
  512. struct move_by_pieces
  513. {
  514. rtx to;
  515. rtx to_addr;
  516. int autinc_to;
  517. int explicit_inc_to;
  518. rtx from;
  519. rtx from_addr;
  520. int autinc_from;
  521. int explicit_inc_from;
  522. int len;
  523. int offset;
  524. int reverse;
  525. };
  526. static void
  527. move_by_pieces (to, from, len, align)
  528. rtx to, from;
  529. int len, align;
  530. {
  531. struct move_by_pieces data;
  532. rtx to_addr = XEXP (to, 0), from_addr = XEXP (from, 0);
  533. data.offset = 0;
  534. data.to_addr = to_addr;
  535. data.from_addr = from_addr;
  536. data.to = to;
  537. data.from = from;
  538. data.autinc_to
  539. = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
  540. || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
  541. data.autinc_from
  542. = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
  543. || GET_CODE (from_addr) == POST_INC
  544. || GET_CODE (from_addr) == POST_DEC);
  545. data.explicit_inc_from = 0;
  546. data.explicit_inc_to = 0;
  547. data.reverse
  548. = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
  549. if (data.reverse) data.offset = len;
  550. data.len = len;
  551. /* If copying requires more than two move insns,
  552. copy addresses to registers (to make displacements shorter)
  553. and use post-increment if available. */
  554. if (!(data.autinc_from && data.autinc_to)
  555. && move_by_pieces_ninsns (len, align) > 2)
  556. {
  557. #ifdef HAVE_PRE_DECREMENT
  558. if (data.reverse && ! data.autinc_from)
  559. {
  560. data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
  561. data.autinc_from = 1;
  562. data.explicit_inc_from = -1;
  563. }
  564. #endif
  565. #ifdef HAVE_POST_INCREMENT
  566. if (! data.autinc_from)
  567. {
  568. data.from_addr = copy_addr_to_reg (from_addr);
  569. data.autinc_from = 1;
  570. data.explicit_inc_from = 1;
  571. }
  572. #endif
  573. if (!data.autinc_from && CONSTANT_P (from_addr))
  574. data.from_addr = copy_addr_to_reg (from_addr);
  575. #ifdef HAVE_PRE_DECREMENT
  576. if (data.reverse && ! data.autinc_to)
  577. {
  578. data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
  579. data.autinc_to = 1;
  580. data.explicit_inc_to = -1;
  581. }
  582. #endif
  583. #ifdef HAVE_POST_INCREMENT
  584. if (! data.reverse && ! data.autinc_to)
  585. {
  586. data.to_addr = copy_addr_to_reg (to_addr);
  587. data.autinc_to = 1;
  588. data.explicit_inc_to = 1;
  589. }
  590. #endif
  591. if (!data.autinc_to && CONSTANT_P (to_addr))
  592. data.to_addr = copy_addr_to_reg (to_addr);
  593. }
  594. #ifdef STRICT_ALIGNMENT
  595. if (align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  596. align = MOVE_MAX;
  597. #else
  598. align = MOVE_MAX;
  599. #endif
  600. #ifdef HAVE_movti
  601. if (HAVE_movti && align >= GET_MODE_SIZE (TImode))
  602. move_by_pieces_1 (gen_movti, TImode, &data);
  603. #endif
  604. #ifdef HAVE_movdi
  605. if (HAVE_movdi && align >= GET_MODE_SIZE (DImode))
  606. move_by_pieces_1 (gen_movdi, DImode, &data);
  607. #endif
  608. #ifdef HAVE_movsi
  609. if (align >= GET_MODE_SIZE (SImode))
  610. move_by_pieces_1 (gen_movsi, SImode, &data);
  611. #endif
  612. #ifdef HAVE_movhi
  613. if (HAVE_movhi && align >= GET_MODE_SIZE (HImode))
  614. move_by_pieces_1 (gen_movhi, HImode, &data);
  615. #endif
  616. #ifdef HAVE_movqi
  617. move_by_pieces_1 (gen_movqi, QImode, &data);
  618. #else
  619. movqi instruction required in machine description
  620. #endif
  621. }
  622. /* Return number of insns required to move L bytes by pieces.
  623. ALIGN (in bytes) is maximum alignment we can assume. */
  624. static int
  625. move_by_pieces_ninsns (l, align)
  626. unsigned int l;
  627. int align;
  628. {
  629. register int n_insns = 0;
  630. #ifdef STRICT_ALIGNMENT
  631. if (align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  632. align = MOVE_MAX;
  633. #else
  634. align = MOVE_MAX;
  635. #endif
  636. #ifdef HAVE_movti
  637. if (HAVE_movti && align >= GET_MODE_SIZE (TImode))
  638. n_insns += l / GET_MODE_SIZE (TImode), l %= GET_MODE_SIZE (TImode);
  639. #endif
  640. #ifdef HAVE_movdi
  641. if (HAVE_movdi && align >= GET_MODE_SIZE (DImode))
  642. n_insns += l / GET_MODE_SIZE (DImode), l %= GET_MODE_SIZE (DImode);
  643. #endif
  644. #ifdef HAVE_movsi
  645. if (HAVE_movsi && align >= GET_MODE_SIZE (SImode))
  646. n_insns += l / GET_MODE_SIZE (SImode), l %= GET_MODE_SIZE (SImode);
  647. #endif
  648. #ifdef HAVE_movhi
  649. if (HAVE_movhi && align >= GET_MODE_SIZE (HImode))
  650. n_insns += l / GET_MODE_SIZE (HImode), l %= GET_MODE_SIZE (HImode);
  651. #endif
  652. n_insns += l;
  653. return n_insns;
  654. }
  655. /* Subroutine of move_by_pieces. Move as many bytes as appropriate
  656. with move instructions for mode MODE. GENFUN is the gen_... function
  657. to make a move insn for that mode. DATA has all the other info. */
  658. static void
  659. move_by_pieces_1 (genfun, mode, data)
  660. rtx (*genfun) ();
  661. enum machine_mode mode;
  662. struct move_by_pieces *data;
  663. {
  664. register int size = GET_MODE_SIZE (mode);
  665. register rtx to1, from1;
  666. #define add_offset(FLAG,X) \
  667. (FLAG ? (X) : plus_constant ((X), data->offset))
  668. while (data->len >= size)
  669. {
  670. if (data->reverse) data->offset -= size;
  671. to1 = change_address (data->to, mode,
  672. add_offset (data->autinc_to, data->to_addr));
  673. from1 = change_address (data->from, mode,
  674. add_offset (data->autinc_from, data->from_addr));
  675. #ifdef HAVE_PRE_DECREMENT
  676. if (data->explicit_inc_to < 0)
  677. emit_insn (gen_sub2_insn (data->to_addr,
  678. gen_rtx (CONST_INT, VOIDmode, size)));
  679. if (data->explicit_inc_from < 0)
  680. emit_insn (gen_sub2_insn (data->from_addr,
  681. gen_rtx (CONST_INT, VOIDmode, size)));
  682. #endif
  683. emit_insn (genfun (to1, from1));
  684. #ifdef HAVE_POST_INCREMENT
  685. if (data->explicit_inc_to > 0)
  686. emit_insn (gen_add2_insn (data->to_addr,
  687. gen_rtx (CONST_INT, VOIDmode, size)));
  688. if (data->explicit_inc_from > 0)
  689. emit_insn (gen_add2_insn (data->from_addr,
  690. gen_rtx (CONST_INT, VOIDmode, size)));
  691. #endif
  692. if (! data->reverse) data->offset += size;
  693. data->len -= size;
  694. }
  695. }
  696. /* Emit code to move a block Y to a block X.
  697. This may be done with string-move instructions,
  698. with multiple scalar move instructions, or with a library call.
  699. Both X and Y must be MEM rtx's (perhaps inside VOLATILE)
  700. with mode BLKmode.
  701. SIZE is an rtx that says how long they are.
  702. ALIGN is the maximum alignment we can assume they have,
  703. measured in bytes. */
  704. static void
  705. emit_block_move (x, y, size, align)
  706. rtx x, y;
  707. rtx size;
  708. int align;
  709. {
  710. if (GET_MODE (x) != BLKmode)
  711. abort ();
  712. if (GET_MODE (y) != BLKmode)
  713. abort ();
  714. x = protect_from_queue (x, 1);
  715. y = protect_from_queue (y, 0);
  716. if (GET_CODE (x) != MEM)
  717. abort ();
  718. if (GET_CODE (y) != MEM)
  719. abort ();
  720. if (size == 0)
  721. abort ();
  722. if (GET_CODE (size) == CONST_INT
  723. && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
  724. < MOVE_RATIO))
  725. move_by_pieces (x, y, INTVAL (size), align);
  726. else
  727. {
  728. #ifdef HAVE_movstrsi
  729. if (HAVE_movstrsi)
  730. {
  731. emit_insn (gen_movstrsi (x, y, size));
  732. return;
  733. }
  734. #endif
  735. #ifdef HAVE_movstrhi
  736. if (HAVE_movstrhi
  737. && GET_CODE (size) == CONST_INT
  738. && ((unsigned) INTVAL (size)
  739. < (1 << (GET_MODE_SIZE (HImode) * BITS_PER_UNIT - 1))))
  740. {
  741. emit_insn (gen_movstrhi (x, y, size));
  742. return;
  743. }
  744. #endif
  745. #ifdef TARGET_MEM_FUNCTIONS
  746. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"),
  747. VOIDmode, 3, XEXP (x, 0), Pmode,
  748. XEXP (y, 0), Pmode,
  749. size, Pmode);
  750. #else
  751. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"),
  752. VOIDmode, 3, XEXP (y, 0), Pmode,
  753. XEXP (x, 0), Pmode,
  754. size, Pmode);
  755. #endif
  756. }
  757. }
  758. /* Copy all or part of a BLKmode value X into registers starting at REGNO.
  759. The number of registers to be filled is NREGS. */
  760. static void
  761. move_block_to_reg (regno, x, nregs)
  762. int regno;
  763. rtx x;
  764. int nregs;
  765. {
  766. int i;
  767. if (GET_CODE (x) == CONST_DOUBLE && x != dconst0_rtx)
  768. x = force_const_double_mem (x);
  769. for (i = 0; i < nregs; i++)
  770. {
  771. if (GET_CODE (x) == REG)
  772. emit_move_insn (gen_rtx (REG, SImode, regno + i),
  773. gen_rtx (SUBREG, SImode, x, i));
  774. else if (x == dconst0_rtx)
  775. emit_move_insn (gen_rtx (REG, SImode, regno + i),
  776. const0_rtx);
  777. else
  778. emit_move_insn (gen_rtx (REG, SImode, regno + i),
  779. gen_rtx (MEM, SImode,
  780. plus_constant (XEXP (x, 0),
  781. i * GET_MODE_SIZE (SImode))));
  782. }
  783. }
  784. /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
  785. The number of registers to be filled is NREGS. */
  786. void
  787. move_block_from_reg (regno, x, nregs)
  788. int regno;
  789. rtx x;
  790. int nregs;
  791. {
  792. int i;
  793. for (i = 0; i < nregs; i++)
  794. {
  795. if (GET_CODE (x) == REG)
  796. emit_move_insn (gen_rtx (SUBREG, SImode, x, i),
  797. gen_rtx (REG, SImode, regno + i));
  798. else
  799. emit_move_insn (gen_rtx (MEM, SImode,
  800. plus_constant (XEXP (x, 0),
  801. i * GET_MODE_SIZE (SImode))),
  802. gen_rtx (REG, SImode, regno + i));
  803. }
  804. }
  805. /* Mark NREGS consecutive regs, starting at REGNO, as being live now. */
  806. static void
  807. use_regs (regno, nregs)
  808. int regno;
  809. int nregs;
  810. {
  811. int i;
  812. for (i = 0; i < nregs; i++)
  813. emit_insn (gen_rtx (USE, VOIDmode, gen_rtx (REG, SImode, regno + i)));
  814. }
  815. /* Write zeros through the storage of OBJECT.
  816. If OBJECT has BLKmode, SIZE is its length in bytes. */
  817. void
  818. clear_storage (object, size)
  819. rtx object;
  820. int size;
  821. {
  822. if (GET_MODE (object) == BLKmode)
  823. {
  824. #ifdef TARGET_MEM_FUNCTIONS
  825. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memset"),
  826. VOIDmode, 3,
  827. XEXP (object, 0), Pmode, const0_rtx, Pmode,
  828. gen_rtx (CONST_INT, VOIDmode, size), Pmode);
  829. #else
  830. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bzero"),
  831. VOIDmode, 2,
  832. XEXP (object, 0), Pmode,
  833. gen_rtx (CONST_INT, VOIDmode, size), Pmode);
  834. #endif
  835. }
  836. else
  837. emit_move_insn (object, const0_rtx, 0);
  838. }
  839. /* Generate code to copy Y into X.
  840. Both Y and X must have the same mode, except that
  841. Y can be a constant with VOIDmode.
  842. This mode cannot be BLKmode; use emit_block_move for that.
  843. Return the last instruction emitted. */
  844. rtx
  845. emit_move_insn (x, y)
  846. rtx x, y;
  847. {
  848. enum machine_mode mode = GET_MODE (x);
  849. x = protect_from_queue (x, 1);
  850. y = protect_from_queue (y, 0);
  851. if (CONSTANT_P (y) && ! LEGITIMATE_CONSTANT_P (y))
  852. y = force_const_mem (mode, y);
  853. if (mode == BLKmode)
  854. abort ();
  855. if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
  856. return
  857. emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
  858. #if 0
  859. /* It turns out you get much better optimization (in cse and flow)
  860. if you define movdi and movdf instruction patterns
  861. even if they must turn into multiple assembler instructions. */
  862. else if (GET_MODE_SIZE (mode) >= GET_MODE_SIZE (SImode))
  863. {
  864. register int count = GET_MODE_SIZE (mode) / GET_MODE_SIZE (SImode);
  865. register int i;
  866. if (GET_CODE (y) == CONST_DOUBLE && y != dconst0_rtx)
  867. y = force_const_double_mem (y);
  868. for (i = 0; i < count; i++)
  869. {
  870. rtx x1, y1;
  871. if (GET_CODE (x) == REG)
  872. x1 = gen_rtx (SUBREG, SImode, x, i);
  873. else
  874. x1 = gen_rtx (MEM, SImode,
  875. memory_address (SImode,
  876. plus_constant (XEXP (x, 0),
  877. i * GET_MODE_SIZE (SImode))));
  878. if (GET_CODE (y) == REG)
  879. y1 = gen_rtx (SUBREG, SImode, y, i);
  880. else if (y == dconst0_rtx)
  881. y1 = const0_rtx;
  882. else
  883. y1 = gen_rtx (MEM, SImode,
  884. memory_address (SImode,
  885. plus_constant (XEXP (y, 0),
  886. i * GET_MODE_SIZE (SImode))));
  887. emit_insn (gen_movsi (protect_from_queue (x1, 1), protect_from_queue (y1, 0)));
  888. }
  889. }
  890. #endif
  891. else
  892. abort ();
  893. }
  894. /* Pushing data onto the stack. */
  895. /* Push a block of length SIZE (perhaps variable)
  896. and return an rtx to address the beginning of the block.
  897. Note that it is not possible for the value returned to be a QUEUED. */
  898. static rtx
  899. push_block (size)
  900. rtx size;
  901. {
  902. register rtx temp;
  903. if (CONSTANT_P (size) || GET_CODE (size) == REG)
  904. anti_adjust_stack (size);
  905. else
  906. anti_adjust_stack (copy_to_mode_reg (Pmode, size));
  907. #ifdef STACK_GROWS_DOWNWARD
  908. temp = stack_pointer_rtx;
  909. #else
  910. temp = gen_rtx (PLUS, Pmode,
  911. stack_pointer_rtx,
  912. size);
  913. if (GET_CODE (size) != CONST_INT)
  914. temp = force_operand (temp, 0);
  915. #endif
  916. return memory_address (QImode, temp);
  917. }
  918. static rtx
  919. gen_push_operand ()
  920. {
  921. return gen_rtx (
  922. #ifdef STACK_GROWS_DOWNWARD
  923. PRE_DEC,
  924. #else
  925. PRE_INC,
  926. #endif
  927. Pmode,
  928. stack_pointer_rtx);
  929. }
  930. /* Generate code to push X onto the stack, assuming it has mode MODE.
  931. MODE is redundant except when X is a CONST_INT (since they don't
  932. carry mode info).
  933. SIZE is an rtx for the size of data to be copied (in bytes),
  934. needed only if X is BLKmode.
  935. ALIGN (in bytes) is maximum alignment we can assume.
  936. If PARTIAL is nonzero, then copy that many of the first words
  937. of X into registers starting with REG, and push the rest of X.
  938. The amount of space pushed is decreased by PARTIAL words,
  939. rounded *down* to a multiple of PARM_BOUNDARY.
  940. REG must be a hard register in this case.
  941. EXTRA is the amount in bytes of extra space to leave next to this arg.
  942. On a machine that lacks real push insns, ARGS_ADDR is the address of
  943. the bottom of the argument block for this call. We use indexing off there
  944. to store the arg. On machines with push insns, ARGS_ADDR is 0.
  945. ARGS_SO_FAR is the size of args previously pushed for this call. */
  946. static void
  947. emit_push_insn (x, mode, size, align, partial, reg, extra, args_addr, args_so_far)
  948. register rtx x;
  949. enum machine_mode mode;
  950. rtx size;
  951. int align;
  952. int partial;
  953. rtx reg;
  954. int extra;
  955. rtx args_addr;
  956. rtx args_so_far;
  957. {
  958. rtx xinner;
  959. xinner = x = protect_from_queue (x, 0);
  960. /* If part should go in registers, copy that part
  961. into the appropriate registers. */
  962. if (partial > 0)
  963. move_block_to_reg (REGNO (reg), x, partial);
  964. #ifdef STACK_GROWS_DOWNWARD
  965. if (extra && args_addr == 0)
  966. anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, extra));
  967. #endif
  968. if (mode == BLKmode)
  969. {
  970. register rtx temp;
  971. int used = partial * UNITS_PER_WORD;
  972. int offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
  973. used -= used % (PARM_BOUNDARY / BITS_PER_UNIT);
  974. if (size == 0)
  975. abort ();
  976. if (partial != 0)
  977. xinner = change_address (xinner, BLKmode,
  978. plus_constant (XEXP (xinner, 0), used));
  979. #ifdef PUSH_ROUNDING
  980. /* Do it with several push insns if that doesn't take lots of insns
  981. and if there is no difficulty with push insns that skip bytes
  982. on the stack for alignment purposes. */
  983. if (args_addr == 0
  984. && GET_CODE (size) == CONST_INT
  985. && args_addr == 0
  986. && (move_by_pieces_ninsns ((unsigned) INTVAL (size) - used, align)
  987. < MOVE_RATIO)
  988. && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
  989. move_by_pieces (gen_rtx (MEM, BLKmode, gen_push_operand ()), xinner,
  990. INTVAL (size) - used, align);
  991. else
  992. #endif /* PUSH_ROUNDING */
  993. {
  994. /* Otherwise make space on the stack and copy the data
  995. to the address of that space. */
  996. /* First deduct part put into registers from the size we need. */
  997. if (partial != 0)
  998. {
  999. if (GET_CODE (size) == CONST_INT)
  1000. size = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - used);
  1001. else
  1002. size = expand_binop (GET_MODE (size), sub_optab, size,
  1003. gen_rtx (CONST_INT, VOIDmode, used),
  1004. 0, 0, OPTAB_LIB_WIDEN);
  1005. }
  1006. /* Get the address of the stack space. */
  1007. if (! args_addr)
  1008. temp = push_block (size);
  1009. else if (GET_CODE (args_so_far) == CONST_INT)
  1010. temp = memory_address (BLKmode,
  1011. plus_constant (args_addr,
  1012. offset + INTVAL (args_so_far)));
  1013. else
  1014. temp = memory_address (BLKmode,
  1015. plus_constant (gen_rtx (PLUS, Pmode,
  1016. args_addr, args_so_far),
  1017. offset));
  1018. /* TEMP is the address of the block. Copy the data there. */
  1019. if (GET_CODE (size) == CONST_INT
  1020. && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
  1021. < MOVE_RATIO))
  1022. {
  1023. move_by_pieces (gen_rtx (MEM, BLKmode, temp), xinner,
  1024. INTVAL (size), align);
  1025. return;
  1026. }
  1027. #ifdef HAVE_movstrsi
  1028. if (HAVE_movstrsi)
  1029. {
  1030. emit_insn (gen_movstrsi (gen_rtx (MEM, BLKmode, temp), x, size));
  1031. return;
  1032. }
  1033. #endif
  1034. #ifdef HAVE_movstrhi
  1035. if (HAVE_movstrhi
  1036. && GET_CODE (size) == CONST_INT
  1037. && ((unsigned) INTVAL (size)
  1038. < (1 << (GET_MODE_SIZE (HImode) * BITS_PER_UNIT - 1))))
  1039. {
  1040. emit_insn (gen_movstrhi (gen_rtx (MEM, BLKmode, temp),
  1041. x, size));
  1042. return;
  1043. }
  1044. #endif
  1045. if (reg_mentioned_p (stack_pointer_rtx, temp))
  1046. {
  1047. /* Correct TEMP so it holds what will be a description of
  1048. the address to copy to, valid after one arg is pushed. */
  1049. #ifdef STACK_GROWS_DOWNWARD
  1050. temp = plus_constant (temp, GET_MODE_SIZE (Pmode));
  1051. #else
  1052. temp = plus_constant (temp, - GET_MODE_SIZE (Pmode));
  1053. #endif
  1054. }
  1055. /* Make current_args_size nonzero around the library call
  1056. to force it to pop the bcopy-arguments right away. */
  1057. current_args_size += 1;
  1058. #ifdef TARGET_MEM_FUNCTIONS
  1059. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"),
  1060. VOIDmode, 3, temp, Pmode, XEXP (xinner, 0), Pmode,
  1061. size, Pmode);
  1062. #else
  1063. emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"),
  1064. VOIDmode, 3, XEXP (xinner, 0), Pmode, temp, Pmode,
  1065. size, Pmode);
  1066. #endif
  1067. current_args_size -= 1;
  1068. }
  1069. }
  1070. else if (partial > 0)
  1071. {
  1072. int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
  1073. int i;
  1074. int used = partial * UNITS_PER_WORD;
  1075. /* # words of start of argument
  1076. that we must make space for but need not store. */
  1077. int skip = partial % (PARM_BOUNDARY / BITS_PER_WORD);
  1078. int args_offset = INTVAL (args_so_far);
  1079. /* If we make space by pushing it, we might as well push
  1080. the real data. Otherwise, we can leave SKIP nonzero
  1081. and leave the space uninitialized. */
  1082. if (args_addr == 0)
  1083. skip = 0;
  1084. /* Deduct all the rest of PARTIAL words from SIZE in any case.
  1085. This is space that we don't even allocate in the stack. */
  1086. used -= used % (PARM_BOUNDARY / BITS_PER_UNIT);
  1087. size -= used / UNITS_PER_WORD;
  1088. if (GET_CODE (x) == CONST_DOUBLE && x != dconst0_rtx)
  1089. x = force_const_double_mem (x);
  1090. #ifndef PUSH_ARGS_REVERSED
  1091. for (i = skip; i < size; i++)
  1092. #else
  1093. for (i = size - 1; i >= skip; i--)
  1094. #endif
  1095. if (GET_CODE (x) == MEM)
  1096. emit_push_insn (gen_rtx (MEM, SImode,
  1097. plus_constant (XEXP (x, 0),
  1098. i * UNITS_PER_WORD)),
  1099. SImode, 0, align, 0, 0, 0, args_addr,
  1100. gen_rtx (CONST_INT, VOIDmode,
  1101. args_offset + i * UNITS_PER_WORD));
  1102. else if (GET_CODE (x) == REG)
  1103. emit_push_insn (gen_rtx (SUBREG, SImode, x, i),
  1104. SImode, 0, align, 0, 0, 0, args_addr,
  1105. gen_rtx (CONST_INT, VOIDmode,
  1106. args_offset + i * UNITS_PER_WORD));
  1107. else if (x == dconst0_rtx)
  1108. emit_push_insn (const0_rtx,
  1109. SImode, 0, align, 0, 0, 0, args_addr,
  1110. gen_rtx (CONST_INT, VOIDmode,
  1111. args_offset + i * UNITS_PER_WORD));
  1112. else
  1113. abort ();
  1114. }
  1115. else
  1116. {
  1117. rtx addr;
  1118. #ifdef PUSH_ROUNDING
  1119. if (args_addr == 0)
  1120. addr = gen_push_operand ();
  1121. else
  1122. #endif
  1123. if (GET_CODE (args_so_far) == CONST_INT)
  1124. addr
  1125. = memory_address (mode,
  1126. plus_constant (args_addr, INTVAL (args_so_far)));
  1127. else
  1128. addr = memory_address (mode, gen_rtx (PLUS, Pmode, args_addr,
  1129. args_so_far));
  1130. emit_move_insn (gen_rtx (MEM, mode, addr), x);
  1131. }
  1132. #ifndef STACK_GROWS_DOWNWARD
  1133. if (extra && args_addr == 0)
  1134. anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, extra));
  1135. #endif
  1136. }
  1137. /* Output a library call to function FUN (a SYMBOL_REF rtx)
  1138. for a value of mode OUTMODE
  1139. with NARGS different arguments, passed as alternating rtx values
  1140. and machine_modes to convert them to.
  1141. The rtx values should have been passed through protect_from_queue already. */
  1142. void
  1143. emit_library_call (va_alist)
  1144. va_dcl
  1145. {
  1146. register va_list p;
  1147. register int args_size = 0;
  1148. register int argnum;
  1149. enum machine_mode outmode;
  1150. int nargs;
  1151. rtx fun;
  1152. rtx orgfun;
  1153. int inc;
  1154. int count;
  1155. rtx *regvec;
  1156. rtx argblock = 0;
  1157. CUMULATIVE_ARGS args_so_far;
  1158. struct arg { rtx value; enum machine_mode mode; };
  1159. struct arg *argvec;
  1160. int old_args_size = current_args_size;
  1161. va_start (p);
  1162. orgfun = fun = va_arg (p, rtx);
  1163. outmode = va_arg (p, enum machine_mode);
  1164. nargs = va_arg (p, int);
  1165. regvec = (rtx *) alloca (nargs * sizeof (rtx));
  1166. /* Copy all the libcall-arguments out of the varargs data
  1167. and into a vector ARGVEC. */
  1168. argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
  1169. for (count = 0; count < nargs; count++)
  1170. {
  1171. argvec[count].value = va_arg (p, rtx);
  1172. argvec[count].mode = va_arg (p, enum machine_mode);
  1173. }
  1174. va_end (p);
  1175. /* If we have no actual push instructions, make space for all the args
  1176. right now. */
  1177. #ifndef PUSH_ROUNDING
  1178. INIT_CUMULATIVE_ARGS (args_so_far, (tree)0);
  1179. for (count = 0; count < nargs; count++)
  1180. {
  1181. register enum machine_mode mode = argvec[count].mode;
  1182. register rtx reg;
  1183. register int partial;
  1184. reg = FUNCTION_ARG (args_so_far, mode, 0, 1);
  1185. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  1186. partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, 0, 1);
  1187. #else
  1188. partial = 0;
  1189. #endif
  1190. if (reg == 0 || partial != 0)
  1191. args_size += GET_MODE_SIZE (mode);
  1192. if (partial != 0)
  1193. args_size -= partial * GET_MODE_SIZE (SImode);
  1194. FUNCTION_ARG_ADVANCE (args_so_far, mode, 0, 1);
  1195. }
  1196. if (args_size != 0)
  1197. argblock
  1198. = push_block (round_push (gen_rtx (CONST_INT, VOIDmode, args_size)));
  1199. #endif
  1200. INIT_CUMULATIVE_ARGS (args_so_far, (tree)0);
  1201. #ifdef PUSH_ARGS_REVERSED
  1202. inc = -1;
  1203. argnum = nargs - 1;
  1204. #else
  1205. inc = 1;
  1206. argnum = 0;
  1207. #endif
  1208. args_size = 0;
  1209. for (count = 0; count < nargs; count++, argnum += inc)
  1210. {
  1211. register enum machine_mode mode = argvec[argnum].mode;
  1212. register rtx val = argvec[argnum].value;
  1213. rtx reg;
  1214. int partial;
  1215. int arg_size;
  1216. /* Convert the arg value to the mode the library wants. */
  1217. /* ??? It is wrong to do it here; must do it earlier
  1218. where we know the signedness of the arg. */
  1219. if (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode)
  1220. {
  1221. val = gen_reg_rtx (mode);
  1222. convert_move (val, argvec[argnum].value, 0);
  1223. }
  1224. reg = FUNCTION_ARG (args_so_far, mode, 0, 1);
  1225. regvec[argnum] = reg;
  1226. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  1227. partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, 0, 1);
  1228. #else
  1229. partial = 0;
  1230. #endif
  1231. if (reg != 0 && partial == 0)
  1232. emit_move_insn (reg, val);
  1233. else
  1234. emit_push_insn (val, mode, 0, 0, partial, reg, 0, argblock,
  1235. gen_rtx (CONST_INT, VOIDmode, args_size));
  1236. /* Compute size of stack space used by this argument. */
  1237. if (reg == 0 || partial != 0)
  1238. arg_size = GET_MODE_SIZE (mode);
  1239. else
  1240. arg_size = 0;
  1241. if (partial != 0)
  1242. arg_size
  1243. -= ((partial * UNITS_PER_WORD)
  1244. / (PARM_BOUNDARY / BITS_PER_UNIT)
  1245. * (PARM_BOUNDARY / BITS_PER_UNIT));
  1246. args_size += arg_size;
  1247. current_args_size += arg_size;
  1248. FUNCTION_ARG_ADVANCE (args_so_far, mode, 0, 1);
  1249. }
  1250. emit_queue ();
  1251. fun = prepare_call_address (fun, 0);
  1252. /* Any regs containing parms remain in use through the call.
  1253. ??? This is not quite correct, since it doesn't indicate
  1254. that they are in use immediately before the call insn.
  1255. Currently that doesn't matter since explicitly-used regs
  1256. won't be used for reloading. But if the reloader becomes smarter,
  1257. this will have to change somehow. */
  1258. for (count = 0; count < nargs; count++)
  1259. if (regvec[count] != 0)
  1260. emit_insn (gen_rtx (USE, VOIDmode, regvec[count]));
  1261. #ifdef STACK_BOUNDARY
  1262. args_size = (args_size + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES;
  1263. #endif
  1264. current_args_size += 1;
  1265. emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size,
  1266. FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
  1267. outmode != VOIDmode ? hard_libcall_value (outmode) : 0,
  1268. old_args_size);
  1269. }
  1270. /* Expand an assignment that stores the value of FROM into TO.
  1271. If WANT_VALUE is nonzero, return an rtx for the value of TO.
  1272. (This may contain a QUEUED rtx.)
  1273. Otherwise, the returned value is not meaningful.
  1274. SUGGEST_REG is no longer actually used.
  1275. It used to mean, copy the value through a register
  1276. and return that register, if that is possible.
  1277. But now we do this if WANT_VALUE.
  1278. If the value stored is a constant, we return the constant. */
  1279. rtx
  1280. expand_assignment (to, from, want_value, suggest_reg)
  1281. tree to, from;
  1282. int want_value;
  1283. int suggest_reg;
  1284. {
  1285. register rtx to_rtx = 0;
  1286. /* Don't crash if the lhs of the assignment was erroneous. */
  1287. if (TREE_CODE (to) == ERROR_MARK)
  1288. return expand_expr (from, 0, VOIDmode, 0);
  1289. /* Assignment of a structure component needs special treatment
  1290. if the structure component's rtx is not simply a MEM.
  1291. Assignment of an array element at a constant index
  1292. has the same problem. */
  1293. if (TREE_CODE (to) == COMPONENT_REF
  1294. || (TREE_CODE (to) == ARRAY_REF
  1295. && TREE_CODE (TREE_OPERAND (to, 1)) == INTEGER_CST
  1296. && TREE_CODE (TYPE_SIZE (TREE_TYPE (to))) == INTEGER_CST))
  1297. {
  1298. register enum machine_mode mode1;
  1299. int bitsize;
  1300. int volstruct = 0;
  1301. tree tem = to;
  1302. int bitpos = 0;
  1303. int unsignedp;
  1304. if (TREE_CODE (to) == COMPONENT_REF)
  1305. {
  1306. tree field = TREE_OPERAND (to, 1);
  1307. bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
  1308. mode1 = DECL_MODE (TREE_OPERAND (to, 1));
  1309. unsignedp = TREE_UNSIGNED (field);
  1310. }
  1311. else
  1312. {
  1313. mode1 = TYPE_MODE (TREE_TYPE (to));
  1314. bitsize = GET_MODE_BITSIZE (mode1);
  1315. unsignedp = TREE_UNSIGNED (TREE_TYPE (to));
  1316. }
  1317. /* Compute cumulative bit-offset for nested component-refs
  1318. and array-refs, and find the ultimate containing object. */
  1319. while (1)
  1320. {
  1321. if (TREE_CODE (tem) == COMPONENT_REF)
  1322. {
  1323. bitpos += DECL_OFFSET (TREE_OPERAND (tem, 1));
  1324. if (TREE_THIS_VOLATILE (tem))
  1325. volstruct = 1;
  1326. }
  1327. else if (TREE_CODE (tem) == ARRAY_REF
  1328. && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
  1329. && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) == INTEGER_CST)
  1330. {
  1331. bitpos += (TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))
  1332. * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)))
  1333. * TYPE_SIZE_UNIT (TREE_TYPE (tem)));
  1334. }
  1335. else
  1336. break;
  1337. tem = TREE_OPERAND (tem, 0);
  1338. }
  1339. /* If we are going to use store_bit_field and extract_bit_field,
  1340. make sure to_rtx will be safe for multiple use. */
  1341. if (mode1 == BImode && want_value)
  1342. tem = stabilize_reference (tem);
  1343. to_rtx = expand_expr (tem, 0, VOIDmode, 0);
  1344. return store_field (to_rtx, bitsize, bitpos, mode1, from,
  1345. want_value ? TYPE_MODE (TREE_TYPE (to)) : VOIDmode,
  1346. unsignedp);
  1347. }
  1348. /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
  1349. Don't re-expand if it was expanded already (in COMPONENT_REF case). */
  1350. if (to_rtx == 0)
  1351. to_rtx = expand_expr (to, 0, VOIDmode, 0);
  1352. /* Compute FROM and store the value in the rtx we got. */
  1353. return store_expr (from, to_rtx, want_value);
  1354. }
  1355. /* Generate code for computing expression EXP,
  1356. and storing the value into TARGET.
  1357. Returns TARGET or an equivalent value.
  1358. TARGET may contain a QUEUED rtx.
  1359. If SUGGEST_REG is nonzero, copy the value through a register
  1360. and return that register, if that is possible.
  1361. If the value stored is a constant, we return the constant. */
  1362. rtx
  1363. store_expr (exp, target, suggest_reg)
  1364. register tree exp;
  1365. register rtx target;
  1366. int suggest_reg;
  1367. {
  1368. register rtx temp;
  1369. int dont_return_target = 0;
  1370. /* Copying a non-constant CONSTRUCTOR needs special treatment. */
  1371. if (TREE_CODE (exp) == CONSTRUCTOR && ! TREE_LITERAL (exp))
  1372. {
  1373. store_constructor (exp, target);
  1374. return target;
  1375. }
  1376. if (suggest_reg && GET_CODE (target) == MEM && GET_MODE (target) != BLKmode)
  1377. /* If target is in memory and caller wants value in a register instead,
  1378. arrange that. Pass TARGET as target for expand_expr so that,
  1379. if EXP is another assignment, SUGGEST_REG will be nonzero for it.
  1380. We know expand_expr will not use the target in that case. */
  1381. {
  1382. temp = expand_expr (exp, cse_not_expected ? 0 : target,
  1383. GET_MODE (target), 0);
  1384. if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
  1385. temp = copy_to_reg (temp);
  1386. dont_return_target = 1;
  1387. }
  1388. else if (queued_subexp_p (target))
  1389. /* If target contains a postincrement, it is not safe
  1390. to use as the returned value. It would access the wrong
  1391. place by the time the queued increment gets output.
  1392. So copy the value through a temporary and use that temp
  1393. as the result. */
  1394. {
  1395. temp = expand_expr (exp, 0, GET_MODE (target), 0);
  1396. if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
  1397. temp = copy_to_reg (temp);
  1398. dont_return_target = 1;
  1399. }
  1400. else
  1401. {
  1402. temp = expand_expr (exp, target, GET_MODE (target), 0);
  1403. /* DO return TARGET if it's a specified hardware register.
  1404. expand_return relies on this. */
  1405. if (!(target && GET_CODE (target) == REG
  1406. && REGNO (target) < FIRST_PSEUDO_REGISTER)
  1407. && (CONSTANT_P (temp) || GET_CODE (temp) == CONST_DOUBLE))
  1408. dont_return_target = 1;
  1409. }
  1410. /* If value was not generated in the target, store it there. */
  1411. if (temp != target && TREE_CODE (exp) != ERROR_MARK)
  1412. {
  1413. target = protect_from_queue (target, 1);
  1414. if (GET_MODE (temp) != GET_MODE (target)
  1415. && GET_MODE (temp) != VOIDmode)
  1416. {
  1417. int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
  1418. if (dont_return_target)
  1419. temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
  1420. else
  1421. convert_move (target, temp, unsignedp);
  1422. }
  1423. else if (GET_MODE (temp) == BLKmode)
  1424. emit_block_move (target, temp, expr_size (exp),
  1425. TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
  1426. else
  1427. emit_move_insn (target, temp);
  1428. }
  1429. if (dont_return_target)
  1430. return temp;
  1431. return target;
  1432. }
  1433. /* Store the value of constructor EXP into the rtx TARGET.
  1434. TARGET is either a REG or a MEM. */
  1435. static void
  1436. store_constructor (exp, target)
  1437. tree exp;
  1438. rtx target;
  1439. {
  1440. if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1441. {
  1442. register tree elt;
  1443. /* If the constructor has fewer fields than the structure,
  1444. clear the whole structure first. */
  1445. if (list_length (CONSTRUCTOR_ELTS (exp))
  1446. != list_length (TYPE_FIELDS (TREE_TYPE (exp))))
  1447. clear_storage (target, int_size_in_bytes (TREE_TYPE (exp)));
  1448. else
  1449. /* Inform later passes that the old value is dead. */
  1450. emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
  1451. /* Store each element of the constructor into
  1452. the corresponding field of TARGET. */
  1453. for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
  1454. {
  1455. register tree field = TREE_PURPOSE (elt);
  1456. register enum machine_mode mode;
  1457. int bitsize;
  1458. int bitpos;
  1459. int unsignedp;
  1460. bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
  1461. mode = DECL_MODE (field);
  1462. unsignedp = TREE_UNSIGNED (field);
  1463. bitpos = DECL_OFFSET (field);
  1464. store_field (target, bitsize, bitpos, mode, TREE_VALUE (elt),
  1465. VOIDmode, 0);
  1466. }
  1467. }
  1468. else if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
  1469. {
  1470. register tree elt;
  1471. register int i;
  1472. tree domain = TYPE_DOMAIN (TREE_TYPE (exp));
  1473. int minelt = TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain));
  1474. int maxelt = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain));
  1475. tree elttype = TREE_TYPE (TREE_TYPE (exp));
  1476. /* If the constructor has fewer fields than the structure,
  1477. clear the whole structure first. */
  1478. if (list_length (CONSTRUCTOR_ELTS (exp)) < maxelt - minelt + 1)
  1479. clear_storage (target, maxelt - minelt + 1);
  1480. else
  1481. /* Inform later passes that the old value is dead. */
  1482. emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
  1483. /* Store each element of the constructor into
  1484. the corresponding element of TARGET, determined
  1485. by counting the elements. */
  1486. for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
  1487. elt;
  1488. elt = TREE_CHAIN (elt), i++)
  1489. {
  1490. register enum machine_mode mode;
  1491. int bitsize;
  1492. int bitpos;
  1493. int unsignedp;
  1494. mode = TYPE_MODE (elttype);
  1495. bitsize = GET_MODE_BITSIZE (mode);
  1496. unsignedp = TREE_UNSIGNED (elttype);
  1497. bitpos = (i * TREE_INT_CST_LOW (TYPE_SIZE (elttype))
  1498. * TYPE_SIZE_UNIT (elttype));
  1499. store_field (target, bitsize, bitpos, mode, TREE_VALUE (elt),
  1500. VOIDmode, 0);
  1501. }
  1502. }
  1503. }
  1504. /* Store the value of EXP (an expression tree)
  1505. into a subfield of TARGET which has mode MODE and occupies
  1506. BITSIZE bits, starting BITPOS bits from the start of TARGET.
  1507. If VALUE_MODE is VOIDmode, return nothing in particular.
  1508. UNSIGNEDP is not used in this case.
  1509. Otherwise, return an rtx for the value stored. This rtx
  1510. has mode VALUE_MODE if that is convenient to do.
  1511. In this case, UNSIGNEDP must be nonzero if the value is an unsigned type. */
  1512. static rtx
  1513. store_field (target, bitsize, bitpos, mode, exp, value_mode, unsignedp)
  1514. rtx target;
  1515. int bitsize, bitpos;
  1516. enum machine_mode mode;
  1517. tree exp;
  1518. enum machine_mode value_mode;
  1519. int unsignedp;
  1520. {
  1521. /* If the structure is in a register or if the component
  1522. is a bit field, we cannot use addressing to access it.
  1523. Use bit-field techniques or SUBREG to store in it. */
  1524. if (mode == BImode || GET_CODE (target) == REG
  1525. || GET_CODE (target) == SUBREG)
  1526. {
  1527. store_bit_field (target, bitsize, bitpos,
  1528. mode,
  1529. expand_expr (exp, 0, VOIDmode, 0));
  1530. if (value_mode != VOIDmode)
  1531. return extract_bit_field (target, bitsize, bitpos, unsignedp,
  1532. 0, value_mode, 0);
  1533. return const0_rtx;
  1534. }
  1535. else
  1536. {
  1537. rtx addr = XEXP (target, 0);
  1538. rtx to_rtx;
  1539. /* If a value is wanted, it must be the lhs;
  1540. so make the address stable for multiple use. */
  1541. if (value_mode != VOIDmode && GET_CODE (addr) != REG
  1542. && ! CONSTANT_ADDRESS_P (addr))
  1543. addr = copy_to_reg (addr);
  1544. /* Now build a reference to just the desired component. */
  1545. to_rtx = change_address (target, mode,
  1546. plus_constant (addr,
  1547. (bitpos / BITS_PER_UNIT)));
  1548. to_rtx->in_struct = 1;
  1549. return store_expr (exp, to_rtx, value_mode != VOIDmode);
  1550. }
  1551. }
  1552. /* Given an rtx VALUE that may contain additions and multiplications,
  1553. return an equivalent value that just refers to a register or memory.
  1554. This is done by generating instructions to perform the arithmetic
  1555. and returning a pseudo-register containing the value. */
  1556. rtx
  1557. force_operand (value, target)
  1558. rtx value, target;
  1559. {
  1560. register optab binoptab = 0;
  1561. register rtx op2;
  1562. /* Use subtarget as the target for operand 0 of a binary operation. */
  1563. register rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
  1564. if (GET_CODE (value) == PLUS)
  1565. binoptab = add_optab;
  1566. else if (GET_CODE (value) == MINUS)
  1567. binoptab = sub_optab;
  1568. else if (GET_CODE (value) == MULT)
  1569. {
  1570. op2 = XEXP (value, 1);
  1571. if (!CONSTANT_P (op2)
  1572. && !(GET_CODE (op2) == REG && op2 != subtarget))
  1573. subtarget = 0;
  1574. return expand_mult (GET_MODE (value),
  1575. force_operand (XEXP (value, 0), subtarget),
  1576. force_operand (op2, 0),
  1577. target, 0);
  1578. }
  1579. if (binoptab)
  1580. {
  1581. op2 = XEXP (value, 1);
  1582. if (!CONSTANT_P (op2)
  1583. && !(GET_CODE (op2) == REG && op2 != subtarget))
  1584. subtarget = 0;
  1585. if (binoptab == sub_optab
  1586. && GET_CODE (op2) == CONST_INT && INTVAL (op2) < 0)
  1587. {
  1588. binoptab = add_optab;
  1589. op2 = gen_rtx (CONST_INT, VOIDmode, - INTVAL (op2));
  1590. }
  1591. return expand_binop (GET_MODE (value), binoptab,
  1592. force_operand (XEXP (value, 0), subtarget),
  1593. force_operand (op2, 0),
  1594. target, 0, OPTAB_LIB_WIDEN);
  1595. /* We give UNSIGNEP = 0 to expand_binop
  1596. because the only operations we are expanding here are signed ones. */
  1597. }
  1598. return value;
  1599. }
  1600. /* expand_expr: generate code for computing expression EXP.
  1601. An rtx for the computed value is returned.
  1602. The value may be stored in TARGET if TARGET is nonzero.
  1603. TARGET is just a suggestion; callers must assume that
  1604. the rtx returned may not be the same as TARGET.
  1605. If TARGET is CONST0_RTX, it means that the value will be ignored.
  1606. If TMODE is not VOIDmode, it suggests generating the
  1607. result in mode TMODE. But this is done only when convenient.
  1608. Otherwise, TMODE is ignored and the value generated in its natural mode.
  1609. TMODE is just a suggestion; callers must assume that
  1610. the rtx returned may not have mode TMODE.
  1611. If MODIFIER is EXPAND_SUM then when EXP is an addition
  1612. we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
  1613. or a nest of (PLUS ...) and (MINUS ...) where the terms are
  1614. products as above, or REG or MEM, or constant.
  1615. Ordinarily in such cases we would output mul or add instructions
  1616. and then return a pseudo reg containing the sum.
  1617. If MODIFIER is EXPAND_CONST_ADDRESS then it is ok to return
  1618. a MEM rtx whose address is a constant that isn't a legitimate address. */
  1619. /* Subroutine of expand_expr:
  1620. return the target to use when recursively expanding
  1621. the first operand of an arithmetic operation. */
  1622. static rtx
  1623. validate_subtarget (subtarget, otherop)
  1624. rtx subtarget;
  1625. tree otherop;
  1626. {
  1627. if (TREE_LITERAL (otherop))
  1628. return subtarget;
  1629. if (TREE_CODE (otherop) == VAR_DECL
  1630. && DECL_RTL (otherop) != subtarget)
  1631. return subtarget;
  1632. return 0;
  1633. }
  1634. rtx
  1635. expand_expr (exp, target, tmode, modifier)
  1636. register tree exp;
  1637. rtx target;
  1638. enum machine_mode tmode;
  1639. enum expand_modifier modifier;
  1640. {
  1641. register rtx op0, op1, temp;
  1642. tree type = TREE_TYPE (exp);
  1643. register enum machine_mode mode = TYPE_MODE (type);
  1644. register enum tree_code code = TREE_CODE (exp);
  1645. optab this_optab;
  1646. int negate_1;
  1647. /* Use subtarget as the target for operand 0 of a binary operation. */
  1648. rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
  1649. rtx original_target = target;
  1650. int ignore = target == const0_rtx;
  1651. if (ignore) target = 0, original_target = 0;
  1652. /* If will do cse, generate all results into registers
  1653. since 1) that allows cse to find more things
  1654. and 2) otherwise cse could produce an insn the machine
  1655. cannot support. */
  1656. if (! cse_not_expected && mode != BLKmode)
  1657. target = subtarget;
  1658. /* No sense saving up arithmetic to be done
  1659. if it's all in the wrong mode to form part of an address.
  1660. And force_operand won't know whether to sign-extend or zero-extend. */
  1661. if (mode != Pmode && modifier == EXPAND_SUM)
  1662. modifier = (enum expand_modifier) 0;
  1663. switch (code)
  1664. {
  1665. case FUNCTION_DECL:
  1666. case VAR_DECL:
  1667. case PARM_DECL:
  1668. case RESULT_DECL:
  1669. if (DECL_RTL (exp) == 0)
  1670. abort ();
  1671. if (GET_CODE (DECL_RTL (exp)) == SYMBOL_REF)
  1672. abort ();
  1673. if (GET_CODE (DECL_RTL (exp)) == MEM
  1674. && modifier != EXPAND_CONST_ADDRESS)
  1675. {
  1676. /* DECL_RTL probably contains a constant address.
  1677. On RISC machines where a constant address isn't valid,
  1678. make some insns to get that address into a register. */
  1679. if (!memory_address_p (DECL_MODE (exp), XEXP (DECL_RTL (exp), 0)))
  1680. return change_address (DECL_RTL (exp), VOIDmode,
  1681. copy_rtx (XEXP (DECL_RTL (exp), 0)));
  1682. }
  1683. return DECL_RTL (exp);
  1684. case INTEGER_CST:
  1685. return gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (exp));
  1686. case CONST_DECL:
  1687. return expand_expr (DECL_INITIAL (exp), target, VOIDmode, 0);
  1688. case REAL_CST:
  1689. if (TREE_CST_RTL (exp))
  1690. return TREE_CST_RTL (exp);
  1691. /* If optimized, generate immediate float
  1692. which will be turned into memory float if necessary. */
  1693. if (!cse_not_expected)
  1694. return immed_real_const (exp);
  1695. output_constant_def (exp);
  1696. return TREE_CST_RTL (exp);
  1697. case COMPLEX_CST:
  1698. case STRING_CST:
  1699. if (TREE_CST_RTL (exp))
  1700. return TREE_CST_RTL (exp);
  1701. output_constant_def (exp);
  1702. return TREE_CST_RTL (exp);
  1703. case SAVE_EXPR:
  1704. if (SAVE_EXPR_RTL (exp) == 0)
  1705. {
  1706. SAVE_EXPR_RTL (exp) = gen_reg_rtx (mode);
  1707. store_expr (TREE_OPERAND (exp, 0), SAVE_EXPR_RTL (exp), 0);
  1708. }
  1709. /* Don't let the same rtl node appear in two places. */
  1710. return SAVE_EXPR_RTL (exp);
  1711. case RTL_EXPR:
  1712. emit_insn (RTL_EXPR_SEQUENCE (exp));
  1713. return RTL_EXPR_RTL (exp);
  1714. case CONSTRUCTOR:
  1715. /* All elts simple constants => refer to a constant in memory. */
  1716. if (TREE_STATIC (exp))
  1717. /* For aggregate types with non-BLKmode modes,
  1718. this should ideally construct a CONST_INT. */
  1719. return output_constant_def (exp);
  1720. if (ignore)
  1721. {
  1722. tree elt;
  1723. for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
  1724. expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
  1725. return const0_rtx;
  1726. }
  1727. else
  1728. {
  1729. if (target == 0)
  1730. target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
  1731. get_structure_value_addr (expr_size (exp)));
  1732. store_expr (exp, target, 0);
  1733. return target;
  1734. }
  1735. case INDIRECT_REF:
  1736. {
  1737. tree exp1 = TREE_OPERAND (exp, 0);
  1738. tree exp2;
  1739. /* A SAVE_EXPR as the address in an INDIRECT_EXPR is generated
  1740. for *PTR += ANYTHING where PTR is put inside the SAVE_EXPR.
  1741. This code has the same general effect as simply doing
  1742. expand_expr on the save expr, except that the expression PTR
  1743. is computed for use as a memory address. This means different
  1744. code, suitable for indexing, may be generated. */
  1745. if (TREE_CODE (exp1) == SAVE_EXPR
  1746. && SAVE_EXPR_RTL (exp1) == 0
  1747. && TREE_CODE (exp2 = TREE_OPERAND (exp1, 0)) != ERROR_MARK
  1748. && TYPE_MODE (TREE_TYPE (exp1)) == Pmode
  1749. && TYPE_MODE (TREE_TYPE (exp2)) == Pmode)
  1750. {
  1751. temp = expand_expr (TREE_OPERAND (exp1, 0), 0, VOIDmode, EXPAND_SUM);
  1752. op0 = memory_address (mode, temp);
  1753. op0 = copy_all_regs (op0);
  1754. SAVE_EXPR_RTL (exp1) = op0;
  1755. }
  1756. else
  1757. {
  1758. op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, EXPAND_SUM);
  1759. op0 = memory_address (mode, op0);
  1760. }
  1761. }
  1762. temp = gen_rtx (MEM, mode, op0);
  1763. /* If address was computed by addition,
  1764. mark this as an element of an aggregate. */
  1765. if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
  1766. || (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR
  1767. && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == PLUS_EXPR))
  1768. temp->in_struct = 1;
  1769. temp->volatil = TREE_THIS_VOLATILE (exp) | flag_volatile;
  1770. temp->unchanging = TREE_READONLY (exp);
  1771. return temp;
  1772. case ARRAY_REF:
  1773. if (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST
  1774. || TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST)
  1775. {
  1776. /* Nonconstant array index or nonconstant element size.
  1777. Generate the tree for *(&array+index) and expand that,
  1778. except do it in a language-independent way
  1779. and don't complain about non-lvalue arrays.
  1780. `mark_addressable' should already have been called
  1781. for any array for which this case will be reached. */
  1782. tree array_adr = build (ADDR_EXPR, TYPE_POINTER_TO (type),
  1783. TREE_OPERAND (exp, 0));
  1784. tree index = TREE_OPERAND (exp, 1);
  1785. tree elt;
  1786. /* Convert the integer argument to a type the same size as a pointer
  1787. so the multiply won't overflow spuriously. */
  1788. if (TYPE_PRECISION (TREE_TYPE (index)) != POINTER_SIZE)
  1789. index = convert (type_for_size (POINTER_SIZE, 0), index);
  1790. /* The array address isn't volatile even if the array is. */
  1791. TREE_VOLATILE (array_adr) = 0;
  1792. elt = build (INDIRECT_REF, type,
  1793. fold (build (PLUS_EXPR, TYPE_POINTER_TO (type),
  1794. array_adr,
  1795. fold (build (MULT_EXPR,
  1796. TYPE_POINTER_TO (type),
  1797. index, size_in_bytes (type))))));
  1798. return expand_expr (elt, target, tmode, modifier);
  1799. }
  1800. /* Treat array-ref with constant index as a component-ref. */
  1801. case COMPONENT_REF:
  1802. {
  1803. register enum machine_mode mode1;
  1804. int volstruct = 0;
  1805. tree dbg1 = TREE_OPERAND (exp, 0); /* For debugging */
  1806. int bitsize;
  1807. tree tem = exp;
  1808. int bitpos = 0;
  1809. int unsignedp;
  1810. if (TREE_CODE (exp) == COMPONENT_REF)
  1811. {
  1812. tree field = TREE_OPERAND (exp, 1);
  1813. bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
  1814. mode1 = DECL_MODE (TREE_OPERAND (exp, 1));
  1815. unsignedp = TREE_UNSIGNED (field);
  1816. }
  1817. else
  1818. {
  1819. mode1 = TYPE_MODE (TREE_TYPE (exp));
  1820. bitsize = GET_MODE_BITSIZE (mode1);
  1821. unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
  1822. }
  1823. /* Compute cumulative bit-offset for nested component-refs
  1824. and array-refs, and find the ultimate containing object. */
  1825. while (1)
  1826. {
  1827. if (TREE_CODE (tem) == COMPONENT_REF)
  1828. {
  1829. bitpos += DECL_OFFSET (TREE_OPERAND (tem, 1));
  1830. if (TREE_THIS_VOLATILE (tem))
  1831. volstruct = 1;
  1832. }
  1833. else if (TREE_CODE (tem) == ARRAY_REF
  1834. && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
  1835. && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) == INTEGER_CST)
  1836. {
  1837. bitpos += (TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))
  1838. * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)))
  1839. * TYPE_SIZE_UNIT (TREE_TYPE (tem)));
  1840. }
  1841. else
  1842. break;
  1843. tem = TREE_OPERAND (tem, 0);
  1844. }
  1845. op0 = expand_expr (tem, 0, VOIDmode,
  1846. (modifier == EXPAND_CONST_ADDRESS
  1847. ? modifier : EXPAND_NORMAL));
  1848. if (mode1 == BImode || GET_CODE (op0) == REG
  1849. || GET_CODE (op0) == SUBREG)
  1850. {
  1851. return extract_bit_field (op0, bitsize, bitpos, unsignedp,
  1852. target, mode, tmode);
  1853. }
  1854. /* Get a reference to just this component. */
  1855. if (modifier == EXPAND_CONST_ADDRESS)
  1856. op0 = gen_rtx (MEM, mode1, plus_constant (XEXP (op0, 0),
  1857. (bitpos / BITS_PER_UNIT)));
  1858. else
  1859. op0 = change_address (op0, mode1,
  1860. plus_constant (XEXP (op0, 0),
  1861. (bitpos / BITS_PER_UNIT)));
  1862. op0->in_struct = 1;
  1863. op0->volatil = volstruct;
  1864. /* If OP0 is in the shared structure-value stack slot,
  1865. and it is not BLKmode, copy it into a register.
  1866. The shared slot may be clobbered at any time by another call.
  1867. BLKmode is safe because our caller will either copy the value away
  1868. or take another component and come back here. */
  1869. if (mode != BLKmode
  1870. && TREE_CODE (TREE_OPERAND (exp, 0)) == CALL_EXPR
  1871. && TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == BLKmode)
  1872. op0 = copy_to_reg (op0);
  1873. if (mode == mode1 || mode1 == BLKmode || mode1 == tmode)
  1874. return op0;
  1875. if (target == 0)
  1876. target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
  1877. convert_move (target, op0, unsignedp);
  1878. return target;
  1879. }
  1880. /* Intended for a reference to a buffer of a file-object in Pascal.
  1881. But it's not certain that a special tree code will really be
  1882. necessary for these. INDIRECT_REF might work for them. */
  1883. case BUFFER_REF:
  1884. abort ();
  1885. case CALL_EXPR:
  1886. /* Check for a built-in function. */
  1887. if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
  1888. && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == FUNCTION_DECL
  1889. && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
  1890. return expand_builtin (exp, target, subtarget, tmode);
  1891. /* If this call was expanded already by preexpand_calls,
  1892. just return the result we got. */
  1893. if (CALL_EXPR_RTL (exp) != 0)
  1894. return CALL_EXPR_RTL (exp);
  1895. return expand_call (exp, target, ignore);
  1896. case NOP_EXPR:
  1897. case CONVERT_EXPR:
  1898. if (TREE_CODE (type) == VOID_TYPE || ignore)
  1899. {
  1900. expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
  1901. return const0_rtx;
  1902. }
  1903. if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
  1904. return expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, modifier);
  1905. op0 = expand_expr (TREE_OPERAND (exp, 0), 0, mode, 0);
  1906. if (GET_MODE (op0) == mode || GET_MODE (op0) == VOIDmode)
  1907. return op0;
  1908. if (flag_force_mem && GET_CODE (op0) == MEM)
  1909. op0 = copy_to_reg (op0);
  1910. if (target == 0)
  1911. target = gen_reg_rtx (mode);
  1912. convert_move (target, op0, TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
  1913. return target;
  1914. case PLUS_EXPR:
  1915. preexpand_calls (exp);
  1916. if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
  1917. && modifier == EXPAND_SUM)
  1918. {
  1919. op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode, EXPAND_SUM);
  1920. op1 = plus_constant (op1, TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)));
  1921. return op1;
  1922. }
  1923. negate_1 = 1;
  1924. plus_minus:
  1925. if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
  1926. && modifier == EXPAND_SUM)
  1927. {
  1928. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
  1929. op0 = plus_constant (op0,
  1930. negate_1 * TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)));
  1931. return op0;
  1932. }
  1933. this_optab = add_optab;
  1934. if (modifier != EXPAND_SUM) goto binop;
  1935. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  1936. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
  1937. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, EXPAND_SUM);
  1938. /* Put a sum last, to simplify what follows. */
  1939. #ifdef OLD_INDEXING
  1940. if (GET_CODE (op1) == MULT)
  1941. {
  1942. temp = op0;
  1943. op0 = op1;
  1944. op1 = temp;
  1945. }
  1946. #endif
  1947. #ifndef OLD_INDEXING
  1948. /* Make sure any term that's a sum with a constant comes last. */
  1949. if (GET_CODE (op0) == PLUS
  1950. && CONSTANT_P (XEXP (op0, 1)))
  1951. {
  1952. temp = op0;
  1953. op0 = op1;
  1954. op1 = temp;
  1955. }
  1956. /* If adding to a sum including a constant,
  1957. associate it to put the constant outside. */
  1958. if (GET_CODE (op1) == PLUS
  1959. && CONSTANT_P (XEXP (op1, 1)))
  1960. {
  1961. op0 = gen_rtx (PLUS, mode, XEXP (op1, 0), op0);
  1962. if (GET_CODE (XEXP (op1, 1)) == CONST_INT)
  1963. return plus_constant (op0, INTVAL (XEXP (op1, 1)));
  1964. else
  1965. return gen_rtx (PLUS, mode, op0, XEXP (op1, 1));
  1966. }
  1967. #endif
  1968. return gen_rtx (PLUS, mode, op0, op1);
  1969. case MINUS_EXPR:
  1970. preexpand_calls (exp);
  1971. if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
  1972. {
  1973. if (modifier == EXPAND_SUM)
  1974. {
  1975. negate_1 = -1;
  1976. goto plus_minus;
  1977. }
  1978. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  1979. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  1980. op1 = gen_rtx (CONST_INT, VOIDmode,
  1981. - TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)));
  1982. this_optab = add_optab;
  1983. goto binop2;
  1984. }
  1985. this_optab = sub_optab;
  1986. goto binop;
  1987. case MULT_EXPR:
  1988. preexpand_calls (exp);
  1989. /* If first operand is constant, swap them.
  1990. Thus the following special case checks need only
  1991. check the second operand. */
  1992. if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
  1993. {
  1994. register tree t1 = TREE_OPERAND (exp, 0);
  1995. TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
  1996. TREE_OPERAND (exp, 1) = t1;
  1997. }
  1998. /* Attempt to return something suitable for generating an
  1999. indexed address, for machines that support that. */
  2000. if (modifier == EXPAND_SUM
  2001. && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
  2002. {
  2003. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
  2004. /* Apply distributive law if OP0 is x+c. */
  2005. if (GET_CODE (op0) == PLUS
  2006. && GET_CODE (XEXP (op0, 1)) == CONST_INT)
  2007. return gen_rtx (PLUS, mode,
  2008. gen_rtx (MULT, mode, XEXP (op0, 0),
  2009. gen_rtx (CONST_INT, VOIDmode,
  2010. TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))),
  2011. gen_rtx (CONST_INT, VOIDmode,
  2012. (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))
  2013. * INTVAL (XEXP (op0, 1)))));
  2014. if (GET_CODE (op0) != REG)
  2015. op0 = force_operand (op0, 0);
  2016. if (GET_CODE (op0) != REG)
  2017. op0 = copy_to_mode_reg (mode, op0);
  2018. return gen_rtx (MULT, mode, op0,
  2019. gen_rtx (CONST_INT, VOIDmode,
  2020. TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))));
  2021. }
  2022. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2023. /* Check for multiplying things that have been extended
  2024. from a narrower type. If this machine supports multiplying
  2025. in that narrower type with a result in the desired type,
  2026. do it that way, and avoid the explicit type-conversion. */
  2027. if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
  2028. && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
  2029. && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
  2030. < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
  2031. && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
  2032. && int_fits_type_p (TREE_OPERAND (exp, 1),
  2033. TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
  2034. /* Don't use a widening multiply if a shift will do. */
  2035. && exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0)
  2036. ||
  2037. (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
  2038. && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
  2039. ==
  2040. TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
  2041. /* If both operands are extended, they must either both
  2042. be zero-extended or both be sign-extended. */
  2043. && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
  2044. ==
  2045. TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
  2046. {
  2047. enum machine_mode innermode
  2048. = TYPE_MODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)));
  2049. this_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
  2050. ? umul_widen_optab : smul_widen_optab);
  2051. if ((int) innermode + 1 == (int) mode
  2052. && this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
  2053. {
  2054. op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
  2055. 0, VOIDmode, 0);
  2056. if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
  2057. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2058. else
  2059. op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
  2060. 0, VOIDmode, 0);
  2061. goto binop2;
  2062. }
  2063. }
  2064. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2065. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2066. return expand_mult (mode, op0, op1, target, TREE_UNSIGNED (type));
  2067. case TRUNC_DIV_EXPR:
  2068. case FLOOR_DIV_EXPR:
  2069. case CEIL_DIV_EXPR:
  2070. case ROUND_DIV_EXPR:
  2071. preexpand_calls (exp);
  2072. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2073. /* Possible optimization: compute the dividend with EXPAND_SUM
  2074. then if the divisor is constant can optimize the case
  2075. where some terms of the dividend have coeffs divisible by it. */
  2076. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2077. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2078. return expand_divmod (0, code, mode, op0, op1, target,
  2079. TREE_UNSIGNED (type));
  2080. case RDIV_EXPR:
  2081. preexpand_calls (exp);
  2082. this_optab = flodiv_optab;
  2083. goto binop;
  2084. case TRUNC_MOD_EXPR:
  2085. case FLOOR_MOD_EXPR:
  2086. case CEIL_MOD_EXPR:
  2087. case ROUND_MOD_EXPR:
  2088. preexpand_calls (exp);
  2089. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2090. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2091. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2092. return expand_divmod (1, code, mode, op0, op1, target,
  2093. TREE_UNSIGNED (type));
  2094. #if 0
  2095. #ifdef HAVE_divmoddisi4
  2096. if (GET_MODE (op0) != DImode)
  2097. {
  2098. temp = gen_reg_rtx (DImode);
  2099. convert_move (temp, op0, 0);
  2100. op0 = temp;
  2101. if (GET_MODE (op1) != SImode && GET_CODE (op1) != CONST_INT)
  2102. {
  2103. temp = gen_reg_rtx (SImode);
  2104. convert_move (temp, op1, 0);
  2105. op1 = temp;
  2106. }
  2107. temp = gen_reg_rtx (SImode);
  2108. if (target == 0)
  2109. target = gen_reg_rtx (SImode);
  2110. emit_insn (gen_divmoddisi4 (temp, protect_from_queue (op0, 0),
  2111. protect_from_queue (op1, 0),
  2112. protect_from_queue (target, 1)));
  2113. return target;
  2114. }
  2115. #endif
  2116. #endif
  2117. case FIX_ROUND_EXPR:
  2118. case FIX_FLOOR_EXPR:
  2119. case FIX_CEIL_EXPR:
  2120. abort (); /* Not used for C. */
  2121. case FIX_TRUNC_EXPR:
  2122. op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
  2123. if (target == 0)
  2124. target = gen_reg_rtx (mode);
  2125. {
  2126. int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
  2127. if (mode == HImode || mode == QImode)
  2128. {
  2129. register rtx temp = gen_reg_rtx (SImode);
  2130. expand_fix (temp, op0, unsignedp);
  2131. convert_move (target, temp, unsignedp);
  2132. }
  2133. else
  2134. expand_fix (target, op0, unsignedp);
  2135. }
  2136. return target;
  2137. case FLOAT_EXPR:
  2138. op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
  2139. if (target == 0)
  2140. target = gen_reg_rtx (mode);
  2141. {
  2142. int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
  2143. if (GET_MODE (op0) == HImode
  2144. || GET_MODE (op0) == QImode)
  2145. {
  2146. register rtx temp = gen_reg_rtx (SImode);
  2147. convert_move (temp, op0, unsignedp);
  2148. expand_float (target, temp, 0);
  2149. }
  2150. else
  2151. expand_float (target, op0, unsignedp);
  2152. }
  2153. return target;
  2154. case NEGATE_EXPR:
  2155. op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
  2156. temp = expand_unop (mode, neg_optab, op0, target, 0);
  2157. if (temp == 0)
  2158. abort ();
  2159. return temp;
  2160. case ABS_EXPR:
  2161. /* First try to do it with a special abs instruction.
  2162. If that does not win, use conditional jump and negate. */
  2163. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2164. temp = expand_unop (mode, abs_optab, op0, target, 0);
  2165. if (temp != 0)
  2166. return temp;
  2167. temp = gen_label_rtx ();
  2168. if (target == 0 || GET_CODE (target) != REG)
  2169. target = gen_reg_rtx (mode);
  2170. emit_move_insn (target, op0);
  2171. emit_cmp_insn (target,
  2172. expand_expr (convert (TREE_TYPE (exp), integer_zero_node),
  2173. 0, VOIDmode, 0),
  2174. 0, 0);
  2175. emit_jump_insn (gen_bge (temp));
  2176. op0 = expand_unop (mode, neg_optab, target, target, 0);
  2177. if (op0 != target)
  2178. emit_move_insn (target, op0);
  2179. emit_label (temp);
  2180. return target;
  2181. case MAX_EXPR:
  2182. case MIN_EXPR:
  2183. mode = TYPE_MODE (TREE_OPERAND (exp, 1));
  2184. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2185. if (target == 0 || GET_CODE (target) != REG || target == op1)
  2186. target = gen_reg_rtx (mode);
  2187. op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
  2188. if (target != op0)
  2189. emit_move_insn (target, op0);
  2190. op0 = gen_label_rtx ();
  2191. if (code == MAX_EXPR)
  2192. temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
  2193. ? compare1 (target, op1, GEU, LEU, 1, mode)
  2194. : compare1 (target, op1, GE, LE, 0, mode));
  2195. else
  2196. temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
  2197. ? compare1 (target, op1, LEU, GEU, 1, mode)
  2198. : compare1 (target, op1, LE, GE, 0, mode));
  2199. if (temp == const0_rtx)
  2200. emit_move_insn (target, op1);
  2201. else if (temp != const1_rtx)
  2202. {
  2203. emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
  2204. gen_rtx (IF_THEN_ELSE, VOIDmode,
  2205. temp,
  2206. gen_rtx (LABEL_REF, VOIDmode, op0),
  2207. pc_rtx)));
  2208. emit_move_insn (target, op1);
  2209. }
  2210. emit_label (op0);
  2211. return target;
  2212. /* ??? Can optimize when the operand of this is a bitwise operation,
  2213. by using a different bitwise operation. */
  2214. case BIT_NOT_EXPR:
  2215. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2216. temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
  2217. if (temp == 0)
  2218. abort ();
  2219. return temp;
  2220. case FFS_EXPR:
  2221. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2222. temp = expand_unop (mode, ffs_optab, op0, target, 1);
  2223. if (temp == 0)
  2224. abort ();
  2225. return temp;
  2226. /* ??? Can optimize bitwise operations with one arg constant.
  2227. Pastel optimizes (a bitwise1 n) bitwise2 (a bitwise3 b)
  2228. and (a bitwise1 b) bitwise2 b (etc)
  2229. but that is probably not worth while. */
  2230. /* BIT_AND_EXPR is for bitwise anding.
  2231. TRUTH_AND_EXPR is for anding two boolean values
  2232. when we want in all cases to compute both of them.
  2233. In general it is fastest to do TRUTH_AND_EXPR by
  2234. computing both operands as actual zero-or-1 values
  2235. and then bitwise anding. In cases where there cannot
  2236. be any side effects, better code would be made by
  2237. treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR;
  2238. but the question is how to recognize those cases. */
  2239. case TRUTH_AND_EXPR:
  2240. case BIT_AND_EXPR:
  2241. preexpand_calls (exp);
  2242. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2243. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2244. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2245. return expand_bit_and (mode, op0, op1, target);
  2246. /* See comment above about TRUTH_AND_EXPR; it applies here too. */
  2247. case TRUTH_OR_EXPR:
  2248. case BIT_IOR_EXPR:
  2249. preexpand_calls (exp);
  2250. this_optab = ior_optab;
  2251. goto binop;
  2252. case BIT_XOR_EXPR:
  2253. preexpand_calls (exp);
  2254. this_optab = xor_optab;
  2255. goto binop;
  2256. case LSHIFT_EXPR:
  2257. case RSHIFT_EXPR:
  2258. case LROTATE_EXPR:
  2259. case RROTATE_EXPR:
  2260. preexpand_calls (exp);
  2261. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2262. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2263. return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
  2264. TREE_UNSIGNED (type));
  2265. /* ??? cv's were used to effect here to combine additive constants
  2266. and to determine the answer when only additive constants differ.
  2267. Also, the addition of one can be handled by changing the condition. */
  2268. case LT_EXPR:
  2269. case LE_EXPR:
  2270. case GT_EXPR:
  2271. case GE_EXPR:
  2272. case EQ_EXPR:
  2273. case NE_EXPR:
  2274. preexpand_calls (exp);
  2275. temp = do_store_flag (exp, target, mode);
  2276. if (temp != 0)
  2277. return temp;
  2278. /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
  2279. if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
  2280. && subtarget
  2281. && (GET_MODE (subtarget)
  2282. == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
  2283. {
  2284. temp = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2285. if (temp != subtarget)
  2286. temp = copy_to_reg (temp);
  2287. op1 = gen_label_rtx ();
  2288. emit_cmp_insn (temp, const0_rtx, 0, TREE_UNSIGNED (type));
  2289. emit_jump_insn (gen_beq (op1));
  2290. emit_move_insn (temp, const1_rtx);
  2291. emit_label (op1);
  2292. return temp;
  2293. }
  2294. /* If no set-flag instruction, must generate a conditional
  2295. store into a temporary variable. Drop through
  2296. and handle this like && and ||. */
  2297. case TRUTH_ANDIF_EXPR:
  2298. case TRUTH_ORIF_EXPR:
  2299. temp = gen_reg_rtx (mode);
  2300. emit_clr_insn (temp);
  2301. op1 = gen_label_rtx ();
  2302. jumpifnot (exp, op1);
  2303. emit_0_to_1_insn (temp);
  2304. emit_label (op1);
  2305. return temp;
  2306. case TRUTH_NOT_EXPR:
  2307. op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
  2308. /* The parser is careful to generate TRUTH_NOT_EXPR
  2309. only with operands that are always zero or one. */
  2310. temp = expand_binop (mode, xor_optab, op0,
  2311. gen_rtx (CONST_INT, mode, 1),
  2312. target, 1, OPTAB_LIB_WIDEN);
  2313. if (temp == 0)
  2314. abort ();
  2315. return temp;
  2316. case COMPOUND_EXPR:
  2317. expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
  2318. emit_queue ();
  2319. return expand_expr (TREE_OPERAND (exp, 1), target, VOIDmode, 0);
  2320. case COND_EXPR:
  2321. /* Note that COND_EXPRs whose type is a structure or union
  2322. are required to be constructed to contain assignments of
  2323. a temporary variable, so that we can evaluate them here
  2324. for side effect only. If type is void, we must do likewise. */
  2325. op0 = gen_label_rtx ();
  2326. op1 = gen_label_rtx ();
  2327. if (mode == VOIDmode || ignore)
  2328. temp = 0;
  2329. else if (target)
  2330. temp = target;
  2331. else if (mode == BLKmode)
  2332. {
  2333. if (TYPE_SIZE (type) == 0 || ! TREE_LITERAL (TYPE_SIZE (type)))
  2334. abort ();
  2335. temp = assign_stack_local (BLKmode,
  2336. (TREE_INT_CST_LOW (TYPE_SIZE (type))
  2337. * TYPE_SIZE_UNIT (type)
  2338. + BITS_PER_UNIT - 1)
  2339. / BITS_PER_UNIT);
  2340. }
  2341. else
  2342. temp = gen_reg_rtx (mode);
  2343. jumpifnot (TREE_OPERAND (exp, 0), op0);
  2344. current_args_size += 1;
  2345. if (temp != 0)
  2346. store_expr (TREE_OPERAND (exp, 1), temp, 0);
  2347. else
  2348. expand_expr (TREE_OPERAND (exp, 1), ignore ? const0_rtx : 0,
  2349. VOIDmode, 0);
  2350. emit_queue ();
  2351. emit_jump_insn (gen_jump (op1));
  2352. emit_barrier ();
  2353. emit_label (op0);
  2354. if (temp != 0)
  2355. store_expr (TREE_OPERAND (exp, 2), temp, 0);
  2356. else
  2357. expand_expr (TREE_OPERAND (exp, 2), ignore ? const0_rtx : 0,
  2358. VOIDmode, 0);
  2359. emit_queue ();
  2360. emit_label (op1);
  2361. current_args_size -= 1;
  2362. return temp;
  2363. case MODIFY_EXPR:
  2364. /* If lhs is complex, expand calls in rhs before computing it.
  2365. That's so we don't compute a pointer and save it over a call.
  2366. If lhs is simple, compute it first so we can give it as a
  2367. target if the rhs is just a call. This avoids an extra temp and copy
  2368. and that prevents a partial-subsumption which makes bad code.
  2369. Actually we could treat component_ref's of vars like vars. */
  2370. if (TREE_CODE (TREE_OPERAND (exp, 0)) != VAR_DECL
  2371. && TREE_CODE (TREE_OPERAND (exp, 0)) != RESULT_DECL
  2372. && TREE_CODE (TREE_OPERAND (exp, 0)) != PARM_DECL)
  2373. preexpand_calls (exp);
  2374. temp = expand_assignment (TREE_OPERAND (exp, 0),
  2375. TREE_OPERAND (exp, 1),
  2376. ! ignore,
  2377. original_target != 0);
  2378. return temp;
  2379. case PREINCREMENT_EXPR:
  2380. case PREDECREMENT_EXPR:
  2381. return expand_increment (exp, 0);
  2382. case POSTINCREMENT_EXPR:
  2383. case POSTDECREMENT_EXPR:
  2384. return expand_increment (exp, 1);
  2385. case ADDR_EXPR:
  2386. op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode,
  2387. EXPAND_CONST_ADDRESS);
  2388. if (GET_CODE (op0) != MEM)
  2389. abort ();
  2390. if (modifier == EXPAND_SUM)
  2391. return XEXP (op0, 0);
  2392. op0 = force_operand (XEXP (op0, 0), target);
  2393. if (flag_force_addr && GET_CODE (op0) != REG)
  2394. return force_reg (Pmode, op0);
  2395. return op0;
  2396. case ENTRY_VALUE_EXPR:
  2397. abort ();
  2398. case ERROR_MARK:
  2399. return const0_rtx;
  2400. default:
  2401. abort ();
  2402. }
  2403. /* Here to do an ordinary binary operator, generating an instruction
  2404. from the optab already placed in `this_optab'. */
  2405. binop:
  2406. /* Detect things like x = y | (a == b)
  2407. and do them as (x = y), (a == b ? x |= 1 : 0), x. */
  2408. /* First, get the comparison or conditional into the second arg. */
  2409. if (comparison_code[(int) TREE_CODE (TREE_OPERAND (exp, 0))]
  2410. || (TREE_CODE (TREE_OPERAND (exp, 0)) == COND_EXPR
  2411. && (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
  2412. || integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 2)))))
  2413. {
  2414. if (this_optab == ior_optab || this_optab == add_optab
  2415. || this_optab == xor_optab)
  2416. {
  2417. tree exch = TREE_OPERAND (exp, 1);
  2418. TREE_OPERAND (exp, 1) = TREE_OPERAND (exp, 0);
  2419. TREE_OPERAND (exp, 0) = exch;
  2420. }
  2421. }
  2422. if (comparison_code[(int) TREE_CODE (TREE_OPERAND (exp, 1))]
  2423. || (TREE_CODE (TREE_OPERAND (exp, 1)) == COND_EXPR
  2424. && (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 1))
  2425. || integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 2)))))
  2426. {
  2427. if (this_optab == ior_optab || this_optab == add_optab
  2428. || this_optab == xor_optab || this_optab == sub_optab
  2429. || this_optab == lshl_optab || this_optab == ashl_optab
  2430. || this_optab == lshr_optab || this_optab == ashr_optab
  2431. || this_optab == rotl_optab || this_optab == rotr_optab)
  2432. {
  2433. tree thenexp;
  2434. rtx thenv = 0;
  2435. if (target == 0) target = gen_reg_rtx (mode);
  2436. store_expr (TREE_OPERAND (exp, 0), target, 0);
  2437. op0 = gen_label_rtx ();
  2438. if (TREE_CODE (TREE_OPERAND (exp, 1)) != COND_EXPR)
  2439. {
  2440. do_jump (TREE_OPERAND (exp, 1), op0, 0);
  2441. thenv = const1_rtx;
  2442. }
  2443. else if (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 2)))
  2444. {
  2445. do_jump (TREE_OPERAND (TREE_OPERAND (exp, 1), 0), op0, 0);
  2446. thenexp = TREE_OPERAND (TREE_OPERAND (exp, 1), 1);
  2447. }
  2448. else
  2449. {
  2450. do_jump (TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0, op0);
  2451. thenexp = TREE_OPERAND (TREE_OPERAND (exp, 1), 2);
  2452. }
  2453. if (thenv == 0)
  2454. thenv = expand_expr (thenexp, 0, VOIDmode, 0);
  2455. if (this_optab == rotl_optab || this_optab == rotr_optab)
  2456. temp = expand_binop (mode, this_optab, target, thenv, target,
  2457. -1, OPTAB_LIB);
  2458. else if (this_optab == lshl_optab || this_optab == lshr_optab)
  2459. temp = expand_binop (mode, this_optab, target, thenv, target,
  2460. 1, OPTAB_LIB_WIDEN);
  2461. else
  2462. temp = expand_binop (mode, this_optab, target, thenv, target,
  2463. 0, OPTAB_LIB_WIDEN);
  2464. if (target != temp)
  2465. emit_move_insn (target, temp);
  2466. emit_label (op0);
  2467. return target;
  2468. }
  2469. }
  2470. subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
  2471. op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
  2472. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2473. binop2:
  2474. temp = expand_binop (mode, this_optab, op0, op1, target,
  2475. TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
  2476. binop1:
  2477. if (temp == 0)
  2478. abort ();
  2479. return temp;
  2480. }
  2481. /* Expand an expression EXP that calls a built-in function,
  2482. with result going to TARGET if that's convenient
  2483. (and in mode MODE if that's convenient).
  2484. SUBTARGET may be used as the target for computing one of EXP's operands. */
  2485. static rtx
  2486. expand_builtin (exp, target, subtarget, mode)
  2487. tree exp;
  2488. rtx target;
  2489. rtx subtarget;
  2490. enum machine_mode mode;
  2491. {
  2492. tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
  2493. tree arglist = TREE_OPERAND (exp, 1);
  2494. rtx op0;
  2495. rtx temp;
  2496. switch (DECL_FUNCTION_CODE (fndecl))
  2497. {
  2498. case BUILT_IN_ABS:
  2499. case BUILT_IN_LABS:
  2500. case BUILT_IN_FABS:
  2501. /* build_function_call changes these into ABS_EXPR. */
  2502. abort ();
  2503. case BUILT_IN_ALLOCA:
  2504. if (arglist == 0)
  2505. return const0_rtx;
  2506. frame_pointer_needed = 1;
  2507. /* Compute the argument. */
  2508. op0 = expand_expr (TREE_VALUE (arglist), 0, VOIDmode, 0);
  2509. if (! CONSTANT_P (op0))
  2510. {
  2511. op0 = force_reg (GET_MODE (op0), op0);
  2512. if (GET_MODE (op0) != Pmode)
  2513. op0 = convert_to_mode (Pmode, op0);
  2514. }
  2515. /* Push that much space (rounding it up). */
  2516. anti_adjust_stack (round_push (op0));
  2517. /* Return a copy of current stack ptr, in TARGET if possible. */
  2518. if (target)
  2519. emit_move_insn (target, stack_pointer_rtx);
  2520. else
  2521. target = copy_to_reg (stack_pointer_rtx);
  2522. return target;
  2523. case BUILT_IN_FFS:
  2524. if (arglist == 0)
  2525. return const0_rtx;
  2526. /* Compute the argument. */
  2527. op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
  2528. /* Compute ffs, into TARGET if possible.
  2529. Set TARGET to wherever the result comes back. */
  2530. target = expand_unop (mode, ffs_optab, op0, target, 1);
  2531. if (target == 0)
  2532. abort ();
  2533. return target;
  2534. default:
  2535. abort ();
  2536. }
  2537. }
  2538. /* Expand code for a post- or pre- increment or decrement
  2539. and return the RTX for the result.
  2540. POST is 1 for postinc/decrements and 0 for preinc/decrements. */
  2541. static rtx
  2542. expand_increment (exp, post)
  2543. register tree exp;
  2544. int post;
  2545. {
  2546. register rtx op0, op1;
  2547. register rtx temp;
  2548. register tree incremented = TREE_OPERAND (exp, 0);
  2549. optab this_optab = add_optab;
  2550. int icode;
  2551. enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
  2552. int op0_is_copy = 0;
  2553. /* Stabilize any component ref that might need to be
  2554. evaluated more than once below. */
  2555. if (TREE_CODE (incremented) == COMPONENT_REF
  2556. && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
  2557. || DECL_MODE (TREE_OPERAND (exp, 1)) == BImode))
  2558. incremented = stabilize_reference (incremented);
  2559. /* Compute the operands as RTX.
  2560. Note whether OP0 is the actual lvalue or a copy of it:
  2561. I believe it is a copy iff it is a register and insns were
  2562. generated in computing it. */
  2563. temp = get_last_insn ();
  2564. op0 = expand_expr (incremented, 0, VOIDmode, 0);
  2565. if (temp != get_last_insn ())
  2566. op0_is_copy = (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG);
  2567. op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  2568. /* Decide whether incrementing or decrementing. */
  2569. if (TREE_CODE (exp) == POSTDECREMENT_EXPR
  2570. || TREE_CODE (exp) == PREDECREMENT_EXPR)
  2571. this_optab = sub_optab;
  2572. /* If OP0 is not the actual lvalue, but rather a copy in a register,
  2573. then we cannot just increment OP0. We must
  2574. therefore contrive to increment the original value.
  2575. Then we can return OP0 since it is a copy of the old value. */
  2576. if (op0_is_copy)
  2577. {
  2578. /* This is the easiest way to increment the value wherever it is.
  2579. Problems with multiple evaluation of INCREMENTED
  2580. are prevented because either (1) it is a component_ref,
  2581. in which case it was stabilized above, or (2) it is an array_ref
  2582. with constant index in an array in a register, which is
  2583. safe to reevaluate. */
  2584. tree newexp = build ((this_optab == add_optab
  2585. ? PLUS_EXPR : MINUS_EXPR),
  2586. TREE_TYPE (exp),
  2587. incremented,
  2588. TREE_OPERAND (exp, 1));
  2589. temp = expand_assignment (incremented, newexp, ! post, 0);
  2590. return post ? op0 : temp;
  2591. }
  2592. /* Convert decrement by a constant into a negative increment. */
  2593. if (this_optab == sub_optab
  2594. && GET_CODE (op1) == CONST_INT)
  2595. {
  2596. op1 = gen_rtx (CONST_INT, VOIDmode, - INTVAL (op1));
  2597. this_optab = add_optab;
  2598. }
  2599. if (post)
  2600. {
  2601. /* We have a true reference to the value in OP0.
  2602. If there is an insn to add or subtract in this mode, queue it. */
  2603. /* I'm not sure this is still necessary. */
  2604. op0 = stabilize (op0);
  2605. icode = (int) this_optab->handlers[(int) mode].insn_code;
  2606. if (icode != (int) CODE_FOR_nothing
  2607. /* Make sure that OP0 is valid for operands 0 and 1
  2608. of the insn we want to queue. */
  2609. && (*insn_operand_predicate[icode][0]) (op0, mode)
  2610. && (*insn_operand_predicate[icode][1]) (op0, mode))
  2611. {
  2612. if (! (*insn_operand_predicate[icode][2]) (op1, mode))
  2613. op1 = force_reg (mode, op1);
  2614. return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
  2615. }
  2616. }
  2617. /* Preincrement, or we can't increment with one simple insn. */
  2618. if (post)
  2619. /* Save a copy of the value before inc or dec, to return it later. */
  2620. temp = copy_to_reg (op0);
  2621. else
  2622. /* Arrange to return the incremented value. */
  2623. temp = op0;
  2624. /* Increment however we can. */
  2625. op1 = expand_binop (mode, this_optab, op0, op1, op0,
  2626. 0, OPTAB_LIB_WIDEN);
  2627. /* Make sure the value is stored into OP0. */
  2628. if (op1 != op0)
  2629. emit_move_insn (op0, op1);
  2630. return temp;
  2631. }
  2632. /* Expand all function calls contained within EXP, innermost ones first.
  2633. But don't look within expressions that have sequence points.
  2634. For each CALL_EXPR, record the rtx for its value
  2635. in the CALL_EXPR_RTL field.
  2636. Calls that return large structures for which a structure return
  2637. stack slot is needed are not preexpanded. Preexpanding them loses
  2638. because if more than one were preexpanded they would try to use the
  2639. same stack slot. */
  2640. static void
  2641. preexpand_calls (exp)
  2642. tree exp;
  2643. {
  2644. register int nops, i;
  2645. if (! do_preexpand_calls)
  2646. return;
  2647. /* Only expressions and references can contain calls. */
  2648. if (tree_code_type[(int) TREE_CODE (exp)][0] != 'e'
  2649. && tree_code_type[(int) TREE_CODE (exp)][0] != 'r')
  2650. return;
  2651. switch (TREE_CODE (exp))
  2652. {
  2653. case CALL_EXPR:
  2654. /* Do nothing to built-in functions. */
  2655. if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
  2656. && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == FUNCTION_DECL
  2657. && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
  2658. return;
  2659. if (CALL_EXPR_RTL (exp) == 0
  2660. && TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
  2661. CALL_EXPR_RTL (exp) = expand_call (exp, 0, 0);
  2662. return;
  2663. case COMPOUND_EXPR:
  2664. case COND_EXPR:
  2665. case TRUTH_ANDIF_EXPR:
  2666. case TRUTH_ORIF_EXPR:
  2667. /* If we find one of these, then we can be sure
  2668. the adjust will be done for it (since it makes jumps).
  2669. Do it now, so that if this is inside an argument
  2670. of a function, we don't get the stack adjustment
  2671. after some other args have already been pushed. */
  2672. do_pending_stack_adjust ();
  2673. return;
  2674. case RTL_EXPR:
  2675. return;
  2676. case SAVE_EXPR:
  2677. if (SAVE_EXPR_RTL (exp) != 0)
  2678. return;
  2679. }
  2680. nops = tree_code_length[(int) TREE_CODE (exp)];
  2681. for (i = 0; i < nops; i++)
  2682. if (TREE_OPERAND (exp, i) != 0)
  2683. {
  2684. register int type = *tree_code_type[(int) TREE_CODE (TREE_OPERAND (exp, i))];
  2685. if (type == 'e' || type == 'r')
  2686. preexpand_calls (TREE_OPERAND (exp, i));
  2687. }
  2688. }
  2689. /* Force FUNEXP into a form suitable for the address of a CALL,
  2690. and return that as an rtx. Also load the static chain register
  2691. from either FUNEXP or CONTEXT. */
  2692. static rtx
  2693. prepare_call_address (funexp, context)
  2694. rtx funexp;
  2695. rtx context;
  2696. {
  2697. funexp = protect_from_queue (funexp, 0);
  2698. if (context != 0)
  2699. context = protect_from_queue (context, 0);
  2700. /* Function variable in language with nested functions. */
  2701. if (GET_MODE (funexp) == EPmode)
  2702. {
  2703. emit_move_insn (static_chain_rtx, gen_highpart (Pmode, funexp));
  2704. funexp = memory_address (FUNCTION_MODE, gen_lowpart (Pmode, funexp));
  2705. emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
  2706. }
  2707. else
  2708. {
  2709. if (context != 0)
  2710. /* Unless function variable in C, or top level function constant */
  2711. emit_move_insn (static_chain_rtx, lookup_static_chain (context));
  2712. /* Make a valid memory address and copy constants thru pseudo-regs,
  2713. but not for a constant address if -fno-function-cse. */
  2714. if (GET_CODE (funexp) != SYMBOL_REF)
  2715. funexp = memory_address (FUNCTION_MODE, funexp);
  2716. else
  2717. {
  2718. #ifndef NO_FUNCTION_CSE
  2719. if (! flag_no_function_cse)
  2720. funexp = copy_to_mode_reg (Pmode, funexp);
  2721. #endif
  2722. }
  2723. if (context != 0)
  2724. emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
  2725. }
  2726. return funexp;
  2727. }
  2728. /* Generate instructions to call function FUNEXP,
  2729. and optionally pop the results.
  2730. The CALL_INSN is the first insn generated.
  2731. FUNTYPE is the data type of the function, or, for a library call,
  2732. the identifier for the name of the call. This is given to the
  2733. macro RETURN_POPS_ARGS to determine whether this function pops its own args.
  2734. STACK_SIZE is the number of bytes of arguments on the stack,
  2735. rounded up to STACK_BOUNDARY; zero if the size is variable.
  2736. This is both to put into the call insn and
  2737. to generate explicit popping code if necessary.
  2738. NEXT_ARG_REG is the rtx that results from executing
  2739. FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
  2740. just after all the args have had their registers assigned.
  2741. This could be whatever you like, but normally it is the first
  2742. arg-register beyond those used for args in this call,
  2743. or 0 if all the arg-registers are used in this call.
  2744. It is passed on to `gen_call' so you can put this info in the call insn.
  2745. VALREG is a hard register in which a value is returned,
  2746. or 0 if the call does not return a value.
  2747. OLD_ARGS_SIZE is the value that `current_args_size' had before
  2748. the args to this call were processed.
  2749. We restore `current_args_size' to that value. */
  2750. static void
  2751. emit_call_1 (funexp, funtype, stack_size, next_arg_reg, valreg, old_args_size)
  2752. rtx funexp;
  2753. tree funtype;
  2754. int stack_size;
  2755. rtx next_arg_reg;
  2756. rtx valreg;
  2757. int old_args_size;
  2758. {
  2759. rtx stack_size_rtx = gen_rtx (CONST_INT, VOIDmode, stack_size);
  2760. if (valreg)
  2761. emit_call_insn (gen_call_value (valreg,
  2762. gen_rtx (MEM, FUNCTION_MODE, funexp),
  2763. stack_size_rtx, next_arg_reg));
  2764. else
  2765. emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
  2766. stack_size_rtx, next_arg_reg));
  2767. current_args_size = old_args_size;
  2768. /* If returning from the subroutine does not automatically pop the args,
  2769. we need an instruction to pop them sooner or later.
  2770. Perhaps do it now; perhaps just record how much space to pop later. */
  2771. if (! RETURN_POPS_ARGS (TREE_TYPE (funtype))
  2772. && stack_size != 0)
  2773. {
  2774. if (flag_defer_pop && current_args_size == 0)
  2775. pending_stack_adjust += stack_size;
  2776. else
  2777. adjust_stack (gen_rtx (CONST_INT, VOIDmode, stack_size));
  2778. }
  2779. }
  2780. /* At the start of a function, record that we have no previously-pushed
  2781. arguments waiting to be popped. */
  2782. void
  2783. init_pending_stack_adjust ()
  2784. {
  2785. pending_stack_adjust = 0;
  2786. }
  2787. /* When exiting from function, if safe, clear out any pending stack adjust
  2788. so the adjustment won't get done. */
  2789. void
  2790. clear_pending_stack_adjust ()
  2791. {
  2792. #if 0
  2793. /* Right now it's never considered safe, because
  2794. it loses in an inline function. */
  2795. #ifdef EXIT_IGNORE_STACK
  2796. if (!flag_omit_frame_pointer && EXIT_IGNORE_STACK)
  2797. pending_stack_adjust = 0;
  2798. #endif
  2799. #endif
  2800. }
  2801. /* At start of function, initialize. */
  2802. void
  2803. clear_current_args_size ()
  2804. {
  2805. current_args_size = 0;
  2806. }
  2807. /* Pop any previously-pushed arguments that have not been popped yet. */
  2808. void
  2809. do_pending_stack_adjust ()
  2810. {
  2811. if (current_args_size == 0)
  2812. {
  2813. if (pending_stack_adjust != 0)
  2814. adjust_stack (gen_rtx (CONST_INT, VOIDmode, pending_stack_adjust));
  2815. pending_stack_adjust = 0;
  2816. }
  2817. }
  2818. /* Generate all the code for a function call
  2819. and return an rtx for its value.
  2820. Store the value in TARGET (specified as an rtx) if convenient.
  2821. If the value is stored in TARGET then TARGET is returned.
  2822. If IGNORE is nonzero, then we ignore the value of the function call. */
  2823. static rtx
  2824. expand_call (exp, target, ignore)
  2825. tree exp;
  2826. rtx target;
  2827. int ignore;
  2828. {
  2829. tree actparms = TREE_OPERAND (exp, 1);
  2830. tree funtype;
  2831. rtx funexp;
  2832. register tree p = TREE_OPERAND (exp, 0);
  2833. struct args_size args_size;
  2834. register int i;
  2835. register tree *argvec;
  2836. rtx *regvec;
  2837. rtx *valvec;
  2838. int *partial;
  2839. struct args_size *arg_offset;
  2840. struct args_size *arg_size;
  2841. int num_actuals;
  2842. rtx structure_value_addr = 0;
  2843. tree fndecl = 0;
  2844. int may_be_alloca;
  2845. int inc;
  2846. int is_setjmp;
  2847. int is_integrable = 0;
  2848. rtx argblock = 0;
  2849. CUMULATIVE_ARGS args_so_far;
  2850. int reg_parm_seen = 0;
  2851. rtx valreg;
  2852. rtx old_stack_level;
  2853. int old_pending_adj;
  2854. int old_current_args_size = current_args_size;
  2855. /* Number of named args. Args after this are anonymous ones
  2856. and they must all go on the stack. */
  2857. int n_named_args;
  2858. args_size.constant = 0;
  2859. args_size.var = 0;
  2860. /* See if we can find a DECL-node for the actual function.
  2861. As a result, decide whether this is a call to an integrable function. */
  2862. if (TREE_CODE (p) == ADDR_EXPR)
  2863. {
  2864. fndecl = TREE_OPERAND (p, 0);
  2865. if (TREE_CODE (fndecl) != FUNCTION_DECL)
  2866. fndecl = 0;
  2867. else
  2868. {
  2869. extern tree current_function_decl;
  2870. if (fndecl != current_function_decl
  2871. && DECL_SAVED_INSNS (fndecl))
  2872. is_integrable = 1;
  2873. else
  2874. /* In case this function later becomes inlineable,
  2875. record that there was already a non-inline call to it. */
  2876. TREE_ADDRESSABLE (fndecl) = 1;
  2877. }
  2878. }
  2879. /* Set up a place to return a structure. */
  2880. if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
  2881. {
  2882. /* This call returns a big structure. */
  2883. if (target)
  2884. structure_value_addr = XEXP (target, 0);
  2885. else
  2886. /* Make room on the stack to hold the value. */
  2887. structure_value_addr = get_structure_value_addr (expr_size (exp));
  2888. }
  2889. if (is_integrable)
  2890. {
  2891. extern int integration_time;
  2892. extern rtx expand_inline_function ();
  2893. rtx temp;
  2894. temp = expand_inline_function (fndecl, actparms, target,
  2895. ignore, TREE_TYPE (exp),
  2896. structure_value_addr);
  2897. /* If the inlining failed for whatever reason, we will just
  2898. issue a normal call. */
  2899. if (temp == (rtx)-1)
  2900. {
  2901. warning_with_decl (fndecl, "inlining function `%s' failed, reverting to function call");
  2902. }
  2903. else
  2904. return temp;
  2905. }
  2906. #if 0
  2907. /* Unless it's a call to a specific function that isn't alloca,
  2908. if it has one argument, we must assume it might be alloca. */
  2909. may_be_alloca =
  2910. (!(fndecl != 0
  2911. && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)),
  2912. "alloca"))
  2913. && actparms != 0
  2914. && TREE_CHAIN (actparms) == 0);
  2915. #else
  2916. /* We assume that alloca will always be called by name. It
  2917. makes no sense to pass it as a pointer-to-function to
  2918. anything that does not understand its behavior. */
  2919. may_be_alloca =
  2920. (fndecl && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "alloca"));
  2921. #endif
  2922. /* See if this is a call to a function that can return more than once. */
  2923. is_setjmp
  2924. = (fndecl != 0
  2925. && (!strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "setjmp")
  2926. || !strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "_setjmp")));
  2927. if (may_be_alloca)
  2928. {
  2929. frame_pointer_needed = 1;
  2930. may_call_alloca = 1;
  2931. }
  2932. /* Don't let pending stack adjusts add up to too much.
  2933. Also, do all pending adjustments now
  2934. if there is any chance this might be a call to alloca. */
  2935. if (pending_stack_adjust >= 32
  2936. || (pending_stack_adjust > 0 && may_be_alloca))
  2937. do_pending_stack_adjust ();
  2938. /* Operand 0 is a pointer-to-function; get the type of the function. */
  2939. funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
  2940. if (TREE_CODE (funtype) != POINTER_TYPE)
  2941. abort ();
  2942. funtype = TREE_TYPE (funtype);
  2943. /* Count the arguments and set NUM_ACTUALS. */
  2944. for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
  2945. num_actuals = i;
  2946. /* Compute number of named args.
  2947. This may actually be 1 too large, but that happens
  2948. only in the case when all args are named, so no trouble results. */
  2949. if (TYPE_ARG_TYPES (funtype) != 0)
  2950. n_named_args = list_length (TYPE_ARG_TYPES (funtype));
  2951. else
  2952. /* If we know nothing, treat all args as named. */
  2953. n_named_args = num_actuals;
  2954. /* Make a vector of the args, in the order we want to compute them,
  2955. and a parallel vector of where we want to put them.
  2956. regvec[I] is 0 to if should push argvec[I] or else a reg to put it in.
  2957. valvec[i] is the arg value as an rtx. */
  2958. argvec = (tree *) alloca (i * sizeof (tree));
  2959. regvec = (rtx *) alloca (i * sizeof (rtx));
  2960. valvec = (rtx *) alloca (i * sizeof (rtx));
  2961. partial = (int *) alloca (i * sizeof (int));
  2962. arg_size = (struct args_size *) alloca (i * sizeof (struct args_size));
  2963. arg_offset = (struct args_size *) alloca (i * sizeof (struct args_size));
  2964. /* In this loop, we consider args in the order they are written.
  2965. We fill up argvec from the front of from the back
  2966. so that the first arg to be pushed ends up at the front. */
  2967. #ifdef PUSH_ARGS_REVERSED
  2968. i = num_actuals - 1, inc = -1;
  2969. /* In this case, must reverse order of args
  2970. so that we compute and push the last arg first. */
  2971. #else
  2972. i = 0, inc = 1;
  2973. #endif
  2974. INIT_CUMULATIVE_ARGS (args_so_far, funtype);
  2975. for (p = actparms; p; p = TREE_CHAIN (p), i += inc)
  2976. {
  2977. tree type = TREE_TYPE (TREE_VALUE (p));
  2978. argvec[i] = p;
  2979. regvec[i] = 0;
  2980. valvec[i] = 0;
  2981. partial[i] = 0;
  2982. arg_size[i].constant = 0;
  2983. arg_size[i].var = 0;
  2984. arg_offset[i] = args_size;
  2985. if (type == error_mark_node)
  2986. continue;
  2987. /* Decide where to pass this arg. */
  2988. /* regvec[i] is nonzero if all or part is passed in registers.
  2989. partial[i] is nonzero if part but not all is passed in registers,
  2990. and the exact value says how many words are passed in registers. */
  2991. if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
  2992. || args_size.var != 0)
  2993. {
  2994. regvec[i] = FUNCTION_ARG (args_so_far, TYPE_MODE (type), type,
  2995. i < n_named_args);
  2996. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  2997. partial[i] = FUNCTION_ARG_PARTIAL_NREGS (args_so_far,
  2998. TYPE_MODE (type), type,
  2999. i < n_named_args);
  3000. #endif
  3001. }
  3002. /* Once we see at least one parm that is being passed in a register,
  3003. precompute that parm and all remaining parms (if they do arithmetic)
  3004. before loading any of them into their specified registers.
  3005. That way we don't lose if one of them involves
  3006. a function call OR a library routine that needs the same regs. */
  3007. if (regvec[i] != 0)
  3008. reg_parm_seen = 1;
  3009. if (reg_parm_seen)
  3010. {
  3011. valvec[i] = expand_expr (TREE_VALUE (p), 0, VOIDmode, 0);
  3012. if (GET_CODE (valvec[i]) != MEM
  3013. && ! CONSTANT_P (valvec[i])
  3014. && GET_CODE (valvec[i]) != CONST_DOUBLE)
  3015. valvec[i] = force_reg (TYPE_MODE (type), valvec[i]);
  3016. }
  3017. /* Increment ARGS_SO_FAR, which has info about which arg-registers
  3018. have been used, etc. */
  3019. FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
  3020. i < n_named_args);
  3021. /* Increment ARGS_SIZE, which is the size of all args so far. */
  3022. if (regvec[i] != 0 && partial[i] == 0)
  3023. /* A register-arg doesn't count. */
  3024. ;
  3025. else if (TYPE_MODE (type) != BLKmode)
  3026. {
  3027. register int size;
  3028. size = GET_MODE_SIZE (TYPE_MODE (type));
  3029. /* Compute how much space the push instruction will push.
  3030. On many machines, pushing a byte will advance the stack
  3031. pointer by a halfword. */
  3032. #ifdef PUSH_ROUNDING
  3033. size = PUSH_ROUNDING (size);
  3034. #endif
  3035. /* Compute how much space the argument should get:
  3036. round up to a multiple of the alignment for arguments. */
  3037. arg_size[i].constant
  3038. = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
  3039. / (PARM_BOUNDARY / BITS_PER_UNIT))
  3040. * (PARM_BOUNDARY / BITS_PER_UNIT));
  3041. }
  3042. else
  3043. {
  3044. register tree size = size_in_bytes (type);
  3045. /* A nonscalar. Round its size up to a multiple
  3046. of the allocation unit for arguments. */
  3047. /* Now round up to multiple of PARM_BOUNDARY bits,
  3048. then express as number of bytes. */
  3049. ADD_PARM_SIZE (arg_size[i],
  3050. convert_units (convert_units (size, BITS_PER_UNIT, PARM_BOUNDARY),
  3051. PARM_BOUNDARY, BITS_PER_UNIT));
  3052. }
  3053. /* If a part of the arg was put into registers,
  3054. don't include that part in the amount pushed. */
  3055. arg_size[i].constant
  3056. -= ((partial[i] * UNITS_PER_WORD)
  3057. / (PARM_BOUNDARY / BITS_PER_UNIT)
  3058. * (PARM_BOUNDARY / BITS_PER_UNIT));
  3059. args_size.constant += arg_size[i].constant;
  3060. if (arg_size[i].var)
  3061. {
  3062. ADD_PARM_SIZE (args_size, arg_size[i].var);
  3063. }
  3064. }
  3065. /* If we have no actual push instructions, or we need a variable
  3066. amount of space, make space for all the args right now.
  3067. In any case, round the needed size up to multiple of STACK_BOUNDARY. */
  3068. if (args_size.var != 0)
  3069. {
  3070. old_stack_level = copy_to_mode_reg (Pmode, stack_pointer_rtx);
  3071. old_pending_adj = pending_stack_adjust;
  3072. argblock = push_block (round_push (ARGS_SIZE_RTX (args_size)));
  3073. }
  3074. else if (args_size.constant != 0)
  3075. {
  3076. int needed = args_size.constant;
  3077. #ifdef STACK_BOUNDARY
  3078. needed = (needed + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES;
  3079. args_size.constant = needed;
  3080. #endif
  3081. #ifndef PUSH_ROUNDING
  3082. /* Try to reuse some or all of the pending_stack_adjust
  3083. to get this space. Maybe we can avoid any pushing. */
  3084. if (needed > pending_stack_adjust)
  3085. {
  3086. needed -= pending_stack_adjust;
  3087. pending_stack_adjust = 0;
  3088. }
  3089. else
  3090. {
  3091. pending_stack_adjust -= needed;
  3092. needed = 0;
  3093. }
  3094. if (needed > 0)
  3095. argblock = push_block (gen_rtx (CONST_INT, VOIDmode, needed));
  3096. #endif /* no PUSH_ROUNDING */
  3097. }
  3098. /* Get the function to call, in the form of RTL. */
  3099. if (fndecl)
  3100. /* Get a SYMBOL_REF rtx for the function address. */
  3101. funexp = XEXP (DECL_RTL (fndecl), 0);
  3102. else
  3103. /* Generate an rtx (probably a pseudo-register) for the address. */
  3104. funexp = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
  3105. /* Now actually compute the args, and push those that need pushing. */
  3106. for (i = 0; i < num_actuals; i++)
  3107. {
  3108. register tree p = argvec[i];
  3109. register tree pval = TREE_VALUE (p);
  3110. int used = 0;
  3111. /* Push the next argument. Note that it has already been converted
  3112. if necessary to the type that the called function expects. */
  3113. if (TREE_CODE (pval) == ERROR_MARK)
  3114. ;
  3115. else if (regvec[i] != 0 && partial[i] == 0)
  3116. {
  3117. /* Being passed entirely in a register. */
  3118. if (valvec[i] != 0)
  3119. {
  3120. if (GET_MODE (valvec[i]) == BLKmode)
  3121. move_block_to_reg (REGNO (regvec[i]), valvec[i],
  3122. (int_size_in_bytes (TREE_TYPE (pval))
  3123. / UNITS_PER_WORD));
  3124. else
  3125. emit_move_insn (regvec[i], valvec[i]);
  3126. }
  3127. else
  3128. store_expr (pval, regvec[i], 0);
  3129. /* Don't allow anything left on stack from computation
  3130. of argument to alloca. */
  3131. if (may_be_alloca)
  3132. do_pending_stack_adjust ();
  3133. }
  3134. else if (TYPE_MODE (TREE_TYPE (pval)) != BLKmode)
  3135. {
  3136. register int size;
  3137. rtx tem;
  3138. /* Argument is a scalar, not entirely passed in registers.
  3139. (If part is passed in registers, partial[I] says how much
  3140. and emit_push_insn will take care of putting it there.)
  3141. Push it, and if its size is less than the
  3142. amount of space allocated to it,
  3143. also bump stack pointer by the additional space.
  3144. Note that in C the default argument promotions
  3145. will prevent such mismatches. */
  3146. used = size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (pval)));
  3147. /* Compute how much space the push instruction will push.
  3148. On many machines, pushing a byte will advance the stack
  3149. pointer by a halfword. */
  3150. #ifdef PUSH_ROUNDING
  3151. size = PUSH_ROUNDING (size);
  3152. #endif
  3153. /* Compute how much space the argument should get:
  3154. round up to a multiple of the alignment for arguments. */
  3155. used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
  3156. / (PARM_BOUNDARY / BITS_PER_UNIT))
  3157. * (PARM_BOUNDARY / BITS_PER_UNIT));
  3158. tem = valvec[i];
  3159. if (tem == 0)
  3160. tem = expand_expr (pval, 0, VOIDmode, 0);
  3161. /* Don't allow anything left on stack from computation
  3162. of argument to alloca. */
  3163. if (may_be_alloca)
  3164. do_pending_stack_adjust ();
  3165. emit_push_insn (tem, TYPE_MODE (TREE_TYPE (pval)), 0, 0,
  3166. partial[i], regvec[i], used - size,
  3167. argblock, ARGS_SIZE_RTX (arg_offset[i]));
  3168. }
  3169. else
  3170. {
  3171. register rtx tem
  3172. = valvec[i] ? valvec[i] : expand_expr (pval, 0, VOIDmode, 0);
  3173. register int excess;
  3174. rtx size_rtx;
  3175. /* Pushing a nonscalar.
  3176. If part is passed in registers, partial[I] says how much
  3177. and emit_push_insn will take care of putting it there. */
  3178. /* Round its size up to a multiple
  3179. of the allocation unit for arguments. */
  3180. if (arg_size[i].var != 0)
  3181. {
  3182. excess = 0;
  3183. size_rtx = ARGS_SIZE_RTX (arg_size[i]);
  3184. }
  3185. else
  3186. {
  3187. register tree size = size_in_bytes (TREE_TYPE (pval));
  3188. /* PUSH_ROUNDING has no effect on us, because
  3189. emit_push_insn for BLKmode is careful to avoid it. */
  3190. excess = arg_size[i].constant - TREE_INT_CST_LOW (size);
  3191. size_rtx = expand_expr (size, 0, VOIDmode, 0);
  3192. }
  3193. emit_push_insn (tem, TYPE_MODE (TREE_TYPE (pval)), size_rtx,
  3194. TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT,
  3195. partial[i], regvec[i], excess, argblock,
  3196. ARGS_SIZE_RTX (arg_offset[i]));
  3197. }
  3198. /* Account for the stack space thus used. */
  3199. current_args_size += arg_size[i].constant;
  3200. if (arg_size[i].var)
  3201. current_args_size += 1;
  3202. }
  3203. /* Perform postincrements before actually calling the function. */
  3204. emit_queue ();
  3205. /* Pass the function the address in which to return a structure value. */
  3206. if (structure_value_addr)
  3207. emit_move_insn (struct_value_rtx, structure_value_addr);
  3208. /* All arguments and registers used for the call must be set up by now! */
  3209. /* ??? Other languages need a nontrivial second argument (static chain). */
  3210. funexp = prepare_call_address (funexp, 0);
  3211. /* Mark all register-parms as living through the call.
  3212. ??? This is not quite correct, since it doesn't indicate
  3213. that they are in use immediately before the call insn.
  3214. Currently that doesn't matter since explicitly-used regs
  3215. won't be used for reloading. But if the reloader becomes smarter,
  3216. this will have to change somehow. */
  3217. for (i = 0; i < num_actuals; i++)
  3218. if (regvec[i] != 0)
  3219. {
  3220. if (partial[i] > 0)
  3221. use_regs (REGNO (regvec[i]), partial[i]);
  3222. else if (GET_MODE (regvec[i]) == BLKmode)
  3223. use_regs (REGNO (regvec[i]),
  3224. (int_size_in_bytes (TREE_TYPE (TREE_VALUE (argvec[i])))
  3225. / UNITS_PER_WORD));
  3226. else
  3227. emit_insn (gen_rtx (USE, VOIDmode, regvec[i]));
  3228. }
  3229. if (structure_value_addr)
  3230. emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
  3231. /* Figure out the register where the value, if any, will come back. */
  3232. valreg = 0;
  3233. if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
  3234. && TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
  3235. valreg = hard_function_value (TREE_TYPE (exp), fndecl);
  3236. /* Generate the actual call instruction. */
  3237. emit_call_1 (funexp, funtype, args_size.constant,
  3238. FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
  3239. valreg, old_current_args_size);
  3240. /* ??? Nothing has been done here to record control flow
  3241. when contained functions can do nonlocal gotos. */
  3242. /* For calls to `setjmp', etc., inform flow.c it should complain
  3243. if nonvolatile values are live. */
  3244. if (is_setjmp)
  3245. emit_note (IDENTIFIER_POINTER (DECL_NAME (fndecl)), NOTE_INSN_SETJMP);
  3246. /* If size of args is variable, restore saved stack-pointer value. */
  3247. if (args_size.var != 0)
  3248. {
  3249. emit_move_insn (stack_pointer_rtx, old_stack_level);
  3250. pending_stack_adjust = old_pending_adj;
  3251. }
  3252. /* If value type not void, return an rtx for the value. */
  3253. if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
  3254. || ignore)
  3255. return 0;
  3256. if (structure_value_addr)
  3257. {
  3258. if (target)
  3259. return target;
  3260. return gen_rtx (MEM, BLKmode,
  3261. memory_address (BLKmode, structure_value_addr));
  3262. }
  3263. if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp)))
  3264. {
  3265. if (!rtx_equal_p (target, valreg))
  3266. emit_move_insn (target, valreg);
  3267. else
  3268. /* This tells expand_inline_function to copy valreg to its target. */
  3269. emit_insn (gen_rtx (USE, VOIDmode, valreg));
  3270. return target;
  3271. }
  3272. return copy_to_reg (valreg);
  3273. }
  3274. /* Expand conditional expressions. */
  3275. /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
  3276. LABEL is an rtx of code CODE_LABEL, in this function and all the
  3277. functions here. */
  3278. void
  3279. jumpifnot (exp, label)
  3280. tree exp;
  3281. rtx label;
  3282. {
  3283. do_jump (exp, label, 0);
  3284. }
  3285. /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
  3286. void
  3287. jumpif (exp, label)
  3288. tree exp;
  3289. rtx label;
  3290. {
  3291. do_jump (exp, 0, label);
  3292. }
  3293. /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
  3294. the result is zero, or IF_TRUE_LABEL if the result is one.
  3295. Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
  3296. meaning fall through in that case.
  3297. This function is responsible for optimizing cases such as
  3298. &&, || and comparison operators in EXP. */
  3299. void
  3300. do_jump (exp, if_false_label, if_true_label)
  3301. tree exp;
  3302. rtx if_false_label, if_true_label;
  3303. {
  3304. register enum tree_code code = TREE_CODE (exp);
  3305. /* Some cases need to create a label to jump to
  3306. in order to properly fall through.
  3307. These cases set DROP_THROUGH_LABEL nonzero. */
  3308. rtx drop_through_label = 0;
  3309. rtx temp;
  3310. rtx comparison = 0;
  3311. emit_queue ();
  3312. switch (code)
  3313. {
  3314. case ERROR_MARK:
  3315. break;
  3316. case INTEGER_CST:
  3317. temp = integer_zerop (exp) ? if_false_label : if_true_label;
  3318. if (temp)
  3319. emit_jump (temp);
  3320. break;
  3321. case ADDR_EXPR:
  3322. /* The address of something can never be zero. */
  3323. if (if_true_label)
  3324. emit_jump (if_true_label);
  3325. break;
  3326. case NOP_EXPR:
  3327. do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
  3328. break;
  3329. case TRUTH_NOT_EXPR:
  3330. do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
  3331. break;
  3332. case TRUTH_ANDIF_EXPR:
  3333. if (if_false_label == 0)
  3334. if_false_label = drop_through_label = gen_label_rtx ();
  3335. do_jump (TREE_OPERAND (exp, 0), if_false_label, 0);
  3336. do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
  3337. break;
  3338. case TRUTH_ORIF_EXPR:
  3339. if (if_true_label == 0)
  3340. if_true_label = drop_through_label = gen_label_rtx ();
  3341. do_jump (TREE_OPERAND (exp, 0), 0, if_true_label);
  3342. do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
  3343. break;
  3344. case COMPOUND_EXPR:
  3345. expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
  3346. emit_queue ();
  3347. do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
  3348. break;
  3349. case COND_EXPR:
  3350. {
  3351. register rtx label1 = gen_label_rtx ();
  3352. drop_through_label = gen_label_rtx ();
  3353. do_jump (TREE_OPERAND (exp, 0), label1, 0);
  3354. /* Now the THEN-expression. */
  3355. do_jump (TREE_OPERAND (exp, 1),
  3356. if_false_label ? if_false_label : drop_through_label,
  3357. if_true_label ? if_true_label : drop_through_label);
  3358. emit_label (label1);
  3359. /* Now the ELSE-expression. */
  3360. do_jump (TREE_OPERAND (exp, 2),
  3361. if_false_label ? if_false_label : drop_through_label,
  3362. if_true_label ? if_true_label : drop_through_label);
  3363. }
  3364. break;
  3365. case EQ_EXPR:
  3366. comparison = compare (exp, EQ, EQ, EQ, EQ);
  3367. break;
  3368. case NE_EXPR:
  3369. comparison = compare (exp, NE, NE, NE, NE);
  3370. break;
  3371. case LT_EXPR:
  3372. comparison = compare (exp, LT, LTU, GT, GTU);
  3373. break;
  3374. case LE_EXPR:
  3375. comparison = compare (exp, LE, LEU, GE, GEU);
  3376. break;
  3377. case GT_EXPR:
  3378. comparison = compare (exp, GT, GTU, LT, LTU);
  3379. break;
  3380. case GE_EXPR:
  3381. comparison = compare (exp, GE, GEU, LE, LEU);
  3382. break;
  3383. default:
  3384. temp = expand_expr (exp, 0, VOIDmode, 0);
  3385. /* Copy to register to avoid generating bad insns by cse
  3386. from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
  3387. if (!cse_not_expected && GET_CODE (temp) == MEM)
  3388. temp = copy_to_reg (temp);
  3389. do_pending_stack_adjust ();
  3390. {
  3391. rtx zero;
  3392. if (GET_MODE (temp) == SFmode)
  3393. zero = fconst0_rtx;
  3394. else if (GET_MODE (temp) == DFmode)
  3395. zero = dconst0_rtx;
  3396. else
  3397. zero = const0_rtx;
  3398. if (GET_CODE (temp) == CONST_INT)
  3399. comparison = compare_constants (NE, 0,
  3400. INTVAL (temp), 0, BITS_PER_WORD);
  3401. else if (GET_MODE (temp) != VOIDmode)
  3402. comparison = compare1 (temp, zero, NE, NE, 0, GET_MODE (temp));
  3403. else
  3404. abort ();
  3405. }
  3406. }
  3407. /* Do any postincrements in the expression that was tested. */
  3408. emit_queue ();
  3409. /* If COMPARISON is nonzero here, it is an rtx that can be substituted
  3410. straight into a conditional jump instruction as the jump condition.
  3411. Otherwise, all the work has been done already. */
  3412. if (comparison == const1_rtx)
  3413. {
  3414. if (if_true_label)
  3415. emit_jump (if_true_label);
  3416. }
  3417. else if (comparison == const0_rtx)
  3418. {
  3419. if (if_false_label)
  3420. emit_jump (if_false_label);
  3421. }
  3422. else if (comparison)
  3423. {
  3424. if (if_true_label)
  3425. {
  3426. emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
  3427. gen_rtx (IF_THEN_ELSE, VOIDmode, comparison,
  3428. gen_rtx (LABEL_REF, VOIDmode,
  3429. if_true_label),
  3430. pc_rtx)));
  3431. if (if_false_label)
  3432. emit_jump (if_false_label);
  3433. }
  3434. else if (if_false_label)
  3435. {
  3436. emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
  3437. gen_rtx (IF_THEN_ELSE, VOIDmode, comparison,
  3438. pc_rtx,
  3439. gen_rtx (LABEL_REF, VOIDmode,
  3440. if_false_label))));
  3441. }
  3442. }
  3443. if (drop_through_label)
  3444. emit_label (drop_through_label);
  3445. }
  3446. /* Compare two integer constant rtx's, OP0 and OP1.
  3447. The comparison operation is OPERATION.
  3448. Return an rtx representing the value 1 or 0.
  3449. WIDTH is the width in bits that is significant. */
  3450. static rtx
  3451. compare_constants (operation, unsignedp, op0, op1, width)
  3452. enum rtx_code operation;
  3453. int unsignedp;
  3454. int op0, op1;
  3455. int width;
  3456. {
  3457. int val;
  3458. /* Sign-extend or zero-extend the operands to a full word
  3459. from an initial width of WIDTH bits. */
  3460. if (width < HOST_BITS_PER_INT)
  3461. {
  3462. op0 &= (1 << width) - 1;
  3463. op1 &= (1 << width) - 1;
  3464. if (! unsignedp)
  3465. {
  3466. if (op0 & (1 << (width - 1)))
  3467. op0 |= ((-1) << width);
  3468. if (op1 & (1 << (width - 1)))
  3469. op1 |= ((-1) << width);
  3470. }
  3471. }
  3472. switch (operation)
  3473. {
  3474. case EQ:
  3475. val = op0 == op1;
  3476. break;
  3477. case NE:
  3478. val = op0 != op1;
  3479. break;
  3480. case GT:
  3481. case GTU:
  3482. val = op0 > op1;
  3483. break;
  3484. case LT:
  3485. case LTU:
  3486. val = op0 < op1;
  3487. break;
  3488. case GE:
  3489. case GEU:
  3490. val = op0 >= op1;
  3491. break;
  3492. case LE:
  3493. case LEU:
  3494. val = op0 <= op1;
  3495. }
  3496. return val ? const1_rtx : const0_rtx;
  3497. }
  3498. /* Generate code for a comparison expression EXP
  3499. (including code to compute the values to be compared)
  3500. and set (CC0) according to the result.
  3501. SIGNED_FORWARD should be the rtx operation for this comparison for
  3502. signed data; UNSIGNED_FORWARD, likewise for use if data is unsigned.
  3503. SIGNED_REVERSE and UNSIGNED_REVERSE are used if it is desirable
  3504. to interchange the operands for the compare instruction.
  3505. We force a stack adjustment unless there are currently
  3506. things pushed on the stack that aren't yet used. */
  3507. static rtx
  3508. compare (exp, signed_forward, unsigned_forward,
  3509. signed_reverse, unsigned_reverse)
  3510. register tree exp;
  3511. enum rtx_code signed_forward, unsigned_forward;
  3512. enum rtx_code signed_reverse, unsigned_reverse;
  3513. {
  3514. register rtx op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
  3515. register rtx op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
  3516. register enum machine_mode mode = GET_MODE (op0);
  3517. int unsignedp;
  3518. /* If one operand is 0, make it the second one. */
  3519. if (op0 == const0_rtx || op0 == fconst0_rtx || op0 == dconst0_rtx)
  3520. {
  3521. rtx tem = op0;
  3522. op0 = op1;
  3523. op1 = tem;
  3524. signed_forward = signed_reverse;
  3525. unsigned_forward = unsigned_reverse;
  3526. }
  3527. if (flag_force_mem)
  3528. {
  3529. op0 = force_not_mem (op0);
  3530. op1 = force_not_mem (op1);
  3531. }
  3532. do_pending_stack_adjust ();
  3533. unsignedp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
  3534. || TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))));
  3535. if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
  3536. return compare_constants (signed_forward, unsignedp,
  3537. INTVAL (op0), INTVAL (op1),
  3538. GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))));
  3539. emit_cmp_insn (op0, op1,
  3540. (mode == BLKmode) ? expr_size (TREE_OPERAND (exp, 0)) : 0,
  3541. unsignedp);
  3542. return gen_rtx ((unsignedp ? unsigned_forward : signed_forward),
  3543. VOIDmode, cc0_rtx, const0_rtx);
  3544. }
  3545. /* Like compare but expects the values to compare as two rtx's.
  3546. The decision as to signed or unsigned comparison must be made by the caller.
  3547. BLKmode is not allowed. */
  3548. static rtx
  3549. compare1 (op0, op1, forward_op, reverse_op, unsignedp, mode)
  3550. register rtx op0, op1;
  3551. enum rtx_code forward_op, reverse_op;
  3552. int unsignedp;
  3553. enum machine_mode mode;
  3554. {
  3555. /* If one operand is 0, make it the second one. */
  3556. if (op0 == const0_rtx || op0 == fconst0_rtx || op0 == dconst0_rtx)
  3557. {
  3558. rtx tem = op0;
  3559. op0 = op1;
  3560. op1 = tem;
  3561. forward_op = reverse_op;
  3562. }
  3563. if (flag_force_mem)
  3564. {
  3565. op0 = force_not_mem (op0);
  3566. op1 = force_not_mem (op1);
  3567. }
  3568. do_pending_stack_adjust ();
  3569. if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
  3570. return compare_constants (forward_op, unsignedp,
  3571. INTVAL (op0), INTVAL (op1),
  3572. GET_MODE_BITSIZE (mode));
  3573. emit_cmp_insn (op0, op1, 0, unsignedp);
  3574. return gen_rtx (forward_op, VOIDmode, cc0_rtx, const0_rtx);
  3575. }
  3576. /* Generate code to calculate EXP using a store-flag instruction
  3577. and return an rtx for the result.
  3578. If TARGET is nonzero, store the result there if convenient.
  3579. Return zero if there is no suitable set-flag instruction
  3580. available on this machine. */
  3581. static rtx
  3582. do_store_flag (exp, target, mode)
  3583. tree exp;
  3584. rtx target;
  3585. enum machine_mode mode;
  3586. {
  3587. register enum tree_code code = TREE_CODE (exp);
  3588. register rtx comparison = 0;
  3589. enum machine_mode compare_mode;
  3590. switch (code)
  3591. {
  3592. #ifdef HAVE_seq
  3593. case EQ_EXPR:
  3594. if (HAVE_seq)
  3595. {
  3596. comparison = compare (exp, EQ, EQ, EQ, EQ);
  3597. compare_mode = insn_operand_mode[(int) CODE_FOR_seq][0];
  3598. }
  3599. break;
  3600. #endif
  3601. #ifdef HAVE_sne
  3602. case NE_EXPR:
  3603. if (HAVE_sne)
  3604. {
  3605. comparison = compare (exp, NE, NE, NE, NE);
  3606. compare_mode = insn_operand_mode[(int) CODE_FOR_sne][0];
  3607. }
  3608. break;
  3609. #endif
  3610. #if defined (HAVE_slt) && defined (HAVE_sltu) && defined (HAVE_sgt) && defined (HAVE_sgtu)
  3611. case LT_EXPR:
  3612. if (HAVE_slt && HAVE_sltu && HAVE_sgt && HAVE_sgtu)
  3613. {
  3614. comparison = compare (exp, LT, LTU, GT, GTU);
  3615. compare_mode = insn_operand_mode[(int) CODE_FOR_slt][0];
  3616. }
  3617. break;
  3618. case GT_EXPR:
  3619. if (HAVE_slt && HAVE_sltu && HAVE_sgt && HAVE_sgtu)
  3620. {
  3621. comparison = compare (exp, GT, GTU, LT, LTU);
  3622. compare_mode = insn_operand_mode[(int) CODE_FOR_slt][0];
  3623. }
  3624. break;
  3625. #endif
  3626. #if defined (HAVE_sle) && defined (HAVE_sleu) && defined (HAVE_sge) && defined (HAVE_sgeu)
  3627. case LE_EXPR:
  3628. if (HAVE_sle && HAVE_sleu && HAVE_sge && HAVE_sgeu)
  3629. {
  3630. comparison = compare (exp, LE, LEU, GE, GEU);
  3631. compare_mode = insn_operand_mode[(int) CODE_FOR_sle][0];
  3632. }
  3633. break;
  3634. case GE_EXPR:
  3635. if (HAVE_sle && HAVE_sleu && HAVE_sge && HAVE_sgeu)
  3636. {
  3637. comparison = compare (exp, GE, GEU, LE, LEU);
  3638. compare_mode = insn_operand_mode[(int) CODE_FOR_sle][0];
  3639. }
  3640. break;
  3641. #endif
  3642. }
  3643. if (comparison == 0)
  3644. return 0;
  3645. if (target == 0 || GET_MODE (target) != mode
  3646. || (mode != compare_mode && GET_CODE (target) != REG))
  3647. target = gen_reg_rtx (mode);
  3648. /* Store the comparison in its proper mode. */
  3649. if (GET_MODE (target) != compare_mode)
  3650. emit_insn (gen_rtx (SET, VOIDmode,
  3651. gen_rtx (SUBREG, compare_mode, target, 0),
  3652. comparison));
  3653. else
  3654. emit_insn (gen_rtx (SET, VOIDmode, target, comparison));
  3655. #if STORE_FLAG_VALUE != 1
  3656. expand_bit_and (mode, target, const1_rtx, target);
  3657. #endif
  3658. return target;
  3659. }
  3660. /* Generate a tablejump instruction (used for switch statements). */
  3661. #ifdef HAVE_tablejump
  3662. /* INDEX is the value being switched on, with the lowest value
  3663. in the table already subtracted.
  3664. RANGE is the length of the jump table.
  3665. TABLE_LABEL is a CODE_LABEL rtx for the table itself.
  3666. DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
  3667. index value is out of range. */
  3668. void
  3669. do_tablejump (index, range, table_label, default_label)
  3670. rtx index, range, table_label, default_label;
  3671. {
  3672. register rtx temp;
  3673. emit_cmp_insn (range, index, 0);
  3674. emit_jump_insn (gen_bltu (default_label));
  3675. index = memory_address (CASE_VECTOR_MODE,
  3676. gen_rtx (PLUS, Pmode,
  3677. gen_rtx (MULT, Pmode, index,
  3678. gen_rtx (CONST_INT, VOIDmode,
  3679. GET_MODE_SIZE (CASE_VECTOR_MODE))),
  3680. gen_rtx (LABEL_REF, VOIDmode, table_label)));
  3681. temp = gen_reg_rtx (CASE_VECTOR_MODE);
  3682. convert_move (temp, gen_rtx (MEM, CASE_VECTOR_MODE, index), 0);
  3683. emit_jump_insn (gen_tablejump (temp, table_label));
  3684. }
  3685. #endif /* HAVE_tablejump */