(*zeroextract[qs]i_compare0_scratch): Use const_int_operand
[official-gcc.git] / gcc / expr.c
blob41fc899eb13727978e8656b50a386b001cec5fc9
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
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.
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "machmode.h"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "obstack.h"
27 #include "flags.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "function.h"
31 #include "insn-flags.h"
32 #include "insn-codes.h"
33 #include "expr.h"
34 #include "insn-config.h"
35 #include "recog.h"
36 #include "output.h"
37 #include "typeclass.h"
39 #include "bytecode.h"
40 #include "bc-opcode.h"
41 #include "bc-typecd.h"
42 #include "bc-optab.h"
43 #include "bc-emit.h"
46 #define CEIL(x,y) (((x) + (y) - 1) / (y))
48 /* Decide whether a function's arguments should be processed
49 from first to last or from last to first.
51 They should if the stack and args grow in opposite directions, but
52 only if we have push insns. */
54 #ifdef PUSH_ROUNDING
56 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
57 #define PUSH_ARGS_REVERSED /* If it's last to first */
58 #endif
60 #endif
62 #ifndef STACK_PUSH_CODE
63 #ifdef STACK_GROWS_DOWNWARD
64 #define STACK_PUSH_CODE PRE_DEC
65 #else
66 #define STACK_PUSH_CODE PRE_INC
67 #endif
68 #endif
70 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
71 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
73 /* If this is nonzero, we do not bother generating VOLATILE
74 around volatile memory references, and we are willing to
75 output indirect addresses. If cse is to follow, we reject
76 indirect addresses so a useful potential cse is generated;
77 if it is used only once, instruction combination will produce
78 the same indirect address eventually. */
79 int cse_not_expected;
81 /* Nonzero to generate code for all the subroutines within an
82 expression before generating the upper levels of the expression.
83 Nowadays this is never zero. */
84 int do_preexpand_calls = 1;
86 /* Number of units that we should eventually pop off the stack.
87 These are the arguments to function calls that have already returned. */
88 int pending_stack_adjust;
90 /* Nonzero means stack pops must not be deferred, and deferred stack
91 pops must not be output. It is nonzero inside a function call,
92 inside a conditional expression, inside a statement expression,
93 and in other cases as well. */
94 int inhibit_defer_pop;
96 /* A list of all cleanups which belong to the arguments of
97 function calls being expanded by expand_call. */
98 tree cleanups_this_call;
100 /* When temporaries are created by TARGET_EXPRs, they are created at
101 this level of temp_slot_level, so that they can remain allocated
102 until no longer needed. CLEANUP_POINT_EXPRs define the lifetime
103 of TARGET_EXPRs. */
104 int target_temp_slot_level;
106 /* Nonzero means __builtin_saveregs has already been done in this function.
107 The value is the pseudoreg containing the value __builtin_saveregs
108 returned. */
109 static rtx saveregs_value;
111 /* Similarly for __builtin_apply_args. */
112 static rtx apply_args_value;
114 /* This structure is used by move_by_pieces to describe the move to
115 be performed. */
117 struct move_by_pieces
119 rtx to;
120 rtx to_addr;
121 int autinc_to;
122 int explicit_inc_to;
123 int to_struct;
124 rtx from;
125 rtx from_addr;
126 int autinc_from;
127 int explicit_inc_from;
128 int from_struct;
129 int len;
130 int offset;
131 int reverse;
134 /* This structure is used by clear_by_pieces to describe the clear to
135 be performed. */
137 struct clear_by_pieces
139 rtx to;
140 rtx to_addr;
141 int autinc_to;
142 int explicit_inc_to;
143 int to_struct;
144 int len;
145 int offset;
146 int reverse;
149 /* Used to generate bytecodes: keep track of size of local variables,
150 as well as depth of arithmetic stack. (Notice that variables are
151 stored on the machine's stack, not the arithmetic stack.) */
153 extern int local_vars_size;
154 extern int stack_depth;
155 extern int max_stack_depth;
156 extern struct obstack permanent_obstack;
157 extern rtx arg_pointer_save_area;
159 static rtx enqueue_insn PROTO((rtx, rtx));
160 static int queued_subexp_p PROTO((rtx));
161 static void init_queue PROTO((void));
162 static void move_by_pieces PROTO((rtx, rtx, int, int));
163 static int move_by_pieces_ninsns PROTO((unsigned int, int));
164 static void move_by_pieces_1 PROTO((rtx (*) (), enum machine_mode,
165 struct move_by_pieces *));
166 static void clear_by_pieces PROTO((rtx, int, int));
167 static void clear_by_pieces_1 PROTO((rtx (*) (), enum machine_mode,
168 struct clear_by_pieces *));
169 static int is_zeros_p PROTO((tree));
170 static int mostly_zeros_p PROTO((tree));
171 static void store_constructor PROTO((tree, rtx, int));
172 static rtx store_field PROTO((rtx, int, int, enum machine_mode, tree,
173 enum machine_mode, int, int, int));
174 static int get_inner_unaligned_p PROTO((tree));
175 static tree save_noncopied_parts PROTO((tree, tree));
176 static tree init_noncopied_parts PROTO((tree, tree));
177 static int safe_from_p PROTO((rtx, tree));
178 static int fixed_type_p PROTO((tree));
179 static int get_pointer_alignment PROTO((tree, unsigned));
180 static tree string_constant PROTO((tree, tree *));
181 static tree c_strlen PROTO((tree));
182 static rtx expand_builtin PROTO((tree, rtx, rtx,
183 enum machine_mode, int));
184 static int apply_args_size PROTO((void));
185 static int apply_result_size PROTO((void));
186 static rtx result_vector PROTO((int, rtx));
187 static rtx expand_builtin_apply_args PROTO((void));
188 static rtx expand_builtin_apply PROTO((rtx, rtx, rtx));
189 static void expand_builtin_return PROTO((rtx));
190 static rtx expand_increment PROTO((tree, int));
191 rtx bc_expand_increment PROTO((struct increment_operator *, tree));
192 tree bc_runtime_type_code PROTO((tree));
193 rtx bc_allocate_local PROTO((int, int));
194 void bc_store_memory PROTO((tree, tree));
195 tree bc_expand_component_address PROTO((tree));
196 tree bc_expand_address PROTO((tree));
197 void bc_expand_constructor PROTO((tree));
198 void bc_adjust_stack PROTO((int));
199 tree bc_canonicalize_array_ref PROTO((tree));
200 void bc_load_memory PROTO((tree, tree));
201 void bc_load_externaddr PROTO((rtx));
202 void bc_load_externaddr_id PROTO((tree, int));
203 void bc_load_localaddr PROTO((rtx));
204 void bc_load_parmaddr PROTO((rtx));
205 static void preexpand_calls PROTO((tree));
206 static void do_jump_by_parts_greater PROTO((tree, int, rtx, rtx));
207 void do_jump_by_parts_greater_rtx PROTO((enum machine_mode, int, rtx, rtx, rtx, rtx));
208 static void do_jump_by_parts_equality PROTO((tree, rtx, rtx));
209 static void do_jump_by_parts_equality_rtx PROTO((rtx, rtx, rtx));
210 static void do_jump_for_compare PROTO((rtx, rtx, rtx));
211 static rtx compare PROTO((tree, enum rtx_code, enum rtx_code));
212 static rtx do_store_flag PROTO((tree, rtx, enum machine_mode, int));
213 static tree defer_cleanups_to PROTO((tree));
214 extern void (*interim_eh_hook) PROTO((tree));
215 extern tree truthvalue_conversion PROTO((tree));
217 /* Record for each mode whether we can move a register directly to or
218 from an object of that mode in memory. If we can't, we won't try
219 to use that mode directly when accessing a field of that mode. */
221 static char direct_load[NUM_MACHINE_MODES];
222 static char direct_store[NUM_MACHINE_MODES];
224 /* MOVE_RATIO is the number of move instructions that is better than
225 a block move. */
227 #ifndef MOVE_RATIO
228 #if defined (HAVE_movstrqi) || defined (HAVE_movstrhi) || defined (HAVE_movstrsi) || defined (HAVE_movstrdi) || defined (HAVE_movstrti)
229 #define MOVE_RATIO 2
230 #else
231 /* A value of around 6 would minimize code size; infinity would minimize
232 execution time. */
233 #define MOVE_RATIO 15
234 #endif
235 #endif
237 /* This array records the insn_code of insns to perform block moves. */
238 enum insn_code movstr_optab[NUM_MACHINE_MODES];
240 /* This array records the insn_code of insns to perform block clears. */
241 enum insn_code clrstr_optab[NUM_MACHINE_MODES];
243 /* SLOW_UNALIGNED_ACCESS is non-zero if unaligned accesses are very slow. */
245 #ifndef SLOW_UNALIGNED_ACCESS
246 #define SLOW_UNALIGNED_ACCESS STRICT_ALIGNMENT
247 #endif
249 /* Register mappings for target machines without register windows. */
250 #ifndef INCOMING_REGNO
251 #define INCOMING_REGNO(OUT) (OUT)
252 #endif
253 #ifndef OUTGOING_REGNO
254 #define OUTGOING_REGNO(IN) (IN)
255 #endif
257 /* Maps used to convert modes to const, load, and store bytecodes. */
258 enum bytecode_opcode mode_to_const_map[MAX_MACHINE_MODE];
259 enum bytecode_opcode mode_to_load_map[MAX_MACHINE_MODE];
260 enum bytecode_opcode mode_to_store_map[MAX_MACHINE_MODE];
262 /* Initialize maps used to convert modes to const, load, and store
263 bytecodes. */
264 void
265 bc_init_mode_to_opcode_maps ()
267 int mode;
269 for (mode = 0; mode < (int) MAX_MACHINE_MODE; mode++)
270 mode_to_const_map[mode] =
271 mode_to_load_map[mode] =
272 mode_to_store_map[mode] = neverneverland;
274 #define DEF_MODEMAP(SYM, CODE, UCODE, CONST, LOAD, STORE) \
275 mode_to_const_map[(int) SYM] = CONST; \
276 mode_to_load_map[(int) SYM] = LOAD; \
277 mode_to_store_map[(int) SYM] = STORE;
279 #include "modemap.def"
280 #undef DEF_MODEMAP
283 /* This is run once per compilation to set up which modes can be used
284 directly in memory and to initialize the block move optab. */
286 void
287 init_expr_once ()
289 rtx insn, pat;
290 enum machine_mode mode;
291 /* Try indexing by frame ptr and try by stack ptr.
292 It is known that on the Convex the stack ptr isn't a valid index.
293 With luck, one or the other is valid on any machine. */
294 rtx mem = gen_rtx (MEM, VOIDmode, stack_pointer_rtx);
295 rtx mem1 = gen_rtx (MEM, VOIDmode, frame_pointer_rtx);
297 start_sequence ();
298 insn = emit_insn (gen_rtx (SET, 0, 0));
299 pat = PATTERN (insn);
301 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
302 mode = (enum machine_mode) ((int) mode + 1))
304 int regno;
305 rtx reg;
306 int num_clobbers;
308 direct_load[(int) mode] = direct_store[(int) mode] = 0;
309 PUT_MODE (mem, mode);
310 PUT_MODE (mem1, mode);
312 /* See if there is some register that can be used in this mode and
313 directly loaded or stored from memory. */
315 if (mode != VOIDmode && mode != BLKmode)
316 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
317 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
318 regno++)
320 if (! HARD_REGNO_MODE_OK (regno, mode))
321 continue;
323 reg = gen_rtx (REG, mode, regno);
325 SET_SRC (pat) = mem;
326 SET_DEST (pat) = reg;
327 if (recog (pat, insn, &num_clobbers) >= 0)
328 direct_load[(int) mode] = 1;
330 SET_SRC (pat) = mem1;
331 SET_DEST (pat) = reg;
332 if (recog (pat, insn, &num_clobbers) >= 0)
333 direct_load[(int) mode] = 1;
335 SET_SRC (pat) = reg;
336 SET_DEST (pat) = mem;
337 if (recog (pat, insn, &num_clobbers) >= 0)
338 direct_store[(int) mode] = 1;
340 SET_SRC (pat) = reg;
341 SET_DEST (pat) = mem1;
342 if (recog (pat, insn, &num_clobbers) >= 0)
343 direct_store[(int) mode] = 1;
347 end_sequence ();
350 /* This is run at the start of compiling a function. */
352 void
353 init_expr ()
355 init_queue ();
357 pending_stack_adjust = 0;
358 inhibit_defer_pop = 0;
359 cleanups_this_call = 0;
360 saveregs_value = 0;
361 apply_args_value = 0;
362 forced_labels = 0;
365 /* Save all variables describing the current status into the structure *P.
366 This is used before starting a nested function. */
368 void
369 save_expr_status (p)
370 struct function *p;
372 /* Instead of saving the postincrement queue, empty it. */
373 emit_queue ();
375 p->pending_stack_adjust = pending_stack_adjust;
376 p->inhibit_defer_pop = inhibit_defer_pop;
377 p->cleanups_this_call = cleanups_this_call;
378 p->saveregs_value = saveregs_value;
379 p->apply_args_value = apply_args_value;
380 p->forced_labels = forced_labels;
382 pending_stack_adjust = 0;
383 inhibit_defer_pop = 0;
384 cleanups_this_call = 0;
385 saveregs_value = 0;
386 apply_args_value = 0;
387 forced_labels = 0;
390 /* Restore all variables describing the current status from the structure *P.
391 This is used after a nested function. */
393 void
394 restore_expr_status (p)
395 struct function *p;
397 pending_stack_adjust = p->pending_stack_adjust;
398 inhibit_defer_pop = p->inhibit_defer_pop;
399 cleanups_this_call = p->cleanups_this_call;
400 saveregs_value = p->saveregs_value;
401 apply_args_value = p->apply_args_value;
402 forced_labels = p->forced_labels;
405 /* Manage the queue of increment instructions to be output
406 for POSTINCREMENT_EXPR expressions, etc. */
408 static rtx pending_chain;
410 /* Queue up to increment (or change) VAR later. BODY says how:
411 BODY should be the same thing you would pass to emit_insn
412 to increment right away. It will go to emit_insn later on.
414 The value is a QUEUED expression to be used in place of VAR
415 where you want to guarantee the pre-incrementation value of VAR. */
417 static rtx
418 enqueue_insn (var, body)
419 rtx var, body;
421 pending_chain = gen_rtx (QUEUED, GET_MODE (var),
422 var, NULL_RTX, NULL_RTX, body, pending_chain);
423 return pending_chain;
426 /* Use protect_from_queue to convert a QUEUED expression
427 into something that you can put immediately into an instruction.
428 If the queued incrementation has not happened yet,
429 protect_from_queue returns the variable itself.
430 If the incrementation has happened, protect_from_queue returns a temp
431 that contains a copy of the old value of the variable.
433 Any time an rtx which might possibly be a QUEUED is to be put
434 into an instruction, it must be passed through protect_from_queue first.
435 QUEUED expressions are not meaningful in instructions.
437 Do not pass a value through protect_from_queue and then hold
438 on to it for a while before putting it in an instruction!
439 If the queue is flushed in between, incorrect code will result. */
442 protect_from_queue (x, modify)
443 register rtx x;
444 int modify;
446 register RTX_CODE code = GET_CODE (x);
448 #if 0 /* A QUEUED can hang around after the queue is forced out. */
449 /* Shortcut for most common case. */
450 if (pending_chain == 0)
451 return x;
452 #endif
454 if (code != QUEUED)
456 /* A special hack for read access to (MEM (QUEUED ...)) to facilitate
457 use of autoincrement. Make a copy of the contents of the memory
458 location rather than a copy of the address, but not if the value is
459 of mode BLKmode. Don't modify X in place since it might be
460 shared. */
461 if (code == MEM && GET_MODE (x) != BLKmode
462 && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
464 register rtx y = XEXP (x, 0);
465 register rtx new = gen_rtx (MEM, GET_MODE (x), QUEUED_VAR (y));
467 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
468 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
469 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
471 if (QUEUED_INSN (y))
473 register rtx temp = gen_reg_rtx (GET_MODE (new));
474 emit_insn_before (gen_move_insn (temp, new),
475 QUEUED_INSN (y));
476 return temp;
478 return new;
480 /* Otherwise, recursively protect the subexpressions of all
481 the kinds of rtx's that can contain a QUEUED. */
482 if (code == MEM)
484 rtx tem = protect_from_queue (XEXP (x, 0), 0);
485 if (tem != XEXP (x, 0))
487 x = copy_rtx (x);
488 XEXP (x, 0) = tem;
491 else if (code == PLUS || code == MULT)
493 rtx new0 = protect_from_queue (XEXP (x, 0), 0);
494 rtx new1 = protect_from_queue (XEXP (x, 1), 0);
495 if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
497 x = copy_rtx (x);
498 XEXP (x, 0) = new0;
499 XEXP (x, 1) = new1;
502 return x;
504 /* If the increment has not happened, use the variable itself. */
505 if (QUEUED_INSN (x) == 0)
506 return QUEUED_VAR (x);
507 /* If the increment has happened and a pre-increment copy exists,
508 use that copy. */
509 if (QUEUED_COPY (x) != 0)
510 return QUEUED_COPY (x);
511 /* The increment has happened but we haven't set up a pre-increment copy.
512 Set one up now, and use it. */
513 QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
514 emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
515 QUEUED_INSN (x));
516 return QUEUED_COPY (x);
519 /* Return nonzero if X contains a QUEUED expression:
520 if it contains anything that will be altered by a queued increment.
521 We handle only combinations of MEM, PLUS, MINUS and MULT operators
522 since memory addresses generally contain only those. */
524 static int
525 queued_subexp_p (x)
526 rtx x;
528 register enum rtx_code code = GET_CODE (x);
529 switch (code)
531 case QUEUED:
532 return 1;
533 case MEM:
534 return queued_subexp_p (XEXP (x, 0));
535 case MULT:
536 case PLUS:
537 case MINUS:
538 return queued_subexp_p (XEXP (x, 0))
539 || queued_subexp_p (XEXP (x, 1));
541 return 0;
544 /* Perform all the pending incrementations. */
546 void
547 emit_queue ()
549 register rtx p;
550 while (p = pending_chain)
552 QUEUED_INSN (p) = emit_insn (QUEUED_BODY (p));
553 pending_chain = QUEUED_NEXT (p);
557 static void
558 init_queue ()
560 if (pending_chain)
561 abort ();
564 /* Copy data from FROM to TO, where the machine modes are not the same.
565 Both modes may be integer, or both may be floating.
566 UNSIGNEDP should be nonzero if FROM is an unsigned type.
567 This causes zero-extension instead of sign-extension. */
569 void
570 convert_move (to, from, unsignedp)
571 register rtx to, from;
572 int unsignedp;
574 enum machine_mode to_mode = GET_MODE (to);
575 enum machine_mode from_mode = GET_MODE (from);
576 int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
577 int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
578 enum insn_code code;
579 rtx libcall;
581 /* rtx code for making an equivalent value. */
582 enum rtx_code equiv_code = (unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
584 to = protect_from_queue (to, 1);
585 from = protect_from_queue (from, 0);
587 if (to_real != from_real)
588 abort ();
590 /* If FROM is a SUBREG that indicates that we have already done at least
591 the required extension, strip it. We don't handle such SUBREGs as
592 TO here. */
594 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
595 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
596 >= GET_MODE_SIZE (to_mode))
597 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
598 from = gen_lowpart (to_mode, from), from_mode = to_mode;
600 if (GET_CODE (to) == SUBREG && SUBREG_PROMOTED_VAR_P (to))
601 abort ();
603 if (to_mode == from_mode
604 || (from_mode == VOIDmode && CONSTANT_P (from)))
606 emit_move_insn (to, from);
607 return;
610 if (to_real)
612 rtx value;
614 #ifdef HAVE_extendqfhf2
615 if (HAVE_extendqfhf2 && from_mode == QFmode && to_mode == HFmode)
617 emit_unop_insn (CODE_FOR_extendqfhf2, to, from, UNKNOWN);
618 return;
620 #endif
621 #ifdef HAVE_extendqfsf2
622 if (HAVE_extendqfsf2 && from_mode == QFmode && to_mode == SFmode)
624 emit_unop_insn (CODE_FOR_extendqfsf2, to, from, UNKNOWN);
625 return;
627 #endif
628 #ifdef HAVE_extendqfdf2
629 if (HAVE_extendqfdf2 && from_mode == QFmode && to_mode == DFmode)
631 emit_unop_insn (CODE_FOR_extendqfdf2, to, from, UNKNOWN);
632 return;
634 #endif
635 #ifdef HAVE_extendqfxf2
636 if (HAVE_extendqfxf2 && from_mode == QFmode && to_mode == XFmode)
638 emit_unop_insn (CODE_FOR_extendqfxf2, to, from, UNKNOWN);
639 return;
641 #endif
642 #ifdef HAVE_extendqftf2
643 if (HAVE_extendqftf2 && from_mode == QFmode && to_mode == TFmode)
645 emit_unop_insn (CODE_FOR_extendqftf2, to, from, UNKNOWN);
646 return;
648 #endif
650 #ifdef HAVE_extendhftqf2
651 if (HAVE_extendhftqf2 && from_mode == HFmode && to_mode == TQFmode)
653 emit_unop_insn (CODE_FOR_extendhftqf2, to, from, UNKNOWN);
654 return;
656 #endif
658 #ifdef HAVE_extendhfsf2
659 if (HAVE_extendhfsf2 && from_mode == HFmode && to_mode == SFmode)
661 emit_unop_insn (CODE_FOR_extendhfsf2, to, from, UNKNOWN);
662 return;
664 #endif
665 #ifdef HAVE_extendhfdf2
666 if (HAVE_extendhfdf2 && from_mode == HFmode && to_mode == DFmode)
668 emit_unop_insn (CODE_FOR_extendhfdf2, to, from, UNKNOWN);
669 return;
671 #endif
672 #ifdef HAVE_extendhfxf2
673 if (HAVE_extendhfxf2 && from_mode == HFmode && to_mode == XFmode)
675 emit_unop_insn (CODE_FOR_extendhfxf2, to, from, UNKNOWN);
676 return;
678 #endif
679 #ifdef HAVE_extendhftf2
680 if (HAVE_extendhftf2 && from_mode == HFmode && to_mode == TFmode)
682 emit_unop_insn (CODE_FOR_extendhftf2, to, from, UNKNOWN);
683 return;
685 #endif
687 #ifdef HAVE_extendsfdf2
688 if (HAVE_extendsfdf2 && from_mode == SFmode && to_mode == DFmode)
690 emit_unop_insn (CODE_FOR_extendsfdf2, to, from, UNKNOWN);
691 return;
693 #endif
694 #ifdef HAVE_extendsfxf2
695 if (HAVE_extendsfxf2 && from_mode == SFmode && to_mode == XFmode)
697 emit_unop_insn (CODE_FOR_extendsfxf2, to, from, UNKNOWN);
698 return;
700 #endif
701 #ifdef HAVE_extendsftf2
702 if (HAVE_extendsftf2 && from_mode == SFmode && to_mode == TFmode)
704 emit_unop_insn (CODE_FOR_extendsftf2, to, from, UNKNOWN);
705 return;
707 #endif
708 #ifdef HAVE_extenddfxf2
709 if (HAVE_extenddfxf2 && from_mode == DFmode && to_mode == XFmode)
711 emit_unop_insn (CODE_FOR_extenddfxf2, to, from, UNKNOWN);
712 return;
714 #endif
715 #ifdef HAVE_extenddftf2
716 if (HAVE_extenddftf2 && from_mode == DFmode && to_mode == TFmode)
718 emit_unop_insn (CODE_FOR_extenddftf2, to, from, UNKNOWN);
719 return;
721 #endif
723 #ifdef HAVE_trunchfqf2
724 if (HAVE_trunchfqf2 && from_mode == HFmode && to_mode == QFmode)
726 emit_unop_insn (CODE_FOR_trunchfqf2, to, from, UNKNOWN);
727 return;
729 #endif
730 #ifdef HAVE_truncsfqf2
731 if (HAVE_truncsfqf2 && from_mode == SFmode && to_mode == QFmode)
733 emit_unop_insn (CODE_FOR_truncsfqf2, to, from, UNKNOWN);
734 return;
736 #endif
737 #ifdef HAVE_truncdfqf2
738 if (HAVE_truncdfqf2 && from_mode == DFmode && to_mode == QFmode)
740 emit_unop_insn (CODE_FOR_truncdfqf2, to, from, UNKNOWN);
741 return;
743 #endif
744 #ifdef HAVE_truncxfqf2
745 if (HAVE_truncxfqf2 && from_mode == XFmode && to_mode == QFmode)
747 emit_unop_insn (CODE_FOR_truncxfqf2, to, from, UNKNOWN);
748 return;
750 #endif
751 #ifdef HAVE_trunctfqf2
752 if (HAVE_trunctfqf2 && from_mode == TFmode && to_mode == QFmode)
754 emit_unop_insn (CODE_FOR_trunctfqf2, to, from, UNKNOWN);
755 return;
757 #endif
759 #ifdef HAVE_trunctqfhf2
760 if (HAVE_trunctqfhf2 && from_mode == TQFmode && to_mode == HFmode)
762 emit_unop_insn (CODE_FOR_trunctqfhf2, to, from, UNKNOWN);
763 return;
765 #endif
766 #ifdef HAVE_truncsfhf2
767 if (HAVE_truncsfhf2 && from_mode == SFmode && to_mode == HFmode)
769 emit_unop_insn (CODE_FOR_truncsfhf2, to, from, UNKNOWN);
770 return;
772 #endif
773 #ifdef HAVE_truncdfhf2
774 if (HAVE_truncdfhf2 && from_mode == DFmode && to_mode == HFmode)
776 emit_unop_insn (CODE_FOR_truncdfhf2, to, from, UNKNOWN);
777 return;
779 #endif
780 #ifdef HAVE_truncxfhf2
781 if (HAVE_truncxfhf2 && from_mode == XFmode && to_mode == HFmode)
783 emit_unop_insn (CODE_FOR_truncxfhf2, to, from, UNKNOWN);
784 return;
786 #endif
787 #ifdef HAVE_trunctfhf2
788 if (HAVE_trunctfhf2 && from_mode == TFmode && to_mode == HFmode)
790 emit_unop_insn (CODE_FOR_trunctfhf2, to, from, UNKNOWN);
791 return;
793 #endif
794 #ifdef HAVE_truncdfsf2
795 if (HAVE_truncdfsf2 && from_mode == DFmode && to_mode == SFmode)
797 emit_unop_insn (CODE_FOR_truncdfsf2, to, from, UNKNOWN);
798 return;
800 #endif
801 #ifdef HAVE_truncxfsf2
802 if (HAVE_truncxfsf2 && from_mode == XFmode && to_mode == SFmode)
804 emit_unop_insn (CODE_FOR_truncxfsf2, to, from, UNKNOWN);
805 return;
807 #endif
808 #ifdef HAVE_trunctfsf2
809 if (HAVE_trunctfsf2 && from_mode == TFmode && to_mode == SFmode)
811 emit_unop_insn (CODE_FOR_trunctfsf2, to, from, UNKNOWN);
812 return;
814 #endif
815 #ifdef HAVE_truncxfdf2
816 if (HAVE_truncxfdf2 && from_mode == XFmode && to_mode == DFmode)
818 emit_unop_insn (CODE_FOR_truncxfdf2, to, from, UNKNOWN);
819 return;
821 #endif
822 #ifdef HAVE_trunctfdf2
823 if (HAVE_trunctfdf2 && from_mode == TFmode && to_mode == DFmode)
825 emit_unop_insn (CODE_FOR_trunctfdf2, to, from, UNKNOWN);
826 return;
828 #endif
830 libcall = (rtx) 0;
831 switch (from_mode)
833 case SFmode:
834 switch (to_mode)
836 case DFmode:
837 libcall = extendsfdf2_libfunc;
838 break;
840 case XFmode:
841 libcall = extendsfxf2_libfunc;
842 break;
844 case TFmode:
845 libcall = extendsftf2_libfunc;
846 break;
848 break;
850 case DFmode:
851 switch (to_mode)
853 case SFmode:
854 libcall = truncdfsf2_libfunc;
855 break;
857 case XFmode:
858 libcall = extenddfxf2_libfunc;
859 break;
861 case TFmode:
862 libcall = extenddftf2_libfunc;
863 break;
865 break;
867 case XFmode:
868 switch (to_mode)
870 case SFmode:
871 libcall = truncxfsf2_libfunc;
872 break;
874 case DFmode:
875 libcall = truncxfdf2_libfunc;
876 break;
878 break;
880 case TFmode:
881 switch (to_mode)
883 case SFmode:
884 libcall = trunctfsf2_libfunc;
885 break;
887 case DFmode:
888 libcall = trunctfdf2_libfunc;
889 break;
891 break;
894 if (libcall == (rtx) 0)
895 /* This conversion is not implemented yet. */
896 abort ();
898 value = emit_library_call_value (libcall, NULL_RTX, 1, to_mode,
899 1, from, from_mode);
900 emit_move_insn (to, value);
901 return;
904 /* Now both modes are integers. */
906 /* Handle expanding beyond a word. */
907 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
908 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
910 rtx insns;
911 rtx lowpart;
912 rtx fill_value;
913 rtx lowfrom;
914 int i;
915 enum machine_mode lowpart_mode;
916 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
918 /* Try converting directly if the insn is supported. */
919 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
920 != CODE_FOR_nothing)
922 /* If FROM is a SUBREG, put it into a register. Do this
923 so that we always generate the same set of insns for
924 better cse'ing; if an intermediate assignment occurred,
925 we won't be doing the operation directly on the SUBREG. */
926 if (optimize > 0 && GET_CODE (from) == SUBREG)
927 from = force_reg (from_mode, from);
928 emit_unop_insn (code, to, from, equiv_code);
929 return;
931 /* Next, try converting via full word. */
932 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
933 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
934 != CODE_FOR_nothing))
936 if (GET_CODE (to) == REG)
937 emit_insn (gen_rtx (CLOBBER, VOIDmode, to));
938 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
939 emit_unop_insn (code, to,
940 gen_lowpart (word_mode, to), equiv_code);
941 return;
944 /* No special multiword conversion insn; do it by hand. */
945 start_sequence ();
947 /* Since we will turn this into a no conflict block, we must ensure
948 that the source does not overlap the target. */
950 if (reg_overlap_mentioned_p (to, from))
951 from = force_reg (from_mode, from);
953 /* Get a copy of FROM widened to a word, if necessary. */
954 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
955 lowpart_mode = word_mode;
956 else
957 lowpart_mode = from_mode;
959 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
961 lowpart = gen_lowpart (lowpart_mode, to);
962 emit_move_insn (lowpart, lowfrom);
964 /* Compute the value to put in each remaining word. */
965 if (unsignedp)
966 fill_value = const0_rtx;
967 else
969 #ifdef HAVE_slt
970 if (HAVE_slt
971 && insn_operand_mode[(int) CODE_FOR_slt][0] == word_mode
972 && STORE_FLAG_VALUE == -1)
974 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
975 lowpart_mode, 0, 0);
976 fill_value = gen_reg_rtx (word_mode);
977 emit_insn (gen_slt (fill_value));
979 else
980 #endif
982 fill_value
983 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
984 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
985 NULL_RTX, 0);
986 fill_value = convert_to_mode (word_mode, fill_value, 1);
990 /* Fill the remaining words. */
991 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
993 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
994 rtx subword = operand_subword (to, index, 1, to_mode);
996 if (subword == 0)
997 abort ();
999 if (fill_value != subword)
1000 emit_move_insn (subword, fill_value);
1003 insns = get_insns ();
1004 end_sequence ();
1006 emit_no_conflict_block (insns, to, from, NULL_RTX,
1007 gen_rtx (equiv_code, to_mode, copy_rtx (from)));
1008 return;
1011 /* Truncating multi-word to a word or less. */
1012 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
1013 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
1015 if (!((GET_CODE (from) == MEM
1016 && ! MEM_VOLATILE_P (from)
1017 && direct_load[(int) to_mode]
1018 && ! mode_dependent_address_p (XEXP (from, 0)))
1019 || GET_CODE (from) == REG
1020 || GET_CODE (from) == SUBREG))
1021 from = force_reg (from_mode, from);
1022 convert_move (to, gen_lowpart (word_mode, from), 0);
1023 return;
1026 /* Handle pointer conversion */ /* SPEE 900220 */
1027 if (to_mode == PSImode)
1029 if (from_mode != SImode)
1030 from = convert_to_mode (SImode, from, unsignedp);
1032 #ifdef HAVE_truncsipsi2
1033 if (HAVE_truncsipsi2)
1035 emit_unop_insn (CODE_FOR_truncsipsi2, to, from, UNKNOWN);
1036 return;
1038 #endif /* HAVE_truncsipsi2 */
1039 abort ();
1042 if (from_mode == PSImode)
1044 if (to_mode != SImode)
1046 from = convert_to_mode (SImode, from, unsignedp);
1047 from_mode = SImode;
1049 else
1051 #ifdef HAVE_extendpsisi2
1052 if (HAVE_extendpsisi2)
1054 emit_unop_insn (CODE_FOR_extendpsisi2, to, from, UNKNOWN);
1055 return;
1057 #endif /* HAVE_extendpsisi2 */
1058 abort ();
1062 if (to_mode == PDImode)
1064 if (from_mode != DImode)
1065 from = convert_to_mode (DImode, from, unsignedp);
1067 #ifdef HAVE_truncdipdi2
1068 if (HAVE_truncdipdi2)
1070 emit_unop_insn (CODE_FOR_truncdipdi2, to, from, UNKNOWN);
1071 return;
1073 #endif /* HAVE_truncdipdi2 */
1074 abort ();
1077 if (from_mode == PDImode)
1079 if (to_mode != DImode)
1081 from = convert_to_mode (DImode, from, unsignedp);
1082 from_mode = DImode;
1084 else
1086 #ifdef HAVE_extendpdidi2
1087 if (HAVE_extendpdidi2)
1089 emit_unop_insn (CODE_FOR_extendpdidi2, to, from, UNKNOWN);
1090 return;
1092 #endif /* HAVE_extendpdidi2 */
1093 abort ();
1097 /* Now follow all the conversions between integers
1098 no more than a word long. */
1100 /* For truncation, usually we can just refer to FROM in a narrower mode. */
1101 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
1102 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
1103 GET_MODE_BITSIZE (from_mode)))
1105 if (!((GET_CODE (from) == MEM
1106 && ! MEM_VOLATILE_P (from)
1107 && direct_load[(int) to_mode]
1108 && ! mode_dependent_address_p (XEXP (from, 0)))
1109 || GET_CODE (from) == REG
1110 || GET_CODE (from) == SUBREG))
1111 from = force_reg (from_mode, from);
1112 if (GET_CODE (from) == REG && REGNO (from) < FIRST_PSEUDO_REGISTER
1113 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
1114 from = copy_to_reg (from);
1115 emit_move_insn (to, gen_lowpart (to_mode, from));
1116 return;
1119 /* Handle extension. */
1120 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
1122 /* Convert directly if that works. */
1123 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
1124 != CODE_FOR_nothing)
1126 emit_unop_insn (code, to, from, equiv_code);
1127 return;
1129 else
1131 enum machine_mode intermediate;
1133 /* Search for a mode to convert via. */
1134 for (intermediate = from_mode; intermediate != VOIDmode;
1135 intermediate = GET_MODE_WIDER_MODE (intermediate))
1136 if (((can_extend_p (to_mode, intermediate, unsignedp)
1137 != CODE_FOR_nothing)
1138 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
1139 && TRULY_NOOP_TRUNCATION (to_mode, intermediate)))
1140 && (can_extend_p (intermediate, from_mode, unsignedp)
1141 != CODE_FOR_nothing))
1143 convert_move (to, convert_to_mode (intermediate, from,
1144 unsignedp), unsignedp);
1145 return;
1148 /* No suitable intermediate mode. */
1149 abort ();
1153 /* Support special truncate insns for certain modes. */
1155 if (from_mode == DImode && to_mode == SImode)
1157 #ifdef HAVE_truncdisi2
1158 if (HAVE_truncdisi2)
1160 emit_unop_insn (CODE_FOR_truncdisi2, to, from, UNKNOWN);
1161 return;
1163 #endif
1164 convert_move (to, force_reg (from_mode, from), unsignedp);
1165 return;
1168 if (from_mode == DImode && to_mode == HImode)
1170 #ifdef HAVE_truncdihi2
1171 if (HAVE_truncdihi2)
1173 emit_unop_insn (CODE_FOR_truncdihi2, to, from, UNKNOWN);
1174 return;
1176 #endif
1177 convert_move (to, force_reg (from_mode, from), unsignedp);
1178 return;
1181 if (from_mode == DImode && to_mode == QImode)
1183 #ifdef HAVE_truncdiqi2
1184 if (HAVE_truncdiqi2)
1186 emit_unop_insn (CODE_FOR_truncdiqi2, to, from, UNKNOWN);
1187 return;
1189 #endif
1190 convert_move (to, force_reg (from_mode, from), unsignedp);
1191 return;
1194 if (from_mode == SImode && to_mode == HImode)
1196 #ifdef HAVE_truncsihi2
1197 if (HAVE_truncsihi2)
1199 emit_unop_insn (CODE_FOR_truncsihi2, to, from, UNKNOWN);
1200 return;
1202 #endif
1203 convert_move (to, force_reg (from_mode, from), unsignedp);
1204 return;
1207 if (from_mode == SImode && to_mode == QImode)
1209 #ifdef HAVE_truncsiqi2
1210 if (HAVE_truncsiqi2)
1212 emit_unop_insn (CODE_FOR_truncsiqi2, to, from, UNKNOWN);
1213 return;
1215 #endif
1216 convert_move (to, force_reg (from_mode, from), unsignedp);
1217 return;
1220 if (from_mode == HImode && to_mode == QImode)
1222 #ifdef HAVE_trunchiqi2
1223 if (HAVE_trunchiqi2)
1225 emit_unop_insn (CODE_FOR_trunchiqi2, to, from, UNKNOWN);
1226 return;
1228 #endif
1229 convert_move (to, force_reg (from_mode, from), unsignedp);
1230 return;
1233 if (from_mode == TImode && to_mode == DImode)
1235 #ifdef HAVE_trunctidi2
1236 if (HAVE_trunctidi2)
1238 emit_unop_insn (CODE_FOR_trunctidi2, to, from, UNKNOWN);
1239 return;
1241 #endif
1242 convert_move (to, force_reg (from_mode, from), unsignedp);
1243 return;
1246 if (from_mode == TImode && to_mode == SImode)
1248 #ifdef HAVE_trunctisi2
1249 if (HAVE_trunctisi2)
1251 emit_unop_insn (CODE_FOR_trunctisi2, to, from, UNKNOWN);
1252 return;
1254 #endif
1255 convert_move (to, force_reg (from_mode, from), unsignedp);
1256 return;
1259 if (from_mode == TImode && to_mode == HImode)
1261 #ifdef HAVE_trunctihi2
1262 if (HAVE_trunctihi2)
1264 emit_unop_insn (CODE_FOR_trunctihi2, to, from, UNKNOWN);
1265 return;
1267 #endif
1268 convert_move (to, force_reg (from_mode, from), unsignedp);
1269 return;
1272 if (from_mode == TImode && to_mode == QImode)
1274 #ifdef HAVE_trunctiqi2
1275 if (HAVE_trunctiqi2)
1277 emit_unop_insn (CODE_FOR_trunctiqi2, to, from, UNKNOWN);
1278 return;
1280 #endif
1281 convert_move (to, force_reg (from_mode, from), unsignedp);
1282 return;
1285 /* Handle truncation of volatile memrefs, and so on;
1286 the things that couldn't be truncated directly,
1287 and for which there was no special instruction. */
1288 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
1290 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
1291 emit_move_insn (to, temp);
1292 return;
1295 /* Mode combination is not recognized. */
1296 abort ();
1299 /* Return an rtx for a value that would result
1300 from converting X to mode MODE.
1301 Both X and MODE may be floating, or both integer.
1302 UNSIGNEDP is nonzero if X is an unsigned value.
1303 This can be done by referring to a part of X in place
1304 or by copying to a new temporary with conversion.
1306 This function *must not* call protect_from_queue
1307 except when putting X into an insn (in which case convert_move does it). */
1310 convert_to_mode (mode, x, unsignedp)
1311 enum machine_mode mode;
1312 rtx x;
1313 int unsignedp;
1315 return convert_modes (mode, VOIDmode, x, unsignedp);
1318 /* Return an rtx for a value that would result
1319 from converting X from mode OLDMODE to mode MODE.
1320 Both modes may be floating, or both integer.
1321 UNSIGNEDP is nonzero if X is an unsigned value.
1323 This can be done by referring to a part of X in place
1324 or by copying to a new temporary with conversion.
1326 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode.
1328 This function *must not* call protect_from_queue
1329 except when putting X into an insn (in which case convert_move does it). */
1332 convert_modes (mode, oldmode, x, unsignedp)
1333 enum machine_mode mode, oldmode;
1334 rtx x;
1335 int unsignedp;
1337 register rtx temp;
1339 /* If FROM is a SUBREG that indicates that we have already done at least
1340 the required extension, strip it. */
1342 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
1343 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
1344 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
1345 x = gen_lowpart (mode, x);
1347 if (GET_MODE (x) != VOIDmode)
1348 oldmode = GET_MODE (x);
1350 if (mode == oldmode)
1351 return x;
1353 /* There is one case that we must handle specially: If we are converting
1354 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
1355 we are to interpret the constant as unsigned, gen_lowpart will do
1356 the wrong if the constant appears negative. What we want to do is
1357 make the high-order word of the constant zero, not all ones. */
1359 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
1360 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
1361 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
1362 return immed_double_const (INTVAL (x), (HOST_WIDE_INT) 0, mode);
1364 /* We can do this with a gen_lowpart if both desired and current modes
1365 are integer, and this is either a constant integer, a register, or a
1366 non-volatile MEM. Except for the constant case where MODE is no
1367 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
1369 if ((GET_CODE (x) == CONST_INT
1370 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1371 || (GET_MODE_CLASS (mode) == MODE_INT
1372 && GET_MODE_CLASS (oldmode) == MODE_INT
1373 && (GET_CODE (x) == CONST_DOUBLE
1374 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
1375 && ((GET_CODE (x) == MEM && ! MEM_VOLATILE_P (x)
1376 && direct_load[(int) mode])
1377 || (GET_CODE (x) == REG
1378 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
1379 GET_MODE_BITSIZE (GET_MODE (x)))))))))
1381 /* ?? If we don't know OLDMODE, we have to assume here that
1382 X does not need sign- or zero-extension. This may not be
1383 the case, but it's the best we can do. */
1384 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
1385 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
1387 HOST_WIDE_INT val = INTVAL (x);
1388 int width = GET_MODE_BITSIZE (oldmode);
1390 /* We must sign or zero-extend in this case. Start by
1391 zero-extending, then sign extend if we need to. */
1392 val &= ((HOST_WIDE_INT) 1 << width) - 1;
1393 if (! unsignedp
1394 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
1395 val |= (HOST_WIDE_INT) (-1) << width;
1397 return GEN_INT (val);
1400 return gen_lowpart (mode, x);
1403 temp = gen_reg_rtx (mode);
1404 convert_move (temp, x, unsignedp);
1405 return temp;
1408 /* Generate several move instructions to copy LEN bytes
1409 from block FROM to block TO. (These are MEM rtx's with BLKmode).
1410 The caller must pass FROM and TO
1411 through protect_from_queue before calling.
1412 ALIGN (in bytes) is maximum alignment we can assume. */
1414 static void
1415 move_by_pieces (to, from, len, align)
1416 rtx to, from;
1417 int len, align;
1419 struct move_by_pieces data;
1420 rtx to_addr = XEXP (to, 0), from_addr = XEXP (from, 0);
1421 int max_size = MOVE_MAX + 1;
1423 data.offset = 0;
1424 data.to_addr = to_addr;
1425 data.from_addr = from_addr;
1426 data.to = to;
1427 data.from = from;
1428 data.autinc_to
1429 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
1430 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
1431 data.autinc_from
1432 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
1433 || GET_CODE (from_addr) == POST_INC
1434 || GET_CODE (from_addr) == POST_DEC);
1436 data.explicit_inc_from = 0;
1437 data.explicit_inc_to = 0;
1438 data.reverse
1439 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1440 if (data.reverse) data.offset = len;
1441 data.len = len;
1443 data.to_struct = MEM_IN_STRUCT_P (to);
1444 data.from_struct = MEM_IN_STRUCT_P (from);
1446 /* If copying requires more than two move insns,
1447 copy addresses to registers (to make displacements shorter)
1448 and use post-increment if available. */
1449 if (!(data.autinc_from && data.autinc_to)
1450 && move_by_pieces_ninsns (len, align) > 2)
1452 #ifdef HAVE_PRE_DECREMENT
1453 if (data.reverse && ! data.autinc_from)
1455 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
1456 data.autinc_from = 1;
1457 data.explicit_inc_from = -1;
1459 #endif
1460 #ifdef HAVE_POST_INCREMENT
1461 if (! data.autinc_from)
1463 data.from_addr = copy_addr_to_reg (from_addr);
1464 data.autinc_from = 1;
1465 data.explicit_inc_from = 1;
1467 #endif
1468 if (!data.autinc_from && CONSTANT_P (from_addr))
1469 data.from_addr = copy_addr_to_reg (from_addr);
1470 #ifdef HAVE_PRE_DECREMENT
1471 if (data.reverse && ! data.autinc_to)
1473 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1474 data.autinc_to = 1;
1475 data.explicit_inc_to = -1;
1477 #endif
1478 #ifdef HAVE_POST_INCREMENT
1479 if (! data.reverse && ! data.autinc_to)
1481 data.to_addr = copy_addr_to_reg (to_addr);
1482 data.autinc_to = 1;
1483 data.explicit_inc_to = 1;
1485 #endif
1486 if (!data.autinc_to && CONSTANT_P (to_addr))
1487 data.to_addr = copy_addr_to_reg (to_addr);
1490 if (! SLOW_UNALIGNED_ACCESS
1491 || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1492 align = MOVE_MAX;
1494 /* First move what we can in the largest integer mode, then go to
1495 successively smaller modes. */
1497 while (max_size > 1)
1499 enum machine_mode mode = VOIDmode, tmode;
1500 enum insn_code icode;
1502 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1503 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1504 if (GET_MODE_SIZE (tmode) < max_size)
1505 mode = tmode;
1507 if (mode == VOIDmode)
1508 break;
1510 icode = mov_optab->handlers[(int) mode].insn_code;
1511 if (icode != CODE_FOR_nothing
1512 && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
1513 GET_MODE_SIZE (mode)))
1514 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
1516 max_size = GET_MODE_SIZE (mode);
1519 /* The code above should have handled everything. */
1520 if (data.len != 0)
1521 abort ();
1524 /* Return number of insns required to move L bytes by pieces.
1525 ALIGN (in bytes) is maximum alignment we can assume. */
1527 static int
1528 move_by_pieces_ninsns (l, align)
1529 unsigned int l;
1530 int align;
1532 register int n_insns = 0;
1533 int max_size = MOVE_MAX + 1;
1535 if (! SLOW_UNALIGNED_ACCESS
1536 || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1537 align = MOVE_MAX;
1539 while (max_size > 1)
1541 enum machine_mode mode = VOIDmode, tmode;
1542 enum insn_code icode;
1544 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1545 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1546 if (GET_MODE_SIZE (tmode) < max_size)
1547 mode = tmode;
1549 if (mode == VOIDmode)
1550 break;
1552 icode = mov_optab->handlers[(int) mode].insn_code;
1553 if (icode != CODE_FOR_nothing
1554 && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
1555 GET_MODE_SIZE (mode)))
1556 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1558 max_size = GET_MODE_SIZE (mode);
1561 return n_insns;
1564 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1565 with move instructions for mode MODE. GENFUN is the gen_... function
1566 to make a move insn for that mode. DATA has all the other info. */
1568 static void
1569 move_by_pieces_1 (genfun, mode, data)
1570 rtx (*genfun) ();
1571 enum machine_mode mode;
1572 struct move_by_pieces *data;
1574 register int size = GET_MODE_SIZE (mode);
1575 register rtx to1, from1;
1577 while (data->len >= size)
1579 if (data->reverse) data->offset -= size;
1581 to1 = (data->autinc_to
1582 ? gen_rtx (MEM, mode, data->to_addr)
1583 : change_address (data->to, mode,
1584 plus_constant (data->to_addr, data->offset)));
1585 MEM_IN_STRUCT_P (to1) = data->to_struct;
1586 from1 =
1587 (data->autinc_from
1588 ? gen_rtx (MEM, mode, data->from_addr)
1589 : change_address (data->from, mode,
1590 plus_constant (data->from_addr, data->offset)));
1591 MEM_IN_STRUCT_P (from1) = data->from_struct;
1593 #ifdef HAVE_PRE_DECREMENT
1594 if (data->explicit_inc_to < 0)
1595 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (-size)));
1596 if (data->explicit_inc_from < 0)
1597 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (-size)));
1598 #endif
1600 emit_insn ((*genfun) (to1, from1));
1601 #ifdef HAVE_POST_INCREMENT
1602 if (data->explicit_inc_to > 0)
1603 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1604 if (data->explicit_inc_from > 0)
1605 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1606 #endif
1608 if (! data->reverse) data->offset += size;
1610 data->len -= size;
1614 /* Emit code to move a block Y to a block X.
1615 This may be done with string-move instructions,
1616 with multiple scalar move instructions, or with a library call.
1618 Both X and Y must be MEM rtx's (perhaps inside VOLATILE)
1619 with mode BLKmode.
1620 SIZE is an rtx that says how long they are.
1621 ALIGN is the maximum alignment we can assume they have,
1622 measured in bytes. */
1624 void
1625 emit_block_move (x, y, size, align)
1626 rtx x, y;
1627 rtx size;
1628 int align;
1630 if (GET_MODE (x) != BLKmode)
1631 abort ();
1633 if (GET_MODE (y) != BLKmode)
1634 abort ();
1636 x = protect_from_queue (x, 1);
1637 y = protect_from_queue (y, 0);
1638 size = protect_from_queue (size, 0);
1640 if (GET_CODE (x) != MEM)
1641 abort ();
1642 if (GET_CODE (y) != MEM)
1643 abort ();
1644 if (size == 0)
1645 abort ();
1647 if (GET_CODE (size) == CONST_INT
1648 && (move_by_pieces_ninsns (INTVAL (size), align) < MOVE_RATIO))
1649 move_by_pieces (x, y, INTVAL (size), align);
1650 else
1652 /* Try the most limited insn first, because there's no point
1653 including more than one in the machine description unless
1654 the more limited one has some advantage. */
1656 rtx opalign = GEN_INT (align);
1657 enum machine_mode mode;
1659 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1660 mode = GET_MODE_WIDER_MODE (mode))
1662 enum insn_code code = movstr_optab[(int) mode];
1664 if (code != CODE_FOR_nothing
1665 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1666 here because if SIZE is less than the mode mask, as it is
1667 returned by the macro, it will definitely be less than the
1668 actual mode mask. */
1669 && ((GET_CODE (size) == CONST_INT
1670 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1671 <= GET_MODE_MASK (mode)))
1672 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1673 && (insn_operand_predicate[(int) code][0] == 0
1674 || (*insn_operand_predicate[(int) code][0]) (x, BLKmode))
1675 && (insn_operand_predicate[(int) code][1] == 0
1676 || (*insn_operand_predicate[(int) code][1]) (y, BLKmode))
1677 && (insn_operand_predicate[(int) code][3] == 0
1678 || (*insn_operand_predicate[(int) code][3]) (opalign,
1679 VOIDmode)))
1681 rtx op2;
1682 rtx last = get_last_insn ();
1683 rtx pat;
1685 op2 = convert_to_mode (mode, size, 1);
1686 if (insn_operand_predicate[(int) code][2] != 0
1687 && ! (*insn_operand_predicate[(int) code][2]) (op2, mode))
1688 op2 = copy_to_mode_reg (mode, op2);
1690 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1691 if (pat)
1693 emit_insn (pat);
1694 return;
1696 else
1697 delete_insns_since (last);
1701 #ifdef TARGET_MEM_FUNCTIONS
1702 emit_library_call (memcpy_libfunc, 0,
1703 VOIDmode, 3, XEXP (x, 0), Pmode,
1704 XEXP (y, 0), Pmode,
1705 convert_to_mode (TYPE_MODE (sizetype), size,
1706 TREE_UNSIGNED (sizetype)),
1707 TYPE_MODE (sizetype));
1708 #else
1709 emit_library_call (bcopy_libfunc, 0,
1710 VOIDmode, 3, XEXP (y, 0), Pmode,
1711 XEXP (x, 0), Pmode,
1712 convert_to_mode (TYPE_MODE (integer_type_node), size,
1713 TREE_UNSIGNED (integer_type_node)),
1714 TYPE_MODE (integer_type_node));
1715 #endif
1719 /* Copy all or part of a value X into registers starting at REGNO.
1720 The number of registers to be filled is NREGS. */
1722 void
1723 move_block_to_reg (regno, x, nregs, mode)
1724 int regno;
1725 rtx x;
1726 int nregs;
1727 enum machine_mode mode;
1729 int i;
1730 rtx pat, last;
1732 if (nregs == 0)
1733 return;
1735 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1736 x = validize_mem (force_const_mem (mode, x));
1738 /* See if the machine can do this with a load multiple insn. */
1739 #ifdef HAVE_load_multiple
1740 if (HAVE_load_multiple)
1742 last = get_last_insn ();
1743 pat = gen_load_multiple (gen_rtx (REG, word_mode, regno), x,
1744 GEN_INT (nregs));
1745 if (pat)
1747 emit_insn (pat);
1748 return;
1750 else
1751 delete_insns_since (last);
1753 #endif
1755 for (i = 0; i < nregs; i++)
1756 emit_move_insn (gen_rtx (REG, word_mode, regno + i),
1757 operand_subword_force (x, i, mode));
1760 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1761 The number of registers to be filled is NREGS. SIZE indicates the number
1762 of bytes in the object X. */
1765 void
1766 move_block_from_reg (regno, x, nregs, size)
1767 int regno;
1768 rtx x;
1769 int nregs;
1770 int size;
1772 int i;
1773 rtx pat, last;
1775 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN machine must be aligned
1776 to the left before storing to memory. */
1777 if (size < UNITS_PER_WORD && BYTES_BIG_ENDIAN)
1779 rtx tem = operand_subword (x, 0, 1, BLKmode);
1780 rtx shift;
1782 if (tem == 0)
1783 abort ();
1785 shift = expand_shift (LSHIFT_EXPR, word_mode,
1786 gen_rtx (REG, word_mode, regno),
1787 build_int_2 ((UNITS_PER_WORD - size)
1788 * BITS_PER_UNIT, 0), NULL_RTX, 0);
1789 emit_move_insn (tem, shift);
1790 return;
1793 /* See if the machine can do this with a store multiple insn. */
1794 #ifdef HAVE_store_multiple
1795 if (HAVE_store_multiple)
1797 last = get_last_insn ();
1798 pat = gen_store_multiple (x, gen_rtx (REG, word_mode, regno),
1799 GEN_INT (nregs));
1800 if (pat)
1802 emit_insn (pat);
1803 return;
1805 else
1806 delete_insns_since (last);
1808 #endif
1810 for (i = 0; i < nregs; i++)
1812 rtx tem = operand_subword (x, i, 1, BLKmode);
1814 if (tem == 0)
1815 abort ();
1817 emit_move_insn (tem, gen_rtx (REG, word_mode, regno + i));
1821 /* Add a USE expression for REG to the (possibly empty) list pointed
1822 to by CALL_FUSAGE. REG must denote a hard register. */
1824 void
1825 use_reg (call_fusage, reg)
1826 rtx *call_fusage, reg;
1828 if (GET_CODE (reg) != REG
1829 || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
1830 abort();
1832 *call_fusage
1833 = gen_rtx (EXPR_LIST, VOIDmode,
1834 gen_rtx (USE, VOIDmode, reg), *call_fusage);
1837 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
1838 starting at REGNO. All of these registers must be hard registers. */
1840 void
1841 use_regs (call_fusage, regno, nregs)
1842 rtx *call_fusage;
1843 int regno;
1844 int nregs;
1846 int i;
1848 if (regno + nregs > FIRST_PSEUDO_REGISTER)
1849 abort ();
1851 for (i = 0; i < nregs; i++)
1852 use_reg (call_fusage, gen_rtx (REG, reg_raw_mode[regno + i], regno + i));
1855 /* Generate several move instructions to clear LEN bytes of block TO.
1856 (A MEM rtx with BLKmode). The caller must pass TO through
1857 protect_from_queue before calling. ALIGN (in bytes) is maximum alignment
1858 we can assume. */
1860 static void
1861 clear_by_pieces (to, len, align)
1862 rtx to;
1863 int len, align;
1865 struct clear_by_pieces data;
1866 rtx to_addr = XEXP (to, 0);
1867 int max_size = MOVE_MAX + 1;
1869 data.offset = 0;
1870 data.to_addr = to_addr;
1871 data.to = to;
1872 data.autinc_to
1873 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
1874 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
1876 data.explicit_inc_to = 0;
1877 data.reverse
1878 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1879 if (data.reverse) data.offset = len;
1880 data.len = len;
1882 data.to_struct = MEM_IN_STRUCT_P (to);
1884 /* If copying requires more than two move insns,
1885 copy addresses to registers (to make displacements shorter)
1886 and use post-increment if available. */
1887 if (!data.autinc_to
1888 && move_by_pieces_ninsns (len, align) > 2)
1890 #ifdef HAVE_PRE_DECREMENT
1891 if (data.reverse && ! data.autinc_to)
1893 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1894 data.autinc_to = 1;
1895 data.explicit_inc_to = -1;
1897 #endif
1898 #ifdef HAVE_POST_INCREMENT
1899 if (! data.reverse && ! data.autinc_to)
1901 data.to_addr = copy_addr_to_reg (to_addr);
1902 data.autinc_to = 1;
1903 data.explicit_inc_to = 1;
1905 #endif
1906 if (!data.autinc_to && CONSTANT_P (to_addr))
1907 data.to_addr = copy_addr_to_reg (to_addr);
1910 if (! SLOW_UNALIGNED_ACCESS
1911 || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1912 align = MOVE_MAX;
1914 /* First move what we can in the largest integer mode, then go to
1915 successively smaller modes. */
1917 while (max_size > 1)
1919 enum machine_mode mode = VOIDmode, tmode;
1920 enum insn_code icode;
1922 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1923 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1924 if (GET_MODE_SIZE (tmode) < max_size)
1925 mode = tmode;
1927 if (mode == VOIDmode)
1928 break;
1930 icode = mov_optab->handlers[(int) mode].insn_code;
1931 if (icode != CODE_FOR_nothing
1932 && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
1933 GET_MODE_SIZE (mode)))
1934 clear_by_pieces_1 (GEN_FCN (icode), mode, &data);
1936 max_size = GET_MODE_SIZE (mode);
1939 /* The code above should have handled everything. */
1940 if (data.len != 0)
1941 abort ();
1944 /* Subroutine of clear_by_pieces. Clear as many bytes as appropriate
1945 with move instructions for mode MODE. GENFUN is the gen_... function
1946 to make a move insn for that mode. DATA has all the other info. */
1948 static void
1949 clear_by_pieces_1 (genfun, mode, data)
1950 rtx (*genfun) ();
1951 enum machine_mode mode;
1952 struct clear_by_pieces *data;
1954 register int size = GET_MODE_SIZE (mode);
1955 register rtx to1;
1957 while (data->len >= size)
1959 if (data->reverse) data->offset -= size;
1961 to1 = (data->autinc_to
1962 ? gen_rtx (MEM, mode, data->to_addr)
1963 : change_address (data->to, mode,
1964 plus_constant (data->to_addr, data->offset)));
1965 MEM_IN_STRUCT_P (to1) = data->to_struct;
1967 #ifdef HAVE_PRE_DECREMENT
1968 if (data->explicit_inc_to < 0)
1969 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (-size)));
1970 #endif
1972 emit_insn ((*genfun) (to1, const0_rtx));
1973 #ifdef HAVE_POST_INCREMENT
1974 if (data->explicit_inc_to > 0)
1975 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1976 #endif
1978 if (! data->reverse) data->offset += size;
1980 data->len -= size;
1984 /* Write zeros through the storage of OBJECT.
1985 If OBJECT has BLKmode, SIZE is its length in bytes and ALIGN is
1986 the maximum alignment we can is has, measured in bytes. */
1988 void
1989 clear_storage (object, size, align)
1990 rtx object;
1991 rtx size;
1992 int align;
1994 if (GET_MODE (object) == BLKmode)
1996 object = protect_from_queue (object, 1);
1997 size = protect_from_queue (size, 0);
1999 if (GET_CODE (size) == CONST_INT
2000 && (move_by_pieces_ninsns (INTVAL (size), align) < MOVE_RATIO))
2001 clear_by_pieces (object, INTVAL (size), align);
2003 else
2005 /* Try the most limited insn first, because there's no point
2006 including more than one in the machine description unless
2007 the more limited one has some advantage. */
2009 rtx opalign = GEN_INT (align);
2010 enum machine_mode mode;
2012 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2013 mode = GET_MODE_WIDER_MODE (mode))
2015 enum insn_code code = clrstr_optab[(int) mode];
2017 if (code != CODE_FOR_nothing
2018 /* We don't need MODE to be narrower than
2019 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2020 the mode mask, as it is returned by the macro, it will
2021 definitely be less than the actual mode mask. */
2022 && ((GET_CODE (size) == CONST_INT
2023 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2024 <= GET_MODE_MASK (mode)))
2025 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2026 && (insn_operand_predicate[(int) code][0] == 0
2027 || (*insn_operand_predicate[(int) code][0]) (object,
2028 BLKmode))
2029 && (insn_operand_predicate[(int) code][2] == 0
2030 || (*insn_operand_predicate[(int) code][2]) (opalign,
2031 VOIDmode)))
2033 rtx op1;
2034 rtx last = get_last_insn ();
2035 rtx pat;
2037 op1 = convert_to_mode (mode, size, 1);
2038 if (insn_operand_predicate[(int) code][1] != 0
2039 && ! (*insn_operand_predicate[(int) code][1]) (op1,
2040 mode))
2041 op1 = copy_to_mode_reg (mode, op1);
2043 pat = GEN_FCN ((int) code) (object, op1, opalign);
2044 if (pat)
2046 emit_insn (pat);
2047 return;
2049 else
2050 delete_insns_since (last);
2055 #ifdef TARGET_MEM_FUNCTIONS
2056 emit_library_call (memset_libfunc, 0,
2057 VOIDmode, 3,
2058 XEXP (object, 0), Pmode,
2059 const0_rtx, TYPE_MODE (integer_type_node),
2060 convert_to_mode (TYPE_MODE (sizetype),
2061 size, TREE_UNSIGNED (sizetype)),
2062 TYPE_MODE (sizetype));
2063 #else
2064 emit_library_call (bzero_libfunc, 0,
2065 VOIDmode, 2,
2066 XEXP (object, 0), Pmode,
2067 convert_to_mode (TYPE_MODE (integer_type_node),
2068 size,
2069 TREE_UNSIGNED (integer_type_node)),
2070 TYPE_MODE (integer_type_node));
2071 #endif
2074 else
2075 emit_move_insn (object, const0_rtx);
2078 /* Generate code to copy Y into X.
2079 Both Y and X must have the same mode, except that
2080 Y can be a constant with VOIDmode.
2081 This mode cannot be BLKmode; use emit_block_move for that.
2083 Return the last instruction emitted. */
2086 emit_move_insn (x, y)
2087 rtx x, y;
2089 enum machine_mode mode = GET_MODE (x);
2091 x = protect_from_queue (x, 1);
2092 y = protect_from_queue (y, 0);
2094 if (mode == BLKmode || (GET_MODE (y) != mode && GET_MODE (y) != VOIDmode))
2095 abort ();
2097 if (CONSTANT_P (y) && ! LEGITIMATE_CONSTANT_P (y))
2098 y = force_const_mem (mode, y);
2100 /* If X or Y are memory references, verify that their addresses are valid
2101 for the machine. */
2102 if (GET_CODE (x) == MEM
2103 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
2104 && ! push_operand (x, GET_MODE (x)))
2105 || (flag_force_addr
2106 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
2107 x = change_address (x, VOIDmode, XEXP (x, 0));
2109 if (GET_CODE (y) == MEM
2110 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
2111 || (flag_force_addr
2112 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
2113 y = change_address (y, VOIDmode, XEXP (y, 0));
2115 if (mode == BLKmode)
2116 abort ();
2118 return emit_move_insn_1 (x, y);
2121 /* Low level part of emit_move_insn.
2122 Called just like emit_move_insn, but assumes X and Y
2123 are basically valid. */
2126 emit_move_insn_1 (x, y)
2127 rtx x, y;
2129 enum machine_mode mode = GET_MODE (x);
2130 enum machine_mode submode;
2131 enum mode_class class = GET_MODE_CLASS (mode);
2132 int i;
2134 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2135 return
2136 emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
2138 /* Expand complex moves by moving real part and imag part, if possible. */
2139 else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
2140 && BLKmode != (submode = mode_for_size ((GET_MODE_UNIT_SIZE (mode)
2141 * BITS_PER_UNIT),
2142 (class == MODE_COMPLEX_INT
2143 ? MODE_INT : MODE_FLOAT),
2145 && (mov_optab->handlers[(int) submode].insn_code
2146 != CODE_FOR_nothing))
2148 /* Don't split destination if it is a stack push. */
2149 int stack = push_operand (x, GET_MODE (x));
2150 rtx insns;
2152 /* If this is a stack, push the highpart first, so it
2153 will be in the argument order.
2155 In that case, change_address is used only to convert
2156 the mode, not to change the address. */
2157 if (stack)
2159 /* Note that the real part always precedes the imag part in memory
2160 regardless of machine's endianness. */
2161 #ifdef STACK_GROWS_DOWNWARD
2162 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2163 (gen_rtx (MEM, submode, (XEXP (x, 0))),
2164 gen_imagpart (submode, y)));
2165 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2166 (gen_rtx (MEM, submode, (XEXP (x, 0))),
2167 gen_realpart (submode, y)));
2168 #else
2169 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2170 (gen_rtx (MEM, submode, (XEXP (x, 0))),
2171 gen_realpart (submode, y)));
2172 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2173 (gen_rtx (MEM, submode, (XEXP (x, 0))),
2174 gen_imagpart (submode, y)));
2175 #endif
2177 else
2179 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2180 (gen_realpart (submode, x), gen_realpart (submode, y)));
2181 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2182 (gen_imagpart (submode, x), gen_imagpart (submode, y)));
2185 return get_last_insn ();
2188 /* This will handle any multi-word mode that lacks a move_insn pattern.
2189 However, you will get better code if you define such patterns,
2190 even if they must turn into multiple assembler instructions. */
2191 else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
2193 rtx last_insn = 0;
2194 rtx insns;
2196 #ifdef PUSH_ROUNDING
2198 /* If X is a push on the stack, do the push now and replace
2199 X with a reference to the stack pointer. */
2200 if (push_operand (x, GET_MODE (x)))
2202 anti_adjust_stack (GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
2203 x = change_address (x, VOIDmode, stack_pointer_rtx);
2205 #endif
2207 /* Show the output dies here. */
2208 if (x != y)
2209 emit_insn (gen_rtx (CLOBBER, VOIDmode, x));
2211 for (i = 0;
2212 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2213 i++)
2215 rtx xpart = operand_subword (x, i, 1, mode);
2216 rtx ypart = operand_subword (y, i, 1, mode);
2218 /* If we can't get a part of Y, put Y into memory if it is a
2219 constant. Otherwise, force it into a register. If we still
2220 can't get a part of Y, abort. */
2221 if (ypart == 0 && CONSTANT_P (y))
2223 y = force_const_mem (mode, y);
2224 ypart = operand_subword (y, i, 1, mode);
2226 else if (ypart == 0)
2227 ypart = operand_subword_force (y, i, mode);
2229 if (xpart == 0 || ypart == 0)
2230 abort ();
2232 last_insn = emit_move_insn (xpart, ypart);
2235 return last_insn;
2237 else
2238 abort ();
2241 /* Pushing data onto the stack. */
2243 /* Push a block of length SIZE (perhaps variable)
2244 and return an rtx to address the beginning of the block.
2245 Note that it is not possible for the value returned to be a QUEUED.
2246 The value may be virtual_outgoing_args_rtx.
2248 EXTRA is the number of bytes of padding to push in addition to SIZE.
2249 BELOW nonzero means this padding comes at low addresses;
2250 otherwise, the padding comes at high addresses. */
2253 push_block (size, extra, below)
2254 rtx size;
2255 int extra, below;
2257 register rtx temp;
2259 size = convert_modes (Pmode, ptr_mode, size, 1);
2260 if (CONSTANT_P (size))
2261 anti_adjust_stack (plus_constant (size, extra));
2262 else if (GET_CODE (size) == REG && extra == 0)
2263 anti_adjust_stack (size);
2264 else
2266 rtx temp = copy_to_mode_reg (Pmode, size);
2267 if (extra != 0)
2268 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
2269 temp, 0, OPTAB_LIB_WIDEN);
2270 anti_adjust_stack (temp);
2273 #ifdef STACK_GROWS_DOWNWARD
2274 temp = virtual_outgoing_args_rtx;
2275 if (extra != 0 && below)
2276 temp = plus_constant (temp, extra);
2277 #else
2278 if (GET_CODE (size) == CONST_INT)
2279 temp = plus_constant (virtual_outgoing_args_rtx,
2280 - INTVAL (size) - (below ? 0 : extra));
2281 else if (extra != 0 && !below)
2282 temp = gen_rtx (PLUS, Pmode, virtual_outgoing_args_rtx,
2283 negate_rtx (Pmode, plus_constant (size, extra)));
2284 else
2285 temp = gen_rtx (PLUS, Pmode, virtual_outgoing_args_rtx,
2286 negate_rtx (Pmode, size));
2287 #endif
2289 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
2293 gen_push_operand ()
2295 return gen_rtx (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
2298 /* Generate code to push X onto the stack, assuming it has mode MODE and
2299 type TYPE.
2300 MODE is redundant except when X is a CONST_INT (since they don't
2301 carry mode info).
2302 SIZE is an rtx for the size of data to be copied (in bytes),
2303 needed only if X is BLKmode.
2305 ALIGN (in bytes) is maximum alignment we can assume.
2307 If PARTIAL and REG are both nonzero, then copy that many of the first
2308 words of X into registers starting with REG, and push the rest of X.
2309 The amount of space pushed is decreased by PARTIAL words,
2310 rounded *down* to a multiple of PARM_BOUNDARY.
2311 REG must be a hard register in this case.
2312 If REG is zero but PARTIAL is not, take any all others actions for an
2313 argument partially in registers, but do not actually load any
2314 registers.
2316 EXTRA is the amount in bytes of extra space to leave next to this arg.
2317 This is ignored if an argument block has already been allocated.
2319 On a machine that lacks real push insns, ARGS_ADDR is the address of
2320 the bottom of the argument block for this call. We use indexing off there
2321 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
2322 argument block has not been preallocated.
2324 ARGS_SO_FAR is the size of args previously pushed for this call. */
2326 void
2327 emit_push_insn (x, mode, type, size, align, partial, reg, extra,
2328 args_addr, args_so_far)
2329 register rtx x;
2330 enum machine_mode mode;
2331 tree type;
2332 rtx size;
2333 int align;
2334 int partial;
2335 rtx reg;
2336 int extra;
2337 rtx args_addr;
2338 rtx args_so_far;
2340 rtx xinner;
2341 enum direction stack_direction
2342 #ifdef STACK_GROWS_DOWNWARD
2343 = downward;
2344 #else
2345 = upward;
2346 #endif
2348 /* Decide where to pad the argument: `downward' for below,
2349 `upward' for above, or `none' for don't pad it.
2350 Default is below for small data on big-endian machines; else above. */
2351 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
2353 /* Invert direction if stack is post-update. */
2354 if (STACK_PUSH_CODE == POST_INC || STACK_PUSH_CODE == POST_DEC)
2355 if (where_pad != none)
2356 where_pad = (where_pad == downward ? upward : downward);
2358 xinner = x = protect_from_queue (x, 0);
2360 if (mode == BLKmode)
2362 /* Copy a block into the stack, entirely or partially. */
2364 register rtx temp;
2365 int used = partial * UNITS_PER_WORD;
2366 int offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
2367 int skip;
2369 if (size == 0)
2370 abort ();
2372 used -= offset;
2374 /* USED is now the # of bytes we need not copy to the stack
2375 because registers will take care of them. */
2377 if (partial != 0)
2378 xinner = change_address (xinner, BLKmode,
2379 plus_constant (XEXP (xinner, 0), used));
2381 /* If the partial register-part of the arg counts in its stack size,
2382 skip the part of stack space corresponding to the registers.
2383 Otherwise, start copying to the beginning of the stack space,
2384 by setting SKIP to 0. */
2385 #ifndef REG_PARM_STACK_SPACE
2386 skip = 0;
2387 #else
2388 skip = used;
2389 #endif
2391 #ifdef PUSH_ROUNDING
2392 /* Do it with several push insns if that doesn't take lots of insns
2393 and if there is no difficulty with push insns that skip bytes
2394 on the stack for alignment purposes. */
2395 if (args_addr == 0
2396 && GET_CODE (size) == CONST_INT
2397 && skip == 0
2398 && (move_by_pieces_ninsns ((unsigned) INTVAL (size) - used, align)
2399 < MOVE_RATIO)
2400 /* Here we avoid the case of a structure whose weak alignment
2401 forces many pushes of a small amount of data,
2402 and such small pushes do rounding that causes trouble. */
2403 && ((! SLOW_UNALIGNED_ACCESS)
2404 || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT
2405 || PUSH_ROUNDING (align) == align)
2406 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
2408 /* Push padding now if padding above and stack grows down,
2409 or if padding below and stack grows up.
2410 But if space already allocated, this has already been done. */
2411 if (extra && args_addr == 0
2412 && where_pad != none && where_pad != stack_direction)
2413 anti_adjust_stack (GEN_INT (extra));
2415 move_by_pieces (gen_rtx (MEM, BLKmode, gen_push_operand ()), xinner,
2416 INTVAL (size) - used, align);
2418 else
2419 #endif /* PUSH_ROUNDING */
2421 /* Otherwise make space on the stack and copy the data
2422 to the address of that space. */
2424 /* Deduct words put into registers from the size we must copy. */
2425 if (partial != 0)
2427 if (GET_CODE (size) == CONST_INT)
2428 size = GEN_INT (INTVAL (size) - used);
2429 else
2430 size = expand_binop (GET_MODE (size), sub_optab, size,
2431 GEN_INT (used), NULL_RTX, 0,
2432 OPTAB_LIB_WIDEN);
2435 /* Get the address of the stack space.
2436 In this case, we do not deal with EXTRA separately.
2437 A single stack adjust will do. */
2438 if (! args_addr)
2440 temp = push_block (size, extra, where_pad == downward);
2441 extra = 0;
2443 else if (GET_CODE (args_so_far) == CONST_INT)
2444 temp = memory_address (BLKmode,
2445 plus_constant (args_addr,
2446 skip + INTVAL (args_so_far)));
2447 else
2448 temp = memory_address (BLKmode,
2449 plus_constant (gen_rtx (PLUS, Pmode,
2450 args_addr, args_so_far),
2451 skip));
2453 /* TEMP is the address of the block. Copy the data there. */
2454 if (GET_CODE (size) == CONST_INT
2455 && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
2456 < MOVE_RATIO))
2458 move_by_pieces (gen_rtx (MEM, BLKmode, temp), xinner,
2459 INTVAL (size), align);
2460 goto ret;
2462 /* Try the most limited insn first, because there's no point
2463 including more than one in the machine description unless
2464 the more limited one has some advantage. */
2465 #ifdef HAVE_movstrqi
2466 if (HAVE_movstrqi
2467 && GET_CODE (size) == CONST_INT
2468 && ((unsigned) INTVAL (size)
2469 < (1 << (GET_MODE_BITSIZE (QImode) - 1))))
2471 rtx pat = gen_movstrqi (gen_rtx (MEM, BLKmode, temp),
2472 xinner, size, GEN_INT (align));
2473 if (pat != 0)
2475 emit_insn (pat);
2476 goto ret;
2479 #endif
2480 #ifdef HAVE_movstrhi
2481 if (HAVE_movstrhi
2482 && GET_CODE (size) == CONST_INT
2483 && ((unsigned) INTVAL (size)
2484 < (1 << (GET_MODE_BITSIZE (HImode) - 1))))
2486 rtx pat = gen_movstrhi (gen_rtx (MEM, BLKmode, temp),
2487 xinner, size, GEN_INT (align));
2488 if (pat != 0)
2490 emit_insn (pat);
2491 goto ret;
2494 #endif
2495 #ifdef HAVE_movstrsi
2496 if (HAVE_movstrsi)
2498 rtx pat = gen_movstrsi (gen_rtx (MEM, BLKmode, temp),
2499 xinner, size, GEN_INT (align));
2500 if (pat != 0)
2502 emit_insn (pat);
2503 goto ret;
2506 #endif
2507 #ifdef HAVE_movstrdi
2508 if (HAVE_movstrdi)
2510 rtx pat = gen_movstrdi (gen_rtx (MEM, BLKmode, temp),
2511 xinner, size, GEN_INT (align));
2512 if (pat != 0)
2514 emit_insn (pat);
2515 goto ret;
2518 #endif
2520 #ifndef ACCUMULATE_OUTGOING_ARGS
2521 /* If the source is referenced relative to the stack pointer,
2522 copy it to another register to stabilize it. We do not need
2523 to do this if we know that we won't be changing sp. */
2525 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
2526 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
2527 temp = copy_to_reg (temp);
2528 #endif
2530 /* Make inhibit_defer_pop nonzero around the library call
2531 to force it to pop the bcopy-arguments right away. */
2532 NO_DEFER_POP;
2533 #ifdef TARGET_MEM_FUNCTIONS
2534 emit_library_call (memcpy_libfunc, 0,
2535 VOIDmode, 3, temp, Pmode, XEXP (xinner, 0), Pmode,
2536 convert_to_mode (TYPE_MODE (sizetype),
2537 size, TREE_UNSIGNED (sizetype)),
2538 TYPE_MODE (sizetype));
2539 #else
2540 emit_library_call (bcopy_libfunc, 0,
2541 VOIDmode, 3, XEXP (xinner, 0), Pmode, temp, Pmode,
2542 convert_to_mode (TYPE_MODE (integer_type_node),
2543 size,
2544 TREE_UNSIGNED (integer_type_node)),
2545 TYPE_MODE (integer_type_node));
2546 #endif
2547 OK_DEFER_POP;
2550 else if (partial > 0)
2552 /* Scalar partly in registers. */
2554 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
2555 int i;
2556 int not_stack;
2557 /* # words of start of argument
2558 that we must make space for but need not store. */
2559 int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
2560 int args_offset = INTVAL (args_so_far);
2561 int skip;
2563 /* Push padding now if padding above and stack grows down,
2564 or if padding below and stack grows up.
2565 But if space already allocated, this has already been done. */
2566 if (extra && args_addr == 0
2567 && where_pad != none && where_pad != stack_direction)
2568 anti_adjust_stack (GEN_INT (extra));
2570 /* If we make space by pushing it, we might as well push
2571 the real data. Otherwise, we can leave OFFSET nonzero
2572 and leave the space uninitialized. */
2573 if (args_addr == 0)
2574 offset = 0;
2576 /* Now NOT_STACK gets the number of words that we don't need to
2577 allocate on the stack. */
2578 not_stack = partial - offset;
2580 /* If the partial register-part of the arg counts in its stack size,
2581 skip the part of stack space corresponding to the registers.
2582 Otherwise, start copying to the beginning of the stack space,
2583 by setting SKIP to 0. */
2584 #ifndef REG_PARM_STACK_SPACE
2585 skip = 0;
2586 #else
2587 skip = not_stack;
2588 #endif
2590 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
2591 x = validize_mem (force_const_mem (mode, x));
2593 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
2594 SUBREGs of such registers are not allowed. */
2595 if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER
2596 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
2597 x = copy_to_reg (x);
2599 /* Loop over all the words allocated on the stack for this arg. */
2600 /* We can do it by words, because any scalar bigger than a word
2601 has a size a multiple of a word. */
2602 #ifndef PUSH_ARGS_REVERSED
2603 for (i = not_stack; i < size; i++)
2604 #else
2605 for (i = size - 1; i >= not_stack; i--)
2606 #endif
2607 if (i >= not_stack + offset)
2608 emit_push_insn (operand_subword_force (x, i, mode),
2609 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
2610 0, args_addr,
2611 GEN_INT (args_offset + ((i - not_stack + skip)
2612 * UNITS_PER_WORD)));
2614 else
2616 rtx addr;
2618 /* Push padding now if padding above and stack grows down,
2619 or if padding below and stack grows up.
2620 But if space already allocated, this has already been done. */
2621 if (extra && args_addr == 0
2622 && where_pad != none && where_pad != stack_direction)
2623 anti_adjust_stack (GEN_INT (extra));
2625 #ifdef PUSH_ROUNDING
2626 if (args_addr == 0)
2627 addr = gen_push_operand ();
2628 else
2629 #endif
2630 if (GET_CODE (args_so_far) == CONST_INT)
2631 addr
2632 = memory_address (mode,
2633 plus_constant (args_addr, INTVAL (args_so_far)));
2634 else
2635 addr = memory_address (mode, gen_rtx (PLUS, Pmode, args_addr,
2636 args_so_far));
2638 emit_move_insn (gen_rtx (MEM, mode, addr), x);
2641 ret:
2642 /* If part should go in registers, copy that part
2643 into the appropriate registers. Do this now, at the end,
2644 since mem-to-mem copies above may do function calls. */
2645 if (partial > 0 && reg != 0)
2646 move_block_to_reg (REGNO (reg), x, partial, mode);
2648 if (extra && args_addr == 0 && where_pad == stack_direction)
2649 anti_adjust_stack (GEN_INT (extra));
2652 /* Expand an assignment that stores the value of FROM into TO.
2653 If WANT_VALUE is nonzero, return an rtx for the value of TO.
2654 (This may contain a QUEUED rtx;
2655 if the value is constant, this rtx is a constant.)
2656 Otherwise, the returned value is NULL_RTX.
2658 SUGGEST_REG is no longer actually used.
2659 It used to mean, copy the value through a register
2660 and return that register, if that is possible.
2661 We now use WANT_VALUE to decide whether to do this. */
2664 expand_assignment (to, from, want_value, suggest_reg)
2665 tree to, from;
2666 int want_value;
2667 int suggest_reg;
2669 register rtx to_rtx = 0;
2670 rtx result;
2672 /* Don't crash if the lhs of the assignment was erroneous. */
2674 if (TREE_CODE (to) == ERROR_MARK)
2676 result = expand_expr (from, NULL_RTX, VOIDmode, 0);
2677 return want_value ? result : NULL_RTX;
2680 if (output_bytecode)
2682 tree dest_innermost;
2684 bc_expand_expr (from);
2685 bc_emit_instruction (duplicate);
2687 dest_innermost = bc_expand_address (to);
2689 /* Can't deduce from TYPE that we're dealing with a bitfield, so
2690 take care of it here. */
2692 bc_store_memory (TREE_TYPE (to), dest_innermost);
2693 return NULL;
2696 /* Assignment of a structure component needs special treatment
2697 if the structure component's rtx is not simply a MEM.
2698 Assignment of an array element at a constant index, and assignment of
2699 an array element in an unaligned packed structure field, has the same
2700 problem. */
2702 if (TREE_CODE (to) == COMPONENT_REF
2703 || TREE_CODE (to) == BIT_FIELD_REF
2704 || (TREE_CODE (to) == ARRAY_REF
2705 && ((TREE_CODE (TREE_OPERAND (to, 1)) == INTEGER_CST
2706 && TREE_CODE (TYPE_SIZE (TREE_TYPE (to))) == INTEGER_CST)
2707 || (SLOW_UNALIGNED_ACCESS && get_inner_unaligned_p (to)))))
2709 enum machine_mode mode1;
2710 int bitsize;
2711 int bitpos;
2712 tree offset;
2713 int unsignedp;
2714 int volatilep = 0;
2715 tree tem;
2716 int alignment;
2718 push_temp_slots ();
2719 tem = get_inner_reference (to, &bitsize, &bitpos, &offset,
2720 &mode1, &unsignedp, &volatilep);
2722 /* If we are going to use store_bit_field and extract_bit_field,
2723 make sure to_rtx will be safe for multiple use. */
2725 if (mode1 == VOIDmode && want_value)
2726 tem = stabilize_reference (tem);
2728 alignment = TYPE_ALIGN (TREE_TYPE (tem)) / BITS_PER_UNIT;
2729 to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, 0);
2730 if (offset != 0)
2732 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
2734 if (GET_CODE (to_rtx) != MEM)
2735 abort ();
2736 to_rtx = change_address (to_rtx, VOIDmode,
2737 gen_rtx (PLUS, ptr_mode, XEXP (to_rtx, 0),
2738 force_reg (ptr_mode, offset_rtx)));
2739 /* If we have a variable offset, the known alignment
2740 is only that of the innermost structure containing the field.
2741 (Actually, we could sometimes do better by using the
2742 align of an element of the innermost array, but no need.) */
2743 if (TREE_CODE (to) == COMPONENT_REF
2744 || TREE_CODE (to) == BIT_FIELD_REF)
2745 alignment
2746 = TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (to, 0))) / BITS_PER_UNIT;
2748 if (volatilep)
2750 if (GET_CODE (to_rtx) == MEM)
2752 /* When the offset is zero, to_rtx is the address of the
2753 structure we are storing into, and hence may be shared.
2754 We must make a new MEM before setting the volatile bit. */
2755 if (offset == 0)
2756 to_rtx = change_address (to_rtx, VOIDmode, XEXP (to_rtx, 0));
2757 MEM_VOLATILE_P (to_rtx) = 1;
2759 #if 0 /* This was turned off because, when a field is volatile
2760 in an object which is not volatile, the object may be in a register,
2761 and then we would abort over here. */
2762 else
2763 abort ();
2764 #endif
2767 result = store_field (to_rtx, bitsize, bitpos, mode1, from,
2768 (want_value
2769 /* Spurious cast makes HPUX compiler happy. */
2770 ? (enum machine_mode) TYPE_MODE (TREE_TYPE (to))
2771 : VOIDmode),
2772 unsignedp,
2773 /* Required alignment of containing datum. */
2774 alignment,
2775 int_size_in_bytes (TREE_TYPE (tem)));
2776 preserve_temp_slots (result);
2777 free_temp_slots ();
2778 pop_temp_slots ();
2780 /* If the value is meaningful, convert RESULT to the proper mode.
2781 Otherwise, return nothing. */
2782 return (want_value ? convert_modes (TYPE_MODE (TREE_TYPE (to)),
2783 TYPE_MODE (TREE_TYPE (from)),
2784 result,
2785 TREE_UNSIGNED (TREE_TYPE (to)))
2786 : NULL_RTX);
2789 /* If the rhs is a function call and its value is not an aggregate,
2790 call the function before we start to compute the lhs.
2791 This is needed for correct code for cases such as
2792 val = setjmp (buf) on machines where reference to val
2793 requires loading up part of an address in a separate insn.
2795 Don't do this if TO is a VAR_DECL whose DECL_RTL is REG since it might be
2796 a promoted variable where the zero- or sign- extension needs to be done.
2797 Handling this in the normal way is safe because no computation is done
2798 before the call. */
2799 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from)
2800 && ! (TREE_CODE (to) == VAR_DECL && GET_CODE (DECL_RTL (to)) == REG))
2802 rtx value;
2804 push_temp_slots ();
2805 value = expand_expr (from, NULL_RTX, VOIDmode, 0);
2806 if (to_rtx == 0)
2807 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, 0);
2809 if (GET_MODE (to_rtx) == BLKmode)
2810 emit_block_move (to_rtx, value, expr_size (from),
2811 TYPE_ALIGN (TREE_TYPE (from)) / BITS_PER_UNIT);
2812 else
2813 emit_move_insn (to_rtx, value);
2814 preserve_temp_slots (to_rtx);
2815 free_temp_slots ();
2816 pop_temp_slots ();
2817 return want_value ? to_rtx : NULL_RTX;
2820 /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
2821 Don't re-expand if it was expanded already (in COMPONENT_REF case). */
2823 if (to_rtx == 0)
2824 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, 0);
2826 /* Don't move directly into a return register. */
2827 if (TREE_CODE (to) == RESULT_DECL && GET_CODE (to_rtx) == REG)
2829 rtx temp;
2831 push_temp_slots ();
2832 temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
2833 emit_move_insn (to_rtx, temp);
2834 preserve_temp_slots (to_rtx);
2835 free_temp_slots ();
2836 pop_temp_slots ();
2837 return want_value ? to_rtx : NULL_RTX;
2840 /* In case we are returning the contents of an object which overlaps
2841 the place the value is being stored, use a safe function when copying
2842 a value through a pointer into a structure value return block. */
2843 if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
2844 && current_function_returns_struct
2845 && !current_function_returns_pcc_struct)
2847 rtx from_rtx, size;
2849 push_temp_slots ();
2850 size = expr_size (from);
2851 from_rtx = expand_expr (from, NULL_RTX, VOIDmode, 0);
2853 #ifdef TARGET_MEM_FUNCTIONS
2854 emit_library_call (memcpy_libfunc, 0,
2855 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
2856 XEXP (from_rtx, 0), Pmode,
2857 convert_to_mode (TYPE_MODE (sizetype),
2858 size, TREE_UNSIGNED (sizetype)),
2859 TYPE_MODE (sizetype));
2860 #else
2861 emit_library_call (bcopy_libfunc, 0,
2862 VOIDmode, 3, XEXP (from_rtx, 0), Pmode,
2863 XEXP (to_rtx, 0), Pmode,
2864 convert_to_mode (TYPE_MODE (integer_type_node),
2865 size, TREE_UNSIGNED (integer_type_node)),
2866 TYPE_MODE (integer_type_node));
2867 #endif
2869 preserve_temp_slots (to_rtx);
2870 free_temp_slots ();
2871 pop_temp_slots ();
2872 return want_value ? to_rtx : NULL_RTX;
2875 /* Compute FROM and store the value in the rtx we got. */
2877 push_temp_slots ();
2878 result = store_expr (from, to_rtx, want_value);
2879 preserve_temp_slots (result);
2880 free_temp_slots ();
2881 pop_temp_slots ();
2882 return want_value ? result : NULL_RTX;
2885 /* Generate code for computing expression EXP,
2886 and storing the value into TARGET.
2887 TARGET may contain a QUEUED rtx.
2889 If WANT_VALUE is nonzero, return a copy of the value
2890 not in TARGET, so that we can be sure to use the proper
2891 value in a containing expression even if TARGET has something
2892 else stored in it. If possible, we copy the value through a pseudo
2893 and return that pseudo. Or, if the value is constant, we try to
2894 return the constant. In some cases, we return a pseudo
2895 copied *from* TARGET.
2897 If the mode is BLKmode then we may return TARGET itself.
2898 It turns out that in BLKmode it doesn't cause a problem.
2899 because C has no operators that could combine two different
2900 assignments into the same BLKmode object with different values
2901 with no sequence point. Will other languages need this to
2902 be more thorough?
2904 If WANT_VALUE is 0, we return NULL, to make sure
2905 to catch quickly any cases where the caller uses the value
2906 and fails to set WANT_VALUE. */
2909 store_expr (exp, target, want_value)
2910 register tree exp;
2911 register rtx target;
2912 int want_value;
2914 register rtx temp;
2915 int dont_return_target = 0;
2917 if (TREE_CODE (exp) == COMPOUND_EXPR)
2919 /* Perform first part of compound expression, then assign from second
2920 part. */
2921 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
2922 emit_queue ();
2923 return store_expr (TREE_OPERAND (exp, 1), target, want_value);
2925 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
2927 /* For conditional expression, get safe form of the target. Then
2928 test the condition, doing the appropriate assignment on either
2929 side. This avoids the creation of unnecessary temporaries.
2930 For non-BLKmode, it is more efficient not to do this. */
2932 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
2934 emit_queue ();
2935 target = protect_from_queue (target, 1);
2937 do_pending_stack_adjust ();
2938 NO_DEFER_POP;
2939 jumpifnot (TREE_OPERAND (exp, 0), lab1);
2940 store_expr (TREE_OPERAND (exp, 1), target, 0);
2941 emit_queue ();
2942 emit_jump_insn (gen_jump (lab2));
2943 emit_barrier ();
2944 emit_label (lab1);
2945 store_expr (TREE_OPERAND (exp, 2), target, 0);
2946 emit_queue ();
2947 emit_label (lab2);
2948 OK_DEFER_POP;
2949 return want_value ? target : NULL_RTX;
2951 else if (want_value && GET_CODE (target) == MEM && ! MEM_VOLATILE_P (target)
2952 && GET_MODE (target) != BLKmode)
2953 /* If target is in memory and caller wants value in a register instead,
2954 arrange that. Pass TARGET as target for expand_expr so that,
2955 if EXP is another assignment, WANT_VALUE will be nonzero for it.
2956 We know expand_expr will not use the target in that case.
2957 Don't do this if TARGET is volatile because we are supposed
2958 to write it and then read it. */
2960 temp = expand_expr (exp, cse_not_expected ? NULL_RTX : target,
2961 GET_MODE (target), 0);
2962 if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
2963 temp = copy_to_reg (temp);
2964 dont_return_target = 1;
2966 else if (queued_subexp_p (target))
2967 /* If target contains a postincrement, let's not risk
2968 using it as the place to generate the rhs. */
2970 if (GET_MODE (target) != BLKmode && GET_MODE (target) != VOIDmode)
2972 /* Expand EXP into a new pseudo. */
2973 temp = gen_reg_rtx (GET_MODE (target));
2974 temp = expand_expr (exp, temp, GET_MODE (target), 0);
2976 else
2977 temp = expand_expr (exp, NULL_RTX, GET_MODE (target), 0);
2979 /* If target is volatile, ANSI requires accessing the value
2980 *from* the target, if it is accessed. So make that happen.
2981 In no case return the target itself. */
2982 if (! MEM_VOLATILE_P (target) && want_value)
2983 dont_return_target = 1;
2985 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
2986 /* If this is an scalar in a register that is stored in a wider mode
2987 than the declared mode, compute the result into its declared mode
2988 and then convert to the wider mode. Our value is the computed
2989 expression. */
2991 /* If we don't want a value, we can do the conversion inside EXP,
2992 which will often result in some optimizations. Do the conversion
2993 in two steps: first change the signedness, if needed, then
2994 the extend. */
2995 if (! want_value)
2997 if (TREE_UNSIGNED (TREE_TYPE (exp))
2998 != SUBREG_PROMOTED_UNSIGNED_P (target))
3000 = convert
3001 (signed_or_unsigned_type (SUBREG_PROMOTED_UNSIGNED_P (target),
3002 TREE_TYPE (exp)),
3003 exp);
3005 exp = convert (type_for_mode (GET_MODE (SUBREG_REG (target)),
3006 SUBREG_PROMOTED_UNSIGNED_P (target)),
3007 exp);
3010 temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
3012 /* If TEMP is a volatile MEM and we want a result value, make
3013 the access now so it gets done only once. Likewise if
3014 it contains TARGET. */
3015 if (GET_CODE (temp) == MEM && want_value
3016 && (MEM_VOLATILE_P (temp)
3017 || reg_mentioned_p (SUBREG_REG (target), XEXP (temp, 0))))
3018 temp = copy_to_reg (temp);
3020 /* If TEMP is a VOIDmode constant, use convert_modes to make
3021 sure that we properly convert it. */
3022 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
3023 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
3024 TYPE_MODE (TREE_TYPE (exp)), temp,
3025 SUBREG_PROMOTED_UNSIGNED_P (target));
3027 convert_move (SUBREG_REG (target), temp,
3028 SUBREG_PROMOTED_UNSIGNED_P (target));
3029 return want_value ? temp : NULL_RTX;
3031 else
3033 temp = expand_expr (exp, target, GET_MODE (target), 0);
3034 /* Return TARGET if it's a specified hardware register.
3035 If TARGET is a volatile mem ref, either return TARGET
3036 or return a reg copied *from* TARGET; ANSI requires this.
3038 Otherwise, if TEMP is not TARGET, return TEMP
3039 if it is constant (for efficiency),
3040 or if we really want the correct value. */
3041 if (!(target && GET_CODE (target) == REG
3042 && REGNO (target) < FIRST_PSEUDO_REGISTER)
3043 && !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
3044 && temp != target
3045 && (CONSTANT_P (temp) || want_value))
3046 dont_return_target = 1;
3049 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
3050 the same as that of TARGET, adjust the constant. This is needed, for
3051 example, in case it is a CONST_DOUBLE and we want only a word-sized
3052 value. */
3053 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
3054 && TREE_CODE (exp) != ERROR_MARK
3055 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
3056 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
3057 temp, TREE_UNSIGNED (TREE_TYPE (exp)));
3059 /* If value was not generated in the target, store it there.
3060 Convert the value to TARGET's type first if nec. */
3062 if (temp != target && TREE_CODE (exp) != ERROR_MARK)
3064 target = protect_from_queue (target, 1);
3065 if (GET_MODE (temp) != GET_MODE (target)
3066 && GET_MODE (temp) != VOIDmode)
3068 int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
3069 if (dont_return_target)
3071 /* In this case, we will return TEMP,
3072 so make sure it has the proper mode.
3073 But don't forget to store the value into TARGET. */
3074 temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
3075 emit_move_insn (target, temp);
3077 else
3078 convert_move (target, temp, unsignedp);
3081 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
3083 /* Handle copying a string constant into an array.
3084 The string constant may be shorter than the array.
3085 So copy just the string's actual length, and clear the rest. */
3086 rtx size;
3087 rtx addr;
3089 /* Get the size of the data type of the string,
3090 which is actually the size of the target. */
3091 size = expr_size (exp);
3092 if (GET_CODE (size) == CONST_INT
3093 && INTVAL (size) < TREE_STRING_LENGTH (exp))
3094 emit_block_move (target, temp, size,
3095 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3096 else
3098 /* Compute the size of the data to copy from the string. */
3099 tree copy_size
3100 = size_binop (MIN_EXPR,
3101 make_tree (sizetype, size),
3102 convert (sizetype,
3103 build_int_2 (TREE_STRING_LENGTH (exp), 0)));
3104 rtx copy_size_rtx = expand_expr (copy_size, NULL_RTX,
3105 VOIDmode, 0);
3106 rtx label = 0;
3108 /* Copy that much. */
3109 emit_block_move (target, temp, copy_size_rtx,
3110 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3112 /* Figure out how much is left in TARGET that we have to clear.
3113 Do all calculations in ptr_mode. */
3115 addr = XEXP (target, 0);
3116 addr = convert_modes (ptr_mode, Pmode, addr, 1);
3118 if (GET_CODE (copy_size_rtx) == CONST_INT)
3120 addr = plus_constant (addr, TREE_STRING_LENGTH (exp));
3121 size = plus_constant (size, - TREE_STRING_LENGTH (exp));
3123 else
3125 addr = force_reg (ptr_mode, addr);
3126 addr = expand_binop (ptr_mode, add_optab, addr,
3127 copy_size_rtx, NULL_RTX, 0,
3128 OPTAB_LIB_WIDEN);
3130 size = expand_binop (ptr_mode, sub_optab, size,
3131 copy_size_rtx, NULL_RTX, 0,
3132 OPTAB_LIB_WIDEN);
3134 emit_cmp_insn (size, const0_rtx, LT, NULL_RTX,
3135 GET_MODE (size), 0, 0);
3136 label = gen_label_rtx ();
3137 emit_jump_insn (gen_blt (label));
3140 if (size != const0_rtx)
3142 #ifdef TARGET_MEM_FUNCTIONS
3143 emit_library_call (memset_libfunc, 0, VOIDmode, 3,
3144 addr, Pmode,
3145 const0_rtx, TYPE_MODE (integer_type_node),
3146 convert_to_mode (TYPE_MODE (sizetype),
3147 size,
3148 TREE_UNSIGNED (sizetype)),
3149 TYPE_MODE (sizetype));
3150 #else
3151 emit_library_call (bzero_libfunc, 0, VOIDmode, 2,
3152 addr, Pmode,
3153 convert_to_mode (TYPE_MODE (integer_type_node),
3154 size,
3155 TREE_UNSIGNED (integer_type_node)),
3156 TYPE_MODE (integer_type_node));
3157 #endif
3160 if (label)
3161 emit_label (label);
3164 else if (GET_MODE (temp) == BLKmode)
3165 emit_block_move (target, temp, expr_size (exp),
3166 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3167 else
3168 emit_move_insn (target, temp);
3171 /* If we don't want a value, return NULL_RTX. */
3172 if (! want_value)
3173 return NULL_RTX;
3175 /* If we are supposed to return TEMP, do so as long as it isn't a MEM.
3176 ??? The latter test doesn't seem to make sense. */
3177 else if (dont_return_target && GET_CODE (temp) != MEM)
3178 return temp;
3180 /* Return TARGET itself if it is a hard register. */
3181 else if (want_value && GET_MODE (target) != BLKmode
3182 && ! (GET_CODE (target) == REG
3183 && REGNO (target) < FIRST_PSEUDO_REGISTER))
3184 return copy_to_reg (target);
3186 else
3187 return target;
3190 /* Return 1 if EXP just contains zeros. */
3192 static int
3193 is_zeros_p (exp)
3194 tree exp;
3196 tree elt;
3198 switch (TREE_CODE (exp))
3200 case CONVERT_EXPR:
3201 case NOP_EXPR:
3202 case NON_LVALUE_EXPR:
3203 return is_zeros_p (TREE_OPERAND (exp, 0));
3205 case INTEGER_CST:
3206 return TREE_INT_CST_LOW (exp) == 0 && TREE_INT_CST_HIGH (exp) == 0;
3208 case COMPLEX_CST:
3209 return
3210 is_zeros_p (TREE_REALPART (exp)) && is_zeros_p (TREE_IMAGPART (exp));
3212 case REAL_CST:
3213 return REAL_VALUES_EQUAL (TREE_REAL_CST (exp), dconst0);
3215 case CONSTRUCTOR:
3216 if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3217 return CONSTRUCTOR_ELTS (exp) == NULL_TREE;
3218 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
3219 if (! is_zeros_p (TREE_VALUE (elt)))
3220 return 0;
3222 return 1;
3225 return 0;
3228 /* Return 1 if EXP contains mostly (3/4) zeros. */
3230 static int
3231 mostly_zeros_p (exp)
3232 tree exp;
3234 if (TREE_CODE (exp) == CONSTRUCTOR)
3236 int elts = 0, zeros = 0;
3237 tree elt = CONSTRUCTOR_ELTS (exp);
3238 if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3240 /* If there are no ranges of true bits, it is all zero. */
3241 return elt == NULL_TREE;
3243 for (; elt; elt = TREE_CHAIN (elt))
3245 /* We do not handle the case where the index is a RANGE_EXPR,
3246 so the statistic will be somewhat inaccurate.
3247 We do make a more accurate count in store_constructor itself,
3248 so since this function is only used for nested array elements,
3249 this should be close enough. */
3250 if (mostly_zeros_p (TREE_VALUE (elt)))
3251 zeros++;
3252 elts++;
3255 return 4 * zeros >= 3 * elts;
3258 return is_zeros_p (exp);
3261 /* Helper function for store_constructor.
3262 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
3263 TYPE is the type of the CONSTRUCTOR, not the element type.
3264 CLEARED is as for store_constructor. */
3266 static void
3267 store_constructor_field (target, bitsize, bitpos,
3268 mode, exp, type, cleared)
3269 rtx target;
3270 int bitsize, bitpos;
3271 enum machine_mode mode;
3272 tree exp, type;
3273 int cleared;
3275 if (TREE_CODE (exp) == CONSTRUCTOR
3276 && (bitpos % BITS_PER_UNIT) == 0)
3278 if (bitpos != 0)
3279 target = change_address (target, VOIDmode,
3280 plus_constant (XEXP (target, 0),
3281 bitpos / BITS_PER_UNIT));
3282 store_constructor (exp, target, cleared);
3284 else
3285 store_field (target, bitsize, bitpos, mode, exp,
3286 VOIDmode, 0, TYPE_ALIGN (type) / BITS_PER_UNIT,
3287 int_size_in_bytes (type));
3290 /* Store the value of constructor EXP into the rtx TARGET.
3291 TARGET is either a REG or a MEM.
3292 CLEARED is true if TARGET is known to have been zero'd. */
3294 static void
3295 store_constructor (exp, target, cleared)
3296 tree exp;
3297 rtx target;
3298 int cleared;
3300 tree type = TREE_TYPE (exp);
3302 /* We know our target cannot conflict, since safe_from_p has been called. */
3303 #if 0
3304 /* Don't try copying piece by piece into a hard register
3305 since that is vulnerable to being clobbered by EXP.
3306 Instead, construct in a pseudo register and then copy it all. */
3307 if (GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER)
3309 rtx temp = gen_reg_rtx (GET_MODE (target));
3310 store_constructor (exp, temp, 0);
3311 emit_move_insn (target, temp);
3312 return;
3314 #endif
3316 if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3317 || TREE_CODE (type) == QUAL_UNION_TYPE)
3319 register tree elt;
3321 /* Inform later passes that the whole union value is dead. */
3322 if (TREE_CODE (type) == UNION_TYPE
3323 || TREE_CODE (type) == QUAL_UNION_TYPE)
3324 emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
3326 /* If we are building a static constructor into a register,
3327 set the initial value as zero so we can fold the value into
3328 a constant. But if more than one register is involved,
3329 this probably loses. */
3330 else if (GET_CODE (target) == REG && TREE_STATIC (exp)
3331 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
3333 if (! cleared)
3334 emit_move_insn (target, const0_rtx);
3336 cleared = 1;
3339 /* If the constructor has fewer fields than the structure
3340 or if we are initializing the structure to mostly zeros,
3341 clear the whole structure first. */
3342 else if ((list_length (CONSTRUCTOR_ELTS (exp))
3343 != list_length (TYPE_FIELDS (type)))
3344 || mostly_zeros_p (exp))
3346 if (! cleared)
3347 clear_storage (target, expr_size (exp),
3348 TYPE_ALIGN (type) / BITS_PER_UNIT);
3350 cleared = 1;
3352 else
3353 /* Inform later passes that the old value is dead. */
3354 emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
3356 /* Store each element of the constructor into
3357 the corresponding field of TARGET. */
3359 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
3361 register tree field = TREE_PURPOSE (elt);
3362 register enum machine_mode mode;
3363 int bitsize;
3364 int bitpos = 0;
3365 int unsignedp;
3366 tree pos, constant = 0, offset = 0;
3367 rtx to_rtx = target;
3369 /* Just ignore missing fields.
3370 We cleared the whole structure, above,
3371 if any fields are missing. */
3372 if (field == 0)
3373 continue;
3375 if (cleared && is_zeros_p (TREE_VALUE (elt)))
3376 continue;
3378 bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3379 unsignedp = TREE_UNSIGNED (field);
3380 mode = DECL_MODE (field);
3381 if (DECL_BIT_FIELD (field))
3382 mode = VOIDmode;
3384 pos = DECL_FIELD_BITPOS (field);
3385 if (TREE_CODE (pos) == INTEGER_CST)
3386 constant = pos;
3387 else if (TREE_CODE (pos) == PLUS_EXPR
3388 && TREE_CODE (TREE_OPERAND (pos, 1)) == INTEGER_CST)
3389 constant = TREE_OPERAND (pos, 1), offset = TREE_OPERAND (pos, 0);
3390 else
3391 offset = pos;
3393 if (constant)
3394 bitpos = TREE_INT_CST_LOW (constant);
3396 if (offset)
3398 rtx offset_rtx;
3400 if (contains_placeholder_p (offset))
3401 offset = build (WITH_RECORD_EXPR, sizetype,
3402 offset, exp);
3404 offset = size_binop (FLOOR_DIV_EXPR, offset,
3405 size_int (BITS_PER_UNIT));
3407 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
3408 if (GET_CODE (to_rtx) != MEM)
3409 abort ();
3411 to_rtx
3412 = change_address (to_rtx, VOIDmode,
3413 gen_rtx (PLUS, ptr_mode, XEXP (to_rtx, 0),
3414 force_reg (ptr_mode, offset_rtx)));
3416 if (TREE_READONLY (field))
3418 if (GET_CODE (to_rtx) == MEM)
3419 to_rtx = change_address (to_rtx, GET_MODE (to_rtx),
3420 XEXP (to_rtx, 0));
3421 RTX_UNCHANGING_P (to_rtx) = 1;
3424 store_constructor_field (to_rtx, bitsize, bitpos,
3425 mode, TREE_VALUE (elt), type, cleared);
3428 else if (TREE_CODE (type) == ARRAY_TYPE)
3430 register tree elt;
3431 register int i;
3432 int need_to_clear;
3433 tree domain = TYPE_DOMAIN (type);
3434 HOST_WIDE_INT minelt = TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain));
3435 HOST_WIDE_INT maxelt = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain));
3436 tree elttype = TREE_TYPE (type);
3438 /* If the constructor has fewer elements than the array,
3439 clear the whole array first. Similarly if this this is
3440 static constructor of a non-BLKmode object. */
3441 if (cleared || (GET_CODE (target) == REG && TREE_STATIC (exp)))
3442 need_to_clear = 1;
3443 else
3445 HOST_WIDE_INT count = 0, zero_count = 0;
3446 need_to_clear = 0;
3447 /* This loop is a more accurate version of the loop in
3448 mostly_zeros_p (it handles RANGE_EXPR in an index).
3449 It is also needed to check for missing elements. */
3450 for (elt = CONSTRUCTOR_ELTS (exp);
3451 elt != NULL_TREE;
3452 elt = TREE_CHAIN (elt), i++)
3454 tree index = TREE_PURPOSE (elt);
3455 HOST_WIDE_INT this_node_count;
3456 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
3458 tree lo_index = TREE_OPERAND (index, 0);
3459 tree hi_index = TREE_OPERAND (index, 1);
3460 if (TREE_CODE (lo_index) != INTEGER_CST
3461 || TREE_CODE (hi_index) != INTEGER_CST)
3463 need_to_clear = 1;
3464 break;
3466 this_node_count = TREE_INT_CST_LOW (hi_index)
3467 - TREE_INT_CST_LOW (lo_index) + 1;
3469 else
3470 this_node_count = 1;
3471 count += this_node_count;
3472 if (mostly_zeros_p (TREE_VALUE (elt)))
3473 zero_count += this_node_count;
3475 if (4 * zero_count >= 3 * count)
3476 need_to_clear = 1;
3478 if (need_to_clear)
3480 if (! cleared)
3481 clear_storage (target, expr_size (exp),
3482 TYPE_ALIGN (type) / BITS_PER_UNIT);
3483 cleared = 1;
3485 else
3486 /* Inform later passes that the old value is dead. */
3487 emit_insn (gen_rtx (CLOBBER, VOIDmode, target));
3489 /* Store each element of the constructor into
3490 the corresponding element of TARGET, determined
3491 by counting the elements. */
3492 for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
3493 elt;
3494 elt = TREE_CHAIN (elt), i++)
3496 register enum machine_mode mode;
3497 int bitsize;
3498 int bitpos;
3499 int unsignedp;
3500 tree value = TREE_VALUE (elt);
3501 tree index = TREE_PURPOSE (elt);
3502 rtx xtarget = target;
3504 if (cleared && is_zeros_p (value))
3505 continue;
3507 mode = TYPE_MODE (elttype);
3508 bitsize = GET_MODE_BITSIZE (mode);
3509 unsignedp = TREE_UNSIGNED (elttype);
3511 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
3513 tree lo_index = TREE_OPERAND (index, 0);
3514 tree hi_index = TREE_OPERAND (index, 1);
3515 rtx index_r, pos_rtx, addr, hi_r, loop_top, loop_end;
3516 struct nesting *loop;
3517 HOST_WIDE_INT lo, hi, count;
3518 tree position;
3520 /* If the range is constant and "small", unroll the loop. */
3521 if (TREE_CODE (lo_index) == INTEGER_CST
3522 && TREE_CODE (hi_index) == INTEGER_CST
3523 && (lo = TREE_INT_CST_LOW (lo_index),
3524 hi = TREE_INT_CST_LOW (hi_index),
3525 count = hi - lo + 1,
3526 (GET_CODE (target) != MEM
3527 || count <= 2
3528 || (TREE_CODE (TYPE_SIZE (elttype)) == INTEGER_CST
3529 && TREE_INT_CST_LOW (TYPE_SIZE (elttype)) * count
3530 <= 40 * 8))))
3532 lo -= minelt; hi -= minelt;
3533 for (; lo <= hi; lo++)
3535 bitpos = lo * TREE_INT_CST_LOW (TYPE_SIZE (elttype));
3536 store_constructor_field (target, bitsize, bitpos,
3537 mode, value, type, cleared);
3540 else
3542 hi_r = expand_expr (hi_index, NULL_RTX, VOIDmode, 0);
3543 loop_top = gen_label_rtx ();
3544 loop_end = gen_label_rtx ();
3546 unsignedp = TREE_UNSIGNED (domain);
3548 index = build_decl (VAR_DECL, NULL_TREE, domain);
3550 DECL_RTL (index) = index_r
3551 = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
3552 &unsignedp, 0));
3554 if (TREE_CODE (value) == SAVE_EXPR
3555 && SAVE_EXPR_RTL (value) == 0)
3557 /* Make sure value gets expanded once before the loop. */
3558 expand_expr (value, const0_rtx, VOIDmode, 0);
3559 emit_queue ();
3561 store_expr (lo_index, index_r, 0);
3562 loop = expand_start_loop (0);
3564 /* Assign value to element index. */
3565 position = size_binop (EXACT_DIV_EXPR, TYPE_SIZE (elttype),
3566 size_int (BITS_PER_UNIT));
3567 position = size_binop (MULT_EXPR,
3568 size_binop (MINUS_EXPR, index,
3569 TYPE_MIN_VALUE (domain)),
3570 position);
3571 pos_rtx = expand_expr (position, 0, VOIDmode, 0);
3572 addr = gen_rtx (PLUS, Pmode, XEXP (target, 0), pos_rtx);
3573 xtarget = change_address (target, mode, addr);
3574 if (TREE_CODE (value) == CONSTRUCTOR)
3575 store_constructor (value, xtarget, cleared);
3576 else
3577 store_expr (value, xtarget, 0);
3579 expand_exit_loop_if_false (loop,
3580 build (LT_EXPR, integer_type_node,
3581 index, hi_index));
3583 expand_increment (build (PREINCREMENT_EXPR,
3584 TREE_TYPE (index),
3585 index, integer_one_node), 0);
3586 expand_end_loop ();
3587 emit_label (loop_end);
3589 /* Needed by stupid register allocation. to extend the
3590 lifetime of pseudo-regs used by target past the end
3591 of the loop. */
3592 emit_insn (gen_rtx (USE, GET_MODE (target), target));
3595 else if ((index != 0 && TREE_CODE (index) != INTEGER_CST)
3596 || TREE_CODE (TYPE_SIZE (elttype)) != INTEGER_CST)
3598 rtx pos_rtx, addr;
3599 tree position;
3601 if (index == 0)
3602 index = size_int (i);
3604 if (minelt)
3605 index = size_binop (MINUS_EXPR, index,
3606 TYPE_MIN_VALUE (domain));
3607 position = size_binop (EXACT_DIV_EXPR, TYPE_SIZE (elttype),
3608 size_int (BITS_PER_UNIT));
3609 position = size_binop (MULT_EXPR, index, position);
3610 pos_rtx = expand_expr (position, 0, VOIDmode, 0);
3611 addr = gen_rtx (PLUS, Pmode, XEXP (target, 0), pos_rtx);
3612 xtarget = change_address (target, mode, addr);
3613 store_expr (value, xtarget, 0);
3615 else
3617 if (index != 0)
3618 bitpos = ((TREE_INT_CST_LOW (index) - minelt)
3619 * TREE_INT_CST_LOW (TYPE_SIZE (elttype)));
3620 else
3621 bitpos = (i * TREE_INT_CST_LOW (TYPE_SIZE (elttype)));
3622 store_constructor_field (target, bitsize, bitpos,
3623 mode, value, type, cleared);
3627 /* set constructor assignments */
3628 else if (TREE_CODE (type) == SET_TYPE)
3630 tree elt = CONSTRUCTOR_ELTS (exp);
3631 rtx xtarget = XEXP (target, 0);
3632 int set_word_size = TYPE_ALIGN (type);
3633 int nbytes = int_size_in_bytes (type), nbits;
3634 tree domain = TYPE_DOMAIN (type);
3635 tree domain_min, domain_max, bitlength;
3637 /* The default implementation strategy is to extract the constant
3638 parts of the constructor, use that to initialize the target,
3639 and then "or" in whatever non-constant ranges we need in addition.
3641 If a large set is all zero or all ones, it is
3642 probably better to set it using memset (if available) or bzero.
3643 Also, if a large set has just a single range, it may also be
3644 better to first clear all the first clear the set (using
3645 bzero/memset), and set the bits we want. */
3647 /* Check for all zeros. */
3648 if (elt == NULL_TREE)
3650 if (!cleared)
3651 clear_storage (target, expr_size (exp),
3652 TYPE_ALIGN (type) / BITS_PER_UNIT);
3653 return;
3656 domain_min = convert (sizetype, TYPE_MIN_VALUE (domain));
3657 domain_max = convert (sizetype, TYPE_MAX_VALUE (domain));
3658 bitlength = size_binop (PLUS_EXPR,
3659 size_binop (MINUS_EXPR, domain_max, domain_min),
3660 size_one_node);
3662 if (nbytes < 0 || TREE_CODE (bitlength) != INTEGER_CST)
3663 abort ();
3664 nbits = TREE_INT_CST_LOW (bitlength);
3666 /* For "small" sets, or "medium-sized" (up to 32 bytes) sets that
3667 are "complicated" (more than one range), initialize (the
3668 constant parts) by copying from a constant. */
3669 if (GET_MODE (target) != BLKmode || nbits <= 2 * BITS_PER_WORD
3670 || (nbytes <= 32 && TREE_CHAIN (elt) != NULL_TREE))
3672 int set_word_size = TYPE_ALIGN (TREE_TYPE (exp));
3673 enum machine_mode mode = mode_for_size (set_word_size, MODE_INT, 1);
3674 char *bit_buffer = (char*) alloca (nbits);
3675 HOST_WIDE_INT word = 0;
3676 int bit_pos = 0;
3677 int ibit = 0;
3678 int offset = 0; /* In bytes from beginning of set. */
3679 elt = get_set_constructor_bits (exp, bit_buffer, nbits);
3680 for (;;)
3682 if (bit_buffer[ibit])
3684 if (BYTES_BIG_ENDIAN)
3685 word |= (1 << (set_word_size - 1 - bit_pos));
3686 else
3687 word |= 1 << bit_pos;
3689 bit_pos++; ibit++;
3690 if (bit_pos >= set_word_size || ibit == nbits)
3692 if (word != 0 || ! cleared)
3694 rtx datum = GEN_INT (word);
3695 rtx to_rtx;
3696 /* The assumption here is that it is safe to use XEXP if
3697 the set is multi-word, but not if it's single-word. */
3698 if (GET_CODE (target) == MEM)
3700 to_rtx = plus_constant (XEXP (target, 0), offset);
3701 to_rtx = change_address (target, mode, to_rtx);
3703 else if (offset == 0)
3704 to_rtx = target;
3705 else
3706 abort ();
3707 emit_move_insn (to_rtx, datum);
3709 if (ibit == nbits)
3710 break;
3711 word = 0;
3712 bit_pos = 0;
3713 offset += set_word_size / BITS_PER_UNIT;
3717 else if (!cleared)
3719 /* Don't bother clearing storage if the set is all ones. */
3720 if (TREE_CHAIN (elt) != NULL_TREE
3721 || (TREE_PURPOSE (elt) == NULL_TREE
3722 ? nbits != 1
3723 : (TREE_CODE (TREE_VALUE (elt)) != INTEGER_CST
3724 || TREE_CODE (TREE_PURPOSE (elt)) != INTEGER_CST
3725 || (TREE_INT_CST_LOW (TREE_VALUE (elt))
3726 - TREE_INT_CST_LOW (TREE_PURPOSE (elt)) + 1
3727 != nbits))))
3728 clear_storage (target, expr_size (exp),
3729 TYPE_ALIGN (type) / BITS_PER_UNIT);
3732 for (; elt != NULL_TREE; elt = TREE_CHAIN (elt))
3734 /* start of range of element or NULL */
3735 tree startbit = TREE_PURPOSE (elt);
3736 /* end of range of element, or element value */
3737 tree endbit = TREE_VALUE (elt);
3738 HOST_WIDE_INT startb, endb;
3739 rtx bitlength_rtx, startbit_rtx, endbit_rtx, targetx;
3741 bitlength_rtx = expand_expr (bitlength,
3742 NULL_RTX, MEM, EXPAND_CONST_ADDRESS);
3744 /* handle non-range tuple element like [ expr ] */
3745 if (startbit == NULL_TREE)
3747 startbit = save_expr (endbit);
3748 endbit = startbit;
3750 startbit = convert (sizetype, startbit);
3751 endbit = convert (sizetype, endbit);
3752 if (! integer_zerop (domain_min))
3754 startbit = size_binop (MINUS_EXPR, startbit, domain_min);
3755 endbit = size_binop (MINUS_EXPR, endbit, domain_min);
3757 startbit_rtx = expand_expr (startbit, NULL_RTX, MEM,
3758 EXPAND_CONST_ADDRESS);
3759 endbit_rtx = expand_expr (endbit, NULL_RTX, MEM,
3760 EXPAND_CONST_ADDRESS);
3762 if (REG_P (target))
3764 targetx = assign_stack_temp (GET_MODE (target),
3765 GET_MODE_SIZE (GET_MODE (target)),
3767 emit_move_insn (targetx, target);
3769 else if (GET_CODE (target) == MEM)
3770 targetx = target;
3771 else
3772 abort ();
3774 #ifdef TARGET_MEM_FUNCTIONS
3775 /* Optimization: If startbit and endbit are
3776 constants divisible by BITS_PER_UNIT,
3777 call memset instead. */
3778 if (TREE_CODE (startbit) == INTEGER_CST
3779 && TREE_CODE (endbit) == INTEGER_CST
3780 && (startb = TREE_INT_CST_LOW (startbit)) % BITS_PER_UNIT == 0
3781 && (endb = TREE_INT_CST_LOW (endbit) + 1) % BITS_PER_UNIT == 0)
3783 emit_library_call (memset_libfunc, 0,
3784 VOIDmode, 3,
3785 plus_constant (XEXP (targetx, 0),
3786 startb / BITS_PER_UNIT),
3787 Pmode,
3788 constm1_rtx, TYPE_MODE (integer_type_node),
3789 GEN_INT ((endb - startb) / BITS_PER_UNIT),
3790 TYPE_MODE (sizetype));
3792 else
3793 #endif
3795 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__setbits"),
3796 0, VOIDmode, 4, XEXP (targetx, 0), Pmode,
3797 bitlength_rtx, TYPE_MODE (sizetype),
3798 startbit_rtx, TYPE_MODE (sizetype),
3799 endbit_rtx, TYPE_MODE (sizetype));
3801 if (REG_P (target))
3802 emit_move_insn (target, targetx);
3806 else
3807 abort ();
3810 /* Store the value of EXP (an expression tree)
3811 into a subfield of TARGET which has mode MODE and occupies
3812 BITSIZE bits, starting BITPOS bits from the start of TARGET.
3813 If MODE is VOIDmode, it means that we are storing into a bit-field.
3815 If VALUE_MODE is VOIDmode, return nothing in particular.
3816 UNSIGNEDP is not used in this case.
3818 Otherwise, return an rtx for the value stored. This rtx
3819 has mode VALUE_MODE if that is convenient to do.
3820 In this case, UNSIGNEDP must be nonzero if the value is an unsigned type.
3822 ALIGN is the alignment that TARGET is known to have, measured in bytes.
3823 TOTAL_SIZE is the size in bytes of the structure, or -1 if varying. */
3825 static rtx
3826 store_field (target, bitsize, bitpos, mode, exp, value_mode,
3827 unsignedp, align, total_size)
3828 rtx target;
3829 int bitsize, bitpos;
3830 enum machine_mode mode;
3831 tree exp;
3832 enum machine_mode value_mode;
3833 int unsignedp;
3834 int align;
3835 int total_size;
3837 HOST_WIDE_INT width_mask = 0;
3839 if (bitsize < HOST_BITS_PER_WIDE_INT)
3840 width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
3842 /* If we are storing into an unaligned field of an aligned union that is
3843 in a register, we may have the mode of TARGET being an integer mode but
3844 MODE == BLKmode. In that case, get an aligned object whose size and
3845 alignment are the same as TARGET and store TARGET into it (we can avoid
3846 the store if the field being stored is the entire width of TARGET). Then
3847 call ourselves recursively to store the field into a BLKmode version of
3848 that object. Finally, load from the object into TARGET. This is not
3849 very efficient in general, but should only be slightly more expensive
3850 than the otherwise-required unaligned accesses. Perhaps this can be
3851 cleaned up later. */
3853 if (mode == BLKmode
3854 && (GET_CODE (target) == REG || GET_CODE (target) == SUBREG))
3856 rtx object = assign_stack_temp (GET_MODE (target),
3857 GET_MODE_SIZE (GET_MODE (target)), 0);
3858 rtx blk_object = copy_rtx (object);
3860 MEM_IN_STRUCT_P (object) = 1;
3861 MEM_IN_STRUCT_P (blk_object) = 1;
3862 PUT_MODE (blk_object, BLKmode);
3864 if (bitsize != GET_MODE_BITSIZE (GET_MODE (target)))
3865 emit_move_insn (object, target);
3867 store_field (blk_object, bitsize, bitpos, mode, exp, VOIDmode, 0,
3868 align, total_size);
3870 /* Even though we aren't returning target, we need to
3871 give it the updated value. */
3872 emit_move_insn (target, object);
3874 return blk_object;
3877 /* If the structure is in a register or if the component
3878 is a bit field, we cannot use addressing to access it.
3879 Use bit-field techniques or SUBREG to store in it. */
3881 if (mode == VOIDmode
3882 || (mode != BLKmode && ! direct_store[(int) mode])
3883 || GET_CODE (target) == REG
3884 || GET_CODE (target) == SUBREG
3885 /* If the field isn't aligned enough to store as an ordinary memref,
3886 store it as a bit field. */
3887 || (SLOW_UNALIGNED_ACCESS
3888 && align * BITS_PER_UNIT < GET_MODE_ALIGNMENT (mode))
3889 || (SLOW_UNALIGNED_ACCESS && bitpos % GET_MODE_ALIGNMENT (mode) != 0))
3891 rtx temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
3893 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
3894 MODE. */
3895 if (mode != VOIDmode && mode != BLKmode
3896 && mode != TYPE_MODE (TREE_TYPE (exp)))
3897 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
3899 /* Store the value in the bitfield. */
3900 store_bit_field (target, bitsize, bitpos, mode, temp, align, total_size);
3901 if (value_mode != VOIDmode)
3903 /* The caller wants an rtx for the value. */
3904 /* If possible, avoid refetching from the bitfield itself. */
3905 if (width_mask != 0
3906 && ! (GET_CODE (target) == MEM && MEM_VOLATILE_P (target)))
3908 tree count;
3909 enum machine_mode tmode;
3911 if (unsignedp)
3912 return expand_and (temp, GEN_INT (width_mask), NULL_RTX);
3913 tmode = GET_MODE (temp);
3914 if (tmode == VOIDmode)
3915 tmode = value_mode;
3916 count = build_int_2 (GET_MODE_BITSIZE (tmode) - bitsize, 0);
3917 temp = expand_shift (LSHIFT_EXPR, tmode, temp, count, 0, 0);
3918 return expand_shift (RSHIFT_EXPR, tmode, temp, count, 0, 0);
3920 return extract_bit_field (target, bitsize, bitpos, unsignedp,
3921 NULL_RTX, value_mode, 0, align,
3922 total_size);
3924 return const0_rtx;
3926 else
3928 rtx addr = XEXP (target, 0);
3929 rtx to_rtx;
3931 /* If a value is wanted, it must be the lhs;
3932 so make the address stable for multiple use. */
3934 if (value_mode != VOIDmode && GET_CODE (addr) != REG
3935 && ! CONSTANT_ADDRESS_P (addr)
3936 /* A frame-pointer reference is already stable. */
3937 && ! (GET_CODE (addr) == PLUS
3938 && GET_CODE (XEXP (addr, 1)) == CONST_INT
3939 && (XEXP (addr, 0) == virtual_incoming_args_rtx
3940 || XEXP (addr, 0) == virtual_stack_vars_rtx)))
3941 addr = copy_to_reg (addr);
3943 /* Now build a reference to just the desired component. */
3945 to_rtx = change_address (target, mode,
3946 plus_constant (addr, (bitpos / BITS_PER_UNIT)));
3947 MEM_IN_STRUCT_P (to_rtx) = 1;
3949 return store_expr (exp, to_rtx, value_mode != VOIDmode);
3953 /* Return true if any object containing the innermost array is an unaligned
3954 packed structure field. */
3956 static int
3957 get_inner_unaligned_p (exp)
3958 tree exp;
3960 int needed_alignment = TYPE_ALIGN (TREE_TYPE (exp));
3962 while (1)
3964 if (TREE_CODE (exp) == COMPONENT_REF || TREE_CODE (exp) == BIT_FIELD_REF)
3966 if (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
3967 < needed_alignment)
3968 return 1;
3970 else if (TREE_CODE (exp) != ARRAY_REF
3971 && TREE_CODE (exp) != NON_LVALUE_EXPR
3972 && ! ((TREE_CODE (exp) == NOP_EXPR
3973 || TREE_CODE (exp) == CONVERT_EXPR)
3974 && (TYPE_MODE (TREE_TYPE (exp))
3975 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
3976 break;
3978 exp = TREE_OPERAND (exp, 0);
3981 return 0;
3984 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
3985 or an ARRAY_REF, look for nested COMPONENT_REFs, BIT_FIELD_REFs, or
3986 ARRAY_REFs and find the ultimate containing object, which we return.
3988 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
3989 bit position, and *PUNSIGNEDP to the signedness of the field.
3990 If the position of the field is variable, we store a tree
3991 giving the variable offset (in units) in *POFFSET.
3992 This offset is in addition to the bit position.
3993 If the position is not variable, we store 0 in *POFFSET.
3995 If any of the extraction expressions is volatile,
3996 we store 1 in *PVOLATILEP. Otherwise we don't change that.
3998 If the field is a bit-field, *PMODE is set to VOIDmode. Otherwise, it
3999 is a mode that can be used to access the field. In that case, *PBITSIZE
4000 is redundant.
4002 If the field describes a variable-sized object, *PMODE is set to
4003 VOIDmode and *PBITSIZE is set to -1. An access cannot be made in
4004 this case, but the address of the object can be found. */
4006 tree
4007 get_inner_reference (exp, pbitsize, pbitpos, poffset, pmode,
4008 punsignedp, pvolatilep)
4009 tree exp;
4010 int *pbitsize;
4011 int *pbitpos;
4012 tree *poffset;
4013 enum machine_mode *pmode;
4014 int *punsignedp;
4015 int *pvolatilep;
4017 tree orig_exp = exp;
4018 tree size_tree = 0;
4019 enum machine_mode mode = VOIDmode;
4020 tree offset = integer_zero_node;
4022 if (TREE_CODE (exp) == COMPONENT_REF)
4024 size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
4025 if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
4026 mode = DECL_MODE (TREE_OPERAND (exp, 1));
4027 *punsignedp = TREE_UNSIGNED (TREE_OPERAND (exp, 1));
4029 else if (TREE_CODE (exp) == BIT_FIELD_REF)
4031 size_tree = TREE_OPERAND (exp, 1);
4032 *punsignedp = TREE_UNSIGNED (exp);
4034 else
4036 mode = TYPE_MODE (TREE_TYPE (exp));
4037 *pbitsize = GET_MODE_BITSIZE (mode);
4038 *punsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
4041 if (size_tree)
4043 if (TREE_CODE (size_tree) != INTEGER_CST)
4044 mode = BLKmode, *pbitsize = -1;
4045 else
4046 *pbitsize = TREE_INT_CST_LOW (size_tree);
4049 /* Compute cumulative bit-offset for nested component-refs and array-refs,
4050 and find the ultimate containing object. */
4052 *pbitpos = 0;
4054 while (1)
4056 if (TREE_CODE (exp) == COMPONENT_REF || TREE_CODE (exp) == BIT_FIELD_REF)
4058 tree pos = (TREE_CODE (exp) == COMPONENT_REF
4059 ? DECL_FIELD_BITPOS (TREE_OPERAND (exp, 1))
4060 : TREE_OPERAND (exp, 2));
4061 tree constant = integer_zero_node, var = pos;
4063 /* If this field hasn't been filled in yet, don't go
4064 past it. This should only happen when folding expressions
4065 made during type construction. */
4066 if (pos == 0)
4067 break;
4069 /* Assume here that the offset is a multiple of a unit.
4070 If not, there should be an explicitly added constant. */
4071 if (TREE_CODE (pos) == PLUS_EXPR
4072 && TREE_CODE (TREE_OPERAND (pos, 1)) == INTEGER_CST)
4073 constant = TREE_OPERAND (pos, 1), var = TREE_OPERAND (pos, 0);
4074 else if (TREE_CODE (pos) == INTEGER_CST)
4075 constant = pos, var = integer_zero_node;
4077 *pbitpos += TREE_INT_CST_LOW (constant);
4079 if (var)
4080 offset = size_binop (PLUS_EXPR, offset,
4081 size_binop (EXACT_DIV_EXPR, var,
4082 size_int (BITS_PER_UNIT)));
4085 else if (TREE_CODE (exp) == ARRAY_REF)
4087 /* This code is based on the code in case ARRAY_REF in expand_expr
4088 below. We assume here that the size of an array element is
4089 always an integral multiple of BITS_PER_UNIT. */
4091 tree index = TREE_OPERAND (exp, 1);
4092 tree domain = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
4093 tree low_bound
4094 = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
4095 tree index_type = TREE_TYPE (index);
4097 if (! integer_zerop (low_bound))
4098 index = fold (build (MINUS_EXPR, index_type, index, low_bound));
4100 if (TYPE_PRECISION (index_type) != TYPE_PRECISION (sizetype))
4102 index = convert (type_for_size (TYPE_PRECISION (sizetype), 0),
4103 index);
4104 index_type = TREE_TYPE (index);
4107 index = fold (build (MULT_EXPR, index_type, index,
4108 TYPE_SIZE (TREE_TYPE (exp))));
4110 if (TREE_CODE (index) == INTEGER_CST
4111 && TREE_INT_CST_HIGH (index) == 0)
4112 *pbitpos += TREE_INT_CST_LOW (index);
4113 else
4114 offset = size_binop (PLUS_EXPR, offset,
4115 size_binop (FLOOR_DIV_EXPR, index,
4116 size_int (BITS_PER_UNIT)));
4118 else if (TREE_CODE (exp) != NON_LVALUE_EXPR
4119 && ! ((TREE_CODE (exp) == NOP_EXPR
4120 || TREE_CODE (exp) == CONVERT_EXPR)
4121 && ! (TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
4122 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0)))
4123 != UNION_TYPE))
4124 && (TYPE_MODE (TREE_TYPE (exp))
4125 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
4126 break;
4128 /* If any reference in the chain is volatile, the effect is volatile. */
4129 if (TREE_THIS_VOLATILE (exp))
4130 *pvolatilep = 1;
4131 exp = TREE_OPERAND (exp, 0);
4134 /* If this was a bit-field, see if there is a mode that allows direct
4135 access in case EXP is in memory. */
4136 if (mode == VOIDmode && *pbitsize != 0 && *pbitpos % *pbitsize == 0)
4138 mode = mode_for_size (*pbitsize, MODE_INT, 0);
4139 if (mode == BLKmode)
4140 mode = VOIDmode;
4143 if (integer_zerop (offset))
4144 offset = 0;
4146 if (offset != 0 && contains_placeholder_p (offset))
4147 offset = build (WITH_RECORD_EXPR, sizetype, offset, orig_exp);
4149 *pmode = mode;
4150 *poffset = offset;
4151 return exp;
4154 /* Given an rtx VALUE that may contain additions and multiplications,
4155 return an equivalent value that just refers to a register or memory.
4156 This is done by generating instructions to perform the arithmetic
4157 and returning a pseudo-register containing the value.
4159 The returned value may be a REG, SUBREG, MEM or constant. */
4162 force_operand (value, target)
4163 rtx value, target;
4165 register optab binoptab = 0;
4166 /* Use a temporary to force order of execution of calls to
4167 `force_operand'. */
4168 rtx tmp;
4169 register rtx op2;
4170 /* Use subtarget as the target for operand 0 of a binary operation. */
4171 register rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
4173 if (GET_CODE (value) == PLUS)
4174 binoptab = add_optab;
4175 else if (GET_CODE (value) == MINUS)
4176 binoptab = sub_optab;
4177 else if (GET_CODE (value) == MULT)
4179 op2 = XEXP (value, 1);
4180 if (!CONSTANT_P (op2)
4181 && !(GET_CODE (op2) == REG && op2 != subtarget))
4182 subtarget = 0;
4183 tmp = force_operand (XEXP (value, 0), subtarget);
4184 return expand_mult (GET_MODE (value), tmp,
4185 force_operand (op2, NULL_RTX),
4186 target, 0);
4189 if (binoptab)
4191 op2 = XEXP (value, 1);
4192 if (!CONSTANT_P (op2)
4193 && !(GET_CODE (op2) == REG && op2 != subtarget))
4194 subtarget = 0;
4195 if (binoptab == sub_optab && GET_CODE (op2) == CONST_INT)
4197 binoptab = add_optab;
4198 op2 = negate_rtx (GET_MODE (value), op2);
4201 /* Check for an addition with OP2 a constant integer and our first
4202 operand a PLUS of a virtual register and something else. In that
4203 case, we want to emit the sum of the virtual register and the
4204 constant first and then add the other value. This allows virtual
4205 register instantiation to simply modify the constant rather than
4206 creating another one around this addition. */
4207 if (binoptab == add_optab && GET_CODE (op2) == CONST_INT
4208 && GET_CODE (XEXP (value, 0)) == PLUS
4209 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
4210 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
4211 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
4213 rtx temp = expand_binop (GET_MODE (value), binoptab,
4214 XEXP (XEXP (value, 0), 0), op2,
4215 subtarget, 0, OPTAB_LIB_WIDEN);
4216 return expand_binop (GET_MODE (value), binoptab, temp,
4217 force_operand (XEXP (XEXP (value, 0), 1), 0),
4218 target, 0, OPTAB_LIB_WIDEN);
4221 tmp = force_operand (XEXP (value, 0), subtarget);
4222 return expand_binop (GET_MODE (value), binoptab, tmp,
4223 force_operand (op2, NULL_RTX),
4224 target, 0, OPTAB_LIB_WIDEN);
4225 /* We give UNSIGNEDP = 0 to expand_binop
4226 because the only operations we are expanding here are signed ones. */
4228 return value;
4231 /* Subroutine of expand_expr:
4232 save the non-copied parts (LIST) of an expr (LHS), and return a list
4233 which can restore these values to their previous values,
4234 should something modify their storage. */
4236 static tree
4237 save_noncopied_parts (lhs, list)
4238 tree lhs;
4239 tree list;
4241 tree tail;
4242 tree parts = 0;
4244 for (tail = list; tail; tail = TREE_CHAIN (tail))
4245 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4246 parts = chainon (parts, save_noncopied_parts (lhs, TREE_VALUE (tail)));
4247 else
4249 tree part = TREE_VALUE (tail);
4250 tree part_type = TREE_TYPE (part);
4251 tree to_be_saved = build (COMPONENT_REF, part_type, lhs, part);
4252 rtx target = assign_temp (part_type, 0, 1, 1);
4253 if (! memory_address_p (TYPE_MODE (part_type), XEXP (target, 0)))
4254 target = change_address (target, TYPE_MODE (part_type), NULL_RTX);
4255 parts = tree_cons (to_be_saved,
4256 build (RTL_EXPR, part_type, NULL_TREE,
4257 (tree) target),
4258 parts);
4259 store_expr (TREE_PURPOSE (parts), RTL_EXPR_RTL (TREE_VALUE (parts)), 0);
4261 return parts;
4264 /* Subroutine of expand_expr:
4265 record the non-copied parts (LIST) of an expr (LHS), and return a list
4266 which specifies the initial values of these parts. */
4268 static tree
4269 init_noncopied_parts (lhs, list)
4270 tree lhs;
4271 tree list;
4273 tree tail;
4274 tree parts = 0;
4276 for (tail = list; tail; tail = TREE_CHAIN (tail))
4277 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4278 parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail)));
4279 else
4281 tree part = TREE_VALUE (tail);
4282 tree part_type = TREE_TYPE (part);
4283 tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part);
4284 parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts);
4286 return parts;
4289 /* Subroutine of expand_expr: return nonzero iff there is no way that
4290 EXP can reference X, which is being modified. */
4292 static int
4293 safe_from_p (x, exp)
4294 rtx x;
4295 tree exp;
4297 rtx exp_rtl = 0;
4298 int i, nops;
4300 if (x == 0
4301 /* If EXP has varying size, we MUST use a target since we currently
4302 have no way of allocating temporaries of variable size. So we
4303 assume here that something at a higher level has prevented a
4304 clash. This is somewhat bogus, but the best we can do. Only
4305 do this when X is BLKmode. */
4306 || (TREE_TYPE (exp) != 0 && TYPE_SIZE (TREE_TYPE (exp)) != 0
4307 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
4308 && GET_MODE (x) == BLKmode))
4309 return 1;
4311 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
4312 find the underlying pseudo. */
4313 if (GET_CODE (x) == SUBREG)
4315 x = SUBREG_REG (x);
4316 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
4317 return 0;
4320 /* If X is a location in the outgoing argument area, it is always safe. */
4321 if (GET_CODE (x) == MEM
4322 && (XEXP (x, 0) == virtual_outgoing_args_rtx
4323 || (GET_CODE (XEXP (x, 0)) == PLUS
4324 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx)))
4325 return 1;
4327 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
4329 case 'd':
4330 exp_rtl = DECL_RTL (exp);
4331 break;
4333 case 'c':
4334 return 1;
4336 case 'x':
4337 if (TREE_CODE (exp) == TREE_LIST)
4338 return ((TREE_VALUE (exp) == 0
4339 || safe_from_p (x, TREE_VALUE (exp)))
4340 && (TREE_CHAIN (exp) == 0
4341 || safe_from_p (x, TREE_CHAIN (exp))));
4342 else
4343 return 0;
4345 case '1':
4346 return safe_from_p (x, TREE_OPERAND (exp, 0));
4348 case '2':
4349 case '<':
4350 return (safe_from_p (x, TREE_OPERAND (exp, 0))
4351 && safe_from_p (x, TREE_OPERAND (exp, 1)));
4353 case 'e':
4354 case 'r':
4355 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
4356 the expression. If it is set, we conflict iff we are that rtx or
4357 both are in memory. Otherwise, we check all operands of the
4358 expression recursively. */
4360 switch (TREE_CODE (exp))
4362 case ADDR_EXPR:
4363 return (staticp (TREE_OPERAND (exp, 0))
4364 || safe_from_p (x, TREE_OPERAND (exp, 0)));
4366 case INDIRECT_REF:
4367 if (GET_CODE (x) == MEM)
4368 return 0;
4369 break;
4371 case CALL_EXPR:
4372 exp_rtl = CALL_EXPR_RTL (exp);
4373 if (exp_rtl == 0)
4375 /* Assume that the call will clobber all hard registers and
4376 all of memory. */
4377 if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
4378 || GET_CODE (x) == MEM)
4379 return 0;
4382 break;
4384 case RTL_EXPR:
4385 /* If a sequence exists, we would have to scan every instruction
4386 in the sequence to see if it was safe. This is probably not
4387 worthwhile. */
4388 if (RTL_EXPR_SEQUENCE (exp))
4389 return 0;
4391 exp_rtl = RTL_EXPR_RTL (exp);
4392 break;
4394 case WITH_CLEANUP_EXPR:
4395 exp_rtl = RTL_EXPR_RTL (exp);
4396 break;
4398 case CLEANUP_POINT_EXPR:
4399 return safe_from_p (x, TREE_OPERAND (exp, 0));
4401 case SAVE_EXPR:
4402 exp_rtl = SAVE_EXPR_RTL (exp);
4403 break;
4405 case BIND_EXPR:
4406 /* The only operand we look at is operand 1. The rest aren't
4407 part of the expression. */
4408 return safe_from_p (x, TREE_OPERAND (exp, 1));
4410 case METHOD_CALL_EXPR:
4411 /* This takes a rtx argument, but shouldn't appear here. */
4412 abort ();
4415 /* If we have an rtx, we do not need to scan our operands. */
4416 if (exp_rtl)
4417 break;
4419 nops = tree_code_length[(int) TREE_CODE (exp)];
4420 for (i = 0; i < nops; i++)
4421 if (TREE_OPERAND (exp, i) != 0
4422 && ! safe_from_p (x, TREE_OPERAND (exp, i)))
4423 return 0;
4426 /* If we have an rtl, find any enclosed object. Then see if we conflict
4427 with it. */
4428 if (exp_rtl)
4430 if (GET_CODE (exp_rtl) == SUBREG)
4432 exp_rtl = SUBREG_REG (exp_rtl);
4433 if (GET_CODE (exp_rtl) == REG
4434 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
4435 return 0;
4438 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
4439 are memory and EXP is not readonly. */
4440 return ! (rtx_equal_p (x, exp_rtl)
4441 || (GET_CODE (x) == MEM && GET_CODE (exp_rtl) == MEM
4442 && ! TREE_READONLY (exp)));
4445 /* If we reach here, it is safe. */
4446 return 1;
4449 /* Subroutine of expand_expr: return nonzero iff EXP is an
4450 expression whose type is statically determinable. */
4452 static int
4453 fixed_type_p (exp)
4454 tree exp;
4456 if (TREE_CODE (exp) == PARM_DECL
4457 || TREE_CODE (exp) == VAR_DECL
4458 || TREE_CODE (exp) == CALL_EXPR || TREE_CODE (exp) == TARGET_EXPR
4459 || TREE_CODE (exp) == COMPONENT_REF
4460 || TREE_CODE (exp) == ARRAY_REF)
4461 return 1;
4462 return 0;
4465 /* expand_expr: generate code for computing expression EXP.
4466 An rtx for the computed value is returned. The value is never null.
4467 In the case of a void EXP, const0_rtx is returned.
4469 The value may be stored in TARGET if TARGET is nonzero.
4470 TARGET is just a suggestion; callers must assume that
4471 the rtx returned may not be the same as TARGET.
4473 If TARGET is CONST0_RTX, it means that the value will be ignored.
4475 If TMODE is not VOIDmode, it suggests generating the
4476 result in mode TMODE. But this is done only when convenient.
4477 Otherwise, TMODE is ignored and the value generated in its natural mode.
4478 TMODE is just a suggestion; callers must assume that
4479 the rtx returned may not have mode TMODE.
4481 Note that TARGET may have neither TMODE nor MODE. In that case, it
4482 probably will not be used.
4484 If MODIFIER is EXPAND_SUM then when EXP is an addition
4485 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
4486 or a nest of (PLUS ...) and (MINUS ...) where the terms are
4487 products as above, or REG or MEM, or constant.
4488 Ordinarily in such cases we would output mul or add instructions
4489 and then return a pseudo reg containing the sum.
4491 EXPAND_INITIALIZER is much like EXPAND_SUM except that
4492 it also marks a label as absolutely required (it can't be dead).
4493 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
4494 This is used for outputting expressions used in initializers.
4496 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
4497 with a constant address even if that address is not normally legitimate.
4498 EXPAND_INITIALIZER and EXPAND_SUM also have this effect. */
4501 expand_expr (exp, target, tmode, modifier)
4502 register tree exp;
4503 rtx target;
4504 enum machine_mode tmode;
4505 enum expand_modifier modifier;
4507 /* Chain of pending expressions for PLACEHOLDER_EXPR to replace.
4508 This is static so it will be accessible to our recursive callees. */
4509 static tree placeholder_list = 0;
4510 register rtx op0, op1, temp;
4511 tree type = TREE_TYPE (exp);
4512 int unsignedp = TREE_UNSIGNED (type);
4513 register enum machine_mode mode = TYPE_MODE (type);
4514 register enum tree_code code = TREE_CODE (exp);
4515 optab this_optab;
4516 /* Use subtarget as the target for operand 0 of a binary operation. */
4517 rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
4518 rtx original_target = target;
4519 /* Maybe defer this until sure not doing bytecode? */
4520 int ignore = (target == const0_rtx
4521 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
4522 || code == CONVERT_EXPR || code == REFERENCE_EXPR
4523 || code == COND_EXPR)
4524 && TREE_CODE (type) == VOID_TYPE));
4525 tree context;
4528 if (output_bytecode && modifier != EXPAND_INITIALIZER)
4530 bc_expand_expr (exp);
4531 return NULL;
4534 /* Don't use hard regs as subtargets, because the combiner
4535 can only handle pseudo regs. */
4536 if (subtarget && REGNO (subtarget) < FIRST_PSEUDO_REGISTER)
4537 subtarget = 0;
4538 /* Avoid subtargets inside loops,
4539 since they hide some invariant expressions. */
4540 if (preserve_subexpressions_p ())
4541 subtarget = 0;
4543 /* If we are going to ignore this result, we need only do something
4544 if there is a side-effect somewhere in the expression. If there
4545 is, short-circuit the most common cases here. Note that we must
4546 not call expand_expr with anything but const0_rtx in case this
4547 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
4549 if (ignore)
4551 if (! TREE_SIDE_EFFECTS (exp))
4552 return const0_rtx;
4554 /* Ensure we reference a volatile object even if value is ignored. */
4555 if (TREE_THIS_VOLATILE (exp)
4556 && TREE_CODE (exp) != FUNCTION_DECL
4557 && mode != VOIDmode && mode != BLKmode)
4559 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
4560 if (GET_CODE (temp) == MEM)
4561 temp = copy_to_reg (temp);
4562 return const0_rtx;
4565 if (TREE_CODE_CLASS (code) == '1')
4566 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
4567 VOIDmode, modifier);
4568 else if (TREE_CODE_CLASS (code) == '2'
4569 || TREE_CODE_CLASS (code) == '<')
4571 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
4572 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
4573 return const0_rtx;
4575 else if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
4576 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
4577 /* If the second operand has no side effects, just evaluate
4578 the first. */
4579 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
4580 VOIDmode, modifier);
4582 target = 0;
4585 /* If will do cse, generate all results into pseudo registers
4586 since 1) that allows cse to find more things
4587 and 2) otherwise cse could produce an insn the machine
4588 cannot support. */
4590 if (! cse_not_expected && mode != BLKmode && target
4591 && (GET_CODE (target) != REG || REGNO (target) < FIRST_PSEUDO_REGISTER))
4592 target = subtarget;
4594 switch (code)
4596 case LABEL_DECL:
4598 tree function = decl_function_context (exp);
4599 /* Handle using a label in a containing function. */
4600 if (function != current_function_decl && function != 0)
4602 struct function *p = find_function_data (function);
4603 /* Allocate in the memory associated with the function
4604 that the label is in. */
4605 push_obstacks (p->function_obstack,
4606 p->function_maybepermanent_obstack);
4608 p->forced_labels = gen_rtx (EXPR_LIST, VOIDmode,
4609 label_rtx (exp), p->forced_labels);
4610 pop_obstacks ();
4612 else if (modifier == EXPAND_INITIALIZER)
4613 forced_labels = gen_rtx (EXPR_LIST, VOIDmode,
4614 label_rtx (exp), forced_labels);
4615 temp = gen_rtx (MEM, FUNCTION_MODE,
4616 gen_rtx (LABEL_REF, Pmode, label_rtx (exp)));
4617 if (function != current_function_decl && function != 0)
4618 LABEL_REF_NONLOCAL_P (XEXP (temp, 0)) = 1;
4619 return temp;
4622 case PARM_DECL:
4623 if (DECL_RTL (exp) == 0)
4625 error_with_decl (exp, "prior parameter's size depends on `%s'");
4626 return CONST0_RTX (mode);
4629 /* ... fall through ... */
4631 case VAR_DECL:
4632 /* If a static var's type was incomplete when the decl was written,
4633 but the type is complete now, lay out the decl now. */
4634 if (DECL_SIZE (exp) == 0 && TYPE_SIZE (TREE_TYPE (exp)) != 0
4635 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
4637 push_obstacks_nochange ();
4638 end_temporary_allocation ();
4639 layout_decl (exp, 0);
4640 PUT_MODE (DECL_RTL (exp), DECL_MODE (exp));
4641 pop_obstacks ();
4644 /* ... fall through ... */
4646 case FUNCTION_DECL:
4647 case RESULT_DECL:
4648 if (DECL_RTL (exp) == 0)
4649 abort ();
4651 /* Ensure variable marked as used even if it doesn't go through
4652 a parser. If it hasn't be used yet, write out an external
4653 definition. */
4654 if (! TREE_USED (exp))
4656 assemble_external (exp);
4657 TREE_USED (exp) = 1;
4660 /* Show we haven't gotten RTL for this yet. */
4661 temp = 0;
4663 /* Handle variables inherited from containing functions. */
4664 context = decl_function_context (exp);
4666 /* We treat inline_function_decl as an alias for the current function
4667 because that is the inline function whose vars, types, etc.
4668 are being merged into the current function.
4669 See expand_inline_function. */
4671 if (context != 0 && context != current_function_decl
4672 && context != inline_function_decl
4673 /* If var is static, we don't need a static chain to access it. */
4674 && ! (GET_CODE (DECL_RTL (exp)) == MEM
4675 && CONSTANT_P (XEXP (DECL_RTL (exp), 0))))
4677 rtx addr;
4679 /* Mark as non-local and addressable. */
4680 DECL_NONLOCAL (exp) = 1;
4681 mark_addressable (exp);
4682 if (GET_CODE (DECL_RTL (exp)) != MEM)
4683 abort ();
4684 addr = XEXP (DECL_RTL (exp), 0);
4685 if (GET_CODE (addr) == MEM)
4686 addr = gen_rtx (MEM, Pmode,
4687 fix_lexical_addr (XEXP (addr, 0), exp));
4688 else
4689 addr = fix_lexical_addr (addr, exp);
4690 temp = change_address (DECL_RTL (exp), mode, addr);
4693 /* This is the case of an array whose size is to be determined
4694 from its initializer, while the initializer is still being parsed.
4695 See expand_decl. */
4697 else if (GET_CODE (DECL_RTL (exp)) == MEM
4698 && GET_CODE (XEXP (DECL_RTL (exp), 0)) == REG)
4699 temp = change_address (DECL_RTL (exp), GET_MODE (DECL_RTL (exp)),
4700 XEXP (DECL_RTL (exp), 0));
4702 /* If DECL_RTL is memory, we are in the normal case and either
4703 the address is not valid or it is not a register and -fforce-addr
4704 is specified, get the address into a register. */
4706 else if (GET_CODE (DECL_RTL (exp)) == MEM
4707 && modifier != EXPAND_CONST_ADDRESS
4708 && modifier != EXPAND_SUM
4709 && modifier != EXPAND_INITIALIZER
4710 && (! memory_address_p (DECL_MODE (exp),
4711 XEXP (DECL_RTL (exp), 0))
4712 || (flag_force_addr
4713 && GET_CODE (XEXP (DECL_RTL (exp), 0)) != REG)))
4714 temp = change_address (DECL_RTL (exp), VOIDmode,
4715 copy_rtx (XEXP (DECL_RTL (exp), 0)));
4717 /* If we got something, return it. But first, set the alignment
4718 the address is a register. */
4719 if (temp != 0)
4721 if (GET_CODE (temp) == MEM && GET_CODE (XEXP (temp, 0)) == REG)
4722 mark_reg_pointer (XEXP (temp, 0),
4723 DECL_ALIGN (exp) / BITS_PER_UNIT);
4725 return temp;
4728 /* If the mode of DECL_RTL does not match that of the decl, it
4729 must be a promoted value. We return a SUBREG of the wanted mode,
4730 but mark it so that we know that it was already extended. */
4732 if (GET_CODE (DECL_RTL (exp)) == REG
4733 && GET_MODE (DECL_RTL (exp)) != mode)
4735 /* Get the signedness used for this variable. Ensure we get the
4736 same mode we got when the variable was declared. */
4737 if (GET_MODE (DECL_RTL (exp))
4738 != promote_mode (type, DECL_MODE (exp), &unsignedp, 0))
4739 abort ();
4741 temp = gen_rtx (SUBREG, mode, DECL_RTL (exp), 0);
4742 SUBREG_PROMOTED_VAR_P (temp) = 1;
4743 SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
4744 return temp;
4747 return DECL_RTL (exp);
4749 case INTEGER_CST:
4750 return immed_double_const (TREE_INT_CST_LOW (exp),
4751 TREE_INT_CST_HIGH (exp),
4752 mode);
4754 case CONST_DECL:
4755 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, 0);
4757 case REAL_CST:
4758 /* If optimized, generate immediate CONST_DOUBLE
4759 which will be turned into memory by reload if necessary.
4761 We used to force a register so that loop.c could see it. But
4762 this does not allow gen_* patterns to perform optimizations with
4763 the constants. It also produces two insns in cases like "x = 1.0;".
4764 On most machines, floating-point constants are not permitted in
4765 many insns, so we'd end up copying it to a register in any case.
4767 Now, we do the copying in expand_binop, if appropriate. */
4768 return immed_real_const (exp);
4770 case COMPLEX_CST:
4771 case STRING_CST:
4772 if (! TREE_CST_RTL (exp))
4773 output_constant_def (exp);
4775 /* TREE_CST_RTL probably contains a constant address.
4776 On RISC machines where a constant address isn't valid,
4777 make some insns to get that address into a register. */
4778 if (GET_CODE (TREE_CST_RTL (exp)) == MEM
4779 && modifier != EXPAND_CONST_ADDRESS
4780 && modifier != EXPAND_INITIALIZER
4781 && modifier != EXPAND_SUM
4782 && (! memory_address_p (mode, XEXP (TREE_CST_RTL (exp), 0))
4783 || (flag_force_addr
4784 && GET_CODE (XEXP (TREE_CST_RTL (exp), 0)) != REG)))
4785 return change_address (TREE_CST_RTL (exp), VOIDmode,
4786 copy_rtx (XEXP (TREE_CST_RTL (exp), 0)));
4787 return TREE_CST_RTL (exp);
4789 case SAVE_EXPR:
4790 context = decl_function_context (exp);
4792 /* We treat inline_function_decl as an alias for the current function
4793 because that is the inline function whose vars, types, etc.
4794 are being merged into the current function.
4795 See expand_inline_function. */
4796 if (context == current_function_decl || context == inline_function_decl)
4797 context = 0;
4799 /* If this is non-local, handle it. */
4800 if (context)
4802 temp = SAVE_EXPR_RTL (exp);
4803 if (temp && GET_CODE (temp) == REG)
4805 put_var_into_stack (exp);
4806 temp = SAVE_EXPR_RTL (exp);
4808 if (temp == 0 || GET_CODE (temp) != MEM)
4809 abort ();
4810 return change_address (temp, mode,
4811 fix_lexical_addr (XEXP (temp, 0), exp));
4813 if (SAVE_EXPR_RTL (exp) == 0)
4815 if (mode == VOIDmode)
4816 temp = const0_rtx;
4817 else
4818 temp = assign_temp (type, 0, 0, 0);
4820 SAVE_EXPR_RTL (exp) = temp;
4821 if (!optimize && GET_CODE (temp) == REG)
4822 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, temp,
4823 save_expr_regs);
4825 /* If the mode of TEMP does not match that of the expression, it
4826 must be a promoted value. We pass store_expr a SUBREG of the
4827 wanted mode but mark it so that we know that it was already
4828 extended. Note that `unsignedp' was modified above in
4829 this case. */
4831 if (GET_CODE (temp) == REG && GET_MODE (temp) != mode)
4833 temp = gen_rtx (SUBREG, mode, SAVE_EXPR_RTL (exp), 0);
4834 SUBREG_PROMOTED_VAR_P (temp) = 1;
4835 SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
4838 if (temp == const0_rtx)
4839 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
4840 else
4841 store_expr (TREE_OPERAND (exp, 0), temp, 0);
4844 /* If the mode of SAVE_EXPR_RTL does not match that of the expression, it
4845 must be a promoted value. We return a SUBREG of the wanted mode,
4846 but mark it so that we know that it was already extended. */
4848 if (GET_CODE (SAVE_EXPR_RTL (exp)) == REG
4849 && GET_MODE (SAVE_EXPR_RTL (exp)) != mode)
4851 /* Compute the signedness and make the proper SUBREG. */
4852 promote_mode (type, mode, &unsignedp, 0);
4853 temp = gen_rtx (SUBREG, mode, SAVE_EXPR_RTL (exp), 0);
4854 SUBREG_PROMOTED_VAR_P (temp) = 1;
4855 SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
4856 return temp;
4859 return SAVE_EXPR_RTL (exp);
4861 case PLACEHOLDER_EXPR:
4862 /* If there is an object on the head of the placeholder list,
4863 see if some object in it's references is of type TYPE. For
4864 further information, see tree.def. */
4865 if (placeholder_list)
4867 tree object;
4868 tree old_list = placeholder_list;
4870 for (object = TREE_PURPOSE (placeholder_list);
4871 (TYPE_MAIN_VARIANT (TREE_TYPE (object))
4872 != TYPE_MAIN_VARIANT (type))
4873 && (TREE_CODE_CLASS (TREE_CODE (object)) == 'r'
4874 || TREE_CODE_CLASS (TREE_CODE (object)) == '1'
4875 || TREE_CODE_CLASS (TREE_CODE (object)) == '2'
4876 || TREE_CODE_CLASS (TREE_CODE (object)) == 'e');
4877 object = TREE_OPERAND (object, 0))
4880 if (object != 0
4881 && (TYPE_MAIN_VARIANT (TREE_TYPE (object))
4882 == TYPE_MAIN_VARIANT (type)))
4884 /* Expand this object skipping the list entries before
4885 it was found in case it is also a PLACEHOLDER_EXPR.
4886 In that case, we want to translate it using subsequent
4887 entries. */
4888 placeholder_list = TREE_CHAIN (placeholder_list);
4889 temp = expand_expr (object, original_target, tmode, modifier);
4890 placeholder_list = old_list;
4891 return temp;
4895 /* We can't find the object or there was a missing WITH_RECORD_EXPR. */
4896 abort ();
4898 case WITH_RECORD_EXPR:
4899 /* Put the object on the placeholder list, expand our first operand,
4900 and pop the list. */
4901 placeholder_list = tree_cons (TREE_OPERAND (exp, 1), NULL_TREE,
4902 placeholder_list);
4903 target = expand_expr (TREE_OPERAND (exp, 0), original_target,
4904 tmode, modifier);
4905 placeholder_list = TREE_CHAIN (placeholder_list);
4906 return target;
4908 case EXIT_EXPR:
4909 expand_exit_loop_if_false (NULL_PTR,
4910 invert_truthvalue (TREE_OPERAND (exp, 0)));
4911 return const0_rtx;
4913 case LOOP_EXPR:
4914 push_temp_slots ();
4915 expand_start_loop (1);
4916 expand_expr_stmt (TREE_OPERAND (exp, 0));
4917 expand_end_loop ();
4918 pop_temp_slots ();
4920 return const0_rtx;
4922 case BIND_EXPR:
4924 tree vars = TREE_OPERAND (exp, 0);
4925 int vars_need_expansion = 0;
4927 /* Need to open a binding contour here because
4928 if there are any cleanups they most be contained here. */
4929 expand_start_bindings (0);
4931 /* Mark the corresponding BLOCK for output in its proper place. */
4932 if (TREE_OPERAND (exp, 2) != 0
4933 && ! TREE_USED (TREE_OPERAND (exp, 2)))
4934 insert_block (TREE_OPERAND (exp, 2));
4936 /* If VARS have not yet been expanded, expand them now. */
4937 while (vars)
4939 if (DECL_RTL (vars) == 0)
4941 vars_need_expansion = 1;
4942 expand_decl (vars);
4944 expand_decl_init (vars);
4945 vars = TREE_CHAIN (vars);
4948 temp = expand_expr (TREE_OPERAND (exp, 1), target, tmode, modifier);
4950 expand_end_bindings (TREE_OPERAND (exp, 0), 0, 0);
4952 return temp;
4955 case RTL_EXPR:
4956 if (RTL_EXPR_SEQUENCE (exp) == const0_rtx)
4957 abort ();
4958 emit_insns (RTL_EXPR_SEQUENCE (exp));
4959 RTL_EXPR_SEQUENCE (exp) = const0_rtx;
4960 preserve_rtl_expr_result (RTL_EXPR_RTL (exp));
4961 free_temps_for_rtl_expr (exp);
4962 return RTL_EXPR_RTL (exp);
4964 case CONSTRUCTOR:
4965 /* If we don't need the result, just ensure we evaluate any
4966 subexpressions. */
4967 if (ignore)
4969 tree elt;
4970 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
4971 expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
4972 return const0_rtx;
4975 /* All elts simple constants => refer to a constant in memory. But
4976 if this is a non-BLKmode mode, let it store a field at a time
4977 since that should make a CONST_INT or CONST_DOUBLE when we
4978 fold. Likewise, if we have a target we can use, it is best to
4979 store directly into the target unless the type is large enough
4980 that memcpy will be used. If we are making an initializer and
4981 all operands are constant, put it in memory as well. */
4982 else if ((TREE_STATIC (exp)
4983 && ((mode == BLKmode
4984 && ! (target != 0 && safe_from_p (target, exp)))
4985 || TREE_ADDRESSABLE (exp)
4986 || (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4987 && (move_by_pieces_ninsns
4988 (TREE_INT_CST_LOW (TYPE_SIZE (type))/BITS_PER_UNIT,
4989 TYPE_ALIGN (type) / BITS_PER_UNIT)
4990 > MOVE_RATIO)
4991 && ! mostly_zeros_p (exp))))
4992 || (modifier == EXPAND_INITIALIZER && TREE_CONSTANT (exp)))
4994 rtx constructor = output_constant_def (exp);
4995 if (modifier != EXPAND_CONST_ADDRESS
4996 && modifier != EXPAND_INITIALIZER
4997 && modifier != EXPAND_SUM
4998 && (! memory_address_p (GET_MODE (constructor),
4999 XEXP (constructor, 0))
5000 || (flag_force_addr
5001 && GET_CODE (XEXP (constructor, 0)) != REG)))
5002 constructor = change_address (constructor, VOIDmode,
5003 XEXP (constructor, 0));
5004 return constructor;
5007 else
5009 if (target == 0 || ! safe_from_p (target, exp))
5011 if (mode != BLKmode && ! TREE_ADDRESSABLE (exp))
5012 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
5013 else
5014 target = assign_temp (type, 0, 1, 1);
5017 if (TREE_READONLY (exp))
5019 if (GET_CODE (target) == MEM)
5020 target = change_address (target, GET_MODE (target),
5021 XEXP (target, 0));
5022 RTX_UNCHANGING_P (target) = 1;
5025 store_constructor (exp, target, 0);
5026 return target;
5029 case INDIRECT_REF:
5031 tree exp1 = TREE_OPERAND (exp, 0);
5032 tree exp2;
5034 /* A SAVE_EXPR as the address in an INDIRECT_EXPR is generated
5035 for *PTR += ANYTHING where PTR is put inside the SAVE_EXPR.
5036 This code has the same general effect as simply doing
5037 expand_expr on the save expr, except that the expression PTR
5038 is computed for use as a memory address. This means different
5039 code, suitable for indexing, may be generated. */
5040 if (TREE_CODE (exp1) == SAVE_EXPR
5041 && SAVE_EXPR_RTL (exp1) == 0
5042 && TYPE_MODE (TREE_TYPE (exp1)) == ptr_mode)
5044 temp = expand_expr (TREE_OPERAND (exp1, 0), NULL_RTX,
5045 VOIDmode, EXPAND_SUM);
5046 op0 = memory_address (mode, temp);
5047 op0 = copy_all_regs (op0);
5048 SAVE_EXPR_RTL (exp1) = op0;
5050 else
5052 op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
5053 op0 = memory_address (mode, op0);
5056 temp = gen_rtx (MEM, mode, op0);
5057 /* If address was computed by addition,
5058 mark this as an element of an aggregate. */
5059 if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
5060 || (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR
5061 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == PLUS_EXPR)
5062 || AGGREGATE_TYPE_P (TREE_TYPE (exp))
5063 || (TREE_CODE (exp1) == ADDR_EXPR
5064 && (exp2 = TREE_OPERAND (exp1, 0))
5065 && AGGREGATE_TYPE_P (TREE_TYPE (exp2))))
5066 MEM_IN_STRUCT_P (temp) = 1;
5067 MEM_VOLATILE_P (temp) = TREE_THIS_VOLATILE (exp) | flag_volatile;
5069 /* It is incorrect to set RTX_UNCHANGING_P from TREE_READONLY
5070 here, because, in C and C++, the fact that a location is accessed
5071 through a pointer to const does not mean that the value there can
5072 never change. Languages where it can never change should
5073 also set TREE_STATIC. */
5074 RTX_UNCHANGING_P (temp) = TREE_READONLY (exp) & TREE_STATIC (exp);
5075 return temp;
5078 case ARRAY_REF:
5079 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) != ARRAY_TYPE)
5080 abort ();
5083 tree array = TREE_OPERAND (exp, 0);
5084 tree domain = TYPE_DOMAIN (TREE_TYPE (array));
5085 tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
5086 tree index = TREE_OPERAND (exp, 1);
5087 tree index_type = TREE_TYPE (index);
5088 int i;
5090 if (TREE_CODE (low_bound) != INTEGER_CST
5091 && contains_placeholder_p (low_bound))
5092 low_bound = build (WITH_RECORD_EXPR, sizetype, low_bound, exp);
5094 /* Optimize the special-case of a zero lower bound.
5096 We convert the low_bound to sizetype to avoid some problems
5097 with constant folding. (E.g. suppose the lower bound is 1,
5098 and its mode is QI. Without the conversion, (ARRAY
5099 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
5100 +INDEX), which becomes (ARRAY+255+INDEX). Oops!)
5102 But sizetype isn't quite right either (especially if
5103 the lowbound is negative). FIXME */
5105 if (! integer_zerop (low_bound))
5106 index = fold (build (MINUS_EXPR, index_type, index,
5107 convert (sizetype, low_bound)));
5109 if ((TREE_CODE (index) != INTEGER_CST
5110 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5111 && (! SLOW_UNALIGNED_ACCESS || ! get_inner_unaligned_p (exp)))
5113 /* Nonconstant array index or nonconstant element size, and
5114 not an array in an unaligned (packed) structure field.
5115 Generate the tree for *(&array+index) and expand that,
5116 except do it in a language-independent way
5117 and don't complain about non-lvalue arrays.
5118 `mark_addressable' should already have been called
5119 for any array for which this case will be reached. */
5121 /* Don't forget the const or volatile flag from the array
5122 element. */
5123 tree variant_type = build_type_variant (type,
5124 TREE_READONLY (exp),
5125 TREE_THIS_VOLATILE (exp));
5126 tree array_adr = build1 (ADDR_EXPR,
5127 build_pointer_type (variant_type), array);
5128 tree elt;
5129 tree size = size_in_bytes (type);
5131 /* Convert the integer argument to a type the same size as sizetype
5132 so the multiply won't overflow spuriously. */
5133 if (TYPE_PRECISION (index_type) != TYPE_PRECISION (sizetype))
5134 index = convert (type_for_size (TYPE_PRECISION (sizetype), 0),
5135 index);
5137 if (TREE_CODE (size) != INTEGER_CST
5138 && contains_placeholder_p (size))
5139 size = build (WITH_RECORD_EXPR, sizetype, size, exp);
5141 /* Don't think the address has side effects
5142 just because the array does.
5143 (In some cases the address might have side effects,
5144 and we fail to record that fact here. However, it should not
5145 matter, since expand_expr should not care.) */
5146 TREE_SIDE_EFFECTS (array_adr) = 0;
5149 = build1
5150 (INDIRECT_REF, type,
5151 fold (build (PLUS_EXPR,
5152 TYPE_POINTER_TO (variant_type),
5153 array_adr,
5154 fold
5155 (build1
5156 (NOP_EXPR,
5157 TYPE_POINTER_TO (variant_type),
5158 fold (build (MULT_EXPR, TREE_TYPE (index),
5159 index,
5160 convert (TREE_TYPE (index),
5161 size))))))));;
5163 /* Volatility, etc., of new expression is same as old
5164 expression. */
5165 TREE_SIDE_EFFECTS (elt) = TREE_SIDE_EFFECTS (exp);
5166 TREE_THIS_VOLATILE (elt) = TREE_THIS_VOLATILE (exp);
5167 TREE_READONLY (elt) = TREE_READONLY (exp);
5169 return expand_expr (elt, target, tmode, modifier);
5172 /* Fold an expression like: "foo"[2].
5173 This is not done in fold so it won't happen inside &.
5174 Don't fold if this is for wide characters since it's too
5175 difficult to do correctly and this is a very rare case. */
5177 if (TREE_CODE (array) == STRING_CST
5178 && TREE_CODE (index) == INTEGER_CST
5179 && !TREE_INT_CST_HIGH (index)
5180 && (i = TREE_INT_CST_LOW (index)) < TREE_STRING_LENGTH (array)
5181 && GET_MODE_CLASS (mode) == MODE_INT
5182 && GET_MODE_SIZE (mode) == 1)
5183 return GEN_INT (TREE_STRING_POINTER (array)[i]);
5185 /* If this is a constant index into a constant array,
5186 just get the value from the array. Handle both the cases when
5187 we have an explicit constructor and when our operand is a variable
5188 that was declared const. */
5190 if (TREE_CODE (array) == CONSTRUCTOR && ! TREE_SIDE_EFFECTS (array))
5192 if (TREE_CODE (index) == INTEGER_CST
5193 && TREE_INT_CST_HIGH (index) == 0)
5195 tree elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0));
5197 i = TREE_INT_CST_LOW (index);
5198 while (elem && i--)
5199 elem = TREE_CHAIN (elem);
5200 if (elem)
5201 return expand_expr (fold (TREE_VALUE (elem)), target,
5202 tmode, modifier);
5206 else if (optimize >= 1
5207 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
5208 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
5209 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK)
5211 if (TREE_CODE (index) == INTEGER_CST
5212 && TREE_INT_CST_HIGH (index) == 0)
5214 tree init = DECL_INITIAL (array);
5216 i = TREE_INT_CST_LOW (index);
5217 if (TREE_CODE (init) == CONSTRUCTOR)
5219 tree elem = CONSTRUCTOR_ELTS (init);
5221 while (elem
5222 && !tree_int_cst_equal (TREE_PURPOSE (elem), index))
5223 elem = TREE_CHAIN (elem);
5224 if (elem)
5225 return expand_expr (fold (TREE_VALUE (elem)), target,
5226 tmode, modifier);
5228 else if (TREE_CODE (init) == STRING_CST
5229 && i < TREE_STRING_LENGTH (init))
5230 return GEN_INT (TREE_STRING_POINTER (init)[i]);
5235 /* Treat array-ref with constant index as a component-ref. */
5237 case COMPONENT_REF:
5238 case BIT_FIELD_REF:
5239 /* If the operand is a CONSTRUCTOR, we can just extract the
5240 appropriate field if it is present. Don't do this if we have
5241 already written the data since we want to refer to that copy
5242 and varasm.c assumes that's what we'll do. */
5243 if (code != ARRAY_REF
5244 && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
5245 && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
5247 tree elt;
5249 for (elt = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)); elt;
5250 elt = TREE_CHAIN (elt))
5251 if (TREE_PURPOSE (elt) == TREE_OPERAND (exp, 1))
5252 return expand_expr (TREE_VALUE (elt), target, tmode, modifier);
5256 enum machine_mode mode1;
5257 int bitsize;
5258 int bitpos;
5259 tree offset;
5260 int volatilep = 0;
5261 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
5262 &mode1, &unsignedp, &volatilep);
5263 int alignment;
5265 /* If we got back the original object, something is wrong. Perhaps
5266 we are evaluating an expression too early. In any event, don't
5267 infinitely recurse. */
5268 if (tem == exp)
5269 abort ();
5271 /* If TEM's type is a union of variable size, pass TARGET to the inner
5272 computation, since it will need a temporary and TARGET is known
5273 to have to do. This occurs in unchecked conversion in Ada. */
5275 op0 = expand_expr (tem,
5276 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
5277 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
5278 != INTEGER_CST)
5279 ? target : NULL_RTX),
5280 VOIDmode,
5281 modifier == EXPAND_INITIALIZER ? modifier : 0);
5283 /* If this is a constant, put it into a register if it is a
5284 legitimate constant and memory if it isn't. */
5285 if (CONSTANT_P (op0))
5287 enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
5288 if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0))
5289 op0 = force_reg (mode, op0);
5290 else
5291 op0 = validize_mem (force_const_mem (mode, op0));
5294 alignment = TYPE_ALIGN (TREE_TYPE (tem)) / BITS_PER_UNIT;
5295 if (offset != 0)
5297 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
5299 if (GET_CODE (op0) != MEM)
5300 abort ();
5301 op0 = change_address (op0, VOIDmode,
5302 gen_rtx (PLUS, ptr_mode, XEXP (op0, 0),
5303 force_reg (ptr_mode, offset_rtx)));
5304 /* If we have a variable offset, the known alignment
5305 is only that of the innermost structure containing the field.
5306 (Actually, we could sometimes do better by using the
5307 size of an element of the innermost array, but no need.) */
5308 if (TREE_CODE (exp) == COMPONENT_REF
5309 || TREE_CODE (exp) == BIT_FIELD_REF)
5310 alignment = (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
5311 / BITS_PER_UNIT);
5314 /* Don't forget about volatility even if this is a bitfield. */
5315 if (GET_CODE (op0) == MEM && volatilep && ! MEM_VOLATILE_P (op0))
5317 op0 = copy_rtx (op0);
5318 MEM_VOLATILE_P (op0) = 1;
5321 /* In cases where an aligned union has an unaligned object
5322 as a field, we might be extracting a BLKmode value from
5323 an integer-mode (e.g., SImode) object. Handle this case
5324 by doing the extract into an object as wide as the field
5325 (which we know to be the width of a basic mode), then
5326 storing into memory, and changing the mode to BLKmode. */
5327 if (mode1 == VOIDmode
5328 || GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
5329 || (modifier != EXPAND_CONST_ADDRESS
5330 && modifier != EXPAND_SUM
5331 && modifier != EXPAND_INITIALIZER
5332 && ((mode1 != BLKmode && ! direct_load[(int) mode1])
5333 /* If the field isn't aligned enough to fetch as a memref,
5334 fetch it as a bit field. */
5335 || (SLOW_UNALIGNED_ACCESS
5336 && ((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode))
5337 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0))))))
5339 enum machine_mode ext_mode = mode;
5341 if (ext_mode == BLKmode)
5342 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
5344 if (ext_mode == BLKmode)
5345 abort ();
5347 op0 = validize_mem (op0);
5349 if (GET_CODE (op0) == MEM && GET_CODE (XEXP (op0, 0)) == REG)
5350 mark_reg_pointer (XEXP (op0, 0), alignment);
5352 op0 = extract_bit_field (op0, bitsize, bitpos,
5353 unsignedp, target, ext_mode, ext_mode,
5354 alignment,
5355 int_size_in_bytes (TREE_TYPE (tem)));
5356 if (mode == BLKmode)
5358 rtx new = assign_stack_temp (ext_mode,
5359 bitsize / BITS_PER_UNIT, 0);
5361 emit_move_insn (new, op0);
5362 op0 = copy_rtx (new);
5363 PUT_MODE (op0, BLKmode);
5364 MEM_IN_STRUCT_P (op0) = 1;
5367 return op0;
5370 /* If the result is BLKmode, use that to access the object
5371 now as well. */
5372 if (mode == BLKmode)
5373 mode1 = BLKmode;
5375 /* Get a reference to just this component. */
5376 if (modifier == EXPAND_CONST_ADDRESS
5377 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
5378 op0 = gen_rtx (MEM, mode1, plus_constant (XEXP (op0, 0),
5379 (bitpos / BITS_PER_UNIT)));
5380 else
5381 op0 = change_address (op0, mode1,
5382 plus_constant (XEXP (op0, 0),
5383 (bitpos / BITS_PER_UNIT)));
5384 if (GET_CODE (XEXP (op0, 0)) == REG)
5385 mark_reg_pointer (XEXP (op0, 0), alignment);
5387 MEM_IN_STRUCT_P (op0) = 1;
5388 MEM_VOLATILE_P (op0) |= volatilep;
5389 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode)
5390 return op0;
5391 if (target == 0)
5392 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
5393 convert_move (target, op0, unsignedp);
5394 return target;
5397 case OFFSET_REF:
5399 tree base = build1 (ADDR_EXPR, type, TREE_OPERAND (exp, 0));
5400 tree addr = build (PLUS_EXPR, type, base, TREE_OPERAND (exp, 1));
5401 op0 = expand_expr (addr, NULL_RTX, VOIDmode, EXPAND_SUM);
5402 temp = gen_rtx (MEM, mode, memory_address (mode, op0));
5403 MEM_IN_STRUCT_P (temp) = 1;
5404 MEM_VOLATILE_P (temp) = TREE_THIS_VOLATILE (exp);
5405 #if 0 /* It is incorrect to set RTX_UNCHANGING_P here, because the fact that
5406 a location is accessed through a pointer to const does not mean
5407 that the value there can never change. */
5408 RTX_UNCHANGING_P (temp) = TREE_READONLY (exp);
5409 #endif
5410 return temp;
5413 /* Intended for a reference to a buffer of a file-object in Pascal.
5414 But it's not certain that a special tree code will really be
5415 necessary for these. INDIRECT_REF might work for them. */
5416 case BUFFER_REF:
5417 abort ();
5419 case IN_EXPR:
5421 /* Pascal set IN expression.
5423 Algorithm:
5424 rlo = set_low - (set_low%bits_per_word);
5425 the_word = set [ (index - rlo)/bits_per_word ];
5426 bit_index = index % bits_per_word;
5427 bitmask = 1 << bit_index;
5428 return !!(the_word & bitmask); */
5430 tree set = TREE_OPERAND (exp, 0);
5431 tree index = TREE_OPERAND (exp, 1);
5432 int iunsignedp = TREE_UNSIGNED (TREE_TYPE (index));
5433 tree set_type = TREE_TYPE (set);
5434 tree set_low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (set_type));
5435 tree set_high_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (set_type));
5436 rtx index_val = expand_expr (index, 0, VOIDmode, 0);
5437 rtx lo_r = expand_expr (set_low_bound, 0, VOIDmode, 0);
5438 rtx hi_r = expand_expr (set_high_bound, 0, VOIDmode, 0);
5439 rtx setval = expand_expr (set, 0, VOIDmode, 0);
5440 rtx setaddr = XEXP (setval, 0);
5441 enum machine_mode index_mode = TYPE_MODE (TREE_TYPE (index));
5442 rtx rlow;
5443 rtx diff, quo, rem, addr, bit, result;
5445 preexpand_calls (exp);
5447 /* If domain is empty, answer is no. Likewise if index is constant
5448 and out of bounds. */
5449 if ((TREE_CODE (set_high_bound) == INTEGER_CST
5450 && TREE_CODE (set_low_bound) == INTEGER_CST
5451 && tree_int_cst_lt (set_high_bound, set_low_bound)
5452 || (TREE_CODE (index) == INTEGER_CST
5453 && TREE_CODE (set_low_bound) == INTEGER_CST
5454 && tree_int_cst_lt (index, set_low_bound))
5455 || (TREE_CODE (set_high_bound) == INTEGER_CST
5456 && TREE_CODE (index) == INTEGER_CST
5457 && tree_int_cst_lt (set_high_bound, index))))
5458 return const0_rtx;
5460 if (target == 0)
5461 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
5463 /* If we get here, we have to generate the code for both cases
5464 (in range and out of range). */
5466 op0 = gen_label_rtx ();
5467 op1 = gen_label_rtx ();
5469 if (! (GET_CODE (index_val) == CONST_INT
5470 && GET_CODE (lo_r) == CONST_INT))
5472 emit_cmp_insn (index_val, lo_r, LT, NULL_RTX,
5473 GET_MODE (index_val), iunsignedp, 0);
5474 emit_jump_insn (gen_blt (op1));
5477 if (! (GET_CODE (index_val) == CONST_INT
5478 && GET_CODE (hi_r) == CONST_INT))
5480 emit_cmp_insn (index_val, hi_r, GT, NULL_RTX,
5481 GET_MODE (index_val), iunsignedp, 0);
5482 emit_jump_insn (gen_bgt (op1));
5485 /* Calculate the element number of bit zero in the first word
5486 of the set. */
5487 if (GET_CODE (lo_r) == CONST_INT)
5488 rlow = GEN_INT (INTVAL (lo_r)
5489 & ~ ((HOST_WIDE_INT) 1 << BITS_PER_UNIT));
5490 else
5491 rlow = expand_binop (index_mode, and_optab, lo_r,
5492 GEN_INT (~((HOST_WIDE_INT) 1 << BITS_PER_UNIT)),
5493 NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
5495 diff = expand_binop (index_mode, sub_optab, index_val, rlow,
5496 NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
5498 quo = expand_divmod (0, TRUNC_DIV_EXPR, index_mode, diff,
5499 GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
5500 rem = expand_divmod (1, TRUNC_MOD_EXPR, index_mode, index_val,
5501 GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
5503 addr = memory_address (byte_mode,
5504 expand_binop (index_mode, add_optab, diff,
5505 setaddr, NULL_RTX, iunsignedp,
5506 OPTAB_LIB_WIDEN));
5508 /* Extract the bit we want to examine */
5509 bit = expand_shift (RSHIFT_EXPR, byte_mode,
5510 gen_rtx (MEM, byte_mode, addr),
5511 make_tree (TREE_TYPE (index), rem),
5512 NULL_RTX, 1);
5513 result = expand_binop (byte_mode, and_optab, bit, const1_rtx,
5514 GET_MODE (target) == byte_mode ? target : 0,
5515 1, OPTAB_LIB_WIDEN);
5517 if (result != target)
5518 convert_move (target, result, 1);
5520 /* Output the code to handle the out-of-range case. */
5521 emit_jump (op0);
5522 emit_label (op1);
5523 emit_move_insn (target, const0_rtx);
5524 emit_label (op0);
5525 return target;
5528 case WITH_CLEANUP_EXPR:
5529 if (RTL_EXPR_RTL (exp) == 0)
5531 RTL_EXPR_RTL (exp)
5532 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
5533 cleanups_this_call
5534 = tree_cons (NULL_TREE, TREE_OPERAND (exp, 2), cleanups_this_call);
5535 /* That's it for this cleanup. */
5536 TREE_OPERAND (exp, 2) = 0;
5537 (*interim_eh_hook) (NULL_TREE);
5539 return RTL_EXPR_RTL (exp);
5541 case CLEANUP_POINT_EXPR:
5543 extern int temp_slot_level;
5544 tree old_cleanups = cleanups_this_call;
5545 int old_temp_level = target_temp_slot_level;
5546 push_temp_slots ();
5547 target_temp_slot_level = temp_slot_level;
5548 op0 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
5549 /* If we're going to use this value, load it up now. */
5550 if (! ignore)
5551 op0 = force_not_mem (op0);
5552 expand_cleanups_to (old_cleanups);
5553 preserve_temp_slots (op0);
5554 free_temp_slots ();
5555 pop_temp_slots ();
5556 target_temp_slot_level = old_temp_level;
5558 return op0;
5560 case CALL_EXPR:
5561 /* Check for a built-in function. */
5562 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5563 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5564 == FUNCTION_DECL)
5565 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
5566 return expand_builtin (exp, target, subtarget, tmode, ignore);
5568 /* If this call was expanded already by preexpand_calls,
5569 just return the result we got. */
5570 if (CALL_EXPR_RTL (exp) != 0)
5571 return CALL_EXPR_RTL (exp);
5573 return expand_call (exp, target, ignore);
5575 case NON_LVALUE_EXPR:
5576 case NOP_EXPR:
5577 case CONVERT_EXPR:
5578 case REFERENCE_EXPR:
5579 if (TREE_CODE (type) == UNION_TYPE)
5581 tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
5582 if (target == 0)
5584 if (mode != BLKmode)
5585 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
5586 else
5587 target = assign_temp (type, 0, 1, 1);
5590 if (GET_CODE (target) == MEM)
5591 /* Store data into beginning of memory target. */
5592 store_expr (TREE_OPERAND (exp, 0),
5593 change_address (target, TYPE_MODE (valtype), 0), 0);
5595 else if (GET_CODE (target) == REG)
5596 /* Store this field into a union of the proper type. */
5597 store_field (target, GET_MODE_BITSIZE (TYPE_MODE (valtype)), 0,
5598 TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
5599 VOIDmode, 0, 1,
5600 int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0))));
5601 else
5602 abort ();
5604 /* Return the entire union. */
5605 return target;
5608 if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
5610 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
5611 modifier);
5613 /* If the signedness of the conversion differs and OP0 is
5614 a promoted SUBREG, clear that indication since we now
5615 have to do the proper extension. */
5616 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
5617 && GET_CODE (op0) == SUBREG)
5618 SUBREG_PROMOTED_VAR_P (op0) = 0;
5620 return op0;
5623 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, 0);
5624 if (GET_MODE (op0) == mode)
5625 return op0;
5627 /* If OP0 is a constant, just convert it into the proper mode. */
5628 if (CONSTANT_P (op0))
5629 return
5630 convert_modes (mode, TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
5631 op0, TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
5633 if (modifier == EXPAND_INITIALIZER)
5634 return gen_rtx (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
5636 if (target == 0)
5637 return
5638 convert_to_mode (mode, op0,
5639 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
5640 else
5641 convert_move (target, op0,
5642 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
5643 return target;
5645 case PLUS_EXPR:
5646 /* We come here from MINUS_EXPR when the second operand is a constant. */
5647 plus_expr:
5648 this_optab = add_optab;
5650 /* If we are adding a constant, an RTL_EXPR that is sp, fp, or ap, and
5651 something else, make sure we add the register to the constant and
5652 then to the other thing. This case can occur during strength
5653 reduction and doing it this way will produce better code if the
5654 frame pointer or argument pointer is eliminated.
5656 fold-const.c will ensure that the constant is always in the inner
5657 PLUS_EXPR, so the only case we need to do anything about is if
5658 sp, ap, or fp is our second argument, in which case we must swap
5659 the innermost first argument and our second argument. */
5661 if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
5662 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
5663 && TREE_CODE (TREE_OPERAND (exp, 1)) == RTL_EXPR
5664 && (RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
5665 || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
5666 || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
5668 tree t = TREE_OPERAND (exp, 1);
5670 TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5671 TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
5674 /* If the result is to be ptr_mode and we are adding an integer to
5675 something, we might be forming a constant. So try to use
5676 plus_constant. If it produces a sum and we can't accept it,
5677 use force_operand. This allows P = &ARR[const] to generate
5678 efficient code on machines where a SYMBOL_REF is not a valid
5679 address.
5681 If this is an EXPAND_SUM call, always return the sum. */
5682 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
5683 || mode == ptr_mode)
5685 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
5686 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
5687 && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
5689 op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
5690 EXPAND_SUM);
5691 op1 = plus_constant (op1, TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)));
5692 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
5693 op1 = force_operand (op1, target);
5694 return op1;
5697 else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
5698 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
5699 && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
5701 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
5702 EXPAND_SUM);
5703 if (! CONSTANT_P (op0))
5705 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
5706 VOIDmode, modifier);
5707 /* Don't go to both_summands if modifier
5708 says it's not right to return a PLUS. */
5709 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
5710 goto binop2;
5711 goto both_summands;
5713 op0 = plus_constant (op0, TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)));
5714 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
5715 op0 = force_operand (op0, target);
5716 return op0;
5720 /* No sense saving up arithmetic to be done
5721 if it's all in the wrong mode to form part of an address.
5722 And force_operand won't know whether to sign-extend or
5723 zero-extend. */
5724 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
5725 || mode != ptr_mode)
5726 goto binop;
5728 preexpand_calls (exp);
5729 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
5730 subtarget = 0;
5732 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, modifier);
5733 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, modifier);
5735 both_summands:
5736 /* Make sure any term that's a sum with a constant comes last. */
5737 if (GET_CODE (op0) == PLUS
5738 && CONSTANT_P (XEXP (op0, 1)))
5740 temp = op0;
5741 op0 = op1;
5742 op1 = temp;
5744 /* If adding to a sum including a constant,
5745 associate it to put the constant outside. */
5746 if (GET_CODE (op1) == PLUS
5747 && CONSTANT_P (XEXP (op1, 1)))
5749 rtx constant_term = const0_rtx;
5751 temp = simplify_binary_operation (PLUS, mode, XEXP (op1, 0), op0);
5752 if (temp != 0)
5753 op0 = temp;
5754 /* Ensure that MULT comes first if there is one. */
5755 else if (GET_CODE (op0) == MULT)
5756 op0 = gen_rtx (PLUS, mode, op0, XEXP (op1, 0));
5757 else
5758 op0 = gen_rtx (PLUS, mode, XEXP (op1, 0), op0);
5760 /* Let's also eliminate constants from op0 if possible. */
5761 op0 = eliminate_constant_term (op0, &constant_term);
5763 /* CONSTANT_TERM and XEXP (op1, 1) are known to be constant, so
5764 their sum should be a constant. Form it into OP1, since the
5765 result we want will then be OP0 + OP1. */
5767 temp = simplify_binary_operation (PLUS, mode, constant_term,
5768 XEXP (op1, 1));
5769 if (temp != 0)
5770 op1 = temp;
5771 else
5772 op1 = gen_rtx (PLUS, mode, constant_term, XEXP (op1, 1));
5775 /* Put a constant term last and put a multiplication first. */
5776 if (CONSTANT_P (op0) || GET_CODE (op1) == MULT)
5777 temp = op1, op1 = op0, op0 = temp;
5779 temp = simplify_binary_operation (PLUS, mode, op0, op1);
5780 return temp ? temp : gen_rtx (PLUS, mode, op0, op1);
5782 case MINUS_EXPR:
5783 /* For initializers, we are allowed to return a MINUS of two
5784 symbolic constants. Here we handle all cases when both operands
5785 are constant. */
5786 /* Handle difference of two symbolic constants,
5787 for the sake of an initializer. */
5788 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
5789 && really_constant_p (TREE_OPERAND (exp, 0))
5790 && really_constant_p (TREE_OPERAND (exp, 1)))
5792 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX,
5793 VOIDmode, modifier);
5794 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
5795 VOIDmode, modifier);
5797 /* If the last operand is a CONST_INT, use plus_constant of
5798 the negated constant. Else make the MINUS. */
5799 if (GET_CODE (op1) == CONST_INT)
5800 return plus_constant (op0, - INTVAL (op1));
5801 else
5802 return gen_rtx (MINUS, mode, op0, op1);
5804 /* Convert A - const to A + (-const). */
5805 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
5807 tree negated = fold (build1 (NEGATE_EXPR, type,
5808 TREE_OPERAND (exp, 1)));
5810 /* Deal with the case where we can't negate the constant
5811 in TYPE. */
5812 if (TREE_UNSIGNED (type) || TREE_OVERFLOW (negated))
5814 tree newtype = signed_type (type);
5815 tree newop0 = convert (newtype, TREE_OPERAND (exp, 0));
5816 tree newop1 = convert (newtype, TREE_OPERAND (exp, 1));
5817 tree newneg = fold (build1 (NEGATE_EXPR, newtype, newop1));
5819 if (! TREE_OVERFLOW (newneg))
5820 return expand_expr (convert (type,
5821 build (PLUS_EXPR, newtype,
5822 newop0, newneg)),
5823 target, tmode, modifier);
5825 else
5827 exp = build (PLUS_EXPR, type, TREE_OPERAND (exp, 0), negated);
5828 goto plus_expr;
5831 this_optab = sub_optab;
5832 goto binop;
5834 case MULT_EXPR:
5835 preexpand_calls (exp);
5836 /* If first operand is constant, swap them.
5837 Thus the following special case checks need only
5838 check the second operand. */
5839 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
5841 register tree t1 = TREE_OPERAND (exp, 0);
5842 TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
5843 TREE_OPERAND (exp, 1) = t1;
5846 /* Attempt to return something suitable for generating an
5847 indexed address, for machines that support that. */
5849 if (modifier == EXPAND_SUM && mode == ptr_mode
5850 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
5851 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
5853 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, EXPAND_SUM);
5855 /* Apply distributive law if OP0 is x+c. */
5856 if (GET_CODE (op0) == PLUS
5857 && GET_CODE (XEXP (op0, 1)) == CONST_INT)
5858 return gen_rtx (PLUS, mode,
5859 gen_rtx (MULT, mode, XEXP (op0, 0),
5860 GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))),
5861 GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))
5862 * INTVAL (XEXP (op0, 1))));
5864 if (GET_CODE (op0) != REG)
5865 op0 = force_operand (op0, NULL_RTX);
5866 if (GET_CODE (op0) != REG)
5867 op0 = copy_to_mode_reg (mode, op0);
5869 return gen_rtx (MULT, mode, op0,
5870 GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))));
5873 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
5874 subtarget = 0;
5876 /* Check for multiplying things that have been extended
5877 from a narrower type. If this machine supports multiplying
5878 in that narrower type with a result in the desired type,
5879 do it that way, and avoid the explicit type-conversion. */
5880 if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
5881 && TREE_CODE (type) == INTEGER_TYPE
5882 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
5883 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
5884 && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
5885 && int_fits_type_p (TREE_OPERAND (exp, 1),
5886 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
5887 /* Don't use a widening multiply if a shift will do. */
5888 && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
5889 > HOST_BITS_PER_WIDE_INT)
5890 || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
5892 (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
5893 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
5895 TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
5896 /* If both operands are extended, they must either both
5897 be zero-extended or both be sign-extended. */
5898 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
5900 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
5902 enum machine_mode innermode
5903 = TYPE_MODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)));
5904 optab other_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
5905 ? smul_widen_optab : umul_widen_optab);
5906 this_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
5907 ? umul_widen_optab : smul_widen_optab);
5908 if (mode == GET_MODE_WIDER_MODE (innermode))
5910 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
5912 op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
5913 NULL_RTX, VOIDmode, 0);
5914 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
5915 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
5916 VOIDmode, 0);
5917 else
5918 op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
5919 NULL_RTX, VOIDmode, 0);
5920 goto binop2;
5922 else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
5923 && innermode == word_mode)
5925 rtx htem;
5926 op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
5927 NULL_RTX, VOIDmode, 0);
5928 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
5929 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
5930 VOIDmode, 0);
5931 else
5932 op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
5933 NULL_RTX, VOIDmode, 0);
5934 temp = expand_binop (mode, other_optab, op0, op1, target,
5935 unsignedp, OPTAB_LIB_WIDEN);
5936 htem = expand_mult_highpart_adjust (innermode,
5937 gen_highpart (innermode, temp),
5938 op0, op1,
5939 gen_highpart (innermode, temp),
5940 unsignedp);
5941 emit_move_insn (gen_highpart (innermode, temp), htem);
5942 return temp;
5946 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
5947 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
5948 return expand_mult (mode, op0, op1, target, unsignedp);
5950 case TRUNC_DIV_EXPR:
5951 case FLOOR_DIV_EXPR:
5952 case CEIL_DIV_EXPR:
5953 case ROUND_DIV_EXPR:
5954 case EXACT_DIV_EXPR:
5955 preexpand_calls (exp);
5956 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
5957 subtarget = 0;
5958 /* Possible optimization: compute the dividend with EXPAND_SUM
5959 then if the divisor is constant can optimize the case
5960 where some terms of the dividend have coeffs divisible by it. */
5961 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
5962 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
5963 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
5965 case RDIV_EXPR:
5966 this_optab = flodiv_optab;
5967 goto binop;
5969 case TRUNC_MOD_EXPR:
5970 case FLOOR_MOD_EXPR:
5971 case CEIL_MOD_EXPR:
5972 case ROUND_MOD_EXPR:
5973 preexpand_calls (exp);
5974 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
5975 subtarget = 0;
5976 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
5977 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
5978 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
5980 case FIX_ROUND_EXPR:
5981 case FIX_FLOOR_EXPR:
5982 case FIX_CEIL_EXPR:
5983 abort (); /* Not used for C. */
5985 case FIX_TRUNC_EXPR:
5986 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
5987 if (target == 0)
5988 target = gen_reg_rtx (mode);
5989 expand_fix (target, op0, unsignedp);
5990 return target;
5992 case FLOAT_EXPR:
5993 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
5994 if (target == 0)
5995 target = gen_reg_rtx (mode);
5996 /* expand_float can't figure out what to do if FROM has VOIDmode.
5997 So give it the correct mode. With -O, cse will optimize this. */
5998 if (GET_MODE (op0) == VOIDmode)
5999 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
6000 op0);
6001 expand_float (target, op0,
6002 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
6003 return target;
6005 case NEGATE_EXPR:
6006 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6007 temp = expand_unop (mode, neg_optab, op0, target, 0);
6008 if (temp == 0)
6009 abort ();
6010 return temp;
6012 case ABS_EXPR:
6013 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6015 /* Handle complex values specially. */
6016 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
6017 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
6018 return expand_complex_abs (mode, op0, target, unsignedp);
6020 /* Unsigned abs is simply the operand. Testing here means we don't
6021 risk generating incorrect code below. */
6022 if (TREE_UNSIGNED (type))
6023 return op0;
6025 return expand_abs (mode, op0, target, unsignedp,
6026 safe_from_p (target, TREE_OPERAND (exp, 0)));
6028 case MAX_EXPR:
6029 case MIN_EXPR:
6030 target = original_target;
6031 if (target == 0 || ! safe_from_p (target, TREE_OPERAND (exp, 1))
6032 || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
6033 || GET_MODE (target) != mode
6034 || (GET_CODE (target) == REG
6035 && REGNO (target) < FIRST_PSEUDO_REGISTER))
6036 target = gen_reg_rtx (mode);
6037 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6038 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
6040 /* First try to do it with a special MIN or MAX instruction.
6041 If that does not win, use a conditional jump to select the proper
6042 value. */
6043 this_optab = (TREE_UNSIGNED (type)
6044 ? (code == MIN_EXPR ? umin_optab : umax_optab)
6045 : (code == MIN_EXPR ? smin_optab : smax_optab));
6047 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
6048 OPTAB_WIDEN);
6049 if (temp != 0)
6050 return temp;
6052 /* At this point, a MEM target is no longer useful; we will get better
6053 code without it. */
6055 if (GET_CODE (target) == MEM)
6056 target = gen_reg_rtx (mode);
6058 if (target != op0)
6059 emit_move_insn (target, op0);
6061 op0 = gen_label_rtx ();
6063 /* If this mode is an integer too wide to compare properly,
6064 compare word by word. Rely on cse to optimize constant cases. */
6065 if (GET_MODE_CLASS (mode) == MODE_INT && !can_compare_p (mode))
6067 if (code == MAX_EXPR)
6068 do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
6069 target, op1, NULL_RTX, op0);
6070 else
6071 do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
6072 op1, target, NULL_RTX, op0);
6073 emit_move_insn (target, op1);
6075 else
6077 if (code == MAX_EXPR)
6078 temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
6079 ? compare_from_rtx (target, op1, GEU, 1, mode, NULL_RTX, 0)
6080 : compare_from_rtx (target, op1, GE, 0, mode, NULL_RTX, 0));
6081 else
6082 temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
6083 ? compare_from_rtx (target, op1, LEU, 1, mode, NULL_RTX, 0)
6084 : compare_from_rtx (target, op1, LE, 0, mode, NULL_RTX, 0));
6085 if (temp == const0_rtx)
6086 emit_move_insn (target, op1);
6087 else if (temp != const_true_rtx)
6089 if (bcc_gen_fctn[(int) GET_CODE (temp)] != 0)
6090 emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (temp)]) (op0));
6091 else
6092 abort ();
6093 emit_move_insn (target, op1);
6096 emit_label (op0);
6097 return target;
6099 case BIT_NOT_EXPR:
6100 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6101 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
6102 if (temp == 0)
6103 abort ();
6104 return temp;
6106 case FFS_EXPR:
6107 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6108 temp = expand_unop (mode, ffs_optab, op0, target, 1);
6109 if (temp == 0)
6110 abort ();
6111 return temp;
6113 /* ??? Can optimize bitwise operations with one arg constant.
6114 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
6115 and (a bitwise1 b) bitwise2 b (etc)
6116 but that is probably not worth while. */
6118 /* BIT_AND_EXPR is for bitwise anding. TRUTH_AND_EXPR is for anding two
6119 boolean values when we want in all cases to compute both of them. In
6120 general it is fastest to do TRUTH_AND_EXPR by computing both operands
6121 as actual zero-or-1 values and then bitwise anding. In cases where
6122 there cannot be any side effects, better code would be made by
6123 treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
6124 how to recognize those cases. */
6126 case TRUTH_AND_EXPR:
6127 case BIT_AND_EXPR:
6128 this_optab = and_optab;
6129 goto binop;
6131 case TRUTH_OR_EXPR:
6132 case BIT_IOR_EXPR:
6133 this_optab = ior_optab;
6134 goto binop;
6136 case TRUTH_XOR_EXPR:
6137 case BIT_XOR_EXPR:
6138 this_optab = xor_optab;
6139 goto binop;
6141 case LSHIFT_EXPR:
6142 case RSHIFT_EXPR:
6143 case LROTATE_EXPR:
6144 case RROTATE_EXPR:
6145 preexpand_calls (exp);
6146 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
6147 subtarget = 0;
6148 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6149 return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
6150 unsignedp);
6152 /* Could determine the answer when only additive constants differ. Also,
6153 the addition of one can be handled by changing the condition. */
6154 case LT_EXPR:
6155 case LE_EXPR:
6156 case GT_EXPR:
6157 case GE_EXPR:
6158 case EQ_EXPR:
6159 case NE_EXPR:
6160 preexpand_calls (exp);
6161 temp = do_store_flag (exp, target, tmode != VOIDmode ? tmode : mode, 0);
6162 if (temp != 0)
6163 return temp;
6165 /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
6166 if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
6167 && original_target
6168 && GET_CODE (original_target) == REG
6169 && (GET_MODE (original_target)
6170 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6172 temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
6173 VOIDmode, 0);
6175 if (temp != original_target)
6176 temp = copy_to_reg (temp);
6178 op1 = gen_label_rtx ();
6179 emit_cmp_insn (temp, const0_rtx, EQ, NULL_RTX,
6180 GET_MODE (temp), unsignedp, 0);
6181 emit_jump_insn (gen_beq (op1));
6182 emit_move_insn (temp, const1_rtx);
6183 emit_label (op1);
6184 return temp;
6187 /* If no set-flag instruction, must generate a conditional
6188 store into a temporary variable. Drop through
6189 and handle this like && and ||. */
6191 case TRUTH_ANDIF_EXPR:
6192 case TRUTH_ORIF_EXPR:
6193 if (! ignore
6194 && (target == 0 || ! safe_from_p (target, exp)
6195 /* Make sure we don't have a hard reg (such as function's return
6196 value) live across basic blocks, if not optimizing. */
6197 || (!optimize && GET_CODE (target) == REG
6198 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
6199 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
6201 if (target)
6202 emit_clr_insn (target);
6204 op1 = gen_label_rtx ();
6205 jumpifnot (exp, op1);
6207 if (target)
6208 emit_0_to_1_insn (target);
6210 emit_label (op1);
6211 return ignore ? const0_rtx : target;
6213 case TRUTH_NOT_EXPR:
6214 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
6215 /* The parser is careful to generate TRUTH_NOT_EXPR
6216 only with operands that are always zero or one. */
6217 temp = expand_binop (mode, xor_optab, op0, const1_rtx,
6218 target, 1, OPTAB_LIB_WIDEN);
6219 if (temp == 0)
6220 abort ();
6221 return temp;
6223 case COMPOUND_EXPR:
6224 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
6225 emit_queue ();
6226 return expand_expr (TREE_OPERAND (exp, 1),
6227 (ignore ? const0_rtx : target),
6228 VOIDmode, 0);
6230 case COND_EXPR:
6232 rtx flag = NULL_RTX;
6233 tree left_cleanups = NULL_TREE;
6234 tree right_cleanups = NULL_TREE;
6236 /* Used to save a pointer to the place to put the setting of
6237 the flag that indicates if this side of the conditional was
6238 taken. We backpatch the code, if we find out later that we
6239 have any conditional cleanups that need to be performed. */
6240 rtx dest_right_flag = NULL_RTX;
6241 rtx dest_left_flag = NULL_RTX;
6243 /* Note that COND_EXPRs whose type is a structure or union
6244 are required to be constructed to contain assignments of
6245 a temporary variable, so that we can evaluate them here
6246 for side effect only. If type is void, we must do likewise. */
6248 /* If an arm of the branch requires a cleanup,
6249 only that cleanup is performed. */
6251 tree singleton = 0;
6252 tree binary_op = 0, unary_op = 0;
6253 tree old_cleanups = cleanups_this_call;
6255 /* If this is (A ? 1 : 0) and A is a condition, just evaluate it and
6256 convert it to our mode, if necessary. */
6257 if (integer_onep (TREE_OPERAND (exp, 1))
6258 && integer_zerop (TREE_OPERAND (exp, 2))
6259 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
6261 if (ignore)
6263 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6264 modifier);
6265 return const0_rtx;
6268 op0 = expand_expr (TREE_OPERAND (exp, 0), target, mode, modifier);
6269 if (GET_MODE (op0) == mode)
6270 return op0;
6272 if (target == 0)
6273 target = gen_reg_rtx (mode);
6274 convert_move (target, op0, unsignedp);
6275 return target;
6278 /* If we are not to produce a result, we have no target. Otherwise,
6279 if a target was specified use it; it will not be used as an
6280 intermediate target unless it is safe. If no target, use a
6281 temporary. */
6283 if (ignore)
6284 temp = 0;
6285 else if (original_target
6286 && safe_from_p (original_target, TREE_OPERAND (exp, 0))
6287 && GET_MODE (original_target) == mode
6288 && ! (GET_CODE (original_target) == MEM
6289 && MEM_VOLATILE_P (original_target)))
6290 temp = original_target;
6291 else
6292 temp = assign_temp (type, 0, 0, 1);
6294 /* Check for X ? A + B : A. If we have this, we can copy
6295 A to the output and conditionally add B. Similarly for unary
6296 operations. Don't do this if X has side-effects because
6297 those side effects might affect A or B and the "?" operation is
6298 a sequence point in ANSI. (We test for side effects later.) */
6300 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '2'
6301 && operand_equal_p (TREE_OPERAND (exp, 2),
6302 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
6303 singleton = TREE_OPERAND (exp, 2), binary_op = TREE_OPERAND (exp, 1);
6304 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '2'
6305 && operand_equal_p (TREE_OPERAND (exp, 1),
6306 TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
6307 singleton = TREE_OPERAND (exp, 1), binary_op = TREE_OPERAND (exp, 2);
6308 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '1'
6309 && operand_equal_p (TREE_OPERAND (exp, 2),
6310 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
6311 singleton = TREE_OPERAND (exp, 2), unary_op = TREE_OPERAND (exp, 1);
6312 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '1'
6313 && operand_equal_p (TREE_OPERAND (exp, 1),
6314 TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
6315 singleton = TREE_OPERAND (exp, 1), unary_op = TREE_OPERAND (exp, 2);
6317 /* If we had X ? A + 1 : A and we can do the test of X as a store-flag
6318 operation, do this as A + (X != 0). Similarly for other simple
6319 binary operators. */
6320 if (temp && singleton && binary_op
6321 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
6322 && (TREE_CODE (binary_op) == PLUS_EXPR
6323 || TREE_CODE (binary_op) == MINUS_EXPR
6324 || TREE_CODE (binary_op) == BIT_IOR_EXPR
6325 || TREE_CODE (binary_op) == BIT_XOR_EXPR)
6326 && integer_onep (TREE_OPERAND (binary_op, 1))
6327 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
6329 rtx result;
6330 optab boptab = (TREE_CODE (binary_op) == PLUS_EXPR ? add_optab
6331 : TREE_CODE (binary_op) == MINUS_EXPR ? sub_optab
6332 : TREE_CODE (binary_op) == BIT_IOR_EXPR ? ior_optab
6333 : xor_optab);
6335 /* If we had X ? A : A + 1, do this as A + (X == 0).
6337 We have to invert the truth value here and then put it
6338 back later if do_store_flag fails. We cannot simply copy
6339 TREE_OPERAND (exp, 0) to another variable and modify that
6340 because invert_truthvalue can modify the tree pointed to
6341 by its argument. */
6342 if (singleton == TREE_OPERAND (exp, 1))
6343 TREE_OPERAND (exp, 0)
6344 = invert_truthvalue (TREE_OPERAND (exp, 0));
6346 result = do_store_flag (TREE_OPERAND (exp, 0),
6347 (safe_from_p (temp, singleton)
6348 ? temp : NULL_RTX),
6349 mode, BRANCH_COST <= 1);
6351 if (result)
6353 op1 = expand_expr (singleton, NULL_RTX, VOIDmode, 0);
6354 return expand_binop (mode, boptab, op1, result, temp,
6355 unsignedp, OPTAB_LIB_WIDEN);
6357 else if (singleton == TREE_OPERAND (exp, 1))
6358 TREE_OPERAND (exp, 0)
6359 = invert_truthvalue (TREE_OPERAND (exp, 0));
6362 do_pending_stack_adjust ();
6363 NO_DEFER_POP;
6364 op0 = gen_label_rtx ();
6366 flag = gen_reg_rtx (word_mode);
6367 if (singleton && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0)))
6369 if (temp != 0)
6371 /* If the target conflicts with the other operand of the
6372 binary op, we can't use it. Also, we can't use the target
6373 if it is a hard register, because evaluating the condition
6374 might clobber it. */
6375 if ((binary_op
6376 && ! safe_from_p (temp, TREE_OPERAND (binary_op, 1)))
6377 || (GET_CODE (temp) == REG
6378 && REGNO (temp) < FIRST_PSEUDO_REGISTER))
6379 temp = gen_reg_rtx (mode);
6380 store_expr (singleton, temp, 0);
6382 else
6383 expand_expr (singleton,
6384 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
6385 dest_left_flag = get_last_insn ();
6386 if (singleton == TREE_OPERAND (exp, 1))
6387 jumpif (TREE_OPERAND (exp, 0), op0);
6388 else
6389 jumpifnot (TREE_OPERAND (exp, 0), op0);
6391 /* Allows cleanups up to here. */
6392 old_cleanups = cleanups_this_call;
6393 if (binary_op && temp == 0)
6394 /* Just touch the other operand. */
6395 expand_expr (TREE_OPERAND (binary_op, 1),
6396 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
6397 else if (binary_op)
6398 store_expr (build (TREE_CODE (binary_op), type,
6399 make_tree (type, temp),
6400 TREE_OPERAND (binary_op, 1)),
6401 temp, 0);
6402 else
6403 store_expr (build1 (TREE_CODE (unary_op), type,
6404 make_tree (type, temp)),
6405 temp, 0);
6406 op1 = op0;
6407 dest_right_flag = get_last_insn ();
6409 #if 0
6410 /* This is now done in jump.c and is better done there because it
6411 produces shorter register lifetimes. */
6413 /* Check for both possibilities either constants or variables
6414 in registers (but not the same as the target!). If so, can
6415 save branches by assigning one, branching, and assigning the
6416 other. */
6417 else if (temp && GET_MODE (temp) != BLKmode
6418 && (TREE_CONSTANT (TREE_OPERAND (exp, 1))
6419 || ((TREE_CODE (TREE_OPERAND (exp, 1)) == PARM_DECL
6420 || TREE_CODE (TREE_OPERAND (exp, 1)) == VAR_DECL)
6421 && DECL_RTL (TREE_OPERAND (exp, 1))
6422 && GET_CODE (DECL_RTL (TREE_OPERAND (exp, 1))) == REG
6423 && DECL_RTL (TREE_OPERAND (exp, 1)) != temp))
6424 && (TREE_CONSTANT (TREE_OPERAND (exp, 2))
6425 || ((TREE_CODE (TREE_OPERAND (exp, 2)) == PARM_DECL
6426 || TREE_CODE (TREE_OPERAND (exp, 2)) == VAR_DECL)
6427 && DECL_RTL (TREE_OPERAND (exp, 2))
6428 && GET_CODE (DECL_RTL (TREE_OPERAND (exp, 2))) == REG
6429 && DECL_RTL (TREE_OPERAND (exp, 2)) != temp)))
6431 if (GET_CODE (temp) == REG && REGNO (temp) < FIRST_PSEUDO_REGISTER)
6432 temp = gen_reg_rtx (mode);
6433 store_expr (TREE_OPERAND (exp, 2), temp, 0);
6434 dest_left_flag = get_last_insn ();
6435 jumpifnot (TREE_OPERAND (exp, 0), op0);
6437 /* Allows cleanups up to here. */
6438 old_cleanups = cleanups_this_call;
6439 store_expr (TREE_OPERAND (exp, 1), temp, 0);
6440 op1 = op0;
6441 dest_right_flag = get_last_insn ();
6443 #endif
6444 /* Check for A op 0 ? A : FOO and A op 0 ? FOO : A where OP is any
6445 comparison operator. If we have one of these cases, set the
6446 output to A, branch on A (cse will merge these two references),
6447 then set the output to FOO. */
6448 else if (temp
6449 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
6450 && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
6451 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
6452 TREE_OPERAND (exp, 1), 0)
6453 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
6454 && safe_from_p (temp, TREE_OPERAND (exp, 2)))
6456 if (GET_CODE (temp) == REG && REGNO (temp) < FIRST_PSEUDO_REGISTER)
6457 temp = gen_reg_rtx (mode);
6458 store_expr (TREE_OPERAND (exp, 1), temp, 0);
6459 dest_left_flag = get_last_insn ();
6460 jumpif (TREE_OPERAND (exp, 0), op0);
6462 /* Allows cleanups up to here. */
6463 old_cleanups = cleanups_this_call;
6464 store_expr (TREE_OPERAND (exp, 2), temp, 0);
6465 op1 = op0;
6466 dest_right_flag = get_last_insn ();
6468 else if (temp
6469 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
6470 && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
6471 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
6472 TREE_OPERAND (exp, 2), 0)
6473 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
6474 && safe_from_p (temp, TREE_OPERAND (exp, 1)))
6476 if (GET_CODE (temp) == REG && REGNO (temp) < FIRST_PSEUDO_REGISTER)
6477 temp = gen_reg_rtx (mode);
6478 store_expr (TREE_OPERAND (exp, 2), temp, 0);
6479 dest_left_flag = get_last_insn ();
6480 jumpifnot (TREE_OPERAND (exp, 0), op0);
6482 /* Allows cleanups up to here. */
6483 old_cleanups = cleanups_this_call;
6484 store_expr (TREE_OPERAND (exp, 1), temp, 0);
6485 op1 = op0;
6486 dest_right_flag = get_last_insn ();
6488 else
6490 op1 = gen_label_rtx ();
6491 jumpifnot (TREE_OPERAND (exp, 0), op0);
6493 /* Allows cleanups up to here. */
6494 old_cleanups = cleanups_this_call;
6495 if (temp != 0)
6496 store_expr (TREE_OPERAND (exp, 1), temp, 0);
6497 else
6498 expand_expr (TREE_OPERAND (exp, 1),
6499 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
6500 dest_left_flag = get_last_insn ();
6502 /* Handle conditional cleanups, if any. */
6503 left_cleanups = defer_cleanups_to (old_cleanups);
6505 emit_queue ();
6506 emit_jump_insn (gen_jump (op1));
6507 emit_barrier ();
6508 emit_label (op0);
6509 if (temp != 0)
6510 store_expr (TREE_OPERAND (exp, 2), temp, 0);
6511 else
6512 expand_expr (TREE_OPERAND (exp, 2),
6513 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
6514 dest_right_flag = get_last_insn ();
6517 /* Handle conditional cleanups, if any. */
6518 right_cleanups = defer_cleanups_to (old_cleanups);
6520 emit_queue ();
6521 emit_label (op1);
6522 OK_DEFER_POP;
6524 /* Add back in, any conditional cleanups. */
6525 if (left_cleanups || right_cleanups)
6527 tree new_cleanups;
6528 tree cond;
6529 rtx last;
6531 /* Now that we know that a flag is needed, go back and add in the
6532 setting of the flag. */
6534 /* Do the left side flag. */
6535 last = get_last_insn ();
6536 /* Flag left cleanups as needed. */
6537 emit_move_insn (flag, const1_rtx);
6538 /* ??? deprecated, use sequences instead. */
6539 reorder_insns (NEXT_INSN (last), get_last_insn (), dest_left_flag);
6541 /* Do the right side flag. */
6542 last = get_last_insn ();
6543 /* Flag left cleanups as needed. */
6544 emit_move_insn (flag, const0_rtx);
6545 /* ??? deprecated, use sequences instead. */
6546 reorder_insns (NEXT_INSN (last), get_last_insn (), dest_right_flag);
6548 /* All cleanups must be on the function_obstack. */
6549 push_obstacks_nochange ();
6550 resume_temporary_allocation ();
6552 /* convert flag, which is an rtx, into a tree. */
6553 cond = make_node (RTL_EXPR);
6554 TREE_TYPE (cond) = integer_type_node;
6555 RTL_EXPR_RTL (cond) = flag;
6556 RTL_EXPR_SEQUENCE (cond) = NULL_RTX;
6557 cond = save_expr (cond);
6559 if (! left_cleanups)
6560 left_cleanups = integer_zero_node;
6561 if (! right_cleanups)
6562 right_cleanups = integer_zero_node;
6563 new_cleanups = build (COND_EXPR, void_type_node,
6564 truthvalue_conversion (cond),
6565 left_cleanups, right_cleanups);
6566 new_cleanups = fold (new_cleanups);
6568 pop_obstacks ();
6570 /* Now add in the conditionalized cleanups. */
6571 cleanups_this_call
6572 = tree_cons (NULL_TREE, new_cleanups, cleanups_this_call);
6573 (*interim_eh_hook) (NULL_TREE);
6575 return temp;
6578 case TARGET_EXPR:
6580 int need_exception_region = 0;
6581 /* Something needs to be initialized, but we didn't know
6582 where that thing was when building the tree. For example,
6583 it could be the return value of a function, or a parameter
6584 to a function which lays down in the stack, or a temporary
6585 variable which must be passed by reference.
6587 We guarantee that the expression will either be constructed
6588 or copied into our original target. */
6590 tree slot = TREE_OPERAND (exp, 0);
6591 tree exp1;
6592 rtx temp;
6594 if (TREE_CODE (slot) != VAR_DECL)
6595 abort ();
6597 if (! ignore)
6598 target = original_target;
6600 if (target == 0)
6602 if (DECL_RTL (slot) != 0)
6604 target = DECL_RTL (slot);
6605 /* If we have already expanded the slot, so don't do
6606 it again. (mrs) */
6607 if (TREE_OPERAND (exp, 1) == NULL_TREE)
6608 return target;
6610 else
6612 target = assign_temp (type, 2, 1, 1);
6613 /* All temp slots at this level must not conflict. */
6614 preserve_temp_slots (target);
6615 DECL_RTL (slot) = target;
6617 /* Since SLOT is not known to the called function
6618 to belong to its stack frame, we must build an explicit
6619 cleanup. This case occurs when we must build up a reference
6620 to pass the reference as an argument. In this case,
6621 it is very likely that such a reference need not be
6622 built here. */
6624 if (TREE_OPERAND (exp, 2) == 0)
6625 TREE_OPERAND (exp, 2) = maybe_build_cleanup (slot);
6626 if (TREE_OPERAND (exp, 2))
6628 cleanups_this_call = tree_cons (NULL_TREE,
6629 TREE_OPERAND (exp, 2),
6630 cleanups_this_call);
6631 need_exception_region = 1;
6635 else
6637 /* This case does occur, when expanding a parameter which
6638 needs to be constructed on the stack. The target
6639 is the actual stack address that we want to initialize.
6640 The function we call will perform the cleanup in this case. */
6642 /* If we have already assigned it space, use that space,
6643 not target that we were passed in, as our target
6644 parameter is only a hint. */
6645 if (DECL_RTL (slot) != 0)
6647 target = DECL_RTL (slot);
6648 /* If we have already expanded the slot, so don't do
6649 it again. (mrs) */
6650 if (TREE_OPERAND (exp, 1) == NULL_TREE)
6651 return target;
6654 DECL_RTL (slot) = target;
6657 exp1 = TREE_OPERAND (exp, 1);
6658 /* Mark it as expanded. */
6659 TREE_OPERAND (exp, 1) = NULL_TREE;
6661 store_expr (exp1, target, 0);
6663 if (need_exception_region)
6664 (*interim_eh_hook) (NULL_TREE);
6666 return target;
6669 case INIT_EXPR:
6671 tree lhs = TREE_OPERAND (exp, 0);
6672 tree rhs = TREE_OPERAND (exp, 1);
6673 tree noncopied_parts = 0;
6674 tree lhs_type = TREE_TYPE (lhs);
6676 temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
6677 if (TYPE_NONCOPIED_PARTS (lhs_type) != 0 && !fixed_type_p (rhs))
6678 noncopied_parts = init_noncopied_parts (stabilize_reference (lhs),
6679 TYPE_NONCOPIED_PARTS (lhs_type));
6680 while (noncopied_parts != 0)
6682 expand_assignment (TREE_VALUE (noncopied_parts),
6683 TREE_PURPOSE (noncopied_parts), 0, 0);
6684 noncopied_parts = TREE_CHAIN (noncopied_parts);
6686 return temp;
6689 case MODIFY_EXPR:
6691 /* If lhs is complex, expand calls in rhs before computing it.
6692 That's so we don't compute a pointer and save it over a call.
6693 If lhs is simple, compute it first so we can give it as a
6694 target if the rhs is just a call. This avoids an extra temp and copy
6695 and that prevents a partial-subsumption which makes bad code.
6696 Actually we could treat component_ref's of vars like vars. */
6698 tree lhs = TREE_OPERAND (exp, 0);
6699 tree rhs = TREE_OPERAND (exp, 1);
6700 tree noncopied_parts = 0;
6701 tree lhs_type = TREE_TYPE (lhs);
6703 temp = 0;
6705 if (TREE_CODE (lhs) != VAR_DECL
6706 && TREE_CODE (lhs) != RESULT_DECL
6707 && TREE_CODE (lhs) != PARM_DECL)
6708 preexpand_calls (exp);
6710 /* Check for |= or &= of a bitfield of size one into another bitfield
6711 of size 1. In this case, (unless we need the result of the
6712 assignment) we can do this more efficiently with a
6713 test followed by an assignment, if necessary.
6715 ??? At this point, we can't get a BIT_FIELD_REF here. But if
6716 things change so we do, this code should be enhanced to
6717 support it. */
6718 if (ignore
6719 && TREE_CODE (lhs) == COMPONENT_REF
6720 && (TREE_CODE (rhs) == BIT_IOR_EXPR
6721 || TREE_CODE (rhs) == BIT_AND_EXPR)
6722 && TREE_OPERAND (rhs, 0) == lhs
6723 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
6724 && TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (lhs, 1))) == 1
6725 && TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))) == 1)
6727 rtx label = gen_label_rtx ();
6729 do_jump (TREE_OPERAND (rhs, 1),
6730 TREE_CODE (rhs) == BIT_IOR_EXPR ? label : 0,
6731 TREE_CODE (rhs) == BIT_AND_EXPR ? label : 0);
6732 expand_assignment (lhs, convert (TREE_TYPE (rhs),
6733 (TREE_CODE (rhs) == BIT_IOR_EXPR
6734 ? integer_one_node
6735 : integer_zero_node)),
6736 0, 0);
6737 do_pending_stack_adjust ();
6738 emit_label (label);
6739 return const0_rtx;
6742 if (TYPE_NONCOPIED_PARTS (lhs_type) != 0
6743 && ! (fixed_type_p (lhs) && fixed_type_p (rhs)))
6744 noncopied_parts = save_noncopied_parts (stabilize_reference (lhs),
6745 TYPE_NONCOPIED_PARTS (lhs_type));
6747 temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
6748 while (noncopied_parts != 0)
6750 expand_assignment (TREE_PURPOSE (noncopied_parts),
6751 TREE_VALUE (noncopied_parts), 0, 0);
6752 noncopied_parts = TREE_CHAIN (noncopied_parts);
6754 return temp;
6757 case PREINCREMENT_EXPR:
6758 case PREDECREMENT_EXPR:
6759 return expand_increment (exp, 0);
6761 case POSTINCREMENT_EXPR:
6762 case POSTDECREMENT_EXPR:
6763 /* Faster to treat as pre-increment if result is not used. */
6764 return expand_increment (exp, ! ignore);
6766 case ADDR_EXPR:
6767 /* If nonzero, TEMP will be set to the address of something that might
6768 be a MEM corresponding to a stack slot. */
6769 temp = 0;
6771 /* Are we taking the address of a nested function? */
6772 if (TREE_CODE (TREE_OPERAND (exp, 0)) == FUNCTION_DECL
6773 && decl_function_context (TREE_OPERAND (exp, 0)) != 0)
6775 op0 = trampoline_address (TREE_OPERAND (exp, 0));
6776 op0 = force_operand (op0, target);
6778 /* If we are taking the address of something erroneous, just
6779 return a zero. */
6780 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
6781 return const0_rtx;
6782 else
6784 /* We make sure to pass const0_rtx down if we came in with
6785 ignore set, to avoid doing the cleanups twice for something. */
6786 op0 = expand_expr (TREE_OPERAND (exp, 0),
6787 ignore ? const0_rtx : NULL_RTX, VOIDmode,
6788 (modifier == EXPAND_INITIALIZER
6789 ? modifier : EXPAND_CONST_ADDRESS));
6791 /* If we are going to ignore the result, OP0 will have been set
6792 to const0_rtx, so just return it. Don't get confused and
6793 think we are taking the address of the constant. */
6794 if (ignore)
6795 return op0;
6797 op0 = protect_from_queue (op0, 0);
6799 /* We would like the object in memory. If it is a constant,
6800 we can have it be statically allocated into memory. For
6801 a non-constant (REG, SUBREG or CONCAT), we need to allocate some
6802 memory and store the value into it. */
6804 if (CONSTANT_P (op0))
6805 op0 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
6806 op0);
6807 else if (GET_CODE (op0) == MEM)
6809 mark_temp_addr_taken (op0);
6810 temp = XEXP (op0, 0);
6813 else if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
6814 || GET_CODE (op0) == CONCAT)
6816 /* If this object is in a register, it must be not
6817 be BLKmode. */
6818 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
6819 rtx memloc = assign_temp (inner_type, 1, 1, 1);
6821 mark_temp_addr_taken (memloc);
6822 emit_move_insn (memloc, op0);
6823 op0 = memloc;
6826 if (GET_CODE (op0) != MEM)
6827 abort ();
6829 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
6831 temp = XEXP (op0, 0);
6832 #ifdef POINTERS_EXTEND_UNSIGNED
6833 if (GET_MODE (temp) == Pmode && GET_MODE (temp) != mode
6834 && mode == ptr_mode)
6835 temp = convert_memory_address (ptr_mode, temp);
6836 #endif
6837 return temp;
6840 op0 = force_operand (XEXP (op0, 0), target);
6843 if (flag_force_addr && GET_CODE (op0) != REG)
6844 op0 = force_reg (Pmode, op0);
6846 if (GET_CODE (op0) == REG
6847 && ! REG_USERVAR_P (op0))
6848 mark_reg_pointer (op0, TYPE_ALIGN (TREE_TYPE (type)) / BITS_PER_UNIT);
6850 /* If we might have had a temp slot, add an equivalent address
6851 for it. */
6852 if (temp != 0)
6853 update_temp_slot_address (temp, op0);
6855 #ifdef POINTERS_EXTEND_UNSIGNED
6856 if (GET_MODE (op0) == Pmode && GET_MODE (op0) != mode
6857 && mode == ptr_mode)
6858 op0 = convert_memory_address (ptr_mode, op0);
6859 #endif
6861 return op0;
6863 case ENTRY_VALUE_EXPR:
6864 abort ();
6866 /* COMPLEX type for Extended Pascal & Fortran */
6867 case COMPLEX_EXPR:
6869 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
6870 rtx insns;
6872 /* Get the rtx code of the operands. */
6873 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
6874 op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
6876 if (! target)
6877 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
6879 start_sequence ();
6881 /* Move the real (op0) and imaginary (op1) parts to their location. */
6882 emit_move_insn (gen_realpart (mode, target), op0);
6883 emit_move_insn (gen_imagpart (mode, target), op1);
6885 insns = get_insns ();
6886 end_sequence ();
6888 /* Complex construction should appear as a single unit. */
6889 /* If TARGET is a CONCAT, we got insns like RD = RS, ID = IS,
6890 each with a separate pseudo as destination.
6891 It's not correct for flow to treat them as a unit. */
6892 if (GET_CODE (target) != CONCAT)
6893 emit_no_conflict_block (insns, target, op0, op1, NULL_RTX);
6894 else
6895 emit_insns (insns);
6897 return target;
6900 case REALPART_EXPR:
6901 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
6902 return gen_realpart (mode, op0);
6904 case IMAGPART_EXPR:
6905 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
6906 return gen_imagpart (mode, op0);
6908 case CONJ_EXPR:
6910 enum machine_mode partmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
6911 rtx imag_t;
6912 rtx insns;
6914 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
6916 if (! target)
6917 target = gen_reg_rtx (mode);
6919 start_sequence ();
6921 /* Store the realpart and the negated imagpart to target. */
6922 emit_move_insn (gen_realpart (partmode, target),
6923 gen_realpart (partmode, op0));
6925 imag_t = gen_imagpart (partmode, target);
6926 temp = expand_unop (partmode, neg_optab,
6927 gen_imagpart (partmode, op0), imag_t, 0);
6928 if (temp != imag_t)
6929 emit_move_insn (imag_t, temp);
6931 insns = get_insns ();
6932 end_sequence ();
6934 /* Conjugate should appear as a single unit
6935 If TARGET is a CONCAT, we got insns like RD = RS, ID = - IS,
6936 each with a separate pseudo as destination.
6937 It's not correct for flow to treat them as a unit. */
6938 if (GET_CODE (target) != CONCAT)
6939 emit_no_conflict_block (insns, target, op0, NULL_RTX, NULL_RTX);
6940 else
6941 emit_insns (insns);
6943 return target;
6946 case ERROR_MARK:
6947 op0 = CONST0_RTX (tmode);
6948 if (op0 != 0)
6949 return op0;
6950 return const0_rtx;
6952 default:
6953 return (*lang_expand_expr) (exp, original_target, tmode, modifier);
6956 /* Here to do an ordinary binary operator, generating an instruction
6957 from the optab already placed in `this_optab'. */
6958 binop:
6959 preexpand_calls (exp);
6960 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1)))
6961 subtarget = 0;
6962 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6963 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6964 binop2:
6965 temp = expand_binop (mode, this_optab, op0, op1, target,
6966 unsignedp, OPTAB_LIB_WIDEN);
6967 if (temp == 0)
6968 abort ();
6969 return temp;
6973 /* Emit bytecode to evaluate the given expression EXP to the stack. */
6974 void
6975 bc_expand_expr (exp)
6976 tree exp;
6978 enum tree_code code;
6979 tree type, arg0;
6980 rtx r;
6981 struct binary_operator *binoptab;
6982 struct unary_operator *unoptab;
6983 struct increment_operator *incroptab;
6984 struct bc_label *lab, *lab1;
6985 enum bytecode_opcode opcode;
6988 code = TREE_CODE (exp);
6990 switch (code)
6992 case PARM_DECL:
6994 if (DECL_RTL (exp) == 0)
6996 error_with_decl (exp, "prior parameter's size depends on `%s'");
6997 return;
7000 bc_load_parmaddr (DECL_RTL (exp));
7001 bc_load_memory (TREE_TYPE (exp), exp);
7003 return;
7005 case VAR_DECL:
7007 if (DECL_RTL (exp) == 0)
7008 abort ();
7010 #if 0
7011 if (BYTECODE_LABEL (DECL_RTL (exp)))
7012 bc_load_externaddr (DECL_RTL (exp));
7013 else
7014 bc_load_localaddr (DECL_RTL (exp));
7015 #endif
7016 if (TREE_PUBLIC (exp))
7017 bc_load_externaddr_id (DECL_ASSEMBLER_NAME (exp),
7018 BYTECODE_BC_LABEL (DECL_RTL (exp))->offset);
7019 else
7020 bc_load_localaddr (DECL_RTL (exp));
7022 bc_load_memory (TREE_TYPE (exp), exp);
7023 return;
7025 case INTEGER_CST:
7027 #ifdef DEBUG_PRINT_CODE
7028 fprintf (stderr, " [%x]\n", TREE_INT_CST_LOW (exp));
7029 #endif
7030 bc_emit_instruction (mode_to_const_map[(int) (DECL_BIT_FIELD (exp)
7031 ? SImode
7032 : TYPE_MODE (TREE_TYPE (exp)))],
7033 (HOST_WIDE_INT) TREE_INT_CST_LOW (exp));
7034 return;
7036 case REAL_CST:
7038 #if 0
7039 #ifdef DEBUG_PRINT_CODE
7040 fprintf (stderr, " [%g]\n", (double) TREE_INT_CST_LOW (exp));
7041 #endif
7042 /* FIX THIS: find a better way to pass real_cst's. -bson */
7043 bc_emit_instruction (mode_to_const_map[TYPE_MODE (TREE_TYPE (exp))],
7044 (double) TREE_REAL_CST (exp));
7045 #else
7046 abort ();
7047 #endif
7049 return;
7051 case CALL_EXPR:
7053 /* We build a call description vector describing the type of
7054 the return value and of the arguments; this call vector,
7055 together with a pointer to a location for the return value
7056 and the base of the argument list, is passed to the low
7057 level machine dependent call subroutine, which is responsible
7058 for putting the arguments wherever real functions expect
7059 them, as well as getting the return value back. */
7061 tree calldesc = 0, arg;
7062 int nargs = 0, i;
7063 rtx retval;
7065 /* Push the evaluated args on the evaluation stack in reverse
7066 order. Also make an entry for each arg in the calldesc
7067 vector while we're at it. */
7069 TREE_OPERAND (exp, 1) = nreverse (TREE_OPERAND (exp, 1));
7071 for (arg = TREE_OPERAND (exp, 1); arg; arg = TREE_CHAIN (arg))
7073 ++nargs;
7074 bc_expand_expr (TREE_VALUE (arg));
7076 calldesc = tree_cons ((tree) 0,
7077 size_in_bytes (TREE_TYPE (TREE_VALUE (arg))),
7078 calldesc);
7079 calldesc = tree_cons ((tree) 0,
7080 bc_runtime_type_code (TREE_TYPE (TREE_VALUE (arg))),
7081 calldesc);
7084 TREE_OPERAND (exp, 1) = nreverse (TREE_OPERAND (exp, 1));
7086 /* Allocate a location for the return value and push its
7087 address on the evaluation stack. Also make an entry
7088 at the front of the calldesc for the return value type. */
7090 type = TREE_TYPE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
7091 retval = bc_allocate_local (int_size_in_bytes (type), TYPE_ALIGN (type));
7092 bc_load_localaddr (retval);
7094 calldesc = tree_cons ((tree) 0, size_in_bytes (type), calldesc);
7095 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (type), calldesc);
7097 /* Prepend the argument count. */
7098 calldesc = tree_cons ((tree) 0,
7099 build_int_2 (nargs, 0),
7100 calldesc);
7102 /* Push the address of the call description vector on the stack. */
7103 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
7104 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
7105 build_index_type (build_int_2 (nargs * 2, 0)));
7106 r = output_constant_def (calldesc);
7107 bc_load_externaddr (r);
7109 /* Push the address of the function to be called. */
7110 bc_expand_expr (TREE_OPERAND (exp, 0));
7112 /* Call the function, popping its address and the calldesc vector
7113 address off the evaluation stack in the process. */
7114 bc_emit_instruction (call);
7116 /* Pop the arguments off the stack. */
7117 bc_adjust_stack (nargs);
7119 /* Load the return value onto the stack. */
7120 bc_load_localaddr (retval);
7121 bc_load_memory (type, TREE_OPERAND (exp, 0));
7123 return;
7125 case SAVE_EXPR:
7127 if (!SAVE_EXPR_RTL (exp))
7129 /* First time around: copy to local variable */
7130 SAVE_EXPR_RTL (exp) = bc_allocate_local (int_size_in_bytes (TREE_TYPE (exp)),
7131 TYPE_ALIGN (TREE_TYPE(exp)));
7132 bc_expand_expr (TREE_OPERAND (exp, 0));
7133 bc_emit_instruction (duplicate);
7135 bc_load_localaddr (SAVE_EXPR_RTL (exp));
7136 bc_store_memory (TREE_TYPE (exp), TREE_OPERAND (exp, 0));
7138 else
7140 /* Consecutive reference: use saved copy */
7141 bc_load_localaddr (SAVE_EXPR_RTL (exp));
7142 bc_load_memory (TREE_TYPE (exp), TREE_OPERAND (exp, 0));
7144 return;
7146 #if 0
7147 /* FIXME: the XXXX_STMT codes have been removed in GCC2, but
7148 how are they handled instead? */
7149 case LET_STMT:
7151 TREE_USED (exp) = 1;
7152 bc_expand_expr (STMT_BODY (exp));
7153 return;
7154 #endif
7156 case NOP_EXPR:
7157 case CONVERT_EXPR:
7159 bc_expand_expr (TREE_OPERAND (exp, 0));
7160 bc_expand_conversion (TREE_TYPE (TREE_OPERAND (exp, 0)), TREE_TYPE (exp));
7161 return;
7163 case MODIFY_EXPR:
7165 expand_assignment (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1), 0, 0);
7166 return;
7168 case ADDR_EXPR:
7170 bc_expand_address (TREE_OPERAND (exp, 0));
7171 return;
7173 case INDIRECT_REF:
7175 bc_expand_expr (TREE_OPERAND (exp, 0));
7176 bc_load_memory (TREE_TYPE (exp), TREE_OPERAND (exp, 0));
7177 return;
7179 case ARRAY_REF:
7181 bc_expand_expr (bc_canonicalize_array_ref (exp));
7182 return;
7184 case COMPONENT_REF:
7186 bc_expand_component_address (exp);
7188 /* If we have a bitfield, generate a proper load */
7189 bc_load_memory (TREE_TYPE (TREE_OPERAND (exp, 1)), TREE_OPERAND (exp, 1));
7190 return;
7192 case COMPOUND_EXPR:
7194 bc_expand_expr (TREE_OPERAND (exp, 0));
7195 bc_emit_instruction (drop);
7196 bc_expand_expr (TREE_OPERAND (exp, 1));
7197 return;
7199 case COND_EXPR:
7201 bc_expand_expr (TREE_OPERAND (exp, 0));
7202 bc_expand_truth_conversion (TREE_TYPE (TREE_OPERAND (exp, 0)));
7203 lab = bc_get_bytecode_label ();
7204 bc_emit_bytecode (xjumpifnot);
7205 bc_emit_bytecode_labelref (lab);
7207 #ifdef DEBUG_PRINT_CODE
7208 fputc ('\n', stderr);
7209 #endif
7210 bc_expand_expr (TREE_OPERAND (exp, 1));
7211 lab1 = bc_get_bytecode_label ();
7212 bc_emit_bytecode (jump);
7213 bc_emit_bytecode_labelref (lab1);
7215 #ifdef DEBUG_PRINT_CODE
7216 fputc ('\n', stderr);
7217 #endif
7219 bc_emit_bytecode_labeldef (lab);
7220 bc_expand_expr (TREE_OPERAND (exp, 2));
7221 bc_emit_bytecode_labeldef (lab1);
7222 return;
7224 case TRUTH_ANDIF_EXPR:
7226 opcode = xjumpifnot;
7227 goto andorif;
7229 case TRUTH_ORIF_EXPR:
7231 opcode = xjumpif;
7232 goto andorif;
7234 case PLUS_EXPR:
7236 binoptab = optab_plus_expr;
7237 goto binop;
7239 case MINUS_EXPR:
7241 binoptab = optab_minus_expr;
7242 goto binop;
7244 case MULT_EXPR:
7246 binoptab = optab_mult_expr;
7247 goto binop;
7249 case TRUNC_DIV_EXPR:
7250 case FLOOR_DIV_EXPR:
7251 case CEIL_DIV_EXPR:
7252 case ROUND_DIV_EXPR:
7253 case EXACT_DIV_EXPR:
7255 binoptab = optab_trunc_div_expr;
7256 goto binop;
7258 case TRUNC_MOD_EXPR:
7259 case FLOOR_MOD_EXPR:
7260 case CEIL_MOD_EXPR:
7261 case ROUND_MOD_EXPR:
7263 binoptab = optab_trunc_mod_expr;
7264 goto binop;
7266 case FIX_ROUND_EXPR:
7267 case FIX_FLOOR_EXPR:
7268 case FIX_CEIL_EXPR:
7269 abort (); /* Not used for C. */
7271 case FIX_TRUNC_EXPR:
7272 case FLOAT_EXPR:
7273 case MAX_EXPR:
7274 case MIN_EXPR:
7275 case FFS_EXPR:
7276 case LROTATE_EXPR:
7277 case RROTATE_EXPR:
7278 abort (); /* FIXME */
7280 case RDIV_EXPR:
7282 binoptab = optab_rdiv_expr;
7283 goto binop;
7285 case BIT_AND_EXPR:
7287 binoptab = optab_bit_and_expr;
7288 goto binop;
7290 case BIT_IOR_EXPR:
7292 binoptab = optab_bit_ior_expr;
7293 goto binop;
7295 case BIT_XOR_EXPR:
7297 binoptab = optab_bit_xor_expr;
7298 goto binop;
7300 case LSHIFT_EXPR:
7302 binoptab = optab_lshift_expr;
7303 goto binop;
7305 case RSHIFT_EXPR:
7307 binoptab = optab_rshift_expr;
7308 goto binop;
7310 case TRUTH_AND_EXPR:
7312 binoptab = optab_truth_and_expr;
7313 goto binop;
7315 case TRUTH_OR_EXPR:
7317 binoptab = optab_truth_or_expr;
7318 goto binop;
7320 case LT_EXPR:
7322 binoptab = optab_lt_expr;
7323 goto binop;
7325 case LE_EXPR:
7327 binoptab = optab_le_expr;
7328 goto binop;
7330 case GE_EXPR:
7332 binoptab = optab_ge_expr;
7333 goto binop;
7335 case GT_EXPR:
7337 binoptab = optab_gt_expr;
7338 goto binop;
7340 case EQ_EXPR:
7342 binoptab = optab_eq_expr;
7343 goto binop;
7345 case NE_EXPR:
7347 binoptab = optab_ne_expr;
7348 goto binop;
7350 case NEGATE_EXPR:
7352 unoptab = optab_negate_expr;
7353 goto unop;
7355 case BIT_NOT_EXPR:
7357 unoptab = optab_bit_not_expr;
7358 goto unop;
7360 case TRUTH_NOT_EXPR:
7362 unoptab = optab_truth_not_expr;
7363 goto unop;
7365 case PREDECREMENT_EXPR:
7367 incroptab = optab_predecrement_expr;
7368 goto increment;
7370 case PREINCREMENT_EXPR:
7372 incroptab = optab_preincrement_expr;
7373 goto increment;
7375 case POSTDECREMENT_EXPR:
7377 incroptab = optab_postdecrement_expr;
7378 goto increment;
7380 case POSTINCREMENT_EXPR:
7382 incroptab = optab_postincrement_expr;
7383 goto increment;
7385 case CONSTRUCTOR:
7387 bc_expand_constructor (exp);
7388 return;
7390 case ERROR_MARK:
7391 case RTL_EXPR:
7393 return;
7395 case BIND_EXPR:
7397 tree vars = TREE_OPERAND (exp, 0);
7398 int vars_need_expansion = 0;
7400 /* Need to open a binding contour here because
7401 if there are any cleanups they most be contained here. */
7402 expand_start_bindings (0);
7404 /* Mark the corresponding BLOCK for output. */
7405 if (TREE_OPERAND (exp, 2) != 0)
7406 TREE_USED (TREE_OPERAND (exp, 2)) = 1;
7408 /* If VARS have not yet been expanded, expand them now. */
7409 while (vars)
7411 if (DECL_RTL (vars) == 0)
7413 vars_need_expansion = 1;
7414 expand_decl (vars);
7416 expand_decl_init (vars);
7417 vars = TREE_CHAIN (vars);
7420 bc_expand_expr (TREE_OPERAND (exp, 1));
7422 expand_end_bindings (TREE_OPERAND (exp, 0), 0, 0);
7424 return;
7428 abort ();
7430 binop:
7432 bc_expand_binary_operation (binoptab, TREE_TYPE (exp),
7433 TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1));
7434 return;
7437 unop:
7439 bc_expand_unary_operation (unoptab, TREE_TYPE (exp), TREE_OPERAND (exp, 0));
7440 return;
7443 andorif:
7445 bc_expand_expr (TREE_OPERAND (exp, 0));
7446 bc_expand_truth_conversion (TREE_TYPE (TREE_OPERAND (exp, 0)));
7447 lab = bc_get_bytecode_label ();
7449 bc_emit_instruction (duplicate);
7450 bc_emit_bytecode (opcode);
7451 bc_emit_bytecode_labelref (lab);
7453 #ifdef DEBUG_PRINT_CODE
7454 fputc ('\n', stderr);
7455 #endif
7457 bc_emit_instruction (drop);
7459 bc_expand_expr (TREE_OPERAND (exp, 1));
7460 bc_expand_truth_conversion (TREE_TYPE (TREE_OPERAND (exp, 1)));
7461 bc_emit_bytecode_labeldef (lab);
7462 return;
7465 increment:
7467 type = TREE_TYPE (TREE_OPERAND (exp, 0));
7469 /* Push the quantum. */
7470 bc_expand_expr (TREE_OPERAND (exp, 1));
7472 /* Convert it to the lvalue's type. */
7473 bc_expand_conversion (TREE_TYPE (TREE_OPERAND (exp, 1)), type);
7475 /* Push the address of the lvalue */
7476 bc_expand_expr (build1 (ADDR_EXPR, TYPE_POINTER_TO (type), TREE_OPERAND (exp, 0)));
7478 /* Perform actual increment */
7479 bc_expand_increment (incroptab, type);
7480 return;
7483 /* Return the alignment in bits of EXP, a pointer valued expression.
7484 But don't return more than MAX_ALIGN no matter what.
7485 The alignment returned is, by default, the alignment of the thing that
7486 EXP points to (if it is not a POINTER_TYPE, 0 is returned).
7488 Otherwise, look at the expression to see if we can do better, i.e., if the
7489 expression is actually pointing at an object whose alignment is tighter. */
7491 static int
7492 get_pointer_alignment (exp, max_align)
7493 tree exp;
7494 unsigned max_align;
7496 unsigned align, inner;
7498 if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
7499 return 0;
7501 align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
7502 align = MIN (align, max_align);
7504 while (1)
7506 switch (TREE_CODE (exp))
7508 case NOP_EXPR:
7509 case CONVERT_EXPR:
7510 case NON_LVALUE_EXPR:
7511 exp = TREE_OPERAND (exp, 0);
7512 if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
7513 return align;
7514 inner = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
7515 align = MIN (inner, max_align);
7516 break;
7518 case PLUS_EXPR:
7519 /* If sum of pointer + int, restrict our maximum alignment to that
7520 imposed by the integer. If not, we can't do any better than
7521 ALIGN. */
7522 if (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST)
7523 return align;
7525 while (((TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)) * BITS_PER_UNIT)
7526 & (max_align - 1))
7527 != 0)
7528 max_align >>= 1;
7530 exp = TREE_OPERAND (exp, 0);
7531 break;
7533 case ADDR_EXPR:
7534 /* See what we are pointing at and look at its alignment. */
7535 exp = TREE_OPERAND (exp, 0);
7536 if (TREE_CODE (exp) == FUNCTION_DECL)
7537 align = FUNCTION_BOUNDARY;
7538 else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
7539 align = DECL_ALIGN (exp);
7540 #ifdef CONSTANT_ALIGNMENT
7541 else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c')
7542 align = CONSTANT_ALIGNMENT (exp, align);
7543 #endif
7544 return MIN (align, max_align);
7546 default:
7547 return align;
7552 /* Return the tree node and offset if a given argument corresponds to
7553 a string constant. */
7555 static tree
7556 string_constant (arg, ptr_offset)
7557 tree arg;
7558 tree *ptr_offset;
7560 STRIP_NOPS (arg);
7562 if (TREE_CODE (arg) == ADDR_EXPR
7563 && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
7565 *ptr_offset = integer_zero_node;
7566 return TREE_OPERAND (arg, 0);
7568 else if (TREE_CODE (arg) == PLUS_EXPR)
7570 tree arg0 = TREE_OPERAND (arg, 0);
7571 tree arg1 = TREE_OPERAND (arg, 1);
7573 STRIP_NOPS (arg0);
7574 STRIP_NOPS (arg1);
7576 if (TREE_CODE (arg0) == ADDR_EXPR
7577 && TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST)
7579 *ptr_offset = arg1;
7580 return TREE_OPERAND (arg0, 0);
7582 else if (TREE_CODE (arg1) == ADDR_EXPR
7583 && TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST)
7585 *ptr_offset = arg0;
7586 return TREE_OPERAND (arg1, 0);
7590 return 0;
7593 /* Compute the length of a C string. TREE_STRING_LENGTH is not the right
7594 way, because it could contain a zero byte in the middle.
7595 TREE_STRING_LENGTH is the size of the character array, not the string.
7597 Unfortunately, string_constant can't access the values of const char
7598 arrays with initializers, so neither can we do so here. */
7600 static tree
7601 c_strlen (src)
7602 tree src;
7604 tree offset_node;
7605 int offset, max;
7606 char *ptr;
7608 src = string_constant (src, &offset_node);
7609 if (src == 0)
7610 return 0;
7611 max = TREE_STRING_LENGTH (src);
7612 ptr = TREE_STRING_POINTER (src);
7613 if (offset_node && TREE_CODE (offset_node) != INTEGER_CST)
7615 /* If the string has an internal zero byte (e.g., "foo\0bar"), we can't
7616 compute the offset to the following null if we don't know where to
7617 start searching for it. */
7618 int i;
7619 for (i = 0; i < max; i++)
7620 if (ptr[i] == 0)
7621 return 0;
7622 /* We don't know the starting offset, but we do know that the string
7623 has no internal zero bytes. We can assume that the offset falls
7624 within the bounds of the string; otherwise, the programmer deserves
7625 what he gets. Subtract the offset from the length of the string,
7626 and return that. */
7627 /* This would perhaps not be valid if we were dealing with named
7628 arrays in addition to literal string constants. */
7629 return size_binop (MINUS_EXPR, size_int (max), offset_node);
7632 /* We have a known offset into the string. Start searching there for
7633 a null character. */
7634 if (offset_node == 0)
7635 offset = 0;
7636 else
7638 /* Did we get a long long offset? If so, punt. */
7639 if (TREE_INT_CST_HIGH (offset_node) != 0)
7640 return 0;
7641 offset = TREE_INT_CST_LOW (offset_node);
7643 /* If the offset is known to be out of bounds, warn, and call strlen at
7644 runtime. */
7645 if (offset < 0 || offset > max)
7647 warning ("offset outside bounds of constant string");
7648 return 0;
7650 /* Use strlen to search for the first zero byte. Since any strings
7651 constructed with build_string will have nulls appended, we win even
7652 if we get handed something like (char[4])"abcd".
7654 Since OFFSET is our starting index into the string, no further
7655 calculation is needed. */
7656 return size_int (strlen (ptr + offset));
7660 expand_builtin_return_addr (fndecl_code, count, tem)
7661 enum built_in_function fndecl_code;
7662 rtx tem;
7663 int count;
7665 int i;
7667 /* Some machines need special handling before we can access
7668 arbitrary frames. For example, on the sparc, we must first flush
7669 all register windows to the stack. */
7670 #ifdef SETUP_FRAME_ADDRESSES
7671 SETUP_FRAME_ADDRESSES ();
7672 #endif
7674 /* On the sparc, the return address is not in the frame, it is in a
7675 register. There is no way to access it off of the current frame
7676 pointer, but it can be accessed off the previous frame pointer by
7677 reading the value from the register window save area. */
7678 #ifdef RETURN_ADDR_IN_PREVIOUS_FRAME
7679 if (fndecl_code == BUILT_IN_RETURN_ADDRESS)
7680 count--;
7681 #endif
7683 /* Scan back COUNT frames to the specified frame. */
7684 for (i = 0; i < count; i++)
7686 /* Assume the dynamic chain pointer is in the word that the
7687 frame address points to, unless otherwise specified. */
7688 #ifdef DYNAMIC_CHAIN_ADDRESS
7689 tem = DYNAMIC_CHAIN_ADDRESS (tem);
7690 #endif
7691 tem = memory_address (Pmode, tem);
7692 tem = copy_to_reg (gen_rtx (MEM, Pmode, tem));
7695 /* For __builtin_frame_address, return what we've got. */
7696 if (fndecl_code == BUILT_IN_FRAME_ADDRESS)
7697 return tem;
7699 /* For __builtin_return_address, Get the return address from that
7700 frame. */
7701 #ifdef RETURN_ADDR_RTX
7702 tem = RETURN_ADDR_RTX (count, tem);
7703 #else
7704 tem = memory_address (Pmode,
7705 plus_constant (tem, GET_MODE_SIZE (Pmode)));
7706 tem = gen_rtx (MEM, Pmode, tem);
7707 #endif
7708 return tem;
7711 /* Expand an expression EXP that calls a built-in function,
7712 with result going to TARGET if that's convenient
7713 (and in mode MODE if that's convenient).
7714 SUBTARGET may be used as the target for computing one of EXP's operands.
7715 IGNORE is nonzero if the value is to be ignored. */
7717 #define CALLED_AS_BUILT_IN(NODE) \
7718 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
7720 static rtx
7721 expand_builtin (exp, target, subtarget, mode, ignore)
7722 tree exp;
7723 rtx target;
7724 rtx subtarget;
7725 enum machine_mode mode;
7726 int ignore;
7728 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7729 tree arglist = TREE_OPERAND (exp, 1);
7730 rtx op0;
7731 rtx lab1, insns;
7732 enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
7733 optab builtin_optab;
7735 switch (DECL_FUNCTION_CODE (fndecl))
7737 case BUILT_IN_ABS:
7738 case BUILT_IN_LABS:
7739 case BUILT_IN_FABS:
7740 /* build_function_call changes these into ABS_EXPR. */
7741 abort ();
7743 case BUILT_IN_SIN:
7744 case BUILT_IN_COS:
7745 /* Treat these like sqrt, but only if the user asks for them. */
7746 if (! flag_fast_math)
7747 break;
7748 case BUILT_IN_FSQRT:
7749 /* If not optimizing, call the library function. */
7750 if (! optimize)
7751 break;
7753 if (arglist == 0
7754 /* Arg could be wrong type if user redeclared this fcn wrong. */
7755 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != REAL_TYPE)
7756 break;
7758 /* Stabilize and compute the argument. */
7759 if (TREE_CODE (TREE_VALUE (arglist)) != VAR_DECL
7760 && TREE_CODE (TREE_VALUE (arglist)) != PARM_DECL)
7762 exp = copy_node (exp);
7763 arglist = copy_node (arglist);
7764 TREE_OPERAND (exp, 1) = arglist;
7765 TREE_VALUE (arglist) = save_expr (TREE_VALUE (arglist));
7767 op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
7769 /* Make a suitable register to place result in. */
7770 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
7772 emit_queue ();
7773 start_sequence ();
7775 switch (DECL_FUNCTION_CODE (fndecl))
7777 case BUILT_IN_SIN:
7778 builtin_optab = sin_optab; break;
7779 case BUILT_IN_COS:
7780 builtin_optab = cos_optab; break;
7781 case BUILT_IN_FSQRT:
7782 builtin_optab = sqrt_optab; break;
7783 default:
7784 abort ();
7787 /* Compute into TARGET.
7788 Set TARGET to wherever the result comes back. */
7789 target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
7790 builtin_optab, op0, target, 0);
7792 /* If we were unable to expand via the builtin, stop the
7793 sequence (without outputting the insns) and break, causing
7794 a call the the library function. */
7795 if (target == 0)
7797 end_sequence ();
7798 break;
7801 /* Check the results by default. But if flag_fast_math is turned on,
7802 then assume sqrt will always be called with valid arguments. */
7804 if (! flag_fast_math)
7806 /* Don't define the builtin FP instructions
7807 if your machine is not IEEE. */
7808 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
7809 abort ();
7811 lab1 = gen_label_rtx ();
7813 /* Test the result; if it is NaN, set errno=EDOM because
7814 the argument was not in the domain. */
7815 emit_cmp_insn (target, target, EQ, 0, GET_MODE (target), 0, 0);
7816 emit_jump_insn (gen_beq (lab1));
7818 #ifdef TARGET_EDOM
7820 #ifdef GEN_ERRNO_RTX
7821 rtx errno_rtx = GEN_ERRNO_RTX;
7822 #else
7823 rtx errno_rtx
7824 = gen_rtx (MEM, word_mode, gen_rtx (SYMBOL_REF, Pmode, "errno"));
7825 #endif
7827 emit_move_insn (errno_rtx, GEN_INT (TARGET_EDOM));
7829 #else
7830 /* We can't set errno=EDOM directly; let the library call do it.
7831 Pop the arguments right away in case the call gets deleted. */
7832 NO_DEFER_POP;
7833 expand_call (exp, target, 0);
7834 OK_DEFER_POP;
7835 #endif
7837 emit_label (lab1);
7840 /* Output the entire sequence. */
7841 insns = get_insns ();
7842 end_sequence ();
7843 emit_insns (insns);
7845 return target;
7847 /* __builtin_apply_args returns block of memory allocated on
7848 the stack into which is stored the arg pointer, structure
7849 value address, static chain, and all the registers that might
7850 possibly be used in performing a function call. The code is
7851 moved to the start of the function so the incoming values are
7852 saved. */
7853 case BUILT_IN_APPLY_ARGS:
7854 /* Don't do __builtin_apply_args more than once in a function.
7855 Save the result of the first call and reuse it. */
7856 if (apply_args_value != 0)
7857 return apply_args_value;
7859 /* When this function is called, it means that registers must be
7860 saved on entry to this function. So we migrate the
7861 call to the first insn of this function. */
7862 rtx temp;
7863 rtx seq;
7865 start_sequence ();
7866 temp = expand_builtin_apply_args ();
7867 seq = get_insns ();
7868 end_sequence ();
7870 apply_args_value = temp;
7872 /* Put the sequence after the NOTE that starts the function.
7873 If this is inside a SEQUENCE, make the outer-level insn
7874 chain current, so the code is placed at the start of the
7875 function. */
7876 push_topmost_sequence ();
7877 emit_insns_before (seq, NEXT_INSN (get_insns ()));
7878 pop_topmost_sequence ();
7879 return temp;
7882 /* __builtin_apply (FUNCTION, ARGUMENTS, ARGSIZE) invokes
7883 FUNCTION with a copy of the parameters described by
7884 ARGUMENTS, and ARGSIZE. It returns a block of memory
7885 allocated on the stack into which is stored all the registers
7886 that might possibly be used for returning the result of a
7887 function. ARGUMENTS is the value returned by
7888 __builtin_apply_args. ARGSIZE is the number of bytes of
7889 arguments that must be copied. ??? How should this value be
7890 computed? We'll also need a safe worst case value for varargs
7891 functions. */
7892 case BUILT_IN_APPLY:
7893 if (arglist == 0
7894 /* Arg could be non-pointer if user redeclared this fcn wrong. */
7895 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
7896 || TREE_CHAIN (arglist) == 0
7897 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
7898 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
7899 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
7900 return const0_rtx;
7901 else
7903 int i;
7904 tree t;
7905 rtx ops[3];
7907 for (t = arglist, i = 0; t; t = TREE_CHAIN (t), i++)
7908 ops[i] = expand_expr (TREE_VALUE (t), NULL_RTX, VOIDmode, 0);
7910 return expand_builtin_apply (ops[0], ops[1], ops[2]);
7913 /* __builtin_return (RESULT) causes the function to return the
7914 value described by RESULT. RESULT is address of the block of
7915 memory returned by __builtin_apply. */
7916 case BUILT_IN_RETURN:
7917 if (arglist
7918 /* Arg could be non-pointer if user redeclared this fcn wrong. */
7919 && TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == POINTER_TYPE)
7920 expand_builtin_return (expand_expr (TREE_VALUE (arglist),
7921 NULL_RTX, VOIDmode, 0));
7922 return const0_rtx;
7924 case BUILT_IN_SAVEREGS:
7925 /* Don't do __builtin_saveregs more than once in a function.
7926 Save the result of the first call and reuse it. */
7927 if (saveregs_value != 0)
7928 return saveregs_value;
7930 /* When this function is called, it means that registers must be
7931 saved on entry to this function. So we migrate the
7932 call to the first insn of this function. */
7933 rtx temp;
7934 rtx seq;
7936 /* Now really call the function. `expand_call' does not call
7937 expand_builtin, so there is no danger of infinite recursion here. */
7938 start_sequence ();
7940 #ifdef EXPAND_BUILTIN_SAVEREGS
7941 /* Do whatever the machine needs done in this case. */
7942 temp = EXPAND_BUILTIN_SAVEREGS (arglist);
7943 #else
7944 /* The register where the function returns its value
7945 is likely to have something else in it, such as an argument.
7946 So preserve that register around the call. */
7948 if (value_mode != VOIDmode)
7950 rtx valreg = hard_libcall_value (value_mode);
7951 rtx saved_valreg = gen_reg_rtx (value_mode);
7953 emit_move_insn (saved_valreg, valreg);
7954 temp = expand_call (exp, target, ignore);
7955 emit_move_insn (valreg, saved_valreg);
7957 else
7958 /* Generate the call, putting the value in a pseudo. */
7959 temp = expand_call (exp, target, ignore);
7960 #endif
7962 seq = get_insns ();
7963 end_sequence ();
7965 saveregs_value = temp;
7967 /* Put the sequence after the NOTE that starts the function.
7968 If this is inside a SEQUENCE, make the outer-level insn
7969 chain current, so the code is placed at the start of the
7970 function. */
7971 push_topmost_sequence ();
7972 emit_insns_before (seq, NEXT_INSN (get_insns ()));
7973 pop_topmost_sequence ();
7974 return temp;
7977 /* __builtin_args_info (N) returns word N of the arg space info
7978 for the current function. The number and meanings of words
7979 is controlled by the definition of CUMULATIVE_ARGS. */
7980 case BUILT_IN_ARGS_INFO:
7982 int nwords = sizeof (CUMULATIVE_ARGS) / sizeof (int);
7983 int i;
7984 int *word_ptr = (int *) &current_function_args_info;
7985 tree type, elts, result;
7987 if (sizeof (CUMULATIVE_ARGS) % sizeof (int) != 0)
7988 fatal ("CUMULATIVE_ARGS type defined badly; see %s, line %d",
7989 __FILE__, __LINE__);
7991 if (arglist != 0)
7993 tree arg = TREE_VALUE (arglist);
7994 if (TREE_CODE (arg) != INTEGER_CST)
7995 error ("argument of `__builtin_args_info' must be constant");
7996 else
7998 int wordnum = TREE_INT_CST_LOW (arg);
8000 if (wordnum < 0 || wordnum >= nwords || TREE_INT_CST_HIGH (arg))
8001 error ("argument of `__builtin_args_info' out of range");
8002 else
8003 return GEN_INT (word_ptr[wordnum]);
8006 else
8007 error ("missing argument in `__builtin_args_info'");
8009 return const0_rtx;
8011 #if 0
8012 for (i = 0; i < nwords; i++)
8013 elts = tree_cons (NULL_TREE, build_int_2 (word_ptr[i], 0));
8015 type = build_array_type (integer_type_node,
8016 build_index_type (build_int_2 (nwords, 0)));
8017 result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (elts));
8018 TREE_CONSTANT (result) = 1;
8019 TREE_STATIC (result) = 1;
8020 result = build (INDIRECT_REF, build_pointer_type (type), result);
8021 TREE_CONSTANT (result) = 1;
8022 return expand_expr (result, NULL_RTX, VOIDmode, 0);
8023 #endif
8026 /* Return the address of the first anonymous stack arg. */
8027 case BUILT_IN_NEXT_ARG:
8029 tree fntype = TREE_TYPE (current_function_decl);
8031 if ((TYPE_ARG_TYPES (fntype) == 0
8032 || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
8033 == void_type_node))
8034 && ! current_function_varargs)
8036 error ("`va_start' used in function with fixed args");
8037 return const0_rtx;
8040 if (arglist)
8042 tree last_parm = tree_last (DECL_ARGUMENTS (current_function_decl));
8043 tree arg = TREE_VALUE (arglist);
8045 /* Strip off all nops for the sake of the comparison. This
8046 is not quite the same as STRIP_NOPS. It does more.
8047 We must also strip off INDIRECT_EXPR for C++ reference
8048 parameters. */
8049 while (TREE_CODE (arg) == NOP_EXPR
8050 || TREE_CODE (arg) == CONVERT_EXPR
8051 || TREE_CODE (arg) == NON_LVALUE_EXPR
8052 || TREE_CODE (arg) == INDIRECT_REF)
8053 arg = TREE_OPERAND (arg, 0);
8054 if (arg != last_parm)
8055 warning ("second parameter of `va_start' not last named argument");
8057 else if (! current_function_varargs)
8058 /* Evidently an out of date version of <stdarg.h>; can't validate
8059 va_start's second argument, but can still work as intended. */
8060 warning ("`__builtin_next_arg' called without an argument");
8063 return expand_binop (Pmode, add_optab,
8064 current_function_internal_arg_pointer,
8065 current_function_arg_offset_rtx,
8066 NULL_RTX, 0, OPTAB_LIB_WIDEN);
8068 case BUILT_IN_CLASSIFY_TYPE:
8069 if (arglist != 0)
8071 tree type = TREE_TYPE (TREE_VALUE (arglist));
8072 enum tree_code code = TREE_CODE (type);
8073 if (code == VOID_TYPE)
8074 return GEN_INT (void_type_class);
8075 if (code == INTEGER_TYPE)
8076 return GEN_INT (integer_type_class);
8077 if (code == CHAR_TYPE)
8078 return GEN_INT (char_type_class);
8079 if (code == ENUMERAL_TYPE)
8080 return GEN_INT (enumeral_type_class);
8081 if (code == BOOLEAN_TYPE)
8082 return GEN_INT (boolean_type_class);
8083 if (code == POINTER_TYPE)
8084 return GEN_INT (pointer_type_class);
8085 if (code == REFERENCE_TYPE)
8086 return GEN_INT (reference_type_class);
8087 if (code == OFFSET_TYPE)
8088 return GEN_INT (offset_type_class);
8089 if (code == REAL_TYPE)
8090 return GEN_INT (real_type_class);
8091 if (code == COMPLEX_TYPE)
8092 return GEN_INT (complex_type_class);
8093 if (code == FUNCTION_TYPE)
8094 return GEN_INT (function_type_class);
8095 if (code == METHOD_TYPE)
8096 return GEN_INT (method_type_class);
8097 if (code == RECORD_TYPE)
8098 return GEN_INT (record_type_class);
8099 if (code == UNION_TYPE || code == QUAL_UNION_TYPE)
8100 return GEN_INT (union_type_class);
8101 if (code == ARRAY_TYPE)
8103 if (TYPE_STRING_FLAG (type))
8104 return GEN_INT (string_type_class);
8105 else
8106 return GEN_INT (array_type_class);
8108 if (code == SET_TYPE)
8109 return GEN_INT (set_type_class);
8110 if (code == FILE_TYPE)
8111 return GEN_INT (file_type_class);
8112 if (code == LANG_TYPE)
8113 return GEN_INT (lang_type_class);
8115 return GEN_INT (no_type_class);
8117 case BUILT_IN_CONSTANT_P:
8118 if (arglist == 0)
8119 return const0_rtx;
8120 else
8122 tree arg = TREE_VALUE (arglist);
8124 STRIP_NOPS (arg);
8125 return (TREE_CODE_CLASS (TREE_CODE (arg)) == 'c'
8126 || (TREE_CODE (arg) == ADDR_EXPR
8127 && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
8128 ? const1_rtx : const0_rtx);
8131 case BUILT_IN_FRAME_ADDRESS:
8132 /* The argument must be a nonnegative integer constant.
8133 It counts the number of frames to scan up the stack.
8134 The value is the address of that frame. */
8135 case BUILT_IN_RETURN_ADDRESS:
8136 /* The argument must be a nonnegative integer constant.
8137 It counts the number of frames to scan up the stack.
8138 The value is the return address saved in that frame. */
8139 if (arglist == 0)
8140 /* Warning about missing arg was already issued. */
8141 return const0_rtx;
8142 else if (TREE_CODE (TREE_VALUE (arglist)) != INTEGER_CST)
8144 error ("invalid arg to `__builtin_return_address'");
8145 return const0_rtx;
8147 else if (tree_int_cst_sgn (TREE_VALUE (arglist)) < 0)
8149 error ("invalid arg to `__builtin_return_address'");
8150 return const0_rtx;
8152 else
8154 rtx tem = expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl),
8155 TREE_INT_CST_LOW (TREE_VALUE (arglist)),
8156 hard_frame_pointer_rtx);
8158 /* For __builtin_frame_address, return what we've got. */
8159 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
8160 return tem;
8162 if (GET_CODE (tem) != REG)
8163 tem = copy_to_reg (tem);
8164 return tem;
8167 case BUILT_IN_ALLOCA:
8168 if (arglist == 0
8169 /* Arg could be non-integer if user redeclared this fcn wrong. */
8170 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
8171 break;
8173 /* Compute the argument. */
8174 op0 = expand_expr (TREE_VALUE (arglist), NULL_RTX, VOIDmode, 0);
8176 /* Allocate the desired space. */
8177 return allocate_dynamic_stack_space (op0, target, BITS_PER_UNIT);
8179 case BUILT_IN_FFS:
8180 /* If not optimizing, call the library function. */
8181 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8182 break;
8184 if (arglist == 0
8185 /* Arg could be non-integer if user redeclared this fcn wrong. */
8186 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
8187 break;
8189 /* Compute the argument. */
8190 op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
8191 /* Compute ffs, into TARGET if possible.
8192 Set TARGET to wherever the result comes back. */
8193 target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
8194 ffs_optab, op0, target, 1);
8195 if (target == 0)
8196 abort ();
8197 return target;
8199 case BUILT_IN_STRLEN:
8200 /* If not optimizing, call the library function. */
8201 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8202 break;
8204 if (arglist == 0
8205 /* Arg could be non-pointer if user redeclared this fcn wrong. */
8206 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
8207 break;
8208 else
8210 tree src = TREE_VALUE (arglist);
8211 tree len = c_strlen (src);
8213 int align
8214 = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8216 rtx result, src_rtx, char_rtx;
8217 enum machine_mode insn_mode = value_mode, char_mode;
8218 enum insn_code icode;
8220 /* If the length is known, just return it. */
8221 if (len != 0)
8222 return expand_expr (len, target, mode, 0);
8224 /* If SRC is not a pointer type, don't do this operation inline. */
8225 if (align == 0)
8226 break;
8228 /* Call a function if we can't compute strlen in the right mode. */
8230 while (insn_mode != VOIDmode)
8232 icode = strlen_optab->handlers[(int) insn_mode].insn_code;
8233 if (icode != CODE_FOR_nothing)
8234 break;
8236 insn_mode = GET_MODE_WIDER_MODE (insn_mode);
8238 if (insn_mode == VOIDmode)
8239 break;
8241 /* Make a place to write the result of the instruction. */
8242 result = target;
8243 if (! (result != 0
8244 && GET_CODE (result) == REG
8245 && GET_MODE (result) == insn_mode
8246 && REGNO (result) >= FIRST_PSEUDO_REGISTER))
8247 result = gen_reg_rtx (insn_mode);
8249 /* Make sure the operands are acceptable to the predicates. */
8251 if (! (*insn_operand_predicate[(int)icode][0]) (result, insn_mode))
8252 result = gen_reg_rtx (insn_mode);
8254 src_rtx = memory_address (BLKmode,
8255 expand_expr (src, NULL_RTX, ptr_mode,
8256 EXPAND_NORMAL));
8257 if (! (*insn_operand_predicate[(int)icode][1]) (src_rtx, Pmode))
8258 src_rtx = copy_to_mode_reg (Pmode, src_rtx);
8260 char_rtx = const0_rtx;
8261 char_mode = insn_operand_mode[(int)icode][2];
8262 if (! (*insn_operand_predicate[(int)icode][2]) (char_rtx, char_mode))
8263 char_rtx = copy_to_mode_reg (char_mode, char_rtx);
8265 emit_insn (GEN_FCN (icode) (result,
8266 gen_rtx (MEM, BLKmode, src_rtx),
8267 char_rtx, GEN_INT (align)));
8269 /* Return the value in the proper mode for this function. */
8270 if (GET_MODE (result) == value_mode)
8271 return result;
8272 else if (target != 0)
8274 convert_move (target, result, 0);
8275 return target;
8277 else
8278 return convert_to_mode (value_mode, result, 0);
8281 case BUILT_IN_STRCPY:
8282 /* If not optimizing, call the library function. */
8283 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8284 break;
8286 if (arglist == 0
8287 /* Arg could be non-pointer if user redeclared this fcn wrong. */
8288 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8289 || TREE_CHAIN (arglist) == 0
8290 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
8291 break;
8292 else
8294 tree len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
8296 if (len == 0)
8297 break;
8299 len = size_binop (PLUS_EXPR, len, integer_one_node);
8301 chainon (arglist, build_tree_list (NULL_TREE, len));
8304 /* Drops in. */
8305 case BUILT_IN_MEMCPY:
8306 /* If not optimizing, call the library function. */
8307 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8308 break;
8310 if (arglist == 0
8311 /* Arg could be non-pointer if user redeclared this fcn wrong. */
8312 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8313 || TREE_CHAIN (arglist) == 0
8314 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
8315 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
8316 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
8317 break;
8318 else
8320 tree dest = TREE_VALUE (arglist);
8321 tree src = TREE_VALUE (TREE_CHAIN (arglist));
8322 tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
8323 tree type;
8325 int src_align
8326 = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8327 int dest_align
8328 = get_pointer_alignment (dest, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8329 rtx dest_rtx, dest_mem, src_mem;
8331 /* If either SRC or DEST is not a pointer type, don't do
8332 this operation in-line. */
8333 if (src_align == 0 || dest_align == 0)
8335 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRCPY)
8336 TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
8337 break;
8340 dest_rtx = expand_expr (dest, NULL_RTX, ptr_mode, EXPAND_SUM);
8341 dest_mem = gen_rtx (MEM, BLKmode,
8342 memory_address (BLKmode, dest_rtx));
8343 /* There could be a void* cast on top of the object. */
8344 while (TREE_CODE (dest) == NOP_EXPR)
8345 dest = TREE_OPERAND (dest, 0);
8346 type = TREE_TYPE (TREE_TYPE (dest));
8347 MEM_IN_STRUCT_P (dest_mem) = AGGREGATE_TYPE_P (type);
8348 src_mem = gen_rtx (MEM, BLKmode,
8349 memory_address (BLKmode,
8350 expand_expr (src, NULL_RTX,
8351 ptr_mode,
8352 EXPAND_SUM)));
8353 /* There could be a void* cast on top of the object. */
8354 while (TREE_CODE (src) == NOP_EXPR)
8355 src = TREE_OPERAND (src, 0);
8356 type = TREE_TYPE (TREE_TYPE (src));
8357 MEM_IN_STRUCT_P (src_mem) = AGGREGATE_TYPE_P (type);
8359 /* Copy word part most expediently. */
8360 emit_block_move (dest_mem, src_mem,
8361 expand_expr (len, NULL_RTX, VOIDmode, 0),
8362 MIN (src_align, dest_align));
8363 return force_operand (dest_rtx, NULL_RTX);
8366 /* These comparison functions need an instruction that returns an actual
8367 index. An ordinary compare that just sets the condition codes
8368 is not enough. */
8369 #ifdef HAVE_cmpstrsi
8370 case BUILT_IN_STRCMP:
8371 /* If not optimizing, call the library function. */
8372 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8373 break;
8375 if (arglist == 0
8376 /* Arg could be non-pointer if user redeclared this fcn wrong. */
8377 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8378 || TREE_CHAIN (arglist) == 0
8379 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
8380 break;
8381 else if (!HAVE_cmpstrsi)
8382 break;
8384 tree arg1 = TREE_VALUE (arglist);
8385 tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
8386 tree offset;
8387 tree len, len2;
8389 len = c_strlen (arg1);
8390 if (len)
8391 len = size_binop (PLUS_EXPR, integer_one_node, len);
8392 len2 = c_strlen (arg2);
8393 if (len2)
8394 len2 = size_binop (PLUS_EXPR, integer_one_node, len2);
8396 /* If we don't have a constant length for the first, use the length
8397 of the second, if we know it. We don't require a constant for
8398 this case; some cost analysis could be done if both are available
8399 but neither is constant. For now, assume they're equally cheap.
8401 If both strings have constant lengths, use the smaller. This
8402 could arise if optimization results in strcpy being called with
8403 two fixed strings, or if the code was machine-generated. We should
8404 add some code to the `memcmp' handler below to deal with such
8405 situations, someday. */
8406 if (!len || TREE_CODE (len) != INTEGER_CST)
8408 if (len2)
8409 len = len2;
8410 else if (len == 0)
8411 break;
8413 else if (len2 && TREE_CODE (len2) == INTEGER_CST)
8415 if (tree_int_cst_lt (len2, len))
8416 len = len2;
8419 chainon (arglist, build_tree_list (NULL_TREE, len));
8422 /* Drops in. */
8423 case BUILT_IN_MEMCMP:
8424 /* If not optimizing, call the library function. */
8425 if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8426 break;
8428 if (arglist == 0
8429 /* Arg could be non-pointer if user redeclared this fcn wrong. */
8430 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8431 || TREE_CHAIN (arglist) == 0
8432 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
8433 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
8434 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
8435 break;
8436 else if (!HAVE_cmpstrsi)
8437 break;
8439 tree arg1 = TREE_VALUE (arglist);
8440 tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
8441 tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
8442 rtx result;
8444 int arg1_align
8445 = get_pointer_alignment (arg1, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8446 int arg2_align
8447 = get_pointer_alignment (arg2, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8448 enum machine_mode insn_mode
8449 = insn_operand_mode[(int) CODE_FOR_cmpstrsi][0];
8451 /* If we don't have POINTER_TYPE, call the function. */
8452 if (arg1_align == 0 || arg2_align == 0)
8454 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRCMP)
8455 TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
8456 break;
8459 /* Make a place to write the result of the instruction. */
8460 result = target;
8461 if (! (result != 0
8462 && GET_CODE (result) == REG && GET_MODE (result) == insn_mode
8463 && REGNO (result) >= FIRST_PSEUDO_REGISTER))
8464 result = gen_reg_rtx (insn_mode);
8466 emit_insn (gen_cmpstrsi (result,
8467 gen_rtx (MEM, BLKmode,
8468 expand_expr (arg1, NULL_RTX,
8469 ptr_mode,
8470 EXPAND_NORMAL)),
8471 gen_rtx (MEM, BLKmode,
8472 expand_expr (arg2, NULL_RTX,
8473 ptr_mode,
8474 EXPAND_NORMAL)),
8475 expand_expr (len, NULL_RTX, VOIDmode, 0),
8476 GEN_INT (MIN (arg1_align, arg2_align))));
8478 /* Return the value in the proper mode for this function. */
8479 mode = TYPE_MODE (TREE_TYPE (exp));
8480 if (GET_MODE (result) == mode)
8481 return result;
8482 else if (target != 0)
8484 convert_move (target, result, 0);
8485 return target;
8487 else
8488 return convert_to_mode (mode, result, 0);
8490 #else
8491 case BUILT_IN_STRCMP:
8492 case BUILT_IN_MEMCMP:
8493 break;
8494 #endif
8496 /* __builtin_setjmp is passed a pointer to an array of five words
8497 (not all will be used on all machines). It operates similarly to
8498 the C library function of the same name, but is more efficient.
8499 Much of the code below (and for longjmp) is copied from the handling
8500 of non-local gotos.
8502 NOTE: This is intended for use by GNAT and will only work in
8503 the method used by it. This code will likely NOT survive to
8504 the GCC 2.8.0 release. */
8505 case BUILT_IN_SETJMP:
8506 if (arglist == 0
8507 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
8508 break;
8511 rtx buf_addr
8512 = force_reg (Pmode, expand_expr (TREE_VALUE (arglist), subtarget,
8513 VOIDmode, 0));
8514 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
8515 enum machine_mode sa_mode = Pmode;
8516 rtx stack_save;
8517 int i;
8519 if (target == 0 || GET_CODE (target) != REG
8520 || REGNO (target) < FIRST_PSEUDO_REGISTER)
8521 target = gen_reg_rtx (value_mode);
8523 emit_queue ();
8525 emit_note (NULL_PTR, NOTE_INSN_SETJMP);
8526 current_function_calls_setjmp = 1;
8528 /* We store the frame pointer and the address of lab1 in the buffer
8529 and use the rest of it for the stack save area, which is
8530 machine-dependent. */
8531 emit_move_insn (gen_rtx (MEM, Pmode, buf_addr),
8532 virtual_stack_vars_rtx);
8533 emit_move_insn
8534 (validize_mem (gen_rtx (MEM, Pmode,
8535 plus_constant (buf_addr,
8536 GET_MODE_SIZE (Pmode)))),
8537 gen_rtx (LABEL_REF, Pmode, lab1));
8539 #ifdef HAVE_save_stack_nonlocal
8540 if (HAVE_save_stack_nonlocal)
8541 sa_mode = insn_operand_mode[(int) CODE_FOR_save_stack_nonlocal][0];
8542 #endif
8544 stack_save = gen_rtx (MEM, sa_mode,
8545 plus_constant (buf_addr,
8546 2 * GET_MODE_SIZE (Pmode)));
8547 emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
8549 /* Set TARGET to zero and branch around the other case. */
8550 emit_move_insn (target, const0_rtx);
8551 emit_jump_insn (gen_jump (lab2));
8552 emit_barrier ();
8553 emit_label (lab1);
8555 /* Note that setjmp clobbers FP when we get here, so we have to
8556 make sure it's marked as used by this function. Also,
8557 some inner function might use a call-saved register, so we
8558 have to set up to save all of them here. */
8559 emit_insn (gen_rtx (USE, VOIDmode, hard_frame_pointer_rtx));
8561 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
8562 if (! call_used_regs[i])
8563 emit_insn (gen_rtx (USE, VOIDmode,
8564 gen_rtx (REG, reg_raw_mode[i], i)));
8566 /* Now put in the code to restore the frame pointer, and argument
8567 pointer, if needed. The code below is from expand_end_bindings
8568 in stmt.c; see detailed documentation there. */
8569 #ifdef HAVE_nonlocal_goto
8570 if (! HAVE_nonlocal_goto)
8571 #endif
8572 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
8574 current_function_has_nonlocal_goto = 1;
8576 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8577 if (fixed_regs[ARG_POINTER_REGNUM])
8579 #ifdef ELIMINABLE_REGS
8580 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
8582 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
8583 if (elim_regs[i].from == ARG_POINTER_REGNUM
8584 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
8585 break;
8587 if (i == sizeof elim_regs / sizeof elim_regs [0])
8588 #endif
8590 /* Now restore our arg pointer from the address at which it
8591 was saved in our stack frame.
8592 If there hasn't be space allocated for it yet, make
8593 some now. */
8594 if (arg_pointer_save_area == 0)
8595 arg_pointer_save_area
8596 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
8597 emit_move_insn (virtual_incoming_args_rtx,
8598 copy_to_reg (arg_pointer_save_area));
8601 #endif
8603 /* The result to return is in the static chain pointer. */
8604 if (GET_MODE (static_chain_rtx) == GET_MODE (target))
8605 emit_move_insn (target, static_chain_rtx);
8606 else
8607 convert_move (target, static_chain_rtx, 0);
8609 emit_label (lab2);
8610 return target;
8613 /* __builtin_longjmp is passed a pointer to an array of five words
8614 and a value to return. It's similar to the C library longjmp
8615 function but works with __builtin_setjmp above. */
8616 case BUILT_IN_LONGJMP:
8617 if (arglist == 0 || TREE_CHAIN (arglist) == 0
8618 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
8619 break;
8622 rtx buf_addr
8623 = force_reg (Pmode, expand_expr (TREE_VALUE (arglist), NULL_RTX,
8624 VOIDmode, 0));
8625 rtx fp = gen_rtx (MEM, Pmode, buf_addr);
8626 rtx lab = gen_rtx (MEM, Pmode,
8627 plus_constant (buf_addr, GET_MODE_SIZE (Pmode)));
8628 enum machine_mode sa_mode
8629 #ifdef HAVE_save_stack_nonlocal
8630 = (HAVE_save_stack_nonlocal
8631 ? insn_operand_mode[(int) CODE_FOR_save_stack_nonlocal][0]
8632 : Pmode);
8633 #else
8634 = Pmode;
8635 #endif
8636 rtx stack = gen_rtx (MEM, sa_mode,
8637 plus_constant (buf_addr,
8638 2 * GET_MODE_SIZE (Pmode)));
8639 rtx value = expand_expr (TREE_VALUE (TREE_CHAIN (arglist)), NULL_RTX,
8640 VOIDmode, 0);
8642 /* Pick up FP, label, and SP from the block and jump. This code is
8643 from expand_goto in stmt.c; see there for detailed comments. */
8644 #if HAVE_nonlocal_goto
8645 if (HAVE_nonlocal_goto)
8646 emit_insn (gen_nonlocal_goto (fp, lab, stack, value));
8647 else
8648 #endif
8650 emit_move_insn (hard_frame_pointer_rtx, fp);
8651 emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
8653 /* Put in the static chain register the return value. */
8654 emit_move_insn (static_chain_rtx, value);
8655 emit_insn (gen_rtx (USE, VOIDmode, hard_frame_pointer_rtx));
8656 emit_insn (gen_rtx (USE, VOIDmode, stack_pointer_rtx));
8657 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
8658 emit_indirect_jump (copy_to_reg (lab));
8661 return const0_rtx;
8664 default: /* just do library call, if unknown builtin */
8665 error ("built-in function `%s' not currently supported",
8666 IDENTIFIER_POINTER (DECL_NAME (fndecl)));
8669 /* The switch statement above can drop through to cause the function
8670 to be called normally. */
8672 return expand_call (exp, target, ignore);
8675 /* Built-in functions to perform an untyped call and return. */
8677 /* For each register that may be used for calling a function, this
8678 gives a mode used to copy the register's value. VOIDmode indicates
8679 the register is not used for calling a function. If the machine
8680 has register windows, this gives only the outbound registers.
8681 INCOMING_REGNO gives the corresponding inbound register. */
8682 static enum machine_mode apply_args_mode[FIRST_PSEUDO_REGISTER];
8684 /* For each register that may be used for returning values, this gives
8685 a mode used to copy the register's value. VOIDmode indicates the
8686 register is not used for returning values. If the machine has
8687 register windows, this gives only the outbound registers.
8688 INCOMING_REGNO gives the corresponding inbound register. */
8689 static enum machine_mode apply_result_mode[FIRST_PSEUDO_REGISTER];
8691 /* For each register that may be used for calling a function, this
8692 gives the offset of that register into the block returned by
8693 __builtin_apply_args. 0 indicates that the register is not
8694 used for calling a function. */
8695 static int apply_args_reg_offset[FIRST_PSEUDO_REGISTER];
8697 /* Return the offset of register REGNO into the block returned by
8698 __builtin_apply_args. This is not declared static, since it is
8699 needed in objc-act.c. */
8701 int
8702 apply_args_register_offset (regno)
8703 int regno;
8705 apply_args_size ();
8707 /* Arguments are always put in outgoing registers (in the argument
8708 block) if such make sense. */
8709 #ifdef OUTGOING_REGNO
8710 regno = OUTGOING_REGNO(regno);
8711 #endif
8712 return apply_args_reg_offset[regno];
8715 /* Return the size required for the block returned by __builtin_apply_args,
8716 and initialize apply_args_mode. */
8718 static int
8719 apply_args_size ()
8721 static int size = -1;
8722 int align, regno;
8723 enum machine_mode mode;
8725 /* The values computed by this function never change. */
8726 if (size < 0)
8728 /* The first value is the incoming arg-pointer. */
8729 size = GET_MODE_SIZE (Pmode);
8731 /* The second value is the structure value address unless this is
8732 passed as an "invisible" first argument. */
8733 if (struct_value_rtx)
8734 size += GET_MODE_SIZE (Pmode);
8736 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8737 if (FUNCTION_ARG_REGNO_P (regno))
8739 /* Search for the proper mode for copying this register's
8740 value. I'm not sure this is right, but it works so far. */
8741 enum machine_mode best_mode = VOIDmode;
8743 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
8744 mode != VOIDmode;
8745 mode = GET_MODE_WIDER_MODE (mode))
8746 if (HARD_REGNO_MODE_OK (regno, mode)
8747 && HARD_REGNO_NREGS (regno, mode) == 1)
8748 best_mode = mode;
8750 if (best_mode == VOIDmode)
8751 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
8752 mode != VOIDmode;
8753 mode = GET_MODE_WIDER_MODE (mode))
8754 if (HARD_REGNO_MODE_OK (regno, mode)
8755 && (mov_optab->handlers[(int) mode].insn_code
8756 != CODE_FOR_nothing))
8757 best_mode = mode;
8759 mode = best_mode;
8760 if (mode == VOIDmode)
8761 abort ();
8763 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
8764 if (size % align != 0)
8765 size = CEIL (size, align) * align;
8766 apply_args_reg_offset[regno] = size;
8767 size += GET_MODE_SIZE (mode);
8768 apply_args_mode[regno] = mode;
8770 else
8772 apply_args_mode[regno] = VOIDmode;
8773 apply_args_reg_offset[regno] = 0;
8776 return size;
8779 /* Return the size required for the block returned by __builtin_apply,
8780 and initialize apply_result_mode. */
8782 static int
8783 apply_result_size ()
8785 static int size = -1;
8786 int align, regno;
8787 enum machine_mode mode;
8789 /* The values computed by this function never change. */
8790 if (size < 0)
8792 size = 0;
8794 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8795 if (FUNCTION_VALUE_REGNO_P (regno))
8797 /* Search for the proper mode for copying this register's
8798 value. I'm not sure this is right, but it works so far. */
8799 enum machine_mode best_mode = VOIDmode;
8801 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
8802 mode != TImode;
8803 mode = GET_MODE_WIDER_MODE (mode))
8804 if (HARD_REGNO_MODE_OK (regno, mode))
8805 best_mode = mode;
8807 if (best_mode == VOIDmode)
8808 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
8809 mode != VOIDmode;
8810 mode = GET_MODE_WIDER_MODE (mode))
8811 if (HARD_REGNO_MODE_OK (regno, mode)
8812 && (mov_optab->handlers[(int) mode].insn_code
8813 != CODE_FOR_nothing))
8814 best_mode = mode;
8816 mode = best_mode;
8817 if (mode == VOIDmode)
8818 abort ();
8820 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
8821 if (size % align != 0)
8822 size = CEIL (size, align) * align;
8823 size += GET_MODE_SIZE (mode);
8824 apply_result_mode[regno] = mode;
8826 else
8827 apply_result_mode[regno] = VOIDmode;
8829 /* Allow targets that use untyped_call and untyped_return to override
8830 the size so that machine-specific information can be stored here. */
8831 #ifdef APPLY_RESULT_SIZE
8832 size = APPLY_RESULT_SIZE;
8833 #endif
8835 return size;
8838 #if defined (HAVE_untyped_call) || defined (HAVE_untyped_return)
8839 /* Create a vector describing the result block RESULT. If SAVEP is true,
8840 the result block is used to save the values; otherwise it is used to
8841 restore the values. */
8843 static rtx
8844 result_vector (savep, result)
8845 int savep;
8846 rtx result;
8848 int regno, size, align, nelts;
8849 enum machine_mode mode;
8850 rtx reg, mem;
8851 rtx *savevec = (rtx *) alloca (FIRST_PSEUDO_REGISTER * sizeof (rtx));
8853 size = nelts = 0;
8854 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8855 if ((mode = apply_result_mode[regno]) != VOIDmode)
8857 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
8858 if (size % align != 0)
8859 size = CEIL (size, align) * align;
8860 reg = gen_rtx (REG, mode, savep ? regno : INCOMING_REGNO (regno));
8861 mem = change_address (result, mode,
8862 plus_constant (XEXP (result, 0), size));
8863 savevec[nelts++] = (savep
8864 ? gen_rtx (SET, VOIDmode, mem, reg)
8865 : gen_rtx (SET, VOIDmode, reg, mem));
8866 size += GET_MODE_SIZE (mode);
8868 return gen_rtx (PARALLEL, VOIDmode, gen_rtvec_v (nelts, savevec));
8870 #endif /* HAVE_untyped_call or HAVE_untyped_return */
8872 /* Save the state required to perform an untyped call with the same
8873 arguments as were passed to the current function. */
8875 static rtx
8876 expand_builtin_apply_args ()
8878 rtx registers;
8879 int size, align, regno;
8880 enum machine_mode mode;
8882 /* Create a block where the arg-pointer, structure value address,
8883 and argument registers can be saved. */
8884 registers = assign_stack_local (BLKmode, apply_args_size (), -1);
8886 /* Walk past the arg-pointer and structure value address. */
8887 size = GET_MODE_SIZE (Pmode);
8888 if (struct_value_rtx)
8889 size += GET_MODE_SIZE (Pmode);
8891 /* Save each register used in calling a function to the block. */
8892 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8893 if ((mode = apply_args_mode[regno]) != VOIDmode)
8895 rtx tem;
8897 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
8898 if (size % align != 0)
8899 size = CEIL (size, align) * align;
8901 tem = gen_rtx (REG, mode, INCOMING_REGNO (regno));
8903 #ifdef STACK_REGS
8904 /* For reg-stack.c's stack register household.
8905 Compare with a similar piece of code in function.c. */
8907 emit_insn (gen_rtx (USE, mode, tem));
8908 #endif
8910 emit_move_insn (change_address (registers, mode,
8911 plus_constant (XEXP (registers, 0),
8912 size)),
8913 tem);
8914 size += GET_MODE_SIZE (mode);
8917 /* Save the arg pointer to the block. */
8918 emit_move_insn (change_address (registers, Pmode, XEXP (registers, 0)),
8919 copy_to_reg (virtual_incoming_args_rtx));
8920 size = GET_MODE_SIZE (Pmode);
8922 /* Save the structure value address unless this is passed as an
8923 "invisible" first argument. */
8924 if (struct_value_incoming_rtx)
8926 emit_move_insn (change_address (registers, Pmode,
8927 plus_constant (XEXP (registers, 0),
8928 size)),
8929 copy_to_reg (struct_value_incoming_rtx));
8930 size += GET_MODE_SIZE (Pmode);
8933 /* Return the address of the block. */
8934 return copy_addr_to_reg (XEXP (registers, 0));
8937 /* Perform an untyped call and save the state required to perform an
8938 untyped return of whatever value was returned by the given function. */
8940 static rtx
8941 expand_builtin_apply (function, arguments, argsize)
8942 rtx function, arguments, argsize;
8944 int size, align, regno;
8945 enum machine_mode mode;
8946 rtx incoming_args, result, reg, dest, call_insn;
8947 rtx old_stack_level = 0;
8948 rtx call_fusage = 0;
8950 /* Create a block where the return registers can be saved. */
8951 result = assign_stack_local (BLKmode, apply_result_size (), -1);
8953 /* ??? The argsize value should be adjusted here. */
8955 /* Fetch the arg pointer from the ARGUMENTS block. */
8956 incoming_args = gen_reg_rtx (Pmode);
8957 emit_move_insn (incoming_args,
8958 gen_rtx (MEM, Pmode, arguments));
8959 #ifndef STACK_GROWS_DOWNWARD
8960 incoming_args = expand_binop (Pmode, sub_optab, incoming_args, argsize,
8961 incoming_args, 0, OPTAB_LIB_WIDEN);
8962 #endif
8964 /* Perform postincrements before actually calling the function. */
8965 emit_queue ();
8967 /* Push a new argument block and copy the arguments. */
8968 do_pending_stack_adjust ();
8969 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
8971 /* Push a block of memory onto the stack to store the memory arguments.
8972 Save the address in a register, and copy the memory arguments. ??? I
8973 haven't figured out how the calling convention macros effect this,
8974 but it's likely that the source and/or destination addresses in
8975 the block copy will need updating in machine specific ways. */
8976 dest = copy_addr_to_reg (push_block (argsize, 0, 0));
8977 emit_block_move (gen_rtx (MEM, BLKmode, dest),
8978 gen_rtx (MEM, BLKmode, incoming_args),
8979 argsize,
8980 PARM_BOUNDARY / BITS_PER_UNIT);
8982 /* Refer to the argument block. */
8983 apply_args_size ();
8984 arguments = gen_rtx (MEM, BLKmode, arguments);
8986 /* Walk past the arg-pointer and structure value address. */
8987 size = GET_MODE_SIZE (Pmode);
8988 if (struct_value_rtx)
8989 size += GET_MODE_SIZE (Pmode);
8991 /* Restore each of the registers previously saved. Make USE insns
8992 for each of these registers for use in making the call. */
8993 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8994 if ((mode = apply_args_mode[regno]) != VOIDmode)
8996 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
8997 if (size % align != 0)
8998 size = CEIL (size, align) * align;
8999 reg = gen_rtx (REG, mode, regno);
9000 emit_move_insn (reg,
9001 change_address (arguments, mode,
9002 plus_constant (XEXP (arguments, 0),
9003 size)));
9005 use_reg (&call_fusage, reg);
9006 size += GET_MODE_SIZE (mode);
9009 /* Restore the structure value address unless this is passed as an
9010 "invisible" first argument. */
9011 size = GET_MODE_SIZE (Pmode);
9012 if (struct_value_rtx)
9014 rtx value = gen_reg_rtx (Pmode);
9015 emit_move_insn (value,
9016 change_address (arguments, Pmode,
9017 plus_constant (XEXP (arguments, 0),
9018 size)));
9019 emit_move_insn (struct_value_rtx, value);
9020 if (GET_CODE (struct_value_rtx) == REG)
9021 use_reg (&call_fusage, struct_value_rtx);
9022 size += GET_MODE_SIZE (Pmode);
9025 /* All arguments and registers used for the call are set up by now! */
9026 function = prepare_call_address (function, NULL_TREE, &call_fusage, 0);
9028 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
9029 and we don't want to load it into a register as an optimization,
9030 because prepare_call_address already did it if it should be done. */
9031 if (GET_CODE (function) != SYMBOL_REF)
9032 function = memory_address (FUNCTION_MODE, function);
9034 /* Generate the actual call instruction and save the return value. */
9035 #ifdef HAVE_untyped_call
9036 if (HAVE_untyped_call)
9037 emit_call_insn (gen_untyped_call (gen_rtx (MEM, FUNCTION_MODE, function),
9038 result, result_vector (1, result)));
9039 else
9040 #endif
9041 #ifdef HAVE_call_value
9042 if (HAVE_call_value)
9044 rtx valreg = 0;
9046 /* Locate the unique return register. It is not possible to
9047 express a call that sets more than one return register using
9048 call_value; use untyped_call for that. In fact, untyped_call
9049 only needs to save the return registers in the given block. */
9050 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9051 if ((mode = apply_result_mode[regno]) != VOIDmode)
9053 if (valreg)
9054 abort (); /* HAVE_untyped_call required. */
9055 valreg = gen_rtx (REG, mode, regno);
9058 emit_call_insn (gen_call_value (valreg,
9059 gen_rtx (MEM, FUNCTION_MODE, function),
9060 const0_rtx, NULL_RTX, const0_rtx));
9062 emit_move_insn (change_address (result, GET_MODE (valreg),
9063 XEXP (result, 0)),
9064 valreg);
9066 else
9067 #endif
9068 abort ();
9070 /* Find the CALL insn we just emitted. */
9071 for (call_insn = get_last_insn ();
9072 call_insn && GET_CODE (call_insn) != CALL_INSN;
9073 call_insn = PREV_INSN (call_insn))
9076 if (! call_insn)
9077 abort ();
9079 /* Put the register usage information on the CALL. If there is already
9080 some usage information, put ours at the end. */
9081 if (CALL_INSN_FUNCTION_USAGE (call_insn))
9083 rtx link;
9085 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
9086 link = XEXP (link, 1))
9089 XEXP (link, 1) = call_fusage;
9091 else
9092 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
9094 /* Restore the stack. */
9095 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
9097 /* Return the address of the result block. */
9098 return copy_addr_to_reg (XEXP (result, 0));
9101 /* Perform an untyped return. */
9103 static void
9104 expand_builtin_return (result)
9105 rtx result;
9107 int size, align, regno;
9108 enum machine_mode mode;
9109 rtx reg;
9110 rtx call_fusage = 0;
9112 apply_result_size ();
9113 result = gen_rtx (MEM, BLKmode, result);
9115 #ifdef HAVE_untyped_return
9116 if (HAVE_untyped_return)
9118 emit_jump_insn (gen_untyped_return (result, result_vector (0, result)));
9119 emit_barrier ();
9120 return;
9122 #endif
9124 /* Restore the return value and note that each value is used. */
9125 size = 0;
9126 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9127 if ((mode = apply_result_mode[regno]) != VOIDmode)
9129 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9130 if (size % align != 0)
9131 size = CEIL (size, align) * align;
9132 reg = gen_rtx (REG, mode, INCOMING_REGNO (regno));
9133 emit_move_insn (reg,
9134 change_address (result, mode,
9135 plus_constant (XEXP (result, 0),
9136 size)));
9138 push_to_sequence (call_fusage);
9139 emit_insn (gen_rtx (USE, VOIDmode, reg));
9140 call_fusage = get_insns ();
9141 end_sequence ();
9142 size += GET_MODE_SIZE (mode);
9145 /* Put the USE insns before the return. */
9146 emit_insns (call_fusage);
9148 /* Return whatever values was restored by jumping directly to the end
9149 of the function. */
9150 expand_null_return ();
9153 /* Expand code for a post- or pre- increment or decrement
9154 and return the RTX for the result.
9155 POST is 1 for postinc/decrements and 0 for preinc/decrements. */
9157 static rtx
9158 expand_increment (exp, post)
9159 register tree exp;
9160 int post;
9162 register rtx op0, op1;
9163 register rtx temp, value;
9164 register tree incremented = TREE_OPERAND (exp, 0);
9165 optab this_optab = add_optab;
9166 int icode;
9167 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
9168 int op0_is_copy = 0;
9169 int single_insn = 0;
9170 /* 1 means we can't store into OP0 directly,
9171 because it is a subreg narrower than a word,
9172 and we don't dare clobber the rest of the word. */
9173 int bad_subreg = 0;
9175 if (output_bytecode)
9177 bc_expand_expr (exp);
9178 return NULL_RTX;
9181 /* Stabilize any component ref that might need to be
9182 evaluated more than once below. */
9183 if (!post
9184 || TREE_CODE (incremented) == BIT_FIELD_REF
9185 || (TREE_CODE (incremented) == COMPONENT_REF
9186 && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
9187 || DECL_BIT_FIELD (TREE_OPERAND (incremented, 1)))))
9188 incremented = stabilize_reference (incremented);
9189 /* Nested *INCREMENT_EXPRs can happen in C++. We must force innermost
9190 ones into save exprs so that they don't accidentally get evaluated
9191 more than once by the code below. */
9192 if (TREE_CODE (incremented) == PREINCREMENT_EXPR
9193 || TREE_CODE (incremented) == PREDECREMENT_EXPR)
9194 incremented = save_expr (incremented);
9196 /* Compute the operands as RTX.
9197 Note whether OP0 is the actual lvalue or a copy of it:
9198 I believe it is a copy iff it is a register or subreg
9199 and insns were generated in computing it. */
9201 temp = get_last_insn ();
9202 op0 = expand_expr (incremented, NULL_RTX, VOIDmode, 0);
9204 /* If OP0 is a SUBREG made for a promoted variable, we cannot increment
9205 in place but instead must do sign- or zero-extension during assignment,
9206 so we copy it into a new register and let the code below use it as
9207 a copy.
9209 Note that we can safely modify this SUBREG since it is know not to be
9210 shared (it was made by the expand_expr call above). */
9212 if (GET_CODE (op0) == SUBREG && SUBREG_PROMOTED_VAR_P (op0))
9214 if (post)
9215 SUBREG_REG (op0) = copy_to_reg (SUBREG_REG (op0));
9216 else
9217 bad_subreg = 1;
9219 else if (GET_CODE (op0) == SUBREG
9220 && GET_MODE_BITSIZE (GET_MODE (op0)) < BITS_PER_WORD)
9222 /* We cannot increment this SUBREG in place. If we are
9223 post-incrementing, get a copy of the old value. Otherwise,
9224 just mark that we cannot increment in place. */
9225 if (post)
9226 op0 = copy_to_reg (op0);
9227 else
9228 bad_subreg = 1;
9231 op0_is_copy = ((GET_CODE (op0) == SUBREG || GET_CODE (op0) == REG)
9232 && temp != get_last_insn ());
9233 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
9235 /* Decide whether incrementing or decrementing. */
9236 if (TREE_CODE (exp) == POSTDECREMENT_EXPR
9237 || TREE_CODE (exp) == PREDECREMENT_EXPR)
9238 this_optab = sub_optab;
9240 /* Convert decrement by a constant into a negative increment. */
9241 if (this_optab == sub_optab
9242 && GET_CODE (op1) == CONST_INT)
9244 op1 = GEN_INT (- INTVAL (op1));
9245 this_optab = add_optab;
9248 /* For a preincrement, see if we can do this with a single instruction. */
9249 if (!post)
9251 icode = (int) this_optab->handlers[(int) mode].insn_code;
9252 if (icode != (int) CODE_FOR_nothing
9253 /* Make sure that OP0 is valid for operands 0 and 1
9254 of the insn we want to queue. */
9255 && (*insn_operand_predicate[icode][0]) (op0, mode)
9256 && (*insn_operand_predicate[icode][1]) (op0, mode)
9257 && (*insn_operand_predicate[icode][2]) (op1, mode))
9258 single_insn = 1;
9261 /* If OP0 is not the actual lvalue, but rather a copy in a register,
9262 then we cannot just increment OP0. We must therefore contrive to
9263 increment the original value. Then, for postincrement, we can return
9264 OP0 since it is a copy of the old value. For preincrement, expand here
9265 unless we can do it with a single insn.
9267 Likewise if storing directly into OP0 would clobber high bits
9268 we need to preserve (bad_subreg). */
9269 if (op0_is_copy || (!post && !single_insn) || bad_subreg)
9271 /* This is the easiest way to increment the value wherever it is.
9272 Problems with multiple evaluation of INCREMENTED are prevented
9273 because either (1) it is a component_ref or preincrement,
9274 in which case it was stabilized above, or (2) it is an array_ref
9275 with constant index in an array in a register, which is
9276 safe to reevaluate. */
9277 tree newexp = build (((TREE_CODE (exp) == POSTDECREMENT_EXPR
9278 || TREE_CODE (exp) == PREDECREMENT_EXPR)
9279 ? MINUS_EXPR : PLUS_EXPR),
9280 TREE_TYPE (exp),
9281 incremented,
9282 TREE_OPERAND (exp, 1));
9284 while (TREE_CODE (incremented) == NOP_EXPR
9285 || TREE_CODE (incremented) == CONVERT_EXPR)
9287 newexp = convert (TREE_TYPE (incremented), newexp);
9288 incremented = TREE_OPERAND (incremented, 0);
9291 temp = expand_assignment (incremented, newexp, ! post, 0);
9292 return post ? op0 : temp;
9295 if (post)
9297 /* We have a true reference to the value in OP0.
9298 If there is an insn to add or subtract in this mode, queue it.
9299 Queueing the increment insn avoids the register shuffling
9300 that often results if we must increment now and first save
9301 the old value for subsequent use. */
9303 #if 0 /* Turned off to avoid making extra insn for indexed memref. */
9304 op0 = stabilize (op0);
9305 #endif
9307 icode = (int) this_optab->handlers[(int) mode].insn_code;
9308 if (icode != (int) CODE_FOR_nothing
9309 /* Make sure that OP0 is valid for operands 0 and 1
9310 of the insn we want to queue. */
9311 && (*insn_operand_predicate[icode][0]) (op0, mode)
9312 && (*insn_operand_predicate[icode][1]) (op0, mode))
9314 if (! (*insn_operand_predicate[icode][2]) (op1, mode))
9315 op1 = force_reg (mode, op1);
9317 return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
9321 /* Preincrement, or we can't increment with one simple insn. */
9322 if (post)
9323 /* Save a copy of the value before inc or dec, to return it later. */
9324 temp = value = copy_to_reg (op0);
9325 else
9326 /* Arrange to return the incremented value. */
9327 /* Copy the rtx because expand_binop will protect from the queue,
9328 and the results of that would be invalid for us to return
9329 if our caller does emit_queue before using our result. */
9330 temp = copy_rtx (value = op0);
9332 /* Increment however we can. */
9333 op1 = expand_binop (mode, this_optab, value, op1, op0,
9334 TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
9335 /* Make sure the value is stored into OP0. */
9336 if (op1 != op0)
9337 emit_move_insn (op0, op1);
9339 return temp;
9342 /* Expand all function calls contained within EXP, innermost ones first.
9343 But don't look within expressions that have sequence points.
9344 For each CALL_EXPR, record the rtx for its value
9345 in the CALL_EXPR_RTL field. */
9347 static void
9348 preexpand_calls (exp)
9349 tree exp;
9351 register int nops, i;
9352 int type = TREE_CODE_CLASS (TREE_CODE (exp));
9354 if (! do_preexpand_calls)
9355 return;
9357 /* Only expressions and references can contain calls. */
9359 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r')
9360 return;
9362 switch (TREE_CODE (exp))
9364 case CALL_EXPR:
9365 /* Do nothing if already expanded. */
9366 if (CALL_EXPR_RTL (exp) != 0)
9367 return;
9369 /* Do nothing to built-in functions. */
9370 if (TREE_CODE (TREE_OPERAND (exp, 0)) != ADDR_EXPR
9371 || TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != FUNCTION_DECL
9372 || ! DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
9373 /* Do nothing if the call returns a variable-sized object. */
9374 || TREE_CODE (TYPE_SIZE (TREE_TYPE(exp))) != INTEGER_CST)
9375 CALL_EXPR_RTL (exp) = expand_call (exp, NULL_RTX, 0);
9376 return;
9378 case COMPOUND_EXPR:
9379 case COND_EXPR:
9380 case TRUTH_ANDIF_EXPR:
9381 case TRUTH_ORIF_EXPR:
9382 /* If we find one of these, then we can be sure
9383 the adjust will be done for it (since it makes jumps).
9384 Do it now, so that if this is inside an argument
9385 of a function, we don't get the stack adjustment
9386 after some other args have already been pushed. */
9387 do_pending_stack_adjust ();
9388 return;
9390 case BLOCK:
9391 case RTL_EXPR:
9392 case WITH_CLEANUP_EXPR:
9393 case CLEANUP_POINT_EXPR:
9394 return;
9396 case SAVE_EXPR:
9397 if (SAVE_EXPR_RTL (exp) != 0)
9398 return;
9401 nops = tree_code_length[(int) TREE_CODE (exp)];
9402 for (i = 0; i < nops; i++)
9403 if (TREE_OPERAND (exp, i) != 0)
9405 type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
9406 if (type == 'e' || type == '<' || type == '1' || type == '2'
9407 || type == 'r')
9408 preexpand_calls (TREE_OPERAND (exp, i));
9412 /* At the start of a function, record that we have no previously-pushed
9413 arguments waiting to be popped. */
9415 void
9416 init_pending_stack_adjust ()
9418 pending_stack_adjust = 0;
9421 /* When exiting from function, if safe, clear out any pending stack adjust
9422 so the adjustment won't get done. */
9424 void
9425 clear_pending_stack_adjust ()
9427 #ifdef EXIT_IGNORE_STACK
9428 if (optimize > 0
9429 && ! flag_omit_frame_pointer && EXIT_IGNORE_STACK
9430 && ! (DECL_INLINE (current_function_decl) && ! flag_no_inline)
9431 && ! flag_inline_functions)
9432 pending_stack_adjust = 0;
9433 #endif
9436 /* Pop any previously-pushed arguments that have not been popped yet. */
9438 void
9439 do_pending_stack_adjust ()
9441 if (inhibit_defer_pop == 0)
9443 if (pending_stack_adjust != 0)
9444 adjust_stack (GEN_INT (pending_stack_adjust));
9445 pending_stack_adjust = 0;
9449 /* Defer the expansion all cleanups up to OLD_CLEANUPS.
9450 Returns the cleanups to be performed. */
9452 static tree
9453 defer_cleanups_to (old_cleanups)
9454 tree old_cleanups;
9456 tree new_cleanups = NULL_TREE;
9457 tree cleanups = cleanups_this_call;
9458 tree last = NULL_TREE;
9460 while (cleanups_this_call != old_cleanups)
9462 (*interim_eh_hook) (TREE_VALUE (cleanups_this_call));
9463 last = cleanups_this_call;
9464 cleanups_this_call = TREE_CHAIN (cleanups_this_call);
9467 if (last)
9469 /* Remove the list from the chain of cleanups. */
9470 TREE_CHAIN (last) = NULL_TREE;
9472 /* reverse them so that we can build them in the right order. */
9473 cleanups = nreverse (cleanups);
9475 /* All cleanups must be on the function_obstack. */
9476 push_obstacks_nochange ();
9477 resume_temporary_allocation ();
9479 while (cleanups)
9481 if (new_cleanups)
9482 new_cleanups = build (COMPOUND_EXPR, TREE_TYPE (new_cleanups),
9483 TREE_VALUE (cleanups), new_cleanups);
9484 else
9485 new_cleanups = TREE_VALUE (cleanups);
9487 cleanups = TREE_CHAIN (cleanups);
9490 pop_obstacks ();
9493 return new_cleanups;
9496 /* Expand all cleanups up to OLD_CLEANUPS.
9497 Needed here, and also for language-dependent calls. */
9499 void
9500 expand_cleanups_to (old_cleanups)
9501 tree old_cleanups;
9503 while (cleanups_this_call != old_cleanups)
9505 (*interim_eh_hook) (TREE_VALUE (cleanups_this_call));
9506 expand_expr (TREE_VALUE (cleanups_this_call), const0_rtx, VOIDmode, 0);
9507 cleanups_this_call = TREE_CHAIN (cleanups_this_call);
9511 /* Expand conditional expressions. */
9513 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
9514 LABEL is an rtx of code CODE_LABEL, in this function and all the
9515 functions here. */
9517 void
9518 jumpifnot (exp, label)
9519 tree exp;
9520 rtx label;
9522 do_jump (exp, label, NULL_RTX);
9525 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
9527 void
9528 jumpif (exp, label)
9529 tree exp;
9530 rtx label;
9532 do_jump (exp, NULL_RTX, label);
9535 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
9536 the result is zero, or IF_TRUE_LABEL if the result is one.
9537 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
9538 meaning fall through in that case.
9540 do_jump always does any pending stack adjust except when it does not
9541 actually perform a jump. An example where there is no jump
9542 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
9544 This function is responsible for optimizing cases such as
9545 &&, || and comparison operators in EXP. */
9547 void
9548 do_jump (exp, if_false_label, if_true_label)
9549 tree exp;
9550 rtx if_false_label, if_true_label;
9552 register enum tree_code code = TREE_CODE (exp);
9553 /* Some cases need to create a label to jump to
9554 in order to properly fall through.
9555 These cases set DROP_THROUGH_LABEL nonzero. */
9556 rtx drop_through_label = 0;
9557 rtx temp;
9558 rtx comparison = 0;
9559 int i;
9560 tree type;
9561 enum machine_mode mode;
9563 emit_queue ();
9565 switch (code)
9567 case ERROR_MARK:
9568 break;
9570 case INTEGER_CST:
9571 temp = integer_zerop (exp) ? if_false_label : if_true_label;
9572 if (temp)
9573 emit_jump (temp);
9574 break;
9576 #if 0
9577 /* This is not true with #pragma weak */
9578 case ADDR_EXPR:
9579 /* The address of something can never be zero. */
9580 if (if_true_label)
9581 emit_jump (if_true_label);
9582 break;
9583 #endif
9585 case NOP_EXPR:
9586 if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
9587 || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
9588 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF)
9589 goto normal;
9590 case CONVERT_EXPR:
9591 /* If we are narrowing the operand, we have to do the compare in the
9592 narrower mode. */
9593 if ((TYPE_PRECISION (TREE_TYPE (exp))
9594 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9595 goto normal;
9596 case NON_LVALUE_EXPR:
9597 case REFERENCE_EXPR:
9598 case ABS_EXPR:
9599 case NEGATE_EXPR:
9600 case LROTATE_EXPR:
9601 case RROTATE_EXPR:
9602 /* These cannot change zero->non-zero or vice versa. */
9603 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9604 break;
9606 #if 0
9607 /* This is never less insns than evaluating the PLUS_EXPR followed by
9608 a test and can be longer if the test is eliminated. */
9609 case PLUS_EXPR:
9610 /* Reduce to minus. */
9611 exp = build (MINUS_EXPR, TREE_TYPE (exp),
9612 TREE_OPERAND (exp, 0),
9613 fold (build1 (NEGATE_EXPR, TREE_TYPE (TREE_OPERAND (exp, 1)),
9614 TREE_OPERAND (exp, 1))));
9615 /* Process as MINUS. */
9616 #endif
9618 case MINUS_EXPR:
9619 /* Non-zero iff operands of minus differ. */
9620 comparison = compare (build (NE_EXPR, TREE_TYPE (exp),
9621 TREE_OPERAND (exp, 0),
9622 TREE_OPERAND (exp, 1)),
9623 NE, NE);
9624 break;
9626 case BIT_AND_EXPR:
9627 /* If we are AND'ing with a small constant, do this comparison in the
9628 smallest type that fits. If the machine doesn't have comparisons
9629 that small, it will be converted back to the wider comparison.
9630 This helps if we are testing the sign bit of a narrower object.
9631 combine can't do this for us because it can't know whether a
9632 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
9634 if (! SLOW_BYTE_ACCESS
9635 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
9636 && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
9637 && (i = floor_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))) >= 0
9638 && (mode = mode_for_size (i + 1, MODE_INT, 0)) != BLKmode
9639 && (type = type_for_mode (mode, 1)) != 0
9640 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
9641 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
9642 != CODE_FOR_nothing))
9644 do_jump (convert (type, exp), if_false_label, if_true_label);
9645 break;
9647 goto normal;
9649 case TRUTH_NOT_EXPR:
9650 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
9651 break;
9653 case TRUTH_ANDIF_EXPR:
9655 rtx seq1, seq2;
9656 tree cleanups, old_cleanups;
9658 if (if_false_label == 0)
9659 if_false_label = drop_through_label = gen_label_rtx ();
9660 start_sequence ();
9661 do_jump (TREE_OPERAND (exp, 0), if_false_label, NULL_RTX);
9662 seq1 = get_insns ();
9663 end_sequence ();
9665 old_cleanups = cleanups_this_call;
9666 start_sequence ();
9667 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9668 seq2 = get_insns ();
9669 end_sequence ();
9671 cleanups = defer_cleanups_to (old_cleanups);
9672 if (cleanups)
9674 rtx flag = gen_reg_rtx (word_mode);
9675 tree new_cleanups;
9676 tree cond;
9678 /* Flag cleanups as not needed. */
9679 emit_move_insn (flag, const0_rtx);
9680 emit_insns (seq1);
9682 /* Flag cleanups as needed. */
9683 emit_move_insn (flag, const1_rtx);
9684 emit_insns (seq2);
9686 /* All cleanups must be on the function_obstack. */
9687 push_obstacks_nochange ();
9688 resume_temporary_allocation ();
9690 /* convert flag, which is an rtx, into a tree. */
9691 cond = make_node (RTL_EXPR);
9692 TREE_TYPE (cond) = integer_type_node;
9693 RTL_EXPR_RTL (cond) = flag;
9694 RTL_EXPR_SEQUENCE (cond) = NULL_RTX;
9695 cond = save_expr (cond);
9697 new_cleanups = build (COND_EXPR, void_type_node,
9698 truthvalue_conversion (cond),
9699 cleanups, integer_zero_node);
9700 new_cleanups = fold (new_cleanups);
9702 pop_obstacks ();
9704 /* Now add in the conditionalized cleanups. */
9705 cleanups_this_call
9706 = tree_cons (NULL_TREE, new_cleanups, cleanups_this_call);
9707 (*interim_eh_hook) (NULL_TREE);
9709 else
9711 emit_insns (seq1);
9712 emit_insns (seq2);
9715 break;
9717 case TRUTH_ORIF_EXPR:
9719 rtx seq1, seq2;
9720 tree cleanups, old_cleanups;
9722 if (if_true_label == 0)
9723 if_true_label = drop_through_label = gen_label_rtx ();
9724 start_sequence ();
9725 do_jump (TREE_OPERAND (exp, 0), NULL_RTX, if_true_label);
9726 seq1 = get_insns ();
9727 end_sequence ();
9729 old_cleanups = cleanups_this_call;
9730 start_sequence ();
9731 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9732 seq2 = get_insns ();
9733 end_sequence ();
9735 cleanups = defer_cleanups_to (old_cleanups);
9736 if (cleanups)
9738 rtx flag = gen_reg_rtx (word_mode);
9739 tree new_cleanups;
9740 tree cond;
9742 /* Flag cleanups as not needed. */
9743 emit_move_insn (flag, const0_rtx);
9744 emit_insns (seq1);
9746 /* Flag cleanups as needed. */
9747 emit_move_insn (flag, const1_rtx);
9748 emit_insns (seq2);
9750 /* All cleanups must be on the function_obstack. */
9751 push_obstacks_nochange ();
9752 resume_temporary_allocation ();
9754 /* convert flag, which is an rtx, into a tree. */
9755 cond = make_node (RTL_EXPR);
9756 TREE_TYPE (cond) = integer_type_node;
9757 RTL_EXPR_RTL (cond) = flag;
9758 RTL_EXPR_SEQUENCE (cond) = NULL_RTX;
9759 cond = save_expr (cond);
9761 new_cleanups = build (COND_EXPR, void_type_node,
9762 truthvalue_conversion (cond),
9763 cleanups, integer_zero_node);
9764 new_cleanups = fold (new_cleanups);
9766 pop_obstacks ();
9768 /* Now add in the conditionalized cleanups. */
9769 cleanups_this_call
9770 = tree_cons (NULL_TREE, new_cleanups, cleanups_this_call);
9771 (*interim_eh_hook) (NULL_TREE);
9773 else
9775 emit_insns (seq1);
9776 emit_insns (seq2);
9779 break;
9781 case COMPOUND_EXPR:
9782 push_temp_slots ();
9783 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
9784 free_temp_slots ();
9785 pop_temp_slots ();
9786 emit_queue ();
9787 do_pending_stack_adjust ();
9788 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9789 break;
9791 case COMPONENT_REF:
9792 case BIT_FIELD_REF:
9793 case ARRAY_REF:
9795 int bitsize, bitpos, unsignedp;
9796 enum machine_mode mode;
9797 tree type;
9798 tree offset;
9799 int volatilep = 0;
9801 /* Get description of this reference. We don't actually care
9802 about the underlying object here. */
9803 get_inner_reference (exp, &bitsize, &bitpos, &offset,
9804 &mode, &unsignedp, &volatilep);
9806 type = type_for_size (bitsize, unsignedp);
9807 if (! SLOW_BYTE_ACCESS
9808 && type != 0 && bitsize >= 0
9809 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
9810 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
9811 != CODE_FOR_nothing))
9813 do_jump (convert (type, exp), if_false_label, if_true_label);
9814 break;
9816 goto normal;
9819 case COND_EXPR:
9820 /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases. */
9821 if (integer_onep (TREE_OPERAND (exp, 1))
9822 && integer_zerop (TREE_OPERAND (exp, 2)))
9823 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9825 else if (integer_zerop (TREE_OPERAND (exp, 1))
9826 && integer_onep (TREE_OPERAND (exp, 2)))
9827 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
9829 else
9831 register rtx label1 = gen_label_rtx ();
9832 drop_through_label = gen_label_rtx ();
9833 do_jump (TREE_OPERAND (exp, 0), label1, NULL_RTX);
9834 /* Now the THEN-expression. */
9835 do_jump (TREE_OPERAND (exp, 1),
9836 if_false_label ? if_false_label : drop_through_label,
9837 if_true_label ? if_true_label : drop_through_label);
9838 /* In case the do_jump just above never jumps. */
9839 do_pending_stack_adjust ();
9840 emit_label (label1);
9841 /* Now the ELSE-expression. */
9842 do_jump (TREE_OPERAND (exp, 2),
9843 if_false_label ? if_false_label : drop_through_label,
9844 if_true_label ? if_true_label : drop_through_label);
9846 break;
9848 case EQ_EXPR:
9850 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
9852 if (integer_zerop (TREE_OPERAND (exp, 1)))
9853 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
9854 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
9855 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
9856 do_jump
9857 (fold
9858 (build (TRUTH_ANDIF_EXPR, TREE_TYPE (exp),
9859 fold (build (EQ_EXPR, TREE_TYPE (exp),
9860 fold (build1 (REALPART_EXPR,
9861 TREE_TYPE (inner_type),
9862 TREE_OPERAND (exp, 0))),
9863 fold (build1 (REALPART_EXPR,
9864 TREE_TYPE (inner_type),
9865 TREE_OPERAND (exp, 1))))),
9866 fold (build (EQ_EXPR, TREE_TYPE (exp),
9867 fold (build1 (IMAGPART_EXPR,
9868 TREE_TYPE (inner_type),
9869 TREE_OPERAND (exp, 0))),
9870 fold (build1 (IMAGPART_EXPR,
9871 TREE_TYPE (inner_type),
9872 TREE_OPERAND (exp, 1))))))),
9873 if_false_label, if_true_label);
9874 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
9875 && !can_compare_p (TYPE_MODE (inner_type)))
9876 do_jump_by_parts_equality (exp, if_false_label, if_true_label);
9877 else
9878 comparison = compare (exp, EQ, EQ);
9879 break;
9882 case NE_EXPR:
9884 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
9886 if (integer_zerop (TREE_OPERAND (exp, 1)))
9887 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9888 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
9889 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
9890 do_jump
9891 (fold
9892 (build (TRUTH_ORIF_EXPR, TREE_TYPE (exp),
9893 fold (build (NE_EXPR, TREE_TYPE (exp),
9894 fold (build1 (REALPART_EXPR,
9895 TREE_TYPE (inner_type),
9896 TREE_OPERAND (exp, 0))),
9897 fold (build1 (REALPART_EXPR,
9898 TREE_TYPE (inner_type),
9899 TREE_OPERAND (exp, 1))))),
9900 fold (build (NE_EXPR, TREE_TYPE (exp),
9901 fold (build1 (IMAGPART_EXPR,
9902 TREE_TYPE (inner_type),
9903 TREE_OPERAND (exp, 0))),
9904 fold (build1 (IMAGPART_EXPR,
9905 TREE_TYPE (inner_type),
9906 TREE_OPERAND (exp, 1))))))),
9907 if_false_label, if_true_label);
9908 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
9909 && !can_compare_p (TYPE_MODE (inner_type)))
9910 do_jump_by_parts_equality (exp, if_true_label, if_false_label);
9911 else
9912 comparison = compare (exp, NE, NE);
9913 break;
9916 case LT_EXPR:
9917 if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9918 == MODE_INT)
9919 && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9920 do_jump_by_parts_greater (exp, 1, if_false_label, if_true_label);
9921 else
9922 comparison = compare (exp, LT, LTU);
9923 break;
9925 case LE_EXPR:
9926 if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9927 == MODE_INT)
9928 && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9929 do_jump_by_parts_greater (exp, 0, if_true_label, if_false_label);
9930 else
9931 comparison = compare (exp, LE, LEU);
9932 break;
9934 case GT_EXPR:
9935 if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9936 == MODE_INT)
9937 && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9938 do_jump_by_parts_greater (exp, 0, if_false_label, if_true_label);
9939 else
9940 comparison = compare (exp, GT, GTU);
9941 break;
9943 case GE_EXPR:
9944 if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9945 == MODE_INT)
9946 && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9947 do_jump_by_parts_greater (exp, 1, if_true_label, if_false_label);
9948 else
9949 comparison = compare (exp, GE, GEU);
9950 break;
9952 default:
9953 normal:
9954 temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
9955 #if 0
9956 /* This is not needed any more and causes poor code since it causes
9957 comparisons and tests from non-SI objects to have different code
9958 sequences. */
9959 /* Copy to register to avoid generating bad insns by cse
9960 from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
9961 if (!cse_not_expected && GET_CODE (temp) == MEM)
9962 temp = copy_to_reg (temp);
9963 #endif
9964 do_pending_stack_adjust ();
9965 if (GET_CODE (temp) == CONST_INT)
9966 comparison = (temp == const0_rtx ? const0_rtx : const_true_rtx);
9967 else if (GET_CODE (temp) == LABEL_REF)
9968 comparison = const_true_rtx;
9969 else if (GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
9970 && !can_compare_p (GET_MODE (temp)))
9971 /* Note swapping the labels gives us not-equal. */
9972 do_jump_by_parts_equality_rtx (temp, if_true_label, if_false_label);
9973 else if (GET_MODE (temp) != VOIDmode)
9974 comparison = compare_from_rtx (temp, CONST0_RTX (GET_MODE (temp)),
9975 NE, TREE_UNSIGNED (TREE_TYPE (exp)),
9976 GET_MODE (temp), NULL_RTX, 0);
9977 else
9978 abort ();
9981 /* Do any postincrements in the expression that was tested. */
9982 emit_queue ();
9984 /* If COMPARISON is nonzero here, it is an rtx that can be substituted
9985 straight into a conditional jump instruction as the jump condition.
9986 Otherwise, all the work has been done already. */
9988 if (comparison == const_true_rtx)
9990 if (if_true_label)
9991 emit_jump (if_true_label);
9993 else if (comparison == const0_rtx)
9995 if (if_false_label)
9996 emit_jump (if_false_label);
9998 else if (comparison)
9999 do_jump_for_compare (comparison, if_false_label, if_true_label);
10001 if (drop_through_label)
10003 /* If do_jump produces code that might be jumped around,
10004 do any stack adjusts from that code, before the place
10005 where control merges in. */
10006 do_pending_stack_adjust ();
10007 emit_label (drop_through_label);
10011 /* Given a comparison expression EXP for values too wide to be compared
10012 with one insn, test the comparison and jump to the appropriate label.
10013 The code of EXP is ignored; we always test GT if SWAP is 0,
10014 and LT if SWAP is 1. */
10016 static void
10017 do_jump_by_parts_greater (exp, swap, if_false_label, if_true_label)
10018 tree exp;
10019 int swap;
10020 rtx if_false_label, if_true_label;
10022 rtx op0 = expand_expr (TREE_OPERAND (exp, swap), NULL_RTX, VOIDmode, 0);
10023 rtx op1 = expand_expr (TREE_OPERAND (exp, !swap), NULL_RTX, VOIDmode, 0);
10024 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10025 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10026 rtx drop_through_label = 0;
10027 int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
10028 int i;
10030 if (! if_true_label || ! if_false_label)
10031 drop_through_label = gen_label_rtx ();
10032 if (! if_true_label)
10033 if_true_label = drop_through_label;
10034 if (! if_false_label)
10035 if_false_label = drop_through_label;
10037 /* Compare a word at a time, high order first. */
10038 for (i = 0; i < nwords; i++)
10040 rtx comp;
10041 rtx op0_word, op1_word;
10043 if (WORDS_BIG_ENDIAN)
10045 op0_word = operand_subword_force (op0, i, mode);
10046 op1_word = operand_subword_force (op1, i, mode);
10048 else
10050 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
10051 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
10054 /* All but high-order word must be compared as unsigned. */
10055 comp = compare_from_rtx (op0_word, op1_word,
10056 (unsignedp || i > 0) ? GTU : GT,
10057 unsignedp, word_mode, NULL_RTX, 0);
10058 if (comp == const_true_rtx)
10059 emit_jump (if_true_label);
10060 else if (comp != const0_rtx)
10061 do_jump_for_compare (comp, NULL_RTX, if_true_label);
10063 /* Consider lower words only if these are equal. */
10064 comp = compare_from_rtx (op0_word, op1_word, NE, unsignedp, word_mode,
10065 NULL_RTX, 0);
10066 if (comp == const_true_rtx)
10067 emit_jump (if_false_label);
10068 else if (comp != const0_rtx)
10069 do_jump_for_compare (comp, NULL_RTX, if_false_label);
10072 if (if_false_label)
10073 emit_jump (if_false_label);
10074 if (drop_through_label)
10075 emit_label (drop_through_label);
10078 /* Compare OP0 with OP1, word at a time, in mode MODE.
10079 UNSIGNEDP says to do unsigned comparison.
10080 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
10082 void
10083 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label, if_true_label)
10084 enum machine_mode mode;
10085 int unsignedp;
10086 rtx op0, op1;
10087 rtx if_false_label, if_true_label;
10089 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10090 rtx drop_through_label = 0;
10091 int i;
10093 if (! if_true_label || ! if_false_label)
10094 drop_through_label = gen_label_rtx ();
10095 if (! if_true_label)
10096 if_true_label = drop_through_label;
10097 if (! if_false_label)
10098 if_false_label = drop_through_label;
10100 /* Compare a word at a time, high order first. */
10101 for (i = 0; i < nwords; i++)
10103 rtx comp;
10104 rtx op0_word, op1_word;
10106 if (WORDS_BIG_ENDIAN)
10108 op0_word = operand_subword_force (op0, i, mode);
10109 op1_word = operand_subword_force (op1, i, mode);
10111 else
10113 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
10114 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
10117 /* All but high-order word must be compared as unsigned. */
10118 comp = compare_from_rtx (op0_word, op1_word,
10119 (unsignedp || i > 0) ? GTU : GT,
10120 unsignedp, word_mode, NULL_RTX, 0);
10121 if (comp == const_true_rtx)
10122 emit_jump (if_true_label);
10123 else if (comp != const0_rtx)
10124 do_jump_for_compare (comp, NULL_RTX, if_true_label);
10126 /* Consider lower words only if these are equal. */
10127 comp = compare_from_rtx (op0_word, op1_word, NE, unsignedp, word_mode,
10128 NULL_RTX, 0);
10129 if (comp == const_true_rtx)
10130 emit_jump (if_false_label);
10131 else if (comp != const0_rtx)
10132 do_jump_for_compare (comp, NULL_RTX, if_false_label);
10135 if (if_false_label)
10136 emit_jump (if_false_label);
10137 if (drop_through_label)
10138 emit_label (drop_through_label);
10141 /* Given an EQ_EXPR expression EXP for values too wide to be compared
10142 with one insn, test the comparison and jump to the appropriate label. */
10144 static void
10145 do_jump_by_parts_equality (exp, if_false_label, if_true_label)
10146 tree exp;
10147 rtx if_false_label, if_true_label;
10149 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10150 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10151 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10152 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10153 int i;
10154 rtx drop_through_label = 0;
10156 if (! if_false_label)
10157 drop_through_label = if_false_label = gen_label_rtx ();
10159 for (i = 0; i < nwords; i++)
10161 rtx comp = compare_from_rtx (operand_subword_force (op0, i, mode),
10162 operand_subword_force (op1, i, mode),
10163 EQ, TREE_UNSIGNED (TREE_TYPE (exp)),
10164 word_mode, NULL_RTX, 0);
10165 if (comp == const_true_rtx)
10166 emit_jump (if_false_label);
10167 else if (comp != const0_rtx)
10168 do_jump_for_compare (comp, if_false_label, NULL_RTX);
10171 if (if_true_label)
10172 emit_jump (if_true_label);
10173 if (drop_through_label)
10174 emit_label (drop_through_label);
10177 /* Jump according to whether OP0 is 0.
10178 We assume that OP0 has an integer mode that is too wide
10179 for the available compare insns. */
10181 static void
10182 do_jump_by_parts_equality_rtx (op0, if_false_label, if_true_label)
10183 rtx op0;
10184 rtx if_false_label, if_true_label;
10186 int nwords = GET_MODE_SIZE (GET_MODE (op0)) / UNITS_PER_WORD;
10187 int i;
10188 rtx drop_through_label = 0;
10190 if (! if_false_label)
10191 drop_through_label = if_false_label = gen_label_rtx ();
10193 for (i = 0; i < nwords; i++)
10195 rtx comp = compare_from_rtx (operand_subword_force (op0, i,
10196 GET_MODE (op0)),
10197 const0_rtx, EQ, 1, word_mode, NULL_RTX, 0);
10198 if (comp == const_true_rtx)
10199 emit_jump (if_false_label);
10200 else if (comp != const0_rtx)
10201 do_jump_for_compare (comp, if_false_label, NULL_RTX);
10204 if (if_true_label)
10205 emit_jump (if_true_label);
10206 if (drop_through_label)
10207 emit_label (drop_through_label);
10210 /* Given a comparison expression in rtl form, output conditional branches to
10211 IF_TRUE_LABEL, IF_FALSE_LABEL, or both. */
10213 static void
10214 do_jump_for_compare (comparison, if_false_label, if_true_label)
10215 rtx comparison, if_false_label, if_true_label;
10217 if (if_true_label)
10219 if (bcc_gen_fctn[(int) GET_CODE (comparison)] != 0)
10220 emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (comparison)]) (if_true_label));
10221 else
10222 abort ();
10224 if (if_false_label)
10225 emit_jump (if_false_label);
10227 else if (if_false_label)
10229 rtx insn;
10230 rtx prev = get_last_insn ();
10231 rtx branch = 0;
10233 /* Output the branch with the opposite condition. Then try to invert
10234 what is generated. If more than one insn is a branch, or if the
10235 branch is not the last insn written, abort. If we can't invert
10236 the branch, emit make a true label, redirect this jump to that,
10237 emit a jump to the false label and define the true label. */
10239 if (bcc_gen_fctn[(int) GET_CODE (comparison)] != 0)
10240 emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (comparison)])(if_false_label));
10241 else
10242 abort ();
10244 /* Here we get the first insn that was just emitted. It used to be the
10245 case that, on some machines, emitting the branch would discard
10246 the previous compare insn and emit a replacement. This isn't
10247 done anymore, but abort if we see that PREV is deleted. */
10249 if (prev == 0)
10250 insn = get_insns ();
10251 else if (INSN_DELETED_P (prev))
10252 abort ();
10253 else
10254 insn = NEXT_INSN (prev);
10256 for (; insn; insn = NEXT_INSN (insn))
10257 if (GET_CODE (insn) == JUMP_INSN)
10259 if (branch)
10260 abort ();
10261 branch = insn;
10264 if (branch != get_last_insn ())
10265 abort ();
10267 JUMP_LABEL (branch) = if_false_label;
10268 if (! invert_jump (branch, if_false_label))
10270 if_true_label = gen_label_rtx ();
10271 redirect_jump (branch, if_true_label);
10272 emit_jump (if_false_label);
10273 emit_label (if_true_label);
10278 /* Generate code for a comparison expression EXP
10279 (including code to compute the values to be compared)
10280 and set (CC0) according to the result.
10281 SIGNED_CODE should be the rtx operation for this comparison for
10282 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
10284 We force a stack adjustment unless there are currently
10285 things pushed on the stack that aren't yet used. */
10287 static rtx
10288 compare (exp, signed_code, unsigned_code)
10289 register tree exp;
10290 enum rtx_code signed_code, unsigned_code;
10292 register rtx op0
10293 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10294 register rtx op1
10295 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10296 register tree type = TREE_TYPE (TREE_OPERAND (exp, 0));
10297 register enum machine_mode mode = TYPE_MODE (type);
10298 int unsignedp = TREE_UNSIGNED (type);
10299 enum rtx_code code = unsignedp ? unsigned_code : signed_code;
10301 return compare_from_rtx (op0, op1, code, unsignedp, mode,
10302 ((mode == BLKmode)
10303 ? expr_size (TREE_OPERAND (exp, 0)) : NULL_RTX),
10304 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
10307 /* Like compare but expects the values to compare as two rtx's.
10308 The decision as to signed or unsigned comparison must be made by the caller.
10310 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
10311 compared.
10313 If ALIGN is non-zero, it is the alignment of this type; if zero, the
10314 size of MODE should be used. */
10317 compare_from_rtx (op0, op1, code, unsignedp, mode, size, align)
10318 register rtx op0, op1;
10319 enum rtx_code code;
10320 int unsignedp;
10321 enum machine_mode mode;
10322 rtx size;
10323 int align;
10325 rtx tem;
10327 /* If one operand is constant, make it the second one. Only do this
10328 if the other operand is not constant as well. */
10330 if ((CONSTANT_P (op0) && ! CONSTANT_P (op1))
10331 || (GET_CODE (op0) == CONST_INT && GET_CODE (op1) != CONST_INT))
10333 tem = op0;
10334 op0 = op1;
10335 op1 = tem;
10336 code = swap_condition (code);
10339 if (flag_force_mem)
10341 op0 = force_not_mem (op0);
10342 op1 = force_not_mem (op1);
10345 do_pending_stack_adjust ();
10347 if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT
10348 && (tem = simplify_relational_operation (code, mode, op0, op1)) != 0)
10349 return tem;
10351 #if 0
10352 /* There's no need to do this now that combine.c can eliminate lots of
10353 sign extensions. This can be less efficient in certain cases on other
10354 machines. */
10356 /* If this is a signed equality comparison, we can do it as an
10357 unsigned comparison since zero-extension is cheaper than sign
10358 extension and comparisons with zero are done as unsigned. This is
10359 the case even on machines that can do fast sign extension, since
10360 zero-extension is easier to combine with other operations than
10361 sign-extension is. If we are comparing against a constant, we must
10362 convert it to what it would look like unsigned. */
10363 if ((code == EQ || code == NE) && ! unsignedp
10364 && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
10366 if (GET_CODE (op1) == CONST_INT
10367 && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
10368 op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
10369 unsignedp = 1;
10371 #endif
10373 emit_cmp_insn (op0, op1, code, size, mode, unsignedp, align);
10375 return gen_rtx (code, VOIDmode, cc0_rtx, const0_rtx);
10378 /* Generate code to calculate EXP using a store-flag instruction
10379 and return an rtx for the result. EXP is either a comparison
10380 or a TRUTH_NOT_EXPR whose operand is a comparison.
10382 If TARGET is nonzero, store the result there if convenient.
10384 If ONLY_CHEAP is non-zero, only do this if it is likely to be very
10385 cheap.
10387 Return zero if there is no suitable set-flag instruction
10388 available on this machine.
10390 Once expand_expr has been called on the arguments of the comparison,
10391 we are committed to doing the store flag, since it is not safe to
10392 re-evaluate the expression. We emit the store-flag insn by calling
10393 emit_store_flag, but only expand the arguments if we have a reason
10394 to believe that emit_store_flag will be successful. If we think that
10395 it will, but it isn't, we have to simulate the store-flag with a
10396 set/jump/set sequence. */
10398 static rtx
10399 do_store_flag (exp, target, mode, only_cheap)
10400 tree exp;
10401 rtx target;
10402 enum machine_mode mode;
10403 int only_cheap;
10405 enum rtx_code code;
10406 tree arg0, arg1, type;
10407 tree tem;
10408 enum machine_mode operand_mode;
10409 int invert = 0;
10410 int unsignedp;
10411 rtx op0, op1;
10412 enum insn_code icode;
10413 rtx subtarget = target;
10414 rtx result, label, pattern, jump_pat;
10416 /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
10417 result at the end. We can't simply invert the test since it would
10418 have already been inverted if it were valid. This case occurs for
10419 some floating-point comparisons. */
10421 if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
10422 invert = 1, exp = TREE_OPERAND (exp, 0);
10424 arg0 = TREE_OPERAND (exp, 0);
10425 arg1 = TREE_OPERAND (exp, 1);
10426 type = TREE_TYPE (arg0);
10427 operand_mode = TYPE_MODE (type);
10428 unsignedp = TREE_UNSIGNED (type);
10430 /* We won't bother with BLKmode store-flag operations because it would mean
10431 passing a lot of information to emit_store_flag. */
10432 if (operand_mode == BLKmode)
10433 return 0;
10435 STRIP_NOPS (arg0);
10436 STRIP_NOPS (arg1);
10438 /* Get the rtx comparison code to use. We know that EXP is a comparison
10439 operation of some type. Some comparisons against 1 and -1 can be
10440 converted to comparisons with zero. Do so here so that the tests
10441 below will be aware that we have a comparison with zero. These
10442 tests will not catch constants in the first operand, but constants
10443 are rarely passed as the first operand. */
10445 switch (TREE_CODE (exp))
10447 case EQ_EXPR:
10448 code = EQ;
10449 break;
10450 case NE_EXPR:
10451 code = NE;
10452 break;
10453 case LT_EXPR:
10454 if (integer_onep (arg1))
10455 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10456 else
10457 code = unsignedp ? LTU : LT;
10458 break;
10459 case LE_EXPR:
10460 if (! unsignedp && integer_all_onesp (arg1))
10461 arg1 = integer_zero_node, code = LT;
10462 else
10463 code = unsignedp ? LEU : LE;
10464 break;
10465 case GT_EXPR:
10466 if (! unsignedp && integer_all_onesp (arg1))
10467 arg1 = integer_zero_node, code = GE;
10468 else
10469 code = unsignedp ? GTU : GT;
10470 break;
10471 case GE_EXPR:
10472 if (integer_onep (arg1))
10473 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10474 else
10475 code = unsignedp ? GEU : GE;
10476 break;
10477 default:
10478 abort ();
10481 /* Put a constant second. */
10482 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
10484 tem = arg0; arg0 = arg1; arg1 = tem;
10485 code = swap_condition (code);
10488 /* If this is an equality or inequality test of a single bit, we can
10489 do this by shifting the bit being tested to the low-order bit and
10490 masking the result with the constant 1. If the condition was EQ,
10491 we xor it with 1. This does not require an scc insn and is faster
10492 than an scc insn even if we have it. */
10494 if ((code == NE || code == EQ)
10495 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
10496 && integer_pow2p (TREE_OPERAND (arg0, 1))
10497 && TYPE_PRECISION (type) <= HOST_BITS_PER_WIDE_INT)
10499 tree inner = TREE_OPERAND (arg0, 0);
10500 int bitnum = exact_log2 (INTVAL (expand_expr (TREE_OPERAND (arg0, 1),
10501 NULL_RTX, VOIDmode, 0)));
10502 int ops_unsignedp;
10504 /* If INNER is a right shift of a constant and it plus BITNUM does
10505 not overflow, adjust BITNUM and INNER. */
10507 if (TREE_CODE (inner) == RSHIFT_EXPR
10508 && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
10509 && TREE_INT_CST_HIGH (TREE_OPERAND (inner, 1)) == 0
10510 && (bitnum + TREE_INT_CST_LOW (TREE_OPERAND (inner, 1))
10511 < TYPE_PRECISION (type)))
10513 bitnum +=TREE_INT_CST_LOW (TREE_OPERAND (inner, 1));
10514 inner = TREE_OPERAND (inner, 0);
10517 /* If we are going to be able to omit the AND below, we must do our
10518 operations as unsigned. If we must use the AND, we have a choice.
10519 Normally unsigned is faster, but for some machines signed is. */
10520 ops_unsignedp = (bitnum == TYPE_PRECISION (type) - 1 ? 1
10521 #ifdef LOAD_EXTEND_OP
10522 : (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND ? 0 : 1)
10523 #else
10525 #endif
10528 if (subtarget == 0 || GET_CODE (subtarget) != REG
10529 || GET_MODE (subtarget) != operand_mode
10530 || ! safe_from_p (subtarget, inner))
10531 subtarget = 0;
10533 op0 = expand_expr (inner, subtarget, VOIDmode, 0);
10535 if (bitnum != 0)
10536 op0 = expand_shift (RSHIFT_EXPR, GET_MODE (op0), op0,
10537 size_int (bitnum), subtarget, ops_unsignedp);
10539 if (GET_MODE (op0) != mode)
10540 op0 = convert_to_mode (mode, op0, ops_unsignedp);
10542 if ((code == EQ && ! invert) || (code == NE && invert))
10543 op0 = expand_binop (mode, xor_optab, op0, const1_rtx, subtarget,
10544 ops_unsignedp, OPTAB_LIB_WIDEN);
10546 /* Put the AND last so it can combine with more things. */
10547 if (bitnum != TYPE_PRECISION (type) - 1)
10548 op0 = expand_and (op0, const1_rtx, subtarget);
10550 return op0;
10553 /* Now see if we are likely to be able to do this. Return if not. */
10554 if (! can_compare_p (operand_mode))
10555 return 0;
10556 icode = setcc_gen_code[(int) code];
10557 if (icode == CODE_FOR_nothing
10558 || (only_cheap && insn_operand_mode[(int) icode][0] != mode))
10560 /* We can only do this if it is one of the special cases that
10561 can be handled without an scc insn. */
10562 if ((code == LT && integer_zerop (arg1))
10563 || (! only_cheap && code == GE && integer_zerop (arg1)))
10565 else if (BRANCH_COST >= 0
10566 && ! only_cheap && (code == NE || code == EQ)
10567 && TREE_CODE (type) != REAL_TYPE
10568 && ((abs_optab->handlers[(int) operand_mode].insn_code
10569 != CODE_FOR_nothing)
10570 || (ffs_optab->handlers[(int) operand_mode].insn_code
10571 != CODE_FOR_nothing)))
10573 else
10574 return 0;
10577 preexpand_calls (exp);
10578 if (subtarget == 0 || GET_CODE (subtarget) != REG
10579 || GET_MODE (subtarget) != operand_mode
10580 || ! safe_from_p (subtarget, arg1))
10581 subtarget = 0;
10583 op0 = expand_expr (arg0, subtarget, VOIDmode, 0);
10584 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
10586 if (target == 0)
10587 target = gen_reg_rtx (mode);
10589 /* Pass copies of OP0 and OP1 in case they contain a QUEUED. This is safe
10590 because, if the emit_store_flag does anything it will succeed and
10591 OP0 and OP1 will not be used subsequently. */
10593 result = emit_store_flag (target, code,
10594 queued_subexp_p (op0) ? copy_rtx (op0) : op0,
10595 queued_subexp_p (op1) ? copy_rtx (op1) : op1,
10596 operand_mode, unsignedp, 1);
10598 if (result)
10600 if (invert)
10601 result = expand_binop (mode, xor_optab, result, const1_rtx,
10602 result, 0, OPTAB_LIB_WIDEN);
10603 return result;
10606 /* If this failed, we have to do this with set/compare/jump/set code. */
10607 if (target == 0 || GET_CODE (target) != REG
10608 || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
10609 target = gen_reg_rtx (GET_MODE (target));
10611 emit_move_insn (target, invert ? const0_rtx : const1_rtx);
10612 result = compare_from_rtx (op0, op1, code, unsignedp,
10613 operand_mode, NULL_RTX, 0);
10614 if (GET_CODE (result) == CONST_INT)
10615 return (((result == const0_rtx && ! invert)
10616 || (result != const0_rtx && invert))
10617 ? const0_rtx : const1_rtx);
10619 label = gen_label_rtx ();
10620 if (bcc_gen_fctn[(int) code] == 0)
10621 abort ();
10623 emit_jump_insn ((*bcc_gen_fctn[(int) code]) (label));
10624 emit_move_insn (target, invert ? const1_rtx : const0_rtx);
10625 emit_label (label);
10627 return target;
10630 /* Generate a tablejump instruction (used for switch statements). */
10632 #ifdef HAVE_tablejump
10634 /* INDEX is the value being switched on, with the lowest value
10635 in the table already subtracted.
10636 MODE is its expected mode (needed if INDEX is constant).
10637 RANGE is the length of the jump table.
10638 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10640 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10641 index value is out of range. */
10643 void
10644 do_tablejump (index, mode, range, table_label, default_label)
10645 rtx index, range, table_label, default_label;
10646 enum machine_mode mode;
10648 register rtx temp, vector;
10650 /* Do an unsigned comparison (in the proper mode) between the index
10651 expression and the value which represents the length of the range.
10652 Since we just finished subtracting the lower bound of the range
10653 from the index expression, this comparison allows us to simultaneously
10654 check that the original index expression value is both greater than
10655 or equal to the minimum value of the range and less than or equal to
10656 the maximum value of the range. */
10658 emit_cmp_insn (index, range, GTU, NULL_RTX, mode, 1, 0);
10659 emit_jump_insn (gen_bgtu (default_label));
10661 /* If index is in range, it must fit in Pmode.
10662 Convert to Pmode so we can index with it. */
10663 if (mode != Pmode)
10664 index = convert_to_mode (Pmode, index, 1);
10666 /* Don't let a MEM slip thru, because then INDEX that comes
10667 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10668 and break_out_memory_refs will go to work on it and mess it up. */
10669 #ifdef PIC_CASE_VECTOR_ADDRESS
10670 if (flag_pic && GET_CODE (index) != REG)
10671 index = copy_to_mode_reg (Pmode, index);
10672 #endif
10674 /* If flag_force_addr were to affect this address
10675 it could interfere with the tricky assumptions made
10676 about addresses that contain label-refs,
10677 which may be valid only very near the tablejump itself. */
10678 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10679 GET_MODE_SIZE, because this indicates how large insns are. The other
10680 uses should all be Pmode, because they are addresses. This code
10681 could fail if addresses and insns are not the same size. */
10682 index = gen_rtx (PLUS, Pmode,
10683 gen_rtx (MULT, Pmode, index,
10684 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
10685 gen_rtx (LABEL_REF, Pmode, table_label));
10686 #ifdef PIC_CASE_VECTOR_ADDRESS
10687 if (flag_pic)
10688 index = PIC_CASE_VECTOR_ADDRESS (index);
10689 else
10690 #endif
10691 index = memory_address_noforce (CASE_VECTOR_MODE, index);
10692 temp = gen_reg_rtx (CASE_VECTOR_MODE);
10693 vector = gen_rtx (MEM, CASE_VECTOR_MODE, index);
10694 RTX_UNCHANGING_P (vector) = 1;
10695 convert_move (temp, vector, 0);
10697 emit_jump_insn (gen_tablejump (temp, table_label));
10699 #ifndef CASE_VECTOR_PC_RELATIVE
10700 /* If we are generating PIC code or if the table is PC-relative, the
10701 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10702 if (! flag_pic)
10703 emit_barrier ();
10704 #endif
10707 #endif /* HAVE_tablejump */
10710 /* Emit a suitable bytecode to load a value from memory, assuming a pointer
10711 to that value is on the top of the stack. The resulting type is TYPE, and
10712 the source declaration is DECL. */
10714 void
10715 bc_load_memory (type, decl)
10716 tree type, decl;
10718 enum bytecode_opcode opcode;
10721 /* Bit fields are special. We only know about signed and
10722 unsigned ints, and enums. The latter are treated as
10723 signed integers. */
10725 if (DECL_BIT_FIELD (decl))
10726 if (TREE_CODE (type) == ENUMERAL_TYPE
10727 || TREE_CODE (type) == INTEGER_TYPE)
10728 opcode = TREE_UNSIGNED (type) ? zxloadBI : sxloadBI;
10729 else
10730 abort ();
10731 else
10732 /* See corresponding comment in bc_store_memory(). */
10733 if (TYPE_MODE (type) == BLKmode
10734 || TYPE_MODE (type) == VOIDmode)
10735 return;
10736 else
10737 opcode = mode_to_load_map [(int) TYPE_MODE (type)];
10739 if (opcode == neverneverland)
10740 abort ();
10742 bc_emit_bytecode (opcode);
10744 #ifdef DEBUG_PRINT_CODE
10745 fputc ('\n', stderr);
10746 #endif
10750 /* Store the contents of the second stack slot to the address in the
10751 top stack slot. DECL is the declaration of the destination and is used
10752 to determine whether we're dealing with a bitfield. */
10754 void
10755 bc_store_memory (type, decl)
10756 tree type, decl;
10758 enum bytecode_opcode opcode;
10761 if (DECL_BIT_FIELD (decl))
10763 if (TREE_CODE (type) == ENUMERAL_TYPE
10764 || TREE_CODE (type) == INTEGER_TYPE)
10765 opcode = sstoreBI;
10766 else
10767 abort ();
10769 else
10770 if (TYPE_MODE (type) == BLKmode)
10772 /* Copy structure. This expands to a block copy instruction, storeBLK.
10773 In addition to the arguments expected by the other store instructions,
10774 it also expects a type size (SImode) on top of the stack, which is the
10775 structure size in size units (usually bytes). The two first arguments
10776 are already on the stack; so we just put the size on level 1. For some
10777 other languages, the size may be variable, this is why we don't encode
10778 it as a storeBLK literal, but rather treat it as a full-fledged expression. */
10780 bc_expand_expr (TYPE_SIZE (type));
10781 opcode = storeBLK;
10783 else
10784 opcode = mode_to_store_map [(int) TYPE_MODE (type)];
10786 if (opcode == neverneverland)
10787 abort ();
10789 bc_emit_bytecode (opcode);
10791 #ifdef DEBUG_PRINT_CODE
10792 fputc ('\n', stderr);
10793 #endif
10797 /* Allocate local stack space sufficient to hold a value of the given
10798 SIZE at alignment boundary ALIGNMENT bits. ALIGNMENT must be an
10799 integral power of 2. A special case is locals of type VOID, which
10800 have size 0 and alignment 1 - any "voidish" SIZE or ALIGNMENT is
10801 remapped into the corresponding attribute of SI. */
10804 bc_allocate_local (size, alignment)
10805 int size, alignment;
10807 rtx retval;
10808 int byte_alignment;
10810 if (size < 0)
10811 abort ();
10813 /* Normalize size and alignment */
10814 if (!size)
10815 size = UNITS_PER_WORD;
10817 if (alignment < BITS_PER_UNIT)
10818 byte_alignment = 1 << (INT_ALIGN - 1);
10819 else
10820 /* Align */
10821 byte_alignment = alignment / BITS_PER_UNIT;
10823 if (local_vars_size & (byte_alignment - 1))
10824 local_vars_size += byte_alignment - (local_vars_size & (byte_alignment - 1));
10826 retval = bc_gen_rtx ((char *) 0, local_vars_size, (struct bc_label *) 0);
10827 local_vars_size += size;
10829 return retval;
10833 /* Allocate variable-sized local array. Variable-sized arrays are
10834 actually pointers to the address in memory where they are stored. */
10837 bc_allocate_variable_array (size)
10838 tree size;
10840 rtx retval;
10841 const int ptralign = (1 << (PTR_ALIGN - 1));
10843 /* Align pointer */
10844 if (local_vars_size & ptralign)
10845 local_vars_size += ptralign - (local_vars_size & ptralign);
10847 /* Note down local space needed: pointer to block; also return
10848 dummy rtx */
10850 retval = bc_gen_rtx ((char *) 0, local_vars_size, (struct bc_label *) 0);
10851 local_vars_size += POINTER_SIZE / BITS_PER_UNIT;
10852 return retval;
10856 /* Push the machine address for the given external variable offset. */
10857 void
10858 bc_load_externaddr (externaddr)
10859 rtx externaddr;
10861 bc_emit_bytecode (constP);
10862 bc_emit_code_labelref (BYTECODE_LABEL (externaddr),
10863 BYTECODE_BC_LABEL (externaddr)->offset);
10865 #ifdef DEBUG_PRINT_CODE
10866 fputc ('\n', stderr);
10867 #endif
10871 static char *
10872 bc_strdup (s)
10873 char *s;
10875 char *new = (char *) xmalloc ((strlen (s) + 1) * sizeof *s);
10876 strcpy (new, s);
10877 return new;
10881 /* Like above, but expects an IDENTIFIER. */
10882 void
10883 bc_load_externaddr_id (id, offset)
10884 tree id;
10885 int offset;
10887 if (!IDENTIFIER_POINTER (id))
10888 abort ();
10890 bc_emit_bytecode (constP);
10891 bc_emit_code_labelref (bc_xstrdup (IDENTIFIER_POINTER (id)), offset);
10893 #ifdef DEBUG_PRINT_CODE
10894 fputc ('\n', stderr);
10895 #endif
10899 /* Push the machine address for the given local variable offset. */
10900 void
10901 bc_load_localaddr (localaddr)
10902 rtx localaddr;
10904 bc_emit_instruction (localP, (HOST_WIDE_INT) BYTECODE_BC_LABEL (localaddr)->offset);
10908 /* Push the machine address for the given parameter offset.
10909 NOTE: offset is in bits. */
10910 void
10911 bc_load_parmaddr (parmaddr)
10912 rtx parmaddr;
10914 bc_emit_instruction (argP, ((HOST_WIDE_INT) BYTECODE_BC_LABEL (parmaddr)->offset
10915 / BITS_PER_UNIT));
10919 /* Convert a[i] into *(a + i). */
10920 tree
10921 bc_canonicalize_array_ref (exp)
10922 tree exp;
10924 tree type = TREE_TYPE (exp);
10925 tree array_adr = build1 (ADDR_EXPR, TYPE_POINTER_TO (type),
10926 TREE_OPERAND (exp, 0));
10927 tree index = TREE_OPERAND (exp, 1);
10930 /* Convert the integer argument to a type the same size as a pointer
10931 so the multiply won't overflow spuriously. */
10933 if (TYPE_PRECISION (TREE_TYPE (index)) != POINTER_SIZE)
10934 index = convert (type_for_size (POINTER_SIZE, 0), index);
10936 /* The array address isn't volatile even if the array is.
10937 (Of course this isn't terribly relevant since the bytecode
10938 translator treats nearly everything as volatile anyway.) */
10939 TREE_THIS_VOLATILE (array_adr) = 0;
10941 return build1 (INDIRECT_REF, type,
10942 fold (build (PLUS_EXPR,
10943 TYPE_POINTER_TO (type),
10944 array_adr,
10945 fold (build (MULT_EXPR,
10946 TYPE_POINTER_TO (type),
10947 index,
10948 size_in_bytes (type))))));
10952 /* Load the address of the component referenced by the given
10953 COMPONENT_REF expression.
10955 Returns innermost lvalue. */
10957 tree
10958 bc_expand_component_address (exp)
10959 tree exp;
10961 tree tem, chain;
10962 enum machine_mode mode;
10963 int bitpos = 0;
10964 HOST_WIDE_INT SIval;
10967 tem = TREE_OPERAND (exp, 1);
10968 mode = DECL_MODE (tem);
10971 /* Compute cumulative bit offset for nested component refs
10972 and array refs, and find the ultimate containing object. */
10974 for (tem = exp;; tem = TREE_OPERAND (tem, 0))
10976 if (TREE_CODE (tem) == COMPONENT_REF)
10977 bitpos += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (tem, 1)));
10978 else
10979 if (TREE_CODE (tem) == ARRAY_REF
10980 && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
10981 && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) == INTEGER_CST)
10983 bitpos += (TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))
10984 * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)))
10985 /* * TYPE_SIZE_UNIT (TREE_TYPE (tem)) */);
10986 else
10987 break;
10990 bc_expand_expr (tem);
10993 /* For bitfields also push their offset and size */
10994 if (DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
10995 bc_push_offset_and_size (bitpos, /* DECL_SIZE_UNIT */ (TREE_OPERAND (exp, 1)));
10996 else
10997 if (SIval = bitpos / BITS_PER_UNIT)
10998 bc_emit_instruction (addconstPSI, SIval);
11000 return (TREE_OPERAND (exp, 1));
11004 /* Emit code to push two SI constants */
11005 void
11006 bc_push_offset_and_size (offset, size)
11007 HOST_WIDE_INT offset, size;
11009 bc_emit_instruction (constSI, offset);
11010 bc_emit_instruction (constSI, size);
11014 /* Emit byte code to push the address of the given lvalue expression to
11015 the stack. If it's a bit field, we also push offset and size info.
11017 Returns innermost component, which allows us to determine not only
11018 its type, but also whether it's a bitfield. */
11020 tree
11021 bc_expand_address (exp)
11022 tree exp;
11024 /* Safeguard */
11025 if (!exp || TREE_CODE (exp) == ERROR_MARK)
11026 return (exp);
11029 switch (TREE_CODE (exp))
11031 case ARRAY_REF:
11033 return (bc_expand_address (bc_canonicalize_array_ref (exp)));
11035 case COMPONENT_REF:
11037 return (bc_expand_component_address (exp));
11039 case INDIRECT_REF:
11041 bc_expand_expr (TREE_OPERAND (exp, 0));
11043 /* For variable-sized types: retrieve pointer. Sometimes the
11044 TYPE_SIZE tree is NULL. Is this a bug or a feature? Let's
11045 also make sure we have an operand, just in case... */
11047 if (TREE_OPERAND (exp, 0)
11048 && TYPE_SIZE (TREE_TYPE (TREE_OPERAND (exp, 0)))
11049 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_OPERAND (exp, 0)))) != INTEGER_CST)
11050 bc_emit_instruction (loadP);
11052 /* If packed, also return offset and size */
11053 if (DECL_BIT_FIELD (TREE_OPERAND (exp, 0)))
11055 bc_push_offset_and_size (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (exp, 0))),
11056 TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (exp, 0))));
11058 return (TREE_OPERAND (exp, 0));
11060 case FUNCTION_DECL:
11062 bc_load_externaddr_id (DECL_ASSEMBLER_NAME (exp),
11063 BYTECODE_BC_LABEL (DECL_RTL (exp))->offset);
11064 break;
11066 case PARM_DECL:
11068 bc_load_parmaddr (DECL_RTL (exp));
11070 /* For variable-sized types: retrieve pointer */
11071 if (TYPE_SIZE (TREE_TYPE (exp))
11072 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST)
11073 bc_emit_instruction (loadP);
11075 /* If packed, also return offset and size */
11076 if (DECL_BIT_FIELD (exp))
11077 bc_push_offset_and_size (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (exp)),
11078 TREE_INT_CST_LOW (DECL_SIZE (exp)));
11080 break;
11082 case RESULT_DECL:
11084 bc_emit_instruction (returnP);
11085 break;
11087 case VAR_DECL:
11089 #if 0
11090 if (BYTECODE_LABEL (DECL_RTL (exp)))
11091 bc_load_externaddr (DECL_RTL (exp));
11092 #endif
11094 if (DECL_EXTERNAL (exp))
11095 bc_load_externaddr_id (DECL_ASSEMBLER_NAME (exp),
11096 (BYTECODE_BC_LABEL (DECL_RTL (exp)))->offset);
11097 else
11098 bc_load_localaddr (DECL_RTL (exp));
11100 /* For variable-sized types: retrieve pointer */
11101 if (TYPE_SIZE (TREE_TYPE (exp))
11102 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST)
11103 bc_emit_instruction (loadP);
11105 /* If packed, also return offset and size */
11106 if (DECL_BIT_FIELD (exp))
11107 bc_push_offset_and_size (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (exp)),
11108 TREE_INT_CST_LOW (DECL_SIZE (exp)));
11110 break;
11112 case STRING_CST:
11114 rtx r;
11116 bc_emit_bytecode (constP);
11117 r = output_constant_def (exp);
11118 bc_emit_code_labelref (BYTECODE_LABEL (r), BYTECODE_BC_LABEL (r)->offset);
11120 #ifdef DEBUG_PRINT_CODE
11121 fputc ('\n', stderr);
11122 #endif
11124 break;
11126 default:
11128 abort();
11129 break;
11132 /* Most lvalues don't have components. */
11133 return (exp);
11137 /* Emit a type code to be used by the runtime support in handling
11138 parameter passing. The type code consists of the machine mode
11139 plus the minimal alignment shifted left 8 bits. */
11141 tree
11142 bc_runtime_type_code (type)
11143 tree type;
11145 int val;
11147 switch (TREE_CODE (type))
11149 case VOID_TYPE:
11150 case INTEGER_TYPE:
11151 case REAL_TYPE:
11152 case COMPLEX_TYPE:
11153 case ENUMERAL_TYPE:
11154 case POINTER_TYPE:
11155 case RECORD_TYPE:
11157 val = (int) TYPE_MODE (type) | TYPE_ALIGN (type) << 8;
11158 break;
11160 case ERROR_MARK:
11162 val = 0;
11163 break;
11165 default:
11167 abort ();
11169 return build_int_2 (val, 0);
11173 /* Generate constructor label */
11174 char *
11175 bc_gen_constr_label ()
11177 static int label_counter;
11178 static char label[20];
11180 sprintf (label, "*LR%d", label_counter++);
11182 return (obstack_copy0 (&permanent_obstack, label, strlen (label)));
11186 /* Evaluate constructor CONSTR and return pointer to it on level one. We
11187 expand the constructor data as static data, and push a pointer to it.
11188 The pointer is put in the pointer table and is retrieved by a constP
11189 bytecode instruction. We then loop and store each constructor member in
11190 the corresponding component. Finally, we return the original pointer on
11191 the stack. */
11193 void
11194 bc_expand_constructor (constr)
11195 tree constr;
11197 char *l;
11198 HOST_WIDE_INT ptroffs;
11199 rtx constr_rtx;
11202 /* Literal constructors are handled as constants, whereas
11203 non-literals are evaluated and stored element by element
11204 into the data segment. */
11206 /* Allocate space in proper segment and push pointer to space on stack.
11209 l = bc_gen_constr_label ();
11211 if (TREE_CONSTANT (constr))
11213 text_section ();
11215 bc_emit_const_labeldef (l);
11216 bc_output_constructor (constr, int_size_in_bytes (TREE_TYPE (constr)));
11218 else
11220 data_section ();
11222 bc_emit_data_labeldef (l);
11223 bc_output_data_constructor (constr);
11227 /* Add reference to pointer table and recall pointer to stack;
11228 this code is common for both types of constructors: literals
11229 and non-literals. */
11231 ptroffs = bc_define_pointer (l);
11232 bc_emit_instruction (constP, ptroffs);
11234 /* This is all that has to be done if it's a literal. */
11235 if (TREE_CONSTANT (constr))
11236 return;
11239 /* At this point, we have the pointer to the structure on top of the stack.
11240 Generate sequences of store_memory calls for the constructor. */
11242 /* constructor type is structure */
11243 if (TREE_CODE (TREE_TYPE (constr)) == RECORD_TYPE)
11245 register tree elt;
11247 /* If the constructor has fewer fields than the structure,
11248 clear the whole structure first. */
11250 if (list_length (CONSTRUCTOR_ELTS (constr))
11251 != list_length (TYPE_FIELDS (TREE_TYPE (constr))))
11253 bc_emit_instruction (duplicate);
11254 bc_emit_instruction (constSI, (HOST_WIDE_INT) int_size_in_bytes (TREE_TYPE (constr)));
11255 bc_emit_instruction (clearBLK);
11258 /* Store each element of the constructor into the corresponding
11259 field of TARGET. */
11261 for (elt = CONSTRUCTOR_ELTS (constr); elt; elt = TREE_CHAIN (elt))
11263 register tree field = TREE_PURPOSE (elt);
11264 register enum machine_mode mode;
11265 int bitsize;
11266 int bitpos;
11267 int unsignedp;
11269 bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)) /* * DECL_SIZE_UNIT (field) */;
11270 mode = DECL_MODE (field);
11271 unsignedp = TREE_UNSIGNED (field);
11273 bitpos = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
11275 bc_store_field (elt, bitsize, bitpos, mode, TREE_VALUE (elt), TREE_TYPE (TREE_VALUE (elt)),
11276 /* The alignment of TARGET is
11277 at least what its type requires. */
11278 VOIDmode, 0,
11279 TYPE_ALIGN (TREE_TYPE (constr)) / BITS_PER_UNIT,
11280 int_size_in_bytes (TREE_TYPE (constr)));
11283 else
11285 /* Constructor type is array */
11286 if (TREE_CODE (TREE_TYPE (constr)) == ARRAY_TYPE)
11288 register tree elt;
11289 register int i;
11290 tree domain = TYPE_DOMAIN (TREE_TYPE (constr));
11291 int minelt = TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain));
11292 int maxelt = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain));
11293 tree elttype = TREE_TYPE (TREE_TYPE (constr));
11295 /* If the constructor has fewer fields than the structure,
11296 clear the whole structure first. */
11298 if (list_length (CONSTRUCTOR_ELTS (constr)) < maxelt - minelt + 1)
11300 bc_emit_instruction (duplicate);
11301 bc_emit_instruction (constSI, (HOST_WIDE_INT) int_size_in_bytes (TREE_TYPE (constr)));
11302 bc_emit_instruction (clearBLK);
11306 /* Store each element of the constructor into the corresponding
11307 element of TARGET, determined by counting the elements. */
11309 for (elt = CONSTRUCTOR_ELTS (constr), i = 0;
11310 elt;
11311 elt = TREE_CHAIN (elt), i++)
11313 register enum machine_mode mode;
11314 int bitsize;
11315 int bitpos;
11316 int unsignedp;
11318 mode = TYPE_MODE (elttype);
11319 bitsize = GET_MODE_BITSIZE (mode);
11320 unsignedp = TREE_UNSIGNED (elttype);
11322 bitpos = (i * TREE_INT_CST_LOW (TYPE_SIZE (elttype))
11323 /* * TYPE_SIZE_UNIT (elttype) */ );
11325 bc_store_field (elt, bitsize, bitpos, mode,
11326 TREE_VALUE (elt), TREE_TYPE (TREE_VALUE (elt)),
11327 /* The alignment of TARGET is
11328 at least what its type requires. */
11329 VOIDmode, 0,
11330 TYPE_ALIGN (TREE_TYPE (constr)) / BITS_PER_UNIT,
11331 int_size_in_bytes (TREE_TYPE (constr)));
11338 /* Store the value of EXP (an expression tree) into member FIELD of
11339 structure at address on stack, which has type TYPE, mode MODE and
11340 occupies BITSIZE bits, starting BITPOS bits from the beginning of the
11341 structure.
11343 ALIGN is the alignment that TARGET is known to have, measured in bytes.
11344 TOTAL_SIZE is its size in bytes, or -1 if variable. */
11346 void
11347 bc_store_field (field, bitsize, bitpos, mode, exp, type,
11348 value_mode, unsignedp, align, total_size)
11349 int bitsize, bitpos;
11350 enum machine_mode mode;
11351 tree field, exp, type;
11352 enum machine_mode value_mode;
11353 int unsignedp;
11354 int align;
11355 int total_size;
11358 /* Expand expression and copy pointer */
11359 bc_expand_expr (exp);
11360 bc_emit_instruction (over);
11363 /* If the component is a bit field, we cannot use addressing to access
11364 it. Use bit-field techniques to store in it. */
11366 if (DECL_BIT_FIELD (field))
11368 bc_store_bit_field (bitpos, bitsize, unsignedp);
11369 return;
11371 else
11372 /* Not bit field */
11374 HOST_WIDE_INT offset = bitpos / BITS_PER_UNIT;
11376 /* Advance pointer to the desired member */
11377 if (offset)
11378 bc_emit_instruction (addconstPSI, offset);
11380 /* Store */
11381 bc_store_memory (type, field);
11386 /* Store SI/SU in bitfield */
11387 void
11388 bc_store_bit_field (offset, size, unsignedp)
11389 int offset, size, unsignedp;
11391 /* Push bitfield offset and size */
11392 bc_push_offset_and_size (offset, size);
11394 /* Store */
11395 bc_emit_instruction (sstoreBI);
11399 /* Load SI/SU from bitfield */
11400 void
11401 bc_load_bit_field (offset, size, unsignedp)
11402 int offset, size, unsignedp;
11404 /* Push bitfield offset and size */
11405 bc_push_offset_and_size (offset, size);
11407 /* Load: sign-extend if signed, else zero-extend */
11408 bc_emit_instruction (unsignedp ? zxloadBI : sxloadBI);
11412 /* Adjust interpreter stack by NLEVELS. Positive means drop NLEVELS
11413 (adjust stack pointer upwards), negative means add that number of
11414 levels (adjust the stack pointer downwards). Only positive values
11415 normally make sense. */
11417 void
11418 bc_adjust_stack (nlevels)
11419 int nlevels;
11421 switch (nlevels)
11423 case 0:
11424 break;
11426 case 2:
11427 bc_emit_instruction (drop);
11429 case 1:
11430 bc_emit_instruction (drop);
11431 break;
11433 default:
11435 bc_emit_instruction (adjstackSI, (HOST_WIDE_INT) nlevels);
11436 stack_depth -= nlevels;
11439 #if defined (VALIDATE_STACK_FOR_BC)
11440 VALIDATE_STACK_FOR_BC ();
11441 #endif