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