/* Expand builtin functions.
- Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU CC.
#include "typeclass.h"
#include "defaults.h"
#include "toplev.h"
+#include "tm_p.h"
#define CALLED_AS_BUILT_IN(NODE) \
(!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
-#define CEIL(x,y) (((x) + (y) - 1) / (y))
-
/* Register mappings for target machines without register windows. */
#ifndef INCOMING_REGNO
#define INCOMING_REGNO(OUT) (OUT)
#define OUTGOING_REGNO(IN) (IN)
#endif
-/* Nonzero means __builtin_saveregs has already been done in this function.
- The value is the pseudoreg containing the value __builtin_saveregs
- returned. */
-rtx saveregs_value;
-
-/* Similarly for __builtin_apply_args. */
-rtx apply_args_value;
-
-static int get_pointer_alignment PROTO((tree, unsigned));
-static tree c_strlen PROTO((tree));
-static rtx get_memory_rtx PROTO((tree));
-static int apply_args_size PROTO((void));
-static int apply_result_size PROTO((void));
-static rtx result_vector PROTO((int, rtx));
-static rtx expand_builtin_apply_args PROTO((void));
-static rtx expand_builtin_apply_args_1 PROTO((void));
-static rtx expand_builtin_apply PROTO((rtx, rtx, rtx));
-static void expand_builtin_return PROTO((rtx));
-static rtx expand_builtin_classify_type PROTO((tree));
-static rtx expand_builtin_mathfn PROTO((tree, rtx, rtx));
-static rtx expand_builtin_constant_p PROTO((tree));
-static rtx expand_builtin_args_info PROTO((tree));
-static rtx expand_builtin_next_arg PROTO((tree));
-static rtx expand_builtin_va_start PROTO((int, tree));
-static rtx expand_builtin_va_end PROTO((tree));
-static rtx expand_builtin_va_copy PROTO((tree));
-static rtx expand_builtin_memcmp PROTO((tree, tree, rtx));
-static rtx expand_builtin_strcmp PROTO((tree, rtx));
-static rtx expand_builtin_memcpy PROTO((tree));
-static rtx expand_builtin_strcpy PROTO((tree));
-static rtx expand_builtin_memset PROTO((tree));
-static rtx expand_builtin_strlen PROTO((tree, rtx, enum machine_mode));
-static rtx expand_builtin_alloca PROTO((tree, rtx));
-static rtx expand_builtin_ffs PROTO((tree, rtx, rtx));
-static rtx expand_builtin_frame_address PROTO((tree));
+#ifndef PAD_VARARGS_DOWN
+#define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN
+#endif
+
+/* Define the names of the builtin function types and codes. */
+const char *const built_in_class_names[4]
+ = {"NOT_BUILT_IN", "BUILT_IN_FRONTEND", "BUILT_IN_MD", "BUILT_IN_NORMAL"};
+
+#define DEF_BUILTIN(x) STRINGIFY(x),
+const char *const built_in_names[(int) END_BUILTINS] =
+{
+#include "builtins.def"
+};
+#undef DEF_BUILTIN
+
+tree (*lang_type_promotes_to) PARAMS ((tree));
+
+static int get_pointer_alignment PARAMS ((tree, unsigned));
+static tree c_strlen PARAMS ((tree));
+static rtx get_memory_rtx PARAMS ((tree));
+static int apply_args_size PARAMS ((void));
+static int apply_result_size PARAMS ((void));
+#if defined (HAVE_untyped_call) || defined (HAVE_untyped_return)
+static rtx result_vector PARAMS ((int, rtx));
+#endif
+static rtx expand_builtin_apply_args PARAMS ((void));
+static rtx expand_builtin_apply_args_1 PARAMS ((void));
+static rtx expand_builtin_apply PARAMS ((rtx, rtx, rtx));
+static void expand_builtin_return PARAMS ((rtx));
+static rtx expand_builtin_classify_type PARAMS ((tree));
+static rtx expand_builtin_mathfn PARAMS ((tree, rtx, rtx));
+static rtx expand_builtin_constant_p PARAMS ((tree));
+static rtx expand_builtin_args_info PARAMS ((tree));
+static rtx expand_builtin_next_arg PARAMS ((tree));
+static rtx expand_builtin_va_start PARAMS ((int, tree));
+static rtx expand_builtin_va_end PARAMS ((tree));
+static rtx expand_builtin_va_copy PARAMS ((tree));
+#ifdef HAVE_cmpstrsi
+static rtx expand_builtin_memcmp PARAMS ((tree, tree, rtx));
+static rtx expand_builtin_strcmp PARAMS ((tree, rtx));
+#endif
+static rtx expand_builtin_memcpy PARAMS ((tree));
+static rtx expand_builtin_strcpy PARAMS ((tree));
+static rtx expand_builtin_memset PARAMS ((tree));
+static rtx expand_builtin_bzero PARAMS ((tree));
+static rtx expand_builtin_strlen PARAMS ((tree, rtx,
+ enum machine_mode));
+static rtx expand_builtin_alloca PARAMS ((tree, rtx));
+static rtx expand_builtin_ffs PARAMS ((tree, rtx, rtx));
+static rtx expand_builtin_frame_address PARAMS ((tree));
+static tree stabilize_va_list PARAMS ((tree, int));
+static rtx expand_builtin_expect PARAMS ((tree, rtx));
/* Return the alignment in bits of EXP, a pointer valued expression.
But don't return more than MAX_ALIGN no matter what.
exp = TREE_OPERAND (exp, 0);
if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
return align;
+
inner = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
align = MIN (inner, max_align);
break;
/* If sum of pointer + int, restrict our maximum alignment to that
imposed by the integer. If not, we can't do any better than
ALIGN. */
- if (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST)
+ if (! host_integerp (TREE_OPERAND (exp, 1), 1))
return align;
- while (((TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)) * BITS_PER_UNIT)
+ while (((tree_low_cst (TREE_OPERAND (exp, 1), 1) * BITS_PER_UNIT)
& (max_align - 1))
!= 0)
max_align >>= 1;
exp = TREE_OPERAND (exp, 0);
if (TREE_CODE (exp) == FUNCTION_DECL)
align = FUNCTION_BOUNDARY;
- else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
+ else if (DECL_P (exp))
align = DECL_ALIGN (exp);
#ifdef CONSTANT_ALIGNMENT
else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c')
way, because it could contain a zero byte in the middle.
TREE_STRING_LENGTH is the size of the character array, not the string.
+ The value returned is of type `ssizetype'.
+
Unfortunately, string_constant can't access the values of const char
arrays with initializers, so neither can we do so here. */
src = string_constant (src, &offset_node);
if (src == 0)
return 0;
+
max = TREE_STRING_LENGTH (src);
ptr = TREE_STRING_POINTER (src);
+
if (offset_node && TREE_CODE (offset_node) != INTEGER_CST)
{
/* If the string has an internal zero byte (e.g., "foo\0bar"), we can't
compute the offset to the following null if we don't know where to
start searching for it. */
int i;
+
for (i = 0; i < max; i++)
if (ptr[i] == 0)
return 0;
+
/* We don't know the starting offset, but we do know that the string
has no internal zero bytes. We can assume that the offset falls
within the bounds of the string; otherwise, the programmer deserves
what he gets. Subtract the offset from the length of the string,
- and return that. */
- /* This would perhaps not be valid if we were dealing with named
- arrays in addition to literal string constants. */
- return size_binop (MINUS_EXPR, size_int (max), offset_node);
+ and return that. This would perhaps not be valid if we were dealing
+ with named arrays in addition to literal string constants. */
+
+ return size_diffop (size_int (max), offset_node);
}
/* We have a known offset into the string. Start searching there for
return 0;
offset = TREE_INT_CST_LOW (offset_node);
}
+
/* If the offset is known to be out of bounds, warn, and call strlen at
runtime. */
if (offset < 0 || offset > max)
warning ("offset outside bounds of constant string");
return 0;
}
+
/* Use strlen to search for the first zero byte. Since any strings
constructed with build_string will have nulls appended, we win even
if we get handed something like (char[4])"abcd".
Since OFFSET is our starting index into the string, no further
calculation is needed. */
- return size_int (strlen (ptr + offset));
+ return ssize_int (strlen (ptr + offset));
}
/* Given TEM, a pointer to a stack frame, follow the dynamic chain COUNT
times to get the address of either a higher stack frame, or a return
address located within it (depending on FNDECL_CODE). */
+
rtx
expand_builtin_return_addr (fndecl_code, count, tem)
enum built_in_function fndecl_code;
buf_addr = convert_memory_address (Pmode, buf_addr);
#endif
- buf_addr = force_reg (Pmode, buf_addr);
+ buf_addr = force_reg (Pmode, force_operand (buf_addr, NULL_RTX));
if (target == 0 || GET_CODE (target) != REG
|| REGNO (target) < FIRST_PSEUDO_REGISTER)
calls may traverse the arc back to this label. */
current_function_has_nonlocal_label = 1;
- nonlocal_goto_handler_labels =
- gen_rtx_EXPR_LIST (VOIDmode, lab1, nonlocal_goto_handler_labels);
+ nonlocal_goto_handler_labels
+ = gen_rtx_EXPR_LIST (VOIDmode, lab1, nonlocal_goto_handler_labels);
/* Clobber the FP when we get here, so we have to make sure it's
marked as used by this function. */
tem = gen_rtx_REG (mode, INCOMING_REGNO (regno));
-#ifdef STACK_REGS
- /* For reg-stack.c's stack register household.
- Compare with a similar piece of code in function.c. */
-
- emit_insn (gen_rtx_USE (mode, tem));
-#endif
-
emit_move_insn (change_address (registers, mode,
plus_constant (XEXP (registers, 0),
size)),
/* Create a block where the return registers can be saved. */
result = assign_stack_local (BLKmode, apply_result_size (), -1);
- /* ??? The argsize value should be adjusted here. */
-
/* Fetch the arg pointer from the ARGUMENTS block. */
incoming_args = gen_reg_rtx (Pmode);
emit_move_insn (incoming_args,
haven't figured out how the calling convention macros effect this,
but it's likely that the source and/or destination addresses in
the block copy will need updating in machine specific ways. */
- dest = allocate_dynamic_stack_space (argsize, 0, 0);
+ dest = allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
emit_block_move (gen_rtx_MEM (BLKmode, dest),
gen_rtx_MEM (BLKmode, incoming_args),
- argsize,
- PARM_BOUNDARY / BITS_PER_UNIT);
+ argsize, PARM_BOUNDARY);
/* Refer to the argument block. */
apply_args_size ();
&& TREE_CODE (TREE_VALUE (arglist)) != PARM_DECL)
{
exp = copy_node (exp);
- arglist = copy_node (arglist);
TREE_OPERAND (exp, 1) = arglist;
+ /* Wrap the computation of the argument in a SAVE_EXPR. That
+ way, if we need to expand the argument again (as in the
+ flag_errno_math case below where we cannot directly set
+ errno), we will not perform side-effects more than once.
+ Note that here we're mutating the original EXP as well as the
+ copy; that's the right thing to do in case the original EXP
+ is expanded later. */
TREE_VALUE (arglist) = save_expr (TREE_VALUE (arglist));
+ arglist = copy_node (arglist);
}
op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
return 0;
else
{
+ rtx pat;
tree src = TREE_VALUE (arglist);
tree len = c_strlen (src);
int align
= get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
- rtx result, src_rtx, char_rtx;
+ rtx result, src_reg, char_rtx, before_strlen;
enum machine_mode insn_mode = value_mode, char_mode;
- enum insn_code icode;
+ enum insn_code icode = CODE_FOR_nothing;
/* If the length is known, just return it. */
if (len != 0)
if (align == 0)
return 0;
- /* Call a function if we can't compute strlen in the right mode. */
-
+ /* Bail out if we can't compute strlen in the right mode. */
while (insn_mode != VOIDmode)
{
icode = strlen_optab->handlers[(int) insn_mode].insn_code;
if (icode != CODE_FOR_nothing)
- return 0;
+ break;
insn_mode = GET_MODE_WIDER_MODE (insn_mode);
}
&& REGNO (result) >= FIRST_PSEUDO_REGISTER))
result = gen_reg_rtx (insn_mode);
- /* Make sure the operands are acceptable to the predicates. */
+ /* Make a place to hold the source address. We will not expand
+ the actual source until we are sure that the expansion will
+ not fail -- there are trees that cannot be expanded twice. */
+ src_reg = gen_reg_rtx (Pmode);
- if (! (*insn_operand_predicate[(int)icode][0]) (result, insn_mode))
- result = gen_reg_rtx (insn_mode);
- src_rtx = memory_address (BLKmode,
- expand_expr (src, NULL_RTX, ptr_mode,
- EXPAND_NORMAL));
-
- if (! (*insn_operand_predicate[(int)icode][1]) (src_rtx, Pmode))
- src_rtx = copy_to_mode_reg (Pmode, src_rtx);
+ /* Mark the beginning of the strlen sequence so we can emit the
+ source operand later. */
+ before_strlen = get_last_insn();
/* Check the string is readable and has an end. */
if (current_function_check_memory_usage)
emit_library_call (chkr_check_str_libfunc, 1, VOIDmode, 2,
- src_rtx, Pmode,
+ src_reg, Pmode,
GEN_INT (MEMORY_USE_RO),
TYPE_MODE (integer_type_node));
char_rtx = const0_rtx;
- char_mode = insn_operand_mode[(int)icode][2];
- if (! (*insn_operand_predicate[(int)icode][2]) (char_rtx, char_mode))
+ char_mode = insn_data[(int)icode].operand[2].mode;
+ if (! (*insn_data[(int)icode].operand[2].predicate) (char_rtx, char_mode))
char_rtx = copy_to_mode_reg (char_mode, char_rtx);
- emit_insn (GEN_FCN (icode) (result,
- gen_rtx_MEM (BLKmode, src_rtx),
- char_rtx, GEN_INT (align)));
+ pat = GEN_FCN (icode) (result, gen_rtx_MEM (BLKmode, src_reg),
+ char_rtx, GEN_INT (align));
+ if (! pat)
+ return 0;
+ emit_insn (pat);
+
+ /* Now that we are assured of success, expand the source. */
+ start_sequence ();
+ pat = memory_address (BLKmode,
+ expand_expr (src, src_reg, ptr_mode, EXPAND_SUM));
+ if (pat != src_reg)
+ emit_move_insn (src_reg, pat);
+ pat = gen_sequence ();
+ end_sequence ();
+
+ if (before_strlen)
+ emit_insn_after (pat, before_strlen);
+ else
+ emit_insn_before (pat, get_insns ());
/* Return the value in the proper mode for this function. */
if (GET_MODE (result) == value_mode)
- return result;
+ target = result;
else if (target != 0)
- {
- convert_move (target, result, 0);
- return target;
- }
+ convert_move (target, result, 0);
else
- return convert_to_mode (value_mode, result, 0);
+ target = convert_to_mode (value_mode, result, 0);
+
+ return target;
}
}
tree src = TREE_VALUE (TREE_CHAIN (arglist));
tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
- int src_align
- = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
- int dest_align
- = get_pointer_alignment (dest, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
+ int src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT);
+ int dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
rtx dest_mem, src_mem, dest_addr, len_rtx;
/* If either SRC or DEST is not a pointer type, don't do
/* Expand expression EXP, which is a call to the strcpy builtin. Return 0
if we failed the caller should emit a normal call. */
+
static rtx
expand_builtin_strcpy (exp)
tree exp;
/* Arg could be non-pointer if user redeclared this fcn wrong. */
|| TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
|| TREE_CHAIN (arglist) == 0
- || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
+ || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
+ != POINTER_TYPE))
return 0;
else
{
if (len == 0)
return 0;
- len = size_binop (PLUS_EXPR, len, integer_one_node);
-
+ len = size_binop (PLUS_EXPR, len, ssize_int (1));
chainon (arglist, build_tree_list (NULL_TREE, len));
}
+
result = expand_builtin_memcpy (arglist);
+
if (! result)
TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
return result;
/* Expand expression EXP, which is a call to the memset builtin. Return 0
if we failed the caller should emit a normal call. */
+
static rtx
expand_builtin_memset (exp)
tree exp;
tree val = TREE_VALUE (TREE_CHAIN (arglist));
tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
- int dest_align
- = get_pointer_alignment (dest, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
+ int dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
rtx dest_mem, dest_addr, len_rtx;
/* If DEST is not a pointer type, don't do this
if (expand_expr (val, NULL_RTX, VOIDmode, 0) != const0_rtx)
return 0;
- /* If LEN does not expand to a constant, don't do this
- operation in-line. */
len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
- if (GET_CODE (len_rtx) != CONST_INT)
- return 0;
dest_mem = get_memory_rtx (dest);
}
}
+/* Expand expression EXP, which is a call to the bzero builtin. Return 0
+ if we failed the caller should emit a normal call. */
+static rtx
+expand_builtin_bzero (exp)
+ tree exp;
+{
+ tree arglist = TREE_OPERAND (exp, 1);
+ tree dest, size, newarglist;
+ rtx result;
+
+ if (arglist == 0
+ /* Arg could be non-pointer if user redeclared this fcn wrong. */
+ || TREE_CODE (TREE_TYPE (dest = TREE_VALUE (arglist))) != POINTER_TYPE
+ || TREE_CHAIN (arglist) == 0
+ || (TREE_CODE (TREE_TYPE (size = TREE_VALUE (TREE_CHAIN (arglist))))
+ != INTEGER_TYPE))
+ return NULL_RTX;
+
+ /* New argument list transforming bzero(ptr x, int y) to
+ memset(ptr x, int 0, size_t y). */
+
+ newarglist = build_tree_list (NULL_TREE, convert (sizetype, size));
+ newarglist = tree_cons (NULL_TREE, integer_zero_node, newarglist);
+ newarglist = tree_cons (NULL_TREE, dest, newarglist);
+
+ TREE_OPERAND (exp, 1) = newarglist;
+ result = expand_builtin_memset(exp);
+
+ /* Always restore the original arguments. */
+ TREE_OPERAND (exp, 1) = arglist;
+
+ return result;
+}
+
#ifdef HAVE_cmpstrsi
/* Expand expression EXP, which is a call to the memcmp or the strcmp builtin.
ARGLIST is the argument list for this call. Return 0 if we failed and the
|| TREE_CHAIN (TREE_CHAIN (arglist)) == 0
|| TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
return 0;
- else if (!HAVE_cmpstrsi)
- return 0;
{
enum machine_mode mode;
tree arg1 = TREE_VALUE (arglist);
tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
+ rtx arg1_rtx, arg2_rtx, arg3_rtx;
rtx result;
+ rtx insn;
int arg1_align
= get_pointer_alignment (arg1, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
int arg2_align
= get_pointer_alignment (arg2, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
enum machine_mode insn_mode
- = insn_operand_mode[(int) CODE_FOR_cmpstrsi][0];
+ = insn_data[(int) CODE_FOR_cmpstrsi].operand[0].mode;
/* If we don't have POINTER_TYPE, call the function. */
if (arg1_align == 0 || arg2_align == 0)
&& REGNO (result) >= FIRST_PSEUDO_REGISTER))
result = gen_reg_rtx (insn_mode);
- emit_insn (gen_cmpstrsi (result, get_memory_rtx (arg1),
- get_memory_rtx (arg2),
- expand_expr (len, NULL_RTX, VOIDmode, 0),
- GEN_INT (MIN (arg1_align, arg2_align))));
+ arg1_rtx = get_memory_rtx (arg1);
+ arg2_rtx = get_memory_rtx (arg2);
+ arg3_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
+ if (!HAVE_cmpstrsi)
+ insn = NULL_RTX;
+ else
+ insn = gen_cmpstrsi (result, arg1_rtx, arg2_rtx, arg3_rtx,
+ GEN_INT (MIN (arg1_align, arg2_align)));
+
+ if (insn)
+ emit_insn (insn);
+ else
+ emit_library_call_value (memcmp_libfunc, result, 2,
+ TYPE_MODE (integer_type_node), 3,
+ XEXP (arg1_rtx, 0), Pmode,
+ XEXP (arg2_rtx, 0), Pmode,
+ convert_to_mode (TYPE_MODE (sizetype), arg3_rtx,
+ TREE_UNSIGNED (sizetype)),
+ TYPE_MODE (sizetype));
/* Return the value in the proper mode for this function. */
mode = TYPE_MODE (TREE_TYPE (exp));
/* Expand expression EXP, which is a call to the strcmp builtin. Return 0
if we failed the caller should emit a normal call, otherwise try to get
the result in TARGET, if convenient. */
+
static rtx
expand_builtin_strcmp (exp, target)
tree exp;
/* Arg could be non-pointer if user redeclared this fcn wrong. */
|| TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
|| TREE_CHAIN (arglist) == 0
- || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
+ || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
+ != POINTER_TYPE))
return 0;
- else if (!HAVE_cmpstrsi)
+
+ else if (! HAVE_cmpstrsi)
return 0;
{
tree arg1 = TREE_VALUE (arglist);
tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
- tree len, len2;
+ tree len = c_strlen (arg1);
+ tree len2 = c_strlen (arg2);
rtx result;
- len = c_strlen (arg1);
+
if (len)
- len = size_binop (PLUS_EXPR, integer_one_node, len);
- len2 = c_strlen (arg2);
+ len = size_binop (PLUS_EXPR, ssize_int (1), len);
+
if (len2)
- len2 = size_binop (PLUS_EXPR, integer_one_node, len2);
+ len2 = size_binop (PLUS_EXPR, ssize_int (1), len2);
/* If we don't have a constant length for the first, use the length
of the second, if we know it. We don't require a constant for
two fixed strings, or if the code was machine-generated. We should
add some code to the `memcmp' handler below to deal with such
situations, someday. */
+
if (!len || TREE_CODE (len) != INTEGER_CST)
{
if (len2)
else if (len == 0)
return 0;
}
- else if (len2 && TREE_CODE (len2) == INTEGER_CST)
- {
- if (tree_int_cst_lt (len2, len))
- len = len2;
- }
+ else if (len2 && TREE_CODE (len2) == INTEGER_CST
+ && tree_int_cst_lt (len2, len))
+ len = len2;
chainon (arglist, build_tree_list (NULL_TREE, len));
result = expand_builtin_memcmp (exp, arglist, target);
if (! result)
TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
+
return result;
}
}
/* Expand a call to __builtin_saveregs, generating the result in TARGET,
if that's convenient. */
+
rtx
expand_builtin_saveregs ()
{
#endif
if (sizeof (CUMULATIVE_ARGS) % sizeof (int) != 0)
- fatal ("CUMULATIVE_ARGS type defined badly; see %s, line %d",
- __FILE__, __LINE__);
+ abort ();
if (arglist != 0)
{
from multiple evaluations. */
static tree
-stabilize_va_list (valist, was_ptr)
+stabilize_va_list (valist, needs_lvalue)
tree valist;
- int was_ptr;
+ int needs_lvalue;
{
- int is_array = TREE_CODE (va_list_type_node) == ARRAY_TYPE;
-
- if (was_ptr)
+ if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
{
- /* If stdarg.h took the address of an array-type valist that was passed
- as a parameter, we'll have taken the address of the parameter itself
- rather than the array as we'd intended. Undo this mistake. */
- if (is_array
- && TREE_CODE (valist) == ADDR_EXPR
- && TREE_CODE (TREE_TYPE (TREE_OPERAND (valist, 0))) == POINTER_TYPE)
- {
- valist = TREE_OPERAND (valist, 0);
- if (TREE_SIDE_EFFECTS (valist))
- valist = save_expr (valist);
- }
- else
+ if (TREE_SIDE_EFFECTS (valist))
+ valist = save_expr (valist);
+
+ /* For this case, the backends will be expecting a pointer to
+ TREE_TYPE (va_list_type_node), but it's possible we've
+ actually been given an array (an actual va_list_type_node).
+ So fix it. */
+ if (TREE_CODE (TREE_TYPE (valist)) == ARRAY_TYPE)
{
- if (TREE_SIDE_EFFECTS (valist))
- valist = save_expr (valist);
- valist = fold (build1 (INDIRECT_REF, va_list_type_node, valist));
+ tree p1 = build_pointer_type (TREE_TYPE (va_list_type_node));
+ tree p2 = build_pointer_type (va_list_type_node);
+
+ valist = build1 (ADDR_EXPR, p2, valist);
+ valist = fold (build1 (NOP_EXPR, p1, valist));
}
}
- else if (TREE_SIDE_EFFECTS (valist))
+ else
{
- if (is_array)
- valist = save_expr (valist);
- else
+ tree pt;
+
+ if (! needs_lvalue)
{
- valist = build1 (ADDR_EXPR, build_pointer_type (va_list_type_node),
- valist);
+ if (! TREE_SIDE_EFFECTS (valist))
+ return valist;
+
+ pt = build_pointer_type (va_list_type_node);
+ valist = fold (build1 (ADDR_EXPR, pt, valist));
TREE_SIDE_EFFECTS (valist) = 1;
- valist = save_expr (valist);
- valist = fold (build1 (INDIRECT_REF, va_list_type_node, valist));
}
+
+ if (TREE_SIDE_EFFECTS (valist))
+ valist = save_expr (valist);
+ valist = fold (build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)),
+ valist));
}
return valist;
/* Get AP. */
addr_tree = valist;
- if (BYTES_BIG_ENDIAN)
+ if (PAD_VARARGS_DOWN)
{
/* Small args are padded downward. */
tree valist, type;
{
rtx addr, result;
+ tree promoted_type, want_va_type, have_va_type;
- if (TYPE_MAIN_VARIANT (TREE_TYPE (valist))
- != TYPE_MAIN_VARIANT (va_list_type_node))
+ /* Verify that valist is of the proper type. */
+
+ want_va_type = va_list_type_node;
+ have_va_type = TREE_TYPE (valist);
+ if (TREE_CODE (want_va_type) == ARRAY_TYPE)
{
- error ("first argument to `__builtin_va_arg' not of type `va_list'");
+ /* If va_list is an array type, the argument may have decayed
+ to a pointer type, e.g. by being passed to another function.
+ In that case, unwrap both types so that we can compare the
+ underlying records. */
+ if (TREE_CODE (have_va_type) == ARRAY_TYPE
+ || TREE_CODE (have_va_type) == POINTER_TYPE)
+ {
+ want_va_type = TREE_TYPE (want_va_type);
+ have_va_type = TREE_TYPE (have_va_type);
+ }
+ }
+ if (TYPE_MAIN_VARIANT (want_va_type) != TYPE_MAIN_VARIANT (have_va_type))
+ {
+ error ("first argument to `va_arg' not of type `va_list'");
+ addr = const0_rtx;
+ }
+
+ /* Generate a diagnostic for requesting data of a type that cannot
+ be passed through `...' due to type promotion at the call site. */
+ else if ((promoted_type = (*lang_type_promotes_to) (type)) != NULL_TREE)
+ {
+ const char *name = "<anonymous type>", *pname = 0;
+ static int gave_help;
+
+ if (TYPE_NAME (type))
+ {
+ if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
+ name = IDENTIFIER_POINTER (TYPE_NAME (type));
+ else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
+ && DECL_NAME (TYPE_NAME (type)))
+ name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
+ }
+ if (TYPE_NAME (promoted_type))
+ {
+ if (TREE_CODE (TYPE_NAME (promoted_type)) == IDENTIFIER_NODE)
+ pname = IDENTIFIER_POINTER (TYPE_NAME (promoted_type));
+ else if (TREE_CODE (TYPE_NAME (promoted_type)) == TYPE_DECL
+ && DECL_NAME (TYPE_NAME (promoted_type)))
+ pname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (promoted_type)));
+ }
+
+ error ("`%s' is promoted to `%s' when passed through `...'", name, pname);
+ if (! gave_help)
+ {
+ gave_help = 1;
+ error ("(so you should pass `%s' not `%s' to `va_arg')", pname, name);
+ }
+
addr = const0_rtx;
}
else
}
else
{
- emit_block_move (expand_expr (dst, NULL_RTX, Pmode, EXPAND_NORMAL),
- expand_expr (src, NULL_RTX, Pmode, EXPAND_NORMAL),
- expand_expr (TYPE_SIZE (va_list_type_node), NULL_RTX,
- VOIDmode, EXPAND_NORMAL),
- TYPE_ALIGN (va_list_type_node) / BITS_PER_UNIT);
+ rtx dstb, srcb, size;
+
+ /* Evaluate to pointers. */
+ dstb = expand_expr (dst, NULL_RTX, Pmode, EXPAND_NORMAL);
+ srcb = expand_expr (src, NULL_RTX, Pmode, EXPAND_NORMAL);
+ size = expand_expr (TYPE_SIZE_UNIT (va_list_type_node), NULL_RTX,
+ VOIDmode, EXPAND_NORMAL);
+
+ /* "Dereference" to BLKmode memories. */
+ dstb = gen_rtx_MEM (BLKmode, dstb);
+ MEM_ALIAS_SET (dstb) = get_alias_set (TREE_TYPE (TREE_TYPE (dst)));
+ srcb = gen_rtx_MEM (BLKmode, srcb);
+ MEM_ALIAS_SET (srcb) = get_alias_set (TREE_TYPE (TREE_TYPE (src)));
+
+ /* Copy. */
+ emit_block_move (dstb, srcb, size, TYPE_ALIGN (va_list_type_node));
}
return const0_rtx;
abort ();
return target;
}
+
+/* Expand a call to __builtin_expect. We return our argument and
+ emit a NOTE_INSN_EXPECTED_VALUE note. */
+
+static rtx
+expand_builtin_expect (arglist, target)
+ tree arglist;
+ rtx target;
+{
+ tree exp, c;
+ rtx note, rtx_c;
+
+ if (arglist == NULL_TREE
+ || TREE_CHAIN (arglist) == NULL_TREE)
+ return const0_rtx;
+ exp = TREE_VALUE (arglist);
+ c = TREE_VALUE (TREE_CHAIN (arglist));
+
+ if (TREE_CODE (c) != INTEGER_CST)
+ {
+ error ("second arg to `__builtin_expect' must be a constant");
+ c = integer_zero_node;
+ }
+
+ target = expand_expr (exp, target, VOIDmode, EXPAND_NORMAL);
+
+ /* Don't bother with expected value notes for integral constants. */
+ if (GET_CODE (target) != CONST_INT)
+ {
+ /* We do need to force this into a register so that we can be
+ moderately sure to be able to correctly interpret the branch
+ condition later. */
+ target = force_reg (GET_MODE (target), target);
+
+ rtx_c = expand_expr (c, NULL_RTX, GET_MODE (target), EXPAND_NORMAL);
+
+ note = emit_note (NULL, NOTE_INSN_EXPECTED_VALUE);
+ NOTE_EXPECTED_VALUE (note) = gen_rtx_EQ (VOIDmode, target, rtx_c);
+ }
+
+ return target;
+}
\f
/* Expand an expression EXP that calls a built-in function,
with result going to TARGET if that's convenient
tree arglist = TREE_OPERAND (exp, 1);
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
+#ifdef MD_EXPAND_BUILTIN
+ if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
+ return MD_EXPAND_BUILTIN (exp, target, subtarget, mode, ignore);
+#endif
+
/* When not optimizing, generate calls to library functions for a certain
set of builtins. */
if (! optimize && ! CALLED_AS_BUILT_IN (fndecl)
&& (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
|| fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET
|| fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
+ || fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
|| fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY
|| fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_FFS))
return expand_call (exp, target, ignore);
return target;
break;
+ case BUILT_IN_BZERO:
+ target = expand_builtin_bzero (exp);
+ if (target)
+ return target;
+ break;
+
/* These comparison functions need an instruction that returns an actual
index. An ordinary compare that just sets the condition codes
is not enough. */
return target;
break;
+ case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP:
target = expand_builtin_memcmp (exp, arglist, target);
if (target)
break;
#else
case BUILT_IN_STRCMP:
+ case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP:
break;
#endif
#ifdef DWARF2_UNWIND_INFO
case BUILT_IN_DWARF_FP_REGNUM:
return expand_builtin_dwarf_fp_regnum ();
- case BUILT_IN_DWARF_REG_SIZE:
- return expand_builtin_dwarf_reg_size (TREE_VALUE (arglist), target);
+ case BUILT_IN_INIT_DWARF_REG_SIZES:
+ expand_builtin_init_dwarf_reg_sizes (TREE_VALUE (arglist));
+ return const0_rtx;
#endif
case BUILT_IN_FROB_RETURN_ADDR:
return expand_builtin_frob_return_addr (TREE_VALUE (arglist));
return expand_builtin_va_end (arglist);
case BUILT_IN_VA_COPY:
return expand_builtin_va_copy (arglist);
+ case BUILT_IN_EXPECT:
+ return expand_builtin_expect (arglist, target);
default: /* just do library call, if unknown builtin */
error ("built-in function `%s' not currently supported",