Add movdi pattern to FR30 port.
[official-gcc.git] / gcc / builtins.c
blobf288916f790874de3261d776abd6bc6d51217ae5
1 /* Expand builtin functions.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "machmode.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "obstack.h"
28 #include "flags.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "except.h"
32 #include "function.h"
33 #include "insn-flags.h"
34 #include "insn-codes.h"
35 #include "insn-config.h"
36 #include "expr.h"
37 #include "recog.h"
38 #include "output.h"
39 #include "typeclass.h"
40 #include "defaults.h"
41 #include "toplev.h"
42 #include "tm_p.h"
44 #define CALLED_AS_BUILT_IN(NODE) \
45 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
47 /* Register mappings for target machines without register windows. */
48 #ifndef INCOMING_REGNO
49 #define INCOMING_REGNO(OUT) (OUT)
50 #endif
51 #ifndef OUTGOING_REGNO
52 #define OUTGOING_REGNO(IN) (IN)
53 #endif
55 #ifndef PAD_VARARGS_DOWN
56 #define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN
57 #endif
59 /* Define the names of the builtin function types and codes. */
60 const char *const built_in_class_names[4]
61 = {"NOT_BUILT_IN", "BUILT_IN_FRONTEND", "BUILT_IN_MD", "BUILT_IN_NORMAL"};
63 #define DEF_BUILTIN(x) STRINGIFY(x),
64 const char *const built_in_names[(int) END_BUILTINS] =
66 #include "builtins.def"
68 #undef DEF_BUILTIN
70 tree (*lang_type_promotes_to) PARAMS ((tree));
72 static int get_pointer_alignment PARAMS ((tree, unsigned));
73 static tree c_strlen PARAMS ((tree));
74 static rtx get_memory_rtx PARAMS ((tree));
75 static int apply_args_size PARAMS ((void));
76 static int apply_result_size PARAMS ((void));
77 #if defined (HAVE_untyped_call) || defined (HAVE_untyped_return)
78 static rtx result_vector PARAMS ((int, rtx));
79 #endif
80 static rtx expand_builtin_apply_args PARAMS ((void));
81 static rtx expand_builtin_apply_args_1 PARAMS ((void));
82 static rtx expand_builtin_apply PARAMS ((rtx, rtx, rtx));
83 static void expand_builtin_return PARAMS ((rtx));
84 static rtx expand_builtin_classify_type PARAMS ((tree));
85 static rtx expand_builtin_mathfn PARAMS ((tree, rtx, rtx));
86 static rtx expand_builtin_constant_p PARAMS ((tree));
87 static rtx expand_builtin_args_info PARAMS ((tree));
88 static rtx expand_builtin_next_arg PARAMS ((tree));
89 static rtx expand_builtin_va_start PARAMS ((int, tree));
90 static rtx expand_builtin_va_end PARAMS ((tree));
91 static rtx expand_builtin_va_copy PARAMS ((tree));
92 #ifdef HAVE_cmpstrsi
93 static rtx expand_builtin_memcmp PARAMS ((tree, tree, rtx));
94 static rtx expand_builtin_strcmp PARAMS ((tree, rtx));
95 #endif
96 static rtx expand_builtin_memcpy PARAMS ((tree));
97 static rtx expand_builtin_strcpy PARAMS ((tree));
98 static rtx expand_builtin_memset PARAMS ((tree));
99 static rtx expand_builtin_bzero PARAMS ((tree));
100 static rtx expand_builtin_strlen PARAMS ((tree, rtx,
101 enum machine_mode));
102 static rtx expand_builtin_alloca PARAMS ((tree, rtx));
103 static rtx expand_builtin_ffs PARAMS ((tree, rtx, rtx));
104 static rtx expand_builtin_frame_address PARAMS ((tree));
105 static tree stabilize_va_list PARAMS ((tree, int));
106 static rtx expand_builtin_expect PARAMS ((tree, rtx));
108 /* Return the alignment in bits of EXP, a pointer valued expression.
109 But don't return more than MAX_ALIGN no matter what.
110 The alignment returned is, by default, the alignment of the thing that
111 EXP points to (if it is not a POINTER_TYPE, 0 is returned).
113 Otherwise, look at the expression to see if we can do better, i.e., if the
114 expression is actually pointing at an object whose alignment is tighter. */
116 static int
117 get_pointer_alignment (exp, max_align)
118 tree exp;
119 unsigned max_align;
121 unsigned align, inner;
123 if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
124 return 0;
126 align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
127 align = MIN (align, max_align);
129 while (1)
131 switch (TREE_CODE (exp))
133 case NOP_EXPR:
134 case CONVERT_EXPR:
135 case NON_LVALUE_EXPR:
136 exp = TREE_OPERAND (exp, 0);
137 if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
138 return align;
140 inner = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
141 align = MIN (inner, max_align);
142 break;
144 case PLUS_EXPR:
145 /* If sum of pointer + int, restrict our maximum alignment to that
146 imposed by the integer. If not, we can't do any better than
147 ALIGN. */
148 if (! host_integerp (TREE_OPERAND (exp, 1), 1))
149 return align;
151 while (((tree_low_cst (TREE_OPERAND (exp, 1), 1) * BITS_PER_UNIT)
152 & (max_align - 1))
153 != 0)
154 max_align >>= 1;
156 exp = TREE_OPERAND (exp, 0);
157 break;
159 case ADDR_EXPR:
160 /* See what we are pointing at and look at its alignment. */
161 exp = TREE_OPERAND (exp, 0);
162 if (TREE_CODE (exp) == FUNCTION_DECL)
163 align = FUNCTION_BOUNDARY;
164 else if (DECL_P (exp))
165 align = DECL_ALIGN (exp);
166 #ifdef CONSTANT_ALIGNMENT
167 else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c')
168 align = CONSTANT_ALIGNMENT (exp, align);
169 #endif
170 return MIN (align, max_align);
172 default:
173 return align;
178 /* Compute the length of a C string. TREE_STRING_LENGTH is not the right
179 way, because it could contain a zero byte in the middle.
180 TREE_STRING_LENGTH is the size of the character array, not the string.
182 The value returned is of type `ssizetype'.
184 Unfortunately, string_constant can't access the values of const char
185 arrays with initializers, so neither can we do so here. */
187 static tree
188 c_strlen (src)
189 tree src;
191 tree offset_node;
192 int offset, max;
193 char *ptr;
195 src = string_constant (src, &offset_node);
196 if (src == 0)
197 return 0;
199 max = TREE_STRING_LENGTH (src);
200 ptr = TREE_STRING_POINTER (src);
202 if (offset_node && TREE_CODE (offset_node) != INTEGER_CST)
204 /* If the string has an internal zero byte (e.g., "foo\0bar"), we can't
205 compute the offset to the following null if we don't know where to
206 start searching for it. */
207 int i;
209 for (i = 0; i < max; i++)
210 if (ptr[i] == 0)
211 return 0;
213 /* We don't know the starting offset, but we do know that the string
214 has no internal zero bytes. We can assume that the offset falls
215 within the bounds of the string; otherwise, the programmer deserves
216 what he gets. Subtract the offset from the length of the string,
217 and return that. This would perhaps not be valid if we were dealing
218 with named arrays in addition to literal string constants. */
220 return size_diffop (size_int (max), offset_node);
223 /* We have a known offset into the string. Start searching there for
224 a null character. */
225 if (offset_node == 0)
226 offset = 0;
227 else
229 /* Did we get a long long offset? If so, punt. */
230 if (TREE_INT_CST_HIGH (offset_node) != 0)
231 return 0;
232 offset = TREE_INT_CST_LOW (offset_node);
235 /* If the offset is known to be out of bounds, warn, and call strlen at
236 runtime. */
237 if (offset < 0 || offset > max)
239 warning ("offset outside bounds of constant string");
240 return 0;
243 /* Use strlen to search for the first zero byte. Since any strings
244 constructed with build_string will have nulls appended, we win even
245 if we get handed something like (char[4])"abcd".
247 Since OFFSET is our starting index into the string, no further
248 calculation is needed. */
249 return ssize_int (strlen (ptr + offset));
252 /* Given TEM, a pointer to a stack frame, follow the dynamic chain COUNT
253 times to get the address of either a higher stack frame, or a return
254 address located within it (depending on FNDECL_CODE). */
257 expand_builtin_return_addr (fndecl_code, count, tem)
258 enum built_in_function fndecl_code;
259 int count;
260 rtx tem;
262 int i;
264 /* Some machines need special handling before we can access
265 arbitrary frames. For example, on the sparc, we must first flush
266 all register windows to the stack. */
267 #ifdef SETUP_FRAME_ADDRESSES
268 if (count > 0)
269 SETUP_FRAME_ADDRESSES ();
270 #endif
272 /* On the sparc, the return address is not in the frame, it is in a
273 register. There is no way to access it off of the current frame
274 pointer, but it can be accessed off the previous frame pointer by
275 reading the value from the register window save area. */
276 #ifdef RETURN_ADDR_IN_PREVIOUS_FRAME
277 if (fndecl_code == BUILT_IN_RETURN_ADDRESS)
278 count--;
279 #endif
281 /* Scan back COUNT frames to the specified frame. */
282 for (i = 0; i < count; i++)
284 /* Assume the dynamic chain pointer is in the word that the
285 frame address points to, unless otherwise specified. */
286 #ifdef DYNAMIC_CHAIN_ADDRESS
287 tem = DYNAMIC_CHAIN_ADDRESS (tem);
288 #endif
289 tem = memory_address (Pmode, tem);
290 tem = copy_to_reg (gen_rtx_MEM (Pmode, tem));
293 /* For __builtin_frame_address, return what we've got. */
294 if (fndecl_code == BUILT_IN_FRAME_ADDRESS)
295 return tem;
297 /* For __builtin_return_address, Get the return address from that
298 frame. */
299 #ifdef RETURN_ADDR_RTX
300 tem = RETURN_ADDR_RTX (count, tem);
301 #else
302 tem = memory_address (Pmode,
303 plus_constant (tem, GET_MODE_SIZE (Pmode)));
304 tem = gen_rtx_MEM (Pmode, tem);
305 #endif
306 return tem;
309 /* __builtin_setjmp is passed a pointer to an array of five words (not
310 all will be used on all machines). It operates similarly to the C
311 library function of the same name, but is more efficient. Much of
312 the code below (and for longjmp) is copied from the handling of
313 non-local gotos.
315 NOTE: This is intended for use by GNAT and the exception handling
316 scheme in the compiler and will only work in the method used by
317 them. */
320 expand_builtin_setjmp (buf_addr, target, first_label, next_label)
321 rtx buf_addr;
322 rtx target;
323 rtx first_label, next_label;
325 rtx lab1 = gen_label_rtx ();
326 enum machine_mode sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
327 enum machine_mode value_mode;
328 rtx stack_save;
330 value_mode = TYPE_MODE (integer_type_node);
332 #ifdef POINTERS_EXTEND_UNSIGNED
333 buf_addr = convert_memory_address (Pmode, buf_addr);
334 #endif
336 buf_addr = force_reg (Pmode, force_operand (buf_addr, NULL_RTX));
338 if (target == 0 || GET_CODE (target) != REG
339 || REGNO (target) < FIRST_PSEUDO_REGISTER)
340 target = gen_reg_rtx (value_mode);
342 emit_queue ();
344 /* We store the frame pointer and the address of lab1 in the buffer
345 and use the rest of it for the stack save area, which is
346 machine-dependent. */
348 #ifndef BUILTIN_SETJMP_FRAME_VALUE
349 #define BUILTIN_SETJMP_FRAME_VALUE virtual_stack_vars_rtx
350 #endif
352 emit_move_insn (gen_rtx_MEM (Pmode, buf_addr),
353 BUILTIN_SETJMP_FRAME_VALUE);
354 emit_move_insn (validize_mem
355 (gen_rtx_MEM (Pmode,
356 plus_constant (buf_addr,
357 GET_MODE_SIZE (Pmode)))),
358 force_reg (Pmode, gen_rtx_LABEL_REF (Pmode, lab1)));
360 stack_save = gen_rtx_MEM (sa_mode,
361 plus_constant (buf_addr,
362 2 * GET_MODE_SIZE (Pmode)));
363 emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
365 /* If there is further processing to do, do it. */
366 #ifdef HAVE_builtin_setjmp_setup
367 if (HAVE_builtin_setjmp_setup)
368 emit_insn (gen_builtin_setjmp_setup (buf_addr));
369 #endif
371 /* Set TARGET to zero and branch to the first-time-through label. */
372 emit_move_insn (target, const0_rtx);
373 emit_jump_insn (gen_jump (first_label));
374 emit_barrier ();
375 emit_label (lab1);
377 /* Tell flow about the strange goings on. Putting `lab1' on
378 `nonlocal_goto_handler_labels' to indicates that function
379 calls may traverse the arc back to this label. */
381 current_function_has_nonlocal_label = 1;
382 nonlocal_goto_handler_labels
383 = gen_rtx_EXPR_LIST (VOIDmode, lab1, nonlocal_goto_handler_labels);
385 /* Clobber the FP when we get here, so we have to make sure it's
386 marked as used by this function. */
387 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
389 /* Mark the static chain as clobbered here so life information
390 doesn't get messed up for it. */
391 emit_insn (gen_rtx_CLOBBER (VOIDmode, static_chain_rtx));
393 /* Now put in the code to restore the frame pointer, and argument
394 pointer, if needed. The code below is from expand_end_bindings
395 in stmt.c; see detailed documentation there. */
396 #ifdef HAVE_nonlocal_goto
397 if (! HAVE_nonlocal_goto)
398 #endif
399 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
401 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
402 if (fixed_regs[ARG_POINTER_REGNUM])
404 #ifdef ELIMINABLE_REGS
405 size_t i;
406 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
408 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
409 if (elim_regs[i].from == ARG_POINTER_REGNUM
410 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
411 break;
413 if (i == sizeof elim_regs / sizeof elim_regs [0])
414 #endif
416 /* Now restore our arg pointer from the address at which it
417 was saved in our stack frame.
418 If there hasn't be space allocated for it yet, make
419 some now. */
420 if (arg_pointer_save_area == 0)
421 arg_pointer_save_area
422 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
423 emit_move_insn (virtual_incoming_args_rtx,
424 copy_to_reg (arg_pointer_save_area));
427 #endif
429 #ifdef HAVE_builtin_setjmp_receiver
430 if (HAVE_builtin_setjmp_receiver)
431 emit_insn (gen_builtin_setjmp_receiver (lab1));
432 else
433 #endif
434 #ifdef HAVE_nonlocal_goto_receiver
435 if (HAVE_nonlocal_goto_receiver)
436 emit_insn (gen_nonlocal_goto_receiver ());
437 else
438 #endif
440 ; /* Nothing */
443 /* Set TARGET, and branch to the next-time-through label. */
444 emit_move_insn (target, const1_rtx);
445 emit_jump_insn (gen_jump (next_label));
446 emit_barrier ();
448 return target;
451 /* __builtin_longjmp is passed a pointer to an array of five words (not
452 all will be used on all machines). It operates similarly to the C
453 library function of the same name, but is more efficient. Much of
454 the code below is copied from the handling of non-local gotos.
456 NOTE: This is intended for use by GNAT and the exception handling
457 scheme in the compiler and will only work in the method used by
458 them. */
460 void
461 expand_builtin_longjmp (buf_addr, value)
462 rtx buf_addr, value;
464 rtx fp, lab, stack;
465 enum machine_mode sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
467 #ifdef POINTERS_EXTEND_UNSIGNED
468 buf_addr = convert_memory_address (Pmode, buf_addr);
469 #endif
470 buf_addr = force_reg (Pmode, buf_addr);
472 /* We used to store value in static_chain_rtx, but that fails if pointers
473 are smaller than integers. We instead require that the user must pass
474 a second argument of 1, because that is what builtin_setjmp will
475 return. This also makes EH slightly more efficient, since we are no
476 longer copying around a value that we don't care about. */
477 if (value != const1_rtx)
478 abort ();
480 #ifdef HAVE_builtin_longjmp
481 if (HAVE_builtin_longjmp)
482 emit_insn (gen_builtin_longjmp (buf_addr));
483 else
484 #endif
486 fp = gen_rtx_MEM (Pmode, buf_addr);
487 lab = gen_rtx_MEM (Pmode, plus_constant (buf_addr,
488 GET_MODE_SIZE (Pmode)));
490 stack = gen_rtx_MEM (sa_mode, plus_constant (buf_addr,
491 2 * GET_MODE_SIZE (Pmode)));
493 /* Pick up FP, label, and SP from the block and jump. This code is
494 from expand_goto in stmt.c; see there for detailed comments. */
495 #if HAVE_nonlocal_goto
496 if (HAVE_nonlocal_goto)
497 /* We have to pass a value to the nonlocal_goto pattern that will
498 get copied into the static_chain pointer, but it does not matter
499 what that value is, because builtin_setjmp does not use it. */
500 emit_insn (gen_nonlocal_goto (value, fp, stack, lab));
501 else
502 #endif
504 lab = copy_to_reg (lab);
506 emit_move_insn (hard_frame_pointer_rtx, fp);
507 emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
509 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
510 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
511 emit_indirect_jump (lab);
516 /* Get a MEM rtx for expression EXP which can be used in a string instruction
517 (cmpstrsi, movstrsi, ..). */
518 static rtx
519 get_memory_rtx (exp)
520 tree exp;
522 rtx mem;
523 int is_aggregate;
525 mem = gen_rtx_MEM (BLKmode,
526 memory_address (BLKmode,
527 expand_expr (exp, NULL_RTX,
528 ptr_mode, EXPAND_SUM)));
530 RTX_UNCHANGING_P (mem) = TREE_READONLY (exp);
532 /* Figure out the type of the object pointed to. Set MEM_IN_STRUCT_P
533 if the value is the address of a structure or if the expression is
534 cast to a pointer to structure type. */
535 is_aggregate = 0;
537 while (TREE_CODE (exp) == NOP_EXPR)
539 tree cast_type = TREE_TYPE (exp);
540 if (TREE_CODE (cast_type) == POINTER_TYPE
541 && AGGREGATE_TYPE_P (TREE_TYPE (cast_type)))
543 is_aggregate = 1;
544 break;
546 exp = TREE_OPERAND (exp, 0);
549 if (is_aggregate == 0)
551 tree type;
553 if (TREE_CODE (exp) == ADDR_EXPR)
554 /* If this is the address of an object, check whether the
555 object is an array. */
556 type = TREE_TYPE (TREE_OPERAND (exp, 0));
557 else
558 type = TREE_TYPE (TREE_TYPE (exp));
559 is_aggregate = AGGREGATE_TYPE_P (type);
562 MEM_SET_IN_STRUCT_P (mem, is_aggregate);
563 return mem;
566 /* Built-in functions to perform an untyped call and return. */
568 /* For each register that may be used for calling a function, this
569 gives a mode used to copy the register's value. VOIDmode indicates
570 the register is not used for calling a function. If the machine
571 has register windows, this gives only the outbound registers.
572 INCOMING_REGNO gives the corresponding inbound register. */
573 static enum machine_mode apply_args_mode[FIRST_PSEUDO_REGISTER];
575 /* For each register that may be used for returning values, this gives
576 a mode used to copy the register's value. VOIDmode indicates the
577 register is not used for returning values. If the machine has
578 register windows, this gives only the outbound registers.
579 INCOMING_REGNO gives the corresponding inbound register. */
580 static enum machine_mode apply_result_mode[FIRST_PSEUDO_REGISTER];
582 /* For each register that may be used for calling a function, this
583 gives the offset of that register into the block returned by
584 __builtin_apply_args. 0 indicates that the register is not
585 used for calling a function. */
586 static int apply_args_reg_offset[FIRST_PSEUDO_REGISTER];
588 /* Return the offset of register REGNO into the block returned by
589 __builtin_apply_args. This is not declared static, since it is
590 needed in objc-act.c. */
592 int
593 apply_args_register_offset (regno)
594 int regno;
596 apply_args_size ();
598 /* Arguments are always put in outgoing registers (in the argument
599 block) if such make sense. */
600 #ifdef OUTGOING_REGNO
601 regno = OUTGOING_REGNO(regno);
602 #endif
603 return apply_args_reg_offset[regno];
606 /* Return the size required for the block returned by __builtin_apply_args,
607 and initialize apply_args_mode. */
609 static int
610 apply_args_size ()
612 static int size = -1;
613 int align, regno;
614 enum machine_mode mode;
616 /* The values computed by this function never change. */
617 if (size < 0)
619 /* The first value is the incoming arg-pointer. */
620 size = GET_MODE_SIZE (Pmode);
622 /* The second value is the structure value address unless this is
623 passed as an "invisible" first argument. */
624 if (struct_value_rtx)
625 size += GET_MODE_SIZE (Pmode);
627 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
628 if (FUNCTION_ARG_REGNO_P (regno))
630 /* Search for the proper mode for copying this register's
631 value. I'm not sure this is right, but it works so far. */
632 enum machine_mode best_mode = VOIDmode;
634 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
635 mode != VOIDmode;
636 mode = GET_MODE_WIDER_MODE (mode))
637 if (HARD_REGNO_MODE_OK (regno, mode)
638 && HARD_REGNO_NREGS (regno, mode) == 1)
639 best_mode = mode;
641 if (best_mode == VOIDmode)
642 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
643 mode != VOIDmode;
644 mode = GET_MODE_WIDER_MODE (mode))
645 if (HARD_REGNO_MODE_OK (regno, mode)
646 && (mov_optab->handlers[(int) mode].insn_code
647 != CODE_FOR_nothing))
648 best_mode = mode;
650 mode = best_mode;
651 if (mode == VOIDmode)
652 abort ();
654 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
655 if (size % align != 0)
656 size = CEIL (size, align) * align;
657 apply_args_reg_offset[regno] = size;
658 size += GET_MODE_SIZE (mode);
659 apply_args_mode[regno] = mode;
661 else
663 apply_args_mode[regno] = VOIDmode;
664 apply_args_reg_offset[regno] = 0;
667 return size;
670 /* Return the size required for the block returned by __builtin_apply,
671 and initialize apply_result_mode. */
673 static int
674 apply_result_size ()
676 static int size = -1;
677 int align, regno;
678 enum machine_mode mode;
680 /* The values computed by this function never change. */
681 if (size < 0)
683 size = 0;
685 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
686 if (FUNCTION_VALUE_REGNO_P (regno))
688 /* Search for the proper mode for copying this register's
689 value. I'm not sure this is right, but it works so far. */
690 enum machine_mode best_mode = VOIDmode;
692 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
693 mode != TImode;
694 mode = GET_MODE_WIDER_MODE (mode))
695 if (HARD_REGNO_MODE_OK (regno, mode))
696 best_mode = mode;
698 if (best_mode == VOIDmode)
699 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
700 mode != VOIDmode;
701 mode = GET_MODE_WIDER_MODE (mode))
702 if (HARD_REGNO_MODE_OK (regno, mode)
703 && (mov_optab->handlers[(int) mode].insn_code
704 != CODE_FOR_nothing))
705 best_mode = mode;
707 mode = best_mode;
708 if (mode == VOIDmode)
709 abort ();
711 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
712 if (size % align != 0)
713 size = CEIL (size, align) * align;
714 size += GET_MODE_SIZE (mode);
715 apply_result_mode[regno] = mode;
717 else
718 apply_result_mode[regno] = VOIDmode;
720 /* Allow targets that use untyped_call and untyped_return to override
721 the size so that machine-specific information can be stored here. */
722 #ifdef APPLY_RESULT_SIZE
723 size = APPLY_RESULT_SIZE;
724 #endif
726 return size;
729 #if defined (HAVE_untyped_call) || defined (HAVE_untyped_return)
730 /* Create a vector describing the result block RESULT. If SAVEP is true,
731 the result block is used to save the values; otherwise it is used to
732 restore the values. */
734 static rtx
735 result_vector (savep, result)
736 int savep;
737 rtx result;
739 int regno, size, align, nelts;
740 enum machine_mode mode;
741 rtx reg, mem;
742 rtx *savevec = (rtx *) alloca (FIRST_PSEUDO_REGISTER * sizeof (rtx));
744 size = nelts = 0;
745 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
746 if ((mode = apply_result_mode[regno]) != VOIDmode)
748 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
749 if (size % align != 0)
750 size = CEIL (size, align) * align;
751 reg = gen_rtx_REG (mode, savep ? regno : INCOMING_REGNO (regno));
752 mem = change_address (result, mode,
753 plus_constant (XEXP (result, 0), size));
754 savevec[nelts++] = (savep
755 ? gen_rtx_SET (VOIDmode, mem, reg)
756 : gen_rtx_SET (VOIDmode, reg, mem));
757 size += GET_MODE_SIZE (mode);
759 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelts, savevec));
761 #endif /* HAVE_untyped_call or HAVE_untyped_return */
763 /* Save the state required to perform an untyped call with the same
764 arguments as were passed to the current function. */
766 static rtx
767 expand_builtin_apply_args_1 ()
769 rtx registers;
770 int size, align, regno;
771 enum machine_mode mode;
773 /* Create a block where the arg-pointer, structure value address,
774 and argument registers can be saved. */
775 registers = assign_stack_local (BLKmode, apply_args_size (), -1);
777 /* Walk past the arg-pointer and structure value address. */
778 size = GET_MODE_SIZE (Pmode);
779 if (struct_value_rtx)
780 size += GET_MODE_SIZE (Pmode);
782 /* Save each register used in calling a function to the block. */
783 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
784 if ((mode = apply_args_mode[regno]) != VOIDmode)
786 rtx tem;
788 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
789 if (size % align != 0)
790 size = CEIL (size, align) * align;
792 tem = gen_rtx_REG (mode, INCOMING_REGNO (regno));
794 emit_move_insn (change_address (registers, mode,
795 plus_constant (XEXP (registers, 0),
796 size)),
797 tem);
798 size += GET_MODE_SIZE (mode);
801 /* Save the arg pointer to the block. */
802 emit_move_insn (change_address (registers, Pmode, XEXP (registers, 0)),
803 copy_to_reg (virtual_incoming_args_rtx));
804 size = GET_MODE_SIZE (Pmode);
806 /* Save the structure value address unless this is passed as an
807 "invisible" first argument. */
808 if (struct_value_incoming_rtx)
810 emit_move_insn (change_address (registers, Pmode,
811 plus_constant (XEXP (registers, 0),
812 size)),
813 copy_to_reg (struct_value_incoming_rtx));
814 size += GET_MODE_SIZE (Pmode);
817 /* Return the address of the block. */
818 return copy_addr_to_reg (XEXP (registers, 0));
821 /* __builtin_apply_args returns block of memory allocated on
822 the stack into which is stored the arg pointer, structure
823 value address, static chain, and all the registers that might
824 possibly be used in performing a function call. The code is
825 moved to the start of the function so the incoming values are
826 saved. */
827 static rtx
828 expand_builtin_apply_args ()
830 /* Don't do __builtin_apply_args more than once in a function.
831 Save the result of the first call and reuse it. */
832 if (apply_args_value != 0)
833 return apply_args_value;
835 /* When this function is called, it means that registers must be
836 saved on entry to this function. So we migrate the
837 call to the first insn of this function. */
838 rtx temp;
839 rtx seq;
841 start_sequence ();
842 temp = expand_builtin_apply_args_1 ();
843 seq = get_insns ();
844 end_sequence ();
846 apply_args_value = temp;
848 /* Put the sequence after the NOTE that starts the function.
849 If this is inside a SEQUENCE, make the outer-level insn
850 chain current, so the code is placed at the start of the
851 function. */
852 push_topmost_sequence ();
853 emit_insns_before (seq, NEXT_INSN (get_insns ()));
854 pop_topmost_sequence ();
855 return temp;
859 /* Perform an untyped call and save the state required to perform an
860 untyped return of whatever value was returned by the given function. */
862 static rtx
863 expand_builtin_apply (function, arguments, argsize)
864 rtx function, arguments, argsize;
866 int size, align, regno;
867 enum machine_mode mode;
868 rtx incoming_args, result, reg, dest, call_insn;
869 rtx old_stack_level = 0;
870 rtx call_fusage = 0;
872 /* Create a block where the return registers can be saved. */
873 result = assign_stack_local (BLKmode, apply_result_size (), -1);
875 /* Fetch the arg pointer from the ARGUMENTS block. */
876 incoming_args = gen_reg_rtx (Pmode);
877 emit_move_insn (incoming_args,
878 gen_rtx_MEM (Pmode, arguments));
879 #ifndef STACK_GROWS_DOWNWARD
880 incoming_args = expand_binop (Pmode, sub_optab, incoming_args, argsize,
881 incoming_args, 0, OPTAB_LIB_WIDEN);
882 #endif
884 /* Perform postincrements before actually calling the function. */
885 emit_queue ();
887 /* Push a new argument block and copy the arguments. */
888 do_pending_stack_adjust ();
890 /* Save the stack with nonlocal if available */
891 #ifdef HAVE_save_stack_nonlocal
892 if (HAVE_save_stack_nonlocal)
893 emit_stack_save (SAVE_NONLOCAL, &old_stack_level, NULL_RTX);
894 else
895 #endif
896 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
898 /* Push a block of memory onto the stack to store the memory arguments.
899 Save the address in a register, and copy the memory arguments. ??? I
900 haven't figured out how the calling convention macros effect this,
901 but it's likely that the source and/or destination addresses in
902 the block copy will need updating in machine specific ways. */
903 dest = allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
904 emit_block_move (gen_rtx_MEM (BLKmode, dest),
905 gen_rtx_MEM (BLKmode, incoming_args),
906 argsize, PARM_BOUNDARY);
908 /* Refer to the argument block. */
909 apply_args_size ();
910 arguments = gen_rtx_MEM (BLKmode, arguments);
912 /* Walk past the arg-pointer and structure value address. */
913 size = GET_MODE_SIZE (Pmode);
914 if (struct_value_rtx)
915 size += GET_MODE_SIZE (Pmode);
917 /* Restore each of the registers previously saved. Make USE insns
918 for each of these registers for use in making the call. */
919 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
920 if ((mode = apply_args_mode[regno]) != VOIDmode)
922 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
923 if (size % align != 0)
924 size = CEIL (size, align) * align;
925 reg = gen_rtx_REG (mode, regno);
926 emit_move_insn (reg,
927 change_address (arguments, mode,
928 plus_constant (XEXP (arguments, 0),
929 size)));
931 use_reg (&call_fusage, reg);
932 size += GET_MODE_SIZE (mode);
935 /* Restore the structure value address unless this is passed as an
936 "invisible" first argument. */
937 size = GET_MODE_SIZE (Pmode);
938 if (struct_value_rtx)
940 rtx value = gen_reg_rtx (Pmode);
941 emit_move_insn (value,
942 change_address (arguments, Pmode,
943 plus_constant (XEXP (arguments, 0),
944 size)));
945 emit_move_insn (struct_value_rtx, value);
946 if (GET_CODE (struct_value_rtx) == REG)
947 use_reg (&call_fusage, struct_value_rtx);
948 size += GET_MODE_SIZE (Pmode);
951 /* All arguments and registers used for the call are set up by now! */
952 function = prepare_call_address (function, NULL_TREE, &call_fusage, 0);
954 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
955 and we don't want to load it into a register as an optimization,
956 because prepare_call_address already did it if it should be done. */
957 if (GET_CODE (function) != SYMBOL_REF)
958 function = memory_address (FUNCTION_MODE, function);
960 /* Generate the actual call instruction and save the return value. */
961 #ifdef HAVE_untyped_call
962 if (HAVE_untyped_call)
963 emit_call_insn (gen_untyped_call (gen_rtx_MEM (FUNCTION_MODE, function),
964 result, result_vector (1, result)));
965 else
966 #endif
967 #ifdef HAVE_call_value
968 if (HAVE_call_value)
970 rtx valreg = 0;
972 /* Locate the unique return register. It is not possible to
973 express a call that sets more than one return register using
974 call_value; use untyped_call for that. In fact, untyped_call
975 only needs to save the return registers in the given block. */
976 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
977 if ((mode = apply_result_mode[regno]) != VOIDmode)
979 if (valreg)
980 abort (); /* HAVE_untyped_call required. */
981 valreg = gen_rtx_REG (mode, regno);
984 emit_call_insn (gen_call_value (valreg,
985 gen_rtx_MEM (FUNCTION_MODE, function),
986 const0_rtx, NULL_RTX, const0_rtx));
988 emit_move_insn (change_address (result, GET_MODE (valreg),
989 XEXP (result, 0)),
990 valreg);
992 else
993 #endif
994 abort ();
996 /* Find the CALL insn we just emitted. */
997 for (call_insn = get_last_insn ();
998 call_insn && GET_CODE (call_insn) != CALL_INSN;
999 call_insn = PREV_INSN (call_insn))
1002 if (! call_insn)
1003 abort ();
1005 /* Put the register usage information on the CALL. If there is already
1006 some usage information, put ours at the end. */
1007 if (CALL_INSN_FUNCTION_USAGE (call_insn))
1009 rtx link;
1011 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
1012 link = XEXP (link, 1))
1015 XEXP (link, 1) = call_fusage;
1017 else
1018 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
1020 /* Restore the stack. */
1021 #ifdef HAVE_save_stack_nonlocal
1022 if (HAVE_save_stack_nonlocal)
1023 emit_stack_restore (SAVE_NONLOCAL, old_stack_level, NULL_RTX);
1024 else
1025 #endif
1026 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1028 /* Return the address of the result block. */
1029 return copy_addr_to_reg (XEXP (result, 0));
1032 /* Perform an untyped return. */
1034 static void
1035 expand_builtin_return (result)
1036 rtx result;
1038 int size, align, regno;
1039 enum machine_mode mode;
1040 rtx reg;
1041 rtx call_fusage = 0;
1043 apply_result_size ();
1044 result = gen_rtx_MEM (BLKmode, result);
1046 #ifdef HAVE_untyped_return
1047 if (HAVE_untyped_return)
1049 emit_jump_insn (gen_untyped_return (result, result_vector (0, result)));
1050 emit_barrier ();
1051 return;
1053 #endif
1055 /* Restore the return value and note that each value is used. */
1056 size = 0;
1057 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1058 if ((mode = apply_result_mode[regno]) != VOIDmode)
1060 align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
1061 if (size % align != 0)
1062 size = CEIL (size, align) * align;
1063 reg = gen_rtx_REG (mode, INCOMING_REGNO (regno));
1064 emit_move_insn (reg,
1065 change_address (result, mode,
1066 plus_constant (XEXP (result, 0),
1067 size)));
1069 push_to_sequence (call_fusage);
1070 emit_insn (gen_rtx_USE (VOIDmode, reg));
1071 call_fusage = get_insns ();
1072 end_sequence ();
1073 size += GET_MODE_SIZE (mode);
1076 /* Put the USE insns before the return. */
1077 emit_insns (call_fusage);
1079 /* Return whatever values was restored by jumping directly to the end
1080 of the function. */
1081 expand_null_return ();
1084 /* Expand a call to __builtin_classify_type with arguments found in
1085 ARGLIST. */
1086 static rtx
1087 expand_builtin_classify_type (arglist)
1088 tree arglist;
1090 if (arglist != 0)
1092 tree type = TREE_TYPE (TREE_VALUE (arglist));
1093 enum tree_code code = TREE_CODE (type);
1094 if (code == VOID_TYPE)
1095 return GEN_INT (void_type_class);
1096 if (code == INTEGER_TYPE)
1097 return GEN_INT (integer_type_class);
1098 if (code == CHAR_TYPE)
1099 return GEN_INT (char_type_class);
1100 if (code == ENUMERAL_TYPE)
1101 return GEN_INT (enumeral_type_class);
1102 if (code == BOOLEAN_TYPE)
1103 return GEN_INT (boolean_type_class);
1104 if (code == POINTER_TYPE)
1105 return GEN_INT (pointer_type_class);
1106 if (code == REFERENCE_TYPE)
1107 return GEN_INT (reference_type_class);
1108 if (code == OFFSET_TYPE)
1109 return GEN_INT (offset_type_class);
1110 if (code == REAL_TYPE)
1111 return GEN_INT (real_type_class);
1112 if (code == COMPLEX_TYPE)
1113 return GEN_INT (complex_type_class);
1114 if (code == FUNCTION_TYPE)
1115 return GEN_INT (function_type_class);
1116 if (code == METHOD_TYPE)
1117 return GEN_INT (method_type_class);
1118 if (code == RECORD_TYPE)
1119 return GEN_INT (record_type_class);
1120 if (code == UNION_TYPE || code == QUAL_UNION_TYPE)
1121 return GEN_INT (union_type_class);
1122 if (code == ARRAY_TYPE)
1124 if (TYPE_STRING_FLAG (type))
1125 return GEN_INT (string_type_class);
1126 else
1127 return GEN_INT (array_type_class);
1129 if (code == SET_TYPE)
1130 return GEN_INT (set_type_class);
1131 if (code == FILE_TYPE)
1132 return GEN_INT (file_type_class);
1133 if (code == LANG_TYPE)
1134 return GEN_INT (lang_type_class);
1136 return GEN_INT (no_type_class);
1139 /* Expand expression EXP, which is a call to __builtin_constant_p. */
1140 static rtx
1141 expand_builtin_constant_p (exp)
1142 tree exp;
1144 tree arglist = TREE_OPERAND (exp, 1);
1145 enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
1147 if (arglist == 0)
1148 return const0_rtx;
1149 else
1151 tree arg = TREE_VALUE (arglist);
1152 rtx tmp;
1154 /* We return 1 for a numeric type that's known to be a constant
1155 value at compile-time or for an aggregate type that's a
1156 literal constant. */
1157 STRIP_NOPS (arg);
1159 /* If we know this is a constant, emit the constant of one. */
1160 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'c'
1161 || (TREE_CODE (arg) == CONSTRUCTOR
1162 && TREE_CONSTANT (arg))
1163 || (TREE_CODE (arg) == ADDR_EXPR
1164 && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST))
1165 return const1_rtx;
1167 /* If we aren't going to be running CSE or this expression
1168 has side effects, show we don't know it to be a constant.
1169 Likewise if it's a pointer or aggregate type since in those
1170 case we only want literals, since those are only optimized
1171 when generating RTL, not later. */
1172 if (TREE_SIDE_EFFECTS (arg) || cse_not_expected
1173 || AGGREGATE_TYPE_P (TREE_TYPE (arg))
1174 || POINTER_TYPE_P (TREE_TYPE (arg)))
1175 return const0_rtx;
1177 /* Otherwise, emit (constant_p_rtx (ARG)) and let CSE get a
1178 chance to see if it can deduce whether ARG is constant. */
1180 tmp = expand_expr (arg, NULL_RTX, VOIDmode, 0);
1181 tmp = gen_rtx_CONSTANT_P_RTX (value_mode, tmp);
1182 return tmp;
1186 /* Expand a call to one of the builtin math functions (sin, cos, or sqrt).
1187 Return 0 if a normal call should be emitted rather than expanding the
1188 function in-line. EXP is the expression that is a call to the builtin
1189 function; if convenient, the result should be placed in TARGET.
1190 SUBTARGET may be used as the target for computing one of EXP's operands. */
1191 static rtx
1192 expand_builtin_mathfn (exp, target, subtarget)
1193 tree exp;
1194 rtx target, subtarget;
1196 optab builtin_optab;
1197 rtx op0, insns;
1198 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
1199 tree arglist = TREE_OPERAND (exp, 1);
1201 if (arglist == 0
1202 /* Arg could be wrong type if user redeclared this fcn wrong. */
1203 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != REAL_TYPE)
1204 return 0;
1206 /* Stabilize and compute the argument. */
1207 if (TREE_CODE (TREE_VALUE (arglist)) != VAR_DECL
1208 && TREE_CODE (TREE_VALUE (arglist)) != PARM_DECL)
1210 exp = copy_node (exp);
1211 TREE_OPERAND (exp, 1) = arglist;
1212 /* Wrap the computation of the argument in a SAVE_EXPR. That
1213 way, if we need to expand the argument again (as in the
1214 flag_errno_math case below where we cannot directly set
1215 errno), we will not perform side-effects more than once.
1216 Note that here we're mutating the original EXP as well as the
1217 copy; that's the right thing to do in case the original EXP
1218 is expanded later. */
1219 TREE_VALUE (arglist) = save_expr (TREE_VALUE (arglist));
1220 arglist = copy_node (arglist);
1222 op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
1224 /* Make a suitable register to place result in. */
1225 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
1227 emit_queue ();
1228 start_sequence ();
1230 switch (DECL_FUNCTION_CODE (fndecl))
1232 case BUILT_IN_SIN:
1233 builtin_optab = sin_optab; break;
1234 case BUILT_IN_COS:
1235 builtin_optab = cos_optab; break;
1236 case BUILT_IN_FSQRT:
1237 builtin_optab = sqrt_optab; break;
1238 default:
1239 abort ();
1242 /* Compute into TARGET.
1243 Set TARGET to wherever the result comes back. */
1244 target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
1245 builtin_optab, op0, target, 0);
1247 /* If we were unable to expand via the builtin, stop the
1248 sequence (without outputting the insns) and return 0, causing
1249 a call to the library function. */
1250 if (target == 0)
1252 end_sequence ();
1253 return 0;
1256 /* Check the results by default. But if flag_fast_math is turned on,
1257 then assume sqrt will always be called with valid arguments. */
1259 if (flag_errno_math && ! flag_fast_math)
1261 rtx lab1;
1263 /* Don't define the builtin FP instructions
1264 if your machine is not IEEE. */
1265 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
1266 abort ();
1268 lab1 = gen_label_rtx ();
1270 /* Test the result; if it is NaN, set errno=EDOM because
1271 the argument was not in the domain. */
1272 emit_cmp_and_jump_insns (target, target, EQ, 0, GET_MODE (target),
1273 0, 0, lab1);
1275 #ifdef TARGET_EDOM
1277 #ifdef GEN_ERRNO_RTX
1278 rtx errno_rtx = GEN_ERRNO_RTX;
1279 #else
1280 rtx errno_rtx
1281 = gen_rtx_MEM (word_mode, gen_rtx_SYMBOL_REF (Pmode, "errno"));
1282 #endif
1284 emit_move_insn (errno_rtx, GEN_INT (TARGET_EDOM));
1286 #else
1287 /* We can't set errno=EDOM directly; let the library call do it.
1288 Pop the arguments right away in case the call gets deleted. */
1289 NO_DEFER_POP;
1290 expand_call (exp, target, 0);
1291 OK_DEFER_POP;
1292 #endif
1294 emit_label (lab1);
1297 /* Output the entire sequence. */
1298 insns = get_insns ();
1299 end_sequence ();
1300 emit_insns (insns);
1302 return target;
1305 /* Expand expression EXP which is a call to the strlen builtin. Return 0
1306 if we failed the caller should emit a normal call, otherwise
1307 try to get the result in TARGET, if convenient (and in mode MODE if that's
1308 convenient). */
1309 static rtx
1310 expand_builtin_strlen (exp, target, mode)
1311 tree exp;
1312 rtx target;
1313 enum machine_mode mode;
1315 tree arglist = TREE_OPERAND (exp, 1);
1316 enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
1318 if (arglist == 0
1319 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1320 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
1321 return 0;
1322 else
1324 rtx pat;
1325 tree src = TREE_VALUE (arglist);
1326 tree len = c_strlen (src);
1328 int align
1329 = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
1331 rtx result, src_reg, char_rtx, before_strlen;
1332 enum machine_mode insn_mode = value_mode, char_mode;
1333 enum insn_code icode = CODE_FOR_nothing;
1335 /* If the length is known, just return it. */
1336 if (len != 0)
1337 return expand_expr (len, target, mode, EXPAND_MEMORY_USE_BAD);
1339 /* If SRC is not a pointer type, don't do this operation inline. */
1340 if (align == 0)
1341 return 0;
1343 /* Bail out if we can't compute strlen in the right mode. */
1344 while (insn_mode != VOIDmode)
1346 icode = strlen_optab->handlers[(int) insn_mode].insn_code;
1347 if (icode != CODE_FOR_nothing)
1348 break;
1350 insn_mode = GET_MODE_WIDER_MODE (insn_mode);
1352 if (insn_mode == VOIDmode)
1353 return 0;
1355 /* Make a place to write the result of the instruction. */
1356 result = target;
1357 if (! (result != 0
1358 && GET_CODE (result) == REG
1359 && GET_MODE (result) == insn_mode
1360 && REGNO (result) >= FIRST_PSEUDO_REGISTER))
1361 result = gen_reg_rtx (insn_mode);
1363 /* Make a place to hold the source address. We will not expand
1364 the actual source until we are sure that the expansion will
1365 not fail -- there are trees that cannot be expanded twice. */
1366 src_reg = gen_reg_rtx (Pmode);
1368 /* Mark the beginning of the strlen sequence so we can emit the
1369 source operand later. */
1370 before_strlen = get_last_insn();
1372 /* Check the string is readable and has an end. */
1373 if (current_function_check_memory_usage)
1374 emit_library_call (chkr_check_str_libfunc, 1, VOIDmode, 2,
1375 src_reg, Pmode,
1376 GEN_INT (MEMORY_USE_RO),
1377 TYPE_MODE (integer_type_node));
1379 char_rtx = const0_rtx;
1380 char_mode = insn_data[(int)icode].operand[2].mode;
1381 if (! (*insn_data[(int)icode].operand[2].predicate) (char_rtx, char_mode))
1382 char_rtx = copy_to_mode_reg (char_mode, char_rtx);
1384 pat = GEN_FCN (icode) (result, gen_rtx_MEM (BLKmode, src_reg),
1385 char_rtx, GEN_INT (align));
1386 if (! pat)
1387 return 0;
1388 emit_insn (pat);
1390 /* Now that we are assured of success, expand the source. */
1391 start_sequence ();
1392 pat = memory_address (BLKmode,
1393 expand_expr (src, src_reg, ptr_mode, EXPAND_SUM));
1394 if (pat != src_reg)
1395 emit_move_insn (src_reg, pat);
1396 pat = gen_sequence ();
1397 end_sequence ();
1399 if (before_strlen)
1400 emit_insn_after (pat, before_strlen);
1401 else
1402 emit_insn_before (pat, get_insns ());
1404 /* Return the value in the proper mode for this function. */
1405 if (GET_MODE (result) == value_mode)
1406 target = result;
1407 else if (target != 0)
1408 convert_move (target, result, 0);
1409 else
1410 target = convert_to_mode (value_mode, result, 0);
1412 return target;
1416 /* Expand a call to the memcpy builtin, with arguments in ARGLIST. */
1417 static rtx
1418 expand_builtin_memcpy (arglist)
1419 tree arglist;
1421 if (arglist == 0
1422 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1423 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
1424 || TREE_CHAIN (arglist) == 0
1425 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
1426 != POINTER_TYPE)
1427 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
1428 || (TREE_CODE (TREE_TYPE (TREE_VALUE
1429 (TREE_CHAIN (TREE_CHAIN (arglist)))))
1430 != INTEGER_TYPE))
1431 return 0;
1432 else
1434 tree dest = TREE_VALUE (arglist);
1435 tree src = TREE_VALUE (TREE_CHAIN (arglist));
1436 tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
1438 int src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT);
1439 int dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
1440 rtx dest_mem, src_mem, dest_addr, len_rtx;
1442 /* If either SRC or DEST is not a pointer type, don't do
1443 this operation in-line. */
1444 if (src_align == 0 || dest_align == 0)
1445 return 0;
1447 dest_mem = get_memory_rtx (dest);
1448 src_mem = get_memory_rtx (src);
1449 len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
1451 /* Just copy the rights of SRC to the rights of DEST. */
1452 if (current_function_check_memory_usage)
1453 emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
1454 XEXP (dest_mem, 0), Pmode,
1455 XEXP (src_mem, 0), Pmode,
1456 len_rtx, TYPE_MODE (sizetype));
1458 /* Copy word part most expediently. */
1459 dest_addr
1460 = emit_block_move (dest_mem, src_mem, len_rtx,
1461 MIN (src_align, dest_align));
1463 if (dest_addr == 0)
1464 dest_addr = force_operand (XEXP (dest_mem, 0), NULL_RTX);
1466 return dest_addr;
1470 /* Expand expression EXP, which is a call to the strcpy builtin. Return 0
1471 if we failed the caller should emit a normal call. */
1473 static rtx
1474 expand_builtin_strcpy (exp)
1475 tree exp;
1477 tree arglist = TREE_OPERAND (exp, 1);
1478 rtx result;
1480 if (arglist == 0
1481 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1482 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
1483 || TREE_CHAIN (arglist) == 0
1484 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
1485 != POINTER_TYPE))
1486 return 0;
1487 else
1489 tree len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
1491 if (len == 0)
1492 return 0;
1494 len = size_binop (PLUS_EXPR, len, ssize_int (1));
1495 chainon (arglist, build_tree_list (NULL_TREE, len));
1498 result = expand_builtin_memcpy (arglist);
1500 if (! result)
1501 TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
1502 return result;
1505 /* Expand expression EXP, which is a call to the memset builtin. Return 0
1506 if we failed the caller should emit a normal call. */
1508 static rtx
1509 expand_builtin_memset (exp)
1510 tree exp;
1512 tree arglist = TREE_OPERAND (exp, 1);
1514 if (arglist == 0
1515 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1516 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
1517 || TREE_CHAIN (arglist) == 0
1518 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
1519 != INTEGER_TYPE)
1520 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
1521 || (INTEGER_TYPE
1522 != (TREE_CODE (TREE_TYPE
1523 (TREE_VALUE
1524 (TREE_CHAIN (TREE_CHAIN (arglist))))))))
1525 return 0;
1526 else
1528 tree dest = TREE_VALUE (arglist);
1529 tree val = TREE_VALUE (TREE_CHAIN (arglist));
1530 tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
1532 int dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
1533 rtx dest_mem, dest_addr, len_rtx;
1535 /* If DEST is not a pointer type, don't do this
1536 operation in-line. */
1537 if (dest_align == 0)
1538 return 0;
1540 /* If the arguments have side-effects, then we can only evaluate
1541 them at most once. The following code evaluates them twice if
1542 they are not constants because we break out to expand_call
1543 in that case. They can't be constants if they have side-effects
1544 so we can check for that first. Alternatively, we could call
1545 save_expr to make multiple evaluation safe. */
1546 if (TREE_SIDE_EFFECTS (val) || TREE_SIDE_EFFECTS (len))
1547 return 0;
1549 /* If VAL is not 0, don't do this operation in-line. */
1550 if (expand_expr (val, NULL_RTX, VOIDmode, 0) != const0_rtx)
1551 return 0;
1553 len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
1555 dest_mem = get_memory_rtx (dest);
1557 /* Just check DST is writable and mark it as readable. */
1558 if (current_function_check_memory_usage)
1559 emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
1560 XEXP (dest_mem, 0), Pmode,
1561 len_rtx, TYPE_MODE (sizetype),
1562 GEN_INT (MEMORY_USE_WO),
1563 TYPE_MODE (integer_type_node));
1566 dest_addr = clear_storage (dest_mem, len_rtx, dest_align);
1568 if (dest_addr == 0)
1569 dest_addr = force_operand (XEXP (dest_mem, 0), NULL_RTX);
1571 return dest_addr;
1575 /* Expand expression EXP, which is a call to the bzero builtin. Return 0
1576 if we failed the caller should emit a normal call. */
1577 static rtx
1578 expand_builtin_bzero (exp)
1579 tree exp;
1581 tree arglist = TREE_OPERAND (exp, 1);
1582 tree dest, size, newarglist;
1583 rtx result;
1585 if (arglist == 0
1586 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1587 || TREE_CODE (TREE_TYPE (dest = TREE_VALUE (arglist))) != POINTER_TYPE
1588 || TREE_CHAIN (arglist) == 0
1589 || (TREE_CODE (TREE_TYPE (size = TREE_VALUE (TREE_CHAIN (arglist))))
1590 != INTEGER_TYPE))
1591 return NULL_RTX;
1593 /* New argument list transforming bzero(ptr x, int y) to
1594 memset(ptr x, int 0, size_t y). */
1596 newarglist = build_tree_list (NULL_TREE, convert (sizetype, size));
1597 newarglist = tree_cons (NULL_TREE, integer_zero_node, newarglist);
1598 newarglist = tree_cons (NULL_TREE, dest, newarglist);
1600 TREE_OPERAND (exp, 1) = newarglist;
1601 result = expand_builtin_memset(exp);
1603 /* Always restore the original arguments. */
1604 TREE_OPERAND (exp, 1) = arglist;
1606 return result;
1609 #ifdef HAVE_cmpstrsi
1610 /* Expand expression EXP, which is a call to the memcmp or the strcmp builtin.
1611 ARGLIST is the argument list for this call. Return 0 if we failed and the
1612 caller should emit a normal call, otherwise try to get the result in
1613 TARGET, if convenient. */
1614 static rtx
1615 expand_builtin_memcmp (exp, arglist, target)
1616 tree exp;
1617 tree arglist;
1618 rtx target;
1620 /* If we need to check memory accesses, call the library function. */
1621 if (current_function_check_memory_usage)
1622 return 0;
1624 if (arglist == 0
1625 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1626 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
1627 || TREE_CHAIN (arglist) == 0
1628 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
1629 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
1630 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
1631 return 0;
1634 enum machine_mode mode;
1635 tree arg1 = TREE_VALUE (arglist);
1636 tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
1637 tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
1638 rtx arg1_rtx, arg2_rtx, arg3_rtx;
1639 rtx result;
1640 rtx insn;
1642 int arg1_align
1643 = get_pointer_alignment (arg1, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
1644 int arg2_align
1645 = get_pointer_alignment (arg2, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
1646 enum machine_mode insn_mode
1647 = insn_data[(int) CODE_FOR_cmpstrsi].operand[0].mode;
1649 /* If we don't have POINTER_TYPE, call the function. */
1650 if (arg1_align == 0 || arg2_align == 0)
1651 return 0;
1653 /* Make a place to write the result of the instruction. */
1654 result = target;
1655 if (! (result != 0
1656 && GET_CODE (result) == REG && GET_MODE (result) == insn_mode
1657 && REGNO (result) >= FIRST_PSEUDO_REGISTER))
1658 result = gen_reg_rtx (insn_mode);
1660 arg1_rtx = get_memory_rtx (arg1);
1661 arg2_rtx = get_memory_rtx (arg2);
1662 arg3_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
1663 if (!HAVE_cmpstrsi)
1664 insn = NULL_RTX;
1665 else
1666 insn = gen_cmpstrsi (result, arg1_rtx, arg2_rtx, arg3_rtx,
1667 GEN_INT (MIN (arg1_align, arg2_align)));
1669 if (insn)
1670 emit_insn (insn);
1671 else
1672 emit_library_call_value (memcmp_libfunc, result, 2,
1673 TYPE_MODE (integer_type_node), 3,
1674 XEXP (arg1_rtx, 0), Pmode,
1675 XEXP (arg2_rtx, 0), Pmode,
1676 convert_to_mode (TYPE_MODE (sizetype), arg3_rtx,
1677 TREE_UNSIGNED (sizetype)),
1678 TYPE_MODE (sizetype));
1680 /* Return the value in the proper mode for this function. */
1681 mode = TYPE_MODE (TREE_TYPE (exp));
1682 if (GET_MODE (result) == mode)
1683 return result;
1684 else if (target != 0)
1686 convert_move (target, result, 0);
1687 return target;
1689 else
1690 return convert_to_mode (mode, result, 0);
1694 /* Expand expression EXP, which is a call to the strcmp builtin. Return 0
1695 if we failed the caller should emit a normal call, otherwise try to get
1696 the result in TARGET, if convenient. */
1698 static rtx
1699 expand_builtin_strcmp (exp, target)
1700 tree exp;
1701 rtx target;
1703 tree arglist = TREE_OPERAND (exp, 1);
1705 /* If we need to check memory accesses, call the library function. */
1706 if (current_function_check_memory_usage)
1707 return 0;
1709 if (arglist == 0
1710 /* Arg could be non-pointer if user redeclared this fcn wrong. */
1711 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
1712 || TREE_CHAIN (arglist) == 0
1713 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
1714 != POINTER_TYPE))
1715 return 0;
1717 else if (! HAVE_cmpstrsi)
1718 return 0;
1720 tree arg1 = TREE_VALUE (arglist);
1721 tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
1722 tree len = c_strlen (arg1);
1723 tree len2 = c_strlen (arg2);
1724 rtx result;
1726 if (len)
1727 len = size_binop (PLUS_EXPR, ssize_int (1), len);
1729 if (len2)
1730 len2 = size_binop (PLUS_EXPR, ssize_int (1), len2);
1732 /* If we don't have a constant length for the first, use the length
1733 of the second, if we know it. We don't require a constant for
1734 this case; some cost analysis could be done if both are available
1735 but neither is constant. For now, assume they're equally cheap.
1737 If both strings have constant lengths, use the smaller. This
1738 could arise if optimization results in strcpy being called with
1739 two fixed strings, or if the code was machine-generated. We should
1740 add some code to the `memcmp' handler below to deal with such
1741 situations, someday. */
1743 if (!len || TREE_CODE (len) != INTEGER_CST)
1745 if (len2)
1746 len = len2;
1747 else if (len == 0)
1748 return 0;
1750 else if (len2 && TREE_CODE (len2) == INTEGER_CST
1751 && tree_int_cst_lt (len2, len))
1752 len = len2;
1754 chainon (arglist, build_tree_list (NULL_TREE, len));
1755 result = expand_builtin_memcmp (exp, arglist, target);
1756 if (! result)
1757 TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
1759 return result;
1762 #endif
1764 /* Expand a call to __builtin_saveregs, generating the result in TARGET,
1765 if that's convenient. */
1768 expand_builtin_saveregs ()
1770 rtx val, seq;
1772 /* Don't do __builtin_saveregs more than once in a function.
1773 Save the result of the first call and reuse it. */
1774 if (saveregs_value != 0)
1775 return saveregs_value;
1777 /* When this function is called, it means that registers must be
1778 saved on entry to this function. So we migrate the call to the
1779 first insn of this function. */
1781 start_sequence ();
1783 #ifdef EXPAND_BUILTIN_SAVEREGS
1784 /* Do whatever the machine needs done in this case. */
1785 val = EXPAND_BUILTIN_SAVEREGS ();
1786 #else
1787 /* ??? We used to try and build up a call to the out of line function,
1788 guessing about what registers needed saving etc. This became much
1789 harder with __builtin_va_start, since we don't have a tree for a
1790 call to __builtin_saveregs to fall back on. There was exactly one
1791 port (i860) that used this code, and I'm unconvinced it could actually
1792 handle the general case. So we no longer try to handle anything
1793 weird and make the backend absorb the evil. */
1795 error ("__builtin_saveregs not supported by this target");
1796 val = const0_rtx;
1797 #endif
1799 seq = get_insns ();
1800 end_sequence ();
1802 saveregs_value = val;
1804 /* Put the sequence after the NOTE that starts the function. If this
1805 is inside a SEQUENCE, make the outer-level insn chain current, so
1806 the code is placed at the start of the function. */
1807 push_topmost_sequence ();
1808 emit_insns_after (seq, get_insns ());
1809 pop_topmost_sequence ();
1811 return val;
1814 /* __builtin_args_info (N) returns word N of the arg space info
1815 for the current function. The number and meanings of words
1816 is controlled by the definition of CUMULATIVE_ARGS. */
1817 static rtx
1818 expand_builtin_args_info (exp)
1819 tree exp;
1821 tree arglist = TREE_OPERAND (exp, 1);
1822 int nwords = sizeof (CUMULATIVE_ARGS) / sizeof (int);
1823 int *word_ptr = (int *) &current_function_args_info;
1824 #if 0
1825 /* These are used by the code below that is if 0'ed away */
1826 int i;
1827 tree type, elts, result;
1828 #endif
1830 if (sizeof (CUMULATIVE_ARGS) % sizeof (int) != 0)
1831 abort ();
1833 if (arglist != 0)
1835 tree arg = TREE_VALUE (arglist);
1836 if (TREE_CODE (arg) != INTEGER_CST)
1837 error ("argument of `__builtin_args_info' must be constant");
1838 else
1840 int wordnum = TREE_INT_CST_LOW (arg);
1842 if (wordnum < 0 || wordnum >= nwords || TREE_INT_CST_HIGH (arg))
1843 error ("argument of `__builtin_args_info' out of range");
1844 else
1845 return GEN_INT (word_ptr[wordnum]);
1848 else
1849 error ("missing argument in `__builtin_args_info'");
1851 return const0_rtx;
1853 #if 0
1854 for (i = 0; i < nwords; i++)
1855 elts = tree_cons (NULL_TREE, build_int_2 (word_ptr[i], 0));
1857 type = build_array_type (integer_type_node,
1858 build_index_type (build_int_2 (nwords, 0)));
1859 result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (elts));
1860 TREE_CONSTANT (result) = 1;
1861 TREE_STATIC (result) = 1;
1862 result = build1 (INDIRECT_REF, build_pointer_type (type), result);
1863 TREE_CONSTANT (result) = 1;
1864 return expand_expr (result, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD);
1865 #endif
1868 /* Expand ARGLIST, from a call to __builtin_next_arg. */
1869 static rtx
1870 expand_builtin_next_arg (arglist)
1871 tree arglist;
1873 tree fntype = TREE_TYPE (current_function_decl);
1875 if ((TYPE_ARG_TYPES (fntype) == 0
1876 || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1877 == void_type_node))
1878 && ! current_function_varargs)
1880 error ("`va_start' used in function with fixed args");
1881 return const0_rtx;
1884 if (arglist)
1886 tree last_parm = tree_last (DECL_ARGUMENTS (current_function_decl));
1887 tree arg = TREE_VALUE (arglist);
1889 /* Strip off all nops for the sake of the comparison. This
1890 is not quite the same as STRIP_NOPS. It does more.
1891 We must also strip off INDIRECT_EXPR for C++ reference
1892 parameters. */
1893 while (TREE_CODE (arg) == NOP_EXPR
1894 || TREE_CODE (arg) == CONVERT_EXPR
1895 || TREE_CODE (arg) == NON_LVALUE_EXPR
1896 || TREE_CODE (arg) == INDIRECT_REF)
1897 arg = TREE_OPERAND (arg, 0);
1898 if (arg != last_parm)
1899 warning ("second parameter of `va_start' not last named argument");
1901 else if (! current_function_varargs)
1902 /* Evidently an out of date version of <stdarg.h>; can't validate
1903 va_start's second argument, but can still work as intended. */
1904 warning ("`__builtin_next_arg' called without an argument");
1906 return expand_binop (Pmode, add_optab,
1907 current_function_internal_arg_pointer,
1908 current_function_arg_offset_rtx,
1909 NULL_RTX, 0, OPTAB_LIB_WIDEN);
1912 /* Make it easier for the backends by protecting the valist argument
1913 from multiple evaluations. */
1915 static tree
1916 stabilize_va_list (valist, needs_lvalue)
1917 tree valist;
1918 int needs_lvalue;
1920 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1922 if (TREE_SIDE_EFFECTS (valist))
1923 valist = save_expr (valist);
1925 /* For this case, the backends will be expecting a pointer to
1926 TREE_TYPE (va_list_type_node), but it's possible we've
1927 actually been given an array (an actual va_list_type_node).
1928 So fix it. */
1929 if (TREE_CODE (TREE_TYPE (valist)) == ARRAY_TYPE)
1931 tree p1 = build_pointer_type (TREE_TYPE (va_list_type_node));
1932 tree p2 = build_pointer_type (va_list_type_node);
1934 valist = build1 (ADDR_EXPR, p2, valist);
1935 valist = fold (build1 (NOP_EXPR, p1, valist));
1938 else
1940 tree pt;
1942 if (! needs_lvalue)
1944 if (! TREE_SIDE_EFFECTS (valist))
1945 return valist;
1947 pt = build_pointer_type (va_list_type_node);
1948 valist = fold (build1 (ADDR_EXPR, pt, valist));
1949 TREE_SIDE_EFFECTS (valist) = 1;
1952 if (TREE_SIDE_EFFECTS (valist))
1953 valist = save_expr (valist);
1954 valist = fold (build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)),
1955 valist));
1958 return valist;
1961 /* The "standard" implementation of va_start: just assign `nextarg' to
1962 the variable. */
1963 void
1964 std_expand_builtin_va_start (stdarg_p, valist, nextarg)
1965 int stdarg_p ATTRIBUTE_UNUSED;
1966 tree valist;
1967 rtx nextarg;
1969 tree t;
1971 if (!stdarg_p)
1972 nextarg = plus_constant (nextarg, -UNITS_PER_WORD);
1974 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1975 make_tree (ptr_type_node, nextarg));
1976 TREE_SIDE_EFFECTS (t) = 1;
1978 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1981 /* Expand ARGLIST, which from a call to __builtin_stdarg_va_start or
1982 __builtin_varargs_va_start, depending on STDARG_P. */
1983 static rtx
1984 expand_builtin_va_start (stdarg_p, arglist)
1985 int stdarg_p;
1986 tree arglist;
1988 rtx nextarg;
1989 tree chain = arglist, valist;
1991 if (stdarg_p)
1992 nextarg = expand_builtin_next_arg (chain = TREE_CHAIN (arglist));
1993 else
1994 nextarg = expand_builtin_next_arg (NULL_TREE);
1996 if (TREE_CHAIN (chain))
1997 error ("too many arguments to function `va_start'");
1999 valist = stabilize_va_list (TREE_VALUE (arglist), 1);
2001 #ifdef EXPAND_BUILTIN_VA_START
2002 EXPAND_BUILTIN_VA_START (stdarg_p, valist, nextarg);
2003 #else
2004 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2005 #endif
2007 return const0_rtx;
2010 /* Allocate an alias set for use in storing and reading from the varargs
2011 spill area. */
2013 get_varargs_alias_set ()
2015 static int set = -1;
2016 if (set == -1)
2017 set = new_alias_set ();
2018 return set;
2021 /* The "standard" implementation of va_arg: read the value from the
2022 current (padded) address and increment by the (padded) size. */
2024 std_expand_builtin_va_arg (valist, type)
2025 tree valist, type;
2027 tree addr_tree, t;
2028 HOST_WIDE_INT align;
2029 HOST_WIDE_INT rounded_size;
2030 rtx addr;
2032 /* Compute the rounded size of the type. */
2033 align = PARM_BOUNDARY / BITS_PER_UNIT;
2034 rounded_size = (((int_size_in_bytes (type) + align - 1) / align) * align);
2036 /* Get AP. */
2037 addr_tree = valist;
2038 if (PAD_VARARGS_DOWN)
2040 /* Small args are padded downward. */
2042 HOST_WIDE_INT adj;
2043 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2044 if (rounded_size > align)
2045 adj = rounded_size;
2047 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2048 build_int_2 (rounded_size - adj, 0));
2051 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2052 addr = copy_to_reg (addr);
2054 /* Compute new value for AP. */
2055 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2056 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2057 build_int_2 (rounded_size, 0)));
2058 TREE_SIDE_EFFECTS (t) = 1;
2059 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2061 return addr;
2064 /* Expand __builtin_va_arg, which is not really a builtin function, but
2065 a very special sort of operator. */
2067 expand_builtin_va_arg (valist, type)
2068 tree valist, type;
2070 rtx addr, result;
2071 tree promoted_type, want_va_type, have_va_type;
2073 /* Verify that valist is of the proper type. */
2075 want_va_type = va_list_type_node;
2076 have_va_type = TREE_TYPE (valist);
2077 if (TREE_CODE (want_va_type) == ARRAY_TYPE)
2079 /* If va_list is an array type, the argument may have decayed
2080 to a pointer type, e.g. by being passed to another function.
2081 In that case, unwrap both types so that we can compare the
2082 underlying records. */
2083 if (TREE_CODE (have_va_type) == ARRAY_TYPE
2084 || TREE_CODE (have_va_type) == POINTER_TYPE)
2086 want_va_type = TREE_TYPE (want_va_type);
2087 have_va_type = TREE_TYPE (have_va_type);
2090 if (TYPE_MAIN_VARIANT (want_va_type) != TYPE_MAIN_VARIANT (have_va_type))
2092 error ("first argument to `va_arg' not of type `va_list'");
2093 addr = const0_rtx;
2096 /* Generate a diagnostic for requesting data of a type that cannot
2097 be passed through `...' due to type promotion at the call site. */
2098 else if ((promoted_type = (*lang_type_promotes_to) (type)) != NULL_TREE)
2100 const char *name = "<anonymous type>", *pname = 0;
2101 static int gave_help;
2103 if (TYPE_NAME (type))
2105 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2106 name = IDENTIFIER_POINTER (TYPE_NAME (type));
2107 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2108 && DECL_NAME (TYPE_NAME (type)))
2109 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
2111 if (TYPE_NAME (promoted_type))
2113 if (TREE_CODE (TYPE_NAME (promoted_type)) == IDENTIFIER_NODE)
2114 pname = IDENTIFIER_POINTER (TYPE_NAME (promoted_type));
2115 else if (TREE_CODE (TYPE_NAME (promoted_type)) == TYPE_DECL
2116 && DECL_NAME (TYPE_NAME (promoted_type)))
2117 pname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (promoted_type)));
2120 error ("`%s' is promoted to `%s' when passed through `...'", name, pname);
2121 if (! gave_help)
2123 gave_help = 1;
2124 error ("(so you should pass `%s' not `%s' to `va_arg')", pname, name);
2127 addr = const0_rtx;
2129 else
2131 /* Make it easier for the backends by protecting the valist argument
2132 from multiple evaluations. */
2133 valist = stabilize_va_list (valist, 0);
2135 #ifdef EXPAND_BUILTIN_VA_ARG
2136 addr = EXPAND_BUILTIN_VA_ARG (valist, type);
2137 #else
2138 addr = std_expand_builtin_va_arg (valist, type);
2139 #endif
2142 result = gen_rtx_MEM (TYPE_MODE (type), addr);
2143 MEM_ALIAS_SET (result) = get_varargs_alias_set ();
2145 return result;
2148 /* Expand ARGLIST, from a call to __builtin_va_end. */
2149 static rtx
2150 expand_builtin_va_end (arglist)
2151 tree arglist;
2153 tree valist = TREE_VALUE (arglist);
2155 #ifdef EXPAND_BUILTIN_VA_END
2156 valist = stabilize_va_list (valist, 0);
2157 EXPAND_BUILTIN_VA_END(arglist);
2158 #else
2159 /* Evaluate for side effects, if needed. I hate macros that don't
2160 do that. */
2161 if (TREE_SIDE_EFFECTS (valist))
2162 expand_expr (valist, const0_rtx, VOIDmode, EXPAND_NORMAL);
2163 #endif
2165 return const0_rtx;
2168 /* Expand ARGLIST, from a call to __builtin_va_copy. We do this as a
2169 builtin rather than just as an assignment in stdarg.h because of the
2170 nastiness of array-type va_list types. */
2171 static rtx
2172 expand_builtin_va_copy (arglist)
2173 tree arglist;
2175 tree dst, src, t;
2177 dst = TREE_VALUE (arglist);
2178 src = TREE_VALUE (TREE_CHAIN (arglist));
2180 dst = stabilize_va_list (dst, 1);
2181 src = stabilize_va_list (src, 0);
2183 if (TREE_CODE (va_list_type_node) != ARRAY_TYPE)
2185 t = build (MODIFY_EXPR, va_list_type_node, dst, src);
2186 TREE_SIDE_EFFECTS (t) = 1;
2187 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2189 else
2191 rtx dstb, srcb, size;
2193 /* Evaluate to pointers. */
2194 dstb = expand_expr (dst, NULL_RTX, Pmode, EXPAND_NORMAL);
2195 srcb = expand_expr (src, NULL_RTX, Pmode, EXPAND_NORMAL);
2196 size = expand_expr (TYPE_SIZE_UNIT (va_list_type_node), NULL_RTX,
2197 VOIDmode, EXPAND_NORMAL);
2199 /* "Dereference" to BLKmode memories. */
2200 dstb = gen_rtx_MEM (BLKmode, dstb);
2201 MEM_ALIAS_SET (dstb) = get_alias_set (TREE_TYPE (TREE_TYPE (dst)));
2202 srcb = gen_rtx_MEM (BLKmode, srcb);
2203 MEM_ALIAS_SET (srcb) = get_alias_set (TREE_TYPE (TREE_TYPE (src)));
2205 /* Copy. */
2206 emit_block_move (dstb, srcb, size, TYPE_ALIGN (va_list_type_node));
2209 return const0_rtx;
2212 /* Expand a call to one of the builtin functions __builtin_frame_address or
2213 __builtin_return_address. */
2214 static rtx
2215 expand_builtin_frame_address (exp)
2216 tree exp;
2218 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2219 tree arglist = TREE_OPERAND (exp, 1);
2221 /* The argument must be a nonnegative integer constant.
2222 It counts the number of frames to scan up the stack.
2223 The value is the return address saved in that frame. */
2224 if (arglist == 0)
2225 /* Warning about missing arg was already issued. */
2226 return const0_rtx;
2227 else if (TREE_CODE (TREE_VALUE (arglist)) != INTEGER_CST
2228 || tree_int_cst_sgn (TREE_VALUE (arglist)) < 0)
2230 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
2231 error ("invalid arg to `__builtin_frame_address'");
2232 else
2233 error ("invalid arg to `__builtin_return_address'");
2234 return const0_rtx;
2236 else
2238 rtx tem = expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl),
2239 TREE_INT_CST_LOW (TREE_VALUE (arglist)),
2240 hard_frame_pointer_rtx);
2242 /* Some ports cannot access arbitrary stack frames. */
2243 if (tem == NULL)
2245 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
2246 warning ("unsupported arg to `__builtin_frame_address'");
2247 else
2248 warning ("unsupported arg to `__builtin_return_address'");
2249 return const0_rtx;
2252 /* For __builtin_frame_address, return what we've got. */
2253 if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
2254 return tem;
2256 if (GET_CODE (tem) != REG
2257 && ! CONSTANT_P (tem))
2258 tem = copy_to_mode_reg (Pmode, tem);
2259 return tem;
2263 /* Expand a call to the alloca builtin, with arguments ARGLIST. Return 0 if
2264 we failed and the caller should emit a normal call, otherwise try to get
2265 the result in TARGET, if convenient. */
2266 static rtx
2267 expand_builtin_alloca (arglist, target)
2268 tree arglist;
2269 rtx target;
2271 rtx op0;
2273 if (arglist == 0
2274 /* Arg could be non-integer if user redeclared this fcn wrong. */
2275 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
2276 return 0;
2278 /* Compute the argument. */
2279 op0 = expand_expr (TREE_VALUE (arglist), NULL_RTX, VOIDmode, 0);
2281 /* Allocate the desired space. */
2282 return allocate_dynamic_stack_space (op0, target, BITS_PER_UNIT);
2285 /* Expand a call to the ffs builtin. The arguments are in ARGLIST.
2286 Return 0 if a normal call should be emitted rather than expanding the
2287 function in-line. If convenient, the result should be placed in TARGET.
2288 SUBTARGET may be used as the target for computing one of EXP's operands. */
2289 static rtx
2290 expand_builtin_ffs (arglist, target, subtarget)
2291 tree arglist;
2292 rtx target, subtarget;
2294 rtx op0;
2295 if (arglist == 0
2296 /* Arg could be non-integer if user redeclared this fcn wrong. */
2297 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
2298 return 0;
2300 /* Compute the argument. */
2301 op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
2302 /* Compute ffs, into TARGET if possible.
2303 Set TARGET to wherever the result comes back. */
2304 target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
2305 ffs_optab, op0, target, 1);
2306 if (target == 0)
2307 abort ();
2308 return target;
2311 /* Expand a call to __builtin_expect. We return our argument and
2312 emit a NOTE_INSN_EXPECTED_VALUE note. */
2314 static rtx
2315 expand_builtin_expect (arglist, target)
2316 tree arglist;
2317 rtx target;
2319 tree exp, c;
2320 rtx note, rtx_c;
2322 if (arglist == NULL_TREE
2323 || TREE_CHAIN (arglist) == NULL_TREE)
2324 return const0_rtx;
2325 exp = TREE_VALUE (arglist);
2326 c = TREE_VALUE (TREE_CHAIN (arglist));
2328 if (TREE_CODE (c) != INTEGER_CST)
2330 error ("second arg to `__builtin_expect' must be a constant");
2331 c = integer_zero_node;
2334 target = expand_expr (exp, target, VOIDmode, EXPAND_NORMAL);
2336 /* Don't bother with expected value notes for integral constants. */
2337 if (GET_CODE (target) != CONST_INT)
2339 /* We do need to force this into a register so that we can be
2340 moderately sure to be able to correctly interpret the branch
2341 condition later. */
2342 target = force_reg (GET_MODE (target), target);
2344 rtx_c = expand_expr (c, NULL_RTX, GET_MODE (target), EXPAND_NORMAL);
2346 note = emit_note (NULL, NOTE_INSN_EXPECTED_VALUE);
2347 NOTE_EXPECTED_VALUE (note) = gen_rtx_EQ (VOIDmode, target, rtx_c);
2350 return target;
2353 /* Expand an expression EXP that calls a built-in function,
2354 with result going to TARGET if that's convenient
2355 (and in mode MODE if that's convenient).
2356 SUBTARGET may be used as the target for computing one of EXP's operands.
2357 IGNORE is nonzero if the value is to be ignored. */
2360 expand_builtin (exp, target, subtarget, mode, ignore)
2361 tree exp;
2362 rtx target;
2363 rtx subtarget;
2364 enum machine_mode mode;
2365 int ignore;
2367 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2368 tree arglist = TREE_OPERAND (exp, 1);
2369 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
2371 #ifdef MD_EXPAND_BUILTIN
2372 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
2373 return MD_EXPAND_BUILTIN (exp, target, subtarget, mode, ignore);
2374 #endif
2376 /* When not optimizing, generate calls to library functions for a certain
2377 set of builtins. */
2378 if (! optimize && ! CALLED_AS_BUILT_IN (fndecl)
2379 && (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
2380 || fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET
2381 || fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
2382 || fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
2383 || fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY
2384 || fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_FFS))
2385 return expand_call (exp, target, ignore);
2387 switch (fcode)
2389 case BUILT_IN_ABS:
2390 case BUILT_IN_LABS:
2391 case BUILT_IN_FABS:
2392 /* build_function_call changes these into ABS_EXPR. */
2393 abort ();
2395 case BUILT_IN_SIN:
2396 case BUILT_IN_COS:
2397 /* Treat these like sqrt, but only if the user asks for them. */
2398 if (! flag_fast_math)
2399 break;
2400 case BUILT_IN_FSQRT:
2401 target = expand_builtin_mathfn (exp, target, subtarget);
2402 if (target)
2403 return target;
2404 break;
2406 case BUILT_IN_FMOD:
2407 break;
2409 case BUILT_IN_APPLY_ARGS:
2410 return expand_builtin_apply_args ();
2412 /* __builtin_apply (FUNCTION, ARGUMENTS, ARGSIZE) invokes
2413 FUNCTION with a copy of the parameters described by
2414 ARGUMENTS, and ARGSIZE. It returns a block of memory
2415 allocated on the stack into which is stored all the registers
2416 that might possibly be used for returning the result of a
2417 function. ARGUMENTS is the value returned by
2418 __builtin_apply_args. ARGSIZE is the number of bytes of
2419 arguments that must be copied. ??? How should this value be
2420 computed? We'll also need a safe worst case value for varargs
2421 functions. */
2422 case BUILT_IN_APPLY:
2423 if (arglist == 0
2424 /* Arg could be non-pointer if user redeclared this fcn wrong. */
2425 || ! POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (arglist)))
2426 || TREE_CHAIN (arglist) == 0
2427 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
2428 || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
2429 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
2430 return const0_rtx;
2431 else
2433 int i;
2434 tree t;
2435 rtx ops[3];
2437 for (t = arglist, i = 0; t; t = TREE_CHAIN (t), i++)
2438 ops[i] = expand_expr (TREE_VALUE (t), NULL_RTX, VOIDmode, 0);
2440 return expand_builtin_apply (ops[0], ops[1], ops[2]);
2443 /* __builtin_return (RESULT) causes the function to return the
2444 value described by RESULT. RESULT is address of the block of
2445 memory returned by __builtin_apply. */
2446 case BUILT_IN_RETURN:
2447 if (arglist
2448 /* Arg could be non-pointer if user redeclared this fcn wrong. */
2449 && TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == POINTER_TYPE)
2450 expand_builtin_return (expand_expr (TREE_VALUE (arglist),
2451 NULL_RTX, VOIDmode, 0));
2452 return const0_rtx;
2454 case BUILT_IN_SAVEREGS:
2455 return expand_builtin_saveregs ();
2457 case BUILT_IN_ARGS_INFO:
2458 return expand_builtin_args_info (exp);
2460 /* Return the address of the first anonymous stack arg. */
2461 case BUILT_IN_NEXT_ARG:
2462 return expand_builtin_next_arg (arglist);
2464 case BUILT_IN_CLASSIFY_TYPE:
2465 return expand_builtin_classify_type (arglist);
2467 case BUILT_IN_CONSTANT_P:
2468 return expand_builtin_constant_p (exp);
2470 case BUILT_IN_FRAME_ADDRESS:
2471 case BUILT_IN_RETURN_ADDRESS:
2472 return expand_builtin_frame_address (exp);
2474 /* Returns the address of the area where the structure is returned.
2475 0 otherwise. */
2476 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
2477 if (arglist != 0
2478 || ! AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))
2479 || GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) != MEM)
2480 return const0_rtx;
2481 else
2482 return XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
2484 case BUILT_IN_ALLOCA:
2485 target = expand_builtin_alloca (arglist, target);
2486 if (target)
2487 return target;
2488 break;
2490 case BUILT_IN_FFS:
2491 target = expand_builtin_ffs (arglist, target, subtarget);
2492 if (target)
2493 return target;
2494 break;
2496 case BUILT_IN_STRLEN:
2497 target = expand_builtin_strlen (exp, target, mode);
2498 if (target)
2499 return target;
2500 break;
2502 case BUILT_IN_STRCPY:
2503 target = expand_builtin_strcpy (exp);
2504 if (target)
2505 return target;
2506 break;
2508 case BUILT_IN_MEMCPY:
2509 target = expand_builtin_memcpy (arglist);
2510 if (target)
2511 return target;
2512 break;
2514 case BUILT_IN_MEMSET:
2515 target = expand_builtin_memset (exp);
2516 if (target)
2517 return target;
2518 break;
2520 case BUILT_IN_BZERO:
2521 target = expand_builtin_bzero (exp);
2522 if (target)
2523 return target;
2524 break;
2526 /* These comparison functions need an instruction that returns an actual
2527 index. An ordinary compare that just sets the condition codes
2528 is not enough. */
2529 #ifdef HAVE_cmpstrsi
2530 case BUILT_IN_STRCMP:
2531 target = expand_builtin_strcmp (exp, target);
2532 if (target)
2533 return target;
2534 break;
2536 case BUILT_IN_BCMP:
2537 case BUILT_IN_MEMCMP:
2538 target = expand_builtin_memcmp (exp, arglist, target);
2539 if (target)
2540 return target;
2541 break;
2542 #else
2543 case BUILT_IN_STRCMP:
2544 case BUILT_IN_BCMP:
2545 case BUILT_IN_MEMCMP:
2546 break;
2547 #endif
2549 case BUILT_IN_SETJMP:
2550 if (arglist == 0
2551 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
2552 break;
2553 else
2555 rtx buf_addr = expand_expr (TREE_VALUE (arglist), subtarget,
2556 VOIDmode, 0);
2557 rtx lab = gen_label_rtx ();
2558 rtx ret = expand_builtin_setjmp (buf_addr, target, lab, lab);
2559 emit_label (lab);
2560 return ret;
2563 /* __builtin_longjmp is passed a pointer to an array of five words.
2564 It's similar to the C library longjmp function but works with
2565 __builtin_setjmp above. */
2566 case BUILT_IN_LONGJMP:
2567 if (arglist == 0 || TREE_CHAIN (arglist) == 0
2568 || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
2569 break;
2570 else
2572 rtx buf_addr = expand_expr (TREE_VALUE (arglist), subtarget,
2573 VOIDmode, 0);
2574 rtx value = expand_expr (TREE_VALUE (TREE_CHAIN (arglist)),
2575 NULL_RTX, VOIDmode, 0);
2577 if (value != const1_rtx)
2579 error ("__builtin_longjmp second argument must be 1");
2580 return const0_rtx;
2583 expand_builtin_longjmp (buf_addr, value);
2584 return const0_rtx;
2587 case BUILT_IN_TRAP:
2588 #ifdef HAVE_trap
2589 if (HAVE_trap)
2590 emit_insn (gen_trap ());
2591 else
2592 #endif
2593 error ("__builtin_trap not supported by this target");
2594 emit_barrier ();
2595 return const0_rtx;
2597 /* Various hooks for the DWARF 2 __throw routine. */
2598 case BUILT_IN_UNWIND_INIT:
2599 expand_builtin_unwind_init ();
2600 return const0_rtx;
2601 case BUILT_IN_DWARF_CFA:
2602 return virtual_cfa_rtx;
2603 #ifdef DWARF2_UNWIND_INFO
2604 case BUILT_IN_DWARF_FP_REGNUM:
2605 return expand_builtin_dwarf_fp_regnum ();
2606 case BUILT_IN_INIT_DWARF_REG_SIZES:
2607 expand_builtin_init_dwarf_reg_sizes (TREE_VALUE (arglist));
2608 return const0_rtx;
2609 #endif
2610 case BUILT_IN_FROB_RETURN_ADDR:
2611 return expand_builtin_frob_return_addr (TREE_VALUE (arglist));
2612 case BUILT_IN_EXTRACT_RETURN_ADDR:
2613 return expand_builtin_extract_return_addr (TREE_VALUE (arglist));
2614 case BUILT_IN_EH_RETURN:
2615 expand_builtin_eh_return (TREE_VALUE (arglist),
2616 TREE_VALUE (TREE_CHAIN (arglist)),
2617 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))));
2618 return const0_rtx;
2619 case BUILT_IN_VARARGS_START:
2620 return expand_builtin_va_start (0, arglist);
2621 case BUILT_IN_STDARG_START:
2622 return expand_builtin_va_start (1, arglist);
2623 case BUILT_IN_VA_END:
2624 return expand_builtin_va_end (arglist);
2625 case BUILT_IN_VA_COPY:
2626 return expand_builtin_va_copy (arglist);
2627 case BUILT_IN_EXPECT:
2628 return expand_builtin_expect (arglist, target);
2630 default: /* just do library call, if unknown builtin */
2631 error ("built-in function `%s' not currently supported",
2632 IDENTIFIER_POINTER (DECL_NAME (fndecl)));
2635 /* The switch statement above can drop through to cause the function
2636 to be called normally. */
2637 return expand_call (exp, target, ignore);