stmt.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2. Copyright (C) 1987,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. /* This file handles the generation of rtl code from tree structure
  18. above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
  19. It also creates the rtl expressions for parameters and auto variables
  20. and has full responsibility for allocating stack slots.
  21. The functions whose names start with `expand_' are called by the
  22. parser to generate RTL instructions for various kinds of constructs.
  23. Some control and binding constructs require calling several such
  24. functions at different times. For example, a simple if-then
  25. is expanded by calling `expand_start_cond' (with the condition-expression
  26. as argument) before parsing the then-clause and calling `expand_end_cond'
  27. after parsing the then-clause.
  28. `expand_start_function' is called at the beginning of a function,
  29. before the function body is parsed, and `expand_end_function' is
  30. called after parsing the body.
  31. Call `assign_stack_local' to allocate a stack slot for a local variable.
  32. This is usually done during the RTL generation for the function body,
  33. but it can also be done in the reload pass when a pseudo-register does
  34. not get a hard register.
  35. Call `put_var_into_stack' when you learn, belatedly, that a variable
  36. previously given a pseudo-register must in fact go in the stack.
  37. This function changes the DECL_RTL to be a stack slot instead of a reg
  38. then scans all the RTL instructions so far generated to correct them. */
  39. #include "config.h"
  40. #include <stdio.h>
  41. #include "rtl.h"
  42. #include "tree.h"
  43. #include "flags.h"
  44. #include "insn-flags.h"
  45. #include "insn-config.h"
  46. #include "expr.h"
  47. #include "regs.h"
  48. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  49. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  50. /* Nonzero if function being compiled pops its args on return.
  51. May affect compilation of return insn or of function epilogue. */
  52. int current_function_pops_args;
  53. /* If function's args have a fixed size, this is that size, in bytes.
  54. Otherwise, it is -1.
  55. May affect compilation of return insn or of function epilogue. */
  56. int current_function_args_size;
  57. /* # bytes the prologue should push and pretend that the caller pushed them.
  58. The prologue must do this, but only if parms can be passed in registers. */
  59. int current_function_pretend_args_size;
  60. /* Name of function now being compiled. */
  61. char *current_function_name;
  62. /* Label that will go on function epilogue.
  63. Jumping to this label serves as a "return" instruction
  64. on machines which require execution of the epilogue on all returns. */
  65. rtx return_label;
  66. /* The FUNCTION_DECL node for the function being compiled. */
  67. static tree this_function;
  68. /* Offset to end of allocated area of stack frame.
  69. If stack grows down, this is the address of the last stack slot allocated.
  70. If stack grows up, this is the address for the next slot. */
  71. static int frame_offset;
  72. /* Nonzero if a stack slot has been generated whose address is not
  73. actually valid. It means that the generated rtl must all be scanned
  74. to detect and correct the invalid addresses where they occur. */
  75. static int invalid_stack_slot;
  76. /* Label to jump back to for tail recursion, or 0 if we have
  77. not yet needed one for this function. */
  78. static rtx tail_recursion_label;
  79. /* Place after which to insert the tail_recursion_label if we need one. */
  80. static rtx tail_recursion_reentry;
  81. /* Each time we expand an expression-statement,
  82. record the expr's type and its RTL value here. */
  83. static tree last_expr_type;
  84. static rtx last_expr_value;
  85. static void fixup_gotos ();
  86. static int tail_recursion_args ();
  87. void fixup_stack_slots ();
  88. static rtx fixup_stack_1 ();
  89. static rtx fixup_memory_subreg ();
  90. static void fixup_var_refs ();
  91. static rtx fixup_var_refs_1 ();
  92. static rtx parm_stack_loc ();
  93. static void optimize_bit_field ();
  94. void do_jump_if_equal ();
  95. /* Stack of control and binding constructs we are currently inside.
  96. These constructs begin when you call `expand_start_WHATEVER'
  97. and end when you call `expand_end_WHATEVER'. This stack records
  98. info about how the construct began that tells the end-function
  99. what to do. It also may provide information about the construct
  100. to alter the behavior of other constructs within the body.
  101. For example, they may affect the behavior of C `break' and `continue'.
  102. Each construct gets one `struct nesting' object.
  103. All of these objects are chained through the `all' field.
  104. `nesting_stack' points to the first object (innermost construct).
  105. The position of an entry on `nesting_stack' is in its `depth' field.
  106. Each type of construct has its own individual stack.
  107. For example, loops have `loop_stack'. Each object points to the
  108. next object of the same type through the `next' field.
  109. Some constructs are visible to `break' exit-statements and others
  110. are not. Which constructs are visible depends on the language.
  111. Therefore, the data structure allows each construct to be visible
  112. or not, according to the args given when the construct is started.
  113. The construct is visible if the `exit_label' field is non-null.
  114. In that case, the value should be a CODE_LABEL rtx. */
  115. struct nesting
  116. {
  117. struct nesting *all;
  118. struct nesting *next;
  119. int depth;
  120. rtx exit_label;
  121. union
  122. {
  123. /* For conds (if-then and if-then-else statements). */
  124. struct
  125. {
  126. /* Label on the else-part, if any, else 0. */
  127. rtx else_label;
  128. /* Label at the end of the whole construct. */
  129. rtx after_label;
  130. } cond;
  131. /* For loops. */
  132. struct
  133. {
  134. /* Label at the top of the loop; place to loop back to. */
  135. rtx start_label;
  136. /* Label at the end of the whole construct. */
  137. rtx end_label;
  138. /* Label for `continue' statement to jump to;
  139. this is in front of the stepper of the loop. */
  140. rtx continue_label;
  141. } loop;
  142. /* For variable binding contours. */
  143. struct
  144. {
  145. /* Nonzero => value to restore stack to on exit. */
  146. rtx stack_level;
  147. /* The NOTE that starts this contour.
  148. Used by expand_goto to check whether the destination
  149. is within each contour or not. */
  150. rtx first_insn;
  151. /* Innermost containing binding contour that has a stack level. */
  152. struct nesting *innermost_stack_block;
  153. /* Chain of labels defined inside this binding contour.
  154. Only for contours that have stack levels. */
  155. struct label_chain *label_chain;
  156. } block;
  157. /* For switch (C) or case (Pascal) statements,
  158. and also for dummies (see `expand_start_case_dummy'). */
  159. struct
  160. {
  161. /* The insn after which the case dispatch should finally
  162. be emitted. Zero for a dummy. */
  163. rtx start;
  164. /* A list of the case-values and their labels.
  165. A chain of TREE_LIST nodes with the value to test for
  166. (a constant node) in the TREE_PURPOSE and the
  167. label (a LABEL_DECL) in the TREE_VALUE. */
  168. tree case_list;
  169. /* The expression to be dispatched on. */
  170. tree index_expr;
  171. /* Type that INDEX_EXPR should be converted to. */
  172. tree nominal_type;
  173. } case_stmt;
  174. } data;
  175. };
  176. /* Chain of all pending binding contours. */
  177. struct nesting *block_stack;
  178. /* Chain of all pending binding contours that restore stack levels. */
  179. struct nesting *stack_block_stack;
  180. /* Chain of all pending conditional statements. */
  181. struct nesting *cond_stack;
  182. /* Chain of all pending loops. */
  183. struct nesting *loop_stack;
  184. /* Chain of all pending case or switch statements. */
  185. struct nesting *case_stack;
  186. /* Separate chain including all of the above,
  187. chained through the `all' field. */
  188. struct nesting *nesting_stack;
  189. /* Number of entries on nesting_stack now. */
  190. int nesting_depth;
  191. /* Pop one of the sub-stacks, such as `loop_stack' or `cond_stack';
  192. and pop off `nesting_stack' down to the same level. */
  193. #define POPSTACK(STACK) \
  194. do { int initial_depth = nesting_stack->depth; \
  195. do { struct nesting *this = STACK; \
  196. STACK = this->next; \
  197. nesting_stack = this->all; \
  198. nesting_depth = this->depth; \
  199. free (this); } \
  200. while (nesting_depth > initial_depth); } while (0)
  201. /* Return the rtx-label that corresponds to a LABEL_DECL,
  202. creating it if necessary. */
  203. static rtx
  204. label_rtx (label)
  205. tree label;
  206. {
  207. if (TREE_CODE (label) != LABEL_DECL)
  208. abort ();
  209. if (DECL_RTL (label))
  210. return DECL_RTL (label);
  211. return DECL_RTL (label) = gen_label_rtx ();
  212. }
  213. /* Add an unconditional jump to LABEL as the next sequential instruction. */
  214. void
  215. emit_jump (label)
  216. rtx label;
  217. {
  218. do_pending_stack_adjust ();
  219. emit_jump_insn (gen_jump (label));
  220. emit_barrier ();
  221. }
  222. /* Handle goto statements and the labels that they can go to. */
  223. /* In some cases it is impossible to generate code for a forward goto
  224. until the label definition is seen. This happens when it may be necessary
  225. for the goto to reset the stack pointer: we don't yet know how to do that.
  226. So expand_goto puts an entry on this fixup list.
  227. Each time a binding contour that resets the stack is exited,
  228. we check each fixup.
  229. If the target label has now been defined, we can insert the proper code. */
  230. struct goto_fixup
  231. {
  232. /* Points to following fixup. */
  233. struct goto_fixup *next;
  234. /* Points to the insn before the jump insn.
  235. If more code must be inserted, it goes after this insn. */
  236. rtx before_jump;
  237. /* The LABEL_DECL that this jump is jumping to. */
  238. tree target;
  239. /* The outermost stack level that should be restored for this jump.
  240. Each time a binding contour that resets the stack is exited,
  241. if the target label is *not* yet defined, this slot is updated. */
  242. rtx stack_level;
  243. };
  244. static struct goto_fixup *goto_fixup_chain;
  245. /* Within any binding contour that must restore a stack level,
  246. all labels are recorded with a chain of these structures. */
  247. struct label_chain
  248. {
  249. /* Points to following fixup. */
  250. struct label_chain *next;
  251. tree label;
  252. };
  253. /* Specify the location in the RTL code of a label BODY,
  254. which is a LABEL_DECL tree node.
  255. This is used for the kind of label that the user can jump to with a
  256. goto statement, and for alternatives of a switch or case statement.
  257. RTL labels generated for loops and conditionals don't go through here;
  258. they are generated directly at the RTL level, by other functions below.
  259. Note that this has nothing to do with defining label *names*.
  260. Languages vary in how they do that and what that even means. */
  261. void
  262. expand_label (body)
  263. tree body;
  264. {
  265. struct label_chain *p;
  266. do_pending_stack_adjust ();
  267. emit_label (label_rtx (body));
  268. if (stack_block_stack)
  269. {
  270. p = (struct label_chain *) oballoc (sizeof (struct label_chain));
  271. p->next = stack_block_stack->data.block.label_chain;
  272. stack_block_stack->data.block.label_chain = p;
  273. p->label = body;
  274. }
  275. }
  276. /* Generate RTL code for a `goto' statement with target label BODY.
  277. BODY should be a LABEL_DECL tree node that was or will later be
  278. defined with `expand_label'. */
  279. void
  280. expand_goto (body)
  281. tree body;
  282. {
  283. struct nesting *block;
  284. rtx stack_level = 0;
  285. rtx label = label_rtx (body);
  286. if (GET_CODE (label) != CODE_LABEL)
  287. abort ();
  288. /* If label has already been defined, we can tell now
  289. whether and how we must alter the stack level. */
  290. if (DECL_SOURCE_LINE (body) != 0)
  291. {
  292. /* Find the outermost pending block that contains the label.
  293. (Check containment by comparing insn-uids.)
  294. Then restore the outermost stack level within that block. */
  295. for (block = block_stack; block; block = block->next)
  296. {
  297. if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
  298. break;
  299. if (block->data.block.stack_level != 0)
  300. stack_level = block->data.block.stack_level;
  301. }
  302. if (stack_level)
  303. emit_move_insn (stack_pointer_rtx, stack_level);
  304. if (TREE_PACKED (body))
  305. error ("goto \"%s\" invalidly jumps into binding contour",
  306. IDENTIFIER_POINTER (DECL_NAME (body)));
  307. }
  308. /* Label not yet defined: may need to put this goto
  309. on the fixup list. */
  310. else
  311. {
  312. /* Does any containing block have a stack level?
  313. If not, no fixup is needed, and that is the normal case
  314. (the only case, for standard C). */
  315. for (block = block_stack; block; block = block->next)
  316. if (block->data.block.stack_level != 0)
  317. break;
  318. if (block)
  319. {
  320. /* Ok, a fixup is needed. Add a fixup to the list of such. */
  321. struct goto_fixup *fixup
  322. = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
  323. /* In case an old stack level is restored, make sure that comes
  324. after any pending stack adjust. */
  325. do_pending_stack_adjust ();
  326. fixup->before_jump = get_last_insn ();
  327. fixup->target = body;
  328. fixup->stack_level = 0;
  329. fixup->next = goto_fixup_chain;
  330. goto_fixup_chain = fixup;
  331. }
  332. else
  333. /* No fixup needed. Record that the label is the target
  334. of at least one goto that has no fixup. */
  335. TREE_ADDRESSABLE (body) = 1;
  336. }
  337. emit_jump (label);
  338. }
  339. /* When exiting a binding contour, process all pending gotos requiring fixups.
  340. STACK_LEVEL is the rtx for the stack level to restore on exit from
  341. this contour. FIRST_INSN is the insn that begain this contour.
  342. Gotos that jump out of this contour must restore the
  343. stack level before actually jumping.
  344. Also print an error message if any fixup describes a jump into this
  345. contour from before the beginning of the contour. */
  346. static void
  347. fixup_gotos (stack_level, first_insn)
  348. rtx stack_level;
  349. rtx first_insn;
  350. {
  351. register struct goto_fixup *f;
  352. for (f = goto_fixup_chain; f; f = f->next)
  353. {
  354. /* Test for a fixup that is inactive because it is already handled. */
  355. if (f->before_jump == 0)
  356. ;
  357. /* Has this fixup's target label been defined?
  358. If so, we can finalize it. */
  359. else if (DECL_SOURCE_LINE (f->target) != 0)
  360. {
  361. /* If this fixup jumped into this contour from before the beginning
  362. of this contour, report an error. */
  363. if (INSN_UID (first_insn) > INSN_UID (f->before_jump)
  364. && ! TREE_ADDRESSABLE (f->target))
  365. {
  366. error_with_file_and_line (DECL_SOURCE_FILE (f->target),
  367. DECL_SOURCE_LINE (f->target),
  368. "label \"%s\" was used \
  369. before containing binding contour",
  370. IDENTIFIER_POINTER (DECL_NAME (f->target)));
  371. /* Prevent multiple errors for one label. */
  372. TREE_ADDRESSABLE (f->target) = 1;
  373. }
  374. /* Restore stack level for the biggest contour that this
  375. jump jumps out of. */
  376. if (f->stack_level)
  377. emit_insn_after (gen_move_insn (stack_pointer_rtx, f->stack_level),
  378. f->before_jump);
  379. f->before_jump = 0;
  380. }
  381. /* Label has still not appeared. If we are exiting a block with
  382. a stack level to restore, mark this stack level as needing
  383. restoration when the fixup is later finalized. */
  384. else if (stack_level)
  385. f->stack_level = stack_level;
  386. }
  387. }
  388. /* Generate RTL for an asm statement (explicit assembler code).
  389. BODY is a STRING_CST node containing the assembler code text. */
  390. void
  391. expand_asm (body)
  392. tree body;
  393. {
  394. emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
  395. TREE_STRING_POINTER (body)));
  396. last_expr_type = 0;
  397. }
  398. /* Generate RTL for an asm statement with arguments.
  399. STRING is the instruction template.
  400. OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
  401. Each output or input has an expression in the TREE_VALUE and
  402. a constraint-string in the TREE_PURPOSE.
  403. Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
  404. Some elements of OUTPUTS may be replaced with trees representing temporary
  405. values. The caller should copy those temporary values to the originally
  406. specified lvalues.
  407. VOL nonzero means the insn is volatile; don't optimize it. */
  408. void
  409. expand_asm_operands (string, outputs, inputs, vol)
  410. tree string, outputs, inputs;
  411. int vol;
  412. {
  413. rtvec argvec, constraints;
  414. rtx body;
  415. int ninputs = list_length (inputs);
  416. int noutputs = list_length (outputs);
  417. int numargs = 0;
  418. tree tail;
  419. int i;
  420. if (ninputs + noutputs > MAX_RECOG_OPERANDS)
  421. {
  422. error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
  423. return;
  424. }
  425. for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  426. {
  427. tree val = TREE_VALUE (tail);
  428. /* If an output operand is not a variable or indirect ref,
  429. create a SAVE_EXPR which is a pseudo-reg
  430. to act as an intermediate temporary.
  431. Make the asm insn write into that, then copy it to
  432. the real output operand. */
  433. if (TREE_CODE (val) != VAR_DECL
  434. && TREE_CODE (val) != PARM_DECL
  435. && TREE_CODE (val) != INDIRECT_REF)
  436. TREE_VALUE (tail) = build (SAVE_EXPR, TREE_TYPE (val), val,
  437. gen_reg_rtx (TYPE_MODE (TREE_TYPE (val))));
  438. }
  439. /* Make vectors for the expression-rtx and constraint strings. */
  440. argvec = rtvec_alloc (ninputs);
  441. constraints = rtvec_alloc (ninputs);
  442. body = gen_rtx (ASM_OPERANDS, VOIDmode,
  443. TREE_STRING_POINTER (string), "", 0, argvec, constraints);
  444. body->volatil = vol;
  445. /* Eval the inputs and put them into ARGVEC.
  446. Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
  447. i = 0;
  448. for (tail = inputs; tail; tail = TREE_CHAIN (tail))
  449. {
  450. XVECEXP (body, 3, i) /* argvec */
  451. = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  452. XVECEXP (body, 4, i) /* constraints */
  453. = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
  454. TREE_STRING_POINTER (TREE_PURPOSE (tail)));
  455. i++;
  456. }
  457. /* Now, for each output, construct an rtx
  458. (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
  459. ARGVEC CONSTRAINTS))
  460. If there is more than one, put them inside a PARALLEL. */
  461. if (noutputs == 1)
  462. {
  463. tree val = TREE_VALUE (outputs);
  464. XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
  465. emit_insn (gen_rtx (SET, VOIDmode,
  466. expand_expr (val, 0, VOIDmode, 0),
  467. body));
  468. }
  469. else
  470. {
  471. body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (noutputs));
  472. for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  473. {
  474. tree val = TREE_VALUE (tail);
  475. XVECEXP (body, 0, i)
  476. = gen_rtx (SET, VOIDmode,
  477. expand_expr (val, 0, VOIDmode, 0),
  478. gen_rtx (ASM_OPERANDS, VOIDmode,
  479. TREE_STRING_POINTER (string),
  480. TREE_STRING_POINTER (TREE_PURPOSE (tail)),
  481. i, argvec, constraints));
  482. SET_SRC (XVECEXP (body, 0, i))->volatil = vol;
  483. }
  484. emit_insn (body);
  485. }
  486. last_expr_type = 0;
  487. }
  488. /* Nonzero if within a ({...}) grouping, in which case we must
  489. always compute a value for each expr-stmt in case it is the last one. */
  490. int expr_stmts_for_value;
  491. /* Generate RTL to evaluate the expression EXP
  492. and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
  493. void
  494. expand_expr_stmt (exp)
  495. tree exp;
  496. {
  497. last_expr_type = TREE_TYPE (exp);
  498. last_expr_value = expand_expr (exp, expr_stmts_for_value ? 0 : const0_rtx,
  499. VOIDmode, 0);
  500. emit_queue ();
  501. }
  502. /* Clear out the memory of the last expression evaluated. */
  503. void
  504. clear_last_expr ()
  505. {
  506. last_expr_type = 0;
  507. }
  508. /* Return a tree node that refers to the last expression evaluated.
  509. The nodes of that expression have been freed by now, so we cannot use them.
  510. But we don't want to do that anyway; the expression has already been
  511. evaluated and now we just want to use the value. So generate a SAVE_EXPR
  512. with the proper type and RTL value.
  513. If the last statement was not an expression,
  514. return something with type `void'. */
  515. tree
  516. get_last_expr ()
  517. {
  518. tree t;
  519. if (last_expr_type == 0)
  520. {
  521. last_expr_type = void_type_node;
  522. last_expr_value = const0_rtx;
  523. }
  524. t = build (RTL_EXPR, last_expr_type, NULL, NULL);
  525. RTL_EXPR_RTL (t) = last_expr_value;
  526. RTL_EXPR_SEQUENCE (t) = gen_sequence ();
  527. return t;
  528. }
  529. void
  530. expand_start_stmt_expr ()
  531. {
  532. extern int emit_to_sequence;
  533. expr_stmts_for_value++;
  534. emit_to_sequence++;
  535. }
  536. void
  537. expand_end_stmt_expr ()
  538. {
  539. extern int emit_to_sequence;
  540. expr_stmts_for_value--;
  541. emit_to_sequence--;
  542. }
  543. /* Generate RTL for the start of an if-then. COND is the expression
  544. whose truth should be tested.
  545. If EXITFLAG is nonzero, this conditional is visible to
  546. `exit_something'. */
  547. void
  548. expand_start_cond (cond, exitflag)
  549. tree cond;
  550. int exitflag;
  551. {
  552. struct nesting *thiscond
  553. = (struct nesting *) xmalloc (sizeof (struct nesting));
  554. /* Make an entry on cond_stack for the cond we are entering. */
  555. thiscond->next = cond_stack;
  556. thiscond->all = nesting_stack;
  557. thiscond->depth = ++nesting_depth;
  558. thiscond->data.cond.after_label = 0;
  559. thiscond->data.cond.else_label = gen_label_rtx ();
  560. thiscond->exit_label = exitflag ? thiscond->data.cond.else_label : 0;
  561. cond_stack = thiscond;
  562. nesting_stack = thiscond;
  563. do_jump (cond, thiscond->data.cond.else_label, NULL);
  564. }
  565. /* Generate RTL for the end of an if-then with no else-clause.
  566. Pop the record for it off of cond_stack. */
  567. void
  568. expand_end_cond ()
  569. {
  570. struct nesting *thiscond = cond_stack;
  571. do_pending_stack_adjust ();
  572. emit_label (thiscond->data.cond.else_label);
  573. POPSTACK (cond_stack);
  574. last_expr_type = 0;
  575. }
  576. /* Generate RTL between the then-clause and the else-clause
  577. of an if-then-else. */
  578. void
  579. expand_start_else ()
  580. {
  581. cond_stack->data.cond.after_label = gen_label_rtx ();
  582. if (cond_stack->exit_label != 0)
  583. cond_stack->exit_label = cond_stack->data.cond.after_label;
  584. emit_jump (cond_stack->data.cond.after_label);
  585. if (cond_stack->data.cond.else_label)
  586. emit_label (cond_stack->data.cond.else_label);
  587. }
  588. /* Generate RTL for the end of an if-then-else.
  589. Pop the record for it off of cond_stack. */
  590. void
  591. expand_end_else ()
  592. {
  593. struct nesting *thiscond = cond_stack;
  594. do_pending_stack_adjust ();
  595. /* Note: a syntax error can cause this to be called
  596. without first calling `expand_start_else'. */
  597. if (thiscond->data.cond.after_label)
  598. emit_label (thiscond->data.cond.after_label);
  599. POPSTACK (cond_stack);
  600. last_expr_type = 0;
  601. }
  602. /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
  603. loop should be exited by `exit_something'. This is a loop for which
  604. `expand_continue' will jump to the top of the loop.
  605. Make an entry on loop_stack to record the labels associated with
  606. this loop. */
  607. void
  608. expand_start_loop (exit_flag)
  609. int exit_flag;
  610. {
  611. register struct nesting *thisloop
  612. = (struct nesting *) xmalloc (sizeof (struct nesting));
  613. /* Make an entry on loop_stack for the loop we are entering. */
  614. thisloop->next = loop_stack;
  615. thisloop->all = nesting_stack;
  616. thisloop->depth = ++nesting_depth;
  617. thisloop->data.loop.start_label = gen_label_rtx ();
  618. thisloop->data.loop.end_label = gen_label_rtx ();
  619. thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
  620. thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
  621. loop_stack = thisloop;
  622. nesting_stack = thisloop;
  623. do_pending_stack_adjust ();
  624. emit_queue ();
  625. emit_note (0, NOTE_INSN_LOOP_BEG);
  626. emit_label (thisloop->data.loop.start_label);
  627. }
  628. /* Like expand_start_loop but for a loop where the continuation point
  629. (for expand_continue_loop) will be specified explicitly. */
  630. void
  631. expand_start_loop_continue_elsewhere (exit_flag)
  632. int exit_flag;
  633. {
  634. expand_start_loop (exit_flag);
  635. loop_stack->data.loop.continue_label = gen_label_rtx ();
  636. }
  637. /* Specify the continuation point for a loop started with
  638. expand_start_loop_continue_elsewhere.
  639. Use this at the point in the code to which a continue statement
  640. should jump. */
  641. void
  642. expand_loop_continue_here ()
  643. {
  644. do_pending_stack_adjust ();
  645. emit_label (loop_stack->data.loop.continue_label);
  646. }
  647. /* Finish a loop. Generate a jump back to the top and the loop-exit label.
  648. Pop the block off of loop_stack. */
  649. void
  650. expand_end_loop ()
  651. {
  652. register struct nesting *thisloop = loop_stack;
  653. register rtx insn = get_last_insn ();
  654. register rtx start_label = loop_stack->data.loop.start_label;
  655. do_pending_stack_adjust ();
  656. /* If optimizing, perhaps reorder the loop. If the loop
  657. starts with a conditional exit, roll that to the end
  658. where it will optimize together with the jump back. */
  659. if (optimize
  660. &&
  661. ! (GET_CODE (insn) == JUMP_INSN
  662. && GET_CODE (PATTERN (insn)) == SET
  663. && SET_DEST (PATTERN (insn)) == pc_rtx
  664. && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
  665. {
  666. /* Scan insns from the top of the loop looking for a qualified
  667. conditional exit. */
  668. for (insn = loop_stack->data.loop.start_label; insn; insn= NEXT_INSN (insn))
  669. if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
  670. && SET_DEST (PATTERN (insn)) == pc_rtx
  671. && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
  672. &&
  673. ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
  674. && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
  675. == loop_stack->data.loop.end_label))
  676. ||
  677. (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
  678. && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
  679. == loop_stack->data.loop.end_label))))
  680. break;
  681. if (insn != 0)
  682. {
  683. /* We found one. Move everything from there up
  684. to the end of the loop, and add a jump into the loop
  685. to jump to there. */
  686. register rtx newstart_label = gen_label_rtx ();
  687. emit_label_after (newstart_label, PREV_INSN (start_label));
  688. reorder_insns (start_label, insn, get_last_insn ());
  689. emit_jump_insn_after (gen_jump (start_label), PREV_INSN (newstart_label));
  690. emit_barrier_after (PREV_INSN (newstart_label));
  691. start_label = newstart_label;
  692. }
  693. }
  694. emit_jump (start_label);
  695. emit_note (0, NOTE_INSN_LOOP_END);
  696. emit_label (loop_stack->data.loop.end_label);
  697. POPSTACK (loop_stack);
  698. last_expr_type = 0;
  699. }
  700. /* Generate a jump to the current loop's continue-point.
  701. This is usually the top of the loop, but may be specified
  702. explicitly elsewhere. If not currently inside a loop,
  703. return 0 and do nothing; caller will print an error message. */
  704. int
  705. expand_continue_loop ()
  706. {
  707. last_expr_type = 0;
  708. if (loop_stack == 0)
  709. return 0;
  710. emit_jump (loop_stack->data.loop.continue_label);
  711. return 1;
  712. }
  713. /* Generate a jump to exit the current loop. If not currently inside a loop,
  714. return 0 and do nothing; caller will print an error message. */
  715. int
  716. expand_exit_loop ()
  717. {
  718. last_expr_type = 0;
  719. if (loop_stack == 0)
  720. return 0;
  721. emit_jump (loop_stack->data.loop.end_label);
  722. return 1;
  723. }
  724. /* Generate a conditional jump to exit the current loop if COND
  725. evaluates to zero. If not currently inside a loop,
  726. return 0 and do nothing; caller will print an error message. */
  727. int
  728. expand_exit_loop_if_false (cond)
  729. tree cond;
  730. {
  731. last_expr_type = 0;
  732. if (loop_stack == 0)
  733. return 0;
  734. do_jump (cond, loop_stack->data.loop.end_label, NULL);
  735. return 1;
  736. }
  737. /* Generate a jump to exit the current loop, conditional, binding contour
  738. or case statement. Not all such constructs are visible to this function,
  739. only those started with EXIT_FLAG nonzero. Individual languages use
  740. the EXIT_FLAG parameter to control which kinds of constructs you can
  741. exit this way.
  742. If not currently inside anything that can be exited,
  743. return 0 and do nothing; caller will print an error message. */
  744. int
  745. expand_exit_something ()
  746. {
  747. struct nesting *n;
  748. last_expr_type = 0;
  749. for (n = nesting_stack; n; n = n->all)
  750. {
  751. if (n->exit_label != 0)
  752. {
  753. emit_jump (n->exit_label);
  754. return 1;
  755. }
  756. }
  757. return 0;
  758. }
  759. /* Generate RTL to return from the current function, with no value.
  760. (That is, we do not do anything about returning any value.) */
  761. void
  762. expand_null_return ()
  763. {
  764. clear_pending_stack_adjust ();
  765. #ifdef FUNCTION_EPILOGUE
  766. emit_jump (return_label);
  767. #else
  768. emit_jump_insn (gen_return ());
  769. emit_barrier ();
  770. #endif
  771. last_expr_type = 0;
  772. }
  773. /* Generate RTL to evaluate the expression RETVAL and return it
  774. from the current function. */
  775. void
  776. expand_return (retval)
  777. tree retval;
  778. {
  779. register rtx val = 0;
  780. register rtx op0;
  781. int really_for_value =
  782. (TREE_CODE (retval) == MODIFY_EXPR
  783. && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL);
  784. /* For tail-recursive call to current function,
  785. just jump back to the beginning.
  786. It's unsafe if any auto variable in this function
  787. has its address taken; for simplicity,
  788. require stack frame to be empty. */
  789. if (optimize && really_for_value
  790. && frame_offset == 0
  791. && TREE_CODE (TREE_OPERAND (retval, 1)) == CALL_EXPR
  792. && TREE_CODE (TREE_OPERAND (TREE_OPERAND (retval, 1), 0)) == ADDR_EXPR
  793. && TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (retval, 1), 0), 0) == this_function
  794. /* Finish checking validity, and if valid emit code
  795. to set the argument variables for the new call. */
  796. && tail_recursion_args (TREE_OPERAND (TREE_OPERAND (retval, 1), 1),
  797. DECL_ARGUMENTS (this_function)))
  798. {
  799. ;
  800. if (tail_recursion_label == 0)
  801. {
  802. tail_recursion_label = gen_label_rtx ();
  803. emit_label_after (tail_recursion_label,
  804. tail_recursion_reentry);
  805. }
  806. emit_jump (tail_recursion_label);
  807. emit_barrier ();
  808. return;
  809. }
  810. #ifndef FUNCTION_EPILOGUE
  811. /* If this is return x == y; then generate
  812. if (x == y) return 1; else return 0;
  813. if we can do it with explicit return insns. */
  814. if (really_for_value)
  815. switch (TREE_CODE (TREE_OPERAND (retval, 1)))
  816. {
  817. case EQ_EXPR:
  818. case NE_EXPR:
  819. case GT_EXPR:
  820. case GE_EXPR:
  821. case LT_EXPR:
  822. case LE_EXPR:
  823. case TRUTH_ANDIF_EXPR:
  824. case TRUTH_ORIF_EXPR:
  825. case TRUTH_NOT_EXPR:
  826. op0 = gen_label_rtx ();
  827. val = DECL_RTL (DECL_RESULT (this_function));
  828. jumpifnot (TREE_OPERAND (retval, 1), op0);
  829. emit_move_insn (val, const1_rtx);
  830. emit_insn (gen_rtx (USE, VOIDmode, val));
  831. expand_null_return ();
  832. emit_label (op0);
  833. emit_move_insn (val, const0_rtx);
  834. emit_insn (gen_rtx (USE, VOIDmode, val));
  835. expand_null_return ();
  836. return;
  837. }
  838. #endif
  839. val = expand_expr (retval, 0, VOIDmode, 0);
  840. emit_queue ();
  841. if (really_for_value && GET_CODE (val) == REG)
  842. emit_insn (gen_rtx (USE, VOIDmode, val));
  843. expand_null_return ();
  844. }
  845. /* Return 1 if the end of the generated RTX is not a barrier.
  846. This means code already compiled can drop through. */
  847. int
  848. drop_through_at_end_p ()
  849. {
  850. rtx insn = get_last_insn ();
  851. while (insn && GET_CODE (insn) == NOTE)
  852. insn = PREV_INSN (insn);
  853. return insn && GET_CODE (insn) != BARRIER;
  854. }
  855. /* Emit code to alter this function's formal parms for a tail-recursive call.
  856. ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
  857. FORMALS is the chain of decls of formals.
  858. Return 1 if this can be done;
  859. otherwise return 0 and do not emit any code. */
  860. static int
  861. tail_recursion_args (actuals, formals)
  862. tree actuals, formals;
  863. {
  864. register tree a = actuals, f = formals;
  865. register int i;
  866. register rtx *argvec;
  867. /* Check that number and types of actuals are compatible
  868. with the formals. This is not always true in valid C code.
  869. Also check that no formal needs to be addressable
  870. and that all formals are scalars. */
  871. /* Also count the args. */
  872. for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
  873. {
  874. if (TREE_TYPE (TREE_VALUE (a)) != TREE_TYPE (f))
  875. return 0;
  876. if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
  877. return 0;
  878. }
  879. if (a != 0 || f != 0)
  880. return 0;
  881. /* Compute all the actuals. */
  882. argvec = (rtx *) alloca (i * sizeof (rtx));
  883. for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  884. argvec[i] = expand_expr (TREE_VALUE (a), 0, VOIDmode, 0);
  885. /* Find which actual values refer to current values of previous formals.
  886. Copy each of them now, before any formal is changed. */
  887. for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  888. {
  889. int copy = 0;
  890. register int j;
  891. for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
  892. if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
  893. { copy = 1; break; }
  894. if (copy)
  895. argvec[i] = copy_to_reg (argvec[i]);
  896. }
  897. /* Store the values of the actuals into the formals. */
  898. for (f = formals, a = actuals, i = 0; f;
  899. f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
  900. {
  901. if (DECL_MODE (f) == GET_MODE (argvec[i]))
  902. emit_move_insn (DECL_RTL (f), argvec[i]);
  903. else
  904. convert_move (DECL_RTL (f), argvec[i],
  905. TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
  906. }
  907. return 1;
  908. }
  909. /* Generate the RTL code for entering a binding contour.
  910. The variables are declared one by one, by calls to `expand_decl'.
  911. EXIT_FLAG is nonzero if this construct should be visible to
  912. `exit_something'. */
  913. void
  914. expand_start_bindings (exit_flag)
  915. int exit_flag;
  916. {
  917. struct nesting *thisblock
  918. = (struct nesting *) xmalloc (sizeof (struct nesting));
  919. rtx note = emit_note (0, NOTE_INSN_BLOCK_BEG);
  920. /* Make an entry on block_stack for the block we are entering. */
  921. thisblock->next = block_stack;
  922. thisblock->all = nesting_stack;
  923. thisblock->depth = ++nesting_depth;
  924. thisblock->data.block.stack_level = 0;
  925. thisblock->data.block.label_chain = 0;
  926. thisblock->data.block.innermost_stack_block = stack_block_stack;
  927. thisblock->data.block.first_insn = note;
  928. thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
  929. block_stack = thisblock;
  930. nesting_stack = thisblock;
  931. }
  932. /* Generate RTL code to terminate a binding contour.
  933. VARS is the chain of VAR_DECL nodes
  934. for the variables bound in this contour.
  935. MARK_ENDs is nonzero if we should put a note at the beginning
  936. and end of this binding contour. */
  937. void
  938. expand_end_bindings (vars, mark_ends)
  939. tree vars;
  940. int mark_ends;
  941. {
  942. register struct nesting *thisblock = block_stack;
  943. register tree decl;
  944. /* Mark the beginning and end of the scope if requested. */
  945. if (mark_ends)
  946. emit_note (0, NOTE_INSN_BLOCK_END);
  947. else
  948. /* Get rid of the beginning-mark if we don't make an end-mark. */
  949. NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
  950. if (thisblock->exit_label)
  951. {
  952. do_pending_stack_adjust ();
  953. emit_label (thisblock->exit_label);
  954. }
  955. /* Restore stack level in effect before the block
  956. (only if variable-size objects allocated). */
  957. if (thisblock->data.block.stack_level != 0)
  958. {
  959. struct label_chain *chain;
  960. do_pending_stack_adjust ();
  961. emit_move_insn (stack_pointer_rtx,
  962. thisblock->data.block.stack_level);
  963. /* Any labels in this block are no longer valid to go to.
  964. Mark them to cause an error message. */
  965. for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
  966. {
  967. TREE_PACKED (chain->label) = 1;
  968. /* If any goto without a fixup came to this label,
  969. that must be an error, because gotos without fixups
  970. come from outside all saved stack-levels. */
  971. if (TREE_ADDRESSABLE (chain->label))
  972. error_with_file_and_line (DECL_SOURCE_FILE (chain->label),
  973. DECL_SOURCE_LINE (chain->label),
  974. "label \"%s\" was used \
  975. before containing binding contour",
  976. IDENTIFIER_POINTER (DECL_NAME (chain->label)));
  977. }
  978. /* Any gotos out of this block must also restore the stack level.
  979. Also report any gotos with fixups that came to labels in this level. */
  980. fixup_gotos (thisblock->data.block.stack_level,
  981. thisblock->data.block.first_insn);
  982. }
  983. /* If doing stupid register allocation, make sure lives of all
  984. register variables declared here extend thru end of scope. */
  985. if (obey_regdecls)
  986. for (decl = vars; decl; decl = TREE_CHAIN (decl))
  987. {
  988. if (TREE_CODE (decl) == VAR_DECL
  989. && DECL_RTL (decl) != 0
  990. && GET_CODE (DECL_RTL (decl)) == REG)
  991. emit_insn (gen_rtx (USE, VOIDmode, DECL_RTL (decl)));
  992. }
  993. /* Restore block_stack level for containing block. */
  994. stack_block_stack = thisblock->data.block.innermost_stack_block;
  995. POPSTACK (block_stack);
  996. }
  997. /* Generate RTL for the automatic variable declaration DECL.
  998. (Other kinds of declarations are simply ignored.) */
  999. void
  1000. expand_decl (decl)
  1001. register tree decl;
  1002. {
  1003. struct nesting *thisblock = block_stack;
  1004. tree type = TREE_TYPE (decl);
  1005. /* External function declarations are supposed to have been
  1006. handled in assemble_variable. Verify this. */
  1007. if (TREE_CODE (decl) == FUNCTION_DECL)
  1008. {
  1009. if (DECL_RTL (decl) == 0)
  1010. abort ();
  1011. return;
  1012. }
  1013. /* Aside from that, only automatic variables need any expansion done.
  1014. Static and external variables were handled by `assemble_variable'
  1015. (called from finish_decl). TYPE_DECL and CONST_DECL require nothing;
  1016. PARM_DECLs are handled in `assign_parms'. */
  1017. if (TREE_CODE (decl) != VAR_DECL)
  1018. return;
  1019. if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
  1020. return;
  1021. /* Create the RTL representation for the variable. */
  1022. if (type == error_mark_node)
  1023. DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
  1024. else if (DECL_MODE (decl) != BLKmode
  1025. /* If -ffloat-store, don't put explicit float vars
  1026. into regs. */
  1027. && !(flag_float_store
  1028. && TREE_CODE (type) == REAL_TYPE)
  1029. && ! TREE_VOLATILE (decl)
  1030. && ! TREE_ADDRESSABLE (decl)
  1031. && (TREE_REGDECL (decl) || ! obey_regdecls))
  1032. {
  1033. /* Automatic variable that can go in a register. */
  1034. DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  1035. if (TREE_CODE (type) == POINTER_TYPE)
  1036. mark_reg_pointer (DECL_RTL (decl));
  1037. DECL_RTL (decl)->volatil = 1;
  1038. }
  1039. else if (DECL_SIZE (decl) == 0)
  1040. /* Variable with incomplete type. */
  1041. /* Error message was already done; now avoid a crash. */
  1042. DECL_RTL (decl) = assign_stack_local (DECL_MODE (decl), 0);
  1043. else if (TREE_LITERAL (DECL_SIZE (decl)))
  1044. {
  1045. /* Variable of fixed size that goes on the stack. */
  1046. DECL_RTL (decl)
  1047. = assign_stack_local (DECL_MODE (decl),
  1048. (TREE_INT_CST_LOW (DECL_SIZE (decl))
  1049. * DECL_SIZE_UNIT (decl)
  1050. + BITS_PER_UNIT - 1)
  1051. / BITS_PER_UNIT);
  1052. /* If this is a memory ref that contains aggregate components,
  1053. mark it as such for cse and loop optimize. */
  1054. DECL_RTL (decl)->in_struct
  1055. = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  1056. || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  1057. || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  1058. }
  1059. else
  1060. /* Dynamic-size object: must push space on the stack. */
  1061. {
  1062. rtx address, size;
  1063. frame_pointer_needed = 1;
  1064. /* Record the stack pointer on entry to block, if have
  1065. not already done so. */
  1066. if (thisblock->data.block.stack_level == 0)
  1067. {
  1068. do_pending_stack_adjust ();
  1069. thisblock->data.block.stack_level
  1070. = copy_to_reg (stack_pointer_rtx);
  1071. stack_block_stack = thisblock;
  1072. }
  1073. /* Compute the variable's size, in bytes. */
  1074. size = expand_expr (convert_units (DECL_SIZE (decl),
  1075. DECL_SIZE_UNIT (decl),
  1076. BITS_PER_UNIT),
  1077. 0, VOIDmode, 0);
  1078. /* Round it up to this machine's required stack boundary. */
  1079. #ifdef STACK_BOUNDARY
  1080. /* Avoid extra code if we can prove it's a multiple already. */
  1081. if (DECL_SIZE_UNIT (decl) % STACK_BOUNDARY)
  1082. size = round_push (size);
  1083. #endif
  1084. /* Make space on the stack, and get an rtx for the address of it. */
  1085. #ifdef STACK_GROWS_DOWNWARD
  1086. anti_adjust_stack (size);
  1087. #endif
  1088. address = copy_to_reg (stack_pointer_rtx);
  1089. #ifndef STACK_GROWS_DOWNWARD
  1090. anti_adjust_stack (size);
  1091. #endif
  1092. /* Reference the variable indirect through that rtx. */
  1093. DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
  1094. }
  1095. if (TREE_VOLATILE (decl))
  1096. DECL_RTL (decl)->volatil = 1;
  1097. if (TREE_READONLY (decl))
  1098. DECL_RTL (decl)->unchanging = 1;
  1099. /* If doing stupid register allocation, make sure life of any
  1100. register variable starts here, at the start of its scope. */
  1101. if (obey_regdecls
  1102. && TREE_CODE (decl) == VAR_DECL
  1103. && DECL_RTL (decl) != 0
  1104. && GET_CODE (DECL_RTL (decl)) == REG)
  1105. emit_insn (gen_rtx (USE, VOIDmode, DECL_RTL (decl)));
  1106. /* Compute and store the initial value now. */
  1107. if (DECL_INITIAL (decl))
  1108. {
  1109. emit_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  1110. expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
  1111. emit_queue ();
  1112. }
  1113. }
  1114. /* Enter a case (Pascal) or switch (C) statement.
  1115. Push a block onto case_stack and nesting_stack
  1116. to accumulate the case-labels that are seen
  1117. and to record the labels generated for the statement.
  1118. EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
  1119. Otherwise, this construct is transparent for `exit_something'.
  1120. EXPR is the index-expression to be dispatched on.
  1121. TYPE is its nominal type. We could simply convert EXPR to this type,
  1122. but instead we take short cuts. */
  1123. void
  1124. expand_start_case (exit_flag, expr, type)
  1125. int exit_flag;
  1126. tree expr;
  1127. tree type;
  1128. {
  1129. register struct nesting *thiscase
  1130. = (struct nesting *) xmalloc (sizeof (struct nesting));
  1131. /* Make an entry on case_stack for the case we are entering. */
  1132. thiscase->next = case_stack;
  1133. thiscase->all = nesting_stack;
  1134. thiscase->depth = ++nesting_depth;
  1135. thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
  1136. thiscase->data.case_stmt.case_list = 0;
  1137. thiscase->data.case_stmt.index_expr = expr;
  1138. thiscase->data.case_stmt.nominal_type = type;
  1139. case_stack = thiscase;
  1140. nesting_stack = thiscase;
  1141. do_pending_stack_adjust ();
  1142. thiscase->data.case_stmt.start = get_last_insn ();
  1143. }
  1144. /* Start a "dummy case statement" within which case labels are invalid
  1145. and are not connected to any larger real case statement.
  1146. This can be used if you don't want to let a case statement jump
  1147. into the middle of certain kinds of constructs. */
  1148. void
  1149. expand_start_case_dummy ()
  1150. {
  1151. register struct nesting *thiscase
  1152. = (struct nesting *) xmalloc (sizeof (struct nesting));
  1153. /* Make an entry on case_stack for the dummy. */
  1154. thiscase->next = case_stack;
  1155. thiscase->all = nesting_stack;
  1156. thiscase->depth = ++nesting_depth;
  1157. thiscase->exit_label = 0;
  1158. thiscase->data.case_stmt.case_list = 0;
  1159. thiscase->data.case_stmt.start = 0;
  1160. thiscase->data.case_stmt.nominal_type = 0;
  1161. case_stack = thiscase;
  1162. nesting_stack = thiscase;
  1163. }
  1164. /* End a dummy case statement. */
  1165. void
  1166. expand_end_case_dummy ()
  1167. {
  1168. POPSTACK (case_stack);
  1169. }
  1170. /* Accumulate one case or default label inside a case or switch statement.
  1171. VALUE is the value of the case (a null pointer, for a default label).
  1172. If not currently inside a case or switch statement, return 1 and do
  1173. nothing. The caller will print a language-specific error message.
  1174. If VALUE is a duplicate, return 2 and do nothing.
  1175. If VALUE is out of range, return 3 and do nothing.
  1176. Return 0 on success. */
  1177. int
  1178. pushcase (value, label)
  1179. register tree value;
  1180. register tree label;
  1181. {
  1182. register tree l;
  1183. tree index_type;
  1184. tree nominal_type;
  1185. /* Fail if not inside a real case statement. */
  1186. if (! (case_stack && case_stack->data.case_stmt.start))
  1187. return 1;
  1188. index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  1189. nominal_type = case_stack->data.case_stmt.nominal_type;
  1190. /* If the index is erroneous, avoid more problems: pretend to succeed. */
  1191. if (index_type == error_mark_node)
  1192. return 0;
  1193. /* Convert VALUE to the type in which the comparisons are nominally done. */
  1194. if (value != 0)
  1195. value = convert (nominal_type, value);
  1196. /* Fail if this is a duplicate entry. */
  1197. for (l = case_stack->data.case_stmt.case_list; l; l = TREE_CHAIN (l))
  1198. {
  1199. if (value == 0 && TREE_PURPOSE (l) == 0)
  1200. return 2;
  1201. if (value != 0 && TREE_PURPOSE (l)
  1202. && (TREE_INT_CST_LOW (value)
  1203. == TREE_INT_CST_LOW (TREE_PURPOSE (l)))
  1204. && (TREE_INT_CST_HIGH (value)
  1205. == TREE_INT_CST_HIGH (TREE_PURPOSE (l))))
  1206. return 2;
  1207. }
  1208. /* Fail if this value is out of range for the actual type of the index
  1209. (which may be narrower than NOMINAL_TYPE). */
  1210. if (value != 0 && ! int_fits_type_p (value, index_type))
  1211. return 3;
  1212. /* Add this label to the list, and succeed.
  1213. Copy VALUE so it is temporary rather than momentary. */
  1214. case_stack->data.case_stmt.case_list
  1215. = tree_cons (value ? copy_node (value) : 0, label,
  1216. case_stack->data.case_stmt.case_list);
  1217. expand_label (label);
  1218. return 0;
  1219. }
  1220. /* Terminate a case (Pascal) or switch (C) statement
  1221. in which CASE_INDEX is the expression to be tested.
  1222. Generate the code to test it and jump to the right place. */
  1223. void
  1224. expand_end_case ()
  1225. {
  1226. tree minval, maxval, range;
  1227. rtx default_label = 0;
  1228. register tree elt;
  1229. register tree c;
  1230. int count;
  1231. rtx index;
  1232. rtx table_label = gen_label_rtx ();
  1233. int ncases;
  1234. rtx *labelvec;
  1235. register int i;
  1236. rtx before_case;
  1237. register struct nesting *thiscase = case_stack;
  1238. tree index_expr = thiscase->data.case_stmt.index_expr;
  1239. do_pending_stack_adjust ();
  1240. /* This happens for various reasons including invalid data type. */
  1241. if (index_expr != error_mark_node)
  1242. {
  1243. /* If we don't have a default-label, create one here,
  1244. after the body of the switch. */
  1245. for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1246. if (TREE_PURPOSE (c) == 0)
  1247. break;
  1248. if (c == 0)
  1249. pushcase (0, build_decl (LABEL_DECL, NULL_TREE, NULL_TREE));
  1250. before_case = get_last_insn ();
  1251. /* Get upper and lower bounds of case values.
  1252. Also convert all the case values to the index expr's data type. */
  1253. count = 0;
  1254. for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1255. if (elt = TREE_PURPOSE (c))
  1256. {
  1257. /* Note that in Pascal it will be possible
  1258. to have a RANGE_EXPR here as long as both
  1259. ends of the range are constant.
  1260. It will be necessary to extend this function
  1261. to handle them. */
  1262. if (TREE_CODE (elt) != INTEGER_CST)
  1263. abort ();
  1264. TREE_PURPOSE (c) = elt = convert (TREE_TYPE (index_expr), elt);
  1265. /* Count the elements and track the largest and
  1266. smallest of them
  1267. (treating them as signed even if they are not). */
  1268. if (count++ == 0)
  1269. {
  1270. minval = maxval = elt;
  1271. }
  1272. else
  1273. {
  1274. if (INT_CST_LT (elt, minval))
  1275. minval = elt;
  1276. if (INT_CST_LT (maxval, elt))
  1277. maxval = elt;
  1278. }
  1279. }
  1280. else
  1281. default_label = label_rtx (TREE_VALUE (c));
  1282. if (default_label == 0)
  1283. abort ();
  1284. /* Compute span of values. */
  1285. if (count != 0)
  1286. range = combine (MINUS_EXPR, maxval, minval);
  1287. if (count == 0 || TREE_CODE (TREE_TYPE (index_expr)) == ERROR_MARK)
  1288. {
  1289. expand_expr (index_expr, const0_rtx, VOIDmode, 0);
  1290. emit_queue ();
  1291. emit_jump (default_label);
  1292. }
  1293. /* If range of values is much bigger than number of values,
  1294. make a sequence of conditional branches instead of a dispatch.
  1295. If the switch-index is a constant, do it this way
  1296. because we can optimize it. */
  1297. else if (TREE_INT_CST_HIGH (range) != 0
  1298. #ifdef HAVE_casesi
  1299. || count < 4
  1300. #else
  1301. /* If machine does not have a case insn that compares the
  1302. bounds, this means extra overhead for dispatch tables
  1303. which raises the threshold for using them. */
  1304. || count < 5
  1305. #endif
  1306. || (unsigned) (TREE_INT_CST_LOW (range)) > 10 * count
  1307. || TREE_CODE (index_expr) == INTEGER_CST)
  1308. {
  1309. index = expand_expr (index_expr, 0, VOIDmode, 0);
  1310. emit_queue ();
  1311. index = protect_from_queue (index, 0);
  1312. if (GET_CODE (index) == MEM)
  1313. index = copy_to_reg (index);
  1314. do_pending_stack_adjust ();
  1315. for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1316. {
  1317. elt = TREE_PURPOSE (c);
  1318. if (elt && TREE_VALUE (c))
  1319. do_jump_if_equal (expand_expr (elt, 0, VOIDmode, 0), index,
  1320. label_rtx (TREE_VALUE (c)));
  1321. }
  1322. emit_jump (default_label);
  1323. }
  1324. else
  1325. {
  1326. #ifdef HAVE_casesi
  1327. if (TYPE_MODE (TREE_TYPE (index_expr)) == DImode)
  1328. {
  1329. index_expr = convert (integer_type_node,
  1330. build (MINUS_EXPR, TREE_TYPE (index_expr),
  1331. index_expr, minval));
  1332. minval = integer_zero_node;
  1333. }
  1334. else if (TYPE_MODE (TREE_TYPE (index_expr)) != SImode)
  1335. index_expr = convert (integer_type_node, index_expr);
  1336. index = expand_expr (index_expr, 0, VOIDmode, 0);
  1337. emit_queue ();
  1338. index = protect_from_queue (index, 0);
  1339. do_pending_stack_adjust ();
  1340. emit_jump_insn (gen_casesi (index, expand_expr (minval, 0, VOIDmode, 0),
  1341. expand_expr (range, 0, VOIDmode, 0),
  1342. table_label, default_label));
  1343. #else
  1344. #ifdef HAVE_tablejump
  1345. index_expr = convert (integer_type_node,
  1346. build (MINUS_EXPR, TREE_TYPE (index_expr),
  1347. index_expr, minval));
  1348. index = expand_expr (index_expr, 0, VOIDmode, 0);
  1349. emit_queue ();
  1350. index = protect_from_queue (index, 0);
  1351. do_pending_stack_adjust ();
  1352. do_tablejump (index,
  1353. gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (range)),
  1354. table_label, default_label);
  1355. #else
  1356. lossage;
  1357. #endif /* not HAVE_tablejump */
  1358. #endif /* not HAVE_casesi */
  1359. /* Get table of labels to jump to, in order of case index. */
  1360. ncases = TREE_INT_CST_LOW (range) + 1;
  1361. labelvec = (rtx *) alloca (ncases * sizeof (rtx));
  1362. bzero (labelvec, ncases * sizeof (rtx));
  1363. for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1364. if (TREE_VALUE (c) && (elt = TREE_PURPOSE (c)))
  1365. {
  1366. register int i
  1367. = TREE_INT_CST_LOW (elt) - TREE_INT_CST_LOW (minval);
  1368. labelvec[i]
  1369. = gen_rtx (LABEL_REF, Pmode, label_rtx (TREE_VALUE (c)));
  1370. }
  1371. /* Fill in the gaps with the default. */
  1372. for (i = 0; i < ncases; i++)
  1373. if (labelvec[i] == 0)
  1374. labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
  1375. /* Output the table */
  1376. emit_label (table_label);
  1377. #ifdef CASE_VECTOR_PC_RELATIVE
  1378. emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
  1379. gen_rtx (LABEL_REF, Pmode, table_label),
  1380. gen_rtvec_v (ncases, labelvec)));
  1381. #else
  1382. emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
  1383. gen_rtvec_v (ncases, labelvec)));
  1384. #endif
  1385. /* If the case insn drops through the table,
  1386. after the table we must jump to the default-label.
  1387. Otherwise record no drop-through after the table. */
  1388. #ifdef CASE_DROPS_THROUGH
  1389. emit_jump (default_label);
  1390. #else
  1391. emit_barrier ();
  1392. #endif
  1393. }
  1394. reorder_insns (NEXT_INSN (before_case), get_last_insn (),
  1395. thiscase->data.case_stmt.start);
  1396. }
  1397. if (thiscase->exit_label)
  1398. emit_label (thiscase->exit_label);
  1399. POPSTACK (case_stack);
  1400. }
  1401. /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
  1402. /* ??? This may need an UNSIGNEDP argument to work properly ??? */
  1403. void
  1404. do_jump_if_equal (op1, op2, label)
  1405. rtx op1, op2, label;
  1406. {
  1407. if (GET_CODE (op1) == CONST_INT
  1408. && GET_CODE (op2) == CONST_INT)
  1409. {
  1410. if (INTVAL (op1) == INTVAL (op2))
  1411. emit_jump (label);
  1412. }
  1413. else
  1414. {
  1415. emit_cmp_insn (op1, op2, 0, 0);
  1416. emit_jump_insn (gen_beq (label));
  1417. }
  1418. }
  1419. /* Allocate fixed slots in the stack frame of the current function. */
  1420. /* Return size needed for stack frame based on slots so far allocated. */
  1421. int
  1422. get_frame_size ()
  1423. {
  1424. #ifdef FRAME_GROWS_DOWNWARD
  1425. return -frame_offset;
  1426. #else
  1427. return frame_offset;
  1428. #endif
  1429. }
  1430. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  1431. with machine mode MODE. */
  1432. rtx
  1433. assign_stack_local (mode, size)
  1434. enum machine_mode mode;
  1435. int size;
  1436. {
  1437. register rtx x, addr;
  1438. frame_pointer_needed = 1;
  1439. /* Make each stack slot a multiple of the main allocation unit. */
  1440. size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  1441. / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  1442. * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  1443. #ifdef FRAME_GROWS_DOWNWARD
  1444. frame_offset -= size;
  1445. #endif
  1446. addr = gen_rtx (PLUS, Pmode, frame_pointer_rtx,
  1447. gen_rtx (CONST_INT, VOIDmode, frame_offset));
  1448. #ifndef FRAME_GROWS_DOWNWARD
  1449. frame_offset += size;
  1450. #endif
  1451. if (! memory_address_p (mode, addr))
  1452. invalid_stack_slot = 1;
  1453. x = gen_rtx (MEM, mode, addr);
  1454. return x;
  1455. }
  1456. /* Retroactively move an auto variable from a register to a stack slot.
  1457. This is done when an address-reference to the variable is seen. */
  1458. void
  1459. put_var_into_stack (decl)
  1460. tree decl;
  1461. {
  1462. register rtx reg = DECL_RTL (decl);
  1463. register rtx new;
  1464. /* No need to do anything if decl has no rtx yet
  1465. since in that case caller is setting TREE_ADDRESSABLE
  1466. and a stack slot will be assigned when the rtl is made. */
  1467. if (reg == 0)
  1468. return;
  1469. if (GET_CODE (reg) != REG)
  1470. return;
  1471. new = parm_stack_loc (reg);
  1472. if (new == 0)
  1473. new = assign_stack_local (GET_MODE (reg), GET_MODE_SIZE (GET_MODE (reg)));
  1474. /* If this is a memory ref that contains aggregate components,
  1475. mark it as such for cse and loop optimize. */
  1476. reg->in_struct
  1477. = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  1478. || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  1479. || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  1480. XEXP (reg, 0) = XEXP (new, 0);
  1481. PUT_CODE (reg, MEM);
  1482. /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
  1483. reg->volatil = 0;
  1484. fixup_var_refs (reg);
  1485. }
  1486. static void
  1487. fixup_var_refs (var)
  1488. rtx var;
  1489. {
  1490. register rtx insn;
  1491. /* Yes. Must scan all insns for stack-refs that exceed the limit. */
  1492. for (insn = get_insns (); insn; )
  1493. {
  1494. rtx next = NEXT_INSN (insn);
  1495. if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1496. || GET_CODE (insn) == JUMP_INSN)
  1497. {
  1498. /* The insn to load VAR from a home in the arglist
  1499. is now a no-op. When we see it, just delete it. */
  1500. if (GET_CODE (PATTERN (insn)) == SET
  1501. && SET_DEST (PATTERN (insn)) == var
  1502. && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  1503. next = delete_insn (insn);
  1504. else
  1505. fixup_var_refs_1 (var, PATTERN (insn), insn);
  1506. }
  1507. insn = next;
  1508. }
  1509. }
  1510. static rtx
  1511. fixup_var_refs_1 (var, x, insn)
  1512. register rtx var;
  1513. register rtx x;
  1514. rtx insn;
  1515. {
  1516. register int i;
  1517. RTX_CODE code = GET_CODE (x);
  1518. register char *fmt;
  1519. register rtx tem;
  1520. switch (code)
  1521. {
  1522. case MEM:
  1523. if (var == x)
  1524. {
  1525. x = fixup_stack_1 (x, insn);
  1526. tem = gen_reg_rtx (GET_MODE (x));
  1527. emit_insn_before (gen_move_insn (tem, x), insn);
  1528. return tem;
  1529. }
  1530. break;
  1531. case REG:
  1532. case CC0:
  1533. case PC:
  1534. case CONST_INT:
  1535. case CONST:
  1536. case SYMBOL_REF:
  1537. case LABEL_REF:
  1538. case CONST_DOUBLE:
  1539. return x;
  1540. case SIGN_EXTRACT:
  1541. case ZERO_EXTRACT:
  1542. /* Note that in some cases those types of expressions are altered
  1543. by optimize_bit_field, and do not survive to get here. */
  1544. case SUBREG:
  1545. tem = x;
  1546. while (GET_CODE (tem) == SUBREG || GET_CODE (tem) == SIGN_EXTRACT
  1547. || GET_CODE (tem) == ZERO_EXTRACT)
  1548. tem = XEXP (tem, 0);
  1549. if (tem == var)
  1550. {
  1551. x = fixup_stack_1 (x, insn);
  1552. tem = gen_reg_rtx (GET_MODE (x));
  1553. emit_insn_before (gen_move_insn (tem, x), insn);
  1554. return tem;
  1555. }
  1556. break;
  1557. case SET:
  1558. /* First do special simplification of bit-field references. */
  1559. if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  1560. || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  1561. optimize_bit_field (x, insn, 0);
  1562. if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  1563. || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  1564. optimize_bit_field (x, insn, 0);
  1565. {
  1566. rtx dest = SET_DEST (x);
  1567. rtx src = SET_SRC (x);
  1568. rtx outerdest = dest;
  1569. rtx outersrc = src;
  1570. int strictflag = GET_CODE (dest) == STRICT_LOW_PART;
  1571. while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  1572. || GET_CODE (dest) == SIGN_EXTRACT
  1573. || GET_CODE (dest) == ZERO_EXTRACT)
  1574. dest = XEXP (dest, 0);
  1575. while (GET_CODE (src) == SUBREG
  1576. || GET_CODE (src) == SIGN_EXTRACT
  1577. || GET_CODE (src) == ZERO_EXTRACT)
  1578. src = XEXP (src, 0);
  1579. /* If VAR does not appear at the top level of the SET
  1580. just scan the lower levels of the tree. */
  1581. if (src != var && dest != var)
  1582. break;
  1583. /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  1584. that may appear inside a SIGN_EXTRACT or ZERO_EXTRACT.
  1585. This was legitimate when the MEM was a REG. */
  1586. if ((GET_CODE (outerdest) == SIGN_EXTRACT
  1587. || GET_CODE (outerdest) == ZERO_EXTRACT)
  1588. && GET_CODE (XEXP (outerdest, 0)) == SUBREG
  1589. && SUBREG_REG (XEXP (outerdest, 0)) == var)
  1590. XEXP (outerdest, 0) = fixup_memory_subreg (XEXP (outerdest, 0));
  1591. if ((GET_CODE (outersrc) == SIGN_EXTRACT
  1592. || GET_CODE (outersrc) == ZERO_EXTRACT)
  1593. && GET_CODE (XEXP (outersrc, 0)) == SUBREG
  1594. && SUBREG_REG (XEXP (outersrc, 0)) == var)
  1595. XEXP (outersrc, 0) = fixup_memory_subreg (XEXP (outersrc, 0));
  1596. /* Make sure a MEM inside a SIGN_EXTRACT has QImode
  1597. since that's what bit-field insns want. */
  1598. if ((GET_CODE (outerdest) == SIGN_EXTRACT
  1599. || GET_CODE (outerdest) == ZERO_EXTRACT)
  1600. && GET_CODE (XEXP (outerdest, 0)) == MEM
  1601. && GET_MODE (XEXP (outerdest, 0)) != QImode)
  1602. {
  1603. XEXP (outerdest, 0) = copy_rtx (XEXP (outerdest, 0));
  1604. PUT_MODE (XEXP (outerdest, 0), QImode);
  1605. }
  1606. if ((GET_CODE (outersrc) == SIGN_EXTRACT
  1607. || GET_CODE (outersrc) == ZERO_EXTRACT)
  1608. && GET_CODE (XEXP (outersrc, 0)) == MEM
  1609. && GET_MODE (XEXP (outersrc, 0)) != QImode)
  1610. {
  1611. XEXP (outersrc, 0) = copy_rtx (XEXP (outersrc, 0));
  1612. PUT_MODE (XEXP (outersrc, 0), QImode);
  1613. }
  1614. /* STRICT_LOW_PART is a no-op on memory references
  1615. and it can cause combinations to be unrecognizable,
  1616. so eliminate it. */
  1617. if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  1618. SET_DEST (x) = XEXP (SET_DEST (x), 0);
  1619. /* An insn to copy VAR into or out of a register
  1620. must be left alone, to avoid an infinite loop here.
  1621. But do fix up the address of VAR's stack slot if nec. */
  1622. if (GET_CODE (SET_SRC (x)) == REG || GET_CODE (SET_DEST (x)) == REG)
  1623. return fixup_stack_1 (x, insn);
  1624. if ((GET_CODE (SET_SRC (x)) == SUBREG
  1625. && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)
  1626. || (GET_CODE (SET_DEST (x)) == SUBREG
  1627. && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  1628. return fixup_stack_1 (x, insn);
  1629. /* Otherwise, storing into VAR must be handled specially
  1630. by storing into a temporary and copying that into VAR
  1631. with a new insn after this one. */
  1632. if (dest == var)
  1633. {
  1634. rtx temp;
  1635. rtx fixeddest;
  1636. tem = SET_DEST (x);
  1637. if (GET_CODE (tem) == STRICT_LOW_PART)
  1638. tem = XEXP (tem, 0);
  1639. temp = gen_reg_rtx (GET_MODE (tem));
  1640. fixeddest = fixup_stack_1 (SET_DEST (x), insn);
  1641. emit_insn_after (gen_move_insn (fixeddest, temp), insn);
  1642. SET_DEST (x) = temp;
  1643. }
  1644. }
  1645. }
  1646. /* Nothing special about this RTX; fix its operands. */
  1647. fmt = GET_RTX_FORMAT (code);
  1648. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1649. {
  1650. if (fmt[i] == 'e')
  1651. XEXP (x, i) = fixup_var_refs_1 (var, XEXP (x, i), insn);
  1652. if (fmt[i] == 'E')
  1653. {
  1654. register int j;
  1655. for (j = 0; j < XVECLEN (x, i); j++)
  1656. XVECEXP (x, i, j)
  1657. = fixup_var_refs_1 (var, XVECEXP (x, i, j), insn);
  1658. }
  1659. }
  1660. return x;
  1661. }
  1662. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  1663. return an rtx (MEM:m1 newaddr) which is equivalent. */
  1664. static rtx
  1665. fixup_memory_subreg (x)
  1666. rtx x;
  1667. {
  1668. int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1669. rtx addr = XEXP (SUBREG_REG (x), 0);
  1670. enum machine_mode mode = GET_MODE (SUBREG_REG (x));
  1671. #ifdef BYTES_BIG_ENDIAN
  1672. offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  1673. - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  1674. #endif
  1675. return change_address (SUBREG_REG (x), mode,
  1676. plus_constant (addr, offset));
  1677. }
  1678. #if 0
  1679. /* Fix up any references to stack slots that are invalid memory addresses
  1680. because they exceed the maximum range of a displacement. */
  1681. void
  1682. fixup_stack_slots ()
  1683. {
  1684. register rtx insn;
  1685. /* Did we generate a stack slot that is out of range
  1686. or otherwise has an invalid address? */
  1687. if (invalid_stack_slot)
  1688. {
  1689. /* Yes. Must scan all insns for stack-refs that exceed the limit. */
  1690. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  1691. if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1692. || GET_CODE (insn) == JUMP_INSN)
  1693. fixup_stack_1 (PATTERN (insn), insn);
  1694. }
  1695. }
  1696. #endif
  1697. /* For each memory ref within X, if it refers to a stack slot
  1698. with an out of range displacement, put the address in a temp register
  1699. (emitting new insns before INSN to load these registers)
  1700. and alter the memory ref to use that register.
  1701. Replace each such MEM rtx with a copy, to avoid clobberage. */
  1702. static rtx
  1703. fixup_stack_1 (x, insn)
  1704. rtx x;
  1705. rtx insn;
  1706. {
  1707. register int i;
  1708. register RTX_CODE code = GET_CODE (x);
  1709. register char *fmt;
  1710. if (code == MEM)
  1711. {
  1712. register rtx ad = XEXP (x, 0);
  1713. /* If we have address of a stack slot but it's not valid
  1714. (displacement is too large), compute the sum in a register. */
  1715. if (GET_CODE (ad) == PLUS
  1716. && XEXP (ad, 0) == frame_pointer_rtx
  1717. && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  1718. {
  1719. rtx temp;
  1720. if (memory_address_p (GET_MODE (x), ad))
  1721. return x;
  1722. temp = gen_reg_rtx (GET_MODE (ad));
  1723. emit_insn_before (gen_move_insn (temp, ad), insn);
  1724. return change_address (x, VOIDmode, temp);
  1725. }
  1726. return x;
  1727. }
  1728. fmt = GET_RTX_FORMAT (code);
  1729. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1730. {
  1731. if (fmt[i] == 'e')
  1732. XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  1733. if (fmt[i] == 'E')
  1734. {
  1735. register int j;
  1736. for (j = 0; j < XVECLEN (x, i); j++)
  1737. XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  1738. }
  1739. }
  1740. return x;
  1741. }
  1742. /* Optimization: a bit-field instruction whose field
  1743. happens to be a byte or halfword in memory
  1744. can be changed to a move instruction.
  1745. We call here when INSN is an insn to examine or store into a bit-field.
  1746. BODY is the SET-rtx to be altered.
  1747. EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  1748. (Currently this is called only from stmt.c, and EQUIV_MEM is always 0.) */
  1749. static void
  1750. optimize_bit_field (body, insn, equiv_mem)
  1751. rtx body;
  1752. rtx insn;
  1753. rtx *equiv_mem;
  1754. {
  1755. register rtx bitfield;
  1756. int destflag;
  1757. if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  1758. || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  1759. bitfield = SET_DEST (body), destflag = 1;
  1760. else
  1761. bitfield = SET_SRC (body), destflag = 0;
  1762. /* First check that the field being stored has constant size and position
  1763. and is in fact a byte or halfword suitably aligned. */
  1764. if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  1765. && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  1766. && (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  1767. || INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (HImode))
  1768. && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  1769. {
  1770. register rtx memref = 0;
  1771. /* Now check that the contanting word is memory, not a register,
  1772. and that it is safe to change the machine mode and to
  1773. add something to the address. */
  1774. if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  1775. memref = XEXP (bitfield, 0);
  1776. else if (GET_CODE (XEXP (bitfield, 0)) == REG
  1777. && equiv_mem != 0
  1778. && (memref = equiv_mem[REGNO (XEXP (bitfield, 0))]) != 0)
  1779. ;
  1780. else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1781. && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  1782. memref = SUBREG_REG (XEXP (bitfield, 0));
  1783. else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1784. && equiv_mem != 0
  1785. && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG
  1786. && (memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]) != 0)
  1787. ;
  1788. if (memref
  1789. && ! mode_dependent_address_p (XEXP (memref, 0))
  1790. && offsetable_address_p (GET_MODE (bitfield), XEXP (memref, 0)))
  1791. {
  1792. /* Now adjust the address, first for any subreg'ing
  1793. that we are now getting rid of,
  1794. and then for which byte of the word is wanted. */
  1795. register int offset
  1796. = INTVAL (XEXP (bitfield, 2)) / GET_MODE_BITSIZE (QImode);
  1797. if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  1798. {
  1799. offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  1800. #ifdef BYTES_BIG_ENDIAN
  1801. offset -= (MIN (UNITS_PER_WORD,
  1802. GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  1803. - MIN (UNITS_PER_WORD,
  1804. GET_MODE_SIZE (GET_MODE (memref))));
  1805. #endif
  1806. }
  1807. memref = gen_rtx (MEM,
  1808. (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  1809. ? QImode : HImode),
  1810. XEXP (memref, 0));
  1811. /* Store this memory reference where
  1812. we found the bit field reference. */
  1813. if (destflag)
  1814. {
  1815. SET_DEST (body)
  1816. = adj_offsetable_operand (memref, offset);
  1817. if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  1818. {
  1819. rtx src = SET_SRC (body);
  1820. while (GET_CODE (src) == SUBREG
  1821. && SUBREG_WORD (src) == 0)
  1822. src = SUBREG_REG (src);
  1823. if (GET_MODE (src) != GET_MODE (memref))
  1824. src = gen_rtx (SUBREG, GET_MODE (memref),
  1825. SET_SRC (body), 0);
  1826. SET_SRC (body) = src;
  1827. }
  1828. else if (GET_MODE (SET_SRC (body)) != VOIDmode
  1829. && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  1830. /* This shouldn't happen because anything that didn't have
  1831. one of these modes should have got converted explicitly
  1832. and then referenced through a subreg.
  1833. This is so because the original bit-field was
  1834. handled by agg_mode and so its tree structure had
  1835. the same mode that memref now has. */
  1836. abort ();
  1837. }
  1838. else
  1839. {
  1840. rtx newreg = gen_reg_rtx (GET_MODE (SET_DEST (body)));
  1841. emit_insn_before (gen_extend_insn (newreg, adj_offsetable_operand (memref, offset),
  1842. GET_MODE (SET_DEST (body)),
  1843. GET_MODE (memref),
  1844. GET_CODE (SET_SRC (body)) == ZERO_EXTRACT),
  1845. insn);
  1846. SET_SRC (body) = newreg;
  1847. }
  1848. /* Cause the insn to be re-recognized. */
  1849. INSN_CODE (insn) = -1;
  1850. }
  1851. }
  1852. }
  1853. /* 1 + last pseudo register number used for loading a copy
  1854. of a parameter of this function. */
  1855. static int max_parm_reg;
  1856. /* Vector indexed by REGNO, containing location on stack in which
  1857. to put the parm which is nominally in pseudo register REGNO,
  1858. if we discover that that parm must go in the stack. */
  1859. static rtx *parm_reg_stack_loc;
  1860. /* Last insn of those whose job was to put parms into their nominal homes. */
  1861. static rtx last_parm_insn;
  1862. int
  1863. max_parm_reg_num ()
  1864. {
  1865. return max_parm_reg;
  1866. }
  1867. /* Return the first insn following those generated by `assign_parms'. */
  1868. rtx
  1869. get_first_nonparm_insn ()
  1870. {
  1871. if (last_parm_insn)
  1872. return NEXT_INSN (last_parm_insn);
  1873. return get_insns ();
  1874. }
  1875. /* Get the stack home of a REG rtx that is one of this function's parameters.
  1876. This is called rather than assign a new stack slot as a local.
  1877. Return 0 if there is no existing stack home suitable for such use. */
  1878. static rtx
  1879. parm_stack_loc (reg)
  1880. rtx reg;
  1881. {
  1882. if (REGNO (reg) < max_parm_reg)
  1883. return parm_reg_stack_loc[REGNO (reg)];
  1884. return 0;
  1885. }
  1886. /* Assign RTL expressions to the function's parameters.
  1887. This may involve copying them into registers and using
  1888. those registers as the RTL for them. */
  1889. static void
  1890. assign_parms (fndecl)
  1891. tree fndecl;
  1892. {
  1893. register tree parm;
  1894. register rtx entry_parm;
  1895. register rtx stack_parm;
  1896. register CUMULATIVE_ARGS args_so_far;
  1897. enum machine_mode passed_mode, nominal_mode;
  1898. /* Total space needed so far for args on the stack,
  1899. given as a constant and a tree-expression. */
  1900. struct args_size stack_args_size;
  1901. int nparmregs
  1902. = list_length (DECL_ARGUMENTS (fndecl)) + FIRST_PSEUDO_REGISTER;
  1903. /* Nonzero if function takes extra anonymous args.
  1904. This means the last named arg must be on the stack
  1905. right before the anonymous ones. */
  1906. int vararg
  1907. = (TYPE_ARG_TYPES (TREE_TYPE (fndecl)) != 0
  1908. && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
  1909. != void_type_node));
  1910. stack_args_size.constant = 0;
  1911. stack_args_size.var = 0;
  1912. parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  1913. bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  1914. INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fndecl));
  1915. for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
  1916. {
  1917. int aggregate
  1918. = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  1919. || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  1920. || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  1921. struct args_size stack_offset;
  1922. rtx stack_offset_rtx;
  1923. /* Get this parm's offset as an rtx. */
  1924. stack_offset = stack_args_size;
  1925. stack_offset.constant += FIRST_PARM_OFFSET;
  1926. stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  1927. DECL_OFFSET (parm) = -1;
  1928. if (TREE_TYPE (parm) == error_mark_node)
  1929. {
  1930. DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx);
  1931. continue;
  1932. }
  1933. /* Find mode of arg as it is passed, and mode of arg
  1934. as it should be during execution of this function. */
  1935. passed_mode = TYPE_MODE (DECL_ARG_TYPE (parm));
  1936. nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  1937. /* Determine parm's home in the stack,
  1938. in case it arrives in the stack or we should pretend it did. */
  1939. stack_parm
  1940. = gen_rtx (MEM, passed_mode,
  1941. memory_address (passed_mode,
  1942. gen_rtx (PLUS, Pmode,
  1943. arg_pointer_rtx, stack_offset_rtx)));
  1944. /* If this is a memory ref that contains aggregate components,
  1945. mark it as such for cse and loop optimize. */
  1946. stack_parm->in_struct = aggregate;
  1947. /* Let machine desc say which reg (if any) the parm arrives in.
  1948. 0 means it arrives on the stack. */
  1949. entry_parm = 0;
  1950. /* Variable-size args, and args following such, are never in regs. */
  1951. if (TREE_CODE (TYPE_SIZE (TREE_TYPE (parm))) == INTEGER_CST
  1952. || stack_offset.var != 0)
  1953. {
  1954. #ifdef FUNCTION_INCOMING_ARG
  1955. entry_parm
  1956. = FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  1957. DECL_ARG_TYPE (parm), 1);
  1958. #else
  1959. entry_parm
  1960. = FUNCTION_ARG (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  1961. #endif
  1962. }
  1963. /* If this parm was passed part in regs and part in memory,
  1964. pretend it arrived entirely in memory
  1965. by pushing the register-part onto the stack.
  1966. In the special case of a DImode or DFmode that is split,
  1967. we could put it together in a pseudoreg directly,
  1968. but for now that's not worth bothering with. */
  1969. /* If this is the last named arg and anonymous args follow,
  1970. likewise pretend this arg arrived on the stack
  1971. so varargs can find the anonymous args following it. */
  1972. {
  1973. int nregs = 0;
  1974. int i;
  1975. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  1976. nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  1977. DECL_ARG_TYPE (parm), 1);
  1978. #endif
  1979. if (TREE_CHAIN (parm) == 0 && vararg && entry_parm != 0)
  1980. nregs = GET_MODE_SIZE (GET_MODE (entry_parm)) / UNITS_PER_WORD;
  1981. if (nregs > 0)
  1982. current_function_pretend_args_size
  1983. = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  1984. / (PARM_BOUNDARY / BITS_PER_UNIT)
  1985. * (PARM_BOUNDARY / BITS_PER_UNIT));
  1986. i = nregs;
  1987. while (--i >= 0)
  1988. emit_move_insn (gen_rtx (MEM, SImode,
  1989. plus_constant (XEXP (stack_parm, 0),
  1990. i * GET_MODE_SIZE (SImode))),
  1991. gen_rtx (REG, SImode, REGNO (entry_parm) + i));
  1992. if (nregs > 0)
  1993. entry_parm = stack_parm;
  1994. }
  1995. if (entry_parm == 0)
  1996. entry_parm = stack_parm;
  1997. /* Now ENTRY_PARM refers to the stack iff this parm uses stack space.
  1998. In that case, count its size in STACK_ARGS_SIZE. */
  1999. if (entry_parm == stack_parm)
  2000. {
  2001. tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  2002. /* Round the size up to multiple of PARM_BOUNDARY bits. */
  2003. tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  2004. tree s2 = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  2005. /* Add it in. */
  2006. ADD_PARM_SIZE (stack_args_size, s2);
  2007. }
  2008. /* Now set STACK_PARM to the place in the stack
  2009. where this parameter should live during execution,
  2010. if we discover that it must live in the stack during execution.
  2011. To make debuggers happier on big-endian machines, we store
  2012. the value in the last bytes of the space available. */
  2013. if (nominal_mode != BLKmode && nominal_mode != passed_mode)
  2014. {
  2015. #ifdef BYTES_BIG_ENDIAN
  2016. stack_offset.constant
  2017. += GET_MODE_SIZE (passed_mode)
  2018. - GET_MODE_SIZE (nominal_mode);
  2019. stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2020. #endif
  2021. stack_parm
  2022. = gen_rtx (MEM, nominal_mode,
  2023. memory_address (nominal_mode,
  2024. gen_rtx (PLUS, Pmode,
  2025. arg_pointer_rtx,
  2026. stack_offset_rtx)));
  2027. /* If this is a memory ref that contains aggregate components,
  2028. mark it as such for cse and loop optimize. */
  2029. stack_parm->in_struct = aggregate;
  2030. }
  2031. /* If the parm arrived in a reg, we don't have an argument
  2032. stack slot for it, so don't think that we do.
  2033. If it needs to be addressable, it will get put into the stack
  2034. like an ordinary automatic variable. */
  2035. if (GET_CODE (entry_parm) == REG)
  2036. stack_parm = 0;
  2037. else
  2038. DECL_OFFSET (parm) = stack_offset.constant * BITS_PER_UNIT;
  2039. #if 0 /* Not needed now that `memory_address' is used above. */
  2040. /* If either STACK_PARM or ENTRY_PARM is a MEM whose address
  2041. is not really valid, arrange to correct all references later. */
  2042. if ((GET_CODE (entry_parm) == MEM
  2043. && ! memory_address_p (passed_mode, XEXP (entry_parm, 0)))
  2044. || (stack_parm != entry_parm && stack_parm != 0
  2045. && GET_CODE (stack_parm) == MEM
  2046. && ! memory_address_p (nominal_mode, XEXP (stack_parm, 0))))
  2047. invalid_stack_slot = 1;
  2048. #endif /* 0 */
  2049. /* ENTRY_PARM is an RTX for the parameter as it arrives,
  2050. in the mode in which it arrives.
  2051. Now output code if necessary to convert it to
  2052. the type in which this function declares it,
  2053. and store a reference to that value in DECL_RTL.
  2054. This reference may be the same as STACK_PARM,
  2055. or a similar stack reference in a different mode,
  2056. or may be a pseudo register. */
  2057. if (nominal_mode == BLKmode)
  2058. {
  2059. /* If a BLKmode arrives in registers, copy it to a stack slot. */
  2060. if (stack_parm == 0)
  2061. {
  2062. stack_parm
  2063. = assign_stack_local (GET_MODE (entry_parm),
  2064. int_size_in_bytes (TREE_TYPE (parm)));
  2065. move_block_from_reg (REGNO (entry_parm), stack_parm,
  2066. int_size_in_bytes (TREE_TYPE (parm))
  2067. / UNITS_PER_WORD);
  2068. }
  2069. DECL_RTL (parm) = stack_parm;
  2070. }
  2071. else if (! ((obey_regdecls && ! TREE_REGDECL (parm))
  2072. /* If -ffloat-store specified, don't put explicit
  2073. float variables into registers. */
  2074. || (flag_float_store
  2075. && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  2076. {
  2077. /* Store the parm in a pseudoregister during the function. */
  2078. register rtx parmreg = gen_reg_rtx (nominal_mode);
  2079. parmreg->volatil = 1;
  2080. DECL_RTL (parm) = parmreg;
  2081. /* Copy the value into the register. */
  2082. if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  2083. convert_move (parmreg, entry_parm, 0);
  2084. else
  2085. emit_move_insn (parmreg, entry_parm);
  2086. /* In any case, record the parm's desired stack location
  2087. in case we later discover it must live in the stack. */
  2088. if (REGNO (parmreg) >= nparmregs)
  2089. {
  2090. rtx *new;
  2091. nparmregs = REGNO (parmreg) + 5;
  2092. new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2093. bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  2094. parm_reg_stack_loc = new;
  2095. }
  2096. parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  2097. /* Mark the register as eliminable if we did no conversion
  2098. and it was copied from memory at a fixed offset. */
  2099. if (nominal_mode == passed_mode
  2100. && GET_CODE (entry_parm) == MEM
  2101. && stack_offset.var == 0)
  2102. REG_NOTES (get_last_insn ()) = gen_rtx (EXPR_LIST, REG_EQUIV,
  2103. entry_parm, 0);
  2104. /* For pointer data type, suggest pointer register. */
  2105. if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  2106. mark_reg_pointer (parmreg);
  2107. }
  2108. else
  2109. {
  2110. /* Value must be stored in the stack slot STACK_PARM
  2111. during function execution. */
  2112. if (passed_mode != nominal_mode)
  2113. /* Conversion is required. */
  2114. entry_parm = convert_to_mode (nominal_mode, entry_parm, 0);
  2115. if (entry_parm != stack_parm)
  2116. {
  2117. if (stack_parm == 0)
  2118. stack_parm = assign_stack_local (GET_MODE (entry_parm),
  2119. GET_MODE_SIZE (GET_MODE (entry_parm)));
  2120. emit_move_insn (stack_parm, entry_parm);
  2121. }
  2122. DECL_RTL (parm) = stack_parm;
  2123. frame_pointer_needed = 1;
  2124. }
  2125. if (TREE_VOLATILE (parm))
  2126. DECL_RTL (parm)->volatil = 1;
  2127. if (TREE_READONLY (parm))
  2128. DECL_RTL (parm)->unchanging = 1;
  2129. /* Update info on where next arg arrives in registers. */
  2130. FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  2131. }
  2132. max_parm_reg = max_reg_num ();
  2133. last_parm_insn = get_last_insn ();
  2134. current_function_args_size = stack_args_size.constant;
  2135. }
  2136. /* Allocation of space for returned structure values.
  2137. During the rtl generation pass, `get_structure_value_addr'
  2138. is called from time to time to request the address of a block in our
  2139. stack frame in which called functions will store the structures
  2140. they are returning. The same space is used for all of these blocks.
  2141. We allocate these blocks like stack locals. We keep reusing
  2142. the same block until a bigger one is needed. */
  2143. /* Length in bytes of largest structure value returned by
  2144. any function called so far in this function. */
  2145. static int max_structure_value_size;
  2146. /* An rtx for the addr we are currently using for structure values.
  2147. This is typically (PLUS (REG:SI stackptr) (CONST_INT...)). */
  2148. static rtx structure_value;
  2149. rtx
  2150. get_structure_value_addr (sizex)
  2151. rtx sizex;
  2152. {
  2153. register int size;
  2154. if (GET_CODE (sizex) != CONST_INT)
  2155. abort ();
  2156. size = INTVAL (sizex);
  2157. /* Round up to a multiple of the main allocation unit. */
  2158. size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  2159. / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  2160. * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  2161. /* If this size is bigger than space we know to use,
  2162. get a bigger piece of space. */
  2163. if (size > max_structure_value_size)
  2164. {
  2165. max_structure_value_size = size;
  2166. structure_value = assign_stack_local (BLKmode, size);
  2167. if (GET_CODE (structure_value) == MEM)
  2168. structure_value = XEXP (structure_value, 0);
  2169. }
  2170. return structure_value;
  2171. }
  2172. /* Walk the tree of LET_STMTs describing the binding levels within a function
  2173. and warn about uninitialized variables.
  2174. This is done after calling flow_analysis and before global_alloc
  2175. clobbers the pseudo-regs to hard regs. */
  2176. void
  2177. uninitialized_vars_warning (block)
  2178. tree block;
  2179. {
  2180. register tree decl, sub;
  2181. for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  2182. {
  2183. if (TREE_CODE (decl) == VAR_DECL
  2184. /* These warnings are unreliable for and aggregates
  2185. because assigning the fields one by one can fail to convince
  2186. flow.c that the entire aggregate was initialized.
  2187. Unions are troublesome because members may be shorter. */
  2188. && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  2189. && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  2190. && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  2191. && GET_CODE (DECL_RTL (decl)) == REG
  2192. && regno_uninitialized (REGNO (DECL_RTL (decl))))
  2193. warning_with_decl (decl,
  2194. "variable `%s' used uninitialized in this function");
  2195. if (TREE_CODE (decl) == VAR_DECL
  2196. && GET_CODE (DECL_RTL (decl)) == REG
  2197. && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  2198. warning_with_decl (decl,
  2199. "variable `%s' may be clobbered by `longjmp'");
  2200. }
  2201. for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub))
  2202. uninitialized_vars_warning (sub);
  2203. }
  2204. /* Generate RTL for the start of the function FUNC (a FUNCTION_DECL tree node)
  2205. and initialize static variables for generating RTL for the statements
  2206. of the function. */
  2207. void
  2208. expand_function_start (subr)
  2209. tree subr;
  2210. {
  2211. register int i;
  2212. tree tem;
  2213. this_function = subr;
  2214. cse_not_expected = ! optimize;
  2215. /* We have not yet found a reason why a frame pointer cannot
  2216. be omitted for this function in particular, but maybe we know
  2217. a priori that it is required.
  2218. `flag_omit_frame_pointer' has its main effect here. */
  2219. frame_pointer_needed = FRAME_POINTER_REQUIRED || ! flag_omit_frame_pointer;
  2220. /* No gotos have been expanded yet. */
  2221. goto_fixup_chain = 0;
  2222. /* No invalid stack slots have been made yet. */
  2223. invalid_stack_slot = 0;
  2224. /* Initialize the RTL mechanism. */
  2225. init_emit (write_symbols);
  2226. /* Initialize the queue of pending postincrement and postdecrements,
  2227. and some other info in expr.c. */
  2228. init_expr ();
  2229. init_const_rtx_hash_table ();
  2230. /* Decide whether function should try to pop its args on return. */
  2231. current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (subr));
  2232. current_function_name = IDENTIFIER_POINTER (DECL_NAME (subr));
  2233. /* Make the label for return statements to jump to, if this machine
  2234. does not have a one-instruction return. */
  2235. #ifdef FUNCTION_EPILOGUE
  2236. return_label = gen_label_rtx ();
  2237. #else
  2238. return_label = 0;
  2239. #endif
  2240. /* No space assigned yet for structure values. */
  2241. max_structure_value_size = 0;
  2242. structure_value = 0;
  2243. /* We are not currently within any block, conditional, loop or case. */
  2244. block_stack = 0;
  2245. loop_stack = 0;
  2246. case_stack = 0;
  2247. cond_stack = 0;
  2248. nesting_stack = 0;
  2249. nesting_depth = 0;
  2250. /* We have not yet needed to make a label to jump to for tail-recursion. */
  2251. tail_recursion_label = 0;
  2252. /* No stack slots allocated yet. */
  2253. frame_offset = STARTING_FRAME_OFFSET;
  2254. init_pending_stack_adjust ();
  2255. clear_current_args_size ();
  2256. /* Prevent ever trying to delete the first instruction of a function.
  2257. Also tell final how to output a linenum before the function prologue. */
  2258. emit_note (DECL_SOURCE_FILE (subr), DECL_SOURCE_LINE (subr));
  2259. /* Make sure first insn is a note even if we don't want linenums.
  2260. This makes sure the first insn will never be deleted.
  2261. Also, final expects a note to appear there. */
  2262. emit_note (0, NOTE_INSN_DELETED);
  2263. /* Initialize rtx for parameters and local variables.
  2264. In some cases this requires emitting insns. */
  2265. assign_parms (subr);
  2266. /* If doing stupid allocation, mark parms as born here. */
  2267. if (obey_regdecls)
  2268. for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  2269. emit_insn (gen_rtx (USE, VOIDmode, regno_reg_rtx[i]));
  2270. /* After the parm initializations is where the tail-recursion label
  2271. should go, if we end up needing one. */
  2272. tail_recursion_reentry = get_last_insn ();
  2273. /* Initialize rtx used to return the value. */
  2274. if (DECL_MODE (DECL_RESULT (subr)) == BLKmode)
  2275. {
  2276. /* Returning something that won't go in a register. */
  2277. register rtx value_address;
  2278. /* Expect to be passed the address of a place to store the value. */
  2279. value_address = gen_reg_rtx (Pmode);
  2280. emit_move_insn (value_address, struct_value_incoming_rtx);
  2281. DECL_RTL (DECL_RESULT (subr))
  2282. = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  2283. value_address);
  2284. }
  2285. else
  2286. #ifdef FUNCTION_OUTGOING_VALUE
  2287. DECL_RTL (DECL_RESULT (subr))
  2288. = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  2289. #else
  2290. DECL_RTL (DECL_RESULT (subr))
  2291. = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  2292. #endif
  2293. }
  2294. /* Generate RTL for the end of the current function. */
  2295. void
  2296. expand_function_end ()
  2297. {
  2298. register int i;
  2299. /* Fix up any gotos that jumped out to the outermost
  2300. binding level of the function. */
  2301. fixup_gotos (0, get_insns ());
  2302. /* If doing stupid register allocation,
  2303. mark register parms as dying here. */
  2304. if (obey_regdecls)
  2305. for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  2306. emit_insn (gen_rtx (USE, VOIDmode, regno_reg_rtx[i]));
  2307. clear_pending_stack_adjust ();
  2308. do_pending_stack_adjust ();
  2309. /* Mark the end of the function body.
  2310. If control reaches this insn, the function can drop through
  2311. without returning a value. */
  2312. emit_note (0, NOTE_INSN_FUNCTION_END);
  2313. /* If we require a true epilogue,
  2314. put here the label that return statements jump to.
  2315. If there will be no epilogue, write a return instruction. */
  2316. #ifdef FUNCTION_EPILOGUE
  2317. emit_label (return_label);
  2318. #else
  2319. emit_jump_insn (gen_return ());
  2320. #endif
  2321. }