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