|
|
1.1 root 1: /* Convert tree expression to rtl instructions, for GNU compiler.
1.1.1.2 root 2: Copyright (C) 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: #include "config.h"
23: #include "rtl.h"
24: #include "tree.h"
1.1.1.2 root 25: #include "flags.h"
1.1 root 26: #include "insn-flags.h"
27: #include "insn-codes.h"
28: #include "expr.h"
1.1.1.2 root 29: #include "insn-config.h"
30: #include "recog.h"
31: #include "varargs.h"
32:
33: /* Decide whether a function's arguments should be processed
34: from first to last or from last to first. */
35:
36: #ifdef STACK_GROWS_DOWNWARD
37: #ifdef PUSH_ROUNDING
38: #define PUSH_ARGS_REVERSED /* If it's last to first */
39: #endif
40: #endif
41:
42: /* Like STACK_BOUNDARY but in units of bytes, not bits. */
43: #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
1.1 root 44:
45: /* If this is nonzero, we do not bother generating VOLATILE
46: around volatile memory references, and we are willing to
47: output indirect addresses. If cse is to follow, we reject
48: indirect addresses so a useful potential cse is generated;
49: if it is used only once, instruction combination will produce
50: the same indirect address eventually. */
51: int cse_not_expected;
52:
53: /* Nonzero to generate code for all the subroutines within an
54: expression before generating the upper levels of the expression.
55: Nowadays this is never zero. */
56: int do_preexpand_calls = 1;
57:
58: /* Number of units that we should eventually pop off the stack.
59: These are the arguments to function calls that have already returned. */
60: int pending_stack_adjust;
61:
62: /* Total size of arguments already pushed for function calls that
1.1.1.6 root 63: have not happened yet. When this is nonzero,
1.1 root 64: args passed to function calls must be popped right away
1.1.1.6 root 65: to ensure contiguity of argument lists for future calls.
66:
67: This can also be temporarily incremented for various other reasons
68: to inhibit deferring of pops. */
1.1.1.2 root 69: static int current_args_size;
1.1 root 70:
1.1.1.6 root 71: #define NO_DEFER_POP current_args_size += 1
72: #define OK_DEFER_POP current_args_size -= 1
73:
1.1.1.8 root 74: /* A list of all cleanup which belong to the arguments of
75: function calls being expanded by expand_call. */
76: static tree cleanups_of_this_call;
77:
1.1.1.2 root 78: /* Nonzero means current function may call alloca. */
79: int may_call_alloca;
80:
81: rtx store_expr ();
82: static void store_constructor ();
83: static rtx store_field ();
1.1 root 84: static rtx expand_call ();
1.1.1.2 root 85: static void emit_call_1 ();
86: static rtx prepare_call_address ();
87: static rtx expand_builtin ();
1.1 root 88: static rtx compare ();
1.1.1.2 root 89: static rtx compare_constants ();
1.1 root 90: static rtx compare1 ();
91: static rtx do_store_flag ();
92: static void preexpand_calls ();
1.1.1.2 root 93: static rtx expand_increment ();
94: static void move_by_pieces_1 ();
1.1.1.4 root 95: static int move_by_pieces_ninsns ();
1.1.1.2 root 96: static void init_queue ();
1.1.1.9 root 97: static void store_one_arg ();
98: static rtx target_for_arg ();
1.1.1.2 root 99:
100: void do_pending_stack_adjust ();
1.1 root 101:
102: /* MOVE_RATIO is the number of move instructions that is better than
103: a block move. */
104:
1.1.1.10 root 105: #ifndef MOVE_RATIO
106: #if defined (HAVE_movstrqi) || defined (HAVE_movstrhi) || defined (HAVE_movstrsi)
1.1 root 107: #define MOVE_RATIO 2
108: #else
1.1.1.10 root 109: /* A value of around 6 would minimize code size; infinity would minimize
110: execution time. */
111: #define MOVE_RATIO 15
112: #endif
1.1 root 113: #endif
114:
115: /* Table indexed by tree code giving 1 if the code is for a
116: comparison operation, or anything that is most easily
117: computed with a conditional branch.
118:
119: We include tree.def to give it the proper length.
120: The contents thus created are irrelevant.
121: The real contents are initialized in init_comparisons. */
122:
1.1.1.2 root 123: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) 0,
1.1 root 124:
125: static char comparison_code[] = {
126: #include "tree.def"
127: };
128: #undef DEFTREECODE
129:
1.1.1.2 root 130: /* This is run once per compilation. */
131:
132: void
1.1 root 133: init_comparisons ()
134: {
135: comparison_code[(int) EQ_EXPR] = 1;
136: comparison_code[(int) NE_EXPR] = 1;
137: comparison_code[(int) LT_EXPR] = 1;
138: comparison_code[(int) GT_EXPR] = 1;
139: comparison_code[(int) LE_EXPR] = 1;
140: comparison_code[(int) GE_EXPR] = 1;
141: }
1.1.1.2 root 142:
143: /* This is run at the start of compiling a function. */
144:
145: void
146: init_expr ()
147: {
148: init_queue ();
149: may_call_alloca = 0;
150: }
1.1 root 151:
152: /* Manage the queue of increment instructions to be output
153: for POSTINCREMENT_EXPR expressions, etc. */
154:
155: static rtx pending_chain;
156:
157: /* Queue up to increment (or change) VAR later. BODY says how:
158: BODY should be the same thing you would pass to emit_insn
159: to increment right away. It will go to emit_insn later on.
160:
161: The value is a QUEUED expression to be used in place of VAR
1.1.1.2 root 162: where you want to guarantee the pre-incrementation value of VAR. */
1.1 root 163:
164: static rtx
165: enqueue_insn (var, body)
166: rtx var, body;
167: {
168: pending_chain = gen_rtx (QUEUED, GET_MODE (var),
169: var, 0, 0, body, pending_chain);
170: return pending_chain;
171: }
172:
173: /* Use protect_from_queue to convert a QUEUED expression
174: into something that you can put immediately into an instruction.
175: If the queued incrementation has not happened yet,
176: protect_from_queue returns the variable itself.
177: If the incrementation has happened, protect_from_queue returns a temp
178: that contains a copy of the old value of the variable.
179:
180: Any time an rtx which might possibly be a QUEUED is to be put
181: into an instruction, it must be passed through protect_from_queue first.
182: QUEUED expressions are not meaningful in instructions.
183:
184: Do not pass a value through protect_from_queue and then hold
185: on to it for a while before putting it in an instruction!
186: If the queue is flushed in between, incorrect code will result. */
187:
188: rtx
189: protect_from_queue (x, modify)
190: register rtx x;
191: int modify;
192: {
193: register RTX_CODE code = GET_CODE (x);
194: if (code != QUEUED)
195: {
196: /* A special hack for read access to (MEM (QUEUED ...))
197: to facilitate use of autoincrement.
198: Make a copy of the contents of the memory location
199: rather than a copy of the address. */
200: if (code == MEM && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
201: {
202: register rtx y = XEXP (x, 0);
203: XEXP (x, 0) = QUEUED_VAR (y);
204: if (QUEUED_INSN (y))
205: {
206: register rtx temp = gen_reg_rtx (GET_MODE (x));
207: emit_insn_before (gen_move_insn (temp, x),
208: QUEUED_INSN (y));
209: return temp;
210: }
211: return x;
212: }
213: /* Otherwise, recursively protect the subexpressions of all
214: the kinds of rtx's that can contain a QUEUED. */
215: if (code == MEM)
216: XEXP (x, 0) = protect_from_queue (XEXP (x, 0), 0);
217: else if (code == PLUS || code == MULT)
218: {
219: XEXP (x, 0) = protect_from_queue (XEXP (x, 0), 0);
220: XEXP (x, 1) = protect_from_queue (XEXP (x, 1), 0);
221: }
222: return x;
223: }
224: /* If the increment has not happened, use the variable itself. */
225: if (QUEUED_INSN (x) == 0)
226: return QUEUED_VAR (x);
227: /* If the increment has happened and a pre-increment copy exists,
228: use that copy. */
229: if (QUEUED_COPY (x) != 0)
230: return QUEUED_COPY (x);
231: /* The increment has happened but we haven't set up a pre-increment copy.
232: Set one up now, and use it. */
233: QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
234: emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
235: QUEUED_INSN (x));
236: return QUEUED_COPY (x);
237: }
238:
1.1.1.2 root 239: /* Return nonzero if X contains a QUEUED expression:
240: if it contains anything that will be altered by a queued increment. */
241:
242: static int
243: queued_subexp_p (x)
244: rtx x;
245: {
246: register enum rtx_code code = GET_CODE (x);
247: switch (code)
248: {
249: case QUEUED:
250: return 1;
251: case MEM:
252: return queued_subexp_p (XEXP (x, 0));
253: case MULT:
254: case PLUS:
255: case MINUS:
256: return queued_subexp_p (XEXP (x, 0))
257: || queued_subexp_p (XEXP (x, 1));
258: }
259: return 0;
260: }
261:
262: /* Perform all the pending incrementations. */
1.1 root 263:
264: void
265: emit_queue ()
266: {
267: register rtx p;
268: while (p = pending_chain)
269: {
270: QUEUED_INSN (p) = emit_insn (QUEUED_BODY (p));
271: pending_chain = QUEUED_NEXT (p);
272: }
273: }
274:
1.1.1.2 root 275: static void
1.1 root 276: init_queue ()
277: {
278: if (pending_chain)
279: abort ();
280: }
281:
282: /* Copy data from FROM to TO, where the machine modes are not the same.
283: Both modes may be integer, or both may be floating.
284: UNSIGNEDP should be nonzero if FROM is an unsigned type.
285: This causes zero-extension instead of sign-extension. */
286:
287: void
288: convert_move (to, from, unsignedp)
289: register rtx to, from;
290: int unsignedp;
291: {
292: enum machine_mode to_mode = GET_MODE (to);
293: enum machine_mode from_mode = GET_MODE (from);
294: int to_real = to_mode == SFmode || to_mode == DFmode;
295: int from_real = from_mode == SFmode || from_mode == DFmode;
296: int extending = (int) to_mode > (int) from_mode;
297:
298: to = protect_from_queue (to, 1);
299: from = protect_from_queue (from, 0);
300:
301: if (to_real != from_real)
302: abort ();
303:
1.1.1.2 root 304: if (to_mode == from_mode
305: || (from_mode == VOIDmode && CONSTANT_P (from)))
1.1 root 306: {
307: emit_move_insn (to, from);
308: return;
309: }
310:
311: if (to_real)
312: {
313: #ifdef HAVE_extendsfdf2
314: if (HAVE_extendsfdf2 && extending)
315: {
1.1.1.2 root 316: emit_unop_insn (CODE_FOR_extendsfdf2, to, from, UNKNOWN);
1.1 root 317: return;
318: }
319: #endif
320: #ifdef HAVE_truncdfsf2
321: if (HAVE_truncdfsf2 && ! extending)
322: {
1.1.1.2 root 323: emit_unop_insn (CODE_FOR_truncdfsf2, to, from, UNKNOWN);
1.1 root 324: return;
325: }
326: #endif
327: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, (extending
1.1.1.2 root 328: ? "_extendsfdf2"
329: : "_truncdfsf2")),
330: GET_MODE (to), 1,
331: from, (extending ? SFmode : DFmode));
332: emit_move_insn (to, hard_libcall_value (GET_MODE (to)));
1.1 root 333: return;
334: }
335:
1.1.1.2 root 336: /* Now both modes are integers. */
337:
1.1 root 338: if (to_mode == DImode)
339: {
340: if (unsignedp)
341: {
1.1.1.5 root 342: emit_insn (gen_rtx (CLOBBER, VOIDmode, to));
1.1 root 343: convert_move (gen_lowpart (SImode, to), from, unsignedp);
344: emit_clr_insn (gen_highpart (SImode, to));
345: }
1.1.1.5 root 346: #ifdef HAVE_extendsidi2
347: else if (HAVE_extendsidi2)
348: emit_insn (gen_extendsidi2 (to, from));
349: #endif
1.1.1.2 root 350: #ifdef HAVE_slt
351: else if (HAVE_slt && insn_operand_mode[(int) CODE_FOR_slt][0] == SImode)
1.1 root 352: {
1.1.1.5 root 353: emit_insn (gen_rtx (CLOBBER, VOIDmode, to));
1.1 root 354: convert_move (gen_lowpart (SImode, to), from, unsignedp);
1.1.1.2 root 355: emit_insn (gen_slt (gen_highpart (SImode, to)));
1.1 root 356: }
357: #endif
358: else
359: {
360: register rtx label = gen_label_rtx ();
361:
1.1.1.5 root 362: emit_insn (gen_rtx (CLOBBER, VOIDmode, to));
1.1 root 363: emit_clr_insn (gen_highpart (SImode, to));
364: convert_move (gen_lowpart (SImode, to), from, unsignedp);
365: emit_cmp_insn (gen_lowpart (SImode, to),
366: gen_rtx (CONST_INT, VOIDmode, 0),
367: 0, 0);
1.1.1.6 root 368: NO_DEFER_POP;
1.1 root 369: emit_jump_insn (gen_bge (label));
370: expand_unop (SImode, one_cmpl_optab,
371: gen_highpart (SImode, to), gen_highpart (SImode, to),
372: 1);
373: emit_label (label);
1.1.1.6 root 374: OK_DEFER_POP;
1.1 root 375: }
376: return;
377: }
378:
379: if (from_mode == DImode)
380: {
381: convert_move (to, gen_lowpart (SImode, from), 0);
382: return;
383: }
384:
385: /* Now follow all the conversions between integers
386: no more than a word long. */
387:
1.1.1.2 root 388: /* For truncation, usually we can just refer to FROM in a narrower mode. */
389: if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
390: && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
391: GET_MODE_BITSIZE (from_mode))
392: && ((GET_CODE (from) == MEM
393: && ! mode_dependent_address_p (XEXP (from, 0)))
394: || GET_CODE (from) == REG))
395: {
396: emit_move_insn (to, gen_lowpart (to_mode, from));
397: return;
398: }
399:
1.1 root 400: if (to_mode == SImode && from_mode == HImode)
401: {
402: if (unsignedp)
403: {
404: #ifdef HAVE_zero_extendhisi2
405: if (HAVE_zero_extendhisi2)
1.1.1.2 root 406: emit_unop_insn (CODE_FOR_zero_extendhisi2, to, from, ZERO_EXTEND);
1.1 root 407: else
408: #endif
409: abort ();
410: }
411: else
412: {
413: #ifdef HAVE_extendhisi2
414: if (HAVE_extendhisi2)
1.1.1.2 root 415: emit_unop_insn (CODE_FOR_extendhisi2, to, from, SIGN_EXTEND);
1.1 root 416: else
417: #endif
418: abort ();
419: }
420: return;
421: }
422:
423: if (to_mode == SImode && from_mode == QImode)
424: {
425: if (unsignedp)
426: {
427: #ifdef HAVE_zero_extendqisi2
428: if (HAVE_zero_extendqisi2)
429: {
1.1.1.2 root 430: emit_unop_insn (CODE_FOR_zero_extendqisi2, to, from, ZERO_EXTEND);
1.1 root 431: return;
432: }
433: #endif
434: #if defined (HAVE_zero_extendqihi2) && defined (HAVE_extendhisi2)
435: if (HAVE_zero_extendqihi2 && HAVE_extendhisi2)
436: {
437: register rtx temp = gen_reg_rtx (HImode);
1.1.1.2 root 438: emit_unop_insn (CODE_FOR_zero_extendqihi2, temp, from, ZERO_EXTEND);
439: emit_unop_insn (CODE_FOR_extendhisi2, to, temp, SIGN_EXTEND);
1.1 root 440: return;
441: }
442: #endif
443: }
444: else
445: {
446: #ifdef HAVE_extendqisi2
447: if (HAVE_extendqisi2)
448: {
1.1.1.2 root 449: emit_unop_insn (CODE_FOR_extendqisi2, to, from, SIGN_EXTEND);
1.1 root 450: return;
451: }
452: #endif
453: #if defined (HAVE_extendqihi2) && defined (HAVE_extendhisi2)
454: if (HAVE_extendqihi2 && HAVE_extendhisi2)
455: {
456: register rtx temp = gen_reg_rtx (HImode);
1.1.1.2 root 457: emit_unop_insn (CODE_FOR_extendqihi2, temp, from, SIGN_EXTEND);
458: emit_unop_insn (CODE_FOR_extendhisi2, to, temp, SIGN_EXTEND);
1.1 root 459: return;
460: }
461: #endif
462: }
463: abort ();
464: }
465:
466: if (to_mode == HImode && from_mode == QImode)
467: {
468: if (unsignedp)
469: {
470: #ifdef HAVE_zero_extendqihi2
471: if (HAVE_zero_extendqihi2)
472: {
1.1.1.2 root 473: emit_unop_insn (CODE_FOR_zero_extendqihi2, to, from, ZERO_EXTEND);
1.1 root 474: return;
475: }
476: #endif
477: }
478: else
479: {
480: #ifdef HAVE_extendqihi2
481: if (HAVE_extendqihi2)
482: {
1.1.1.2 root 483: emit_unop_insn (CODE_FOR_extendqihi2, to, from, SIGN_EXTEND);
1.1 root 484: return;
485: }
486: #endif
487: }
488: abort ();
489: }
490:
491: /* Now we are truncating an integer to a smaller one.
492: If the result is a temporary, we might as well just copy it,
493: since only the low-order part of the result needs to be valid
494: and it is valid with no change. */
495:
496: if (GET_CODE (to) == REG)
497: {
498: if (GET_CODE (from) == REG)
499: {
500: emit_move_insn (to, gen_lowpart (GET_MODE (to), from));
501: return;
502: }
1.1.1.2 root 503: else if (GET_CODE (from) == SUBREG)
504: {
505: from = copy_rtx (from);
506: /* This is safe since FROM is not more than one word. */
507: PUT_MODE (from, GET_MODE (to));
508: emit_move_insn (to, from);
509: return;
510: }
1.1 root 511: #ifndef BYTES_BIG_ENDIAN
512: else if (GET_CODE (from) == MEM)
513: {
514: register rtx addr = XEXP (from, 0);
1.1.1.2 root 515: if (memory_address_p (GET_MODE (to), addr))
1.1 root 516: {
517: emit_move_insn (to, gen_rtx (MEM, GET_MODE (to), addr));
518: return;
519: }
520: }
521: #endif /* not BYTES_BIG_ENDIAN */
522: }
523:
524: if (from_mode == SImode && to_mode == HImode)
525: {
526: #ifdef HAVE_truncsihi2
527: if (HAVE_truncsihi2)
528: {
1.1.1.2 root 529: emit_unop_insn (CODE_FOR_truncsihi2, to, from, UNKNOWN);
1.1 root 530: return;
531: }
532: #endif
533: abort ();
534: }
535:
536: if (from_mode == SImode && to_mode == QImode)
537: {
538: #ifdef HAVE_truncsiqi2
539: if (HAVE_truncsiqi2)
540: {
1.1.1.2 root 541: emit_unop_insn (CODE_FOR_truncsiqi2, to, from, UNKNOWN);
1.1 root 542: return;
543: }
544: #endif
545: abort ();
546: }
547:
548: if (from_mode == HImode && to_mode == QImode)
549: {
550: #ifdef HAVE_trunchiqi2
551: if (HAVE_trunchiqi2)
552: {
1.1.1.2 root 553: emit_unop_insn (CODE_FOR_trunchiqi2, to, from, UNKNOWN);
1.1 root 554: return;
555: }
556: #endif
557: abort ();
558: }
1.1.1.2 root 559:
560: /* Mode combination is not recognized. */
561: abort ();
1.1 root 562: }
563:
564: /* Return an rtx for a value that would result
565: from converting X to mode MODE.
566: Both X and MODE may be floating, or both integer.
567: UNSIGNEDP is nonzero if X is an unsigned value.
568: This can be done by referring to a part of X in place
569: or by copying to a new temporary with conversion. */
570:
571: rtx
572: convert_to_mode (mode, x, unsignedp)
573: enum machine_mode mode;
574: rtx x;
575: int unsignedp;
576: {
577: register rtx temp;
578: if (mode == GET_MODE (x))
579: return x;
1.1.1.2 root 580: if (integer_mode_p (mode)
581: && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (x)))
1.1 root 582: return gen_lowpart (mode, x);
583: temp = gen_reg_rtx (mode);
584: convert_move (temp, x, unsignedp);
585: return temp;
586: }
1.1.1.2 root 587:
588: int
589: integer_mode_p (mode)
590: enum machine_mode mode;
591: {
592: return (int) mode > (int) VOIDmode && (int) mode <= (int) TImode;
593: }
1.1 root 594:
595: /* Generate several move instructions to copy LEN bytes
1.1.1.2 root 596: from block FROM to block TO. (These are MEM rtx's with BLKmode).
597: The caller must pass FROM and TO
1.1 root 598: through protect_from_queue before calling.
599: ALIGN (in bytes) is maximum alignment we can assume. */
600:
601: struct move_by_pieces
602: {
603: rtx to;
1.1.1.2 root 604: rtx to_addr;
1.1 root 605: int autinc_to;
606: int explicit_inc_to;
607: rtx from;
1.1.1.2 root 608: rtx from_addr;
1.1 root 609: int autinc_from;
610: int explicit_inc_from;
611: int len;
612: int offset;
613: int reverse;
614: };
615:
616: static void
1.1.1.2 root 617: move_by_pieces (to, from, len, align)
1.1 root 618: rtx to, from;
619: int len, align;
620: {
621: struct move_by_pieces data;
1.1.1.2 root 622: rtx to_addr = XEXP (to, 0), from_addr = XEXP (from, 0);
1.1 root 623:
624: data.offset = 0;
1.1.1.2 root 625: data.to_addr = to_addr;
626: data.from_addr = from_addr;
1.1 root 627: data.to = to;
628: data.from = from;
1.1.1.2 root 629: data.autinc_to
630: = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
631: || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
632: data.autinc_from
633: = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
634: || GET_CODE (from_addr) == POST_INC
635: || GET_CODE (from_addr) == POST_DEC);
1.1 root 636:
637: data.explicit_inc_from = 0;
638: data.explicit_inc_to = 0;
1.1.1.2 root 639: data.reverse
640: = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1.1 root 641: if (data.reverse) data.offset = len;
642: data.len = len;
643:
644: /* If copying requires more than two move insns,
645: copy addresses to registers (to make displacements shorter)
646: and use post-increment if available. */
647: if (!(data.autinc_from && data.autinc_to)
648: && move_by_pieces_ninsns (len, align) > 2)
649: {
650: #ifdef HAVE_PRE_DECREMENT
651: if (data.reverse && ! data.autinc_from)
652: {
1.1.1.2 root 653: data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
1.1 root 654: data.autinc_from = 1;
655: data.explicit_inc_from = -1;
656: }
657: #endif
658: #ifdef HAVE_POST_INCREMENT
659: if (! data.autinc_from)
660: {
1.1.1.2 root 661: data.from_addr = copy_addr_to_reg (from_addr);
1.1 root 662: data.autinc_from = 1;
663: data.explicit_inc_from = 1;
664: }
665: #endif
1.1.1.2 root 666: if (!data.autinc_from && CONSTANT_P (from_addr))
667: data.from_addr = copy_addr_to_reg (from_addr);
1.1 root 668: #ifdef HAVE_PRE_DECREMENT
669: if (data.reverse && ! data.autinc_to)
670: {
1.1.1.2 root 671: data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1.1 root 672: data.autinc_to = 1;
673: data.explicit_inc_to = -1;
674: }
675: #endif
676: #ifdef HAVE_POST_INCREMENT
677: if (! data.reverse && ! data.autinc_to)
678: {
1.1.1.2 root 679: data.to_addr = copy_addr_to_reg (to_addr);
1.1 root 680: data.autinc_to = 1;
681: data.explicit_inc_to = 1;
682: }
683: #endif
1.1.1.2 root 684: if (!data.autinc_to && CONSTANT_P (to_addr))
685: data.to_addr = copy_addr_to_reg (to_addr);
1.1 root 686: }
687:
688: #ifdef STRICT_ALIGNMENT
1.1.1.2 root 689: if (align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1.1 root 690: align = MOVE_MAX;
691: #else
692: align = MOVE_MAX;
693: #endif
694:
695: #ifdef HAVE_movti
696: if (HAVE_movti && align >= GET_MODE_SIZE (TImode))
697: move_by_pieces_1 (gen_movti, TImode, &data);
698: #endif
699: #ifdef HAVE_movdi
700: if (HAVE_movdi && align >= GET_MODE_SIZE (DImode))
701: move_by_pieces_1 (gen_movdi, DImode, &data);
702: #endif
1.1.1.2 root 703: #ifdef HAVE_movsi
1.1 root 704: if (align >= GET_MODE_SIZE (SImode))
705: move_by_pieces_1 (gen_movsi, SImode, &data);
1.1.1.2 root 706: #endif
707: #ifdef HAVE_movhi
708: if (HAVE_movhi && align >= GET_MODE_SIZE (HImode))
1.1 root 709: move_by_pieces_1 (gen_movhi, HImode, &data);
1.1.1.2 root 710: #endif
711: #ifdef HAVE_movqi
1.1 root 712: move_by_pieces_1 (gen_movqi, QImode, &data);
1.1.1.2 root 713: #else
714: movqi instruction required in machine description
715: #endif
1.1 root 716: }
717:
718: /* Return number of insns required to move L bytes by pieces.
719: ALIGN (in bytes) is maximum alignment we can assume. */
720:
1.1.1.2 root 721: static int
1.1 root 722: move_by_pieces_ninsns (l, align)
723: unsigned int l;
724: int align;
725: {
726: register int n_insns = 0;
727:
728: #ifdef STRICT_ALIGNMENT
1.1.1.2 root 729: if (align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1.1 root 730: align = MOVE_MAX;
731: #else
732: align = MOVE_MAX;
733: #endif
734:
735: #ifdef HAVE_movti
736: if (HAVE_movti && align >= GET_MODE_SIZE (TImode))
737: n_insns += l / GET_MODE_SIZE (TImode), l %= GET_MODE_SIZE (TImode);
738: #endif
739: #ifdef HAVE_movdi
740: if (HAVE_movdi && align >= GET_MODE_SIZE (DImode))
741: n_insns += l / GET_MODE_SIZE (DImode), l %= GET_MODE_SIZE (DImode);
742: #endif
1.1.1.2 root 743: #ifdef HAVE_movsi
1.1 root 744: if (HAVE_movsi && align >= GET_MODE_SIZE (SImode))
745: n_insns += l / GET_MODE_SIZE (SImode), l %= GET_MODE_SIZE (SImode);
1.1.1.2 root 746: #endif
747: #ifdef HAVE_movhi
1.1 root 748: if (HAVE_movhi && align >= GET_MODE_SIZE (HImode))
749: n_insns += l / GET_MODE_SIZE (HImode), l %= GET_MODE_SIZE (HImode);
1.1.1.2 root 750: #endif
1.1 root 751: n_insns += l;
752:
753: return n_insns;
754: }
755:
756: /* Subroutine of move_by_pieces. Move as many bytes as appropriate
757: with move instructions for mode MODE. GENFUN is the gen_... function
758: to make a move insn for that mode. DATA has all the other info. */
759:
1.1.1.2 root 760: static void
1.1 root 761: move_by_pieces_1 (genfun, mode, data)
762: rtx (*genfun) ();
763: enum machine_mode mode;
764: struct move_by_pieces *data;
765: {
766: register int size = GET_MODE_SIZE (mode);
767: register rtx to1, from1;
768:
1.1.1.2 root 769: #define add_offset(FLAG,X) \
770: (FLAG ? (X) : plus_constant ((X), data->offset))
1.1 root 771:
772: while (data->len >= size)
773: {
1.1.1.2 root 774: if (data->reverse) data->offset -= size;
1.1 root 775:
1.1.1.2 root 776: to1 = change_address (data->to, mode,
777: add_offset (data->autinc_to, data->to_addr));
778: from1 = change_address (data->from, mode,
779: add_offset (data->autinc_from, data->from_addr));
1.1 root 780:
781: #ifdef HAVE_PRE_DECREMENT
782: if (data->explicit_inc_to < 0)
1.1.1.2 root 783: emit_insn (gen_sub2_insn (data->to_addr,
1.1 root 784: gen_rtx (CONST_INT, VOIDmode, size)));
785: if (data->explicit_inc_from < 0)
1.1.1.2 root 786: emit_insn (gen_sub2_insn (data->from_addr,
1.1 root 787: gen_rtx (CONST_INT, VOIDmode, size)));
788: #endif
789:
1.1.1.5 root 790: emit_insn ((*genfun) (to1, from1));
1.1 root 791: #ifdef HAVE_POST_INCREMENT
792: if (data->explicit_inc_to > 0)
1.1.1.2 root 793: emit_insn (gen_add2_insn (data->to_addr,
1.1 root 794: gen_rtx (CONST_INT, VOIDmode, size)));
795: if (data->explicit_inc_from > 0)
1.1.1.2 root 796: emit_insn (gen_add2_insn (data->from_addr,
1.1 root 797: gen_rtx (CONST_INT, VOIDmode, size)));
798: #endif
799:
800: if (! data->reverse) data->offset += size;
1.1.1.2 root 801:
1.1 root 802: data->len -= size;
803: }
804: }
805:
806: /* Emit code to move a block Y to a block X.
807: This may be done with string-move instructions,
808: with multiple scalar move instructions, or with a library call.
809:
810: Both X and Y must be MEM rtx's (perhaps inside VOLATILE)
811: with mode BLKmode.
812: SIZE is an rtx that says how long they are.
813: ALIGN is the maximum alignment we can assume they have,
814: measured in bytes. */
815:
816: static void
817: emit_block_move (x, y, size, align)
818: rtx x, y;
819: rtx size;
820: int align;
821: {
822: if (GET_MODE (x) != BLKmode)
823: abort ();
824:
825: if (GET_MODE (y) != BLKmode)
826: abort ();
827:
828: x = protect_from_queue (x, 1);
829: y = protect_from_queue (y, 0);
830:
1.1.1.2 root 831: if (GET_CODE (x) != MEM)
1.1 root 832: abort ();
1.1.1.2 root 833: if (GET_CODE (y) != MEM)
1.1 root 834: abort ();
835: if (size == 0)
836: abort ();
837:
838: if (GET_CODE (size) == CONST_INT
839: && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
840: < MOVE_RATIO))
1.1.1.2 root 841: move_by_pieces (x, y, INTVAL (size), align);
1.1 root 842: else
843: {
1.1.1.9 root 844: /* Try the most limited insn first, because there's no point
845: including more than one in the machine description unless
846: the more limited one has some advantage. */
847: #ifdef HAVE_movstrqi
848: if (HAVE_movstrqi
849: && GET_CODE (size) == CONST_INT
850: && ((unsigned) INTVAL (size)
851: < (1 << (GET_MODE_BITSIZE (QImode) - 1))))
1.1 root 852: {
1.1.1.9 root 853: emit_insn (gen_movstrqi (x, y, size));
1.1 root 854: return;
855: }
856: #endif
857: #ifdef HAVE_movstrhi
858: if (HAVE_movstrhi
859: && GET_CODE (size) == CONST_INT
860: && ((unsigned) INTVAL (size)
1.1.1.5 root 861: < (1 << (GET_MODE_BITSIZE (HImode) - 1))))
1.1 root 862: {
863: emit_insn (gen_movstrhi (x, y, size));
864: return;
865: }
866: #endif
1.1.1.9 root 867: #ifdef HAVE_movstrsi
868: if (HAVE_movstrsi)
1.1.1.5 root 869: {
1.1.1.9 root 870: emit_insn (gen_movstrsi (x, y, size));
1.1.1.5 root 871: return;
872: }
873: #endif
1.1.1.2 root 874:
875: #ifdef TARGET_MEM_FUNCTIONS
876: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"),
877: VOIDmode, 3, XEXP (x, 0), Pmode,
878: XEXP (y, 0), Pmode,
879: size, Pmode);
880: #else
1.1 root 881: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"),
1.1.1.2 root 882: VOIDmode, 3, XEXP (y, 0), Pmode,
883: XEXP (x, 0), Pmode,
1.1 root 884: size, Pmode);
1.1.1.2 root 885: #endif
886: }
887: }
888:
889: /* Copy all or part of a BLKmode value X into registers starting at REGNO.
890: The number of registers to be filled is NREGS. */
891:
892: static void
893: move_block_to_reg (regno, x, nregs)
894: int regno;
895: rtx x;
896: int nregs;
897: {
898: int i;
899: if (GET_CODE (x) == CONST_DOUBLE && x != dconst0_rtx)
900: x = force_const_double_mem (x);
901: for (i = 0; i < nregs; i++)
902: {
903: if (GET_CODE (x) == REG)
904: emit_move_insn (gen_rtx (REG, SImode, regno + i),
905: gen_rtx (SUBREG, SImode, x, i));
906: else if (x == dconst0_rtx)
907: emit_move_insn (gen_rtx (REG, SImode, regno + i),
908: const0_rtx);
909: else
910: emit_move_insn (gen_rtx (REG, SImode, regno + i),
911: gen_rtx (MEM, SImode,
1.1.1.10 root 912: memory_address (SImode,
913: plus_constant (XEXP (x, 0),
914: i * GET_MODE_SIZE (SImode)))));
1.1.1.2 root 915: }
916: }
917:
918: /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
919: The number of registers to be filled is NREGS. */
920:
921: void
922: move_block_from_reg (regno, x, nregs)
923: int regno;
924: rtx x;
925: int nregs;
926: {
927: int i;
928: for (i = 0; i < nregs; i++)
929: {
930: if (GET_CODE (x) == REG)
931: emit_move_insn (gen_rtx (SUBREG, SImode, x, i),
932: gen_rtx (REG, SImode, regno + i));
933: else
934: emit_move_insn (gen_rtx (MEM, SImode,
1.1.1.10 root 935: memory_address (SImode,
936: plus_constant (XEXP (x, 0),
937: i * GET_MODE_SIZE (SImode)))),
1.1.1.2 root 938: gen_rtx (REG, SImode, regno + i));
1.1 root 939: }
940: }
1.1.1.2 root 941:
942: /* Mark NREGS consecutive regs, starting at REGNO, as being live now. */
943:
944: static void
945: use_regs (regno, nregs)
946: int regno;
947: int nregs;
948: {
949: int i;
950: for (i = 0; i < nregs; i++)
951: emit_insn (gen_rtx (USE, VOIDmode, gen_rtx (REG, SImode, regno + i)));
952: }
1.1 root 953:
1.1.1.2 root 954: /* Write zeros through the storage of OBJECT.
955: If OBJECT has BLKmode, SIZE is its length in bytes. */
956:
957: void
958: clear_storage (object, size)
959: rtx object;
960: int size;
961: {
962: if (GET_MODE (object) == BLKmode)
963: {
964: #ifdef TARGET_MEM_FUNCTIONS
965: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memset"),
966: VOIDmode, 3,
967: XEXP (object, 0), Pmode, const0_rtx, Pmode,
968: gen_rtx (CONST_INT, VOIDmode, size), Pmode);
969: #else
970: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bzero"),
971: VOIDmode, 2,
972: XEXP (object, 0), Pmode,
973: gen_rtx (CONST_INT, VOIDmode, size), Pmode);
974: #endif
975: }
976: else
977: emit_move_insn (object, const0_rtx, 0);
978: }
979:
1.1 root 980: /* Generate code to copy Y into X.
981: Both Y and X must have the same mode, except that
982: Y can be a constant with VOIDmode.
1.1.1.2 root 983: This mode cannot be BLKmode; use emit_block_move for that.
1.1 root 984:
1.1.1.2 root 985: Return the last instruction emitted. */
986:
987: rtx
1.1 root 988: emit_move_insn (x, y)
989: rtx x, y;
990: {
991: enum machine_mode mode = GET_MODE (x);
992: x = protect_from_queue (x, 1);
993: y = protect_from_queue (y, 0);
994:
1.1.1.3 root 995: if ((CONSTANT_P (y) || GET_CODE (y) == CONST_DOUBLE)
996: && ! LEGITIMATE_CONSTANT_P (y))
1.1.1.10 root 997: {
998: y = force_const_mem (mode, y);
999: if (! memory_address_p (mode, y))
1000: y = gen_rtx (MEM, mode, memory_address (mode, XEXP (y, 0)));
1001: }
1.1.1.2 root 1002:
1.1 root 1003: if (mode == BLKmode)
1004: abort ();
1.1.1.2 root 1005: if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1.1.1.6 root 1006: return
1.1.1.2 root 1007: emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
1008: #if 0
1009: /* It turns out you get much better optimization (in cse and flow)
1010: if you define movdi and movdf instruction patterns
1011: even if they must turn into multiple assembler instructions. */
1.1 root 1012: else if (GET_MODE_SIZE (mode) >= GET_MODE_SIZE (SImode))
1013: {
1014: register int count = GET_MODE_SIZE (mode) / GET_MODE_SIZE (SImode);
1015: register int i;
1.1.1.2 root 1016: if (GET_CODE (y) == CONST_DOUBLE && y != dconst0_rtx)
1017: y = force_const_double_mem (y);
1.1 root 1018: for (i = 0; i < count; i++)
1019: {
1020: rtx x1, y1;
1021: if (GET_CODE (x) == REG)
1022: x1 = gen_rtx (SUBREG, SImode, x, i);
1023: else
1024: x1 = gen_rtx (MEM, SImode,
1025: memory_address (SImode,
1026: plus_constant (XEXP (x, 0),
1027: i * GET_MODE_SIZE (SImode))));
1028: if (GET_CODE (y) == REG)
1029: y1 = gen_rtx (SUBREG, SImode, y, i);
1.1.1.2 root 1030: else if (y == dconst0_rtx)
1031: y1 = const0_rtx;
1.1 root 1032: else
1033: y1 = gen_rtx (MEM, SImode,
1034: memory_address (SImode,
1035: plus_constant (XEXP (y, 0),
1036: i * GET_MODE_SIZE (SImode))));
1037: emit_insn (gen_movsi (protect_from_queue (x1, 1), protect_from_queue (y1, 0)));
1038: }
1039: }
1.1.1.2 root 1040: #endif
1.1 root 1041: else
1042: abort ();
1043: }
1044:
1045: /* Pushing data onto the stack. */
1046:
1047: /* Push a block of length SIZE (perhaps variable)
1048: and return an rtx to address the beginning of the block.
1.1.1.4 root 1049: Note that it is not possible for the value returned to be a QUEUED.
1050: The value may be stack_pointer_rtx.
1051:
1.1.1.7 root 1052: The value we return does take account of STACK_POINTER_OFFSET. */
1.1 root 1053:
1.1.1.7 root 1054: rtx
1.1 root 1055: push_block (size)
1056: rtx size;
1057: {
1058: register rtx temp;
1.1.1.2 root 1059: if (CONSTANT_P (size) || GET_CODE (size) == REG)
1060: anti_adjust_stack (size);
1061: else
1062: anti_adjust_stack (copy_to_mode_reg (Pmode, size));
1.1.1.6 root 1063:
1.1 root 1064: #ifdef STACK_GROWS_DOWNWARD
1.1.1.2 root 1065: temp = stack_pointer_rtx;
1.1 root 1066: #else
1067: temp = gen_rtx (PLUS, Pmode,
1.1.1.2 root 1068: stack_pointer_rtx,
1.1.1.11! root 1069: negate_rtx (Pmode, size));
1.1 root 1070: if (GET_CODE (size) != CONST_INT)
1071: temp = force_operand (temp, 0);
1072: #endif
1.1.1.7 root 1073:
1074: #ifdef STACK_POINTER_OFFSET
1075: temp = plus_constant (temp, STACK_POINTER_OFFSET);
1076: #endif /* STACK_POINTER_OFFSET */
1077:
1.1 root 1078: return memory_address (QImode, temp);
1079: }
1080:
1081: static rtx
1082: gen_push_operand ()
1083: {
1084: return gen_rtx (
1085: #ifdef STACK_GROWS_DOWNWARD
1086: PRE_DEC,
1087: #else
1088: PRE_INC,
1089: #endif
1090: Pmode,
1.1.1.2 root 1091: stack_pointer_rtx);
1.1 root 1092: }
1093:
1094: /* Generate code to push X onto the stack, assuming it has mode MODE.
1095: MODE is redundant except when X is a CONST_INT (since they don't
1096: carry mode info).
1097: SIZE is an rtx for the size of data to be copied (in bytes),
1098: needed only if X is BLKmode.
1.1.1.2 root 1099: ALIGN (in bytes) is maximum alignment we can assume.
1100:
1101: If PARTIAL is nonzero, then copy that many of the first words
1102: of X into registers starting with REG, and push the rest of X.
1103: The amount of space pushed is decreased by PARTIAL words,
1104: rounded *down* to a multiple of PARM_BOUNDARY.
1105: REG must be a hard register in this case.
1106:
1107: EXTRA is the amount in bytes of extra space to leave next to this arg.
1108:
1109: On a machine that lacks real push insns, ARGS_ADDR is the address of
1110: the bottom of the argument block for this call. We use indexing off there
1111: to store the arg. On machines with push insns, ARGS_ADDR is 0.
1112:
1113: ARGS_SO_FAR is the size of args previously pushed for this call. */
1.1 root 1114:
1115: static void
1.1.1.2 root 1116: emit_push_insn (x, mode, size, align, partial, reg, extra, args_addr, args_so_far)
1.1 root 1117: register rtx x;
1118: enum machine_mode mode;
1119: rtx size;
1120: int align;
1.1.1.2 root 1121: int partial;
1122: rtx reg;
1123: int extra;
1124: rtx args_addr;
1125: rtx args_so_far;
1.1 root 1126: {
1127: rtx xinner;
1.1.1.6 root 1128: enum direction stack_direction
1129: #ifdef STACK_GROWS_DOWNWARD
1130: = downward;
1131: #else
1132: = upward;
1133: #endif
1134:
1135: /* Decide where to pad the argument: `downward' for below,
1136: `upward' for above, or `none' for don't pad it.
1137: Default is below for small data on big-endian machines; else above. */
1138: enum direction where_pad = FUNCTION_ARG_PADDING (mode, size);
1.1 root 1139:
1140: xinner = x = protect_from_queue (x, 0);
1141:
1.1.1.2 root 1142: /* If part should go in registers, copy that part
1143: into the appropriate registers. */
1144: if (partial > 0)
1145: move_block_to_reg (REGNO (reg), x, partial);
1146:
1.1.1.6 root 1147: if (extra)
1148: {
1149: if (args_addr == 0)
1150: {
1151: /* Push padding now if padding above and stack grows down,
1152: or if padding below and stack grows up. */
1153: if (where_pad != none && where_pad != stack_direction)
1154: anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, extra));
1155: }
1156: else
1157: {
1158: /* If space already allocated, just adjust the address we use. */
1159: if (where_pad == downward)
1160: args_so_far = plus_constant (args_so_far, extra);
1161: }
1162: }
1.1 root 1163:
1164: if (mode == BLKmode)
1165: {
1166: register rtx temp;
1.1.1.2 root 1167: int used = partial * UNITS_PER_WORD;
1168: int offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
1169:
1170: used -= used % (PARM_BOUNDARY / BITS_PER_UNIT);
1171:
1.1 root 1172: if (size == 0)
1173: abort ();
1174:
1.1.1.2 root 1175: if (partial != 0)
1176: xinner = change_address (xinner, BLKmode,
1177: plus_constant (XEXP (xinner, 0), used));
1178:
1179: #ifdef PUSH_ROUNDING
1180: /* Do it with several push insns if that doesn't take lots of insns
1181: and if there is no difficulty with push insns that skip bytes
1182: on the stack for alignment purposes. */
1183: if (args_addr == 0
1184: && GET_CODE (size) == CONST_INT
1185: && args_addr == 0
1186: && (move_by_pieces_ninsns ((unsigned) INTVAL (size) - used, align)
1187: < MOVE_RATIO)
1188: && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
1189: move_by_pieces (gen_rtx (MEM, BLKmode, gen_push_operand ()), xinner,
1190: INTVAL (size) - used, align);
1.1 root 1191: else
1.1.1.2 root 1192: #endif /* PUSH_ROUNDING */
1.1 root 1193: {
1.1.1.2 root 1194: /* Otherwise make space on the stack and copy the data
1195: to the address of that space. */
1196:
1197: /* First deduct part put into registers from the size we need. */
1198: if (partial != 0)
1199: {
1200: if (GET_CODE (size) == CONST_INT)
1201: size = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - used);
1202: else
1203: size = expand_binop (GET_MODE (size), sub_optab, size,
1204: gen_rtx (CONST_INT, VOIDmode, used),
1205: 0, 0, OPTAB_LIB_WIDEN);
1206: }
1207:
1208: /* Get the address of the stack space. */
1209: if (! args_addr)
1210: temp = push_block (size);
1211: else if (GET_CODE (args_so_far) == CONST_INT)
1212: temp = memory_address (BLKmode,
1213: plus_constant (args_addr,
1214: offset + INTVAL (args_so_far)));
1215: else
1216: temp = memory_address (BLKmode,
1217: plus_constant (gen_rtx (PLUS, Pmode,
1218: args_addr, args_so_far),
1219: offset));
1220:
1221:
1222: /* TEMP is the address of the block. Copy the data there. */
1223: if (GET_CODE (size) == CONST_INT
1224: && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
1225: < MOVE_RATIO))
1226: {
1227: move_by_pieces (gen_rtx (MEM, BLKmode, temp), xinner,
1228: INTVAL (size), align);
1229: return;
1230: }
1.1.1.9 root 1231: /* Try the most limited insn first, because there's no point
1232: including more than one in the machine description unless
1233: the more limited one has some advantage. */
1234: #ifdef HAVE_movstrqi
1235: if (HAVE_movstrqi
1236: && GET_CODE (size) == CONST_INT
1237: && ((unsigned) INTVAL (size)
1238: < (1 << (GET_MODE_BITSIZE (QImode) - 1))))
1.1 root 1239: {
1.1.1.9 root 1240: emit_insn (gen_movstrqi (gen_rtx (MEM, BLKmode, temp),
1241: x, size));
1.1 root 1242: return;
1243: }
1244: #endif
1245: #ifdef HAVE_movstrhi
1246: if (HAVE_movstrhi
1247: && GET_CODE (size) == CONST_INT
1248: && ((unsigned) INTVAL (size)
1.1.1.5 root 1249: < (1 << (GET_MODE_BITSIZE (HImode) - 1))))
1.1 root 1250: {
1251: emit_insn (gen_movstrhi (gen_rtx (MEM, BLKmode, temp),
1252: x, size));
1253: return;
1254: }
1255: #endif
1.1.1.9 root 1256: #ifdef HAVE_movstrsi
1257: if (HAVE_movstrsi)
1.1.1.5 root 1258: {
1.1.1.9 root 1259: emit_insn (gen_movstrsi (gen_rtx (MEM, BLKmode, temp), x, size));
1.1.1.5 root 1260: return;
1261: }
1262: #endif
1.1.1.2 root 1263:
1264: if (reg_mentioned_p (stack_pointer_rtx, temp))
1265: {
1266: /* Correct TEMP so it holds what will be a description of
1267: the address to copy to, valid after one arg is pushed. */
1.1.1.5 root 1268: int xsize = GET_MODE_SIZE (Pmode);
1269: #ifdef PUSH_ROUNDING
1270: xsize = PUSH_ROUNDING (xsize);
1271: #endif
1272: xsize = ((xsize + PARM_BOUNDARY / BITS_PER_UNIT - 1)
1273: / (PARM_BOUNDARY / BITS_PER_UNIT)
1274: * (PARM_BOUNDARY / BITS_PER_UNIT));
1.1.1.8 root 1275: #ifdef TARGET_MEM_FUNCTIONS
1276: /* If we are calling bcopy, we push one arg before TEMP.
1277: If calling memcpy, we push two. */
1278: xsize *= 2;
1279: #endif
1.1 root 1280: #ifdef STACK_GROWS_DOWNWARD
1.1.1.4 root 1281: temp = plus_constant (temp, xsize);
1.1 root 1282: #else
1.1.1.6 root 1283: temp = plus_constant (temp, -xsize);
1.1 root 1284: #endif
1.1.1.2 root 1285: }
1286:
1287: /* Make current_args_size nonzero around the library call
1288: to force it to pop the bcopy-arguments right away. */
1.1.1.9 root 1289: NO_DEFER_POP;
1.1.1.2 root 1290: #ifdef TARGET_MEM_FUNCTIONS
1291: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"),
1292: VOIDmode, 3, temp, Pmode, XEXP (xinner, 0), Pmode,
1293: size, Pmode);
1294: #else
1.1 root 1295: emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"),
1.1.1.2 root 1296: VOIDmode, 3, XEXP (xinner, 0), Pmode, temp, Pmode,
1.1 root 1297: size, Pmode);
1.1.1.2 root 1298: #endif
1.1.1.9 root 1299: OK_DEFER_POP;
1.1 root 1300: }
1301: }
1.1.1.2 root 1302: else if (partial > 0)
1.1 root 1303: {
1.1.1.2 root 1304: int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
1305: int i;
1306: int used = partial * UNITS_PER_WORD;
1.1.1.6 root 1307: /* # words of start of argument
1.1.1.2 root 1308: that we must make space for but need not store. */
1309: int skip = partial % (PARM_BOUNDARY / BITS_PER_WORD);
1310: int args_offset = INTVAL (args_so_far);
1.1.1.9 root 1311: int stack_offset;
1312:
1313: stack_offset = 0; /* This is a placeholder for a questionable change. */
1.1.1.2 root 1314:
1315: /* If we make space by pushing it, we might as well push
1316: the real data. Otherwise, we can leave SKIP nonzero
1317: and leave the space uninitialized. */
1318: if (args_addr == 0)
1319: skip = 0;
1320:
1321: /* Deduct all the rest of PARTIAL words from SIZE in any case.
1322: This is space that we don't even allocate in the stack. */
1323: used -= used % (PARM_BOUNDARY / BITS_PER_UNIT);
1324: size -= used / UNITS_PER_WORD;
1325:
1326: if (GET_CODE (x) == CONST_DOUBLE && x != dconst0_rtx)
1327: x = force_const_double_mem (x);
1328:
1329: #ifndef PUSH_ARGS_REVERSED
1330: for (i = skip; i < size; i++)
1331: #else
1332: for (i = size - 1; i >= skip; i--)
1333: #endif
1334: if (GET_CODE (x) == MEM)
1335: emit_push_insn (gen_rtx (MEM, SImode,
1336: plus_constant (XEXP (x, 0),
1.1.1.9 root 1337: stack_offset + i * UNITS_PER_WORD)),
1.1.1.2 root 1338: SImode, 0, align, 0, 0, 0, args_addr,
1339: gen_rtx (CONST_INT, VOIDmode,
1340: args_offset + i * UNITS_PER_WORD));
1341: else if (GET_CODE (x) == REG)
1342: emit_push_insn (gen_rtx (SUBREG, SImode, x, i),
1343: SImode, 0, align, 0, 0, 0, args_addr,
1344: gen_rtx (CONST_INT, VOIDmode,
1345: args_offset + i * UNITS_PER_WORD));
1346: else if (x == dconst0_rtx)
1347: emit_push_insn (const0_rtx,
1348: SImode, 0, align, 0, 0, 0, args_addr,
1349: gen_rtx (CONST_INT, VOIDmode,
1350: args_offset + i * UNITS_PER_WORD));
1351: else
1352: abort ();
1.1 root 1353: }
1354: else
1.1.1.2 root 1355: {
1356: rtx addr;
1357: #ifdef PUSH_ROUNDING
1358: if (args_addr == 0)
1359: addr = gen_push_operand ();
1360: else
1361: #endif
1362: if (GET_CODE (args_so_far) == CONST_INT)
1363: addr
1364: = memory_address (mode,
1365: plus_constant (args_addr, INTVAL (args_so_far)));
1366: else
1367: addr = memory_address (mode, gen_rtx (PLUS, Pmode, args_addr,
1368: args_so_far));
1369:
1370: emit_move_insn (gen_rtx (MEM, mode, addr), x);
1371: }
1372:
1.1.1.6 root 1373: if (extra && args_addr == 0 && where_pad == stack_direction)
1.1.1.2 root 1374: anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, extra));
1.1 root 1375: }
1376:
1377: /* Output a library call to function FUN (a SYMBOL_REF rtx)
1.1.1.2 root 1378: for a value of mode OUTMODE
1.1 root 1379: with NARGS different arguments, passed as alternating rtx values
1380: and machine_modes to convert them to.
1381: The rtx values should have been passed through protect_from_queue already. */
1382:
1383: void
1.1.1.2 root 1384: emit_library_call (va_alist)
1385: va_dcl
1.1 root 1386: {
1.1.1.2 root 1387: register va_list p;
1.1 root 1388: register int args_size = 0;
1389: register int argnum;
1.1.1.2 root 1390: enum machine_mode outmode;
1391: int nargs;
1392: rtx fun;
1393: rtx orgfun;
1394: int inc;
1395: int count;
1396: rtx *regvec;
1397: rtx argblock = 0;
1398: CUMULATIVE_ARGS args_so_far;
1399: struct arg { rtx value; enum machine_mode mode; };
1400: struct arg *argvec;
1401: int old_args_size = current_args_size;
1402:
1403: va_start (p);
1404: orgfun = fun = va_arg (p, rtx);
1405: outmode = va_arg (p, enum machine_mode);
1406: nargs = va_arg (p, int);
1407:
1408: regvec = (rtx *) alloca (nargs * sizeof (rtx));
1409:
1410: /* Copy all the libcall-arguments out of the varargs data
1411: and into a vector ARGVEC. */
1412: argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
1413: for (count = 0; count < nargs; count++)
1414: {
1415: argvec[count].value = va_arg (p, rtx);
1416: argvec[count].mode = va_arg (p, enum machine_mode);
1417: }
1418: va_end (p);
1419:
1420: /* If we have no actual push instructions, make space for all the args
1421: right now. */
1422: #ifndef PUSH_ROUNDING
1423: INIT_CUMULATIVE_ARGS (args_so_far, (tree)0);
1424: for (count = 0; count < nargs; count++)
1425: {
1426: register enum machine_mode mode = argvec[count].mode;
1427: register rtx reg;
1428: register int partial;
1429:
1430: reg = FUNCTION_ARG (args_so_far, mode, 0, 1);
1431: #ifdef FUNCTION_ARG_PARTIAL_NREGS
1432: partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, 0, 1);
1433: #else
1434: partial = 0;
1435: #endif
1436: if (reg == 0 || partial != 0)
1437: args_size += GET_MODE_SIZE (mode);
1438: if (partial != 0)
1439: args_size -= partial * GET_MODE_SIZE (SImode);
1440: FUNCTION_ARG_ADVANCE (args_so_far, mode, 0, 1);
1441: }
1442:
1443: if (args_size != 0)
1444: argblock
1445: = push_block (round_push (gen_rtx (CONST_INT, VOIDmode, args_size)));
1446: #endif
1447:
1448: INIT_CUMULATIVE_ARGS (args_so_far, (tree)0);
1449:
1450: #ifdef PUSH_ARGS_REVERSED
1451: inc = -1;
1452: argnum = nargs - 1;
1.1 root 1453: #else
1.1.1.2 root 1454: inc = 1;
1455: argnum = 0;
1.1 root 1456: #endif
1.1.1.2 root 1457: args_size = 0;
1458:
1459: for (count = 0; count < nargs; count++, argnum += inc)
1.1 root 1460: {
1.1.1.2 root 1461: register enum machine_mode mode = argvec[argnum].mode;
1462: register rtx val = argvec[argnum].value;
1463: rtx reg;
1464: int partial;
1465: int arg_size;
1466:
1.1 root 1467: /* Convert the arg value to the mode the library wants. */
1468: /* ??? It is wrong to do it here; must do it earlier
1469: where we know the signedness of the arg. */
1470: if (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode)
1471: {
1472: val = gen_reg_rtx (mode);
1.1.1.2 root 1473: convert_move (val, argvec[argnum].value, 0);
1.1 root 1474: }
1.1.1.2 root 1475: reg = FUNCTION_ARG (args_so_far, mode, 0, 1);
1476: regvec[argnum] = reg;
1477: #ifdef FUNCTION_ARG_PARTIAL_NREGS
1478: partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, 0, 1);
1479: #else
1480: partial = 0;
1481: #endif
1482:
1483: if (reg != 0 && partial == 0)
1484: emit_move_insn (reg, val);
1485: else
1486: emit_push_insn (val, mode, 0, 0, partial, reg, 0, argblock,
1487: gen_rtx (CONST_INT, VOIDmode, args_size));
1488:
1489: /* Compute size of stack space used by this argument. */
1490: if (reg == 0 || partial != 0)
1491: arg_size = GET_MODE_SIZE (mode);
1492: else
1493: arg_size = 0;
1494: if (partial != 0)
1495: arg_size
1496: -= ((partial * UNITS_PER_WORD)
1497: / (PARM_BOUNDARY / BITS_PER_UNIT)
1498: * (PARM_BOUNDARY / BITS_PER_UNIT));
1499:
1500: args_size += arg_size;
1.1.1.9 root 1501: NO_DEFER_POP;
1.1.1.2 root 1502: FUNCTION_ARG_ADVANCE (args_so_far, mode, 0, 1);
1.1 root 1503: }
1504:
1505: emit_queue ();
1.1.1.2 root 1506:
1507: fun = prepare_call_address (fun, 0);
1508:
1509: /* Any regs containing parms remain in use through the call.
1510: ??? This is not quite correct, since it doesn't indicate
1511: that they are in use immediately before the call insn.
1512: Currently that doesn't matter since explicitly-used regs
1513: won't be used for reloading. But if the reloader becomes smarter,
1514: this will have to change somehow. */
1515: for (count = 0; count < nargs; count++)
1516: if (regvec[count] != 0)
1517: emit_insn (gen_rtx (USE, VOIDmode, regvec[count]));
1518:
1519: #ifdef STACK_BOUNDARY
1520: args_size = (args_size + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES;
1521: #endif
1522:
1.1.1.3 root 1523: /* Don't allow popping to be deferred, since then
1524: cse'ing of library calls could delete a call and leave the pop. */
1.1.1.9 root 1525: NO_DEFER_POP;
1.1.1.2 root 1526: emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size,
1527: FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1528: outmode != VOIDmode ? hard_libcall_value (outmode) : 0,
1.1.1.3 root 1529: old_args_size + 1);
1.1.1.9 root 1530: OK_DEFER_POP;
1.1 root 1531: }
1532:
1533: /* Expand an assignment that stores the value of FROM into TO.
1.1.1.2 root 1534: If WANT_VALUE is nonzero, return an rtx for the value of TO.
1535: (This may contain a QUEUED rtx.)
1536: Otherwise, the returned value is not meaningful.
1537:
1538: SUGGEST_REG is no longer actually used.
1539: It used to mean, copy the value through a register
1540: and return that register, if that is possible.
1541: But now we do this if WANT_VALUE.
1542:
1543: If the value stored is a constant, we return the constant. */
1.1 root 1544:
1545: rtx
1.1.1.2 root 1546: expand_assignment (to, from, want_value, suggest_reg)
1.1 root 1547: tree to, from;
1.1.1.2 root 1548: int want_value;
1549: int suggest_reg;
1.1 root 1550: {
1551: register rtx to_rtx = 0;
1552:
1553: /* Don't crash if the lhs of the assignment was erroneous. */
1554:
1555: if (TREE_CODE (to) == ERROR_MARK)
1556: return expand_expr (from, 0, VOIDmode, 0);
1557:
1558: /* Assignment of a structure component needs special treatment
1.1.1.2 root 1559: if the structure component's rtx is not simply a MEM.
1560: Assignment of an array element at a constant index
1561: has the same problem. */
1562:
1563: if (TREE_CODE (to) == COMPONENT_REF
1564: || (TREE_CODE (to) == ARRAY_REF
1565: && TREE_CODE (TREE_OPERAND (to, 1)) == INTEGER_CST
1566: && TREE_CODE (TYPE_SIZE (TREE_TYPE (to))) == INTEGER_CST))
1.1 root 1567: {
1.1.1.2 root 1568: register enum machine_mode mode1;
1569: int bitsize;
1.1 root 1570: int volstruct = 0;
1.1.1.2 root 1571: tree tem = to;
1572: int bitpos = 0;
1573: int unsignedp;
1.1 root 1574:
1.1.1.2 root 1575: if (TREE_CODE (to) == COMPONENT_REF)
1.1 root 1576: {
1577: tree field = TREE_OPERAND (to, 1);
1.1.1.2 root 1578: bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
1579: mode1 = DECL_MODE (TREE_OPERAND (to, 1));
1580: unsignedp = TREE_UNSIGNED (field);
1.1 root 1581: }
1.1.1.2 root 1582: else
1.1 root 1583: {
1.1.1.2 root 1584: mode1 = TYPE_MODE (TREE_TYPE (to));
1585: bitsize = GET_MODE_BITSIZE (mode1);
1586: unsignedp = TREE_UNSIGNED (TREE_TYPE (to));
1.1 root 1587: }
1588:
1.1.1.2 root 1589: /* Compute cumulative bit-offset for nested component-refs
1590: and array-refs, and find the ultimate containing object. */
1.1 root 1591:
1.1.1.2 root 1592: while (1)
1.1 root 1593: {
1.1.1.2 root 1594: if (TREE_CODE (tem) == COMPONENT_REF)
1595: {
1596: bitpos += DECL_OFFSET (TREE_OPERAND (tem, 1));
1597: if (TREE_THIS_VOLATILE (tem))
1598: volstruct = 1;
1599: }
1600: else if (TREE_CODE (tem) == ARRAY_REF
1601: && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
1602: && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) == INTEGER_CST)
1603: {
1604: bitpos += (TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))
1605: * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)))
1606: * TYPE_SIZE_UNIT (TREE_TYPE (tem)));
1607: }
1608: else
1609: break;
1610: tem = TREE_OPERAND (tem, 0);
1.1 root 1611: }
1612:
1.1.1.2 root 1613: /* If we are going to use store_bit_field and extract_bit_field,
1614: make sure to_rtx will be safe for multiple use. */
1615: if (mode1 == BImode && want_value)
1616: tem = stabilize_reference (tem);
1.1 root 1617:
1.1.1.2 root 1618: to_rtx = expand_expr (tem, 0, VOIDmode, 0);
1619:
1620: return store_field (to_rtx, bitsize, bitpos, mode1, from,
1.1.1.10 root 1621: (want_value
1622: /* Spurious cast makes HPUX compiler happy. */
1623: ? (enum machine_mode) TYPE_MODE (TREE_TYPE (to))
1624: : VOIDmode),
1.1.1.2 root 1625: unsignedp);
1.1 root 1626: }
1627:
1628: /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
1629: Don't re-expand if it was expanded already (in COMPONENT_REF case). */
1630:
1631: if (to_rtx == 0)
1632: to_rtx = expand_expr (to, 0, VOIDmode, 0);
1633:
1634: /* Compute FROM and store the value in the rtx we got. */
1635:
1.1.1.2 root 1636: return store_expr (from, to_rtx, want_value);
1.1 root 1637: }
1638:
1639: /* Generate code for computing expression EXP,
1.1.1.2 root 1640: and storing the value into TARGET.
1641: Returns TARGET or an equivalent value.
1642: TARGET may contain a QUEUED rtx.
1.1 root 1643:
1.1.1.2 root 1644: If SUGGEST_REG is nonzero, copy the value through a register
1645: and return that register, if that is possible.
1646:
1647: If the value stored is a constant, we return the constant. */
1648:
1649: rtx
1650: store_expr (exp, target, suggest_reg)
1.1 root 1651: register tree exp;
1652: register rtx target;
1.1.1.2 root 1653: int suggest_reg;
1.1 root 1654: {
1.1.1.2 root 1655: register rtx temp;
1656: int dont_return_target = 0;
1657:
1658: /* Copying a non-constant CONSTRUCTOR needs special treatment. */
1659:
1660: if (TREE_CODE (exp) == CONSTRUCTOR && ! TREE_LITERAL (exp))
1661: {
1662: store_constructor (exp, target);
1663: return target;
1664: }
1665:
1666: if (suggest_reg && GET_CODE (target) == MEM && GET_MODE (target) != BLKmode)
1667: /* If target is in memory and caller wants value in a register instead,
1668: arrange that. Pass TARGET as target for expand_expr so that,
1669: if EXP is another assignment, SUGGEST_REG will be nonzero for it.
1670: We know expand_expr will not use the target in that case. */
1671: {
1672: temp = expand_expr (exp, cse_not_expected ? 0 : target,
1673: GET_MODE (target), 0);
1674: if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
1675: temp = copy_to_reg (temp);
1676: dont_return_target = 1;
1677: }
1678: else if (queued_subexp_p (target))
1679: /* If target contains a postincrement, it is not safe
1680: to use as the returned value. It would access the wrong
1681: place by the time the queued increment gets output.
1682: So copy the value through a temporary and use that temp
1683: as the result. */
1684: {
1685: temp = expand_expr (exp, 0, GET_MODE (target), 0);
1686: if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
1687: temp = copy_to_reg (temp);
1688: dont_return_target = 1;
1689: }
1690: else
1691: {
1692: temp = expand_expr (exp, target, GET_MODE (target), 0);
1693: /* DO return TARGET if it's a specified hardware register.
1694: expand_return relies on this. */
1695: if (!(target && GET_CODE (target) == REG
1696: && REGNO (target) < FIRST_PSEUDO_REGISTER)
1697: && (CONSTANT_P (temp) || GET_CODE (temp) == CONST_DOUBLE))
1698: dont_return_target = 1;
1699: }
1700:
1701: /* If value was not generated in the target, store it there. */
1702:
1.1 root 1703: if (temp != target && TREE_CODE (exp) != ERROR_MARK)
1704: {
1705: target = protect_from_queue (target, 1);
1706: if (GET_MODE (temp) != GET_MODE (target)
1707: && GET_MODE (temp) != VOIDmode)
1.1.1.2 root 1708: {
1709: int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1710: if (dont_return_target)
1711: temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
1712: else
1713: convert_move (target, temp, unsignedp);
1714: }
1715:
1.1 root 1716: else if (GET_MODE (temp) == BLKmode)
1717: emit_block_move (target, temp, expr_size (exp),
1718: TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
1719: else
1720: emit_move_insn (target, temp);
1721: }
1.1.1.2 root 1722: if (dont_return_target)
1723: return temp;
1.1 root 1724: return target;
1725: }
1726:
1.1.1.2 root 1727: /* Store the value of constructor EXP into the rtx TARGET.
1728: TARGET is either a REG or a MEM. */
1.1 root 1729:
1.1.1.2 root 1730: static void
1731: store_constructor (exp, target)
1732: tree exp;
1733: rtx target;
1.1 root 1734: {
1.1.1.7 root 1735: /* Don't try copying piece by piece into a hard register
1736: since that is vulnerable to being clobbered by EXP.
1737: Instead, construct in a pseudo register and then copy it all. */
1738: if (GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER)
1739: {
1740: rtx temp = gen_reg_rtx (GET_MODE (target));
1741: store_constructor (exp, temp);
1742: emit_move_insn (target, temp);
1743: return;
1744: }
1745:
1.1.1.2 root 1746: if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1.1 root 1747: {
1.1.1.2 root 1748: register tree elt;
1.1 root 1749:
1.1.1.2 root 1750: /* If the constructor has fewer fields than the structure,
1751: clear the whole structure first. */
1.1 root 1752:
1.1.1.2 root 1753: if (list_length (CONSTRUCTOR_ELTS (exp))
1754: != list_length (TYPE_FIELDS (TREE_TYPE (exp))))
1755: clear_storage (target, int_size_in_bytes (TREE_TYPE (exp)));
1756: else
1757: /* Inform later passes that the old value is dead. */
1758: emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
1759:
1760: /* Store each element of the constructor into
1761: the corresponding field of TARGET. */
1762:
1763: for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
1764: {
1765: register tree field = TREE_PURPOSE (elt);
1766: register enum machine_mode mode;
1767: int bitsize;
1768: int bitpos;
1769: int unsignedp;
1770:
1771: bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
1772: mode = DECL_MODE (field);
1773: unsignedp = TREE_UNSIGNED (field);
1774:
1775: bitpos = DECL_OFFSET (field);
1776:
1777: store_field (target, bitsize, bitpos, mode, TREE_VALUE (elt),
1778: VOIDmode, 0);
1779: }
1780: }
1781: else if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1782: {
1783: register tree elt;
1784: register int i;
1785: tree domain = TYPE_DOMAIN (TREE_TYPE (exp));
1786: int minelt = TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain));
1787: int maxelt = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain));
1788: tree elttype = TREE_TYPE (TREE_TYPE (exp));
1789:
1790: /* If the constructor has fewer fields than the structure,
1791: clear the whole structure first. */
1792:
1793: if (list_length (CONSTRUCTOR_ELTS (exp)) < maxelt - minelt + 1)
1794: clear_storage (target, maxelt - minelt + 1);
1795: else
1796: /* Inform later passes that the old value is dead. */
1797: emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
1798:
1799: /* Store each element of the constructor into
1800: the corresponding element of TARGET, determined
1801: by counting the elements. */
1802: for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
1803: elt;
1804: elt = TREE_CHAIN (elt), i++)
1805: {
1806: register enum machine_mode mode;
1807: int bitsize;
1808: int bitpos;
1809: int unsignedp;
1810:
1811: mode = TYPE_MODE (elttype);
1812: bitsize = GET_MODE_BITSIZE (mode);
1813: unsignedp = TREE_UNSIGNED (elttype);
1814:
1815: bitpos = (i * TREE_INT_CST_LOW (TYPE_SIZE (elttype))
1816: * TYPE_SIZE_UNIT (elttype));
1817:
1818: store_field (target, bitsize, bitpos, mode, TREE_VALUE (elt),
1819: VOIDmode, 0);
1820: }
1821: }
1822: }
1823:
1824: /* Store the value of EXP (an expression tree)
1825: into a subfield of TARGET which has mode MODE and occupies
1826: BITSIZE bits, starting BITPOS bits from the start of TARGET.
1827:
1828: If VALUE_MODE is VOIDmode, return nothing in particular.
1829: UNSIGNEDP is not used in this case.
1830:
1831: Otherwise, return an rtx for the value stored. This rtx
1832: has mode VALUE_MODE if that is convenient to do.
1833: In this case, UNSIGNEDP must be nonzero if the value is an unsigned type. */
1834:
1835: static rtx
1836: store_field (target, bitsize, bitpos, mode, exp, value_mode, unsignedp)
1837: rtx target;
1838: int bitsize, bitpos;
1839: enum machine_mode mode;
1840: tree exp;
1841: enum machine_mode value_mode;
1842: int unsignedp;
1843: {
1844: /* If the structure is in a register or if the component
1845: is a bit field, we cannot use addressing to access it.
1846: Use bit-field techniques or SUBREG to store in it. */
1847:
1848: if (mode == BImode || GET_CODE (target) == REG
1849: || GET_CODE (target) == SUBREG)
1850: {
1851: store_bit_field (target, bitsize, bitpos,
1852: mode,
1853: expand_expr (exp, 0, VOIDmode, 0));
1854: if (value_mode != VOIDmode)
1855: return extract_bit_field (target, bitsize, bitpos, unsignedp,
1856: 0, value_mode, 0);
1857: return const0_rtx;
1858: }
1859: else
1860: {
1861: rtx addr = XEXP (target, 0);
1862: rtx to_rtx;
1863:
1864: /* If a value is wanted, it must be the lhs;
1865: so make the address stable for multiple use. */
1866:
1867: if (value_mode != VOIDmode && GET_CODE (addr) != REG
1868: && ! CONSTANT_ADDRESS_P (addr))
1869: addr = copy_to_reg (addr);
1870:
1871: /* Now build a reference to just the desired component. */
1872:
1873: to_rtx = change_address (target, mode,
1874: plus_constant (addr,
1875: (bitpos / BITS_PER_UNIT)));
1.1.1.10 root 1876: MEM_IN_STRUCT_P (to_rtx) = 1;
1.1.1.2 root 1877:
1878: return store_expr (exp, to_rtx, value_mode != VOIDmode);
1879: }
1880: }
1881:
1882: /* Given an rtx VALUE that may contain additions and multiplications,
1883: return an equivalent value that just refers to a register or memory.
1884: This is done by generating instructions to perform the arithmetic
1885: and returning a pseudo-register containing the value. */
1886:
1887: rtx
1888: force_operand (value, target)
1889: rtx value, target;
1890: {
1891: register optab binoptab = 0;
1892: register rtx op2;
1893: /* Use subtarget as the target for operand 0 of a binary operation. */
1894: register rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
1895:
1896: if (GET_CODE (value) == PLUS)
1897: binoptab = add_optab;
1898: else if (GET_CODE (value) == MINUS)
1899: binoptab = sub_optab;
1900: else if (GET_CODE (value) == MULT)
1901: {
1902: op2 = XEXP (value, 1);
1903: if (!CONSTANT_P (op2)
1904: && !(GET_CODE (op2) == REG && op2 != subtarget))
1905: subtarget = 0;
1906: return expand_mult (GET_MODE (value),
1907: force_operand (XEXP (value, 0), subtarget),
1908: force_operand (op2, 0),
1909: target, 0);
1910: }
1911:
1912: if (binoptab)
1913: {
1914: op2 = XEXP (value, 1);
1915: if (!CONSTANT_P (op2)
1916: && !(GET_CODE (op2) == REG && op2 != subtarget))
1917: subtarget = 0;
1918: if (binoptab == sub_optab
1919: && GET_CODE (op2) == CONST_INT && INTVAL (op2) < 0)
1920: {
1921: binoptab = add_optab;
1922: op2 = gen_rtx (CONST_INT, VOIDmode, - INTVAL (op2));
1923: }
1924: return expand_binop (GET_MODE (value), binoptab,
1925: force_operand (XEXP (value, 0), subtarget),
1926: force_operand (op2, 0),
1927: target, 0, OPTAB_LIB_WIDEN);
1928: /* We give UNSIGNEP = 0 to expand_binop
1929: because the only operations we are expanding here are signed ones. */
1930: }
1931: return value;
1932: }
1933:
1934: /* expand_expr: generate code for computing expression EXP.
1935: An rtx for the computed value is returned.
1936:
1937: The value may be stored in TARGET if TARGET is nonzero.
1.1 root 1938: TARGET is just a suggestion; callers must assume that
1939: the rtx returned may not be the same as TARGET.
1940:
1.1.1.2 root 1941: If TARGET is CONST0_RTX, it means that the value will be ignored.
1942:
1.1 root 1943: If TMODE is not VOIDmode, it suggests generating the
1944: result in mode TMODE. But this is done only when convenient.
1945: Otherwise, TMODE is ignored and the value generated in its natural mode.
1946: TMODE is just a suggestion; callers must assume that
1947: the rtx returned may not have mode TMODE.
1948:
1.1.1.2 root 1949: If MODIFIER is EXPAND_SUM then when EXP is an addition
1.1 root 1950: we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
1951: or a nest of (PLUS ...) and (MINUS ...) where the terms are
1952: products as above, or REG or MEM, or constant.
1.1.1.2 root 1953: Ordinarily in such cases we would output mul or add instructions
1954: and then return a pseudo reg containing the sum.
1955:
1956: If MODIFIER is EXPAND_CONST_ADDRESS then it is ok to return
1957: a MEM rtx whose address is a constant that isn't a legitimate address. */
1.1 root 1958:
1959: /* Subroutine of expand_expr:
1960: return the target to use when recursively expanding
1961: the first operand of an arithmetic operation. */
1962:
1963: static rtx
1964: validate_subtarget (subtarget, otherop)
1965: rtx subtarget;
1966: tree otherop;
1967: {
1968: if (TREE_LITERAL (otherop))
1969: return subtarget;
1970: if (TREE_CODE (otherop) == VAR_DECL
1971: && DECL_RTL (otherop) != subtarget)
1972: return subtarget;
1973: return 0;
1974: }
1975:
1976: rtx
1.1.1.2 root 1977: expand_expr (exp, target, tmode, modifier)
1.1 root 1978: register tree exp;
1979: rtx target;
1980: enum machine_mode tmode;
1.1.1.2 root 1981: enum expand_modifier modifier;
1.1 root 1982: {
1983: register rtx op0, op1, temp;
1984: tree type = TREE_TYPE (exp);
1985: register enum machine_mode mode = TYPE_MODE (type);
1986: register enum tree_code code = TREE_CODE (exp);
1.1.1.2 root 1987: optab this_optab;
1.1 root 1988: int negate_1;
1989: /* Use subtarget as the target for operand 0 of a binary operation. */
1990: rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
1.1.1.2 root 1991: rtx original_target = target;
1992: int ignore = target == const0_rtx;
1993:
1.1.1.7 root 1994: /* Don't use hard regs as subtargets, because the combiner
1995: can only handle pseudo regs. */
1996: if (subtarget && REGNO (subtarget) < FIRST_PSEUDO_REGISTER)
1997: subtarget = 0;
1998:
1.1.1.2 root 1999: if (ignore) target = 0, original_target = 0;
1.1 root 2000:
2001: /* If will do cse, generate all results into registers
2002: since 1) that allows cse to find more things
2003: and 2) otherwise cse could produce an insn the machine
2004: cannot support. */
2005:
2006: if (! cse_not_expected && mode != BLKmode)
2007: target = subtarget;
2008:
1.1.1.2 root 2009: /* No sense saving up arithmetic to be done
2010: if it's all in the wrong mode to form part of an address.
2011: And force_operand won't know whether to sign-extend or zero-extend. */
2012:
2013: if (mode != Pmode && modifier == EXPAND_SUM)
1.1.1.6 root 2014: modifier = EXPAND_NORMAL;
1.1.1.2 root 2015:
1.1 root 2016: switch (code)
2017: {
1.1.1.4 root 2018: case PARM_DECL:
2019: if (DECL_RTL (exp) == 0)
2020: {
2021: error_with_decl (exp, "prior parameter's size depends on `%s'");
2022: return const0_rtx;
2023: }
2024:
1.1 root 2025: case FUNCTION_DECL:
2026: case VAR_DECL:
2027: case RESULT_DECL:
2028: if (DECL_RTL (exp) == 0)
2029: abort ();
2030: if (GET_CODE (DECL_RTL (exp)) == SYMBOL_REF)
2031: abort ();
1.1.1.2 root 2032: if (GET_CODE (DECL_RTL (exp)) == MEM
2033: && modifier != EXPAND_CONST_ADDRESS)
2034: {
2035: /* DECL_RTL probably contains a constant address.
2036: On RISC machines where a constant address isn't valid,
2037: make some insns to get that address into a register. */
1.1.1.7 root 2038: if (!memory_address_p (DECL_MODE (exp), XEXP (DECL_RTL (exp), 0))
2039: || (flag_force_addr
2040: && CONSTANT_ADDRESS_P (XEXP (DECL_RTL (exp), 0))))
1.1.1.2 root 2041: return change_address (DECL_RTL (exp), VOIDmode,
2042: copy_rtx (XEXP (DECL_RTL (exp), 0)));
2043: }
1.1 root 2044: return DECL_RTL (exp);
2045:
2046: case INTEGER_CST:
1.1.1.7 root 2047: if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT)
2048: return gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (exp));
1.1.1.8 root 2049: /* Generate immediate CONST_DOUBLE
1.1.1.7 root 2050: which will be turned into memory by reload if necessary. */
1.1.1.8 root 2051: #ifdef WORDS_BIG_ENDIAN
2052: return immed_double_const (TREE_INT_CST_HIGH (exp),
2053: TREE_INT_CST_LOW (exp),
2054: mode);
2055: #else
2056: return immed_double_const (TREE_INT_CST_LOW (exp),
2057: TREE_INT_CST_HIGH (exp),
2058: mode);
2059: #endif
1.1 root 2060:
2061: case CONST_DECL:
2062: return expand_expr (DECL_INITIAL (exp), target, VOIDmode, 0);
2063:
2064: case REAL_CST:
1.1.1.7 root 2065: /* If optimized, generate immediate CONST_DOUBLE
2066: which will be turned into memory by reload if necessary. */
1.1 root 2067: if (!cse_not_expected)
2068: return immed_real_const (exp);
2069: case COMPLEX_CST:
2070: case STRING_CST:
1.1.1.8 root 2071: if (! TREE_CST_RTL (exp))
2072: output_constant_def (exp);
2073:
2074: /* TREE_CST_RTL probably contains a constant address.
2075: On RISC machines where a constant address isn't valid,
2076: make some insns to get that address into a register. */
2077: if (GET_CODE (TREE_CST_RTL (exp)) == MEM
2078: && modifier != EXPAND_CONST_ADDRESS
2079: && !memory_address_p (mode, XEXP (TREE_CST_RTL (exp), 0)))
2080: return change_address (TREE_CST_RTL (exp), VOIDmode,
2081: copy_rtx (XEXP (TREE_CST_RTL (exp), 0)));
1.1 root 2082: return TREE_CST_RTL (exp);
2083:
2084: case SAVE_EXPR:
2085: if (SAVE_EXPR_RTL (exp) == 0)
2086: {
1.1.1.5 root 2087: rtx reg = gen_reg_rtx (mode);
2088: SAVE_EXPR_RTL (exp) = reg;
2089: store_expr (TREE_OPERAND (exp, 0), reg, 0);
2090: if (!optimize)
2091: save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, reg,
2092: save_expr_regs);
1.1 root 2093: }
1.1.1.2 root 2094: /* Don't let the same rtl node appear in two places. */
1.1 root 2095: return SAVE_EXPR_RTL (exp);
2096:
1.1.1.2 root 2097: case RTL_EXPR:
1.1.1.10 root 2098: if (RTL_EXPR_SEQUENCE (exp) == const0_rtx)
2099: abort ();
2100: emit_insns (RTL_EXPR_SEQUENCE (exp));
2101: RTL_EXPR_SEQUENCE (exp) = const0_rtx;
1.1.1.2 root 2102: return RTL_EXPR_RTL (exp);
2103:
2104: case CONSTRUCTOR:
2105: /* All elts simple constants => refer to a constant in memory. */
2106: if (TREE_STATIC (exp))
2107: /* For aggregate types with non-BLKmode modes,
2108: this should ideally construct a CONST_INT. */
2109: return output_constant_def (exp);
2110:
2111: if (ignore)
2112: {
2113: tree elt;
2114: for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
2115: expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
2116: return const0_rtx;
2117: }
2118: else
2119: {
2120: if (target == 0)
2121: target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
2122: get_structure_value_addr (expr_size (exp)));
2123: store_expr (exp, target, 0);
2124: return target;
2125: }
2126:
1.1 root 2127: case INDIRECT_REF:
2128: {
2129: tree exp1 = TREE_OPERAND (exp, 0);
2130: tree exp2;
2131:
2132: /* A SAVE_EXPR as the address in an INDIRECT_EXPR is generated
2133: for *PTR += ANYTHING where PTR is put inside the SAVE_EXPR.
2134: This code has the same general effect as simply doing
2135: expand_expr on the save expr, except that the expression PTR
2136: is computed for use as a memory address. This means different
2137: code, suitable for indexing, may be generated. */
2138: if (TREE_CODE (exp1) == SAVE_EXPR
2139: && SAVE_EXPR_RTL (exp1) == 0
2140: && TREE_CODE (exp2 = TREE_OPERAND (exp1, 0)) != ERROR_MARK
2141: && TYPE_MODE (TREE_TYPE (exp1)) == Pmode
2142: && TYPE_MODE (TREE_TYPE (exp2)) == Pmode)
2143: {
1.1.1.2 root 2144: temp = expand_expr (TREE_OPERAND (exp1, 0), 0, VOIDmode, EXPAND_SUM);
1.1 root 2145: op0 = memory_address (mode, temp);
2146: op0 = copy_all_regs (op0);
2147: SAVE_EXPR_RTL (exp1) = op0;
2148: }
2149: else
2150: {
1.1.1.2 root 2151: op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, EXPAND_SUM);
1.1 root 2152: op0 = memory_address (mode, op0);
2153: }
2154: }
2155: temp = gen_rtx (MEM, mode, op0);
1.1.1.2 root 2156: /* If address was computed by addition,
2157: mark this as an element of an aggregate. */
2158: if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
2159: || (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR
2160: && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == PLUS_EXPR))
1.1.1.10 root 2161: MEM_IN_STRUCT_P (temp) = 1;
2162: MEM_VOLATILE_P (temp) = TREE_THIS_VOLATILE (exp);
2163: RTX_UNCHANGING_P (temp) = TREE_READONLY (exp);
1.1.1.2 root 2164: return temp;
2165:
2166: case ARRAY_REF:
2167: if (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST
2168: || TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST)
2169: {
2170: /* Nonconstant array index or nonconstant element size.
2171: Generate the tree for *(&array+index) and expand that,
2172: except do it in a language-independent way
2173: and don't complain about non-lvalue arrays.
2174: `mark_addressable' should already have been called
2175: for any array for which this case will be reached. */
2176:
2177: tree array_adr = build (ADDR_EXPR, TYPE_POINTER_TO (type),
2178: TREE_OPERAND (exp, 0));
2179: tree index = TREE_OPERAND (exp, 1);
2180: tree elt;
2181:
2182: /* Convert the integer argument to a type the same size as a pointer
2183: so the multiply won't overflow spuriously. */
2184: if (TYPE_PRECISION (TREE_TYPE (index)) != POINTER_SIZE)
2185: index = convert (type_for_size (POINTER_SIZE, 0), index);
2186:
2187: /* The array address isn't volatile even if the array is. */
2188: TREE_VOLATILE (array_adr) = 0;
2189:
2190: elt = build (INDIRECT_REF, type,
2191: fold (build (PLUS_EXPR, TYPE_POINTER_TO (type),
2192: array_adr,
2193: fold (build (MULT_EXPR,
2194: TYPE_POINTER_TO (type),
2195: index, size_in_bytes (type))))));
2196:
2197: return expand_expr (elt, target, tmode, modifier);
2198: }
2199: /* Treat array-ref with constant index as a component-ref. */
1.1 root 2200:
2201: case COMPONENT_REF:
2202: {
1.1.1.2 root 2203: register enum machine_mode mode1;
1.1 root 2204: int volstruct = 0;
2205: tree dbg1 = TREE_OPERAND (exp, 0); /* For debugging */
1.1.1.2 root 2206: int bitsize;
2207: tree tem = exp;
2208: int bitpos = 0;
2209: int unsignedp;
1.1 root 2210:
1.1.1.2 root 2211: if (TREE_CODE (exp) == COMPONENT_REF)
1.1 root 2212: {
2213: tree field = TREE_OPERAND (exp, 1);
1.1.1.2 root 2214: bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) * DECL_SIZE_UNIT (field);
2215: mode1 = DECL_MODE (TREE_OPERAND (exp, 1));
2216: unsignedp = TREE_UNSIGNED (field);
1.1 root 2217: }
1.1.1.2 root 2218: else
1.1 root 2219: {
1.1.1.2 root 2220: mode1 = TYPE_MODE (TREE_TYPE (exp));
2221: bitsize = GET_MODE_BITSIZE (mode1);
2222: unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1.1 root 2223: }
2224:
1.1.1.2 root 2225: /* Compute cumulative bit-offset for nested component-refs
2226: and array-refs, and find the ultimate containing object. */
2227:
2228: while (1)
1.1 root 2229: {
1.1.1.2 root 2230: if (TREE_CODE (tem) == COMPONENT_REF)
2231: {
2232: bitpos += DECL_OFFSET (TREE_OPERAND (tem, 1));
2233: if (TREE_THIS_VOLATILE (tem))
2234: volstruct = 1;
2235: }
2236: else if (TREE_CODE (tem) == ARRAY_REF
2237: && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
2238: && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) == INTEGER_CST)
2239: {
2240: bitpos += (TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))
2241: * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)))
2242: * TYPE_SIZE_UNIT (TREE_TYPE (tem)));
2243: }
2244: else
2245: break;
2246: tem = TREE_OPERAND (tem, 0);
1.1 root 2247: }
2248:
1.1.1.2 root 2249: op0 = expand_expr (tem, 0, VOIDmode,
2250: (modifier == EXPAND_CONST_ADDRESS
2251: ? modifier : EXPAND_NORMAL));
1.1 root 2252:
1.1.1.2 root 2253: if (mode1 == BImode || GET_CODE (op0) == REG
2254: || GET_CODE (op0) == SUBREG)
2255: {
2256: return extract_bit_field (op0, bitsize, bitpos, unsignedp,
2257: target, mode, tmode);
2258: }
2259: /* Get a reference to just this component. */
2260: if (modifier == EXPAND_CONST_ADDRESS)
2261: op0 = gen_rtx (MEM, mode1, plus_constant (XEXP (op0, 0),
2262: (bitpos / BITS_PER_UNIT)));
2263: else
2264: op0 = change_address (op0, mode1,
2265: plus_constant (XEXP (op0, 0),
2266: (bitpos / BITS_PER_UNIT)));
1.1.1.10 root 2267: MEM_IN_STRUCT_P (op0) = 1;
2268: MEM_VOLATILE_P (op0) = volstruct;
1.1.1.2 root 2269: /* If OP0 is in the shared structure-value stack slot,
2270: and it is not BLKmode, copy it into a register.
2271: The shared slot may be clobbered at any time by another call.
2272: BLKmode is safe because our caller will either copy the value away
2273: or take another component and come back here. */
2274: if (mode != BLKmode
2275: && TREE_CODE (TREE_OPERAND (exp, 0)) == CALL_EXPR
2276: && TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == BLKmode)
2277: op0 = copy_to_reg (op0);
2278: if (mode == mode1 || mode1 == BLKmode || mode1 == tmode)
2279: return op0;
2280: if (target == 0)
2281: target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
2282: convert_move (target, op0, unsignedp);
2283: return target;
1.1 root 2284: }
2285:
2286: /* Intended for a reference to a buffer of a file-object in Pascal.
2287: But it's not certain that a special tree code will really be
2288: necessary for these. INDIRECT_REF might work for them. */
2289: case BUFFER_REF:
2290: abort ();
2291:
2292: case CALL_EXPR:
1.1.1.2 root 2293: /* Check for a built-in function. */
2294: if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
2295: && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == FUNCTION_DECL
1.1.1.5 root 2296: && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
2297: != NOT_BUILT_IN))
1.1.1.2 root 2298: return expand_builtin (exp, target, subtarget, tmode);
1.1 root 2299: /* If this call was expanded already by preexpand_calls,
2300: just return the result we got. */
2301: if (CALL_EXPR_RTL (exp) != 0)
2302: return CALL_EXPR_RTL (exp);
1.1.1.2 root 2303: return expand_call (exp, target, ignore);
1.1 root 2304:
2305: case NOP_EXPR:
2306: case CONVERT_EXPR:
1.1.1.7 root 2307: case REFERENCE_EXPR:
1.1.1.2 root 2308: if (TREE_CODE (type) == VOID_TYPE || ignore)
1.1 root 2309: {
1.1.1.2 root 2310: expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
1.1 root 2311: return const0_rtx;
2312: }
2313: if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
1.1.1.2 root 2314: return expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, modifier);
1.1 root 2315: op0 = expand_expr (TREE_OPERAND (exp, 0), 0, mode, 0);
1.1.1.2 root 2316: if (GET_MODE (op0) == mode || GET_MODE (op0) == VOIDmode)
1.1 root 2317: return op0;
1.1.1.2 root 2318: if (flag_force_mem && GET_CODE (op0) == MEM)
2319: op0 = copy_to_reg (op0);
1.1 root 2320: if (target == 0)
2321: target = gen_reg_rtx (mode);
1.1.1.2 root 2322: convert_move (target, op0, TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
1.1 root 2323: return target;
2324:
2325: case PLUS_EXPR:
2326: preexpand_calls (exp);
1.1.1.2 root 2327: if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
2328: && modifier == EXPAND_SUM)
1.1 root 2329: {
1.1.1.2 root 2330: op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode, EXPAND_SUM);
1.1 root 2331: op1 = plus_constant (op1, TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)));
1.1.1.2 root 2332: return op1;
1.1 root 2333: }
2334: negate_1 = 1;
2335: plus_minus:
1.1.1.2 root 2336: if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
2337: && modifier == EXPAND_SUM)
1.1 root 2338: {
1.1.1.2 root 2339: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
1.1 root 2340: op0 = plus_constant (op0,
2341: negate_1 * TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)));
1.1.1.2 root 2342: return op0;
1.1 root 2343: }
2344: this_optab = add_optab;
1.1.1.2 root 2345: if (modifier != EXPAND_SUM) goto binop;
1.1 root 2346: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
1.1.1.2 root 2347: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
2348: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, EXPAND_SUM);
1.1 root 2349: /* Put a sum last, to simplify what follows. */
2350: #ifdef OLD_INDEXING
2351: if (GET_CODE (op1) == MULT)
2352: {
2353: temp = op0;
2354: op0 = op1;
2355: op1 = temp;
2356: }
2357: #endif
2358: #ifndef OLD_INDEXING
2359: /* Make sure any term that's a sum with a constant comes last. */
2360: if (GET_CODE (op0) == PLUS
1.1.1.2 root 2361: && CONSTANT_P (XEXP (op0, 1)))
1.1 root 2362: {
2363: temp = op0;
2364: op0 = op1;
2365: op1 = temp;
2366: }
2367: /* If adding to a sum including a constant,
2368: associate it to put the constant outside. */
2369: if (GET_CODE (op1) == PLUS
1.1.1.2 root 2370: && CONSTANT_P (XEXP (op1, 1)))
1.1 root 2371: {
2372: op0 = gen_rtx (PLUS, mode, XEXP (op1, 0), op0);
2373: if (GET_CODE (XEXP (op1, 1)) == CONST_INT)
2374: return plus_constant (op0, INTVAL (XEXP (op1, 1)));
2375: else
2376: return gen_rtx (PLUS, mode, op0, XEXP (op1, 1));
2377: }
2378: #endif
2379: return gen_rtx (PLUS, mode, op0, op1);
2380:
2381: case MINUS_EXPR:
2382: preexpand_calls (exp);
2383: if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
2384: {
1.1.1.10 root 2385: int negated;
1.1.1.2 root 2386: if (modifier == EXPAND_SUM)
2387: {
2388: negate_1 = -1;
2389: goto plus_minus;
2390: }
2391: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
2392: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
1.1.1.10 root 2393: negated = - TREE_INT_CST_LOW (TREE_OPERAND (exp, 1));
2394: if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_INT)
2395: negated &= (1 << GET_MODE_BITSIZE (mode)) - 1;
2396: op1 = gen_rtx (CONST_INT, VOIDmode, negated);
1.1.1.2 root 2397: this_optab = add_optab;
2398: goto binop2;
1.1 root 2399: }
2400: this_optab = sub_optab;
2401: goto binop;
2402:
2403: case MULT_EXPR:
2404: preexpand_calls (exp);
2405: /* If first operand is constant, swap them.
2406: Thus the following special case checks need only
2407: check the second operand. */
2408: if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
2409: {
2410: register tree t1 = TREE_OPERAND (exp, 0);
2411: TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
2412: TREE_OPERAND (exp, 1) = t1;
2413: }
2414:
2415: /* Attempt to return something suitable for generating an
2416: indexed address, for machines that support that. */
2417:
1.1.1.2 root 2418: if (modifier == EXPAND_SUM
1.1.1.6 root 2419: && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
1.1 root 2420: {
1.1.1.2 root 2421: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
2422:
2423: /* Apply distributive law if OP0 is x+c. */
2424: if (GET_CODE (op0) == PLUS
2425: && GET_CODE (XEXP (op0, 1)) == CONST_INT)
2426: return gen_rtx (PLUS, mode,
2427: gen_rtx (MULT, mode, XEXP (op0, 0),
2428: gen_rtx (CONST_INT, VOIDmode,
2429: TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))),
2430: gen_rtx (CONST_INT, VOIDmode,
2431: (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))
2432: * INTVAL (XEXP (op0, 1)))));
2433:
1.1 root 2434: if (GET_CODE (op0) != REG)
1.1.1.2 root 2435: op0 = force_operand (op0, 0);
2436: if (GET_CODE (op0) != REG)
2437: op0 = copy_to_mode_reg (mode, op0);
2438:
1.1.1.6 root 2439: return gen_rtx (MULT, mode, op0,
1.1 root 2440: gen_rtx (CONST_INT, VOIDmode,
2441: TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))));
2442: }
2443: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
2444: /* Check for multiplying things that have been extended
2445: from a narrower type. If this machine supports multiplying
2446: in that narrower type with a result in the desired type,
2447: do it that way, and avoid the explicit type-conversion. */
2448: if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
2449: && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
2450: && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
2451: < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
2452: && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
2453: && int_fits_type_p (TREE_OPERAND (exp, 1),
1.1.1.2 root 2454: TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
2455: /* Don't use a widening multiply if a shift will do. */
2456: && exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0)
1.1 root 2457: ||
2458: (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
2459: && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
2460: ==
1.1.1.2 root 2461: TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
2462: /* If both operands are extended, they must either both
2463: be zero-extended or both be sign-extended. */
2464: && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
2465: ==
2466: TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
1.1 root 2467: {
2468: enum machine_mode innermode
2469: = TYPE_MODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)));
1.1.1.2 root 2470: this_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
1.1 root 2471: ? umul_widen_optab : smul_widen_optab);
2472: if ((int) innermode + 1 == (int) mode
1.1.1.2 root 2473: && this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1.1 root 2474: {
2475: op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
2476: 0, VOIDmode, 0);
2477: if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
2478: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
2479: else
2480: op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
2481: 0, VOIDmode, 0);
2482: goto binop2;
2483: }
2484: }
2485: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2486: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
1.1.1.2 root 2487: return expand_mult (mode, op0, op1, target, TREE_UNSIGNED (type));
1.1 root 2488:
2489: case TRUNC_DIV_EXPR:
2490: case FLOOR_DIV_EXPR:
2491: case CEIL_DIV_EXPR:
2492: case ROUND_DIV_EXPR:
2493: preexpand_calls (exp);
2494: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
1.1.1.2 root 2495: /* Possible optimization: compute the dividend with EXPAND_SUM
1.1 root 2496: then if the divisor is constant can optimize the case
2497: where some terms of the dividend have coeffs divisible by it. */
2498: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2499: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
2500: return expand_divmod (0, code, mode, op0, op1, target,
1.1.1.2 root 2501: TREE_UNSIGNED (type));
1.1 root 2502:
2503: case RDIV_EXPR:
2504: preexpand_calls (exp);
2505: this_optab = flodiv_optab;
2506: goto binop;
2507:
2508: case TRUNC_MOD_EXPR:
2509: case FLOOR_MOD_EXPR:
2510: case CEIL_MOD_EXPR:
2511: case ROUND_MOD_EXPR:
2512: preexpand_calls (exp);
2513: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
2514: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2515: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
2516: return expand_divmod (1, code, mode, op0, op1, target,
1.1.1.2 root 2517: TREE_UNSIGNED (type));
1.1 root 2518: #if 0
2519: #ifdef HAVE_divmoddisi4
2520: if (GET_MODE (op0) != DImode)
2521: {
2522: temp = gen_reg_rtx (DImode);
2523: convert_move (temp, op0, 0);
2524: op0 = temp;
2525: if (GET_MODE (op1) != SImode && GET_CODE (op1) != CONST_INT)
2526: {
2527: temp = gen_reg_rtx (SImode);
2528: convert_move (temp, op1, 0);
2529: op1 = temp;
2530: }
2531: temp = gen_reg_rtx (SImode);
2532: if (target == 0)
2533: target = gen_reg_rtx (SImode);
2534: emit_insn (gen_divmoddisi4 (temp, protect_from_queue (op0, 0),
2535: protect_from_queue (op1, 0),
2536: protect_from_queue (target, 1)));
2537: return target;
2538: }
2539: #endif
2540: #endif
2541:
2542: case FIX_ROUND_EXPR:
2543: case FIX_FLOOR_EXPR:
2544: case FIX_CEIL_EXPR:
2545: abort (); /* Not used for C. */
2546:
2547: case FIX_TRUNC_EXPR:
2548: op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
2549: if (target == 0)
2550: target = gen_reg_rtx (mode);
1.1.1.2 root 2551: {
2552: int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
2553: if (mode == HImode || mode == QImode)
2554: {
2555: register rtx temp = gen_reg_rtx (SImode);
1.1.1.6 root 2556: expand_fix (temp, op0, 0);
2557: convert_move (target, temp, 0);
1.1.1.2 root 2558: }
2559: else
2560: expand_fix (target, op0, unsignedp);
2561: }
1.1 root 2562: return target;
2563:
2564: case FLOAT_EXPR:
2565: op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
2566: if (target == 0)
2567: target = gen_reg_rtx (mode);
1.1.1.2 root 2568: {
2569: int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
2570: if (GET_MODE (op0) == HImode
2571: || GET_MODE (op0) == QImode)
2572: {
2573: register rtx temp = gen_reg_rtx (SImode);
2574: convert_move (temp, op0, unsignedp);
2575: expand_float (target, temp, 0);
2576: }
2577: else
2578: expand_float (target, op0, unsignedp);
2579: }
1.1 root 2580: return target;
2581:
2582: case NEGATE_EXPR:
2583: op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
2584: temp = expand_unop (mode, neg_optab, op0, target, 0);
2585: if (temp == 0)
2586: abort ();
2587: return temp;
2588:
2589: case ABS_EXPR:
2590: /* First try to do it with a special abs instruction.
2591: If that does not win, use conditional jump and negate. */
1.1.1.2 root 2592: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
1.1 root 2593: temp = expand_unop (mode, abs_optab, op0, target, 0);
2594: if (temp != 0)
2595: return temp;
2596: temp = gen_label_rtx ();
2597: if (target == 0 || GET_CODE (target) != REG)
1.1.1.2 root 2598: target = gen_reg_rtx (mode);
1.1 root 2599: emit_move_insn (target, op0);
1.1.1.2 root 2600: emit_cmp_insn (target,
2601: expand_expr (convert (TREE_TYPE (exp), integer_zero_node),
2602: 0, VOIDmode, 0),
2603: 0, 0);
1.1.1.6 root 2604: NO_DEFER_POP;
1.1 root 2605: emit_jump_insn (gen_bge (temp));
2606: op0 = expand_unop (mode, neg_optab, target, target, 0);
2607: if (op0 != target)
2608: emit_move_insn (target, op0);
2609: emit_label (temp);
1.1.1.6 root 2610: OK_DEFER_POP;
1.1 root 2611: return target;
2612:
2613: case MAX_EXPR:
2614: case MIN_EXPR:
1.1.1.8 root 2615: mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
1.1 root 2616: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
2617: if (target == 0 || GET_CODE (target) != REG || target == op1)
1.1.1.2 root 2618: target = gen_reg_rtx (mode);
1.1 root 2619: op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
2620: if (target != op0)
2621: emit_move_insn (target, op0);
2622: op0 = gen_label_rtx ();
2623: if (code == MAX_EXPR)
1.1.1.2 root 2624: temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
2625: ? compare1 (target, op1, GEU, LEU, 1, mode)
2626: : compare1 (target, op1, GE, LE, 0, mode));
2627: else
2628: temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
2629: ? compare1 (target, op1, LEU, GEU, 1, mode)
2630: : compare1 (target, op1, LE, GE, 0, mode));
2631: if (temp == const0_rtx)
2632: emit_move_insn (target, op1);
2633: else if (temp != const1_rtx)
2634: {
2635: emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
2636: gen_rtx (IF_THEN_ELSE, VOIDmode,
2637: temp,
2638: gen_rtx (LABEL_REF, VOIDmode, op0),
2639: pc_rtx)));
2640: emit_move_insn (target, op1);
2641: }
2642: emit_label (op0);
1.1 root 2643: return target;
2644:
2645: /* ??? Can optimize when the operand of this is a bitwise operation,
2646: by using a different bitwise operation. */
2647: case BIT_NOT_EXPR:
2648: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2649: temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
2650: if (temp == 0)
2651: abort ();
2652: return temp;
2653:
1.1.1.2 root 2654: case FFS_EXPR:
2655: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2656: temp = expand_unop (mode, ffs_optab, op0, target, 1);
2657: if (temp == 0)
2658: abort ();
2659: return temp;
2660:
1.1 root 2661: /* ??? Can optimize bitwise operations with one arg constant.
2662: Pastel optimizes (a bitwise1 n) bitwise2 (a bitwise3 b)
2663: and (a bitwise1 b) bitwise2 b (etc)
2664: but that is probably not worth while. */
2665:
1.1.1.2 root 2666: /* BIT_AND_EXPR is for bitwise anding.
1.1 root 2667: TRUTH_AND_EXPR is for anding two boolean values
2668: when we want in all cases to compute both of them.
2669: In general it is fastest to do TRUTH_AND_EXPR by
2670: computing both operands as actual zero-or-1 values
2671: and then bitwise anding. In cases where there cannot
2672: be any side effects, better code would be made by
2673: treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR;
2674: but the question is how to recognize those cases. */
2675:
2676: case TRUTH_AND_EXPR:
2677: case BIT_AND_EXPR:
2678: preexpand_calls (exp);
2679: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
2680: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2681: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
2682: return expand_bit_and (mode, op0, op1, target);
2683:
2684: /* See comment above about TRUTH_AND_EXPR; it applies here too. */
2685: case TRUTH_OR_EXPR:
2686: case BIT_IOR_EXPR:
2687: preexpand_calls (exp);
2688: this_optab = ior_optab;
2689: goto binop;
2690:
2691: case BIT_XOR_EXPR:
2692: preexpand_calls (exp);
2693: this_optab = xor_optab;
2694: goto binop;
2695:
2696: case LSHIFT_EXPR:
2697: case RSHIFT_EXPR:
2698: case LROTATE_EXPR:
2699: case RROTATE_EXPR:
2700: preexpand_calls (exp);
2701: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
2702: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2703: return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
1.1.1.2 root 2704: TREE_UNSIGNED (type));
1.1 root 2705:
2706: /* ??? cv's were used to effect here to combine additive constants
2707: and to determine the answer when only additive constants differ.
2708: Also, the addition of one can be handled by changing the condition. */
2709: case LT_EXPR:
2710: case LE_EXPR:
2711: case GT_EXPR:
2712: case GE_EXPR:
2713: case EQ_EXPR:
2714: case NE_EXPR:
2715: preexpand_calls (exp);
1.1.1.2 root 2716: temp = do_store_flag (exp, target, mode);
1.1 root 2717: if (temp != 0)
2718: return temp;
1.1.1.2 root 2719: /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
2720: if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
2721: && subtarget
2722: && (GET_MODE (subtarget)
2723: == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
1.1 root 2724: {
2725: temp = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
2726: if (temp != subtarget)
2727: temp = copy_to_reg (temp);
2728: op1 = gen_label_rtx ();
1.1.1.2 root 2729: emit_cmp_insn (temp, const0_rtx, 0, TREE_UNSIGNED (type));
1.1 root 2730: emit_jump_insn (gen_beq (op1));
2731: emit_move_insn (temp, const1_rtx);
2732: emit_label (op1);
2733: return temp;
2734: }
2735: /* If no set-flag instruction, must generate a conditional
2736: store into a temporary variable. Drop through
2737: and handle this like && and ||. */
2738:
2739: case TRUTH_ANDIF_EXPR:
2740: case TRUTH_ORIF_EXPR:
2741: temp = gen_reg_rtx (mode);
2742: emit_clr_insn (temp);
2743: op1 = gen_label_rtx ();
2744: jumpifnot (exp, op1);
2745: emit_0_to_1_insn (temp);
2746: emit_label (op1);
2747: return temp;
2748:
2749: case TRUTH_NOT_EXPR:
2750: op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
2751: /* The parser is careful to generate TRUTH_NOT_EXPR
2752: only with operands that are always zero or one. */
2753: temp = expand_binop (mode, xor_optab, op0,
2754: gen_rtx (CONST_INT, mode, 1),
2755: target, 1, OPTAB_LIB_WIDEN);
2756: if (temp == 0)
2757: abort ();
2758: return temp;
2759:
2760: case COMPOUND_EXPR:
1.1.1.2 root 2761: expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
1.1 root 2762: emit_queue ();
2763: return expand_expr (TREE_OPERAND (exp, 1), target, VOIDmode, 0);
2764:
2765: case COND_EXPR:
2766: /* Note that COND_EXPRs whose type is a structure or union
2767: are required to be constructed to contain assignments of
2768: a temporary variable, so that we can evaluate them here
2769: for side effect only. If type is void, we must do likewise. */
2770: op0 = gen_label_rtx ();
2771: op1 = gen_label_rtx ();
2772:
1.1.1.2 root 2773: if (mode == VOIDmode || ignore)
1.1 root 2774: temp = 0;
2775: else if (target)
2776: temp = target;
1.1.1.2 root 2777: else if (mode == BLKmode)
2778: {
2779: if (TYPE_SIZE (type) == 0 || ! TREE_LITERAL (TYPE_SIZE (type)))
2780: abort ();
2781: temp = assign_stack_local (BLKmode,
2782: (TREE_INT_CST_LOW (TYPE_SIZE (type))
2783: * TYPE_SIZE_UNIT (type)
2784: + BITS_PER_UNIT - 1)
2785: / BITS_PER_UNIT);
2786: }
1.1 root 2787: else
2788: temp = gen_reg_rtx (mode);
2789:
2790: jumpifnot (TREE_OPERAND (exp, 0), op0);
1.1.1.6 root 2791: NO_DEFER_POP;
1.1 root 2792: if (temp != 0)
1.1.1.2 root 2793: store_expr (TREE_OPERAND (exp, 1), temp, 0);
1.1 root 2794: else
1.1.1.2 root 2795: expand_expr (TREE_OPERAND (exp, 1), ignore ? const0_rtx : 0,
2796: VOIDmode, 0);
1.1 root 2797: emit_queue ();
2798: emit_jump_insn (gen_jump (op1));
2799: emit_barrier ();
2800: emit_label (op0);
2801: if (temp != 0)
1.1.1.2 root 2802: store_expr (TREE_OPERAND (exp, 2), temp, 0);
1.1 root 2803: else
1.1.1.2 root 2804: expand_expr (TREE_OPERAND (exp, 2), ignore ? const0_rtx : 0,
2805: VOIDmode, 0);
1.1 root 2806: emit_queue ();
2807: emit_label (op1);
1.1.1.6 root 2808: OK_DEFER_POP;
1.1 root 2809: return temp;
2810:
1.1.1.7 root 2811: case INIT_EXPR:
2812: {
2813: tree lhs = TREE_OPERAND (exp, 0);
2814: tree rhs = TREE_OPERAND (exp, 1);
2815: tree type = TREE_TYPE (lhs);
2816:
2817: /* We are initializing via bitwise copy. After doing that,
2818: if we cannot be sure of the virtual function table pointer
2819: that is returned, store it by hand. */
2820:
2821: temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
2822: #if 0
2823: if (TREE_VIRTUAL (type)
2824: && (type != TYPE_MAIN_VARIANT (TREE_TYPE (rhs))
2825: || TREE_CODE (rhs) != PARM_DECL
2826: || TREE_CODE (rhs) != VAR_DECL
2827: || TREE_CODE (rhs) != CALL_EXPR))
2828: {
2829: extern tree build_component_ref ();
2830: expand_assignment (build_component_ref (lhs, get_vfield_name (type), 0),
2831: build_unary_op (ADDR_EXPR, lookup_name (get_vtable_name (type)), 0),
2832: 0, 0);
2833: }
2834: #endif
2835: return temp;
2836: }
2837:
1.1 root 2838: case MODIFY_EXPR:
1.1.1.7 root 2839: {
2840: /* If lhs is complex, expand calls in rhs before computing it.
2841: That's so we don't compute a pointer and save it over a call.
2842: If lhs is simple, compute it first so we can give it as a
2843: target if the rhs is just a call. This avoids an extra temp and copy
2844: and that prevents a partial-subsumption which makes bad code.
2845: Actually we could treat component_ref's of vars like vars. */
2846:
2847: tree lhs = TREE_OPERAND (exp, 0);
2848: tree rhs = TREE_OPERAND (exp, 1);
2849: tree type = TREE_TYPE (lhs);
2850: temp = 0;
2851:
2852: if (TREE_CODE (lhs) != VAR_DECL
2853: && TREE_CODE (lhs) != RESULT_DECL
2854: && TREE_CODE (lhs) != PARM_DECL)
2855: preexpand_calls (exp);
2856:
2857: #if 0
2858: if (TREE_VIRTUAL (type)
2859: && (TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (rhs))
2860: || (TREE_CODE (rhs) != VAR_DECL
2861: && TREE_CODE (rhs) != PARM_DECL
2862: && TREE_CODE (rhs) != RESULT_DECL)))
2863: {
2864: /* We are performing structure assignment. If the
2865: types of the structures are different, or if the
2866: RHS is not "pure" (i.e., a VAR_DECL, PARM_DECLs are
2867: too hard right now), then we must preserve the purity
2868: of the LHS, by queueing the assignment of
2869: it virtual function table pointer to itself. */
2870: extern tree build_component_ref ();
2871: tree vptr = build_component_ref (lhs, get_vfield_name (type), 0);
2872: enum machine_mode mode = TYPE_MODE (TREE_TYPE (vptr));
2873: int icode = (int) mov_optab->handlers[(int) mode].insn_code;
2874: rtx vptr_rtx = stabilize (expand_expr (vptr, 0, Pmode, 0));
2875: rtx vptr_tmp = copy_to_reg (vptr_rtx);
2876:
2877: if (icode == (int)CODE_FOR_nothing)
2878: abort ();
2879:
2880: temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
2881: enqueue_insn (temp, GEN_FCN (icode) (vptr_rtx, vptr_tmp));
2882: }
2883: else
2884: {
2885: #endif
2886: /* ??? Original code */
2887: temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
2888: }
1.1 root 2889: return temp;
2890:
2891: case PREINCREMENT_EXPR:
2892: case PREDECREMENT_EXPR:
1.1.1.2 root 2893: return expand_increment (exp, 0);
1.1 root 2894:
2895: case POSTINCREMENT_EXPR:
2896: case POSTDECREMENT_EXPR:
1.1.1.2 root 2897: return expand_increment (exp, 1);
1.1 root 2898:
2899: case ADDR_EXPR:
1.1.1.2 root 2900: op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode,
2901: EXPAND_CONST_ADDRESS);
1.1 root 2902: if (GET_CODE (op0) != MEM)
2903: abort ();
1.1.1.2 root 2904: if (modifier == EXPAND_SUM)
1.1 root 2905: return XEXP (op0, 0);
1.1.1.2 root 2906: op0 = force_operand (XEXP (op0, 0), target);
2907: if (flag_force_addr && GET_CODE (op0) != REG)
2908: return force_reg (Pmode, op0);
2909: return op0;
1.1 root 2910:
2911: case ENTRY_VALUE_EXPR:
2912: abort ();
2913:
2914: case ERROR_MARK:
1.1.1.2 root 2915: return const0_rtx;
1.1 root 2916:
2917: default:
2918: abort ();
2919: }
2920:
2921: /* Here to do an ordinary binary operator, generating an instruction
2922: from the optab already placed in `this_optab'. */
2923: binop:
2924: /* Detect things like x = y | (a == b)
2925: and do them as (x = y), (a == b ? x |= 1 : 0), x. */
2926: /* First, get the comparison or conditional into the second arg. */
2927: if (comparison_code[(int) TREE_CODE (TREE_OPERAND (exp, 0))]
2928: || (TREE_CODE (TREE_OPERAND (exp, 0)) == COND_EXPR
2929: && (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
2930: || integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 2)))))
2931: {
2932: if (this_optab == ior_optab || this_optab == add_optab
2933: || this_optab == xor_optab)
2934: {
2935: tree exch = TREE_OPERAND (exp, 1);
2936: TREE_OPERAND (exp, 1) = TREE_OPERAND (exp, 0);
2937: TREE_OPERAND (exp, 0) = exch;
2938: }
2939: }
1.1.1.3 root 2940: /* Optimize X + (Y ? Z : 0) by computing X and maybe adding Z. */
1.1 root 2941: if (comparison_code[(int) TREE_CODE (TREE_OPERAND (exp, 1))]
2942: || (TREE_CODE (TREE_OPERAND (exp, 1)) == COND_EXPR
2943: && (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 1))
2944: || integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 2)))))
2945: {
2946: if (this_optab == ior_optab || this_optab == add_optab
2947: || this_optab == xor_optab || this_optab == sub_optab
2948: || this_optab == lshl_optab || this_optab == ashl_optab
2949: || this_optab == lshr_optab || this_optab == ashr_optab
2950: || this_optab == rotl_optab || this_optab == rotr_optab)
2951: {
1.1.1.2 root 2952: tree thenexp;
1.1 root 2953: rtx thenv = 0;
2954:
1.1.1.8 root 2955: /* TARGET gets a reg in which we can perform the computation.
2956: Use the specified target if it's a pseudo reg and safe. */
2957: target = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
1.1 root 2958: if (target == 0) target = gen_reg_rtx (mode);
1.1.1.3 root 2959:
2960: /* Compute X into the target. */
1.1.1.2 root 2961: store_expr (TREE_OPERAND (exp, 0), target, 0);
1.1 root 2962: op0 = gen_label_rtx ();
2963:
1.1.1.3 root 2964: /* If other operand is a comparison COMP, treat it as COMP ? 1 : 0 */
1.1 root 2965: if (TREE_CODE (TREE_OPERAND (exp, 1)) != COND_EXPR)
2966: {
2967: do_jump (TREE_OPERAND (exp, 1), op0, 0);
2968: thenv = const1_rtx;
2969: }
2970: else if (integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 1), 2)))
2971: {
2972: do_jump (TREE_OPERAND (TREE_OPERAND (exp, 1), 0), op0, 0);
2973: thenexp = TREE_OPERAND (TREE_OPERAND (exp, 1), 1);
2974: }
2975: else
2976: {
2977: do_jump (TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0, op0);
2978: thenexp = TREE_OPERAND (TREE_OPERAND (exp, 1), 2);
2979: }
2980:
2981: if (thenv == 0)
2982: thenv = expand_expr (thenexp, 0, VOIDmode, 0);
2983:
1.1.1.3 root 2984: /* THENV is now Z, the value to operate on, as an rtx.
2985: We have already tested that Y isn't zero, so do the operation. */
2986:
1.1 root 2987: if (this_optab == rotl_optab || this_optab == rotr_optab)
2988: temp = expand_binop (mode, this_optab, target, thenv, target,
2989: -1, OPTAB_LIB);
2990: else if (this_optab == lshl_optab || this_optab == lshr_optab)
2991: temp = expand_binop (mode, this_optab, target, thenv, target,
2992: 1, OPTAB_LIB_WIDEN);
2993: else
2994: temp = expand_binop (mode, this_optab, target, thenv, target,
2995: 0, OPTAB_LIB_WIDEN);
2996: if (target != temp)
2997: emit_move_insn (target, temp);
2998:
1.1.1.6 root 2999: do_pending_stack_adjust ();
1.1 root 3000: emit_label (op0);
3001: return target;
3002: }
3003: }
3004: subtarget = validate_subtarget (subtarget, TREE_OPERAND (exp, 1));
3005: op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
3006: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
3007: binop2:
3008: temp = expand_binop (mode, this_optab, op0, op1, target,
1.1.1.2 root 3009: TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
1.1 root 3010: binop1:
3011: if (temp == 0)
3012: abort ();
3013: return temp;
3014: }
3015:
1.1.1.2 root 3016: /* Expand an expression EXP that calls a built-in function,
3017: with result going to TARGET if that's convenient
3018: (and in mode MODE if that's convenient).
3019: SUBTARGET may be used as the target for computing one of EXP's operands. */
3020:
3021: static rtx
3022: expand_builtin (exp, target, subtarget, mode)
3023: tree exp;
3024: rtx target;
3025: rtx subtarget;
3026: enum machine_mode mode;
3027: {
3028: tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
3029: tree arglist = TREE_OPERAND (exp, 1);
3030: rtx op0;
3031: rtx temp;
3032:
3033: switch (DECL_FUNCTION_CODE (fndecl))
3034: {
3035: case BUILT_IN_ABS:
3036: case BUILT_IN_LABS:
3037: case BUILT_IN_FABS:
3038: /* build_function_call changes these into ABS_EXPR. */
3039: abort ();
3040:
3041: case BUILT_IN_ALLOCA:
1.1.1.10 root 3042: if (arglist == 0
3043: /* Arg could be non-integer if user redeclared this fcn wrong. */
3044: || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
1.1.1.2 root 3045: return const0_rtx;
3046: frame_pointer_needed = 1;
3047: /* Compute the argument. */
3048: op0 = expand_expr (TREE_VALUE (arglist), 0, VOIDmode, 0);
3049: if (! CONSTANT_P (op0))
3050: {
3051: op0 = force_reg (GET_MODE (op0), op0);
3052: if (GET_MODE (op0) != Pmode)
3053: op0 = convert_to_mode (Pmode, op0);
3054: }
3055: /* Push that much space (rounding it up). */
1.1.1.3 root 3056: do_pending_stack_adjust ();
1.1.1.8 root 3057:
3058: #ifdef STACK_POINTER_OFFSET
1.1.1.9 root 3059: /* If we will have to round the result down (which is up
3060: if stack grows down), make sure we have extra space so the
3061: user still gets at least as much space as he asked for. */
1.1.1.8 root 3062: if ((STACK_POINTER_OFFSET + STACK_BYTES - 1) / STACK_BYTES
3063: != STACK_POINTER_OFFSET / STACK_BYTES)
3064: op0 = plus_constant (op0, STACK_BYTES);
3065: #endif
3066:
1.1.1.4 root 3067: #ifdef STACK_GROWS_DOWNWARD
1.1.1.2 root 3068: anti_adjust_stack (round_push (op0));
1.1.1.4 root 3069: #endif
1.1.1.2 root 3070: /* Return a copy of current stack ptr, in TARGET if possible. */
3071: if (target)
3072: emit_move_insn (target, stack_pointer_rtx);
3073: else
3074: target = copy_to_reg (stack_pointer_rtx);
1.1.1.4 root 3075: #ifdef STACK_POINTER_OFFSET
3076: /* If the contents of the stack pointer reg are offset from the
3077: actual top-of-stack address, add the offset here. */
1.1.1.6 root 3078: if (GET_CODE (target) == REG)
1.1.1.8 root 3079: emit_insn (gen_add2_insn (target,
3080: gen_rtx (CONST_INT, VOIDmode,
3081: (STACK_POINTER_OFFSET + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES)));
1.1.1.6 root 3082: else
3083: {
3084: rtx temp =
3085: expand_binop (GET_MODE (target), add_optab, target,
1.1.1.8 root 3086: gen_rtx (CONST_INT, VOIDmode,
3087: (STACK_POINTER_OFFSET + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES),
1.1.1.6 root 3088: target,
3089: 1, OPTAB_DIRECT);
3090: if (temp == 0) abort ();
3091: if (temp != target)
3092: emit_move_insn (target, temp);
3093: }
1.1.1.4 root 3094: #endif
3095: #ifndef STACK_GROWS_DOWNWARD
3096: anti_adjust_stack (round_push (op0));
3097: #endif
1.1.1.2 root 3098: return target;
3099:
3100: case BUILT_IN_FFS:
1.1.1.10 root 3101: if (arglist == 0
3102: /* Arg could be non-integer if user redeclared this fcn wrong. */
3103: || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
1.1.1.2 root 3104: return const0_rtx;
3105:
3106: /* Compute the argument. */
3107: op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
3108: /* Compute ffs, into TARGET if possible.
3109: Set TARGET to wherever the result comes back. */
3110: target = expand_unop (mode, ffs_optab, op0, target, 1);
3111: if (target == 0)
3112: abort ();
3113: return target;
3114:
3115: default:
3116: abort ();
3117: }
3118: }
3119:
3120: /* Expand code for a post- or pre- increment or decrement
3121: and return the RTX for the result.
3122: POST is 1 for postinc/decrements and 0 for preinc/decrements. */
3123:
3124: static rtx
3125: expand_increment (exp, post)
3126: register tree exp;
3127: int post;
3128: {
3129: register rtx op0, op1;
3130: register rtx temp;
3131: register tree incremented = TREE_OPERAND (exp, 0);
3132: optab this_optab = add_optab;
3133: int icode;
3134: enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
3135: int op0_is_copy = 0;
3136:
3137: /* Stabilize any component ref that might need to be
3138: evaluated more than once below. */
3139: if (TREE_CODE (incremented) == COMPONENT_REF
3140: && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
3141: || DECL_MODE (TREE_OPERAND (exp, 1)) == BImode))
3142: incremented = stabilize_reference (incremented);
3143:
3144: /* Compute the operands as RTX.
3145: Note whether OP0 is the actual lvalue or a copy of it:
3146: I believe it is a copy iff it is a register and insns were
3147: generated in computing it. */
3148: temp = get_last_insn ();
3149: op0 = expand_expr (incremented, 0, VOIDmode, 0);
3150: if (temp != get_last_insn ())
3151: op0_is_copy = (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG);
3152: op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
3153:
3154: /* Decide whether incrementing or decrementing. */
3155: if (TREE_CODE (exp) == POSTDECREMENT_EXPR
3156: || TREE_CODE (exp) == PREDECREMENT_EXPR)
3157: this_optab = sub_optab;
3158:
3159: /* If OP0 is not the actual lvalue, but rather a copy in a register,
3160: then we cannot just increment OP0. We must
3161: therefore contrive to increment the original value.
3162: Then we can return OP0 since it is a copy of the old value. */
3163: if (op0_is_copy)
3164: {
3165: /* This is the easiest way to increment the value wherever it is.
3166: Problems with multiple evaluation of INCREMENTED
3167: are prevented because either (1) it is a component_ref,
3168: in which case it was stabilized above, or (2) it is an array_ref
3169: with constant index in an array in a register, which is
3170: safe to reevaluate. */
3171: tree newexp = build ((this_optab == add_optab
3172: ? PLUS_EXPR : MINUS_EXPR),
3173: TREE_TYPE (exp),
3174: incremented,
3175: TREE_OPERAND (exp, 1));
3176: temp = expand_assignment (incremented, newexp, ! post, 0);
3177: return post ? op0 : temp;
3178: }
3179:
3180: /* Convert decrement by a constant into a negative increment. */
3181: if (this_optab == sub_optab
3182: && GET_CODE (op1) == CONST_INT)
3183: {
3184: op1 = gen_rtx (CONST_INT, VOIDmode, - INTVAL (op1));
3185: this_optab = add_optab;
3186: }
3187:
3188: if (post)
3189: {
3190: /* We have a true reference to the value in OP0.
3191: If there is an insn to add or subtract in this mode, queue it. */
3192:
3193: /* I'm not sure this is still necessary. */
3194: op0 = stabilize (op0);
3195:
3196: icode = (int) this_optab->handlers[(int) mode].insn_code;
3197: if (icode != (int) CODE_FOR_nothing
3198: /* Make sure that OP0 is valid for operands 0 and 1
3199: of the insn we want to queue. */
3200: && (*insn_operand_predicate[icode][0]) (op0, mode)
3201: && (*insn_operand_predicate[icode][1]) (op0, mode))
3202: {
3203: if (! (*insn_operand_predicate[icode][2]) (op1, mode))
3204: op1 = force_reg (mode, op1);
3205:
3206: return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
3207: }
3208: }
3209:
3210: /* Preincrement, or we can't increment with one simple insn. */
3211: if (post)
3212: /* Save a copy of the value before inc or dec, to return it later. */
3213: temp = copy_to_reg (op0);
3214: else
3215: /* Arrange to return the incremented value. */
3216: temp = op0;
3217:
3218: /* Increment however we can. */
3219: op1 = expand_binop (mode, this_optab, op0, op1, op0,
3220: 0, OPTAB_LIB_WIDEN);
3221: /* Make sure the value is stored into OP0. */
3222: if (op1 != op0)
3223: emit_move_insn (op0, op1);
3224:
3225: return temp;
3226: }
3227:
1.1 root 3228: /* Expand all function calls contained within EXP, innermost ones first.
3229: But don't look within expressions that have sequence points.
3230: For each CALL_EXPR, record the rtx for its value
1.1.1.2 root 3231: in the CALL_EXPR_RTL field.
3232:
3233: Calls that return large structures for which a structure return
3234: stack slot is needed are not preexpanded. Preexpanding them loses
3235: because if more than one were preexpanded they would try to use the
3236: same stack slot. */
1.1 root 3237:
3238: static void
3239: preexpand_calls (exp)
3240: tree exp;
3241: {
3242: register int nops, i;
3243:
3244: if (! do_preexpand_calls)
3245: return;
3246:
1.1.1.2 root 3247: /* Only expressions and references can contain calls. */
3248:
3249: if (tree_code_type[(int) TREE_CODE (exp)][0] != 'e'
3250: && tree_code_type[(int) TREE_CODE (exp)][0] != 'r')
3251: return;
3252:
1.1 root 3253: switch (TREE_CODE (exp))
3254: {
3255: case CALL_EXPR:
1.1.1.2 root 3256: /* Do nothing to built-in functions. */
3257: if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
3258: && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == FUNCTION_DECL
1.1.1.5 root 3259: && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
3260: != NOT_BUILT_IN))
1.1.1.2 root 3261: return;
3262: if (CALL_EXPR_RTL (exp) == 0
3263: && TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
3264: CALL_EXPR_RTL (exp) = expand_call (exp, 0, 0);
1.1 root 3265: return;
3266:
3267: case COMPOUND_EXPR:
3268: case COND_EXPR:
3269: case TRUTH_ANDIF_EXPR:
3270: case TRUTH_ORIF_EXPR:
3271: /* If we find one of these, then we can be sure
3272: the adjust will be done for it (since it makes jumps).
3273: Do it now, so that if this is inside an argument
3274: of a function, we don't get the stack adjustment
3275: after some other args have already been pushed. */
3276: do_pending_stack_adjust ();
3277: return;
3278:
1.1.1.2 root 3279: case RTL_EXPR:
3280: return;
3281:
1.1 root 3282: case SAVE_EXPR:
3283: if (SAVE_EXPR_RTL (exp) != 0)
3284: return;
3285: }
3286:
3287: nops = tree_code_length[(int) TREE_CODE (exp)];
3288: for (i = 0; i < nops; i++)
3289: if (TREE_OPERAND (exp, i) != 0)
3290: {
3291: register int type = *tree_code_type[(int) TREE_CODE (TREE_OPERAND (exp, i))];
3292: if (type == 'e' || type == 'r')
3293: preexpand_calls (TREE_OPERAND (exp, i));
3294: }
3295: }
3296:
1.1.1.2 root 3297: /* Force FUNEXP into a form suitable for the address of a CALL,
3298: and return that as an rtx. Also load the static chain register
3299: from either FUNEXP or CONTEXT. */
1.1 root 3300:
1.1.1.2 root 3301: static rtx
3302: prepare_call_address (funexp, context)
1.1 root 3303: rtx funexp;
3304: rtx context;
3305: {
3306: funexp = protect_from_queue (funexp, 0);
1.1.1.2 root 3307: if (context != 0)
1.1 root 3308: context = protect_from_queue (context, 0);
3309:
3310: /* Function variable in language with nested functions. */
3311: if (GET_MODE (funexp) == EPmode)
3312: {
1.1.1.2 root 3313: emit_move_insn (static_chain_rtx, gen_highpart (Pmode, funexp));
3314: funexp = memory_address (FUNCTION_MODE, gen_lowpart (Pmode, funexp));
3315: emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
1.1 root 3316: }
3317: else
3318: {
3319: if (context != 0)
1.1.1.2 root 3320: /* Unless function variable in C, or top level function constant */
3321: emit_move_insn (static_chain_rtx, lookup_static_chain (context));
3322:
3323: /* Make a valid memory address and copy constants thru pseudo-regs,
3324: but not for a constant address if -fno-function-cse. */
3325: if (GET_CODE (funexp) != SYMBOL_REF)
3326: funexp = memory_address (FUNCTION_MODE, funexp);
3327: else
1.1 root 3328: {
1.1.1.2 root 3329: #ifndef NO_FUNCTION_CSE
1.1.1.6 root 3330: if (optimize && ! flag_no_function_cse)
3331: funexp = force_reg (Pmode, funexp);
1.1.1.2 root 3332: #endif
3333: }
3334:
3335: if (context != 0)
3336: emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
1.1 root 3337: }
1.1.1.2 root 3338: return funexp;
3339: }
3340:
3341: /* Generate instructions to call function FUNEXP,
3342: and optionally pop the results.
3343: The CALL_INSN is the first insn generated.
3344:
3345: FUNTYPE is the data type of the function, or, for a library call,
3346: the identifier for the name of the call. This is given to the
3347: macro RETURN_POPS_ARGS to determine whether this function pops its own args.
3348:
1.1.1.6 root 3349: STACK_SIZE is the number of bytes of arguments on the stack,
1.1.1.2 root 3350: rounded up to STACK_BOUNDARY; zero if the size is variable.
3351: This is both to put into the call insn and
3352: to generate explicit popping code if necessary.
3353:
3354: NEXT_ARG_REG is the rtx that results from executing
3355: FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
3356: just after all the args have had their registers assigned.
3357: This could be whatever you like, but normally it is the first
3358: arg-register beyond those used for args in this call,
3359: or 0 if all the arg-registers are used in this call.
3360: It is passed on to `gen_call' so you can put this info in the call insn.
3361:
3362: VALREG is a hard register in which a value is returned,
3363: or 0 if the call does not return a value.
3364:
3365: OLD_ARGS_SIZE is the value that `current_args_size' had before
3366: the args to this call were processed.
3367: We restore `current_args_size' to that value. */
3368:
3369: static void
3370: emit_call_1 (funexp, funtype, stack_size, next_arg_reg, valreg, old_args_size)
3371: rtx funexp;
3372: tree funtype;
3373: int stack_size;
3374: rtx next_arg_reg;
3375: rtx valreg;
3376: int old_args_size;
3377: {
3378: rtx stack_size_rtx = gen_rtx (CONST_INT, VOIDmode, stack_size);
3379:
3380: if (valreg)
3381: emit_call_insn (gen_call_value (valreg,
3382: gen_rtx (MEM, FUNCTION_MODE, funexp),
3383: stack_size_rtx, next_arg_reg));
3384: else
3385: emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
3386: stack_size_rtx, next_arg_reg));
3387:
3388: current_args_size = old_args_size;
3389:
1.1 root 3390: /* If returning from the subroutine does not automatically pop the args,
3391: we need an instruction to pop them sooner or later.
3392: Perhaps do it now; perhaps just record how much space to pop later. */
1.1.1.2 root 3393:
3394: if (! RETURN_POPS_ARGS (TREE_TYPE (funtype))
3395: && stack_size != 0)
1.1 root 3396: {
1.1.1.2 root 3397: if (flag_defer_pop && current_args_size == 0)
3398: pending_stack_adjust += stack_size;
1.1 root 3399: else
1.1.1.3 root 3400: adjust_stack (stack_size_rtx);
1.1 root 3401: }
3402: }
3403:
3404: /* At the start of a function, record that we have no previously-pushed
3405: arguments waiting to be popped. */
3406:
1.1.1.2 root 3407: void
3408: init_pending_stack_adjust ()
1.1 root 3409: {
3410: pending_stack_adjust = 0;
3411: }
3412:
1.1.1.2 root 3413: /* When exiting from function, if safe, clear out any pending stack adjust
3414: so the adjustment won't get done. */
3415:
3416: void
3417: clear_pending_stack_adjust ()
3418: {
3419: #ifdef EXIT_IGNORE_STACK
1.1.1.4 root 3420: if (!flag_omit_frame_pointer && EXIT_IGNORE_STACK
1.1.1.10 root 3421: && ! TREE_INLINE (current_function_decl)
3422: && ! flag_inline_functions)
1.1.1.2 root 3423: pending_stack_adjust = 0;
3424: #endif
3425: }
3426:
1.1 root 3427: /* At start of function, initialize. */
1.1.1.2 root 3428: void
1.1 root 3429: clear_current_args_size ()
3430: {
3431: current_args_size = 0;
3432: }
3433:
3434: /* Pop any previously-pushed arguments that have not been popped yet. */
3435:
1.1.1.2 root 3436: void
1.1 root 3437: do_pending_stack_adjust ()
3438: {
3439: if (current_args_size == 0)
3440: {
3441: if (pending_stack_adjust != 0)
3442: adjust_stack (gen_rtx (CONST_INT, VOIDmode, pending_stack_adjust));
3443: pending_stack_adjust = 0;
3444: }
3445: }
3446:
3447: /* Generate all the code for a function call
3448: and return an rtx for its value.
3449: Store the value in TARGET (specified as an rtx) if convenient.
1.1.1.2 root 3450: If the value is stored in TARGET then TARGET is returned.
3451: If IGNORE is nonzero, then we ignore the value of the function call. */
1.1 root 3452:
1.1.1.9 root 3453: struct arg_data
3454: {
3455: /* Tree node for this argument. */
3456: tree tree_value;
3457: /* Precomputed RTL value, or 0 if it isn't precomputed. */
3458: rtx value;
3459: /* Register to pass this argument in, or 0 if passed on stack. */
3460: rtx reg;
3461: /* Number of registers to use. 0 means put the whole arg in registers.
3462: Also 0 if not passed in registers. */
3463: int partial;
3464: /* Offset of this argument from beginning of stack-args. */
3465: struct args_size offset;
3466: /* Size of this argument on the stack, rounded up for any padding it gets,
3467: parts of the argument passed in registers do not count.
3468: If the FIRST_PARM_CALLER_OFFSET is negative, then register parms
3469: are counted here as well. */
3470: struct args_size size;
3471: /* Nonzero if this arg has already been stored. */
3472: int stored;
3473: /* const0_rtx means should preallocate stack space for this arg.
3474: Other non0 value is the stack slot, preallocated.
3475: Used only for BLKmode. */
3476: rtx stack;
3477: };
3478:
1.1 root 3479: static rtx
1.1.1.2 root 3480: expand_call (exp, target, ignore)
1.1 root 3481: tree exp;
3482: rtx target;
1.1.1.2 root 3483: int ignore;
1.1 root 3484: {
1.1.1.8 root 3485: /* List of actual parameters. */
1.1 root 3486: tree actparms = TREE_OPERAND (exp, 1);
1.1.1.8 root 3487: /* RTX for the function to be called. */
1.1.1.2 root 3488: rtx funexp;
1.1.1.8 root 3489: /* Data type of the function. */
3490: tree funtype;
3491: /* Declaration of the function being called,
3492: or 0 if the function is computed (not known by name). */
3493: tree fndecl = 0;
3494:
3495: /* Register in which non-BLKmode value will be returned,
3496: or 0 if no value or if value is BLKmode. */
3497: rtx valreg;
3498: /* Address where we should return a BLKmode value;
3499: 0 if value not BLKmode. */
3500: rtx structure_value_addr = 0;
3501: /* Nonzero if that address is being passed by treating it as
3502: an extra, implicit first parameter. Otherwise,
3503: it is passed by being copied directly into struct_value_rtx. */
3504: int structure_value_addr_parm = 0;
3505:
3506: /* Number of actual parameters in this call, including struct value addr. */
3507: int num_actuals;
3508: /* Number of named args. Args after this are anonymous ones
3509: and they must all go on the stack. */
3510: int n_named_args;
3511:
1.1.1.9 root 3512: /* Vector of information about each argument.
3513: Arguments are numbered in the order they will be pushed,
1.1.1.8 root 3514: not the order they are written. */
1.1.1.9 root 3515: struct arg_data *args;
1.1.1.8 root 3516:
3517: /* Total size in bytes of all the stack-parms scanned so far. */
3518: struct args_size args_size;
1.1.1.9 root 3519: /* Remember initial value of args_size.constant. */
3520: int starting_args_size;
3521: /* Nonzero means count reg-parms' size in ARGS_SIZE. */
3522: int stack_count_regparms = 0;
1.1.1.8 root 3523: /* Data on reg parms scanned so far. */
3524: CUMULATIVE_ARGS args_so_far;
3525: /* Nonzero if a reg parm has been scanned. */
1.1.1.9 root 3526: int reg_parm_seen;
3527: /* Nonzero if we must avoid push-insns in the args for this call. */
3528: int must_preallocate;
1.1.1.8 root 3529: /* 1 if scanning parms front to back, -1 if scanning back to front. */
1.1.1.2 root 3530: int inc;
1.1.1.8 root 3531: /* Address of space preallocated for stack parms
3532: (on machines that lack push insns), or 0 if space not preallocated. */
3533: rtx argblock = 0;
3534:
3535: /* Nonzero if it is plausible that this is a call to alloca. */
3536: int may_be_alloca;
3537: /* Nonzero if this is a call to setjmp or a related function. */
1.1.1.2 root 3538: int is_setjmp;
1.1.1.8 root 3539: /* Nonzero if this is a call to an inline function. */
1.1.1.2 root 3540: int is_integrable = 0;
1.1.1.8 root 3541: /* Nonzero if this is a call to __builtin_new. */
3542: int is_builtin_new;
3543:
1.1.1.9 root 3544: /* Nonzero if there are BLKmode args whose data types require them
3545: to be passed in memory, not (even partially) in registers. */
3546: int BLKmode_parms_forced = 0;
3547: /* The offset of the first BLKmode parameter which
3548: *must* be passed in memory. */
3549: int BLKmode_parms_first_offset = 0;
3550: /* Total size of BLKmode parms which could usefully be preallocated. */
3551: int BLKmode_parms_sizes = 0;
3552:
3553: /* Amount stack was adjusted to protect BLKmode parameters
3554: which are below the nominal "stack address" value. */
3555: rtx protected_stack = 0;
3556:
3557: rtx old_stack_level = 0;
1.1.1.2 root 3558: int old_pending_adj;
3559: int old_current_args_size = current_args_size;
1.1.1.8 root 3560: tree old_cleanups = cleanups_of_this_call;
1.1.1.2 root 3561:
1.1.1.8 root 3562: register tree p;
3563: register int i;
1.1.1.2 root 3564:
3565: /* See if we can find a DECL-node for the actual function.
3566: As a result, decide whether this is a call to an integrable function. */
3567:
1.1.1.8 root 3568: p = TREE_OPERAND (exp, 0);
1.1.1.2 root 3569: if (TREE_CODE (p) == ADDR_EXPR)
3570: {
3571: fndecl = TREE_OPERAND (p, 0);
3572: if (TREE_CODE (fndecl) != FUNCTION_DECL)
3573: fndecl = 0;
3574: else
3575: {
3576: extern tree current_function_decl;
1.1 root 3577:
1.1.1.2 root 3578: if (fndecl != current_function_decl
3579: && DECL_SAVED_INSNS (fndecl))
3580: is_integrable = 1;
3581: else
1.1.1.4 root 3582: {
3583: /* In case this function later becomes inlineable,
3584: record that there was already a non-inline call to it. */
3585: TREE_ADDRESSABLE (fndecl) = 1;
3586: TREE_ADDRESSABLE (DECL_NAME (fndecl)) = 1;
3587: }
1.1.1.2 root 3588: }
3589: }
1.1 root 3590:
1.1.1.2 root 3591: /* Set up a place to return a structure. */
1.1 root 3592:
3593: if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
3594: {
3595: /* This call returns a big structure. */
3596: if (target)
1.1.1.9 root 3597: {
3598: structure_value_addr = XEXP (target, 0);
3599: if (reg_mentioned_p (stack_pointer_rtx, structure_value_addr))
3600: structure_value_addr = copy_to_reg (structure_value_addr);
3601: }
1.1 root 3602: else
3603: /* Make room on the stack to hold the value. */
3604: structure_value_addr = get_structure_value_addr (expr_size (exp));
3605: }
3606:
1.1.1.2 root 3607: if (is_integrable)
3608: {
3609: extern rtx expand_inline_function ();
3610: rtx temp;
3611:
3612: temp = expand_inline_function (fndecl, actparms, target,
3613: ignore, TREE_TYPE (exp),
3614: structure_value_addr);
3615:
1.1.1.8 root 3616: /* If inlining succeeded, return. */
3617: if ((int) temp != -1)
1.1.1.2 root 3618: return temp;
1.1.1.8 root 3619:
3620: /* If inlining failed, mark FNDECL as needing to be compiled
3621: separately after all. */
3622: TREE_ADDRESSABLE (fndecl) = 1;
3623: TREE_ADDRESSABLE (DECL_NAME (fndecl)) = 1;
1.1.1.2 root 3624: }
3625:
3626: #if 0
3627: /* Unless it's a call to a specific function that isn't alloca,
3628: if it has one argument, we must assume it might be alloca. */
3629:
3630: may_be_alloca =
3631: (!(fndecl != 0
3632: && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)),
3633: "alloca"))
3634: && actparms != 0
3635: && TREE_CHAIN (actparms) == 0);
3636: #else
3637: /* We assume that alloca will always be called by name. It
3638: makes no sense to pass it as a pointer-to-function to
3639: anything that does not understand its behavior. */
3640: may_be_alloca =
1.1.1.9 root 3641: (fndecl && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "alloca")
3642: || ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)),
3643: "__builtin_alloca")));
1.1.1.2 root 3644: #endif
3645:
3646: /* See if this is a call to a function that can return more than once. */
3647:
3648: is_setjmp
3649: = (fndecl != 0
3650: && (!strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "setjmp")
3651: || !strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "_setjmp")));
3652:
1.1.1.8 root 3653: is_builtin_new
3654: = (fndecl != 0
3655: && (!strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "__builtin_new")));
3656:
1.1.1.2 root 3657: if (may_be_alloca)
3658: {
3659: frame_pointer_needed = 1;
3660: may_call_alloca = 1;
3661: }
3662:
3663: /* Don't let pending stack adjusts add up to too much.
3664: Also, do all pending adjustments now
3665: if there is any chance this might be a call to alloca. */
3666:
3667: if (pending_stack_adjust >= 32
3668: || (pending_stack_adjust > 0 && may_be_alloca))
3669: do_pending_stack_adjust ();
3670:
3671: /* Operand 0 is a pointer-to-function; get the type of the function. */
3672: funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
3673: if (TREE_CODE (funtype) != POINTER_TYPE)
3674: abort ();
3675: funtype = TREE_TYPE (funtype);
3676:
1.1.1.7 root 3677: if (TREE_CODE (funtype) == METHOD_TYPE)
3678: funtype = TREE_TYPE (funtype);
3679:
1.1.1.8 root 3680: /* If the address for a structure value should be in memory,
3681: and it would go in memory if treated as an extra parameter,
3682: treat it that way. */
1.1.1.6 root 3683: if (structure_value_addr && GET_CODE (struct_value_rtx) == MEM)
1.1.1.8 root 3684: {
3685: rtx tem;
3686:
3687: INIT_CUMULATIVE_ARGS (args_so_far, funtype);
3688: tem = FUNCTION_ARG (args_so_far, Pmode,
3689: build_pointer_type (TREE_TYPE (funtype)), 1);
1.1.1.10 root 3690: if (tem != 0 && GET_CODE (tem) == MEM)
1.1.1.8 root 3691: {
3692: actparms = tree_cons (error_mark_node,
3693: build (SAVE_EXPR,
3694: type_for_size (GET_MODE_BITSIZE (Pmode), 0),
3695: 0,
3696: force_reg (Pmode, structure_value_addr)),
3697: actparms);
3698: structure_value_addr_parm = 1;
3699: }
3700: }
1.1.1.6 root 3701:
1.1.1.2 root 3702: /* Count the arguments and set NUM_ACTUALS. */
1.1 root 3703: for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
3704: num_actuals = i;
1.1.1.2 root 3705:
3706: /* Compute number of named args.
3707: This may actually be 1 too large, but that happens
3708: only in the case when all args are named, so no trouble results. */
3709: if (TYPE_ARG_TYPES (funtype) != 0)
3710: n_named_args = list_length (TYPE_ARG_TYPES (funtype));
3711: else
3712: /* If we know nothing, treat all args as named. */
3713: n_named_args = num_actuals;
3714:
1.1.1.9 root 3715: /* Make a vector to hold all the information about each arg. */
3716: args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
3717: bzero (args, num_actuals * sizeof (struct arg_data));
3718:
3719: args_size.constant = 0;
3720: args_size.var = 0;
3721: #ifdef FIRST_PARM_CALLER_OFFSET
3722: args_size.constant = FIRST_PARM_CALLER_OFFSET (fntype);
3723: stack_count_regparms = 1;
3724: #endif
3725: starting_args_size = args_size.constant;
1.1.1.2 root 3726:
3727: /* In this loop, we consider args in the order they are written.
1.1.1.9 root 3728: We fill up ARGS from the front of from the back if necessary
3729: so that in any case the first arg to be pushed ends up at the front. */
1.1 root 3730:
1.1.1.2 root 3731: #ifdef PUSH_ARGS_REVERSED
3732: i = num_actuals - 1, inc = -1;
1.1 root 3733: /* In this case, must reverse order of args
1.1.1.2 root 3734: so that we compute and push the last arg first. */
1.1 root 3735: #else
1.1.1.2 root 3736: i = 0, inc = 1;
3737: #endif
3738:
3739: INIT_CUMULATIVE_ARGS (args_so_far, funtype);
3740:
3741: for (p = actparms; p; p = TREE_CHAIN (p), i += inc)
3742: {
3743: tree type = TREE_TYPE (TREE_VALUE (p));
1.1.1.9 root 3744: args[i].tree_value = TREE_VALUE (p);
3745: args[i].offset = args_size;
1.1.1.2 root 3746:
3747: if (type == error_mark_node)
3748: continue;
3749:
3750: /* Decide where to pass this arg. */
1.1.1.9 root 3751: /* args[i].reg is nonzero if all or part is passed in registers.
3752: args[i].partial is nonzero if part but not all is passed in registers,
1.1.1.2 root 3753: and the exact value says how many words are passed in registers. */
3754:
3755: if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1.1.1.6 root 3756: && args_size.var == 0
3757: /* error_mark_node here is a flag for the fake argument
3758: for a structure value address. */
3759: && TREE_PURPOSE (p) != error_mark_node)
1.1.1.2 root 3760: {
1.1.1.9 root 3761: args[i].reg = FUNCTION_ARG (args_so_far, TYPE_MODE (type), type,
3762: i < n_named_args);
1.1.1.2 root 3763: #ifdef FUNCTION_ARG_PARTIAL_NREGS
1.1.1.9 root 3764: args[i].partial
3765: = FUNCTION_ARG_PARTIAL_NREGS (args_so_far,
3766: TYPE_MODE (type), type,
3767: i < n_named_args);
1.1.1.2 root 3768: #endif
3769: }
3770:
1.1.1.9 root 3771: /* Compute the stack-size of this argument. */
1.1.1.2 root 3772:
1.1.1.9 root 3773: if (args[i].reg != 0 && args[i].partial == 0
3774: && ! stack_count_regparms)
3775: /* On most machines, don't count stack space for a register arg. */
1.1.1.2 root 3776: ;
3777: else if (TYPE_MODE (type) != BLKmode)
3778: {
3779: register int size;
3780:
3781: size = GET_MODE_SIZE (TYPE_MODE (type));
3782: /* Compute how much space the push instruction will push.
3783: On many machines, pushing a byte will advance the stack
3784: pointer by a halfword. */
3785: #ifdef PUSH_ROUNDING
3786: size = PUSH_ROUNDING (size);
1.1 root 3787: #endif
1.1.1.2 root 3788: /* Compute how much space the argument should get:
1.1.1.6 root 3789: maybe pad to a multiple of the alignment for arguments. */
3790: if (none == FUNCTION_ARG_PADDING (TYPE_MODE (type), (rtx)0))
1.1.1.9 root 3791: args[i].size.constant = size;
1.1.1.6 root 3792: else
1.1.1.9 root 3793: args[i].size.constant
1.1.1.6 root 3794: = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3795: / (PARM_BOUNDARY / BITS_PER_UNIT))
3796: * (PARM_BOUNDARY / BITS_PER_UNIT));
1.1.1.2 root 3797: }
3798: else
3799: {
3800: register tree size = size_in_bytes (type);
3801:
3802: /* A nonscalar. Round its size up to a multiple
1.1.1.9 root 3803: of PARM_BOUNDARY bits, unless it is not supposed to be padded. */
1.1.1.6 root 3804: if (none
3805: != FUNCTION_ARG_PADDING (TYPE_MODE (type),
3806: expand_expr (size, 0, VOIDmode, 0)))
3807: size = convert_units (convert_units (size, BITS_PER_UNIT,
3808: PARM_BOUNDARY),
3809: PARM_BOUNDARY, BITS_PER_UNIT);
1.1.1.9 root 3810: ADD_PARM_SIZE (args[i].size, size);
3811:
3812: /* Certain data types may not be passed in registers
3813: (eg C++ classes with constructors).
3814: Also, BLKmode parameters initialized from CALL_EXPRs
3815: are treated specially, if it is a win to do so. */
3816: if (TREE_CODE (TREE_VALUE (p)) == CALL_EXPR
3817: || TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (p))))
3818: {
3819: if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (p))))
3820: BLKmode_parms_forced = 1;
3821: /* This is a marker for such a parameter. */
3822: args[i].stack = const0_rtx;
3823: BLKmode_parms_sizes += TREE_INT_CST_LOW (size);
3824:
3825: /* If this parm's location is "below" the nominal stack pointer,
3826: note to decrement the stack pointer while it is computed. */
3827: #ifdef FIRST_PARM_CALLER_OFFSET
3828: if (BLKmode_parms_first_offset == 0)
3829: BLKmode_parms_first_offset
3830: /* If parameter's offset is variable, assume the worst. */
3831: = (args[i].offset.var
3832: ? FIRST_PARM_CALLER_OFFSET (fntype)
3833: : args[i].offset.constant);
3834: #endif
3835: }
1.1.1.2 root 3836: }
1.1.1.9 root 3837:
1.1.1.2 root 3838: /* If a part of the arg was put into registers,
3839: don't include that part in the amount pushed. */
1.1.1.9 root 3840: if (! stack_count_regparms)
3841: args[i].size.constant
3842: -= ((args[i].partial * UNITS_PER_WORD)
3843: / (PARM_BOUNDARY / BITS_PER_UNIT)
3844: * (PARM_BOUNDARY / BITS_PER_UNIT));
1.1.1.2 root 3845:
1.1.1.9 root 3846: /* Update ARGS_SIZE, the total stack space for args so far. */
1.1.1.2 root 3847:
1.1.1.9 root 3848: args_size.constant += args[i].size.constant;
3849: if (args[i].size.var)
1.1.1.2 root 3850: {
1.1.1.9 root 3851: ADD_PARM_SIZE (args_size, args[i].size.var);
1.1.1.2 root 3852: }
1.1.1.9 root 3853:
3854: /* Increment ARGS_SO_FAR, which has info about which arg-registers
3855: have been used, etc. */
3856:
3857: FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
3858: i < n_named_args);
1.1.1.2 root 3859: }
3860:
1.1.1.9 root 3861: /* If we would have to push a partially-in-regs parm
3862: before other stack parms, preallocate stack space instead. */
3863: must_preallocate = 0;
3864: {
3865: int partial_seen = 0;
3866: for (i = 0; i < num_actuals; i++)
3867: {
3868: if (args[i].partial > 0)
3869: partial_seen = 1;
3870: else if (partial_seen && args[i].reg == 0)
3871: must_preallocate = 1;
3872: }
3873: }
3874:
3875: /* If we have no actual push instructions, or shouldn't use them,
3876: or we need a variable amount of space, make space for all args right now.
3877: Round the needed size up to multiple of STACK_BOUNDARY. */
1.1.1.2 root 3878:
3879: if (args_size.var != 0)
3880: {
3881: old_stack_level = copy_to_mode_reg (Pmode, stack_pointer_rtx);
3882: old_pending_adj = pending_stack_adjust;
3883: argblock = push_block (round_push (ARGS_SIZE_RTX (args_size)));
3884: }
1.1.1.9 root 3885: else if (args_size.constant > 0)
1.1.1.2 root 3886: {
3887: int needed = args_size.constant;
3888:
3889: #ifdef STACK_BOUNDARY
3890: needed = (needed + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES;
3891: args_size.constant = needed;
3892: #endif
3893:
1.1.1.9 root 3894: if (
1.1.1.2 root 3895: #ifndef PUSH_ROUNDING
1.1.1.9 root 3896: 1 /* Always preallocate if no push insns. */
3897: #else
3898: must_preallocate || BLKmode_parms_forced
3899: || BLKmode_parms_sizes > (args_size.constant >> 1)
3900: #endif
3901: )
1.1.1.2 root 3902: {
1.1.1.9 root 3903: /* Try to reuse some or all of the pending_stack_adjust
3904: to get this space. Maybe we can avoid any pushing. */
3905: if (needed > pending_stack_adjust)
3906: {
3907: needed -= pending_stack_adjust;
3908: pending_stack_adjust = 0;
3909: }
3910: else
3911: {
3912: pending_stack_adjust -= needed;
3913: needed = 0;
3914: }
3915: argblock = push_block (gen_rtx (CONST_INT, VOIDmode, needed));
1.1.1.2 root 3916: }
3917: }
3918:
1.1.1.9 root 3919: /* Don't try to defer pops if preallocating, not even from the first arg,
3920: since ARGBLOCK probably refers to the SP. */
3921: if (argblock)
3922: NO_DEFER_POP;
3923:
3924: #ifdef STACK_GROWS_DOWNWARD
3925: /* If any BLKmode parms need to be preallocated in space
3926: below the nominal stack-pointer address, we need to adjust the
3927: stack pointer so that this location is temporarily above it.
3928: This ensures that computation won't clobber that space. */
3929: if (BLKmode_parms_first_offset < 0 && argblock != 0)
3930: {
3931: int needed = -BLKmode_parms_first_offset;
3932: argblock = copy_to_reg (argblock);
3933:
3934: #ifdef STACK_BOUNDARY
3935: needed = (needed + STACK_BYTES - 1) / STACK_BYTES * STACK_BYTES;
3936: #endif
3937: protected_stack = gen_rtx (CONST_INT, VOIDmode, needed);
3938: anti_adjust_stack (protected_stack);
3939: }
3940: #endif /* STACK_GROWS_DOWNWARD */
3941:
3942: /* Precompute all register parameters. It isn't safe to compute anything
3943: once we have started filling any specific hard regs. */
3944:
3945: reg_parm_seen = 0;
3946: for (i = 0; i < num_actuals; i++)
3947: if (args[i].reg != 0)
3948: {
3949: reg_parm_seen = 1;
3950: args[i].value = expand_expr (args[i].tree_value, 0, VOIDmode, 0);
3951: if (GET_CODE (args[i].value) != MEM
3952: && ! CONSTANT_P (args[i].value)
3953: && GET_CODE (args[i].value) != CONST_DOUBLE)
3954: args[i].value
3955: = force_reg (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3956: args[i].value);
3957: /* ANSI doesn't require a sequence point here,
3958: but PCC has one, so this will avoid some problems. */
3959: emit_queue ();
3960: }
3961:
1.1.1.2 root 3962: /* Get the function to call, in the form of RTL. */
3963: if (fndecl)
3964: /* Get a SYMBOL_REF rtx for the function address. */
3965: funexp = XEXP (DECL_RTL (fndecl), 0);
3966: else
3967: /* Generate an rtx (probably a pseudo-register) for the address. */
1.1.1.4 root 3968: {
3969: funexp = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
3970: emit_queue ();
3971: }
1.1.1.2 root 3972:
1.1.1.9 root 3973: /* Now compute and store all non-register parms.
3974: These come before register parms, since they can require block-moves,
3975: which could clobber the registers used for register parms.
3976: Parms which have partial registers are not stored here,
3977: but we do preallocate space here if they want that. */
1.1.1.2 root 3978:
1.1 root 3979: for (i = 0; i < num_actuals; i++)
3980: {
1.1.1.9 root 3981: /* Preallocate the stack space for a parm if appropriate
3982: so it can be computed directly in the stack space. */
3983: if (args[i].stack != 0 && argblock != 0)
3984: args[i].stack = target_for_arg (TREE_TYPE (args[i].tree_value),
3985: ARGS_SIZE_RTX (args[i].size),
3986: argblock, args[i].offset);
1.1 root 3987: else
1.1.1.9 root 3988: args[i].stack = 0;
1.1 root 3989:
1.1.1.9 root 3990: if (args[i].reg == 0)
3991: store_one_arg (&args[i], argblock, may_be_alloca);
3992: }
1.1 root 3993:
1.1.1.9 root 3994: /* Now store any partially-in-registers parm.
3995: This is the last place a block-move can happen. */
3996: if (reg_parm_seen)
3997: for (i = 0; i < num_actuals; i++)
3998: if (args[i].partial != 0)
3999: store_one_arg (&args[i], argblock, may_be_alloca);
1.1 root 4000:
1.1.1.9 root 4001: if (protected_stack != 0)
4002: adjust_stack (protected_stack);
1.1 root 4003:
1.1.1.9 root 4004: /* Pass the function the address in which to return a structure value. */
4005: if (structure_value_addr && ! structure_value_addr_parm)
4006: emit_move_insn (struct_value_rtx, force_reg (Pmode, structure_value_addr));
1.1 root 4007:
1.1.1.9 root 4008: /* Now set up any wholly-register parms. They were computed already. */
4009: if (reg_parm_seen)
4010: for (i = 0; i < num_actuals; i++)
4011: if (args[i].reg != 0 && args[i].partial == 0)
4012: store_one_arg (&args[i], argblock, may_be_alloca);
1.1 root 4013:
4014: /* Perform postincrements before actually calling the function. */
4015: emit_queue ();
4016:
1.1.1.2 root 4017: /* All arguments and registers used for the call must be set up by now! */
1.1 root 4018:
1.1.1.2 root 4019: /* ??? Other languages need a nontrivial second argument (static chain). */
4020: funexp = prepare_call_address (funexp, 0);
4021:
4022: /* Mark all register-parms as living through the call.
4023: ??? This is not quite correct, since it doesn't indicate
4024: that they are in use immediately before the call insn.
4025: Currently that doesn't matter since explicitly-used regs
4026: won't be used for reloading. But if the reloader becomes smarter,
4027: this will have to change somehow. */
4028: for (i = 0; i < num_actuals; i++)
1.1.1.9 root 4029: if (args[i].reg != 0)
1.1.1.2 root 4030: {
1.1.1.9 root 4031: if (args[i].partial > 0)
4032: use_regs (REGNO (args[i].reg), args[i].partial);
4033: else if (GET_MODE (args[i].reg) == BLKmode)
4034: use_regs (REGNO (args[i].reg),
1.1.1.10 root 4035: (int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1.1.1.2 root 4036: / UNITS_PER_WORD));
4037: else
1.1.1.9 root 4038: emit_insn (gen_rtx (USE, VOIDmode, args[i].reg));
1.1.1.2 root 4039: }
4040:
1.1.1.9 root 4041: if (structure_value_addr && GET_CODE (struct_value_rtx) == REG)
1.1.1.2 root 4042: emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
4043:
4044: /* Figure out the register where the value, if any, will come back. */
4045: valreg = 0;
4046: if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
4047: && TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
4048: valreg = hard_function_value (TREE_TYPE (exp), fndecl);
4049:
4050: /* Generate the actual call instruction. */
1.1.1.9 root 4051: if (args_size.constant < 0)
4052: args_size.constant = 0;
1.1.1.2 root 4053: emit_call_1 (funexp, funtype, args_size.constant,
4054: FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
4055: valreg, old_current_args_size);
1.1 root 4056:
4057: /* ??? Nothing has been done here to record control flow
4058: when contained functions can do nonlocal gotos. */
4059:
1.1.1.2 root 4060: /* For calls to `setjmp', etc., inform flow.c it should complain
4061: if nonvolatile values are live. */
4062:
4063: if (is_setjmp)
1.1.1.11! root 4064: {
! 4065: emit_note (IDENTIFIER_POINTER (DECL_NAME (fndecl)), NOTE_INSN_SETJMP);
! 4066: current_function_calls_setjmp = 1;
! 4067: }
1.1.1.2 root 4068:
1.1.1.8 root 4069: /* For calls to __builtin_new, note that it can never return 0.
4070: This is because a new handler will be called, and 0 it not
4071: among the numbers it is supposed to return. */
4072: #if 0
4073: if (is_builtin_new)
4074: emit_note (IDENTIFIER_POINTER (DECL_NAME (fndecl)), NOTE_INSN_BUILTIN_NEW);
4075: #endif
1.1.1.2 root 4076:
1.1 root 4077: /* If value type not void, return an rtx for the value. */
4078:
1.1.1.2 root 4079: if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
4080: || ignore)
1.1 root 4081: {
1.1.1.8 root 4082: target = 0;
1.1 root 4083: }
1.1.1.8 root 4084: else if (structure_value_addr)
4085: {
4086: if (target == 0)
4087: target = gen_rtx (MEM, BLKmode,
4088: memory_address (BLKmode, structure_value_addr));
4089: }
4090: else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp)))
1.1 root 4091: {
1.1.1.2 root 4092: if (!rtx_equal_p (target, valreg))
4093: emit_move_insn (target, valreg);
4094: else
4095: /* This tells expand_inline_function to copy valreg to its target. */
4096: emit_insn (gen_rtx (USE, VOIDmode, valreg));
1.1 root 4097: }
1.1.1.8 root 4098: else
4099: target = copy_to_reg (valreg);
4100:
1.1.1.9 root 4101: /* Perform all cleanups needed for the arguments of this call
4102: (i.e. destructors in C++). */
4103: while (cleanups_of_this_call != old_cleanups)
4104: {
4105: expand_expr (TREE_VALUE (cleanups_of_this_call), 0, VOIDmode, 0);
4106: cleanups_of_this_call = TREE_CHAIN (cleanups_of_this_call);
4107: }
4108:
1.1.1.8 root 4109: /* If size of args is variable, restore saved stack-pointer value. */
4110:
1.1.1.9 root 4111: if (old_stack_level)
1.1.1.8 root 4112: {
4113: emit_move_insn (stack_pointer_rtx, old_stack_level);
4114: pending_stack_adjust = old_pending_adj;
4115: }
4116:
1.1.1.9 root 4117: return target;
4118: }
4119:
4120: /* Return an rtx which represents a suitable home on the stack
4121: given TYPE, the type of the argument looking for a home.
4122: This is called only for BLKmode arguments.
4123:
4124: SIZE is the size needed for this target.
4125: ARGS_ADDR is the address of the bottom of the argument block for this call.
4126: OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
4127: if this machine uses push insns. */
4128:
4129: static rtx
4130: target_for_arg (type, size, args_addr, offset)
4131: tree type;
4132: rtx size;
4133: rtx args_addr;
4134: struct args_size offset;
4135: {
4136: rtx target;
4137: rtx offset_rtx = ARGS_SIZE_RTX (offset);
4138:
4139: /* We do not call memory_address if possible,
4140: because we want to address as close to the stack
4141: as possible. For non-variable sized arguments,
4142: this will be stack-pointer relative addressing. */
4143: if (GET_CODE (offset_rtx) == CONST_INT)
4144: target = plus_constant (args_addr, INTVAL (offset_rtx));
4145: else
1.1.1.8 root 4146: {
1.1.1.9 root 4147: /* I have no idea how to guarantee that this
4148: will work in the presence of register parameters. */
4149: target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
4150: target = memory_address (QImode, target);
1.1.1.8 root 4151: }
1.1.1.9 root 4152:
4153: return gen_rtx (MEM, BLKmode, target);
4154: }
4155:
4156: /* Store a single argument for a function call
4157: into the register or memory area where it must be passed.
4158: *ARG describes the argument value and where to pass it.
4159: ARGBLOCK is the address of the stack-block for all the arguments,
4160: or 0 on a machine where arguemnts are pushed individually.
4161: MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4162: so must be careful about how the stack is used. */
4163:
4164: static void
4165: store_one_arg (arg, argblock, may_be_alloca)
4166: struct arg_data *arg;
4167: rtx argblock;
4168: int may_be_alloca;
4169: {
4170: register tree pval = arg->tree_value;
4171: int used = 0;
4172:
4173: if (TREE_CODE (pval) == ERROR_MARK)
4174: return;
4175:
4176: if (arg->reg != 0 && arg->partial == 0)
4177: {
4178: /* Being passed entirely in a register. */
4179: if (arg->value != 0)
4180: {
4181: if (GET_MODE (arg->value) == BLKmode)
4182: move_block_to_reg (REGNO (arg->reg), arg->value,
4183: (int_size_in_bytes (TREE_TYPE (pval))
4184: / UNITS_PER_WORD));
4185: else
4186: emit_move_insn (arg->reg, arg->value);
4187: }
4188: else
4189: store_expr (pval, arg->reg, 0);
4190:
4191: /* Don't allow anything left on stack from computation
4192: of argument to alloca. */
4193: if (may_be_alloca)
4194: do_pending_stack_adjust ();
4195: }
4196: else if (TYPE_MODE (TREE_TYPE (pval)) != BLKmode)
4197: {
4198: register int size;
4199: rtx tem;
4200:
4201: /* Argument is a scalar, not entirely passed in registers.
4202: (If part is passed in registers, arg->partial says how much
4203: and emit_push_insn will take care of putting it there.)
4204:
4205: Push it, and if its size is less than the
4206: amount of space allocated to it,
4207: also bump stack pointer by the additional space.
4208: Note that in C the default argument promotions
4209: will prevent such mismatches. */
4210:
4211: used = size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (pval)));
4212: /* Compute how much space the push instruction will push.
4213: On many machines, pushing a byte will advance the stack
4214: pointer by a halfword. */
4215: #ifdef PUSH_ROUNDING
4216: size = PUSH_ROUNDING (size);
4217: #endif
4218: /* Compute how much space the argument should get:
4219: round up to a multiple of the alignment for arguments. */
4220: if (none != FUNCTION_ARG_PADDING (TYPE_MODE (TREE_TYPE (pval)), (rtx)0))
4221: used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4222: / (PARM_BOUNDARY / BITS_PER_UNIT))
4223: * (PARM_BOUNDARY / BITS_PER_UNIT));
4224:
4225: tem = arg->value;
4226: if (tem == 0)
4227: {
4228: tem = expand_expr (pval, 0, VOIDmode, 0);
4229: /* ANSI doesn't require a sequence point here,
4230: but PCC has one, so this will avoid some problems. */
4231: emit_queue ();
4232: }
4233:
4234: /* Don't allow anything left on stack from computation
4235: of argument to alloca. */
4236: if (may_be_alloca)
4237: do_pending_stack_adjust ();
4238:
4239: emit_push_insn (tem, TYPE_MODE (TREE_TYPE (pval)), 0, 0,
4240: arg->partial, arg->reg, used - size,
4241: argblock, ARGS_SIZE_RTX (arg->offset));
4242: }
4243: else if (arg->stack != 0)
4244: {
4245: /* BLKmode argument that should go in a prespecified stack location. */
4246: if (arg->value == 0)
4247: /* Not yet computed => compute it there. */
4248: /* ??? This should be changed to tell expand_expr
4249: that it can store directly in the target. */
4250: arg->value = store_expr (arg->tree_value, arg->stack, 0);
4251: else if (arg->value != arg->stack)
4252: /* It was computed somewhere, but not where we wanted.
4253: For example, the value may have come from an official
4254: local variable or parameter. In that case, expand_expr
4255: does not fill our suggested target. */
4256: emit_block_move (arg->stack, arg->value, ARGS_SIZE_RTX (arg->size),
1.1.1.10 root 4257: TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT);
1.1.1.9 root 4258:
4259: /* Now, if this value wanted to be partly in registers,
4260: move the value from the stack to the registers
4261: that are supposed to hold the values. */
4262: if (arg->partial > 0)
4263: move_block_to_reg (REGNO (arg->reg), arg->stack, arg->partial);
4264: }
4265: else
4266: {
4267: /* No place on the stack waiting for it, so just push. */
4268: register rtx tem
4269: = arg->value ? arg->value : expand_expr (pval, 0, VOIDmode, 0);
4270: register int excess;
4271: rtx size_rtx;
4272:
4273: /* Pushing a nonscalar.
4274: If part is passed in registers, arg->partial says how much
4275: and emit_push_insn will take care of putting it there. */
4276:
4277: /* Round its size up to a multiple
4278: of the allocation unit for arguments. */
4279:
4280: if (arg->size.var != 0)
4281: {
4282: excess = 0;
4283: size_rtx = ARGS_SIZE_RTX (arg->size);
4284: }
4285: else
4286: {
4287: register tree size = size_in_bytes (TREE_TYPE (pval));
4288: /* PUSH_ROUNDING has no effect on us, because
4289: emit_push_insn for BLKmode is careful to avoid it. */
4290: excess = arg->size.constant - TREE_INT_CST_LOW (size);
4291: size_rtx = expand_expr (size, 0, VOIDmode, 0);
4292: }
4293:
4294: if (arg->stack)
4295: abort ();
4296:
4297: emit_push_insn (tem, TYPE_MODE (TREE_TYPE (pval)), size_rtx,
4298: TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT,
4299: arg->partial, arg->reg, excess, argblock,
4300: ARGS_SIZE_RTX (arg->offset));
4301: }
4302:
4303: /* Once we have pushed something, pops can't safely
4304: be deferred during the rest of the arguments. */
4305: NO_DEFER_POP;
1.1 root 4306: }
4307:
4308: /* Expand conditional expressions. */
4309:
4310: /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
4311: LABEL is an rtx of code CODE_LABEL, in this function and all the
4312: functions here. */
4313:
1.1.1.2 root 4314: void
1.1 root 4315: jumpifnot (exp, label)
4316: tree exp;
4317: rtx label;
4318: {
4319: do_jump (exp, label, 0);
4320: }
4321:
4322: /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
4323:
1.1.1.2 root 4324: void
1.1 root 4325: jumpif (exp, label)
4326: tree exp;
4327: rtx label;
4328: {
4329: do_jump (exp, 0, label);
4330: }
4331:
4332: /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
4333: the result is zero, or IF_TRUE_LABEL if the result is one.
4334: Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
4335: meaning fall through in that case.
4336:
4337: This function is responsible for optimizing cases such as
4338: &&, || and comparison operators in EXP. */
4339:
1.1.1.2 root 4340: void
1.1 root 4341: do_jump (exp, if_false_label, if_true_label)
4342: tree exp;
4343: rtx if_false_label, if_true_label;
4344: {
4345: register enum tree_code code = TREE_CODE (exp);
4346: /* Some cases need to create a label to jump to
4347: in order to properly fall through.
4348: These cases set DROP_THROUGH_LABEL nonzero. */
4349: rtx drop_through_label = 0;
4350: rtx temp;
4351: rtx comparison = 0;
4352:
4353: emit_queue ();
4354:
4355: switch (code)
4356: {
4357: case ERROR_MARK:
4358: break;
4359:
4360: case INTEGER_CST:
4361: temp = integer_zerop (exp) ? if_false_label : if_true_label;
4362: if (temp)
4363: emit_jump (temp);
4364: break;
4365:
4366: case ADDR_EXPR:
4367: /* The address of something can never be zero. */
4368: if (if_true_label)
4369: emit_jump (if_true_label);
4370: break;
1.1.1.6 root 4371:
1.1 root 4372: case NOP_EXPR:
4373: do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
4374: break;
4375:
4376: case TRUTH_NOT_EXPR:
4377: do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
4378: break;
4379:
4380: case TRUTH_ANDIF_EXPR:
4381: if (if_false_label == 0)
4382: if_false_label = drop_through_label = gen_label_rtx ();
4383: do_jump (TREE_OPERAND (exp, 0), if_false_label, 0);
4384: do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
4385: break;
4386:
4387: case TRUTH_ORIF_EXPR:
4388: if (if_true_label == 0)
4389: if_true_label = drop_through_label = gen_label_rtx ();
4390: do_jump (TREE_OPERAND (exp, 0), 0, if_true_label);
4391: do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
4392: break;
4393:
4394: case COMPOUND_EXPR:
1.1.1.2 root 4395: expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
1.1 root 4396: emit_queue ();
4397: do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
4398: break;
4399:
4400: case COND_EXPR:
4401: {
4402: register rtx label1 = gen_label_rtx ();
4403: drop_through_label = gen_label_rtx ();
4404: do_jump (TREE_OPERAND (exp, 0), label1, 0);
4405: /* Now the THEN-expression. */
4406: do_jump (TREE_OPERAND (exp, 1),
4407: if_false_label ? if_false_label : drop_through_label,
4408: if_true_label ? if_true_label : drop_through_label);
4409: emit_label (label1);
4410: /* Now the ELSE-expression. */
4411: do_jump (TREE_OPERAND (exp, 2),
4412: if_false_label ? if_false_label : drop_through_label,
4413: if_true_label ? if_true_label : drop_through_label);
4414: }
4415: break;
4416:
4417: case EQ_EXPR:
4418: comparison = compare (exp, EQ, EQ, EQ, EQ);
4419: break;
4420:
4421: case NE_EXPR:
4422: comparison = compare (exp, NE, NE, NE, NE);
4423: break;
4424:
4425: case LT_EXPR:
4426: comparison = compare (exp, LT, LTU, GT, GTU);
4427: break;
4428:
4429: case LE_EXPR:
4430: comparison = compare (exp, LE, LEU, GE, GEU);
4431: break;
4432:
4433: case GT_EXPR:
4434: comparison = compare (exp, GT, GTU, LT, LTU);
4435: break;
4436:
4437: case GE_EXPR:
4438: comparison = compare (exp, GE, GEU, LE, LEU);
4439: break;
4440:
4441: default:
4442: temp = expand_expr (exp, 0, VOIDmode, 0);
1.1.1.2 root 4443: /* Copy to register to avoid generating bad insns by cse
4444: from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
4445: if (!cse_not_expected && GET_CODE (temp) == MEM)
4446: temp = copy_to_reg (temp);
1.1 root 4447: do_pending_stack_adjust ();
1.1.1.2 root 4448: {
4449: rtx zero;
4450: if (GET_MODE (temp) == SFmode)
4451: zero = fconst0_rtx;
4452: else if (GET_MODE (temp) == DFmode)
4453: zero = dconst0_rtx;
4454: else
4455: zero = const0_rtx;
1.1 root 4456:
1.1.1.2 root 4457: if (GET_CODE (temp) == CONST_INT)
4458: comparison = compare_constants (NE, 0,
4459: INTVAL (temp), 0, BITS_PER_WORD);
4460: else if (GET_MODE (temp) != VOIDmode)
4461: comparison = compare1 (temp, zero, NE, NE, 0, GET_MODE (temp));
4462: else
4463: abort ();
4464: }
1.1 root 4465: }
4466:
1.1.1.2 root 4467: /* Do any postincrements in the expression that was tested. */
4468: emit_queue ();
4469:
1.1 root 4470: /* If COMPARISON is nonzero here, it is an rtx that can be substituted
4471: straight into a conditional jump instruction as the jump condition.
4472: Otherwise, all the work has been done already. */
4473:
1.1.1.2 root 4474: if (comparison == const1_rtx)
4475: {
4476: if (if_true_label)
4477: emit_jump (if_true_label);
4478: }
4479: else if (comparison == const0_rtx)
4480: {
4481: if (if_false_label)
4482: emit_jump (if_false_label);
4483: }
4484: else if (comparison)
4485: {
4486: if (if_true_label)
4487: {
4488: emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
4489: gen_rtx (IF_THEN_ELSE, VOIDmode, comparison,
4490: gen_rtx (LABEL_REF, VOIDmode,
4491: if_true_label),
4492: pc_rtx)));
4493: if (if_false_label)
4494: emit_jump (if_false_label);
4495: }
4496: else if (if_false_label)
4497: {
4498: emit_jump_insn (gen_rtx (SET, VOIDmode, pc_rtx,
4499: gen_rtx (IF_THEN_ELSE, VOIDmode, comparison,
4500: pc_rtx,
4501: gen_rtx (LABEL_REF, VOIDmode,
4502: if_false_label))));
4503: }
4504: }
1.1 root 4505:
4506: if (drop_through_label)
4507: emit_label (drop_through_label);
4508: }
4509:
1.1.1.2 root 4510: /* Compare two integer constant rtx's, OP0 and OP1.
4511: The comparison operation is OPERATION.
4512: Return an rtx representing the value 1 or 0.
4513: WIDTH is the width in bits that is significant. */
4514:
4515: static rtx
4516: compare_constants (operation, unsignedp, op0, op1, width)
4517: enum rtx_code operation;
4518: int unsignedp;
4519: int op0, op1;
4520: int width;
4521: {
4522: int val;
4523:
4524: /* Sign-extend or zero-extend the operands to a full word
4525: from an initial width of WIDTH bits. */
4526: if (width < HOST_BITS_PER_INT)
4527: {
4528: op0 &= (1 << width) - 1;
4529: op1 &= (1 << width) - 1;
4530:
4531: if (! unsignedp)
4532: {
4533: if (op0 & (1 << (width - 1)))
4534: op0 |= ((-1) << width);
4535: if (op1 & (1 << (width - 1)))
4536: op1 |= ((-1) << width);
4537: }
4538: }
4539:
4540: switch (operation)
4541: {
4542: case EQ:
4543: val = op0 == op1;
4544: break;
4545:
4546: case NE:
4547: val = op0 != op1;
4548: break;
4549:
4550: case GT:
4551: case GTU:
4552: val = op0 > op1;
4553: break;
4554:
4555: case LT:
4556: case LTU:
4557: val = op0 < op1;
4558: break;
4559:
4560: case GE:
4561: case GEU:
4562: val = op0 >= op1;
4563: break;
4564:
4565: case LE:
4566: case LEU:
4567: val = op0 <= op1;
4568: }
4569:
4570: return val ? const1_rtx : const0_rtx;
4571: }
4572:
1.1 root 4573: /* Generate code for a comparison expression EXP
4574: (including code to compute the values to be compared)
4575: and set (CC0) according to the result.
4576: SIGNED_FORWARD should be the rtx operation for this comparison for
4577: signed data; UNSIGNED_FORWARD, likewise for use if data is unsigned.
4578: SIGNED_REVERSE and UNSIGNED_REVERSE are used if it is desirable
4579: to interchange the operands for the compare instruction.
4580:
4581: We force a stack adjustment unless there are currently
4582: things pushed on the stack that aren't yet used. */
4583:
4584: static rtx
4585: compare (exp, signed_forward, unsigned_forward,
4586: signed_reverse, unsigned_reverse)
4587: register tree exp;
4588: enum rtx_code signed_forward, unsigned_forward;
4589: enum rtx_code signed_reverse, unsigned_reverse;
4590: {
1.1.1.2 root 4591:
1.1 root 4592: register rtx op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
4593: register rtx op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
4594: register enum machine_mode mode = GET_MODE (op0);
4595: int unsignedp;
4596:
4597: /* If one operand is 0, make it the second one. */
4598:
4599: if (op0 == const0_rtx || op0 == fconst0_rtx || op0 == dconst0_rtx)
4600: {
4601: rtx tem = op0;
4602: op0 = op1;
4603: op1 = tem;
4604: signed_forward = signed_reverse;
4605: unsigned_forward = unsigned_reverse;
4606: }
4607:
1.1.1.2 root 4608: if (flag_force_mem)
1.1 root 4609: {
4610: op0 = force_not_mem (op0);
4611: op1 = force_not_mem (op1);
4612: }
4613:
4614: do_pending_stack_adjust ();
4615:
1.1.1.2 root 4616: unsignedp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
4617: || TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))));
4618:
4619: if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
4620: return compare_constants (signed_forward, unsignedp,
4621: INTVAL (op0), INTVAL (op1),
4622: GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))));
1.1 root 4623:
4624: emit_cmp_insn (op0, op1,
4625: (mode == BLKmode) ? expr_size (TREE_OPERAND (exp, 0)) : 0,
4626: unsignedp);
4627:
4628: return gen_rtx ((unsignedp ? unsigned_forward : signed_forward),
4629: VOIDmode, cc0_rtx, const0_rtx);
4630: }
4631:
4632: /* Like compare but expects the values to compare as two rtx's.
4633: The decision as to signed or unsigned comparison must be made by the caller.
4634: BLKmode is not allowed. */
4635:
4636: static rtx
1.1.1.2 root 4637: compare1 (op0, op1, forward_op, reverse_op, unsignedp, mode)
1.1 root 4638: register rtx op0, op1;
4639: enum rtx_code forward_op, reverse_op;
4640: int unsignedp;
1.1.1.2 root 4641: enum machine_mode mode;
1.1 root 4642: {
4643: /* If one operand is 0, make it the second one. */
4644:
4645: if (op0 == const0_rtx || op0 == fconst0_rtx || op0 == dconst0_rtx)
4646: {
4647: rtx tem = op0;
4648: op0 = op1;
4649: op1 = tem;
4650: forward_op = reverse_op;
4651: }
4652:
1.1.1.2 root 4653: if (flag_force_mem)
1.1 root 4654: {
4655: op0 = force_not_mem (op0);
4656: op1 = force_not_mem (op1);
4657: }
4658:
4659: do_pending_stack_adjust ();
4660:
1.1.1.2 root 4661: if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
4662: return compare_constants (forward_op, unsignedp,
4663: INTVAL (op0), INTVAL (op1),
4664: GET_MODE_BITSIZE (mode));
4665:
1.1 root 4666: emit_cmp_insn (op0, op1, 0, unsignedp);
4667:
4668: return gen_rtx (forward_op, VOIDmode, cc0_rtx, const0_rtx);
4669: }
4670:
4671: /* Generate code to calculate EXP using a store-flag instruction
4672: and return an rtx for the result.
4673: If TARGET is nonzero, store the result there if convenient.
4674:
4675: Return zero if there is no suitable set-flag instruction
4676: available on this machine. */
4677:
4678: static rtx
1.1.1.2 root 4679: do_store_flag (exp, target, mode)
1.1 root 4680: tree exp;
4681: rtx target;
1.1.1.2 root 4682: enum machine_mode mode;
1.1 root 4683: {
4684: register enum tree_code code = TREE_CODE (exp);
4685: register rtx comparison = 0;
1.1.1.2 root 4686: enum machine_mode compare_mode;
1.1 root 4687:
4688: switch (code)
4689: {
1.1.1.2 root 4690: #ifdef HAVE_seq
1.1 root 4691: case EQ_EXPR:
1.1.1.2 root 4692: if (HAVE_seq)
4693: {
4694: comparison = compare (exp, EQ, EQ, EQ, EQ);
4695: compare_mode = insn_operand_mode[(int) CODE_FOR_seq][0];
4696: }
1.1 root 4697: break;
4698: #endif
4699:
1.1.1.2 root 4700: #ifdef HAVE_sne
1.1 root 4701: case NE_EXPR:
1.1.1.2 root 4702: if (HAVE_sne)
4703: {
4704: comparison = compare (exp, NE, NE, NE, NE);
4705: compare_mode = insn_operand_mode[(int) CODE_FOR_sne][0];
4706: }
1.1 root 4707: break;
4708: #endif
4709:
1.1.1.2 root 4710: #if defined (HAVE_slt) && defined (HAVE_sltu) && defined (HAVE_sgt) && defined (HAVE_sgtu)
1.1 root 4711: case LT_EXPR:
1.1.1.2 root 4712: if (HAVE_slt && HAVE_sltu && HAVE_sgt && HAVE_sgtu)
4713: {
4714: comparison = compare (exp, LT, LTU, GT, GTU);
4715: compare_mode = insn_operand_mode[(int) CODE_FOR_slt][0];
4716: }
1.1 root 4717: break;
4718:
4719: case GT_EXPR:
1.1.1.2 root 4720: if (HAVE_slt && HAVE_sltu && HAVE_sgt && HAVE_sgtu)
4721: {
4722: comparison = compare (exp, GT, GTU, LT, LTU);
4723: compare_mode = insn_operand_mode[(int) CODE_FOR_slt][0];
4724: }
1.1 root 4725: break;
4726: #endif
4727:
1.1.1.2 root 4728: #if defined (HAVE_sle) && defined (HAVE_sleu) && defined (HAVE_sge) && defined (HAVE_sgeu)
1.1 root 4729: case LE_EXPR:
1.1.1.2 root 4730: if (HAVE_sle && HAVE_sleu && HAVE_sge && HAVE_sgeu)
4731: {
4732: comparison = compare (exp, LE, LEU, GE, GEU);
4733: compare_mode = insn_operand_mode[(int) CODE_FOR_sle][0];
4734: }
1.1 root 4735: break;
4736:
4737: case GE_EXPR:
1.1.1.2 root 4738: if (HAVE_sle && HAVE_sleu && HAVE_sge && HAVE_sgeu)
4739: {
4740: comparison = compare (exp, GE, GEU, LE, LEU);
4741: compare_mode = insn_operand_mode[(int) CODE_FOR_sle][0];
4742: }
1.1 root 4743: break;
4744: #endif
4745: }
4746: if (comparison == 0)
4747: return 0;
4748:
1.1.1.2 root 4749: if (target == 0 || GET_MODE (target) != mode
4750: || (mode != compare_mode && GET_CODE (target) != REG))
4751: target = gen_reg_rtx (mode);
4752:
4753: /* Store the comparison in its proper mode. */
4754: if (GET_MODE (target) != compare_mode)
4755: emit_insn (gen_rtx (SET, VOIDmode,
4756: gen_rtx (SUBREG, compare_mode, target, 0),
4757: comparison));
4758: else
4759: emit_insn (gen_rtx (SET, VOIDmode, target, comparison));
4760:
4761: #if STORE_FLAG_VALUE != 1
4762: expand_bit_and (mode, target, const1_rtx, target);
4763: #endif
1.1 root 4764: return target;
4765: }
4766:
4767: /* Generate a tablejump instruction (used for switch statements). */
4768:
4769: #ifdef HAVE_tablejump
4770:
4771: /* INDEX is the value being switched on, with the lowest value
4772: in the table already subtracted.
4773: RANGE is the length of the jump table.
4774: TABLE_LABEL is a CODE_LABEL rtx for the table itself.
1.1.1.2 root 4775:
1.1 root 4776: DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
4777: index value is out of range. */
4778:
4779: void
4780: do_tablejump (index, range, table_label, default_label)
4781: rtx index, range, table_label, default_label;
4782: {
4783: register rtx temp;
4784:
4785: emit_cmp_insn (range, index, 0);
1.1.1.2 root 4786: emit_jump_insn (gen_bltu (default_label));
1.1.1.4 root 4787: /* If flag_force_addr were to affect this address
4788: it could interfere with the tricky assumptions made
4789: about addresses that contain label-refs,
4790: which may be valid only very near the tablejump itself. */
4791: index = memory_address_noforce
4792: (CASE_VECTOR_MODE,
4793: gen_rtx (PLUS, Pmode,
4794: gen_rtx (MULT, Pmode, index,
4795: gen_rtx (CONST_INT, VOIDmode,
4796: GET_MODE_SIZE (CASE_VECTOR_MODE))),
4797: gen_rtx (LABEL_REF, VOIDmode, table_label)));
1.1 root 4798: temp = gen_reg_rtx (CASE_VECTOR_MODE);
4799: convert_move (temp, gen_rtx (MEM, CASE_VECTOR_MODE, index), 0);
4800:
1.1.1.2 root 4801: emit_jump_insn (gen_tablejump (temp, table_label));
1.1 root 4802: }
4803:
1.1.1.2 root 4804: #endif /* HAVE_tablejump */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.