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